draftgo-cli 3.0.55 → 4.0.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.
Files changed (50) hide show
  1. package/README.md +112 -316
  2. package/package.json +5 -5
  3. package/resources/skill/SKILL.md +25 -24
  4. package/resources/skill/init/SKILL.md +5 -10
  5. package/resources/skill/manifest.json +2 -2
  6. package/resources/skill/references/aihub.md +10 -5
  7. package/resources/skill/references/chat-sdk.md +10 -0
  8. package/resources/skill/references/checkout.md +4 -4
  9. package/resources/skill/references/custom-services.md +65 -226
  10. package/resources/skill/references/data.md +3 -2
  11. package/resources/skill/references/frontend.md +96 -490
  12. package/resources/skill/references/mcp.md +39 -103
  13. package/resources/skill/references/runtime.md +3 -2
  14. package/resources/skill/story/SKILL.md +1 -2
  15. package/src/apiContractCache.js +112 -0
  16. package/src/cli.js +1 -21
  17. package/src/commandRegistry.js +6 -11
  18. package/src/commands/api.js +28 -8
  19. package/src/commands/check.js +1 -10
  20. package/src/commands/customService.js +2 -4
  21. package/src/commands/delete.js +23 -46
  22. package/src/commands/deploy.js +1 -1
  23. package/src/commands/help.js +16 -31
  24. package/src/commands/init.js +4 -10
  25. package/src/commands/listTargets.js +1 -1
  26. package/src/commands/local.js +2 -6
  27. package/src/commands/map.js +0 -11
  28. package/src/commands/status.js +1 -1
  29. package/src/commands/uninstall.js +3 -3
  30. package/src/commands/update.js +1 -1
  31. package/src/commands/verify.js +43 -21
  32. package/src/commands/{verifyUi.js → visualVerify.js} +28 -116
  33. package/src/commands/worklog.js +86 -0
  34. package/src/customServices.js +150 -33
  35. package/src/{localdev → localRuntime}/detect.js +1 -1
  36. package/src/{localdev → localRuntime}/mysqlClient.js +1 -1
  37. package/src/{localdev → localRuntime}/services.js +1 -1
  38. package/src/projectConfig.js +2 -0
  39. package/src/{installers/index.js → targets.js} +3 -5
  40. package/src/worklog.js +274 -0
  41. package/src/workspaceHealth.js +1 -1
  42. package/src/worktree/index.js +81 -51
  43. package/src/changelog.js +0 -276
  44. package/src/commands/changelog.js +0 -24
  45. package/src/commands/localDev.js +0 -9
  46. package/src/commands/sync.js +0 -46
  47. package/src/commands/task.js +0 -408
  48. package/src/commands/verifyUiCompat.js +0 -16
  49. /package/src/{localdev → localRuntime}/compose.js +0 -0
  50. /package/src/{localdev → localRuntime}/index.js +0 -0
package/README.md CHANGED
@@ -1,381 +1,177 @@
1
- # draftgo-cli
1
+ # DraftGo CLI 4
2
2
 
3
- ## Workflow 2.0
3
+ 面向 AI 编码工具的 DraftGo 工作台 CLI。它负责 Skill 安装、项目连接、MCP 发现、长正文 checkout/commit、自定义服务草稿、统一本地验收和 worklog 记录。
4
4
 
5
- The root DraftGo Skill loads automatically in supported AI hosts. Agents read the smallest task-specific Reference set first, then query current project state through precise MCP tools instead of generating an aggregate context bundle.
5
+ ## 核心规则
6
6
 
7
- Pages, navigations, documents, and custom services are long-content resources. Custom services use `draftgo checkout custom-services <id>` and a four-file worktree (`service.go`, `go.mod`, `go.sum`, `service.json`). `commit` saves the shared cloud draft, `test` validates or executes it in the DraftGo Runner, and `publish` explicitly promotes a validated draft without interrupting the current live version. Start later work with `refresh`; it stops when local edits exist. Cloud versions are the only history, while local storage keeps only current content and one base.
7
+ - Skill 自动加载;Agent 只读取当前任务需要的 Reference。
8
+ - pages、navigations、docs/articles 和 custom services 的完整正文使用 `checkout`、worktree、`diff`、`commit`;结构化资源使用 MCP/API。
9
+ - MCP schema 是服务端实时契约。已知 operation 优先使用项目私有缓存;首次使用或 `registry_revision` 变化时 describe。schema 不写入 Skill 或聊天上下文。
10
+ - 不同资源、operation 和 owner 的工作全部并发;同一资源的依赖步骤保持串行。
11
+ - 每个任务开始记录到 `.draftgo/worklog.md`,验证和交付成功后再标记完成。
8
12
 
9
- Small, single-point changes do not need Task overhead. Cross-module, cross-session, or multi-Agent work uses one authoritative `.draftgo/Task/[YYYY-MM-DD]<slug>/Task.md` and `draftgo task create|add|claim|start|complete|block|reopen|accept|finish`. The file keeps the user's original request, the clarified executable requirement, expected effects, scope, checklist, decisions, blockers, and final acceptance together. Legacy `task.yaml + plan.md + items/` tasks remain readable and migrate only through an explicit `draftgo task migrate`. `.draftgo/tmp/` is entirely disposable; user-facing evidence belongs in registered `.draftgo/artifacts/`, and `draftgo clean` removes all tmp plus registered artifacts. UI smoke checks remain single viewport and use `--screenshot never` by default. Supply `on-failure` or `always` only for explicit strong visual verification.
13
+ ## 验收策略
10
14
 
11
- 面向 AI 编码工具的 DraftGo 工作台 CLI:分发 DraftGo Skill,通过 MCP 发现和操作实时资源,并为页面、导航和文档提供可校验的 `checkout` / `commit` 工作流。
15
+ 普通交付只运行:
12
16
 
13
- DraftGo Next 壳层使用 React + Vite;数据库页面可按任务使用原生 Web 技术、Tailwind CSS 或平台内置组件库。CLI 仍提供 Docker 本地运行、项目检查和浏览器验证能力。
14
-
15
- 支持安装 Skill 的宿主:Claude Code、Codex CLI、Cursor、Windsurf、Antigravity、GitHub Copilot、Gemini CLI、Kiro。
16
-
17
- ## 前置条件
18
-
19
- - Node.js >=20.19
20
- - 使用 `draftgo local ...` 时需要 Docker 和 Docker Compose
21
-
22
- CLI 不再依赖 Python 同步脚本,也不会创建 DraftGo 业务资源的全量本地镜像。
23
-
24
- ## 工作模型
25
-
26
- ```text
27
- 根 SKILL.md -> Agent 按任务读取最少必要的 Reference
28
- AI 宿主 -> draftgo mcp serve -> DraftGo /mcp
29
- |
30
- +-> 结构化资源、元数据、搜索和正文片段
31
-
32
- draftgo checkout/commit -> DraftGo 专用 HTTP 正文端点
33
- (完整 HTML/Markdown 不经过 MCP 上下文)
17
+ ```bash
18
+ draftgo verify
34
19
  ```
35
20
 
36
- - Agent 负责理解任务语义、选择 Reference,并通过精确 MCP 工具逐步定位相关资源;CLI 不生成聚合上下文包。
37
- - MCP 用于项目概览、资源搜索/列表、元数据、正文片段和实时 API 调用。
38
- - `pages`、`navigations` 和 `docs/articles` 的完整正文使用 `checkout` / `commit`。
39
- - `db_meta`、AIHub、`system_config`、角色、用户、文档分类、自定义服务等结构化资源直接通过 MCP/API 操作,不生成本地索引。
40
- - `.draftgo/pages/`、`.draftgo/navigations/` 等旧 `index.json` 缓存只视为 legacy 数据;CLI 不删除它们,但 `map` 和 `check` 会忽略它们。
41
- - DraftGo Skill 继续提供资源关系、前端运行能力与实践、数据和权限、安全规则、自定义服务经验以及验证流程;MCP 不替代 Skill。
42
- - CLI 不提供页面模板,也不替 Agent 选择页面结构或视觉风格。
21
+ 默认验收只做本地检查,不启动浏览器,也不生成截图。只有用户明确要求视觉验收时才访问浏览器或截图;两者同时要求时先截图并查看结果,再做交互或 DOM 检查。
43
22
 
44
- ## Agent 阅读顺序
23
+ ```bash
24
+ # 截图验收,默认 desktop 1440x900
25
+ draftgo verify --url http://localhost:3000/path --screenshot always
45
26
 
46
- DraftGo Skill 不能被 MCP 替代。根 `SKILL.md` 会在 Skill 触发时自动加载;Agent 按任务路由渐进读取相关 Reference:
27
+ # 用户明确要求交互或 DOM 验收
28
+ draftgo verify --url http://localhost:3000/path --ui always
47
29
 
48
- ```text
49
- 已加载的 SKILL.md
50
- -> 读取任务所需的最少 Reference
51
- -> 用 resource_search / api_search 精确定位
52
- -> 按需 describe、读取 metadata 或片段
53
- -> 必要时 checkout 正文
30
+ # 仅在用户要求时增加移动端
31
+ draftgo verify --url http://localhost:3000/path --screenshot always --viewport both
54
32
  ```
55
33
 
56
- 页面任务读取 `frontend.md`,按需补读 `runtime.md` / `app-api.md`;数据、自定义服务和 AIHub 任务分别读取对应 Reference。目标明确时不要全量枚举无关资源。`mcp test` 是连接诊断,不是每次资源查询的前置步骤。
57
-
58
- 页面需求先结合用户意图和 MCP 实时资源判断是修改已有页面还是新增页面。已有页面在确认唯一 ID 后 checkout;独立新页面先通过实时 API 创建并取得 ID,再 checkout 完整正文。“做一个功能页面”本身不预设新建或修改,只有不同判断会产生明显不同结果时才需要向用户澄清。
59
-
60
- 只回答无需实时状态的本地规则问题时,不必调用 MCP。静态资源须先区分:平台内置目录由 `frontend.md` 说明,指定页面依赖经 MCP 定位、checkout 后本地搜索,服务器全量文件不能凭现有 Skill、MCP 摘要或 checkout 声称已枚举。
61
-
62
- Skill 说明产品约束、内置能力和操作规则;MCP 说明当前远端状态;checkout 正文才能证明某个页面完整引用了哪些静态资源。汇报时应明确标注这三类证据,不能互相替代。
34
+ `--ui` 和 `--screenshot` 的默认值都是 `never`;截图模式只有 `always` `never`。默认视口是 desktop `1440x900`,移动端为 `390x844`。
63
35
 
64
36
  ## 安装与连接
65
37
 
66
38
  ```bash
67
39
  npm install -g draftgo-cli
68
-
69
- cd /path/to/your/project
70
- draftgo init # 自动识别宿主并安装 DraftGo Skill
71
- draftgo connect codex # 输入 server 和 SAT,验证 MCP,并配置 Codex
40
+ cd /path/to/project
41
+ draftgo init
42
+ draftgo connect --server https://draftgo.example --token "$DRAFTGO_SAT"
43
+ draftgo mcp setup
44
+ draftgo mcp test
72
45
  ```
73
46
 
74
- 也可以非交互连接:
47
+ `connect` 会验证 SAT、MCP initialize、tools/list 和关键工具调用,然后把连接写入项目私有的 `.draftgo/config.json`。宿主 MCP 配置只包含 `draftgo mcp serve`,不会保存 SAT。
48
+
49
+ 本地底座:
75
50
 
76
51
  ```bash
77
- draftgo connect codex --server https://draftgo.example --token "$DRAFTGO_SAT"
52
+ draftgo local setup
53
+ draftgo local start
54
+ draftgo local status
55
+ draftgo local logs app
56
+ draftgo local stop
78
57
  ```
79
58
 
80
- `--server` 始终表示 DraftGo 基础地址。直接连接 MCP endpoint 时使用 `--mcp-url https://draftgo.example/mcp`;CLI 会显式保存 `mcp_url`,若未同时传 `--server`,则从标准 `/mcp` 后缀推导基础地址,避免猜测已有 base URL 的语义。
81
-
82
- `connect` 会先验证 SAT、MCP `initialize`、`tools/list` 和关键 `tools/call`,成功后写入项目私有配置 `.draftgo/config.json`,并尝试为指定或自动检测到的宿主执行 MCP setup。`init` / `connect` 不会预建 Task、lessons、changelog、worktree、conflicts 等运行时内容;这些文件和目录只在对应能力首次使用时按需创建。它不会 pull 页面、导航、文档或任何其他业务资源。
83
-
84
- 远端暂不可用时,只有显式传入 `--allow-offline` 才会保存配置;恢复后运行 `draftgo mcp test`。使用 `--no-mcp-setup` 可跳过宿主配置。
59
+ ## 命令
85
60
 
86
- `connect` 会把以下运行时路径加入项目 `.gitignore`:
61
+ ### 项目与 Skill
87
62
 
88
63
  ```text
89
- .draftgo/config.json
90
- .draftgo/token
91
- .draftgo/worktree/
92
- .draftgo/conflicts/
64
+ draftgo init [target...]
65
+ draftgo update [target...]
66
+ draftgo uninstall <target|all> [--purge]
67
+ draftgo status
68
+ draftgo list-targets
69
+ draftgo connect [target...]
93
70
  ```
94
71
 
95
- SAT 只从 `.draftgo/config.json` 读取。宿主 MCP 配置、命令输出和错误信息都不应包含 SAT。
72
+ ### 发现与正文
96
73
 
97
- ## MCP 命令
98
-
99
- ```bash
100
- draftgo mcp setup [target...] # 写入或合并项目级 MCP 配置
101
- draftgo mcp status [target...] # 检查配置是否存在且不含敏感连接参数
102
- draftgo mcp test # 验证 initialize、tools/list、项目/正文/API 三条调用路径
103
- draftgo mcp serve # 启动 stdio -> 远端 Streamable HTTP bridge
74
+ ```text
75
+ draftgo map [--type pages|nav|docs]
76
+ draftgo checkout <pages|nav|docs|custom-services> <id...> [--force]
77
+ draftgo check [custom-services <id...>] [--remote]
78
+ draftgo verify [<type> <id...>] [visual flags]
79
+ draftgo diff <type> <id>
80
+ draftgo commit <type> <id...>
81
+ draftgo refresh <type> <id...>
82
+ draftgo reconcile <type> <id...>
83
+ draftgo conflicts [--all]
84
+ draftgo conflict show <type> <id>
85
+ draftgo conflict resolve <type> <id>
104
86
  ```
105
87
 
106
- `mcp serve` 会保留远端 `Mcp-Session-Id`。服务重启或 session 过期后,它会自动重新 initialize,并只重试一次被明确拒绝为 session 无效的当前请求;普通工具失败、超时和 5xx 不会自动重试。`mcp test` 使用独立的新连接,只证明当前配置能够建立新 session,不能直接证明宿主此前持有的 session 仍有效。
107
-
108
- `setup` 不传 target 时自动检测当前项目的宿主。可用 `--target codex,cursor` 传入多个目标。
109
-
110
- 当前 MCP 宿主支持:
88
+ `checkout` 下载正文和经过 hash 校验的 base。`commit` 先并发完成所有目标的本地与远端 preflight,全部通过后再并发上传;任何 409/412 都保留 base/local/remote 冲突材料,不 force、不覆盖、不自动合并。
111
89
 
112
- | 宿主 | 项目配置 | 状态 |
113
- |---|---|---|
114
- | Codex CLI | `.codex/config.toml` | 支持 |
115
- | Claude Code | `.mcp.json` | 支持 |
116
- | Cursor | `.cursor/mcp.json` | 支持 |
117
- | Gemini CLI | `.gemini/settings.json` | 支持 |
118
- | Kiro | `.kiro/settings/mcp.json` | 支持 |
119
- | GitHub Copilot | `.vscode/mcp.json` | 支持 |
120
- | Windsurf | - | 不支持项目级 MCP setup |
121
- | Antigravity | - | 不支持项目级 MCP setup |
90
+ ### Custom service
122
91
 
123
- Codex 配置由 `draftgo mcp setup codex` 合并为:
124
-
125
- ```toml
126
- [mcp_servers.draftgo]
127
- command = "draftgo"
128
- args = ["mcp", "serve"]
129
- ```
130
-
131
- 其他支持的宿主同样只保存 stdio 命令。例如 Claude Code、Cursor、Gemini 和 Kiro 使用 `mcpServers.draftgo`:
132
-
133
- ```json
134
- {
135
- "mcpServers": {
136
- "draftgo": {
137
- "command": "draftgo",
138
- "args": ["mcp", "serve"]
139
- }
140
- }
141
- }
92
+ ```text
93
+ draftgo checkout custom-services <id...>
94
+ draftgo diff custom-services <id>
95
+ draftgo commit custom-services <id...>
96
+ draftgo validate custom-services <id>
97
+ draftgo test custom-services <id> [--handler route:POST:/path]
98
+ draftgo publish custom-services <id...>
142
99
  ```
143
100
 
144
- GitHub Copilot 使用 `.vscode/mcp.json` `servers.draftgo`,并额外写入 `"type": "stdio"`。这些文件不包含 server、SAT、header 或环境变量;bridge 在运行时从当前项目读取私有配置。
101
+ 每个 custom service worktree 只包含 `service.go`、`go.mod`、`go.sum` `service.json`。保存或 commit 草稿会清空验证凭证;validate 把凭证绑定当前 revision、源码、依赖、SDK 和 Runner 协议。publish 只接受当前有效凭证,Runner/SDK 变化造成的 `validation_stale` 会由 CLI 自动重新 validate 一次;revision 冲突仍直接失败。
145
102
 
146
- DraftGo MCP 预期提供以下工具:
147
-
148
- - `draftgo_project_overview`
149
- - `draftgo_resource_list`
150
- - `draftgo_resource_search`
151
- - `draftgo_resource_get_metadata`
152
- - `draftgo_resource_read_fragment`
153
- - `draftgo_api_search`
154
- - `draftgo_api_describe`
155
- - `draftgo_api_call`
156
-
157
- ## 标准工作流
103
+ ### MCP/API
158
104
 
159
105
  ```text
160
- Agent 按任务读取相关 Reference
161
- MCP 精确定位
162
- Agent 自主设计并批量 checkout
163
- 独立资源按需并行开发
164
- Agent 一次统一验证
165
- commit
166
- draftgo changelog add "<完成结果>"
106
+ draftgo mcp setup [target...]
107
+ draftgo mcp status [target...]
108
+ draftgo mcp test
109
+ draftgo mcp serve
110
+ draftgo api <query>
111
+ draftgo api search <query>
112
+ draftgo api describe <operation_id>
113
+ draftgo api call <operation_id> --input <json-file>
114
+ draftgo delete <operation_id> [id] [--params JSON]
167
115
  ```
168
116
 
169
- 无依赖且修改不同资源的工作可以并行;同一文件或 DraftGo 资源全程只分配给一个 Agent。开始并行实现前先确定共享 schema、接口、权限和路由。单页面、强依赖或仍共享主要资源的任务由一个 Agent 完成。主 Agent 负责 Reference/MCP 路由、资源 owner、汇总回读、统一验证、commit 和最终 changelog
117
+ `api call` 对已缓存 operation 直接调用并携带 `registry_revision`。服务端返回 `CONTRACT_CHANGED` 时只 describe、更新缓存并重试一次。调用输入必须是 UTF-8 JSON object;输出包含 HTTP status、服务端 code 和 request ID
170
118
 
171
- 前端任务先读取 `references/frontend.md`,涉及 iframe、路由、认证或全局层时补读 `runtime.md` / `app-api.md`,再通过 MCP 定位目标资源。
119
+ ### 交付与记录
172
120
 
173
- 确定全部正文资源后批量 checkout,自主设计并按唯一 owner 编辑,最后统一验证和交付:
174
-
175
- ```bash
176
- draftgo checkout pages 42 43
177
- # 独立资源可并行编辑;同一资源只由一个 Agent 修改
178
- draftgo check
179
- draftgo verify pages 42 --remote --url http://localhost:5173/example
180
- draftgo diff pages 42
181
- draftgo diff pages 43
182
- draftgo commit pages 42 43
183
- draftgo changelog add "完成文档管理系统及角色权限"
121
+ ```text
122
+ draftgo deploy <type> <id...> [--delivery local|preview|deploy]
123
+ draftgo auto-push [<type> <id...>]
124
+ draftgo work start <item>
125
+ draftgo work add <item>
126
+ draftgo work start-item <number|date#number>
127
+ draftgo work complete <number|date#number> [--note <evidence>]
128
+ draftgo work show|list
129
+ draftgo clean [--dry-run|--yes]
184
130
  ```
185
131
 
186
- 只查询长内容时,优先使用 MCP 搜索和片段工具;需要全文分析或编辑时才 checkout。不要要求 MCP 返回完整 HTML 或 Markdown。
187
-
188
- 结构化资源使用 `draftgo_api_search` / `draftgo_api_describe` 查实时契约,再用 `draftgo_api_call` 操作。AIHub Agent、Prompt、MCP、Skill、供应商和模型路由也属于实时结构化资源,不写本地快照;供应商密钥或 header 值不得出现在 Agent 输出中。
189
-
190
- 只有整个任务统一验证并且所有 commit/MCP 写入成功后才执行一次 `changelog add`。验证失败、409/412 或任一交付失败时不得写入。
191
-
192
- ## 命令清单
132
+ ## Worklog
193
133
 
194
- ### Skill 与连接
195
-
196
- | 命令 | 说明 |
197
- |---|---|
198
- | `draftgo init [target]...` | 安装 Skill;不传 target 时自动识别,`all` 表示全部。 |
199
- | `draftgo update [target]...` | 更新全局 CLI,并原子刷新已安装或检测到的 Skill。 |
200
- | `draftgo uninstall <target|all>` | 移除指定宿主的 Skill;`--purge` 还会删除整个 `.draftgo/`。 |
201
- | `draftgo status` | 显示已安装宿主和 Skill 版本。 |
202
- | `draftgo connect [target]...` | 验证并保存 server/SAT,随后配置宿主 MCP;不下载业务资源。 |
203
- | `draftgo list-targets` | 列出可安装 Skill 的 AI 宿主。 |
204
-
205
- ### 发现、正文和冲突
206
-
207
- | 命令 | 说明 |
208
- |---|---|
209
- | `draftgo map` | 并行读取 pages、navigations、docs/articles 元数据,再叠加本地 checkout 状态;`--type` 可限制一种类型。 |
210
- | `draftgo checkout <pages|nav|docs> <id...>` | 下载完整正文和 base,校验 hash 后原子落盘;`--force` 可显式覆盖已修改的本地正文。 |
211
- | `draftgo check` | 默认只检查本地 checkout;`--remote` 额外对比 local/base/manifest/remote 的版本和 hash。 |
212
- | `draftgo verify [<type> <id...>]` | 统一执行静态检查;`--remote` 增加远端比较,`--url` 增加 iframe-aware 浏览器验证。 |
213
- | `draftgo diff <pages|nav|docs> <id>` | 显示 checkout base 与当前本地正文的差异。 |
214
- | `draftgo commit <pages|nav|docs> <id...>` | 本地校验后,通过专用 HTTP 上传完整正文并更新 base/manifest。 |
215
- | `draftgo reconcile <pages|nav|docs> <id...>` | 仅当 local 与经校验的 remote 字节一致时,安全修复落后的 base/manifest 元数据。 |
216
- | `draftgo conflicts` | 列出未解决冲突;存在冲突时返回非零。`--all` 包括已解决记录。 |
217
- | `draftgo conflict show <type> <id>` | 显示冲突的 base/local/remote/worktree 路径。 |
218
- | `draftgo conflict resolve <type> <id>` | 确认 worktree 已合并,把保留的 remote 设为新 base;随后重新 check、diff、commit。 |
219
- | `draftgo verify-ui <url>` | `verify --url <url> --ui always` 的弃用兼容入口。 |
220
-
221
- `pages`、`page`,`nav`、`navigation`、`navigations`,以及 `docs`、`doc`、`article`、`articles`、`docs/articles` 都会规范化到三个支持的正文类型。
222
-
223
- ### 实时 API 与交付
224
-
225
- | 命令 | 说明 |
226
- |---|---|
227
- | `draftgo api <query>` | 通过 MCP `api_search` 查询实时 API 契约。 |
228
- | `draftgo api search <query>` | `draftgo api <query>` 的显式搜索形式。 |
229
- | `draftgo api describe <operation_id>` | 通过 MCP `api_describe` 查看指定操作。 |
230
- | `draftgo api call <operation_id> --input <file>` | 描述后调用实时 operation;JSON 文件严格按 UTF-8 解码并输出状态码、服务端 code 和 request ID。 |
231
- | `draftgo delete <operation_id> [id]` | 描述并确认后调用实时 MCP `api_call`;支持 `--params JSON`、`--input file` 和 `--yes`。 |
232
- | `draftgo deploy [<type> <id...>]` | 先 `check`,再按 delivery 模式检查 diff 或 commit。仅 `--delivery local` 可省略 type/id。 |
233
- | `draftgo auto-push [<type> <id...>]` | `auto_push: true` 时检查并 commit 已 checkout 的变更;有冲突立即停止。 |
234
- | `draftgo changelog add "<完成结果>"` | 在整个任务统一验证并全部交付成功后追加一条完成结果。 |
235
- | `draftgo pull` | 仅输出迁移提示并返回非零;永不下载资源。 |
236
- | `draftgo push <type> <id...>` | 已弃用;仅对 pages/nav/docs 显示提示后转发到 `commit`。不支持 push-all 或结构化资源。 |
237
-
238
- `deploy` 的 `--delivery local` 只运行检查,`preview` 运行检查并显示 diff,`deploy` 运行检查后 commit 指定正文。它不会遍历旧索引。`push --dry-run` 只显示指定正文的 diff。
239
-
240
- `auto-push` 不传 id 时只处理 manifest 中已修改的 checkout;项目未连接或 `auto_push` 未启用时安全跳过。
241
-
242
- ### 更新日志
243
-
244
- `draftgo changelog add` 写入 `.draftgo/changelog.md`。同一天继续编号;本地日期变化后追加新区块并从 `1` 开始。命令只接受单行、非空的完成结果;现有文件不符合固定格式时拒绝改写。
134
+ `.draftgo/worklog.md` 是任务、进度和完成证据的唯一记录。格式如下:
245
135
 
246
136
  ```markdown
247
- 2026-07-31
248
- ===
249
- 1. 完成文档管理系统及角色权限
250
- 2. 修复文档编辑权限问题
251
-
252
- 2026-08-01
253
- ===
254
- 1. 增加文档分类功能
137
+ [ 2026-08-09 ]
138
+ 1. [ ● ] 实现页面权限
139
+ // 正在开发
140
+ 2. [ ] 补充验收
141
+
142
+ [ 2026-08-10 ]
143
+ 1. [ √ ] 完成文档
144
+ // draftgo verify、commit 已通过
255
145
  ```
256
146
 
257
- 只记录已完成结果,不记录排查过程。统一验证、409/412 或任一交付失败时不运行该命令。
258
-
259
- ### 本地 DraftGo
260
-
261
- | 命令 | 说明 |
262
- |---|---|
263
- | `draftgo local setup` | 生成 `.draftgo/docker/docker-compose.yaml`,初始化并启动本地 DraftGo 栈。 |
264
- | `draftgo local start` | 启动本地栈;`up` 是兼容别名。 |
265
- | `draftgo local stop` | 停止本地栈;`down` 是兼容别名。 |
266
- | `draftgo local logs [service...]` | 查看日志;不传服务时跟随 `app`。 |
267
- | `draftgo local status` | 显示容器状态;`ps` 是兼容别名。 |
268
- | `draftgo local-dev` | `draftgo local setup` 的兼容入口。 |
269
-
270
- 本地 Docker、MySQL、Redis、Milvus 和 app 生命周期与 MCP/checkout 工作流相互独立。
147
+ 空状态表示待开发,`●` 表示开发中,`√` 表示开发完成。任务开始就写入记录;验证、冲突或交付失败时不能标记为完成。
271
148
 
272
- ## Worktree 与 manifest
149
+ ## 运行时目录
273
150
 
274
151
  ```text
275
152
  .draftgo/
276
153
  ├── config.json
154
+ ├── api-contract-cache.json
155
+ ├── worklog.md
277
156
  ├── worktree/
278
- ├── manifest.json
279
- ├── pages/
280
- │ ├── navigations/
281
- │ ├── docs/
282
- │ └── .base/
283
- └── conflicts/
284
- ```
285
-
286
- `.draftgo/worktree/manifest.json` 使用 `schema_version: 1`,条目键为规范化类型和 id,例如 `pages:42`。每个条目记录:
287
-
288
- - `server`、`resource_type`、`resource_id`
289
- - `title`、`route` / `code` / `slug`
290
- - `local_path`、`base_path`
291
- - `content_type`、`file_extension`、`content_size`
292
- - `base_version`、`base_revision`、`base_etag`、`base_hash`
293
- - `checked_out_at`,commit 后还会记录更新时间
294
-
295
- 已知正文类型保持原始字节和语义:`text/html` 使用 `.html`,Markdown 使用 `.md`,纯文本使用 `.txt`,其他类型使用底座返回且通过安全校验的扩展名。CLI 不转换 HTML、Markdown 或正文编码。
296
-
297
- checkout 会通过 MCP 获取元数据和专用下载地址,流式写入临时文件,同时校验 content type、大小和 SHA-256,再原子安装 local/base 并写 manifest。commit 会校验本地结构,携带 checkout 时的 version/revision/ETag,通过专用 HTTP 上传原始正文;完整正文不会成为 MCP tool 参数。
298
-
299
- ## 冲突处理
300
-
301
- 远端对 commit 返回 HTTP 409/412 时,CLI 不重试、不 force,也不会覆盖 worktree local。它会在以下目录保存冲突材料并返回非零:
302
-
303
- ```text
304
- .draftgo/conflicts/<pages|navigations|docs>/<id>/
305
- ├── conflict.json
306
- ├── base.<ext>
307
- ├── local.<ext>
308
- └── remote.<ext>
157
+ ├── conflicts/
158
+ ├── artifacts/
159
+ └── tmp/
309
160
  ```
310
161
 
311
- 处理流程:
162
+ 连接配置、契约缓存、worktree、冲突材料和截图都属于项目运行时数据并写入 `.gitignore`。`.draftgo/tmp/` 可由 `draftgo clean` 清理;需要用户查看的证据放在已注册的 `.draftgo/artifacts/` 下。
312
163
 
313
- 1. `draftgo conflict show <type> <id>` 定位三份材料和 worktree 文件。
314
- 2. 在 worktree 文件中人工或借助可靠的三方合并工具完成合并。
315
- 3. `draftgo conflict resolve <type> <id>` 校验 worktree,并把冲突时保存的 remote 版本设为新 base。
316
- 4. 重新运行 `draftgo check`、必要时 `draftgo verify`、`draftgo diff`,最后 `draftgo commit`。
164
+ ## Skill Reference
317
165
 
318
- ## map check 输出
166
+ Skill 只放稳定的领域知识、项目边界和操作规则;动态 operation schema 由 MCP 提供并缓存在项目运行时。Reference 不拆成更小文件,保留按任务路由、前端运行时、安全、自定义服务、checkout 和 MCP 契约所需的完整上下文,避免过度拆分损失效果。
319
167
 
320
- `draftgo map --output json` 返回:
168
+ ## 开发与测试
321
169
 
322
- ```json
323
- {
324
- "server": "https://draftgo.example",
325
- "overview": {},
326
- "resources": [],
327
- "checkouts": [],
328
- "legacy_cache": { "ignored": true, "detected": [] }
329
- }
170
+ ```bash
171
+ npm run validate:skill
172
+ npm test
330
173
  ```
331
174
 
332
- `draftgo check --output json` 返回结构化的本地、远端和工作区检查结果。它以声明的 charset(默认 UTF-8)严格解码 HTML,并在内存中检查内联 JavaScript,错误直接映射到原 HTML 行列,不生成 `.draftgo/tmp/syntax/*.js`。`--strict` 会把 warnings 也视为失败。默认 `check` 不访问远端;显式使用 `--remote` 时读取实时 metadata,并把 `committed_unrecorded` 等可恢复状态指向 `draftgo reconcile`。
333
-
334
- `draftgo verify` 是交付前统一入口。无参数时只运行快速本地 `check`;`--remote` 才联网,`--url` 才启动浏览器。浏览器检查默认使用 `--frame auto`,同时检查顶层页面和可见 iframe,因此 `--selector` 可匹配 `iframe.srcdoc` 中的业务 DOM。`--viewport mobile|desktop|both` 控制目标视口,截图默认关闭。
335
-
336
- `.draftgo/tmp/` 是统一临时区,CLI 和 AI 产生的可丢弃中间文件必须位于 `.draftgo/tmp/<owner>/<run-id>/`;AI 自建文件使用 `.draftgo/tmp/ai/<run-id>/`。`draftgo clean --dry-run` 会列出全部 tmp 文件和已注册 artifacts,`draftgo clean --yes` 负责回收并删除空运行目录。需要保留供用户查看的截图或报告应进入 `.draftgo/artifacts/`,而不是 tmp。
337
-
338
- ## Skill 与领域约定
339
-
340
- 安装到每个宿主的 DraftGo Skill 包含主 `SKILL.md`、`init` / `story` 子技能和按需 references。实时 API 契约以 MCP `api_search` / `api_describe` 为准;references 只保留 API 无法表达的领域知识和实践约束。
341
-
342
- 前端和自定义服务的关键约定仍然适用:
343
-
344
- - 壳层源码使用 React 19 + Vite 8 + Tailwind CSS 4;数据库页面和导航以 HTML 文档运行,可加载平台内置组件库,但不进入壳层的 TSX、ESM 或 npm 构建链。
345
- - 内置 UI、图标、Chat SDK、AIHub 结构化输出以及前端运行、交互和验收规则见 `resources/skill/references/`;CLI 和 Skill 不提供页面模板。
346
- - 自定义服务使用 Go `draftgo/sdk`,通过 `Register(app *sdk.App)` 注册 Route、事件和定时任务;管理权限、调用权限、并发和出站请求约束见 `resources/skill/references/custom-services.md`。
347
- - 自定义服务、数据、AIHub、权限和系统配置通过实时 MCP/API 操作,不从 `.draftgo/*/index.json` 推断远端状态。
348
-
349
- `draftgo update` 只刷新 CLI 和 Skill 资源,不覆盖项目的 `.draftgo/config.json`、worktree、冲突材料、Task、lessons 或 changelog。渲染 Skill 时,`{{SKILL_DIR}}` / `{{SKILL_SCRIPTS}}` 会替换为当前宿主目录;CLI 不改写项目的 `AGENTS.md` 或 `GEMINI.md`。
350
-
351
- ## 常用选项
352
-
353
- - `--project <dir>`:操作指定项目目录,默认当前目录。
354
- - `--output json`:为 map、check、checkout、commit、diff、conflicts、conflict、api 或 delete 输出 JSON。
355
- - `--type <type>`:限制 `map` 查询一种正文资源类型;支持 pages、nav/navigations、docs/articles 及其别名。
356
- - `--strict`:check/deploy/auto-push 将 warnings 视为失败。
357
- - `--remote`:让 check 按需对比 checkout 的远端版本和 hash;默认仍为快速离线检查。
358
- - `--force`:init 覆盖已有 Skill;checkout 显式覆盖已修改的本地正文。update 始终刷新目标 Skill。
359
- - `--purge`:uninstall 时同时删除整个 `.draftgo/` 运行时目录。
360
- - `--skip-update-check`:update 不访问 npm,直接用当前 CLI 刷新 Skill。
361
- - `--connect` / `--local-dev` / `--no-setup`:控制 init 安装 Skill 后的基座处理流程。
362
- - `--target <name,...>`:为 MCP setup/status 指定一个或多个宿主。
363
- - `--server <url>` / `--token <sat>`:非交互 connect;不传时安全提示输入。
364
- - `--mcp-url <url>`:为 connect 显式指定完整 MCP endpoint;标准 `/mcp` 可自动推导基础地址,自定义路径需同时传 `--server`。
365
- - `--allow-offline` / `--no-mcp-setup`:允许 connect 在 MCP 暂不可用时保存,或跳过宿主配置。
366
- - `--yes`:跳过支持该选项的交互确认。
367
- - `--ui auto|always|never`:控制 verify 的浏览器验证;默认 auto,只在提供 `--url` 时运行。
368
- - `--viewport mobile|desktop|both`:控制 verify 的目标视口;不传时使用 `--width/--height` 或 390x844。
369
- - `--frame auto|top|all|<iframe-selector>`:控制 verify 检查哪些 frame;默认检查顶层与可见 iframe。
370
- - `--resource <type:id>`:兼容入口使用;推荐直接写 `draftgo verify pages 42 --url ...`。
371
- - `--browser-path <file>`:verify 显式使用浏览器可执行文件;也可设置 `DRAFTGO_BROWSER_PATH`,否则自动查找系统浏览器和 Playwright 缓存。
372
- - `--token auto|never`:verify 默认读取 `.draftgo/config.json`,对与 `server` 同源的地址自动附加 `token=<SAT>`;配置无 SAT、跨源地址或 `never` 模式均不附加。
373
- - `--screenshot on-failure|always|never`:控制 UI 截图。
374
- - `--delivery local|preview|deploy`:控制 deploy 行为。
375
- - `--timeout <ms>`:控制 connect 或 MCP test 的远端请求超时。
376
-
377
- 设置 `DRAFTGO_NO_UPDATE_CHECK=1` 可关闭 npm 版本检查,适用于离线或 CI 环境。
378
-
379
- ## 许可证
175
+ 本地开发要求 Node.js `>=20.19`。浏览器依赖仅在显式视觉验收时使用;普通 `npm test` 不会启动浏览器。
380
176
 
381
- MIT
177
+ 许可证:MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draftgo-cli",
3
- "version": "3.0.55",
3
+ "version": "4.0.1",
4
4
  "description": "Install and manage the DraftGo skill across AI coding agents (Claude Code, Codex, Cursor, Windsurf, Antigravity, Copilot, Gemini, Kiro).",
5
5
  "bin": {
6
6
  "draftgo": "bin/draftgo.js"
@@ -45,13 +45,13 @@
45
45
  "lint": "node scripts/check-syntax.js",
46
46
  "validate:skill": "node scripts/validate-skill.js",
47
47
  "verify:package": "node scripts/verify-package.js",
48
- "test": "npm run lint && npm run validate:skill && npm run verify:package && npm run test:unit && npm run test:workflow && npm run test:changelog && npm run test:mcp && npm run test:worktree && npm run test:migration && npm run test:local && npm run test:e2e",
48
+ "test": "npm run lint && npm run validate:skill && npm run verify:package && npm run test:unit && npm run test:workflow && npm run test:worklog && npm run test:mcp && npm run test:worktree && npm run test:integration && npm run test:local && npm run test:e2e",
49
49
  "test:unit": "node tests/unit.js",
50
- "test:workflow": "node tests/workflow-upgrade.test.js",
51
- "test:changelog": "node tests/changelog.test.js",
50
+ "test:workflow": "node tests/workflow.test.js",
51
+ "test:worklog": "node tests/worklog.test.js",
52
52
  "test:mcp": "node tests/mcp.test.js",
53
53
  "test:worktree": "node tests/worktree.test.js",
54
- "test:migration": "node tests/migration.test.js",
54
+ "test:integration": "node tests/integration.test.js",
55
55
  "test:local": "node tests/local-runtime.js",
56
56
  "test:e2e": "node tests/e2e.js"
57
57
  },