draftgo-cli 4.0.1 → 4.0.22

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 (78) hide show
  1. package/README.md +87 -11
  2. package/package.json +9 -4
  3. package/resources/custom-service-sdk/ai.go +520 -0
  4. package/resources/custom-service-sdk/ai_test.go +156 -0
  5. package/resources/custom-service-sdk/billing.go +596 -0
  6. package/resources/custom-service-sdk/billing_test.go +150 -0
  7. package/resources/custom-service-sdk/go.mod +3 -0
  8. package/resources/custom-service-sdk/manifest.json +72 -0
  9. package/resources/custom-service-sdk/platform.go +360 -0
  10. package/resources/custom-service-sdk/platform_logger_test.go +24 -0
  11. package/resources/custom-service-sdk/registration_test.go +39 -0
  12. package/resources/custom-service-sdk/resources.go +246 -0
  13. package/resources/custom-service-sdk/resources_billing_test.go +115 -0
  14. package/resources/custom-service-sdk/resources_files_test.go +57 -0
  15. package/resources/custom-service-sdk/resources_scope_test.go +87 -0
  16. package/resources/custom-service-sdk/sdk.go +208 -0
  17. package/resources/skill/SKILL.md +36 -88
  18. package/resources/skill/init/SKILL.md +4 -4
  19. package/resources/skill/manifest.json +5 -1
  20. package/resources/skill/references/aihub.md +25 -2
  21. package/resources/skill/references/app-api.md +56 -6
  22. package/resources/skill/references/architecture.md +2 -2
  23. package/resources/skill/references/chat-sdk.md +4 -2
  24. package/resources/skill/references/checkout.md +17 -3
  25. package/resources/skill/references/custom-services.md +111 -46
  26. package/resources/skill/references/data.md +19 -4
  27. package/resources/skill/references/delivery.md +33 -0
  28. package/resources/skill/references/diagnostics.md +51 -0
  29. package/resources/skill/references/frontend.md +34 -46
  30. package/resources/skill/references/mcp.md +33 -5
  31. package/resources/skill/references/methods.md +189 -0
  32. package/resources/skill/references/modules.md +36 -8
  33. package/resources/skill/references/runtime.md +23 -1
  34. package/src/cli.js +24 -0
  35. package/src/commandRegistry.js +9 -1
  36. package/src/commands/api.js +21 -10
  37. package/src/commands/apiKey.js +34 -0
  38. package/src/commands/capabilities.js +93 -0
  39. package/src/commands/checkout.js +1 -1
  40. package/src/commands/commit.js +1 -1
  41. package/src/commands/components.js +550 -0
  42. package/src/commands/conflict.js +1 -1
  43. package/src/commands/connect.js +18 -8
  44. package/src/commands/customService.js +20 -4
  45. package/src/commands/dataRange.js +33 -0
  46. package/src/commands/delete.js +12 -1
  47. package/src/commands/diff.js +18 -2
  48. package/src/commands/grant.js +29 -0
  49. package/src/commands/group.js +38 -0
  50. package/src/commands/help.js +64 -20
  51. package/src/commands/init.js +3 -3
  52. package/src/commands/map.js +145 -17
  53. package/src/commands/mcp.js +2 -2
  54. package/src/commands/reconcile.js +1 -1
  55. package/src/commands/role.js +32 -0
  56. package/src/commands/space.js +41 -0
  57. package/src/commands/status.js +110 -7
  58. package/src/commands/update.js +23 -11
  59. package/src/commands/verify.js +75 -0
  60. package/src/commands/worklog.js +6 -2
  61. package/src/consoleEncoding.js +34 -0
  62. package/src/contractCompatibility.js +57 -0
  63. package/src/customServices.js +138 -18
  64. package/src/diffReport.js +106 -0
  65. package/src/index.js +2 -0
  66. package/src/localRuntime/compose.js +14 -17
  67. package/src/localRuntime/index.js +22 -23
  68. package/src/localRuntime/services.js +27 -36
  69. package/src/mcp/client.js +11 -2
  70. package/src/mcp/protocol.js +2 -2
  71. package/src/mcp/tools.js +14 -1
  72. package/src/platforms.js +9 -0
  73. package/src/projectConfig.js +6 -4
  74. package/src/releaseInstall.js +105 -0
  75. package/src/updateCheck.js +48 -28
  76. package/src/worklog.js +2 -1
  77. package/src/worktree/backend.js +1 -1
  78. package/src/worktree/index.js +7 -2
package/README.md CHANGED
@@ -9,6 +9,10 @@
9
9
  - MCP schema 是服务端实时契约。已知 operation 优先使用项目私有缓存;首次使用或 `registry_revision` 变化时 describe。schema 不写入 Skill 或聊天上下文。
10
10
  - 不同资源、operation 和 owner 的工作全部并发;同一资源的依赖步骤保持串行。
11
11
  - 每个任务开始记录到 `.draftgo/worklog.md`,验证和交付成功后再标记完成。
12
+ - 已知页面使用 `draftgo map --type pages --route <path>` 或 `--title <title>` 精确定位;只需范围和状态时使用 `--summary`,浏览列表时使用 `--limit`(默认 20)/`--cursor`,不默认全量 map。
13
+ - `--output json` 的 stdout 只包含 UTF-8 JSON;诊断和进度写入 stderr。大变更先用 `draftgo diff --stat` 或 `--summary`。
14
+
15
+ 跨板块任务先看[极简方法指南](resources/skill/references/methods.md):它按 AIHub、知识库/记忆、页面/内容、动态数据、自定义服务、MCP、运行诊断和交付验收给出“适用场景 + 最短正确命令链 + 失败定位 + 完成条件”。动态 operation 不写死;未知契约统一用 `draftgo api search`、`draftgo api describe`、`draftgo api call` 实时发现。
12
16
 
13
17
  ## 验收策略
14
18
 
@@ -39,12 +43,12 @@ draftgo verify --url http://localhost:3000/path --screenshot always --viewport b
39
43
  npm install -g draftgo-cli
40
44
  cd /path/to/project
41
45
  draftgo init
42
- draftgo connect --server https://draftgo.example --token "$DRAFTGO_SAT"
46
+ draftgo connect --server https://draftgo.example --api-key "$DRAFTGO_API_KEY"
43
47
  draftgo mcp setup
44
48
  draftgo mcp test
45
49
  ```
46
50
 
47
- `connect` 会验证 SAT、MCP initialize、tools/list 和关键工具调用,然后把连接写入项目私有的 `.draftgo/config.json`。宿主 MCP 配置只包含 `draftgo mcp serve`,不会保存 SAT。
51
+ `connect` 会验证当前用户的 DraftGo API Key、MCP initialize、tools/list 和关键工具调用,然后把连接写入项目私有的 `.draftgo/config.json`。宿主 MCP 配置只包含 `draftgo mcp serve`,不会保存 API Key。需要开发 space 资源时增加 `--scope-type space --space-id <id>`;平台组件和系统配置仍按 operation 契约使用 platform 上下文。
48
52
 
49
53
  本地底座:
50
54
 
@@ -69,14 +73,16 @@ draftgo list-targets
69
73
  draftgo connect [target...]
70
74
  ```
71
75
 
76
+ `draftgo status` 会通过只读 MCP/API 诊断显示服务连接健康状态、服务版本和当前用户 API Key 的 `platform`/`space` 上下文;`--output json` 适合读取 `connection.health`、`workspace_id` 与 `space_id`。
77
+
72
78
  ### 发现与正文
73
79
 
74
80
  ```text
75
- draftgo map [--type pages|nav|docs]
81
+ draftgo map [--type pages|nav|docs|custom-services] [--route <path>] [--title <title>] [--summary] [--limit <1-100>] [--cursor <opaque>] [--output json]
76
82
  draftgo checkout <pages|nav|docs|custom-services> <id...> [--force]
77
83
  draftgo check [custom-services <id...>] [--remote]
78
84
  draftgo verify [<type> <id...>] [visual flags]
79
- draftgo diff <type> <id>
85
+ draftgo diff <type> <id> [--stat|--summary] [--output json]
80
86
  draftgo commit <type> <id...>
81
87
  draftgo refresh <type> <id...>
82
88
  draftgo reconcile <type> <id...>
@@ -87,18 +93,48 @@ draftgo conflict resolve <type> <id>
87
93
 
88
94
  `checkout` 下载正文和经过 hash 校验的 base。`commit` 先并发完成所有目标的本地与远端 preflight,全部通过后再并发上传;任何 409/412 都保留 base/local/remote 冲突材料,不 force、不覆盖、不自动合并。
89
95
 
96
+ `--route`、`--title` 为精确匹配,同时给出时取交集。CLI 可用资源搜索缩小候选,但最终在本地做精确判定;服务端 `resource_search` 只接受通用 `query`,不能传 route/title。`map --summary` 不输出 project overview、资源列表或 hash。`diff --stat` 输出文件与增删行数,`--summary` 输出资源、版本和变更概要;只有不带这两个参数的 diff 才展开正文。
97
+
98
+ ### Page 组件库
99
+
100
+ ```bash
101
+ draftgo components search <query> --output json
102
+ draftgo components show <library/component> --output json
103
+ draftgo components expand --page <id> --instance <data-dg-instance>
104
+ draftgo verify pages <id>
105
+
106
+ # 开发组件:commit 保存草稿,publish 显式上线
107
+ draftgo components checkout <library/component>
108
+ draftgo components diff <library/component>
109
+ draftgo components verify <library/component>
110
+ draftgo components commit <library/component>
111
+ draftgo components publish <library/component>
112
+
113
+ # 库管理和标准 ZIP 迁移
114
+ draftgo components libraries list|show|create|update|delete
115
+ draftgo components import <archive.zip> --dry-run
116
+ draftgo components export <library> --file <archive.zip>
117
+ ```
118
+
119
+ `search` 和 `show` 始终读取当前 DraftGo 实例的组件目录,AI 不得按名称猜写 props/slots。Page 以真实根标签和 `data-dg-use="library/component"` 保存活引用,发布新 revision 后刷新自动升级。高度个性化时先 checkout Page,再用 `expand` 固化当前 props、slots、组件/库 CSS、公共资产和 mount 初始化;展开实例变成普通 HTML/CSS/JavaScript,不再随组件升级,仍需经过 `diff -> verify -> commit`。
120
+
90
121
  ### Custom service
91
122
 
92
- ```text
123
+ 最短开发闭环:
124
+
125
+ ```bash
126
+ # 先用 MCP 定位或创建服务并取得 ID
93
127
  draftgo checkout custom-services <id...>
94
- draftgo diff custom-services <id>
128
+ draftgo diff custom-services <id> --stat
95
129
  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...>
130
+ draftgo test custom-services <id> --source draft --handler route:POST:/path --input request.json
99
131
  ```
100
132
 
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 冲突仍直接失败。
133
+ 每个 worktree 只有 `service.go` `service.json` 是用户内容;Route/Event/Scheduled handler 仅由 `Register` 自动发现。CLI 另生成带 `DO NOT EDIT` 标记的 `go.mod/go.sum`、本地编译入口和 SDK 副本,供 gopls、`go build` 使用;它们会在 checkout 和 commit 时重建,且永不进入 diff、hash、归档、冲突材料或云端。第三方依赖只在源码顶部用 `//draftgo:require module@version` 固定。旧四文件 worktree 不受支持,请删除后用当前 CLI 重新 checkout。
134
+
135
+ `commit custom-services` 会自动完成提交、验证和发布,并输出明确的 published 提示;`validate`、`test`、`publish` 仍可作为单独的兼容入口。`test` 只运行 cloud draft,不调用线上版本;发布后如需再试运行,先修改并提交形成新草稿。默认拒绝外部副作用;外部调用用 `--side-effect-policy mock` 模拟,只有明确需要真实副作用时才组合 `--side-effect-policy live --test-write`。数据库等写操作也必须显式加 `--test-write`。
136
+
137
+ `--source` 支持 `draft`(默认)、`auto`、`published`。Selector 支持 `route:METHOD:/path`、`event:name`、`scheduled:name` 或 handler 名;`--input`、`--headers`、`--user` 都读取 UTF-8 JSON object。普通 SDK 调用继承已验证的 `platform` 或 `space` 上下文;可信服务可对单次操作显式使用 `ctx.Admin.*`,该提升会审计且不会泄漏到后续调用。余额扣款、权益、支付和订阅使用 `ctx.Billing` / `ctx.Admin.Billing`,精确签名查看 checkout 后只读的 `.draftgo-sdk/billing.go`。完整字段与规则见[自定义服务方法指南](resources/skill/references/custom-services.md)。
102
138
 
103
139
  ### MCP/API
104
140
 
@@ -112,9 +148,31 @@ draftgo api search <query>
112
148
  draftgo api describe <operation_id>
113
149
  draftgo api call <operation_id> --input <json-file>
114
150
  draftgo delete <operation_id> [id] [--params JSON]
151
+ draftgo capabilities list [--module <name>] [--type <resource>] [--method <method>]
152
+ draftgo capabilities search <query> [--risk <level>] [--permission <permission>]
153
+ draftgo capabilities show <operation_id>
154
+ draftgo capabilities audit --output json
115
155
  ```
116
156
 
117
- `api call` 对已缓存 operation 直接调用并携带 `registry_revision`。服务端返回 `CONTRACT_CHANGED` 时只 describe、更新缓存并重试一次。调用输入必须是 UTF-8 JSON object;输出包含 HTTP status、服务端 code 和 request ID。
157
+ `api call` 对已缓存 operation 直接调用并携带 `registry_revision`。服务端返回 `CONTRACT_CHANGED` 时重新 describe;只读或 operation 契约未变化时最多重试一次,危险 operation 自身契约变化时阻断调用并提示升级 CLI 后重新确认。调用输入必须是 UTF-8 JSON object;输出包含 HTTP status、服务端 code 和 request ID。
158
+
159
+ 权限快捷命令:
160
+
161
+ ```bash
162
+ draftgo role list
163
+ draftgo space list
164
+ draftgo space members list --input request.json
165
+ draftgo group members add --input request.json
166
+ draftgo grant create --input request.json
167
+ draftgo api-key status
168
+ draftgo api-key rotate
169
+ draftgo data-range list
170
+ ```
171
+
172
+ `role` 管理无作用域的 Role 模板;授权使用 `grant` 创建带 `platform` 或 `space` 范围的 AccessGrant。工作区成员关系不直接授予权限。资源归属由服务端持久化 ResourceOwnership 决定,DB 的 DataRange
173
+ 只在该范围内应用 `none`、`owner` 或 `all` 记录策略。交互式 CLI、MCP 和普通 HTTP API 均使用当前用户的
174
+ API Key,并始终按该用户的 AccessGrant 授权;API Key 不能创建或伪造服务身份。CI、定时任务和共享服务等
175
+ 无人值守自动化使用平台提供的独立服务凭据通道及服务主体 AccessGrant,不复用个人 API Key。
118
176
 
119
177
  ### 交付与记录
120
178
 
@@ -129,6 +187,8 @@ draftgo work show|list
129
187
  draftgo clean [--dry-run|--yes]
130
188
  ```
131
189
 
190
+ `draftgo work start <item>` 的文本输出会返回可直接传给后续命令的引用,例如 `Started work item #21 (2026-08-20#21)`。
191
+
132
192
  ## Worklog
133
193
 
134
194
  `.draftgo/worklog.md` 是任务、进度和完成证据的唯一记录。格式如下:
@@ -165,6 +225,8 @@ draftgo clean [--dry-run|--yes]
165
225
 
166
226
  Skill 只放稳定的领域知识、项目边界和操作规则;动态 operation schema 由 MCP 提供并缓存在项目运行时。Reference 不拆成更小文件,保留按任务路由、前端运行时、安全、自定义服务、checkout 和 MCP 契约所需的完整上下文,避免过度拆分损失效果。
167
227
 
228
+ 支持的 Skill target 包括 Claude Code、Cursor、Windsurf、Antigravity、Kiro、GitHub Copilot、Codex CLI、Gemini CLI 和 Pi。Pi 的项目级 Skill 安装到 `.agents/skills/draftgo/`,可被 Pi 按 Agent Skills 标准自动发现。
229
+
168
230
  ## 开发与测试
169
231
 
170
232
  ```bash
@@ -175,3 +237,17 @@ npm test
175
237
  本地开发要求 Node.js `>=20.19`。浏览器依赖仅在显式视觉验收时使用;普通 `npm test` 不会启动浏览器。
176
238
 
177
239
  许可证:MIT
240
+
241
+ ## Install without npm
242
+
243
+ DraftGo can be installed from the China download endpoint. The installer falls back to a GitHub mirror and the official GitHub Release when the primary endpoint is unavailable.
244
+
245
+ ```bash
246
+ # macOS / Linux
247
+ curl -fsSL https://draftgo.cn/draftgo-cli/install.sh | sh
248
+
249
+ # Windows PowerShell
250
+ irm https://draftgo.cn/draftgo-cli/install.ps1 | iex
251
+ ```
252
+
253
+ The download source can be overridden with `DRAFTGO_INSTALL_BASE_URL`, the GitHub Release mirror with `DRAFTGO_GITHUB_MIRROR`, and the version with `DRAFTGO_VERSION`. The CLI archive includes its npm dependencies but currently requires Node.js >=20.19.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "draftgo-cli",
3
- "version": "4.0.1",
4
- "description": "Install and manage the DraftGo skill across AI coding agents (Claude Code, Codex, Cursor, Windsurf, Antigravity, Copilot, Gemini, Kiro).",
3
+ "version": "4.0.22",
4
+ "description": "Install and manage the DraftGo skill across AI coding agents (Claude Code, Codex, Cursor, Windsurf, Antigravity, Copilot, Gemini, Kiro, Pi).",
5
5
  "bin": {
6
6
  "draftgo": "bin/draftgo.js"
7
7
  },
@@ -29,7 +29,8 @@
29
29
  "antigravity",
30
30
  "copilot",
31
31
  "gemini",
32
- "kiro"
32
+ "kiro",
33
+ "pi"
33
34
  ],
34
35
  "author": "draftgo <cabinai@163.com> (https://github.com/draftgo)",
35
36
  "license": "MIT",
@@ -44,9 +45,13 @@
44
45
  "scripts": {
45
46
  "lint": "node scripts/check-syntax.js",
46
47
  "validate:skill": "node scripts/validate-skill.js",
48
+ "sync:custom-service-sdk": "node scripts/sync-custom-service-sdk.js",
49
+ "build:release": "node scripts/build-release.js",
47
50
  "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:worklog && npm run test:mcp && npm run test:worktree && npm run test:integration && npm run test:local && npm run test:e2e",
51
+ "test": "npm run lint && npm run validate:skill && npm run verify:package && npm run test:unit && npm run test:components && npm run test:capabilities && 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
52
  "test:unit": "node tests/unit.js",
53
+ "test:components": "node --test tests/components.test.js",
54
+ "test:capabilities": "node --test tests/capabilities.test.js",
50
55
  "test:workflow": "node tests/workflow.test.js",
51
56
  "test:worklog": "node tests/worklog.test.js",
52
57
  "test:mcp": "node tests/mcp.test.js",