draftgo-cli 3.0.49 → 3.0.52

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/README.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # draftgo-cli
2
2
 
3
+ ## Workflow 2.0
4
+
5
+ `draftgo context` outputs schema `2.0` with separate `bundled_references`, `live_project`, `live_resources`, `live_apis`, `live_db_meta`, and `live_session` sections. It writes to stdout by default, uses current cloud data on every run, and does not create a persistent context cache. Frontend and custom-service tasks always retain complete live DB Meta.
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.
8
+
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.
10
+
3
11
  面向 AI 编码工具的 DraftGo 工作台 CLI:分发 DraftGo Skill,通过 MCP 发现和操作实时资源,并为页面、导航和文档提供可校验的 `checkout` / `commit` 工作流。
4
12
 
5
13
  DraftGo Next 壳层使用 React + Vite;数据库页面可按任务使用原生 Web 技术、Tailwind CSS 或平台内置组件库。CLI 仍提供 Docker 本地运行、项目检查和浏览器验证能力。
@@ -72,7 +80,7 @@ draftgo connect codex --server https://draftgo.example --token "$DRAFTGO_SAT"
72
80
 
73
81
  `--server` 始终表示 DraftGo 基础地址。直接连接 MCP endpoint 时使用 `--mcp-url https://draftgo.example/mcp`;CLI 会显式保存 `mcp_url`,若未同时传 `--server`,则从标准 `/mcp` 后缀推导基础地址,避免猜测已有 base URL 的语义。
74
82
 
75
- `connect` 会先验证 SAT、MCP `initialize`、`tools/list` 和关键 `tools/call`,成功后写入项目私有配置 `.draftgo/config.json`,并尝试为指定或自动检测到的宿主执行 MCP setup。它不会 pull 页面、导航、文档或任何其他业务资源。
83
+ `connect` 会先验证 SAT、MCP `initialize`、`tools/list` 和关键 `tools/call`,成功后写入项目私有配置 `.draftgo/config.json`,并尝试为指定或自动检测到的宿主执行 MCP setup。`init` / `connect` 不会预建 Task、lessons、changelog、worktree、conflicts 等运行时内容;这些文件和目录只在对应能力首次使用时按需创建。它不会 pull 页面、导航、文档或任何其他业务资源。
76
84
 
77
85
  远端暂不可用时,只有显式传入 `--allow-offline` 才会保存配置;恢复后运行 `draftgo mcp test`。使用 `--no-mcp-setup` 可跳过宿主配置。
78
86
 
@@ -170,8 +178,7 @@ draftgo context --task frontend --output json
170
178
  draftgo checkout pages 42 43
171
179
  # 独立资源可并行编辑;同一资源只由一个 Agent 修改
172
180
  draftgo check
173
- draftgo check --remote # 交付前按需对比远端版本/hash
174
- draftgo verify-ui http://localhost:5173 # UI 变更时
181
+ draftgo verify pages 42 --remote --url http://localhost:5173/example
175
182
  draftgo diff pages 42
176
183
  draftgo diff pages 43
177
184
  draftgo commit pages 42 43
@@ -205,13 +212,14 @@ draftgo changelog add "完成文档管理系统及角色权限"
205
212
  | `draftgo map` | 并行读取 pages、navigations、docs/articles 元数据,再叠加本地 checkout 状态;`--type` 可限制一种类型。 |
206
213
  | `draftgo checkout <pages|nav|docs> <id...>` | 下载完整正文和 base,校验 hash 后原子落盘;`--force` 可显式覆盖已修改的本地正文。 |
207
214
  | `draftgo check` | 默认只检查本地 checkout;`--remote` 额外对比 local/base/manifest/remote 的版本和 hash。 |
215
+ | `draftgo verify [<type> <id...>]` | 统一执行静态检查;`--remote` 增加远端比较,`--url` 增加 iframe-aware 浏览器验证。 |
208
216
  | `draftgo diff <pages|nav|docs> <id>` | 显示 checkout base 与当前本地正文的差异。 |
209
217
  | `draftgo commit <pages|nav|docs> <id...>` | 本地校验后,通过专用 HTTP 上传完整正文并更新 base/manifest。 |
210
218
  | `draftgo reconcile <pages|nav|docs> <id...>` | 仅当 local 与经校验的 remote 字节一致时,安全修复落后的 base/manifest 元数据。 |
211
219
  | `draftgo conflicts` | 列出未解决冲突;存在冲突时返回非零。`--all` 包括已解决记录。 |
212
220
  | `draftgo conflict show <type> <id>` | 显示冲突的 base/local/remote/worktree 路径。 |
213
221
  | `draftgo conflict resolve <type> <id>` | 确认 worktree 已合并,把保留的 remote 设为新 base;随后重新 check、diff、commit。 |
214
- | `draftgo verify-ui <url>` | 使用 Playwright 执行确定性的浏览器 smoke check。 |
222
+ | `draftgo verify-ui <url>` | `verify --url <url> --ui always` 的弃用兼容入口。 |
215
223
 
216
224
  `pages`、`page`,`nav`、`navigation`、`navigations`,以及 `docs`、`doc`、`article`、`articles`、`docs/articles` 都会规范化到三个支持的正文类型。
217
225
 
@@ -308,7 +316,7 @@ checkout 会通过 MCP 获取元数据和专用下载地址,流式写入临时
308
316
  1. `draftgo conflict show <type> <id>` 定位三份材料和 worktree 文件。
309
317
  2. 在 worktree 文件中人工或借助可靠的三方合并工具完成合并。
310
318
  3. `draftgo conflict resolve <type> <id>` 校验 worktree,并把冲突时保存的 remote 版本设为新 base。
311
- 4. 重新运行 `draftgo check`、必要时 `verify-ui`、`draftgo diff`,最后 `draftgo commit`。
319
+ 4. 重新运行 `draftgo check`、必要时 `draftgo verify`、`draftgo diff`,最后 `draftgo commit`。
312
320
 
313
321
  ## map 与 check 输出
314
322
 
@@ -324,7 +332,11 @@ checkout 会通过 MCP 获取元数据和专用下载地址,流式写入临时
324
332
  }
325
333
  ```
326
334
 
327
- `draftgo check --output json` 返回 `{ map, errors, warnings, warningDetails, remote, remote_error, legacy_cache_ignored }`。`--strict` 会把 warnings 也视为失败。默认 `check` 不访问远端;显式使用 `--remote` 时读取每个 checkout 的实时 metadata,并把 `committed_unrecorded` 等可恢复状态指向 `draftgo reconcile`。它始终不会读取旧全量资源索引。
335
+ `draftgo check --output json` 返回结构化的本地、远端和工作区检查结果。它以声明的 charset(默认 UTF-8)严格解码 HTML,并在内存中检查内联 JavaScript,错误直接映射到原 HTML 行列,不生成 `.draftgo/tmp/syntax/*.js`。`--strict` 会把 warnings 也视为失败。默认 `check` 不访问远端;显式使用 `--remote` 时读取实时 metadata,并把 `committed_unrecorded` 等可恢复状态指向 `draftgo reconcile`。
336
+
337
+ `draftgo verify` 是交付前统一入口。无参数时只运行快速本地 `check`;`--remote` 才联网,`--url` 才启动浏览器。浏览器检查默认使用 `--frame auto`,同时检查顶层页面和可见 iframe,因此 `--selector` 可匹配 `iframe.srcdoc` 中的业务 DOM。`--viewport mobile|desktop|both` 控制目标视口,截图默认关闭。
338
+
339
+ `.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。
328
340
 
329
341
  ## Skill 与领域约定
330
342
 
@@ -356,10 +368,12 @@ checkout 会通过 MCP 获取元数据和专用下载地址,流式写入临时
356
368
  - `--mcp-url <url>`:为 connect 显式指定完整 MCP endpoint;标准 `/mcp` 可自动推导基础地址,自定义路径需同时传 `--server`。
357
369
  - `--allow-offline` / `--no-mcp-setup`:允许 connect 在 MCP 暂不可用时保存,或跳过宿主配置。
358
370
  - `--yes`:跳过支持该选项的交互确认。
359
- - `--mobile-check auto|always|never`:控制 `verify-ui` 是否执行。
360
- - `--resource <type:id>`:verify-ui 打开 URL 前对比本地 checkout 与远端已提交版本,并明确报告实际验证来源。
361
- - `--browser-path <file>`:verify-ui 显式使用浏览器可执行文件;也可设置 `DRAFTGO_BROWSER_PATH`,否则自动查找系统浏览器和 Playwright 缓存。
362
- - `--token auto|never`:`verify-ui` 默认读取 `.draftgo/config.json`,对与 `server` 同源的地址自动附加 `token=<SAT>`;配置无 SAT、跨源地址或 `never` 模式均不附加。
371
+ - `--ui auto|always|never`:控制 verify 的浏览器验证;默认 auto,只在提供 `--url` 时运行。
372
+ - `--viewport mobile|desktop|both`:控制 verify 的目标视口;不传时使用 `--width/--height` 390x844。
373
+ - `--frame auto|top|all|<iframe-selector>`:控制 verify 检查哪些 frame;默认检查顶层与可见 iframe。
374
+ - `--resource <type:id>`:兼容入口使用;推荐直接写 `draftgo verify pages 42 --url ...`。
375
+ - `--browser-path <file>`:verify 显式使用浏览器可执行文件;也可设置 `DRAFTGO_BROWSER_PATH`,否则自动查找系统浏览器和 Playwright 缓存。
376
+ - `--token auto|never`:verify 默认读取 `.draftgo/config.json`,对与 `server` 同源的地址自动附加 `token=<SAT>`;配置无 SAT、跨源地址或 `never` 模式均不附加。
363
377
  - `--screenshot on-failure|always|never`:控制 UI 截图。
364
378
  - `--delivery local|preview|deploy`:控制 deploy 行为。
365
379
  - `--timeout <ms>`:控制 connect、MCP test 或 context 的远端请求超时。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "draftgo-cli",
3
- "version": "3.0.49",
3
+ "version": "3.0.52",
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,9 +45,10 @@
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:context && 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:context && 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",
49
49
  "test:unit": "node tests/unit.js",
50
50
  "test:context": "node tests/context.test.js",
51
+ "test:workflow": "node tests/workflow-upgrade.test.js",
51
52
  "test:changelog": "node tests/changelog.test.js",
52
53
  "test:mcp": "node tests/mcp.test.js",
53
54
  "test:worktree": "node tests/worktree.test.js",
@@ -57,11 +58,11 @@
57
58
  },
58
59
  "dependencies": {
59
60
  "@grpc/grpc-js": "1.14.1",
61
+ "adm-zip": "0.5.16",
60
62
  "parse5": "6.0.1",
61
63
  "playwright-core": "1.61.1"
62
64
  },
63
65
  "directories": {
64
66
  "test": "tests"
65
- },
66
- "devDependencies": {}
67
+ }
67
68
  }
@@ -3,6 +3,15 @@ name: draftgo
3
3
  description: Use this skill to inspect, develop, debug, or deliver a DraftGo application. Use draftgo context for task-specific references and live MCP discovery, checkout/commit for complete page, navigation, and document bodies, and write the changelog only after all verification and delivery succeed.
4
4
  ---
5
5
 
6
+ ## Workflow 2.0 authority
7
+
8
+ - Treat pages, navigations, docs/articles, and custom services as checkout resources. Never save complete MCP responses, duplicate source snapshots, temporary Go modules, SDK stubs, executables, or build directories by hand.
9
+ - `context` schema 2.0 separates `bundled_references` from `live_project`, `live_resources`, `live_apis`, and complete `live_db_meta`. It is stdout-only by default and has no persistent or delta cache.
10
+ - Custom-service flow: `context --task custom-service` -> `checkout custom-services` -> edit four files -> `commit` cloud draft -> `test` in the server Runner -> `check --remote` -> `publish` -> `refresh`. CLI and admin UI edit the same cloud draft.
11
+ - Do not create Task overhead for a small, single-point change. For cross-module, cross-session, or multi-Agent work, create or resume `.draftgo/Task/[YYYY-MM-DD]<slug>/Task.md`. It is the only task state: preserve both the user's original request and the clarified executable requirement, assign one owner per item/resource, and check an item only with verification evidence. Changelog remains the final delivery record, not a task tracker.
12
+ - Normal delivery uses `draftgo verify`; add `--remote` only when remote comparison is required and `--url` only for browser evidence. UI verification is iframe-aware and defaults to one viewport with no screenshot. Only explicit visual acceptance or regression diagnosis may pass `--viewport both` or `--screenshot on-failure|always`.
13
+ - `.draftgo/tmp/` is entirely disposable. CLI data uses `.draftgo/tmp/<command>/<run-id>/`; AI-created scratch files use `.draftgo/tmp/ai/<run-id>/`. User-facing evidence belongs under registered `.draftgo/artifacts/`. Use `draftgo clean --dry-run` before `draftgo clean --yes`.
14
+
6
15
  # DraftGo 开发助手
7
16
 
8
17
  ## 核心边界
@@ -50,8 +59,8 @@ context 会校验本地 Reference,返回逐字章节、来源、实时项目/
50
59
 
51
60
  1. MCP 定位 pages/nav/docs 并读取 metadata。
52
61
  2. 批量 checkout;在 `.draftgo/worktree/` 按唯一 owner 编辑。
53
- 3. 主 Agent 回读全部修改,统一运行 `draftgo check`;交付前需要核对远端版本时运行 `draftgo check --remote`。
54
- 4. 用 `draftgo diff <type> <id>` 检查 base/local 差异,再按类型运行 `draftgo commit ...`。页面布局或交互变化时在 commit 后用 `draftgo verify-ui <url> --resource <type:id>` 验证远端已提交版本。
62
+ 3. 主 Agent 回读全部修改,编辑过程中统一运行一次快速 `draftgo check`。交付前运行 `draftgo verify <type> <id...>`;需要远端证据时加 `--remote`,页面布局或交互变化时加对应 `--url`。
63
+ 4. 用 `draftgo diff <type> <id>` 检查 base/local 差异,再按类型运行 `draftgo commit ...`。commit 后需要验证远端页面时运行 `draftgo verify <type> <id> --remote --url <url>`。
55
64
  5. 409/412 时停止自动提交,保留 base/local/remote 冲突材料;不得 force、覆盖或自动合并。
56
65
 
57
66
  完整 manifest、流式传输、哈希和冲突规则见 `references/checkout.md`。
@@ -84,10 +93,10 @@ draftgo changelog add "<完成结果>"
84
93
  | 范围 | 最低证据 |
85
94
  |---|---|
86
95
  | MCP 连接 | 失败时用 `draftgo mcp test` 核对 initialize、tools/list 和关键工具;输出不含 SAT |
87
- | 页面、导航、文档 | checkout manifest、`draftgo check`、必要的 `verify-ui`、diff、commit 返回版本与哈希 |
96
+ | 页面、导航、文档 | checkout manifest、`draftgo check`、交付前 `draftgo verify`、diff、commit 返回版本与哈希 |
88
97
  | 结构化资源 | search/describe 契约、call 结果与回读的权限、字段、错误和副作用 |
89
98
  | 自定义服务 | 动态 Route describe、无副作用健康请求或目标行为结果,以及管理员调用审计 |
90
- | 冲突 | `.draftgo/conflicts/` 的 base/local/remote;解决后重新 check、必要的 verify-ui 和 commit |
99
+ | 冲突 | `.draftgo/conflicts/` 的 base/local/remote;解决后重新 check、必要的 verify 和 commit |
91
100
  | 本地底座 | `draftgo local status`、日志和相关 local 测试 |
92
101
 
93
102
  `draftgo deploy`、`auto-push` 和兼容 `push pages|nav|docs` 只能沿用当前 check/commit 语义,不能恢复旧的全量 push。主 Agent 最终明确区分 Skill 约束、MCP 实时状态和 checkout 正文证据。
@@ -21,6 +21,8 @@ description: Install or refresh the DraftGo skill, connect a project to a DraftG
21
21
 
22
22
  draftgo init 只负责 Skill 安装;draftgo connect 负责保存并验证 server/SAT;draftgo mcp setup 负责宿主配置。不要混用职责。
23
23
 
24
+ 初始化后 `.draftgo/` 只保留已经写入的 `config.json`。不要预建 Task、lessons、changelog、worktree、conflicts 或其他占位文件和目录;首次实际使用对应能力时再创建。
25
+
24
26
  ## SAT 与配置
25
27
 
26
28
  - 交互式连接应使用隐藏输入;不要把 SAT 写入宿主配置、Skill 文件、命令行示例或日志。
@@ -33,7 +35,7 @@ draftgo init 只负责 Skill 安装;draftgo connect 负责保存并验证 serv
33
35
  - 宿主配置和诊断:draftgo mcp setup/status/test,详见 ../references/mcp.md。
34
36
  - 开发上下文:先运行匹配领域的 `draftgo context --task <task> --output json`;context 后仍可按需直接调用 MCP。
35
37
  - 远端资源补充定位:MCP project_overview、resource_search、resource_list。
36
- - 正文编辑:自主设计并批量 checkout,不同资源按唯一 owner 并行修改,由主 Agent 统一运行 check/必要的 verify-ui、diff 和 commit。
38
+ - 正文编辑:自主设计并批量 checkout,不同资源按唯一 owner 并行修改,由主 Agent 统一运行 check、交付前 verify、diff 和 commit。
37
39
  - 结构化资源:直接使用 MCP 的 api_search、api_describe、api_call;不 checkout、不生成本地镜像。
38
40
  - 完成日志:只有整个任务统一验证且全部 commit/MCP 交付成功后,由主 Agent 执行一次 `draftgo changelog add "<完成结果>"`;验证、冲突或交付失败时不得写入。
39
41
  - 管理本地基座:draftgo local start|stop|logs|status;local-dev、local up/down 仍可用。
@@ -2,7 +2,7 @@
2
2
  "schema_version": "1.0",
3
3
  "id": "draftgo",
4
4
  "name": "DraftGo 开发助手",
5
- "version": "3.0.49",
5
+ "version": "3.0.52",
6
6
  "entry": "SKILL.md",
7
7
  "description": "以 context 聚合编排、Skill/reference 原文、MCP 实时发现、长正文 checkout/commit、统一验证和完成日志为边界的 DraftGo 工作流。",
8
8
  "license": "MIT",
@@ -4,6 +4,12 @@ read_when: 编辑 pages、navigation 或 docs 正文时 · 查看 checkout manif
4
4
 
5
5
  # Checkout / Commit
6
6
 
7
+ ## Workflow 2.0 scope
8
+
9
+ The checkout set includes `pages`, `navigations`, `docs/articles`, and `custom_services`. A custom-service checkout is a directory containing exactly `service.go`, `go.mod`, `go.sum`, and `service.json`, plus one complete `.base` directory. `draftgo commit custom-services <id>` saves a cloud draft; it does not publish. Use `draftgo test custom-services <id>` for server Runner validation/execution and `draftgo publish custom-services <id>` for explicit publication. DB Meta remains a live MCP/API resource and is never checked out.
10
+
11
+ `draftgo refresh <type> <id...>` is a safe checkout shortcut. It updates only a clean local worktree; local changes stop it. A successful commit keeps current local files and one base only. Cloud version storage is the sole history source.
12
+
7
13
  > 根 `SKILL.md` 在 Skill 触发时会自动加载。使用本文件前,先完成根 Skill 的“强制预读:Reference 优先于 MCP”任务路由。本文件只说明长正文的传输、版本和冲突规则,不能替代页面、前端、运行时或安全资料。
8
14
 
9
15
  ## 适用范围
@@ -87,12 +93,12 @@ base 已变化时必须拒绝覆盖。
87
93
  ## Commit 流程
88
94
 
89
95
  1. 读取 manifest 指向的 worktree 文件,计算当前字节数和 SHA-256;未变化时返回 `unchanged`。
90
- 2. 按 content_type 执行本地结构检查;页面布局或交互有变化时另外运行 `draftgo verify-ui`。
96
+ 2. 按 content_type 执行本地结构和内联脚本检查;页面布局或交互有变化时运行 `draftgo verify <type> <id> --url <url>`。
91
97
  3. 通过专用 HTTP 流式上传原始文件,携带 `If-Match`、base version/revision、content_type、长度和 SHA-256。
92
98
  4. 完整正文不得作为 MCP tool 参数发送。
93
99
  5. 底座确认 hash 和新版本后,CLI 原子更新 `.base` 与 manifest。返回 hash 不一致时不得推进基线。
94
100
 
95
- 推荐编辑顺序:主 Agent 执行一次 context -> MCP 按需补充定位 -> Agent 自主设计并批量 checkout -> 独立资源按唯一 owner 并行编辑 -> 主 Agent 汇总回读 -> 统一运行一次 `draftgo check` -> `draftgo diff` -> commit -> 页面变化时用 `draftgo verify-ui <url> --resource <type:id>` 验证远端已提交版本。遇到本地正文已经等于远端、但 base/manifest 落后时,先用 `draftgo check --remote` 确认 `committed_unrecorded`,再运行 `draftgo reconcile`;不要手改 manifest。
101
+ 推荐编辑顺序:主 Agent 执行一次 context -> MCP 按需补充定位 -> Agent 自主设计并批量 checkout -> 独立资源按唯一 owner 并行编辑 -> 主 Agent 汇总回读 -> 统一运行一次 `draftgo check` -> `draftgo diff` -> commit -> 页面变化时用 `draftgo verify <type> <id> --remote --url <url>` 验证远端已提交版本。遇到本地正文已经等于远端、但 base/manifest 落后时,先用 `draftgo check --remote` 确认 `committed_unrecorded`,再运行 `draftgo reconcile`;不要手改 manifest。
96
102
 
97
103
  单个 commit 成功不自动写 changelog。只有整个任务统一验证且全部 commit/MCP 交付成功后,主 Agent 才执行一次 `draftgo changelog add "<完成结果>"`。任何检查失败、409/412 或交付失败都不得写入。
98
104
 
@@ -111,7 +117,7 @@ base 已变化时必须拒绝覆盖。
111
117
  - `base` 是 checkout 时的内容;`local` 是发生冲突时的本地快照;`remote` 是重新下载并校验的当前远端内容。
112
118
  - `conflict.json` 记录三份路径、版本、ETag 和哈希,不嵌入完整正文。
113
119
  - Agent 或用户在 worktree local 文件中完成合并;不要手写 HTML 自动合并器,也不要改动保存的三份证据。
114
- - 合并完成后运行 `draftgo check`、必要时 `draftgo verify-ui`,再执行 `draftgo conflict resolve <type> <id>`。
120
+ - 合并完成后运行 `draftgo check`、必要时 `draftgo verify`,再执行 `draftgo conflict resolve <type> <id>`。
115
121
  - resolve 校验 worktree 与 remote,采用 remote 版本作为新的 base,但保留合并后的 worktree;随后运行
116
122
  `draftgo diff` 并 `draftgo commit`。
117
123
 
@@ -1,4 +1,5 @@
1
1
  ---
2
+
2
3
  read_when: 编写、修改、调试或评审自定义服务时;使用服务 SDK、路由、事件、定时任务或服务依赖时
3
4
  ---
4
5
 
@@ -68,7 +68,7 @@ version: 2.0.0
68
68
  - 表格、代码和其他超宽内容应在合理边界内可访问,不能让核心操作因溢出而不可达。
69
69
  - 弹窗和抽屉在目标视口内完整可用,长内容有明确滚动边界。
70
70
 
71
- 需要浏览器证据时按页面受众和现有断点运行 `draftgo verify-ui <url> --mobile-check auto`;不要机械遍历与任务无关的视口。
71
+ 需要浏览器证据时按页面受众和现有断点运行 `draftgo verify <type> <id> --url <url>`;只有验收确实覆盖多端时加 `--viewport both`,不要机械遍历与任务无关的视口。业务 HTML 位于 iframe 时默认 `--frame auto` 会检查顶层和可见 iframe,`--selector` 可直接定位业务 DOM。
72
72
 
73
73
  ### 导航与系统页边界(强制)
74
74
 
package/src/cli.js CHANGED
@@ -15,6 +15,9 @@ const VALUE_FLAGS = new Set([
15
15
  'browser-path',
16
16
  'resource',
17
17
  'mobile-check',
18
+ 'ui',
19
+ 'frame',
20
+ 'viewport',
18
21
  'screenshot',
19
22
  'selector',
20
23
  'width',
@@ -29,6 +32,30 @@ const VALUE_FLAGS = new Set([
29
32
  'input',
30
33
  'type',
31
34
  'task',
35
+ 'title',
36
+ 'description',
37
+ 'item-id',
38
+ 'id',
39
+ 'owner',
40
+ 'original',
41
+ 'original-requirement',
42
+ 'clarified',
43
+ 'clarified-requirement',
44
+ 'expected-effect',
45
+ 'effect',
46
+ 'scope',
47
+ 'out-of-scope',
48
+ 'content',
49
+ 'acceptance',
50
+ 'module-logic',
51
+ 'user-journey',
52
+ 'item',
53
+ 'date',
54
+ 'handler',
55
+ 'headers',
56
+ 'user',
57
+ 'side-effect-policy',
58
+ 'evidence',
32
59
  ]);
33
60
 
34
61
  function parse(argv) {
@@ -36,24 +63,24 @@ function parse(argv) {
36
63
  const out = { command: null, positional: [], flags: {}, errors: [] };
37
64
  while (args.length) {
38
65
  const a = args.shift();
39
- if (a === '--') { out.positional.push(...args); break; }
66
+ if (a === '--') {
67
+ out.positional.push(...args);
68
+ break;
69
+ }
40
70
  if (a.startsWith('--')) {
41
71
  const raw = a.slice(2);
42
72
  const eq = raw.indexOf('=');
43
73
  if (eq >= 0) {
44
74
  const key = raw.slice(0, eq);
45
75
  const value = raw.slice(eq + 1);
46
- if (VALUE_FLAGS.has(key) && !value) {
47
- out.errors.push(`选项 --${key} 需要一个值。`);
48
- } else {
49
- out.flags[key] = value;
50
- }
76
+ if (VALUE_FLAGS.has(key) && !value) out.errors.push(`Option --${key} requires a value.`);
77
+ else out.flags[key] = value;
51
78
  } else {
52
79
  const next = args[0];
53
80
  if (VALUE_FLAGS.has(raw)) {
54
81
  // A declared value flag must never silently become boolean true.
55
82
  if (next === undefined || next === '--' || next.startsWith('--')) {
56
- out.errors.push(`选项 --${raw} 需要一个值。`);
83
+ out.errors.push(`Option --${raw} requires a value.`);
57
84
  } else {
58
85
  out.flags[raw] = next;
59
86
  args.shift();
@@ -63,8 +90,7 @@ function parse(argv) {
63
90
  }
64
91
  }
65
92
  } else if (a.startsWith('-') && a.length > 1) {
66
- const key = a.slice(1);
67
- out.flags[key] = true;
93
+ out.flags[a.slice(1)] = true;
68
94
  } else if (!out.command) {
69
95
  out.command = a;
70
96
  } else {
@@ -9,12 +9,19 @@ const commands = [
9
9
  { name: 'status', run: (dir) => require('./commands/status')(dir) },
10
10
  { name: 'context', run: (dir, args, flags) => require('./commands/context')(dir, args, flags) },
11
11
  { name: 'changelog', run: (dir, args, flags) => require('./commands/changelog')(dir, args, flags) },
12
+ { name: 'task', run: (dir, args, flags) => require('./commands/task')(dir, args, flags) },
13
+ { name: 'clean', run: (dir, args, flags) => require('./commands/clean')(dir, args, flags) },
12
14
  { name: 'map', run: (dir, _args, flags) => require('./commands/map')(dir, flags) },
13
- { name: 'check', run: (dir, _args, flags) => require('./commands/check')(dir, flags) },
14
- { name: 'verify-ui', aliases: ['verifyui'], run: (dir, args, flags) => require('./commands/verifyUi')(dir, args, flags) },
15
+ { name: 'check', run: (dir, args, flags) => require('./commands/check')(dir, args, flags) },
16
+ { name: 'verify', run: (dir, args, flags) => require('./commands/verify')(dir, args, flags) },
17
+ { name: 'verify-ui', aliases: ['verifyui'], run: (dir, args, flags) => require('./commands/verifyUiCompat')(dir, args, flags) },
15
18
  { name: 'mcp', run: (dir, args, flags) => require('./commands/mcp')(dir, args, flags) },
16
19
  { name: 'checkout', run: (dir, args, flags) => require('./commands/checkout')(dir, args, flags) },
20
+ { name: 'refresh', run: (dir, args, flags) => require('./commands/checkout')(dir, args, flags) },
17
21
  { name: 'commit', run: (dir, args, flags) => require('./commands/commit')(dir, args, flags) },
22
+ { name: 'validate', run: (dir, args, flags) => require('./commands/customService').validate(dir, args, flags) },
23
+ { name: 'test', run: (dir, args, flags) => require('./commands/customService').test(dir, args, flags) },
24
+ { name: 'publish', run: (dir, args, flags) => require('./commands/customService').publish(dir, args, flags) },
18
25
  { name: 'reconcile', run: (dir, args, flags) => require('./commands/reconcile')(dir, args, flags) },
19
26
  { name: 'diff', run: (dir, args, flags) => require('./commands/diff')(dir, args, flags) },
20
27
  { name: 'conflicts', run: (dir, args, flags) => require('./commands/conflicts')(dir, args, flags) },
@@ -5,19 +5,75 @@ const path = require('path');
5
5
  const log = require('../logger');
6
6
  const { analyzeProject } = require('../projectMap');
7
7
  const { inspectRemoteCheckouts } = require('../worktree/status');
8
+ const customServices = require('../customServices');
9
+ const { workspaceHealth } = require('../workspaceHealth');
8
10
 
9
11
  function legacyCacheDetected(projectDir) {
10
12
  return ['pages', 'navigations', 'docs', 'db_meta', 'custom_scripts', 'aihub', 'roles', 'users', 'system_config']
11
13
  .some((name) => fs.existsSync(path.join(projectDir, '.draftgo', name, 'index.json')));
12
14
  }
13
15
 
14
- async function check(projectDir, flags = {}) {
15
- const result = analyzeProject(projectDir);
16
+ async function check(projectDir, positional = [], flags = {}) {
17
+ if (!Array.isArray(positional)) {
18
+ flags = positional || {};
19
+ positional = [];
20
+ }
21
+ const [requestedType, ...requestedIds] = positional;
22
+ if (requestedType && !customServicesCommand().isServiceType(requestedType)) {
23
+ log.err('Usage: draftgo check [custom-services <id...>] [--remote]');
24
+ return 1;
25
+ }
26
+ if (requestedType && !requestedIds.length) {
27
+ log.err('Usage: draftgo check custom-services <id...> [--remote]');
28
+ return 1;
29
+ }
30
+ const resourceKeys = flags.resourceKeys || null;
31
+ const result = analyzeProject(projectDir, { resourceKeys });
32
+ if (resourceKeys) {
33
+ const manifestKeys = new Set(Object.keys(result.map.checkouts.reduce((entries, entry) => {
34
+ entries[`${entry.resource_type}:${entry.resource_id}`] = true;
35
+ return entries;
36
+ }, {})));
37
+ for (const key of resourceKeys) if (!manifestKeys.has(key)) result.errors.push(`${key}: resource is not checked out`);
38
+ }
39
+ const hygiene = workspaceHealth(projectDir);
40
+ hygiene.warnings.forEach((warning) => result.warningDetails.push({ code: warning.code, confidence: 'high', message: `${warning.path}${warning.size ? ` (${warning.size} bytes)` : ''}` }));
41
+ hygiene.warnings.forEach((warning) => result.warnings.push(`${warning.code}: ${warning.path}`));
42
+ const serviceManifest = customServices.loadManifest(projectDir);
43
+ const customServiceChecks = [];
44
+ const requested = new Set(requestedIds.map(String));
45
+ const serviceEntries = Object.values(serviceManifest.entries)
46
+ .filter((entry) => !resourceKeys && (!requestedType || requested.has(String(entry.resource_id))));
47
+ if (requestedType) {
48
+ for (const id of requested) {
49
+ if (!serviceEntries.some((entry) => String(entry.resource_id) === id)) {
50
+ result.errors.push(`custom_services ${id}: resource is not checked out`);
51
+ }
52
+ }
53
+ }
54
+ for (const entry of serviceEntries) {
55
+ try {
56
+ const state = customServices.diff(projectDir, entry.resource_id);
57
+ customServiceChecks.push({ resource_type: 'custom_services', resource_id: entry.resource_id, state: state.changed ? 'local_modified' : 'clean_local', files: state.files });
58
+ } catch (error) {
59
+ result.errors.push(`custom_services ${entry.resource_id}: ${error.message}`);
60
+ }
61
+ }
16
62
  let remote = null;
17
63
  let remoteError = null;
18
64
  if (flags.remote) {
19
65
  try {
20
- remote = await inspectRemoteCheckouts(projectDir);
66
+ const [contentRemote, serviceRemote] = await Promise.all([
67
+ inspectRemoteCheckouts(projectDir, resourceKeys ? {
68
+ entries: result.map.checkouts.filter((entry) => resourceKeys.includes(`${entry.resource_type}:${entry.resource_id}`)),
69
+ } : {}),
70
+ resourceKeys
71
+ ? Promise.resolve([])
72
+ : customServices.inspectRemote(projectDir, requestedType ? { ids: [...requested] } : {}),
73
+ ]);
74
+ remote = requestedType
75
+ ? serviceRemote.filter((entry) => requested.has(String(entry.resource_id)))
76
+ : [...contentRemote, ...serviceRemote];
21
77
  for (const entry of remote) {
22
78
  if (!['clean', 'clean_local', 'local_modified'].includes(entry.state)) {
23
79
  const detail = `${entry.resource_type} ${entry.resource_id}: ${entry.state}`
@@ -32,16 +88,26 @@ async function check(projectDir, flags = {}) {
32
88
  result.errors.push(`Remote checkout check failed: ${error.message}`);
33
89
  }
34
90
  }
35
- const output = { ...result, remote, remote_error: remoteError };
91
+ const output = {
92
+ content_validation: { map: result.map, errors: result.errors, warnings: result.warnings, warning_details: result.warningDetails, custom_services: customServiceChecks },
93
+ remote_validation: { resources: remote, error: remoteError },
94
+ workspace_hygiene: hygiene,
95
+ };
36
96
  if (flags.output === 'json') {
37
97
  console.log(JSON.stringify({ ...output, legacy_cache_ignored: legacyCacheDetected(projectDir) }, null, 2));
38
98
  return result.errors.length || (flags.strict && result.warnings.length) ? 1 : 0;
39
99
  }
40
100
 
41
101
  log.title('draftgo check');
42
- log.info(`Checked-out pages: ${result.map.pages.length}`);
43
- log.info(`Checked-out navigations: ${result.map.navigations.length}`);
44
- log.info(`Checked-out docs: ${result.map.docs.length}`);
102
+ const selectedCount = (type, entries) => resourceKeys
103
+ ? entries.filter((entry) => resourceKeys.includes(`${type}:${entry.resource_id}`)).length
104
+ : entries.length;
105
+ log.info(`Checked-out pages: ${selectedCount('pages', result.map.pages)}`);
106
+ log.info(`Checked-out navigations: ${selectedCount('navigations', result.map.navigations)}`);
107
+ log.info(`Checked-out docs: ${selectedCount('docs', result.map.docs)}`);
108
+ log.info(`Checked-out custom services: ${customServiceChecks.length}`);
109
+ log.info(`Workspace: ${hygiene.managed_files} managed, ${hygiene.unknown_files} unknown, ${hygiene.temporary_files} temporary, ${hygiene.artifact_files} artifact file(s)`);
110
+ log.info(`Workspace size: ${hygiene.total_bytes} bytes; reclaimable: ${hygiene.reclaimable_bytes} bytes`);
45
111
  if (remote) log.info(`Remote checkout comparison: ${remote.length} resource(s)`);
46
112
  for (const message of result.errors) log.err(message);
47
113
  for (const detail of result.warningDetails) log.warn(`[${detail.code}/${detail.confidence}] ${detail.message}`);
@@ -52,4 +118,8 @@ async function check(projectDir, flags = {}) {
52
118
  return 0;
53
119
  }
54
120
 
121
+ function customServicesCommand() {
122
+ return require('./customService');
123
+ }
124
+
55
125
  module.exports = check;
@@ -9,6 +9,9 @@ async function checkout(projectDir, positional, flags = {}) {
9
9
  log.err('Usage: draftgo checkout <pages|nav|docs> <id...>');
10
10
  return 1;
11
11
  }
12
+ if (require('./customService').isServiceType(resourceType)) {
13
+ return require('./customService').checkout(projectDir, ids, flags);
14
+ }
12
15
  const results = await checkoutResources(projectDir, resourceType, ids, { force: Boolean(flags.force) });
13
16
  if (flags.output === 'json') console.log(JSON.stringify(results, null, 2));
14
17
  else for (const entry of results) log.ok(`Checked out ${entry.resource_type} ${entry.resource_id} -> ${entry.local_path}`);
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const log = require('../logger');
6
+ const runtime = require('../runtimeFiles');
7
+
8
+ const MANAGED_PREFIXES = ['tmp/', 'artifacts/ui/', 'artifacts/api/', 'artifacts/custom-services/'];
9
+ function fileSize(file) { try { const stat = fs.statSync(file); return stat.isFile() ? stat.size : 0; } catch { return 0; } }
10
+ function olderThan(value) {
11
+ if (value == null || value === '') return 0;
12
+ const match = String(value).match(/^(\d+)([dhm])$/i); if (!match) throw new Error('--older-than must use <number>d, <number>h, or <number>m.');
13
+ const unit = { d: 86400000, h: 3600000, m: 60000 }[match[2].toLowerCase()]; return Number(match[1]) * unit;
14
+ }
15
+ function plan(projectDir, flags = {}) {
16
+ const root = runtime.draftgoRoot(projectDir); const manifest = runtime.load(projectDir); const age = olderThan(flags['older-than']); const now = Date.now();
17
+ const types = new Set(String(flags.type || '').split(',').map((item) => item.trim()).filter(Boolean)); const candidates = [];
18
+ for (const entry of manifest.entries) {
19
+ if (!entry.cleanable || (types.size && !types.has(entry.type))) continue;
20
+ const relative = String(entry.path).replace(/\\/g, '/');
21
+ if (!MANAGED_PREFIXES.some((prefix) => relative.startsWith(prefix))) continue;
22
+ const absolute = path.resolve(root, relative); if (!runtime.inside(root, absolute) || !fs.existsSync(absolute)) continue;
23
+ const stat = fs.statSync(absolute); if (age && now - stat.mtimeMs < age) continue;
24
+ candidates.push({ ...entry, absolute, size: stat.isFile() ? stat.size : 0, reason: 'runtime_manifest' });
25
+ }
26
+ const tmp = path.resolve(root, 'tmp');
27
+ if (fs.existsSync(tmp) && runtime.inside(root, tmp) && (!types.size || types.has('tmp') || types.has('ai'))) {
28
+ const visitTmp = (current) => {
29
+ for (const child of fs.readdirSync(current, { withFileTypes: true })) {
30
+ const absolute = path.join(current, child.name);
31
+ if (child.isDirectory()) visitTmp(absolute);
32
+ else if (child.isFile() && !candidates.some((entry) => entry.absolute === absolute)) {
33
+ const stat = fs.statSync(absolute);
34
+ if (!age || now - stat.mtimeMs >= age) candidates.push({
35
+ path: path.relative(root, absolute).replace(/\\/g, '/'), absolute,
36
+ type: path.relative(tmp, absolute).replace(/\\/g, '/').startsWith('ai/') ? 'ai' : 'tmp',
37
+ size: stat.size, reason: 'temporary_area',
38
+ });
39
+ }
40
+ }
41
+ };
42
+ visitTmp(tmp);
43
+ }
44
+ if (flags['all-artifacts']) {
45
+ for (const prefix of MANAGED_PREFIXES.filter((item) => item.startsWith('artifacts/'))) {
46
+ const directory = path.resolve(root, prefix); if (!runtime.inside(root, directory) || !fs.existsSync(directory)) continue;
47
+ const visit = (current) => { for (const child of fs.readdirSync(current, { withFileTypes: true })) { const absolute = path.join(current, child.name); if (child.isDirectory()) visit(absolute); else if (child.isFile() && !candidates.some((entry) => entry.absolute === absolute)) candidates.push({ path: path.relative(root, absolute).replace(/\\/g, '/'), absolute, type: 'artifact', size: fileSize(absolute), reason: 'all_artifacts' }); } };
48
+ visit(directory);
49
+ }
50
+ }
51
+ return { entries: candidates, count: candidates.length, bytes: candidates.reduce((sum, entry) => sum + entry.size, 0) };
52
+ }
53
+ async function clean(projectDir, _positional, flags = {}) {
54
+ const result = plan(projectDir, flags); const output = { count: result.count, bytes: result.bytes, entries: result.entries.map(({ absolute, ...entry }) => entry) };
55
+ if (flags.output === 'json') console.log(JSON.stringify({ ...output, deleted: Boolean(flags.yes && !flags['dry-run']) }, null, 2));
56
+ else { log.title('draftgo clean'); result.entries.forEach((entry) => log.info(`${entry.path} (${entry.size} bytes)`)); log.info(`Reclaimable: ${result.bytes} bytes in ${result.count} file(s).`); }
57
+ if (!flags.yes || flags['dry-run']) { if (!flags.output) log.dim('Run with --yes to delete this plan.'); return 0; }
58
+ const manifest = runtime.load(projectDir); const removed = new Set();
59
+ for (const entry of result.entries) { if (!runtime.inside(runtime.draftgoRoot(projectDir), entry.absolute)) throw new Error('Clean target escaped .draftgo.'); fs.rmSync(entry.absolute, { force: true }); removed.add(entry.path); }
60
+ const tmp = path.join(runtime.draftgoRoot(projectDir), 'tmp');
61
+ if (fs.existsSync(tmp)) {
62
+ const removeEmpty = (directory) => {
63
+ for (const child of fs.readdirSync(directory, { withFileTypes: true })) if (child.isDirectory()) removeEmpty(path.join(directory, child.name));
64
+ if (directory !== tmp && fs.readdirSync(directory).length === 0) fs.rmdirSync(directory);
65
+ };
66
+ removeEmpty(tmp);
67
+ }
68
+ manifest.entries = manifest.entries.filter((entry) => !removed.has(entry.path)); runtime.save(projectDir, manifest);
69
+ if (!flags.output) log.ok(`Deleted ${result.count} managed file(s).`); return 0;
70
+ }
71
+ clean.plan = plan;
72
+ module.exports = clean;
@@ -9,6 +9,9 @@ async function commit(projectDir, positional, flags = {}) {
9
9
  log.err('Usage: draftgo commit <pages|nav|docs> <id...>');
10
10
  return 1;
11
11
  }
12
+ if (require('./customService').isServiceType(resourceType)) {
13
+ return require('./customService').commit(projectDir, ids, flags);
14
+ }
12
15
  const streamed = [];
13
16
  const printStatus = (result) => {
14
17
  streamed.push(result);
@@ -18,9 +18,11 @@ async function conflict(projectDir, positional, flags = {}) {
18
18
  log.err('Usage: draftgo conflict <show|resolve> <pages|nav|docs> <id>');
19
19
  return 1;
20
20
  }
21
- const record = action === 'show'
22
- ? showConflict(projectDir, resourceType, resourceId)
23
- : await resolveConflict(projectDir, resourceType, resourceId);
21
+ const custom = require('./customService').isServiceType(resourceType);
22
+ const services = custom ? require('../customServices') : null;
23
+ const record = custom
24
+ ? (action === 'show' ? services.showConflict(projectDir, resourceId) : services.resolveConflict(projectDir, resourceId))
25
+ : (action === 'show' ? showConflict(projectDir, resourceType, resourceId) : await resolveConflict(projectDir, resourceType, resourceId));
24
26
  if (flags.output === 'json') console.log(JSON.stringify(record, null, 2));
25
27
  else printRecord(record);
26
28
  if (action === 'resolve') log.info('The remote revision is now the base; run check, diff, and commit the merged worktree file.');
@@ -2,9 +2,10 @@
2
2
 
3
3
  const log = require('../logger');
4
4
  const { listConflicts } = require('../worktree');
5
+ const { serviceConflicts } = require('../customServices');
5
6
 
6
7
  function conflicts(projectDir, _positional, flags = {}) {
7
- const records = listConflicts(projectDir, { all: Boolean(flags.all) });
8
+ const records = [...listConflicts(projectDir, { all: Boolean(flags.all) }), ...serviceConflicts(projectDir, { all: Boolean(flags.all) })];
8
9
  if (flags.output === 'json') console.log(JSON.stringify(records, null, 2));
9
10
  else if (!records.length) log.ok('No unresolved DraftGo conflicts.');
10
11
  else for (const record of records) {
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const log = require('../logger');
4
- const { collectContext, TASK_PROFILES } = require('../context');
4
+ const { collectContext, compactContext, TASK_PROFILES } = require('../context');
5
5
  const { parseTimeout } = require('../timeout');
6
6
 
7
7
  function printUsage() {
@@ -17,7 +17,7 @@ async function contextCommand(projectDir, positional = [], flags = {}) {
17
17
  const result = await collectContext(projectDir, flags.task, {
18
18
  timeoutMs: parseTimeout(flags.timeout),
19
19
  });
20
- console.log(JSON.stringify(result, null, 2));
20
+ console.log(JSON.stringify(flags.compact ? compactContext(result) : result, null, 2));
21
21
  return 0;
22
22
  }
23
23