draftgo-cli 4.0.1 → 4.0.23
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 +87 -11
- package/package.json +9 -4
- package/resources/custom-service-sdk/ai.go +520 -0
- package/resources/custom-service-sdk/ai_test.go +156 -0
- package/resources/custom-service-sdk/auth_test.go +56 -0
- package/resources/custom-service-sdk/billing.go +596 -0
- package/resources/custom-service-sdk/billing_test.go +150 -0
- package/resources/custom-service-sdk/go.mod +3 -0
- package/resources/custom-service-sdk/manifest.json +77 -0
- package/resources/custom-service-sdk/platform.go +345 -0
- package/resources/custom-service-sdk/platform_logger_test.go +24 -0
- package/resources/custom-service-sdk/registration_test.go +39 -0
- package/resources/custom-service-sdk/resources.go +246 -0
- package/resources/custom-service-sdk/resources_billing_test.go +115 -0
- package/resources/custom-service-sdk/resources_files_test.go +57 -0
- package/resources/custom-service-sdk/resources_scope_test.go +87 -0
- package/resources/custom-service-sdk/sdk.go +208 -0
- package/resources/skill/SKILL.md +36 -88
- package/resources/skill/init/SKILL.md +4 -4
- package/resources/skill/manifest.json +5 -1
- package/resources/skill/references/aihub.md +25 -2
- package/resources/skill/references/app-api.md +56 -6
- package/resources/skill/references/architecture.md +2 -2
- package/resources/skill/references/chat-sdk.md +4 -2
- package/resources/skill/references/checkout.md +17 -3
- package/resources/skill/references/custom-services.md +112 -47
- package/resources/skill/references/data.md +19 -4
- package/resources/skill/references/delivery.md +33 -0
- package/resources/skill/references/diagnostics.md +51 -0
- package/resources/skill/references/frontend.md +34 -46
- package/resources/skill/references/mcp.md +33 -5
- package/resources/skill/references/methods.md +189 -0
- package/resources/skill/references/modules.md +37 -9
- package/resources/skill/references/runtime.md +23 -1
- package/src/cli.js +24 -0
- package/src/commandRegistry.js +9 -1
- package/src/commands/api.js +21 -10
- package/src/commands/apiKey.js +34 -0
- package/src/commands/capabilities.js +93 -0
- package/src/commands/checkout.js +1 -1
- package/src/commands/commit.js +1 -1
- package/src/commands/components.js +550 -0
- package/src/commands/conflict.js +1 -1
- package/src/commands/connect.js +18 -8
- package/src/commands/customService.js +20 -4
- package/src/commands/dataRange.js +33 -0
- package/src/commands/delete.js +12 -1
- package/src/commands/diff.js +18 -2
- package/src/commands/grant.js +29 -0
- package/src/commands/group.js +38 -0
- package/src/commands/help.js +64 -20
- package/src/commands/init.js +3 -3
- package/src/commands/map.js +145 -17
- package/src/commands/mcp.js +2 -2
- package/src/commands/reconcile.js +1 -1
- package/src/commands/role.js +32 -0
- package/src/commands/space.js +41 -0
- package/src/commands/status.js +110 -7
- package/src/commands/update.js +23 -11
- package/src/commands/verify.js +75 -0
- package/src/commands/worklog.js +6 -2
- package/src/consoleEncoding.js +34 -0
- package/src/contractCompatibility.js +57 -0
- package/src/customServices.js +138 -18
- package/src/diffReport.js +106 -0
- package/src/index.js +2 -0
- package/src/localRuntime/compose.js +14 -17
- package/src/localRuntime/index.js +22 -23
- package/src/localRuntime/services.js +27 -36
- package/src/mcp/client.js +11 -2
- package/src/mcp/protocol.js +22 -2
- package/src/mcp/tools.js +14 -1
- package/src/platforms.js +9 -0
- package/src/projectConfig.js +6 -4
- package/src/releaseInstall.js +105 -0
- package/src/updateCheck.js +48 -28
- package/src/worklog.js +2 -1
- package/src/worktree/backend.js +1 -1
- package/src/worktree/index.js +7 -2
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// Package sdk is the public contract for DraftGo Go custom services.
|
|
2
|
+
//
|
|
3
|
+
// A service implements Register and calls App.Route, App.On and App.Schedule.
|
|
4
|
+
// The isolated script runner invokes Register once at publish time to discover
|
|
5
|
+
// handlers, then invokes the selected Handler for each execution.
|
|
6
|
+
package sdk
|
|
7
|
+
|
|
8
|
+
import (
|
|
9
|
+
"context"
|
|
10
|
+
"fmt"
|
|
11
|
+
"net/http"
|
|
12
|
+
"strings"
|
|
13
|
+
"sync"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
// Handler is a user supplied custom-service function.
|
|
17
|
+
type Handler func(*Context) (any, error)
|
|
18
|
+
|
|
19
|
+
// Registration is an immutable description of one platform trigger.
|
|
20
|
+
type Registration struct {
|
|
21
|
+
Kind string `json:"kind"`
|
|
22
|
+
Method string `json:"method,omitempty"`
|
|
23
|
+
Path string `json:"path,omitempty"`
|
|
24
|
+
Event string `json:"event,omitempty"`
|
|
25
|
+
Cron string `json:"cron,omitempty"`
|
|
26
|
+
Name string `json:"name,omitempty"`
|
|
27
|
+
Handler Handler `json:"-"`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// App is supplied to Register. It is safe to inspect registrations after
|
|
31
|
+
// Register returns; registration itself is intentionally limited to startup.
|
|
32
|
+
type App struct {
|
|
33
|
+
mu sync.RWMutex
|
|
34
|
+
registrations []Registration
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// NewApp creates the registration collector used by a script runner.
|
|
38
|
+
func NewApp() *App { return &App{} }
|
|
39
|
+
|
|
40
|
+
// Route registers an HTTP endpoint. Path is relative to the custom-service
|
|
41
|
+
// mount point and must start with '/'.
|
|
42
|
+
func (app *App) Route(method, path string, handler Handler) {
|
|
43
|
+
method, path = strings.ToUpper(strings.TrimSpace(method)), strings.TrimSpace(path)
|
|
44
|
+
if method == "" || path == "" || !strings.HasPrefix(path, "/") || handler == nil {
|
|
45
|
+
panic("sdk.Route requires method, absolute path and handler")
|
|
46
|
+
}
|
|
47
|
+
trimmed := strings.Trim(path, "/")
|
|
48
|
+
if trimmed == "" {
|
|
49
|
+
path = "/"
|
|
50
|
+
} else {
|
|
51
|
+
path = "/" + trimmed
|
|
52
|
+
}
|
|
53
|
+
app.add(Registration{Kind: "route", Method: method, Path: path, Handler: handler})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// On registers a named DraftGo event handler.
|
|
57
|
+
func (app *App) On(event string, handler Handler) {
|
|
58
|
+
event = strings.TrimSpace(event)
|
|
59
|
+
if event == "" || handler == nil {
|
|
60
|
+
panic("sdk.On requires event and handler")
|
|
61
|
+
}
|
|
62
|
+
app.add(Registration{Kind: "event", Event: event, Handler: handler})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Schedule registers a five-field cron expression or a DraftGo interval
|
|
66
|
+
// expression (for example "interval:5m").
|
|
67
|
+
func (app *App) Schedule(cron string, handler Handler) {
|
|
68
|
+
cron = strings.TrimSpace(cron)
|
|
69
|
+
if cron == "" || handler == nil {
|
|
70
|
+
panic("sdk.Schedule requires cron and handler")
|
|
71
|
+
}
|
|
72
|
+
app.add(Registration{Kind: "scheduled", Cron: cron, Handler: handler})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
func (app *App) add(registration Registration) {
|
|
76
|
+
app.mu.Lock()
|
|
77
|
+
defer app.mu.Unlock()
|
|
78
|
+
for _, existing := range app.registrations {
|
|
79
|
+
if registration.Kind == "route" && existing.Kind == "route" && existing.Method == registration.Method && existing.Path == registration.Path {
|
|
80
|
+
panic(fmt.Sprintf("duplicate route %s %s", registration.Method, registration.Path))
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Function names are not a stable Go runtime API. A deterministic ID based
|
|
84
|
+
// on registration order is therefore persisted in the published manifest.
|
|
85
|
+
registration.Name = fmt.Sprintf("%s-%d", registration.Kind, len(app.registrations)+1)
|
|
86
|
+
app.registrations = append(app.registrations, registration)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Registrations returns a copy, so callers cannot mutate the published
|
|
90
|
+
// registration set.
|
|
91
|
+
func (app *App) Registrations() []Registration {
|
|
92
|
+
app.mu.RLock()
|
|
93
|
+
defer app.mu.RUnlock()
|
|
94
|
+
result := make([]Registration, len(app.registrations))
|
|
95
|
+
copy(result, app.registrations)
|
|
96
|
+
return result
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Context is passed to a handler. Input and User are JSON-compatible values
|
|
100
|
+
// supplied by DraftGo; platform resource methods will be added by the runner
|
|
101
|
+
// RPC client rather than by exposing database handles to scripts.
|
|
102
|
+
type Context struct {
|
|
103
|
+
Input map[string]any `json:"input"`
|
|
104
|
+
User map[string]any `json:"user,omitempty"`
|
|
105
|
+
Headers http.Header `json:"headers,omitempty"`
|
|
106
|
+
Platform bool `json:"platform"`
|
|
107
|
+
WorkspaceID int64 `json:"workspace_id,omitempty"`
|
|
108
|
+
SpaceID int64 `json:"space_id,omitempty"`
|
|
109
|
+
Principal ScopePrincipal `json:"principal"`
|
|
110
|
+
|
|
111
|
+
DB Database `json:"-"`
|
|
112
|
+
Users Users `json:"-"`
|
|
113
|
+
Auth Auth `json:"-"`
|
|
114
|
+
Notify Notifier `json:"-"`
|
|
115
|
+
HTTP HTTPClient `json:"-"`
|
|
116
|
+
Cache Cache `json:"-"`
|
|
117
|
+
Config Config `json:"-"`
|
|
118
|
+
AIHub AIHub `json:"-"`
|
|
119
|
+
Knowledge Knowledge `json:"-"`
|
|
120
|
+
Memory Memory `json:"-"`
|
|
121
|
+
Files FileStore `json:"-"`
|
|
122
|
+
Scope ScopeAPI `json:"-"`
|
|
123
|
+
Billing BillingAPI `json:"-"`
|
|
124
|
+
// Admin groups explicitly elevated operations for trusted custom services.
|
|
125
|
+
// Elevation applies to one RPC call, is audited, and never exposes credentials.
|
|
126
|
+
Admin Admin `json:"-"`
|
|
127
|
+
Log *Logger `json:"-"`
|
|
128
|
+
|
|
129
|
+
context context.Context
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// NewContext constructs the platform facade used by the isolated runner. The
|
|
133
|
+
// client is intentionally a narrow RPC interface rather than a database or
|
|
134
|
+
// HTTP-server handle.
|
|
135
|
+
func NewContext(draftgo context.Context, input, user map[string]any, headers http.Header, client Client) *Context {
|
|
136
|
+
return NewContextWithResource(draftgo, input, user, headers, client, ResourceContext{}, ScopePrincipal{})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// NewContextWithResource constructs a handler context with persisted resource
|
|
140
|
+
// ownership and the service principal supplied by DraftGo. Custom services
|
|
141
|
+
// cannot override these values through Input or request headers.
|
|
142
|
+
func NewContextWithResource(draftgo context.Context, input, user map[string]any, headers http.Header, client Client, resource ResourceContext, principal ScopePrincipal) *Context {
|
|
143
|
+
if draftgo == nil {
|
|
144
|
+
draftgo = context.Background()
|
|
145
|
+
}
|
|
146
|
+
if input == nil {
|
|
147
|
+
input = map[string]any{}
|
|
148
|
+
}
|
|
149
|
+
platform := platformClient{client: client, context: draftgo}
|
|
150
|
+
adminPlatform := platformClient{client: client, context: draftgo, admin: true}
|
|
151
|
+
return &Context{
|
|
152
|
+
Input: input, User: user, Headers: headers, context: draftgo,
|
|
153
|
+
Platform: resource.ScopeType == ScopePlatform, WorkspaceID: resource.WorkspaceID, SpaceID: resource.SpaceID, Principal: principal,
|
|
154
|
+
DB: dbClient{platform}, Users: usersClient{platform}, Auth: authClient{platformClient: platform, user: user}, Notify: notifierClient{platform},
|
|
155
|
+
HTTP: httpClient{platform}, Cache: cacheClient{platform}, Config: configClient{platform}, AIHub: aiHubClient{platform},
|
|
156
|
+
Knowledge: knowledgeClient{platform}, Memory: memoryClient{platform}, Files: fileStoreClient{platform}, Scope: scopeClient{platform}, Billing: billingClient{platform},
|
|
157
|
+
Admin: Admin{
|
|
158
|
+
DB: dbClient{adminPlatform}, Users: usersClient{adminPlatform}, Auth: authClient{platformClient: adminPlatform, user: user}, Notify: notifierClient{adminPlatform},
|
|
159
|
+
HTTP: httpClient{adminPlatform}, Cache: cacheClient{adminPlatform}, Config: configClient{adminPlatform}, AIHub: aiHubClient{adminPlatform},
|
|
160
|
+
Knowledge: knowledgeClient{adminPlatform}, Memory: memoryClient{adminPlatform},
|
|
161
|
+
Files: fileStoreClient{adminPlatform}, Scope: scopeClient{adminPlatform}, Billing: billingClient{adminPlatform},
|
|
162
|
+
},
|
|
163
|
+
Log: &Logger{},
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Admin exposes explicitly elevated platform capabilities to trusted custom
|
|
168
|
+
// services. The runtime preserves the service subject, scopes elevation to one
|
|
169
|
+
// audited RPC call, and never exposes platform credentials.
|
|
170
|
+
type Admin struct {
|
|
171
|
+
DB Database
|
|
172
|
+
Users Users
|
|
173
|
+
Auth Auth
|
|
174
|
+
Notify Notifier
|
|
175
|
+
HTTP HTTPClient
|
|
176
|
+
Cache Cache
|
|
177
|
+
Config Config
|
|
178
|
+
AIHub AIHub
|
|
179
|
+
Knowledge Knowledge
|
|
180
|
+
Memory Memory
|
|
181
|
+
Files FileStore
|
|
182
|
+
Scope ScopeAPI
|
|
183
|
+
Billing BillingAPI
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Context returns the invocation deadline/cancellation context supplied by
|
|
187
|
+
// DraftGo. Pass it to SDK calls that accept a context.Context.
|
|
188
|
+
func (draftgo *Context) Context() context.Context {
|
|
189
|
+
if draftgo == nil || draftgo.context == nil {
|
|
190
|
+
return context.Background()
|
|
191
|
+
}
|
|
192
|
+
return draftgo.context
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Response allows handlers to explicitly control an HTTP response.
|
|
196
|
+
type Response struct {
|
|
197
|
+
Body any `json:"body"`
|
|
198
|
+
StatusCode int `json:"status_code"`
|
|
199
|
+
Headers http.Header `json:"headers,omitempty"`
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Respond creates a response result. A status of zero defaults to 200.
|
|
203
|
+
func (draftgo *Context) Respond(body any, status int, headers http.Header) Response {
|
|
204
|
+
if status == 0 {
|
|
205
|
+
status = http.StatusOK
|
|
206
|
+
}
|
|
207
|
+
return Response{Body: body, StatusCode: status, Headers: headers}
|
|
208
|
+
}
|
package/resources/skill/SKILL.md
CHANGED
|
@@ -1,107 +1,55 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: draftgo
|
|
3
|
-
description: Use this skill to inspect, develop, debug, or deliver a DraftGo application. Read task-specific references
|
|
3
|
+
description: Use this skill to inspect, develop, debug, or deliver a DraftGo application. Read only the task-specific references, locate long-content resources precisely, and use checkout/commit with a project worklog.
|
|
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
|
-
- The root Skill loads automatically. Before acting, read the smallest relevant Reference set from the task-routing table, then use MCP only for live project evidence.
|
|
10
|
-
- Custom-service flow: read `references/custom-services.md`, locate and checkout the service, edit four files, then commit and validate the cloud draft. Run a server test or publish only when the task requires it. CLI and admin UI edit the same cloud draft.
|
|
11
|
-
- At task start, run `draftgo work start "<item>"`. Add independent items with `draftgo work add`; mark them active with `start-item` and complete only after verification and delivery. `.draftgo/worklog.md` is the only task and completion record.
|
|
12
|
-
- Normal delivery runs `draftgo verify` once; it already includes the local checks. Never start browser verification or create screenshots unless the user explicitly requests visual acceptance. For explicit visual acceptance, capture and inspect a desktop screenshot first with `--url <url> --screenshot always`; use `--ui always` only when the user also requests interaction or DOM verification, and add mobile/multi-viewport checks only when requested.
|
|
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
|
-
|
|
15
6
|
# DraftGo 开发助手
|
|
16
7
|
|
|
17
|
-
##
|
|
8
|
+
## 开始前
|
|
18
9
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
10
|
+
- 任务开始即运行 `draftgo work start "<事项>"`;记录 CLI 返回的工作项引用。独立事项用 `draftgo work add`,仅在验证和交付成功后运行 `draftgo work complete <ref> --note "<证据>"`。
|
|
11
|
+
- 根 Skill 会在触发时自动加载;先读取下表中最少必要的 Reference,再用 MCP 查询当前项目。不要预先读取所有 Reference,也不要把动态 operation schema 写入 Skill 或聊天上下文。
|
|
12
|
+
- pages、navigations、docs/articles 与 custom services 的完整正文只能通过 `draftgo checkout`、worktree、`draftgo diff`、`draftgo verify` 和 `draftgo commit` 处理;MCP 只用于定位、元数据和结构化资源。不要把完整正文、响应快照、临时 Go 模块、SDK 副本或构建目录写入聊天上下文或手工归档。
|
|
13
|
+
- 已知页面 route 或标题时,用 `draftgo map --type pages --route <path>` 或 `--title <title>` 精确定位;两个筛选条件取交集。只需范围或状态时加 `--summary`;需要浏览时使用 `--limit`(默认 20)和后续 `--cursor`,绝不默认全量枚举。
|
|
14
|
+
- `--output json` 的 stdout 是单一 UTF-8 JSON;诊断和进度走 stderr。不要依赖终端截断来控制上下文。
|
|
15
|
+
- 正常交付只运行 `draftgo verify`。默认跳过 UI;只有用户明确要求视觉验收时才使用截图,要求交互或 DOM 验证时才使用 `--ui always`。
|
|
25
16
|
|
|
26
|
-
|
|
17
|
+
不要用 MCP 摘要代替完整正文,也不要把 Skill 中列出的 `/assets/` 能力声称为当前服务器全部文件。CLI 不提供页面模板;页面根据任务、受众、现有产品语言和可用资源设计。
|
|
27
18
|
|
|
28
|
-
|
|
19
|
+
## 任务路由
|
|
29
20
|
|
|
30
|
-
| 任务 |
|
|
21
|
+
| 任务 | 先读 |
|
|
31
22
|
|---|---|
|
|
32
|
-
| 页面、导航、交互或 UI | `references/frontend.md`;涉及 iframe、路由、认证或全局层加读 `runtime.md` / `app-api.md
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
页面需求不因出现“页面”二字就默认新建或 checkout。Agent 结合用户意图、现有 route、页面职责和入口自主判断:修改已有页面时定位唯一资源后 checkout;确需独立新页面时先通过 MCP 实时 API 创建并取得 ID,再 checkout 正文。证据足以判断时直接推进;多个候选会导致不同产品结果时再向用户澄清。
|
|
43
|
-
|
|
44
|
-
## 所有权与执行
|
|
45
|
-
|
|
46
|
-
- 同一文件或 DraftGo 资源全程只能由一个 Agent 修改;其他 Agent 只读分析并回传建议。
|
|
47
|
-
- 不同资源、operation 和 owner 不冲突的工作单元并发执行,不设置客户端并发上限;同一资源的依赖步骤保持串行。
|
|
48
|
-
- 主 Agent 负责 Reference/MCP 路由、owner 分配、汇总回读、统一验证、交付和 worklog 状态。
|
|
49
|
-
- 冲突 owner、接口依赖或验证失败会阻塞依赖项,不影响无关分支继续汇总。
|
|
50
|
-
|
|
51
|
-
## 开发与交付
|
|
23
|
+
| 页面、导航、交互或 UI | `references/frontend.md`;涉及 iframe、路由、认证或全局层加读 `runtime.md` / `app-api.md` |
|
|
24
|
+
| pages/nav/docs 正文、版本或冲突 | `references/checkout.md` |
|
|
25
|
+
| 动态 DB、筛选或关系 | `references/data.md`;复杂关系再读 `db-relations.md` |
|
|
26
|
+
| AIHub、知识库、记忆、聊天或图片 | `references/aihub.md`;页面调用再读 `chat-sdk.md` |
|
|
27
|
+
| 自定义服务、权限、外部调用、余额扣款或订阅 | `references/custom-services.md` |
|
|
28
|
+
| MCP 配置、API 契约或故障 | `references/mcp.md`;连接或调用失败时运行 `draftgo mcp test` |
|
|
29
|
+
| 运行失败、日志或请求链路 | `references/diagnostics.md` |
|
|
30
|
+
| 验证、发布或交付验收 | `references/delivery.md` |
|
|
31
|
+
| 跨领域任务且不确定最短链路 | `references/methods.md`,再打开所需领域资料 |
|
|
32
|
+
| 架构、模块选型或陌生项目 | `references/architecture.md`、`references/modules.md`;存在时一并读 `.draftgo/story.yaml` |
|
|
52
33
|
|
|
53
|
-
|
|
34
|
+
业务归属、系统资源或页面类型没有元数据时,报告证据不足,不凭标题、路径或片段猜测。页面需求不因出现“页面”二字就默认新建或 checkout:修改已有资源时先唯一定位,确需独立新页面时先通过 MCP 实时 API 创建并取得 ID,再 checkout 正文;多个候选会导致不同产品结果时再向用户澄清。
|
|
54
35
|
|
|
55
|
-
|
|
56
|
-
2. 对需要完整分析或编辑的目标批量 checkout;在 `.draftgo/worktree/` 按唯一 owner 编辑。
|
|
57
|
-
3. 主 Agent 回读全部修改,并按顶部统一验证策略完成交付前验收。
|
|
58
|
-
4. 用 `draftgo diff <type> <id>` 检查 base/local 差异,再按类型运行 `draftgo commit ...`。
|
|
59
|
-
5. 409/412 时停止自动提交,保留 base/local/remote 冲突材料;不得 force、覆盖或自动合并。
|
|
36
|
+
## 长正文与结构化资源
|
|
60
37
|
|
|
61
|
-
|
|
38
|
+
1. 精确定位目标后再 checkout;对需要完整分析或编辑的目标批量 checkout,并在 `.draftgo/worktree/` 由唯一 owner 编辑。
|
|
39
|
+
2. 先用 `draftgo diff <type> <id> --stat` 或 `--summary` 判断范围;只有需要审查内容时才展开完整 diff。
|
|
40
|
+
3. 运行所需的 `draftgo verify`,再 commit。409/412 时停止,保留 base/local/remote;不得 force、覆盖或自动合并。
|
|
41
|
+
4. 结构化资源不 checkout:未知 operation 才 search,首次使用或 registry revision 变化时 describe,其余使用缓存后 call;describe 不完整就停止,不猜字段、权限或风险。
|
|
62
42
|
|
|
63
|
-
|
|
43
|
+
完整传输、manifest 和冲突规则见 `references/checkout.md`;交付证据见 `references/delivery.md`。
|
|
64
44
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
### 工作记录
|
|
68
|
-
|
|
69
|
-
任务开始即写入开发中状态;独立事项可先以待开发状态加入:
|
|
70
|
-
|
|
71
|
-
```bash
|
|
72
|
-
draftgo work start "<事项>"
|
|
73
|
-
draftgo work add "<独立事项>"
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
开始处理待开发项时运行 `draftgo work start-item <编号>`。只有 `draftgo verify` 和所有 commit/MCP 写入成功后,才运行 `draftgo work complete <编号> --note "<结果或证据>"`。用户明确要求视觉验收时还需完成对应截图或浏览器校验。任何验证失败、409/412 或交付失败都不得标记为完成。
|
|
77
|
-
|
|
78
|
-
## 安全规则
|
|
79
|
-
|
|
80
|
-
- SAT 只保存在 `.draftgo/config.json`;不得进入宿主配置、命令行参数、Skill、日志、manifest 或错误消息。宿主只配置 `draftgo mcp serve`。
|
|
81
|
-
- 页面优先使用可信本地资源;禁止境外 CDN。用户输入或不可信 HTML 在渲染前净化,关键状态不能只靠颜色或动效表达。
|
|
82
|
-
- 页面通过 `window.parent.App` 使用认证、权限、反馈和主题;登出调用 `await App.logout()`,路由参数读取运行时注入对象。详细规则见 `frontend.md`、`runtime.md` 与 `app-api.md`。
|
|
83
|
-
- 自定义服务普通 SDK 继承调用者权限;仅显式 `draftgo.Admin.*` 提升单次调用并进入审计。Route 权限、脚本管理权限、定时/事件身份和出站限制见 `custom-services.md`。
|
|
84
|
-
- 高风险 MCP operation 仅在用户意图明确且影响范围已核对时设置 `confirm=true`。不要传 SAT、Authorization、tenant override 或自行实现旧式二次认证。
|
|
85
|
-
- 不要隐式 force、自动重试覆盖或自动合并冲突。
|
|
86
|
-
|
|
87
|
-
## 验证证据
|
|
88
|
-
|
|
89
|
-
| 范围 | 最低证据 |
|
|
90
|
-
|---|---|
|
|
91
|
-
| MCP 连接 | 失败时用 `draftgo mcp test` 核对 initialize、tools/list 和关键工具;输出不含 SAT |
|
|
92
|
-
| 页面、导航、文档 | checkout manifest、交付前 `draftgo verify`、diff、commit 返回版本与哈希 |
|
|
93
|
-
| 结构化资源 | 缓存或最新 describe 契约、call 结果与必要回读 |
|
|
94
|
-
| 自定义服务 | commit revision、validate 结果;任务涉及运行或发布时再提供 test/publish 结果 |
|
|
95
|
-
| 冲突 | `.draftgo/conflicts/` 的 base/local/remote;解决后重新 `draftgo verify`、diff 和 commit |
|
|
96
|
-
| 本地底座 | `draftgo local status`、日志和相关 local 测试 |
|
|
45
|
+
## 所有权与安全
|
|
97
46
|
|
|
98
|
-
|
|
47
|
+
- 同一文件或 DraftGo 资源全程只能由一个 Agent 修改;不同资源、operation 和 owner 不冲突的单元可以并发,不设置客户端并发上限;同一资源的依赖步骤保持串行。主 Agent 负责 owner 分配、汇总、验证、交付和 worklog 状态。
|
|
48
|
+
- 用户 API Key 只保存在 `.draftgo/config.json`,不得进入宿主配置、命令参数、Skill、日志、manifest 或错误消息。宿主 MCP 配置只运行 `draftgo mcp serve`。
|
|
49
|
+
- 页面优先使用可信本地资源;禁止境外 CDN。净化不可信 HTML,关键状态不能只靠颜色或动效表达。页面通过 `window.parent.App` 使用认证、权限、反馈和主题;详细规则见前端与运行时 Reference。
|
|
50
|
+
- 普通自定义服务 SDK 调用继承调用者、服务归属和 AccessGrant;`ctx.Admin.*` 是仅供自定义服务显式选择的单次系统内部授权,按 `*:*:all` 全权限执行并进入审计,不会泄漏到后续调用。高风险 MCP operation 仅在用户意图明确且影响范围已核对时设置 `confirm=true`。
|
|
51
|
+
- `.draftgo/tmp/` 可清理;先运行 `draftgo clean --dry-run`,再在需要时使用 `--yes`。用户可查验的证据放入已注册的 `.draftgo/artifacts/`。
|
|
99
52
|
|
|
100
|
-
##
|
|
53
|
+
## 完成条件
|
|
101
54
|
|
|
102
|
-
|
|
103
|
-
- `.draftgo/api-contract-cache.json`:按 registry revision 缓存的私有 operation schema,必须 gitignore。
|
|
104
|
-
- `.draftgo/worktree/`、`.base/`、`manifest.json`:checkout 正文及基线,必须 gitignore。
|
|
105
|
-
- `.draftgo/conflicts/`:409/412 材料,必须 gitignore。
|
|
106
|
-
- `.draftgo/story.yaml`、`lessons/`:项目决策和经验。
|
|
107
|
-
- `.draftgo/worklog.md`:待开发、开发中和已完成事项及备注。
|
|
55
|
+
每个目标均有与其类型相符的证据:正文有 checkout、验证、commit 返回的版本/哈希及必要远端回读;结构化资源有 describe、写入结果和回读;自定义服务的 `commit` 会完成 validate/publish,按需补充 test。任何验证失败、409/412 或交付失败都不得标记为完成;任何 verify、写入、回读或要求的视觉验收失败时,工作项保持 active。
|
|
@@ -19,15 +19,15 @@ description: Install or refresh the DraftGo skill, connect a project to a DraftG
|
|
|
19
19
|
6. 连接后运行 draftgo mcp setup(或指定目标),再运行 draftgo mcp test 验证 initialize、tools/list 和关键工具。
|
|
20
20
|
7. 根 Skill 自动加载后,按实际任务读取最少必要的 Reference,并通过 MCP project_overview、resource_search 或 api_search 获取实时信息;需要叠加本地 checkout 状态时运行 `draftgo map`。MCP 不可用时报告原因。
|
|
21
21
|
|
|
22
|
-
draftgo init 只负责 Skill 安装;draftgo connect 负责保存并验证 server/
|
|
22
|
+
draftgo init 只负责 Skill 安装;draftgo connect 负责保存并验证 server/API Key;draftgo mcp setup 负责宿主配置。不要混用职责。
|
|
23
23
|
|
|
24
24
|
初始化后 `.draftgo/` 只保留已经写入的 `config.json`。不要预建 worklog、lessons、worktree、conflicts 或其他占位文件和目录;首次实际使用对应能力时再创建。
|
|
25
25
|
|
|
26
|
-
##
|
|
26
|
+
## API Key 与配置
|
|
27
27
|
|
|
28
|
-
-
|
|
28
|
+
- 交互式连接使用当前用户的 DraftGo API Key 和隐藏输入;不要把 API Key 写入宿主配置、Skill 文件、命令行示例或日志。
|
|
29
29
|
- .draftgo/config.json、checkout manifest、base 和冲突目录必须加入项目 .gitignore。
|
|
30
|
-
- bridge 从当前项目配置读取
|
|
30
|
+
- bridge 从当前项目配置读取 API Key;宿主配置只引用 draftgo mcp serve。
|
|
31
31
|
|
|
32
32
|
## 后续动作
|
|
33
33
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schema_version": "1.0",
|
|
3
3
|
"id": "draftgo",
|
|
4
4
|
"name": "DraftGo 开发助手",
|
|
5
|
-
"version": "4.0.
|
|
5
|
+
"version": "4.0.23",
|
|
6
6
|
"entry": "SKILL.md",
|
|
7
7
|
"description": "以 Skill/reference 任务路由、MCP 实时发现、长正文 checkout/commit、统一验证和完成日志为边界的 DraftGo 工作流。",
|
|
8
8
|
"license": "MIT",
|
|
@@ -11,8 +11,12 @@
|
|
|
11
11
|
"reference-routing",
|
|
12
12
|
"worklog-tracking",
|
|
13
13
|
"custom-service-ai-sdk",
|
|
14
|
+
"minimal-method-guides",
|
|
15
|
+
"aihub-knowledge-memory",
|
|
14
16
|
"mcp-bridge",
|
|
15
17
|
"content-checkout-commit",
|
|
18
|
+
"runtime-diagnostics",
|
|
19
|
+
"delivery-acceptance",
|
|
16
20
|
"conflict-safe-delivery",
|
|
17
21
|
"project-validation",
|
|
18
22
|
"skill-installation"
|
|
@@ -4,6 +4,24 @@ read_when: 创建或调优 AI Agent 时 · 需要工具/子智能体/记忆/多
|
|
|
4
4
|
|
|
5
5
|
# AIHub / Agent 资源
|
|
6
6
|
|
|
7
|
+
## 最短管理流程
|
|
8
|
+
|
|
9
|
+
AIHub、知识库与记忆都是结构化远端资源。先按领域搜索实时 operation,再描述契约并调用;`request.json` 只包含 describe 允许的字段:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
draftgo api search "AIHub Agent"
|
|
13
|
+
draftgo api search "knowledge base"
|
|
14
|
+
draftgo api search "agent memory"
|
|
15
|
+
draftgo api describe <operation_id>
|
|
16
|
+
draftgo api call <operation_id> --input request.json --output json
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
已有精确 `operation_id` 时跳过 search。写入后用对应 get/list operation 回读目标 ID;需要验证运行行为时,再查调用 operation 和 AI run 日志,不把配置成功当成推理成功。知识库存放可检索资料,长期记忆存放 Agent 运行时按作用域提炼的用户/Agent 记忆,两者不要互相代替。
|
|
20
|
+
|
|
21
|
+
AIHub 与知识库是独立权限域:Agent、模型和 AI 运行使用 `aihub:*`,知识库、文档、上传、检索和重建使用 `knowledge:*`。配置了 `aihub:*` 不会自动获得知识库权限,反之亦然;具体动作仍以实时 operation 契约为准。
|
|
22
|
+
|
|
23
|
+
完成条件:目标资产可回读,状态与调用权限符合预期;任务涉及调用时,运行成功且日志能按入口 Agent/模型定位。任何文件和输出都不得包含供应商密钥。
|
|
24
|
+
|
|
7
25
|
AIHub 是结构化远端资源,不 checkout,也不生成本地镜像。先使用 MCP `draftgo_resource_search`/`draftgo_resource_list`
|
|
8
26
|
定位资产;未知 operation 才用 `draftgo_api_search`,首次使用或 registry revision 变化时 `draftgo_api_describe`,然后通过 `draftgo_api_call` 读写。
|
|
9
27
|
更新 AIHub 资产时只发送实时契约允许的字段;常见字段包括
|
|
@@ -37,7 +55,7 @@ AIHub 是结构化远端资源,不 checkout,也不生成本地镜像。先
|
|
|
37
55
|
|
|
38
56
|
| 字段 | 类型 / 取值 | 说明 |
|
|
39
57
|
|---|---|---|
|
|
40
|
-
| `mode` | `chat` / `image_generation` |
|
|
58
|
+
| `mode` | `chat` / `image_generation` | 决定主要交互形态;具体 Responses、Embedding、Rerank、TTS、ASR、Video operation 以 MCP 和模型 capability 为准 |
|
|
41
59
|
| `model` | string | 主模型(逻辑模型名,映射到供应商路由) |
|
|
42
60
|
| `fallback_models` | string[] | 主模型失败后按序回退(跨模型 failover) |
|
|
43
61
|
| `model_selection.user_selectable` | bool | 是否允许调用方在请求里覆盖 `model`(配合 `selectable-models`) |
|
|
@@ -57,6 +75,7 @@ AIHub 是结构化远端资源,不 checkout,也不生成本地镜像。先
|
|
|
57
75
|
| `skills` | 见运行时 | 绑定 Skill |
|
|
58
76
|
| `sub_agent_ids` | int[] | 子智能体:为每个 id 生成 `agent_{id}` 委派工具(用法同 `knowledge_base_ids`) |
|
|
59
77
|
| `call_permissions` | 角色配置 | 哪些角色可以调用此 Agent;调用接口与筛选条件以 MCP 实时契约为准 |
|
|
78
|
+
| `billing_mode` | `disabled` / `inherit_model` / `per_call` / `usage` | Agent 零售计费;公开 Agent 强制 `disabled`,订阅/会员额度由业务服务管理 |
|
|
60
79
|
|
|
61
80
|
### `orchestration.*`(编排开关)
|
|
62
81
|
|
|
@@ -88,6 +107,10 @@ AIHub 是结构化远端资源,不 checkout,也不生成本地镜像。先
|
|
|
88
107
|
每次调用都开一条 AI run,管理台 `/admin/ai-runs` 展示状态、tokens、延迟、`ttft_ms` 与 span 链路。
|
|
89
108
|
运行记录接口通过 MCP 实时发现,不维护静态路径表;已知 operation 复用 registry revision 未变化的契约缓存。
|
|
90
109
|
|
|
110
|
+
模型价格使用 `disabled`、`per_call`、`usage`。模型能否调用某项能力必须同时满足模型声明、Provider
|
|
111
|
+
profile、transport readiness 和实际 route;不要只根据供应商名称推断支持音频、视频或其他能力。
|
|
112
|
+
能力名大小写敏感,使用实时 describe 返回的 canonical 值,不使用历史别名。
|
|
113
|
+
|
|
91
114
|
Agent 对外响应(`/api/agents/{id}/chat`、图片接口、Go/Script SDK Agent 调用)不返回内部 `model`、`fallback_models` 或 `upstream_model`;错误也不暴露内部模型名、供应商名称、服务地址或运行时实现名。只有显式启用 `model_selection.user_selectable` 后,`/selectable-models` 才作为授权的模型选择目录返回可选逻辑模型名。运行日志仍在服务端保留真实模型、供应商与链路信息用于定位。
|
|
92
115
|
|
|
93
|
-
> 权威细节以 DraftGo
|
|
116
|
+
> 权威细节以 DraftGo `docs/modules/ai-platform/agent-runtime.md` 和实时 MCP schema 为准;本页是基座开发者视角的字段速查。
|
|
@@ -12,11 +12,11 @@ const App = window.parent?.App;
|
|
|
12
12
|
|
|
13
13
|
| 方法 | 签名 | 说明 |
|
|
14
14
|
|---|---|---|
|
|
15
|
-
| `App.get` | `(path, params?)` | GET,params 为 query 参数 |
|
|
16
|
-
| `App.post` | `(path, body?)` | POST |
|
|
17
|
-
| `App.put` | `(path, body?)` | PUT |
|
|
18
|
-
| `App.patch` | `(path, body?)` | PATCH |
|
|
19
|
-
| `App.delete` | `(path)` | DELETE |
|
|
15
|
+
| `App.get` | `(path, params?, headers?)` | GET,params 为 query 参数 |
|
|
16
|
+
| `App.post` | `(path, body?, headers?)` | POST |
|
|
17
|
+
| `App.put` | `(path, body?, headers?)` | PUT |
|
|
18
|
+
| `App.patch` | `(path, body?, headers?)` | PATCH |
|
|
19
|
+
| `App.delete` | `(path, params?, headers?)` | DELETE |
|
|
20
20
|
| `App.uploadFile` | `(file, onProgress?)` | 文件上传,返回标准信封 |
|
|
21
21
|
|
|
22
22
|
**响应格式**:`{ code: 200, data: <载荷>, message: "success" }`
|
|
@@ -67,11 +67,57 @@ const { patientId, visitId } = routeContext.query;
|
|
|
67
67
|
|---|---|---|
|
|
68
68
|
| `App.currentUser` | object \| null | 当前用户,未登录为 null |
|
|
69
69
|
| `App.isAdmin` | boolean | 是否管理员 |
|
|
70
|
+
| `App.permissions` | string[] | 当前用户有效 permission grant 的展示投影;仅用于页面显隐,不替代服务端授权 |
|
|
70
71
|
| `App.isAuthenticated` | boolean | 是否已认证 |
|
|
71
72
|
| `App.hasToken` | boolean | 是否有 token(含未验证) |
|
|
72
73
|
| `App.config` | object | 系统配置 KV |
|
|
73
74
|
| `App.theme` | `'light'` \| `'dark'` | 当前显示模式 |
|
|
74
75
|
| `App.colorScheme` | string | 当前配色方案 |
|
|
76
|
+
| `App.scopeContext` | object | null | 当前候选范围;`scope_type` 为 `platform` / `space` |
|
|
77
|
+
| `App.availableSpaces` | object[] | 当前用户可选择的工作区与递归空间 |
|
|
78
|
+
|
|
79
|
+
### 空间上下文
|
|
80
|
+
|
|
81
|
+
空间业务请求使用运行时当前上下文。页面先显示加载状态,再等待有效空间;返回 `null` 时呈现紧凑的工作空间状态和重试入口,本轮不发送业务请求。
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
function currentSpace() {
|
|
85
|
+
const scope = App.getScopeContext?.() || App.scopeContext;
|
|
86
|
+
return scope?.scope_type === 'space' && scope.space_id ? scope : null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function waitForSpace(timeout = 4000) {
|
|
90
|
+
if (currentSpace()) return currentSpace();
|
|
91
|
+
return new Promise(resolve => {
|
|
92
|
+
const host = window.parent;
|
|
93
|
+
const done = value => {
|
|
94
|
+
clearTimeout(timer);
|
|
95
|
+
host?.removeEventListener('dg:scope-changed', check);
|
|
96
|
+
host?.removeEventListener('dg:scope-spaces-changed', check);
|
|
97
|
+
resolve(value);
|
|
98
|
+
};
|
|
99
|
+
const check = () => { if (currentSpace()) done(currentSpace()); };
|
|
100
|
+
const timer = setTimeout(() => done(null), timeout);
|
|
101
|
+
host?.addEventListener('dg:scope-changed', check);
|
|
102
|
+
host?.addEventListener('dg:scope-spaces-changed', check);
|
|
103
|
+
check();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const scope = await waitForSpace();
|
|
108
|
+
if (!scope) {
|
|
109
|
+
renderWorkspaceState();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
await App.get('business-items', { page: 1 });
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
平台管理接口按接口契约显式传入平台范围:
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
const platformHeaders = { 'X-DraftGo-Scope-Type': 'platform' };
|
|
119
|
+
await App.get('roles', {}, platformHeaders);
|
|
120
|
+
```
|
|
75
121
|
|
|
76
122
|
## 主题
|
|
77
123
|
|
|
@@ -89,7 +135,11 @@ await App.logout(); // 服务端登出、清理状态并跳转
|
|
|
89
135
|
App.setAuthTokens({ access_token, refresh_token }); // 登录后写入 token
|
|
90
136
|
App.reloadGlobalLayer(); // 重载全局层
|
|
91
137
|
App.openGlobalWidget(name); // 触发全局挂件打开
|
|
92
|
-
App.
|
|
138
|
+
App.getScopeContext(); // 读取当前作用域
|
|
139
|
+
App.setScopeContext({ scope_type: 'space', space_id: '120' });
|
|
140
|
+
App.clearScopeContext(); // 清除手工选择,恢复服务端默认
|
|
141
|
+
App.t(key, fallback?, values?); // 页面级国际化文本,values 保留 ICU 占位符
|
|
142
|
+
App.formatDateTime(value, options?); // 按 system_timezone 格式化 API 返回的 UTC 时间
|
|
93
143
|
```
|
|
94
144
|
|
|
95
145
|
Token、刷新、路由上下文和认证事件见 `references/runtime.md`。AI 对话、图片和兼容门面的完整契约见 `references/chat-sdk.md`,Agent 能力见 `references/aihub.md`。
|
|
@@ -40,7 +40,7 @@ DraftGo **不是传统 SPA**,是「数据库驱动的页面资产运行时」
|
|
|
40
40
|
|---|---|
|
|
41
41
|
| 后端 | Go 1.26 · 标准库 `net/http` · `database/sql`(go-sql-driver/mysql)· MySQL · Redis |
|
|
42
42
|
| 壳层前端 | React · Vite |
|
|
43
|
-
| 数据库页面 | HTML 文档运行时 ·
|
|
43
|
+
| 数据库页面 | HTML 文档运行时 · Tailwind CSS 4 · Basecoat UI(默认)· Oat UI(可选)· Font Awesome · GSAP · 内置 SVG 图标库 |
|
|
44
44
|
| CLI | Node.js(draftgo-cli) |
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
数据库页面以完整 HTML 文档运行,直接加载平台提供的本地资源;壳层源码按 React + Vite 工程构建。开发时按目标所属层使用上表对应技术栈。
|
|
@@ -4,7 +4,7 @@ read_when: 页面需要 AI 对话 UI 时 · 使用 dg-chat 或 DraftGoChat 时
|
|
|
4
4
|
|
|
5
5
|
# DraftGo Chat SDK
|
|
6
6
|
|
|
7
|
-
DraftGo
|
|
7
|
+
DraftGo 页面使用完整版 `/assets/draftgo-chat.js` 原生 Web Component。SDK 统一提供消息状态机、流解析、停止、重试和历史逻辑。
|
|
8
8
|
|
|
9
9
|
## 目录
|
|
10
10
|
|
|
@@ -71,7 +71,7 @@ DraftGo 页面只使用完整版 `/assets/draftgo-chat.js`。它是原生 Web Co
|
|
|
71
71
|
|
|
72
72
|
这些 `/api/ai-proxy/*` 是接入方实现的占位路由,不是 DraftGo 自动提供的默认代理。不要将供应商密钥或长期 token 写入页面。
|
|
73
73
|
|
|
74
|
-
内置 transport 支持 SSE、NDJSON 和普通 JSON,并把上游响应归一化为 `text.delta`、`reasoning.delta`、`tool.start`、`tool.delta`、`tool.finish`、`artifact.complete`、`source`、`usage`、`message.finish`、`error`
|
|
74
|
+
内置 transport 支持 SSE、NDJSON 和普通 JSON,并把上游响应归一化为 `text.delta`、`reasoning.delta`、`tool.start`、`tool.delta`、`tool.finish`、`step.finish`、`artifact.complete`、`source`、`usage`、`message.finish`、`error` 等事件。配置 JSON 以 DraftGo 当前 `contracts/chat-sdk.schema.json` 为准;不要猜测字段或把函数、DOM、renderer、plugin、transport 写入 JSON。
|
|
75
75
|
|
|
76
76
|
## 配置与布局
|
|
77
77
|
|
|
@@ -160,6 +160,8 @@ chat.addEventListener('dg-chat:run-finish', event => {
|
|
|
160
160
|
|
|
161
161
|
页面销毁或离开路由时调用 `stop()`,取消上传、plugin 和在途 transport。
|
|
162
162
|
|
|
163
|
+
`requestTimeoutMs` 和 `streamTimeoutMs` 分别控制客户端非流式/流式总时限,默认 120000/610000 毫秒,`0` 表示禁用。两者只处理客户端半开连接,不替代 Agent 的服务端超时。
|
|
164
|
+
|
|
163
165
|
## 历史与会话
|
|
164
166
|
|
|
165
167
|
- `persist` 默认开启,将 UI thread 历史写入 `localStorage`;敏感或临时页面设为 `false`。
|
|
@@ -4,9 +4,21 @@ read_when: 编辑 pages、navigation 或 docs 正文时 · 查看 checkout manif
|
|
|
4
4
|
|
|
5
5
|
# Checkout / Commit
|
|
6
6
|
|
|
7
|
+
## 页面与内容最短流程
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
draftgo map --type pages --route /admin/channel-ops --output json
|
|
11
|
+
draftgo checkout pages 42
|
|
12
|
+
draftgo diff pages 42 --stat
|
|
13
|
+
draftgo verify pages 42
|
|
14
|
+
draftgo commit pages 42
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
导航和文档分别替换为 `nav`、`docs`。route/title 为精确匹配,两个条件取交集;只需确认范围或 checkout 状态时使用 `map --summary`,必须浏览时使用 `--limit <1-100>`(默认 20),并仅在单一 `--type` 下用 `--cursor <opaque>` 翻页。新资源先用 `draftgo api search "create page"` 或对应内容类型定位创建 operation,describe/call 取得 ID 后再 checkout;不要用 checkout 创建资源。`verify` 通过不等于已交付,commit 返回新版本与哈希才算正文写入成功。发生 409/412 时保留冲突材料并停止提交。
|
|
18
|
+
|
|
7
19
|
## Workflow 2.0 scope
|
|
8
20
|
|
|
9
|
-
The checkout set includes `pages`, `navigations`, `docs/articles`, and `custom_services`. A custom-service checkout
|
|
21
|
+
The checkout set includes `pages`, `navigations`, `docs/articles`, and `custom_services`. A custom-service checkout contains exactly `service.go` and `service.json`, plus one complete `.base` directory. Runner-managed `go.mod/go.sum` never participate in diff or commit. `draftgo commit custom-services <id>` performs the complete delivery (`commit -> validate -> publish`) and prints an explicit published confirmation. Use `draftgo test custom-services <id>` for server Runner validation/execution; `draftgo publish custom-services <id>` remains as a direct compatibility entry point. DB Meta remains a live MCP/API resource and is never checked out.
|
|
10
22
|
|
|
11
23
|
`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
24
|
|
|
@@ -32,7 +44,7 @@ Checkout 只为已存在且已确认 ID 的资源建立本地正文与 base,
|
|
|
32
44
|
draftgo checkout <pages|nav|docs> <id...>
|
|
33
45
|
draftgo commit <pages|nav|docs> <id...>
|
|
34
46
|
draftgo reconcile <pages|nav|docs> <id...>
|
|
35
|
-
draftgo diff <pages|nav|docs> <id>
|
|
47
|
+
draftgo diff <pages|nav|docs|custom-services> <id> [--stat|--summary]
|
|
36
48
|
draftgo conflicts
|
|
37
49
|
draftgo conflict show <pages|nav|docs> <id>
|
|
38
50
|
draftgo conflict resolve <pages|nav|docs> <id>
|
|
@@ -41,11 +53,13 @@ draftgo conflict resolve <pages|nav|docs> <id>
|
|
|
41
53
|
`checkout --force` 只用于用户明确允许丢弃未提交本地修改的情况。默认 checkout 检测到 worktree 文件相对
|
|
42
54
|
base 已变化时必须拒绝覆盖。
|
|
43
55
|
|
|
56
|
+
`diff --stat` 只显示文件与增删行数;`diff --summary` 显示资源、基线版本和变化概要。两者均不输出正文 diff,先用它们确认范围,再按需展开完整 `diff`。`--output json` 时 stdout 只包含 UTF-8 JSON,诊断走 stderr。
|
|
57
|
+
|
|
44
58
|
## Checkout 流程
|
|
45
59
|
|
|
46
60
|
1. CLI 通过 MCP `draftgo_resource_get_metadata` 取得规范类型、content_type、SHA-256、大小、版本/revision、
|
|
47
61
|
ETag 和受信任的下载/提交 URL。
|
|
48
|
-
2. CLI 使用 `.draftgo/config.json`
|
|
62
|
+
2. CLI 使用 `.draftgo/config.json` 中的用户 API Key 通过专用 HTTP 下载完整正文;API Key 不进入 MCP 参数或日志。
|
|
49
63
|
3. 响应体直接流式写入同目录临时文件,校验 content_type、字节数和 SHA-256。
|
|
50
64
|
4. 校验成功后原子重命名到 worktree 文件,并保存相同字节的 `.base` 文件。
|
|
51
65
|
5. 最后原子更新 `.draftgo/worktree/manifest.json`。失败时不得留下半截正式文件或推进 manifest。
|