prd-workflow-cli 1.1.25

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/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "prd-workflow-cli",
3
+ "version": "1.1.25",
4
+ "description": "产品需求管理规范 CLI 工具 - 基于 A→R→B→C 流程,集成 PM 确认机制和对话归档的需求管理命令行工具",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "prd": "./bin/prd-cli.js"
8
+ },
9
+ "scripts": {
10
+ "test": "jest",
11
+ "test:cn": "jest --reporters=./tests/reporters/chinese-reporter.js",
12
+ "test:unit": "jest tests/unit",
13
+ "test:integration": "jest tests/integration",
14
+ "test:watch": "jest --watch",
15
+ "test:coverage": "jest --coverage",
16
+ "postinstall": "node scripts/postinstall.js"
17
+ },
18
+ "keywords": [
19
+ "prd",
20
+ "product",
21
+ "requirements",
22
+ "workflow",
23
+ "ai-assisted",
24
+ "okr",
25
+ "product-management",
26
+ "cli"
27
+ ],
28
+ "author": "Hou Tong",
29
+ "license": "MIT",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/houtonghoutong/PRD-CLI"
33
+ },
34
+ "homepage": "https://github.com/houtonghoutong/PRD-CLI#readme",
35
+ "bugs": {
36
+ "url": "https://github.com/houtonghoutong/PRD-CLI/issues"
37
+ },
38
+ "dependencies": {
39
+ "chalk": "^4.1.2",
40
+ "commander": "^11.1.0",
41
+ "fs-extra": "^11.2.0",
42
+ "inquirer": "^8.2.5"
43
+ },
44
+ "engines": {
45
+ "node": ">=14.0.0"
46
+ },
47
+ "files": [
48
+ "bin/",
49
+ "commands/",
50
+ "scripts/",
51
+ ".agent/",
52
+ ".antigravity/",
53
+ "templates/",
54
+ ".cursorrules",
55
+ "AI-GUIDE.md",
56
+ "README.md",
57
+ "GUIDE.md"
58
+ ],
59
+ "devDependencies": {
60
+ "jest": "^29.7.0"
61
+ },
62
+ "jest": {
63
+ "testEnvironment": "node",
64
+ "testMatch": [
65
+ "**/tests/**/*.test.js"
66
+ ],
67
+ "testTimeout": 30000,
68
+ "coverageDirectory": "coverage",
69
+ "coveragePathIgnorePatterns": [
70
+ "/node_modules/",
71
+ "/tests/"
72
+ ]
73
+ }
74
+ }
@@ -0,0 +1,241 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * postinstall 脚本
5
+ * 在 npm install 完成后自动执行,更新项目中的 workflows 和规则文件
6
+ */
7
+
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+
11
+ // 静默模式运行(减少安装时的输出噪音)
12
+ const SILENT = process.env.PRD_POSTINSTALL_SILENT === 'true';
13
+
14
+ function log(msg) {
15
+ if (!SILENT) {
16
+ console.log(msg);
17
+ }
18
+ }
19
+
20
+ function logError(msg) {
21
+ // 错误始终输出
22
+ console.error(msg);
23
+ }
24
+
25
+ /**
26
+ * 获取项目根目录(向上查找包含 .prd-config.json 的目录)
27
+ */
28
+ function findProjectRoot(startDir) {
29
+ let currentDir = startDir;
30
+ const root = path.parse(currentDir).root;
31
+
32
+ while (currentDir !== root) {
33
+ const configPath = path.join(currentDir, '.prd-config.json');
34
+ if (fs.existsSync(configPath)) {
35
+ return currentDir;
36
+ }
37
+ currentDir = path.dirname(currentDir);
38
+ }
39
+
40
+ return null;
41
+ }
42
+
43
+ /**
44
+ * 比较文件是否有变化
45
+ */
46
+ function filesAreDifferent(sourcePath, targetPath) {
47
+ if (!fs.existsSync(targetPath)) {
48
+ return true;
49
+ }
50
+
51
+ try {
52
+ const sourceContent = fs.readFileSync(sourcePath, 'utf8');
53
+ const targetContent = fs.readFileSync(targetPath, 'utf8');
54
+ return sourceContent !== targetContent;
55
+ } catch {
56
+ return true;
57
+ }
58
+ }
59
+
60
+ /**
61
+ * 递归复制目录
62
+ */
63
+ function copyDirSync(src, dest) {
64
+ if (!fs.existsSync(dest)) {
65
+ fs.mkdirSync(dest, { recursive: true });
66
+ }
67
+
68
+ const entries = fs.readdirSync(src, { withFileTypes: true });
69
+
70
+ for (const entry of entries) {
71
+ const srcPath = path.join(src, entry.name);
72
+ const destPath = path.join(dest, entry.name);
73
+
74
+ if (entry.isDirectory()) {
75
+ copyDirSync(srcPath, destPath);
76
+ } else {
77
+ fs.copyFileSync(srcPath, destPath);
78
+ }
79
+ }
80
+ }
81
+
82
+ /**
83
+ * 获取目录下所有文件(递归)
84
+ */
85
+ function getAllFiles(dirPath, basePath = dirPath) {
86
+ const files = [];
87
+
88
+ if (!fs.existsSync(dirPath)) {
89
+ return files;
90
+ }
91
+
92
+ const entries = fs.readdirSync(dirPath, { withFileTypes: true });
93
+
94
+ for (const entry of entries) {
95
+ const fullPath = path.join(dirPath, entry.name);
96
+
97
+ if (entry.isDirectory()) {
98
+ files.push(...getAllFiles(fullPath, basePath));
99
+ } else {
100
+ files.push({
101
+ fullPath,
102
+ relativePath: path.relative(basePath, fullPath)
103
+ });
104
+ }
105
+ }
106
+
107
+ return files;
108
+ }
109
+
110
+ /**
111
+ * 主函数
112
+ */
113
+ function main() {
114
+ try {
115
+ // 获取 npm 包的路径(当前脚本所在目录的上级)
116
+ const packagePath = path.join(__dirname, '..');
117
+
118
+ // 尝试找到项目根目录
119
+ // 通常 node_modules 在项目根目录下,所以向上查找
120
+ const nodeModulesPath = path.dirname(path.dirname(packagePath));
121
+ const potentialProjectRoot = path.dirname(nodeModulesPath);
122
+
123
+ // 检查是否是 PRD 项目
124
+ const projectRoot = findProjectRoot(potentialProjectRoot);
125
+
126
+ if (!projectRoot) {
127
+ // 不是 PRD 项目,静默退出(这是正常情况,比如全局安装)
128
+ return;
129
+ }
130
+
131
+ log('\n📦 prd-workflow-cli: 检测到 PRD 项目,正在更新配置文件...');
132
+
133
+ // 定义需要更新的文件/目录
134
+ const updateItems = [
135
+ {
136
+ name: 'Workflows',
137
+ source: '.agent/workflows',
138
+ target: '.agent/workflows',
139
+ isDir: true
140
+ },
141
+ {
142
+ name: 'Cursor Rules',
143
+ source: '.cursorrules',
144
+ target: '.cursorrules',
145
+ isDir: false
146
+ },
147
+ {
148
+ name: 'Antigravity Rules',
149
+ source: '.antigravity',
150
+ target: '.antigravity',
151
+ isDir: true
152
+ },
153
+ {
154
+ name: 'AI Guide',
155
+ source: 'AI-GUIDE.md',
156
+ target: 'AI-GUIDE.md',
157
+ isDir: false
158
+ }
159
+ ];
160
+
161
+ let updatedCount = 0;
162
+ let newCount = 0;
163
+
164
+ for (const item of updateItems) {
165
+ const sourcePath = path.join(packagePath, item.source);
166
+ const targetPath = path.join(projectRoot, item.target);
167
+
168
+ if (!fs.existsSync(sourcePath)) {
169
+ continue;
170
+ }
171
+
172
+ if (item.isDir) {
173
+ // 处理目录
174
+ const files = getAllFiles(sourcePath);
175
+
176
+ for (const file of files) {
177
+ const targetFilePath = path.join(targetPath, file.relativePath);
178
+ const isNew = !fs.existsSync(targetFilePath);
179
+ const isDifferent = filesAreDifferent(file.fullPath, targetFilePath);
180
+
181
+ if (isDifferent) {
182
+ // 确保目标目录存在
183
+ const targetDir = path.dirname(targetFilePath);
184
+ if (!fs.existsSync(targetDir)) {
185
+ fs.mkdirSync(targetDir, { recursive: true });
186
+ }
187
+
188
+ fs.copyFileSync(file.fullPath, targetFilePath);
189
+
190
+ if (isNew) {
191
+ newCount++;
192
+ } else {
193
+ updatedCount++;
194
+ }
195
+ }
196
+ }
197
+ } else {
198
+ // 处理单个文件
199
+ const isNew = !fs.existsSync(targetPath);
200
+ const isDifferent = filesAreDifferent(sourcePath, targetPath);
201
+
202
+ if (isDifferent) {
203
+ // 确保目标目录存在
204
+ const targetDir = path.dirname(targetPath);
205
+ if (!fs.existsSync(targetDir)) {
206
+ fs.mkdirSync(targetDir, { recursive: true });
207
+ }
208
+
209
+ fs.copyFileSync(sourcePath, targetPath);
210
+
211
+ if (isNew) {
212
+ newCount++;
213
+ } else {
214
+ updatedCount++;
215
+ }
216
+ }
217
+ }
218
+ }
219
+
220
+ // 输出结果
221
+ if (newCount > 0 || updatedCount > 0) {
222
+ if (newCount > 0) {
223
+ log(` ✨ 新增 ${newCount} 个文件`);
224
+ }
225
+ if (updatedCount > 0) {
226
+ log(` 🔄 更新 ${updatedCount} 个文件`);
227
+ }
228
+ log(' ✅ 配置文件已同步到最新版本\n');
229
+ } else {
230
+ log(' ✅ 所有配置文件已是最新版本\n');
231
+ }
232
+
233
+ } catch (error) {
234
+ // postinstall 失败不应该阻止安装
235
+ // 只输出警告,不抛出错误
236
+ logError(`\n⚠️ prd-workflow-cli: 自动更新配置文件失败: ${error.message}`);
237
+ logError(' 您可以稍后手动运行 "prd upgrade" 来更新配置文件\n');
238
+ }
239
+ }
240
+
241
+ main();
@@ -0,0 +1,105 @@
1
+ # 🚀 新用户必读 - PRD 工作流项目
2
+
3
+ 欢迎使用本项目!在开始之前,请先完成以下设置。
4
+
5
+ ---
6
+
7
+ ## 第 1 步:安装项目依赖
8
+
9
+ 在项目根目录运行:
10
+
11
+ ```bash
12
+ npm install
13
+ ```
14
+
15
+ 这会安装 `prd-workflow-cli` 和其他依赖。
16
+
17
+ ---
18
+
19
+ ## 第 2 步:验证安装
20
+
21
+ 安装完成后,运行以下命令验证:
22
+
23
+ ```bash
24
+ npx prd --version
25
+ ```
26
+
27
+ 如果显示版本号(如 `1.1.12`),说明安装成功。
28
+
29
+ ---
30
+
31
+ ## 第 3 步:使用 CLI 命令
32
+
33
+ **⚠️ 重要:请使用 `npx prd` 而不是 `prd`**
34
+
35
+ ```bash
36
+ # 查看项目状态
37
+ npx prd status
38
+
39
+ # 创建基线文档
40
+ npx prd baseline create A0
41
+
42
+ # 创建规划文档
43
+ npx prd plan create B1
44
+
45
+ # 执行审视
46
+ npx prd review r1
47
+ ```
48
+
49
+ ### 其他 IDE
50
+
51
+ 请参考 `.agent/workflows/` 目录中的工作流文档。
52
+
53
+ ---
54
+
55
+ ## 第 3 步:了解项目结构
56
+
57
+ ```
58
+ 项目目录/
59
+ ├── 00_项目总览/ # P0 项目基本信息
60
+ ├── 01_产品基线/ # A0/A1/A2/R0 基线文档
61
+ ├── 02_迭代记录/ # 每轮迭代的 B/C/R 文档
62
+ ├── 98_对话归档/ # PM 与 AI 的对话记录
63
+ ├── 99_归档区/ # 历史版本归档
64
+ ├── .agent/workflows/ # AI 工作流规则
65
+ ├── .cursorrules # Cursor AI 行为规则
66
+ └── .prd-config.json # 项目配置
67
+ ```
68
+
69
+ ---
70
+
71
+ ## 第 4 步:开始使用
72
+
73
+ ### 查看项目状态
74
+
75
+ ```bash
76
+ prd status
77
+ ```
78
+
79
+ ### 常用命令
80
+
81
+ | 命令 | 用途 |
82
+ |------|------|
83
+ | `prd status` | 查看当前状态 |
84
+ | `prd iteration list` | 列出所有迭代 |
85
+ | `prd plan create B1` | 创建规划草案 |
86
+ | `prd review r1` | 执行 R1 审视 |
87
+ | `prd version create C1` | 创建版本需求清单 |
88
+
89
+ ---
90
+
91
+ ## 遇到问题?
92
+
93
+ 1. **命令提示 `prd: command not found`**
94
+ - 说明 CLI 未安装,请回到第 1 步
95
+
96
+ 2. **提示 "当前目录不是一个 PRD 项目"**
97
+ - 确保你在项目根目录(包含 `.prd-config.json` 的目录)
98
+
99
+ 3. **AI 行为不正确**
100
+ - 检查 `.cursorrules` 文件是否存在
101
+ - 可以提醒 AI:"请遵循 .cursorrules 的规则"
102
+
103
+ ---
104
+
105
+ **Happy Working! 🎉**
@@ -0,0 +1,109 @@
1
+ # [文档名称] - 对话记录
2
+
3
+ **创建时间**: [YYYY-MM-DD HH:MM:SS]
4
+ **迭代轮次**: [第 XX 轮迭代 / 基线阶段]
5
+ **文档类型**: [P0/A0/A1/A2/R0/B1/B2/R1/C0/C1/R2]
6
+
7
+ ---
8
+
9
+ ## 💬 对话 #1
10
+
11
+ **时间**: [YYYY-MM-DD HH:MM:SS]
12
+ **讨论主题**: [主题描述]
13
+
14
+ ### 🤖 AI [提问/分析/建议]
15
+ > [AI 的具体内容]
16
+ >
17
+ > [如果有多行,继续写...]
18
+
19
+ ### 🧑 PM [回答/决策/选择]
20
+ > [PM 的具体内容]
21
+ >
22
+ > [PM 的原话,不要总结]
23
+
24
+ ### 🤖 AI [引导/总结/确认]
25
+ > [AI 的回复内容]
26
+
27
+ ### ✅ PM 确认
28
+ > [PM 的确认内容]
29
+
30
+ ### 📝 AI 执行
31
+ > [AI 写入了什么文件、哪个章节]
32
+
33
+ ---
34
+
35
+ ## 💬 对话 #2
36
+
37
+ **时间**: [YYYY-MM-DD HH:MM:SS]
38
+ **讨论主题**: [主题描述]
39
+
40
+ ### 🤖 AI 提问
41
+ > [内容]
42
+
43
+ ### 🧑 PM 回答
44
+ > [内容]
45
+
46
+ ### 🤖 AI 总结
47
+ > [内容]
48
+
49
+ ### ✅ PM 确认
50
+ > [内容]
51
+
52
+ ### 📝 AI 执行
53
+ > [内容]
54
+
55
+ ---
56
+
57
+ ## 📊 对话统计
58
+
59
+ - **总对话轮次**: [N] 轮
60
+ - **PM 决策次数**: [N] 次
61
+ - **AI 提问次数**: [N] 次
62
+ - **AI 建议次数**: [N] 次
63
+ - **写入文件次数**: [N] 次
64
+
65
+ ---
66
+
67
+ ## 🔑 关键决策
68
+
69
+ | 决策项 | PM 决策 | 理由 |
70
+ |--------|---------|------|
71
+ | [决策1] | [决定] | [原因] |
72
+ | [决策2] | [决定] | [原因] |
73
+
74
+ ---
75
+
76
+ **归档完成时间**: [YYYY-MM-DD HH:MM:SS]
77
+
78
+ ---
79
+
80
+ ## 📝 使用说明
81
+
82
+ ### 什么时候使用这个模板?
83
+
84
+ AI 在以下时机必须归档对话:
85
+ 1. **每完成一个文档部分**(如 B1 的"规划目标"章节)
86
+ 2. **每次 PM 做出决策**(如选择采纳哪个建议)
87
+ 3. **每轮战略分析完成后**(如 B2 的分析 → 质疑 → 建议 → 决策)
88
+
89
+ ### 如何使用?
90
+
91
+ 1. 复制这个模板
92
+ 2. 修改文件名:如 `B1_对话记录.md`
93
+ 3. 填写对话内容(保持格式)
94
+ 4. 及时追加新的对话轮次
95
+
96
+ ### 归档原则
97
+
98
+ - ✅ 完整记录对话过程(不只是结论)
99
+ - ✅ 保留 PM 的原话(不要总结)
100
+ - ✅ 记录 AI 的引导过程
101
+ - ✅ 标注时间戳
102
+ - ✅ 及时归档(不要积累)
103
+
104
+ ### 不要
105
+
106
+ - ❌ 只记录结论
107
+ - ❌ 等到全部完成再归档
108
+ - ❌ 省略中间过程
109
+ - ❌ 总结或改写 PM 的话