growork 1.0.1 → 1.1.1

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.
@@ -16,9 +16,9 @@ node --import tsx --test tests/notion.test.ts
16
16
 
17
17
  | 文件 | 测试内容 | 用例数 |
18
18
  |-----|---------|-------|
19
- | `tests/config.test.ts` | 配置文件解析和验证 | 12 |
20
- | `tests/feishu.test.ts` | 飞书 URL 解析、Markdown 转换 | 34 |
21
- | `tests/notion.test.ts` | Notion URL 解析、属性提取 | 28 |
19
+ | `tests/config.test.ts` | 配置文件解析、验证、V2.0 配置规范化 | 34 |
20
+ | `tests/feishu.test.ts` | 飞书 URL 解析、Markdown 转换 | 31 |
21
+ | `tests/notion.test.ts` | Notion URL 解析、属性提取 | 34 |
22
22
 
23
23
  ## 回归测试流程
24
24
 
@@ -32,8 +32,9 @@ npm test
32
32
 
33
33
  预期输出:
34
34
  ```
35
- ℹ tests 74
36
- pass 74
35
+ ℹ tests 99
36
+ suites 29
37
+ ℹ pass 99
37
38
  ℹ fail 0
38
39
  ```
39
40
 
@@ -59,12 +60,12 @@ npm test
59
60
 
60
61
  ### config.test.ts
61
62
 
62
- **配置解析**
63
+ **V1.0 配置解析**
63
64
  - 有效 YAML 配置解析
64
65
  - Notion 配置解析
65
66
  - 混合配置(飞书 + Notion)
66
67
 
67
- **配置验证**
68
+ **V1.0 配置验证**
68
69
  - 空文档配置 → 报错
69
70
  - 缺少飞书凭证 → 报错
70
71
  - 缺少 Notion 凭证 → 报错
@@ -72,6 +73,41 @@ npm test
72
73
  - 只有 Notion 文档 → 无需飞书凭证
73
74
  - 混合文档 → 需要所有相关凭证
74
75
 
76
+ **V2.0 文档类型推断**
77
+ - `feishu.cn` URL → feishu
78
+ - `larksuite.com` URL → feishu
79
+ - `notion.so` URL → notion
80
+ - `notion.site` URL → notion
81
+ - 未知域名 → 报错
82
+
83
+ **V2.0 文件名清理**
84
+ - 移除文件系统保留字符
85
+ - 空格替换为连字符
86
+ - 合并连续空格
87
+ - 移除首尾连字符
88
+ - 处理复杂标题
89
+ - 处理纯特殊字符
90
+
91
+ **V2.0 文档输入解析**
92
+ - 字符串输入 → `{ url }`
93
+ - 对象输入(只有 url)
94
+ - 对象输入(带 name)
95
+
96
+ **V2.0 配置规范化**
97
+ - custom 文档处理
98
+ - 带 name 的 custom 文档
99
+ - versions 中的简单 feature
100
+ - versions 中的分类型 feature(prd/design/api/test)
101
+ - 自定义 outputDir
102
+ - version 过滤
103
+ - feature 过滤
104
+ - custom 选项(只获取 custom 文档)
105
+ - 默认返回所有文档
106
+ - 多版本多 feature 处理
107
+
108
+ **V2.0 YAML 配置解析**
109
+ - 完整 V2.0 配置结构解析
110
+
75
111
  ### feishu.test.ts
76
112
 
77
113
  **URL 解析**
@@ -155,34 +191,48 @@ assert.throws(() => fn(), /错误信息/);
155
191
  assert.doesNotThrow(() => fn());
156
192
  ```
157
193
 
158
- ## 端到端测试(手动)
194
+ ## 端到端测试
195
+
196
+ 自动化测试覆盖纯函数逻辑,E2E 测试验证完整流程。
159
197
 
160
- 自动化测试覆盖纯函数逻辑,以下场景需要手动验证:
198
+ ### 快速验证(本地开发)
161
199
 
162
- ### init 命令
200
+ 修改代码后,运行以下命令验证:
163
201
 
164
202
  ```bash
165
- # 在空目录执行
166
- mkdir /tmp/test-growork && cd /tmp/test-growork
167
- growork init
203
+ # 1. 构建
204
+ npm run build
168
205
 
169
- # 验证
170
- ls -la docs/ # 应有 product/design/api/tech/test
171
- cat growork.config.yaml # 应有默认配置
172
- cat .gitignore # 应包含 growork.config.yaml
206
+ # 2. 同步文档(需要已配置 growork.config.yaml)
207
+ node dist/index.js sync
208
+
209
+ # 或者如果已全局安装
210
+ growork sync
173
211
  ```
174
212
 
175
- ### sync 命令
213
+ ### 完整 E2E 流程
176
214
 
177
215
  ```bash
178
- # 配置真实凭证和文档后
179
- growork sync # 同步所有
180
- growork sync prd # 同步指定文档
181
- growork sync invalid # 应报错并列出可用文档
182
- ```
216
+ # 1. 构建并本地安装
217
+ npm run build
218
+ npm link
183
219
 
184
- ### list 命令
220
+ # 2. 测试 init 命令
221
+ mkdir /tmp/test-growork && cd /tmp/test-growork
222
+ growork init
223
+ ls docs/ # 应有 product/design/api/tech/test
224
+ cat growork.config.yaml # 应有默认配置
185
225
 
186
- ```bash
187
- growork list # 显示文档列表和同步状态
226
+ # 3. 配置真实凭证后测试 sync
227
+ # 编辑 growork.config.yaml,填入真实的飞书/Notion 凭证
228
+ growork sync # 同步所有文档
229
+ growork sync prd # 同步指定文档
230
+ growork sync invalid # 应报错并列出可用文档
231
+
232
+ # 4. 测试 list 命令
233
+ growork list # 显示文档列表和同步状态
234
+
235
+ # 5. 清理
236
+ cd ~ && rm -rf /tmp/test-growork
237
+ npm unlink -g growork
188
238
  ```
@@ -1,418 +0,0 @@
1
- # GroWork v1.0 产品需求文档 (PRD)
2
-
3
- ## 1. 概述
4
-
5
- | 项目 | 内容 |
6
- | -------- | -------------------- |
7
- | 产品名称 | GroWork |
8
- | 版本 | v1.0 |
9
- | 产品形态 | CLI 命令行工具 |
10
- | 技术栈 | Node.js / TypeScript |
11
- | 发布日期 | 2025-01-30 |
12
-
13
- ## 2. 背景与目标
14
-
15
- ### 2.1 背景描述
16
-
17
- AI Code 时代,放大 Claude Code 这类 Agent Coding 工具的能力,提供更多的上下文,让 AI 在一个目录下搞定所有的需求。
18
-
19
- 常规的开发流程,
20
-
21
- #### 准备阶段
22
-
23
- 需求侧:"需求评审,文档在 Lark,设计稿评审,地址在 Figma
24
- 技术方案侧:后端出技术方案,包含业务接口后端和ai通信后端
25
- 客户端侧:客户端根据需求和技术方案,产出自己的技术方案和项目排期,结合项目的时间节点,给出项目时间
26
-
27
- #### 开发阶段
28
-
29
- 根据准备阶段手机到的东西,不断的抽象成feature,流程就是 方案(prompt)+ code + 自测,提交
30
- 提测之前会测试会产出测试用例
31
-
32
- #### 测试阶段
33
-
34
- 测试会把 bug 维护到 Lark 文档上,开发看到 bug,根据 bug 写方案(prompt)+ code + 自测,提交,修改 bug 状态
35
- 最后上线
36
-
37
- 全流程没有打通
38
-
39
- 已经做到的部分,desgin to code,通过fimga mcp + 设计元素的脚本自动化,让ai能够还原设计稿
40
- api to dart ,通过swagger实现flutter自动生成dart代码
41
-
42
- ### 2.2 产品目标
43
-
44
- 实现产品开发测试全流程在一个文件夹下闭环。
45
-
46
- ### 2.3 成功指标
47
-
48
- 自己成功闭环需求。
49
-
50
- ## 3. 用户分析
51
-
52
- ### 3.1 目标用户
53
-
54
- 使用 Agent 开发工具的开发团队。
55
-
56
- ### 3.2 用户痛点
57
-
58
- App 开发时,产品 PRD、设计稿、接口文档、后端技术方案、测试用例方案分散在不同平台,不能在一个工程内闭环,需要来回切换:
59
-
60
- | 文档类型 | 当前存放位置 |
61
- | ------------ | ------------- |
62
- | 产品 PRD | Lark / Notion |
63
- | 设计稿 | Figma |
64
- | 接口文档 | Lark / Notion |
65
- | 后端技术方案 | Lark / Notion |
66
- | 测试用例 | Lark / Notion |
67
- | 需求数据库 | Notion |
68
-
69
- ### 3.3 用户场景
70
-
71
- 日常开发工作中,希望 AI Agent 能一次性获取完整上下文进行开发。
72
-
73
- ## 4. 功能需求
74
-
75
- ### 4.1 版本规划
76
-
77
- **第一版(MVP):** 聚焦 Lark 和 Notion 文档同步,打通客户端开发场景。
78
-
79
- **后续版本:** Figma 设计稿同步、更多平台支持。
80
-
81
- ### 4.2 第一版功能列表
82
-
83
- | 命令 | 作用 | 状态 |
84
- | ----------------------- | ----------------------------------------- | --------- |
85
- | `growork init` | 生成配置文件模板 + 标准目录结构 | ✅ 已实现 |
86
- | `growork sync` | 同步所有配置的文档 | ✅ 已实现 |
87
- | `growork sync <name>` | 只同步指定的文档,如 `growork sync prd` | ✅ 已实现 |
88
- | `growork list` | 列出所有配置的文档及同步状态 | ✅ 已实现 |
89
-
90
- ### 4.2.1 批量文档同步
91
-
92
- **核心能力**:在 `growork.config.yaml` 中配置多个文档,一键同步到本地。
93
-
94
- ```yaml
95
- docs:
96
- - name: prd
97
- type: feishu
98
- url: "https://xxx.larksuite.com/wiki/xxxxx"
99
- output: "docs/product/prd.md"
100
-
101
- - name: api
102
- type: feishu
103
- url: "https://xxx.larksuite.com/wiki/xxxxx"
104
- output: "docs/api/api-spec.md"
105
-
106
- - name: test
107
- type: feishu
108
- url: "https://xxx.larksuite.com/wiki/xxxxx"
109
- output: "docs/test/test-cases.md"
110
- ```
111
-
112
- 执行 `growork sync` 后,所有配置的文档会被同步到指定路径,转换为 AI 友好的 Markdown 格式。
113
-
114
- **支持的文档类型**:
115
-
116
- | 类型 | 说明 | URL 格式 |
117
- | ---------- | -------------------------------- | ------------------------------ |
118
- | `feishu` | Lark 文档 (docx) 和知识库 (wiki) | `/docx/xxx` 或 `/wiki/xxx` |
119
- | `notion` | Notion 页面(含内嵌数据库) | 包含 32 位 ID 的 URL |
120
-
121
- ### 4.3 配置文件设计
122
-
123
- 用户在项目根目录维护 `growork.config.yaml` 配置文件:
124
-
125
- ```yaml
126
- # Lark 应用凭证
127
- feishu:
128
- appId: "cli_xxxx"
129
- appSecret: "xxxx"
130
- domain: "lark"
131
-
132
- # Notion 凭证
133
- notion:
134
- token: "ntn_xxxx"
135
-
136
- # 文档同步配置
137
- docs:
138
- # 产品文档(Lark 知识库)
139
- - name: prd
140
- type: feishu
141
- url: "https://xxx.larksuite.com/wiki/xxxxx"
142
- output: "docs/product/prd.md"
143
-
144
- # 产品文档(Notion 页面)
145
- - name: prd-notion
146
- type: notion
147
- url: "https://www.notion.so/xxxxx"
148
- output: "docs/product/prd-notion.md"
149
-
150
- # 接口文档(Lark)
151
- - name: api
152
- type: feishu
153
- url: "https://xxx.larksuite.com/docx/xxxxx"
154
- output: "docs/api/api-spec.md"
155
-
156
- # 后端技术方案
157
- - name: backend
158
- type: feishu
159
- url: "https://xxx.larksuite.com/docx/xxxxx"
160
- output: "docs/tech/backend.md"
161
-
162
- # 测试用例
163
- - name: test-cases
164
- type: feishu
165
- url: "https://xxx.larksuite.com/docx/xxxxx"
166
- output: "docs/test/test-cases.md"
167
- ```
168
-
169
- ### 4.4 标准目录结构
170
-
171
- 执行 `growork init` 后生成:
172
-
173
- ```
174
- project/
175
- ├── growork.config.yaml # 配置文件
176
- ├── docs/
177
- │ ├── product/ # 产品文档
178
- │ │ └── prd.md
179
- │ ├── design/ # 设计稿(后续版本)
180
- │ ├── api/ # 接口文档
181
- │ │ └── api-spec.md
182
- │ ├── tech/ # 技术方案
183
- │ │ └── backend.md
184
- │ └── test/ # 测试用例
185
- │ └── test-cases.md
186
- └── src/ # 代码目录
187
- ```
188
-
189
- ### 4.5 使用流程
190
-
191
- ```
192
- 1. npm install -g growork # 安装 CLI 工具
193
- 2. growork init # 生成配置文件和目录结构
194
- 3. 编辑 growork.config.yaml,填入 Lark 凭证和文档链接
195
- 4. growork sync # 一键同步所有文档
196
- ```
197
-
198
- ### 4.6 同步输出示例
199
-
200
- ```
201
- $ growork sync
202
-
203
- 📄 Syncing documents...
204
-
205
- ✓ prd → docs/product/prd.md
206
- ✓ api → docs/api/api-spec.md
207
- ✓ backend → docs/tech/backend.md
208
- ✗ test-cases → 获取失败:文档无权限
209
-
210
- Synced 3/4 documents.
211
- ```
212
-
213
- ## 5. 非功能需求
214
-
215
- ### 5.1 性能要求
216
-
217
- - 单个文档同步时间 < 5 秒
218
-
219
- ### 5.2 安全要求
220
-
221
- - Lark 凭证不应提交到 Git,配置文件应加入 .gitignore 或支持环境变量
222
-
223
- ### 5.3 兼容性要求
224
-
225
- - 支持 macOS / Linux / Windows
226
- - Node.js >= 18
227
-
228
- ## 6. 技术设计
229
-
230
- ### 6.1 项目结构
231
-
232
- ```
233
- growork/
234
- ├── package.json
235
- ├── tsconfig.json
236
- ├── src/
237
- │ ├── index.ts # CLI 入口
238
- │ ├── commands/
239
- │ │ ├── init.ts # growork init
240
- │ │ ├── sync.ts # growork sync
241
- │ │ └── list.ts # growork list
242
- │ ├── services/
243
- │ │ ├── feishu.ts # Lark API 封装 + Markdown 转换
244
- │ │ └── notion.ts # Notion API 封装 + Markdown 转换
245
- │ └── utils/
246
- │ └── config.ts # 配置文件读取
247
- └── bin/
248
- └── growork # CLI 可执行文件入口
249
- ```
250
-
251
- ### 6.2 技术选型
252
-
253
- | 用途 | 选择 |
254
- | ----------- | ----------------------- |
255
- | 语言 | TypeScript |
256
- | CLI 框架 | Commander.js |
257
- | Lark SDK | @larksuiteoapi/node-sdk |
258
- | Notion SDK | @notionhq/client |
259
- | Notion 转换 | notion-to-md |
260
- | 配置解析 | yaml |
261
- | 构建工具 | tsup |
262
-
263
- ### 6.3 Lark 同步流程
264
-
265
- ```
266
- 读取 growork.config.yaml
267
-
268
- 遍历 docs 配置
269
-
270
- 解析 Lark 文档 URL,提取 document_id
271
-
272
- 调用 Lark API 获取文档内容
273
-
274
- 转换为 Markdown 格式
275
-
276
- 写入到配置的 output 路径
277
- ```
278
-
279
- ### 6.4 Notion 同步流程
280
-
281
- ```
282
- 读取 growork.config.yaml
283
-
284
- 遍历 docs 配置(type: notion)
285
-
286
- 解析 Notion URL,提取 page_id
287
-
288
- 调用 Notion API 获取页面内容
289
-
290
- 使用 notion-to-md 转换为 Markdown
291
- (内嵌数据库自动转换为表格)
292
-
293
- 写入到配置的 output 路径
294
- ```
295
-
296
- ## 7. 导出格式支持
297
-
298
- ### 7.1 支持的导出格式
299
-
300
- | 格式 | 说明 | 使用场景 |
301
- | ----------- | ---------------------------- | --------------------- |
302
- | Markdown | Block API 直接转换,结构清晰 | AI Agent 读取(推荐) |
303
- | Word (docx) | Lark 原生导出 | 人工阅读、存档 |
304
- | PDF | Lark 原生导出 | 分享、打印 |
305
-
306
- ### 7.2 Markdown 转换能力
307
-
308
- 支持的 Lark 文档元素:
309
-
310
- | 元素 | Markdown 输出 |
311
- | ---------------- | ----------------------------------------- |
312
- | 标题 H1-H6 | `# ~ ######` |
313
- | 正文文本 | 普通段落 |
314
- | 无序列表 | `- item` |
315
- | 有序列表 | `1. item` |
316
- | 待办事项 | `- [ ] / - [x]` |
317
- | 代码块 | ` ```lang ``` ` |
318
- | 引用 | `> text` |
319
- | 表格 | Markdown 表格 |
320
- | 分割线 | `---` |
321
- | 粗体/斜体/删除线 | `**bold**` / `*italic*` / `~~del~~` |
322
- | 链接 | `[text](url)` |
323
- | 高亮块 (Callout) | 递归转换内容 |
324
- | 分栏布局 (Grid) | 递归转换内容 |
325
- | 嵌入表格 | `[嵌入表格: token]` 提示 |
326
-
327
- ## 8. 开放问题
328
-
329
- - [ ] 是否需要支持增量同步(只同步有变更的文档)?
330
- - [ ] 配置文件中的凭证是否改用环境变量更安全?
331
- - [ ] 是否需要支持独立的 Notion 数据库同步(目前仅支持页面内嵌数据库)?
332
- - [X] ~~是否需要支持 Lark 知识库/Wiki?~~ → 已支持
333
- - [X] ~~是否需要支持 Notion?~~ → v1.2 已支持页面(含内嵌数据库转换)
334
-
335
- ## 9. 附录
336
-
337
- ### 9.1 Lark 开放平台配置
338
-
339
- 使用前需要:
340
-
341
- 1. 在 [Lark 开放平台](https://open.larksuite.com/) 创建应用
342
- 2. 获取 App ID 和 App Secret
343
- 3. 开通以下权限:
344
-
345
- **必需权限(Markdown 同步)**:
346
-
347
- - `docx:document:readonly` - 读取文档内容
348
- - `wiki:wiki:readonly` - 读取知识库
349
-
350
- **可选权限(导出 Word/PDF)**:
351
-
352
- - `drive:drive:export` - 导出云文档
353
- - 需要将应用添加为知识库成员
354
-
355
- ### 9.2 Notion 配置
356
-
357
- 使用前需要:
358
-
359
- 1. 在 [Notion Integrations](https://www.notion.so/my-integrations) 创建一个 Integration
360
- 2. 获取 Internal Integration Token(以 `ntn_` 开头)
361
- 3. 在需要同步的页面中,点击右上角「...」→「Add connections」→ 选择你的 Integration
362
-
363
- **支持的 URL 格式**:
364
-
365
- - `https://www.notion.so/页面ID`
366
- - `https://www.notion.so/workspace/页面标题-页面ID`
367
- - `https://notion.so/页面ID?v=xxx`
368
-
369
- **注意**:页面内嵌入的数据库会自动转换为 Markdown 表格。
370
-
371
- ### 9.3 配置文件示例
372
-
373
- ```yaml
374
- # growork.config.yaml
375
-
376
- # Lark 应用凭证
377
- feishu:
378
- appId: "cli_xxxx"
379
- appSecret: "xxxx"
380
- domain: "lark"
381
-
382
- # Notion 凭证
383
- notion:
384
- token: "ntn_xxxx"
385
-
386
- # 文档同步配置
387
- docs:
388
- - name: prd
389
- type: feishu
390
- url: "https://xxx.larksuite.com/wiki/xxxxx"
391
- output: "docs/product/prd.md"
392
-
393
- - name: api
394
- type: feishu
395
- url: "https://xxx.larksuite.com/wiki/xxxxx"
396
- output: "docs/api/api-spec.md"
397
-
398
- - name: design-spec
399
- type: notion
400
- url: "https://www.notion.so/xxxxx"
401
- output: "docs/design/spec.md"
402
- ```
403
-
404
- ### 9.4 AI Agent 使用场景
405
-
406
- 配置好文档后,AI Agent(如 Claude Code)可以:
407
-
408
- 1. 读取 `docs/` 目录下的所有 Markdown 文档
409
- 2. 获取完整的产品需求、接口规范、技术方案
410
- 3. 基于上下文进行开发、测试、问题排查
411
-
412
- ```bash
413
- # 同步最新文档
414
- growork sync
415
-
416
- # AI Agent 读取上下文
417
- # Claude Code 会自动读取 docs/ 目录下的文档
418
- ```