@gaoding/cli 2.1.7 → 3.0.0

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 (62) hide show
  1. package/README.md +6 -3
  2. package/contracts/operations/tool.call/canvas-input.schema.json +0 -3
  3. package/contracts/presentations/agent.send.schema.json +303 -0
  4. package/contracts/presentations/model.get.schema.json +246 -0
  5. package/contracts/presentations/model.list.schema.json +144 -0
  6. package/contracts/presentations/task.get.schema.json +146 -0
  7. package/contracts/presentations/tool.call.schema.json +200 -0
  8. package/dist/bin/gd-cli.js +9 -3
  9. package/dist/bin/insmind-cli.js +6 -1
  10. package/dist/src/bootstrap/create-cli.js +7 -4
  11. package/dist/src/bootstrap/create-runtime.js +7 -32
  12. package/dist/src/cli/action-binding.js +2 -2
  13. package/dist/src/cli/agent-commands.js +5 -4
  14. package/dist/src/cli/auth-commands.js +1 -1
  15. package/dist/src/cli/dam-commands.js +18 -10
  16. package/dist/src/cli/errors.js +1 -35
  17. package/dist/src/cli/host-input.js +0 -11
  18. package/dist/src/cli/model-commands.js +6 -5
  19. package/dist/src/cli/skill-output.js +13 -0
  20. package/dist/src/cli/tool-commands.js +9 -5
  21. package/dist/src/features/skill/catalog.js +152 -0
  22. package/dist/src/features/skill/manual.js +71 -0
  23. package/dist/src/features/tool/archived-ocr-result.js +74 -0
  24. package/dist/src/features/tool/canvas-copy.js +2 -3
  25. package/dist/src/features/tool/canvas-models.js +8 -5
  26. package/dist/src/features/tool/canvas-recovery.js +3 -2
  27. package/dist/src/features/tool/canvas-results.js +1 -55
  28. package/dist/src/features/tool/canvas-tool-adapter.js +7 -10
  29. package/dist/src/features/tool/mns-catalog-adapter.js +4 -4
  30. package/dist/src/features/tool/resource-authorizer.js +1 -1
  31. package/dist/src/features/tool/scene-catalog-adapter.js +20 -22
  32. package/dist/src/features/tool/tool-definitions.js +0 -1
  33. package/dist/src/product/config.js +0 -7
  34. package/dist/src/telemetry/command-routes.json +1 -1
  35. package/package.json +4 -4
  36. package/skills/gd-cli/SKILL.md +10 -29
  37. package/contracts/operations/editor.apply/input.schema.json +0 -134
  38. package/contracts/operations/editor.apply/output.schema.json +0 -15
  39. package/contracts/operations/editor.connect/input.schema.json +0 -15
  40. package/contracts/operations/editor.connect/output.schema.json +0 -17
  41. package/contracts/operations/editor.disconnect/input.schema.json +0 -8
  42. package/contracts/operations/editor.disconnect/output.schema.json +0 -14
  43. package/contracts/operations/editor.save/input.schema.json +0 -8
  44. package/contracts/operations/editor.save/output.schema.json +0 -23
  45. package/contracts/operations/editor.screenshot/input.schema.json +0 -8
  46. package/contracts/operations/editor.screenshot/output.schema.json +0 -16
  47. package/contracts/operations/editor.snapshot/input.schema.json +0 -8
  48. package/contracts/operations/editor.snapshot/output.schema.json +0 -113
  49. package/contracts/operations/tool.call/models/image-ocr.schema.json +0 -22
  50. package/contracts/operations/tool.call/ocr-payload.schema.json +0 -65
  51. package/dist/src/cli/editor-commands.js +0 -136
  52. package/skills/gd-cli/references/agent.md +0 -39
  53. package/skills/gd-cli/references/auth-org.md +0 -11
  54. package/skills/gd-cli/references/creation.md +0 -61
  55. package/skills/gd-cli/references/dam.md +0 -53
  56. package/skills/gd-cli/references/editor.md +0 -67
  57. package/skills/gd-cli/references/errors.md +0 -46
  58. package/skills/gd-cli/references/generation-constraints.md +0 -40
  59. package/skills/gd-cli/references/matting.md +0 -27
  60. package/skills/gd-cli/references/media-tools.md +0 -46
  61. package/skills/gd-cli/references/tool.md +0 -24
  62. package/skills/gd-cli/references/update.md +0 -22
@@ -1,134 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "EditorApplyInput",
4
- "description": "要依次应用到当前编辑器的操作。",
5
- "type": "array",
6
- "items": {
7
- "oneOf": [
8
- { "$ref": "#/$defs/EditorUpsertAction" },
9
- { "$ref": "#/$defs/EditorDeleteAction" }
10
- ]
11
- },
12
- "$defs": {
13
- "EditorUpsertAction": {
14
- "title": "EditorUpsertAction",
15
- "type": "object",
16
- "additionalProperties": false,
17
- "required": ["_type", "element"],
18
- "properties": {
19
- "_type": {
20
- "type": "string",
21
- "enum": ["create", "update"],
22
- "description": "创建或完整更新元素。"
23
- },
24
- "element": {
25
- "description": "要创建或完整更新的元素。",
26
- "oneOf": [
27
- { "$ref": "#/$defs/EditorShape" },
28
- { "$ref": "#/$defs/EditorConnector" }
29
- ]
30
- }
31
- }
32
- },
33
- "EditorDeleteAction": {
34
- "title": "EditorDeleteAction",
35
- "type": "object",
36
- "additionalProperties": false,
37
- "required": ["_type", "id"],
38
- "properties": {
39
- "_type": {
40
- "const": "delete",
41
- "description": "删除元素。"
42
- },
43
- "id": {
44
- "type": "string",
45
- "minLength": 1,
46
- "pattern": ".*\\S.*",
47
- "description": "要删除的元素 ID。"
48
- }
49
- }
50
- },
51
- "EditorShape": {
52
- "title": "EditorShape",
53
- "type": "object",
54
- "additionalProperties": false,
55
- "required": ["_type", "id", "shapeType", "x", "y", "w", "h", "fill", "stroke"],
56
- "properties": {
57
- "_type": {
58
- "const": "shape",
59
- "description": "元素类型。"
60
- },
61
- "id": {
62
- "type": "string",
63
- "minLength": 1,
64
- "pattern": ".*\\S.*",
65
- "description": "元素 ID。"
66
- },
67
- "shapeType": {
68
- "type": "string",
69
- "enum": ["rectangle", "rounded-rectangle", "triangle-up", "ellipse", "diamond"],
70
- "description": "图形类型。"
71
- },
72
- "x": { "type": "number", "description": "左上角横坐标。" },
73
- "y": { "type": "number", "description": "左上角纵坐标。" },
74
- "w": { "type": "number", "description": "宽度。" },
75
- "h": { "type": "number", "description": "高度。" },
76
- "text": { "type": "string", "description": "图形中的文本。" },
77
- "fill": {
78
- "type": "string",
79
- "minLength": 1,
80
- "pattern": ".*\\S.*",
81
- "description": "填充颜色。"
82
- },
83
- "stroke": {
84
- "description": "描边颜色;null 表示无描边。",
85
- "anyOf": [
86
- { "type": "string", "minLength": 1, "pattern": ".*\\S.*" },
87
- { "type": "null" }
88
- ]
89
- }
90
- }
91
- },
92
- "EditorConnector": {
93
- "title": "EditorConnector",
94
- "type": "object",
95
- "additionalProperties": false,
96
- "required": ["_type", "id", "fromId", "toId", "lineType", "color"],
97
- "properties": {
98
- "_type": {
99
- "const": "connector",
100
- "description": "元素类型。"
101
- },
102
- "id": {
103
- "type": "string",
104
- "minLength": 1,
105
- "pattern": ".*\\S.*",
106
- "description": "连线 ID。"
107
- },
108
- "fromId": {
109
- "type": "string",
110
- "minLength": 1,
111
- "pattern": ".*\\S.*",
112
- "description": "起点元素 ID。"
113
- },
114
- "toId": {
115
- "type": "string",
116
- "minLength": 1,
117
- "pattern": ".*\\S.*",
118
- "description": "终点元素 ID。"
119
- },
120
- "lineType": {
121
- "type": "string",
122
- "enum": ["straight", "elbowed"],
123
- "description": "连线类型。"
124
- },
125
- "color": {
126
- "type": "string",
127
- "minLength": 1,
128
- "pattern": ".*\\S.*",
129
- "description": "连线颜色。"
130
- }
131
- }
132
- }
133
- }
134
- }
@@ -1,15 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "EditorApplyResult",
4
- "description": "编辑器操作应用结果。",
5
- "type": "object",
6
- "additionalProperties": false,
7
- "required": ["appliedCount"],
8
- "properties": {
9
- "appliedCount": {
10
- "type": "integer",
11
- "minimum": 0,
12
- "description": "已成功应用的操作数量。"
13
- }
14
- }
15
- }
@@ -1,15 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "EditorConnectInput",
4
- "description": "编辑器连接参数。",
5
- "type": "object",
6
- "additionalProperties": false,
7
- "properties": {
8
- "target": {
9
- "type": "string",
10
- "minLength": 1,
11
- "pattern": ".*\\S.*",
12
- "description": "作品 ID 或 AI+ Editor URL;省略时创建新作品。"
13
- }
14
- }
15
- }
@@ -1,17 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "EditorConnectResult",
4
- "description": "已连接的编辑器页面。",
5
- "type": "object",
6
- "additionalProperties": false,
7
- "required": ["target"],
8
- "properties": {
9
- "target": {
10
- "type": "string",
11
- "format": "uri",
12
- "minLength": 1,
13
- "pattern": ".*\\S.*",
14
- "description": "已连接的 AI+ Editor URL。"
15
- }
16
- }
17
- }
@@ -1,8 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "EditorDisconnectInput",
4
- "description": "断开当前编辑器连接。",
5
- "type": "object",
6
- "additionalProperties": false,
7
- "properties": {}
8
- }
@@ -1,14 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "EditorDisconnectResult",
4
- "description": "编辑器断开结果。",
5
- "type": "object",
6
- "additionalProperties": false,
7
- "required": ["disconnected"],
8
- "properties": {
9
- "disconnected": {
10
- "type": "boolean",
11
- "description": "是否断开了一个当前连接。"
12
- }
13
- }
14
- }
@@ -1,8 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "EditorSaveInput",
4
- "description": "保存当前编辑器作品。",
5
- "type": "object",
6
- "additionalProperties": false,
7
- "properties": {}
8
- }
@@ -1,23 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "EditorSaveResult",
4
- "description": "已保存的编辑器作品。",
5
- "type": "object",
6
- "additionalProperties": false,
7
- "required": ["workId", "url"],
8
- "properties": {
9
- "workId": {
10
- "type": "string",
11
- "minLength": 1,
12
- "pattern": ".*\\S.*",
13
- "description": "作品 ID。"
14
- },
15
- "url": {
16
- "type": "string",
17
- "format": "uri",
18
- "minLength": 1,
19
- "pattern": ".*\\S.*",
20
- "description": "作品的 AI+ Editor URL。"
21
- }
22
- }
23
- }
@@ -1,8 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "EditorScreenshotInput",
4
- "description": "导出当前编辑器截图。",
5
- "type": "object",
6
- "additionalProperties": false,
7
- "properties": {}
8
- }
@@ -1,16 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "EditorScreenshotResult",
4
- "description": "已导出的编辑器截图。",
5
- "type": "object",
6
- "additionalProperties": false,
7
- "required": ["path"],
8
- "properties": {
9
- "path": {
10
- "type": "string",
11
- "minLength": 1,
12
- "pattern": ".*\\S.*",
13
- "description": "截图在本机的绝对路径。"
14
- }
15
- }
16
- }
@@ -1,8 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "EditorSnapshotInput",
4
- "description": "读取当前编辑器快照。",
5
- "type": "object",
6
- "additionalProperties": false,
7
- "properties": {}
8
- }
@@ -1,113 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "EditorSnapshotResult",
4
- "description": "当前编辑器中的受支持元素与选区。",
5
- "type": "object",
6
- "additionalProperties": false,
7
- "required": ["elements", "selectedIds"],
8
- "properties": {
9
- "elements": {
10
- "type": "array",
11
- "description": "当前编辑器中的受支持元素。",
12
- "items": {
13
- "oneOf": [
14
- { "$ref": "#/$defs/EditorShape" },
15
- { "$ref": "#/$defs/EditorConnector" }
16
- ]
17
- }
18
- },
19
- "selectedIds": {
20
- "type": "array",
21
- "description": "当前选中元素的 ID。",
22
- "items": {
23
- "type": "string",
24
- "minLength": 1,
25
- "pattern": ".*\\S.*"
26
- }
27
- }
28
- },
29
- "$defs": {
30
- "EditorShape": {
31
- "title": "EditorShape",
32
- "type": "object",
33
- "additionalProperties": false,
34
- "required": ["_type", "id", "shapeType", "x", "y", "w", "h", "fill", "stroke"],
35
- "properties": {
36
- "_type": {
37
- "const": "shape",
38
- "description": "元素类型。"
39
- },
40
- "id": {
41
- "type": "string",
42
- "minLength": 1,
43
- "pattern": ".*\\S.*",
44
- "description": "元素 ID。"
45
- },
46
- "shapeType": {
47
- "type": "string",
48
- "enum": ["rectangle", "rounded-rectangle", "triangle-up", "ellipse", "diamond"],
49
- "description": "图形类型。"
50
- },
51
- "x": { "type": "number", "description": "左上角横坐标。" },
52
- "y": { "type": "number", "description": "左上角纵坐标。" },
53
- "w": { "type": "number", "description": "宽度。" },
54
- "h": { "type": "number", "description": "高度。" },
55
- "text": { "type": "string", "description": "图形中的文本。" },
56
- "fill": {
57
- "type": "string",
58
- "minLength": 1,
59
- "pattern": ".*\\S.*",
60
- "description": "填充颜色。"
61
- },
62
- "stroke": {
63
- "description": "描边颜色;null 表示无描边。",
64
- "anyOf": [
65
- { "type": "string", "minLength": 1, "pattern": ".*\\S.*" },
66
- { "type": "null" }
67
- ]
68
- }
69
- }
70
- },
71
- "EditorConnector": {
72
- "title": "EditorConnector",
73
- "type": "object",
74
- "additionalProperties": false,
75
- "required": ["_type", "id", "fromId", "toId", "lineType", "color"],
76
- "properties": {
77
- "_type": {
78
- "const": "connector",
79
- "description": "元素类型。"
80
- },
81
- "id": {
82
- "type": "string",
83
- "minLength": 1,
84
- "pattern": ".*\\S.*",
85
- "description": "连线 ID。"
86
- },
87
- "fromId": {
88
- "type": "string",
89
- "minLength": 1,
90
- "pattern": ".*\\S.*",
91
- "description": "起点元素 ID。"
92
- },
93
- "toId": {
94
- "type": "string",
95
- "minLength": 1,
96
- "pattern": ".*\\S.*",
97
- "description": "终点元素 ID。"
98
- },
99
- "lineType": {
100
- "type": "string",
101
- "enum": ["straight", "elbowed"],
102
- "description": "连线类型。"
103
- },
104
- "color": {
105
- "type": "string",
106
- "minLength": 1,
107
- "pattern": ".*\\S.*",
108
- "description": "连线颜色。"
109
- }
110
- }
111
- }
112
- }
113
- }
@@ -1,22 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "ImageOcrInput",
4
- "type": "object",
5
- "additionalProperties": false,
6
- "required": [
7
- "model",
8
- "image"
9
- ],
10
- "properties": {
11
- "model": {
12
- "type": "string",
13
- "const": "image-ocr",
14
- "description": "本次调用的模型机器标识;使用当前 model list/get 返回值。"
15
- },
16
- "image": {
17
- "type": "string",
18
- "format": "uri",
19
- "description": "本次要处理的原图 URI;HTTP(S) URL 或标准 file URI。参考图另放 referenceImages(若该模型支持),不与原图互换。"
20
- }
21
- }
22
- }
@@ -1,65 +0,0 @@
1
- {
2
- "$schema": "https://json-schema.org/draft/2020-12/schema",
3
- "title": "OcrPayload",
4
- "type": "object",
5
- "additionalProperties": true,
6
- "required": [
7
- "image",
8
- "blocks"
9
- ],
10
- "properties": {
11
- "image": {
12
- "type": "object",
13
- "additionalProperties": true,
14
- "required": [
15
- "uri",
16
- "width",
17
- "height"
18
- ],
19
- "properties": {
20
- "uri": {
21
- "type": "string",
22
- "format": "uri",
23
- "description": "单个 HTTP(S) 或 CLI file:// 素材 URI。"
24
- },
25
- "width": {
26
- "type": "integer",
27
- "minimum": 1
28
- },
29
- "height": {
30
- "type": "integer",
31
- "minimum": 1
32
- }
33
- }
34
- },
35
- "blocks": {
36
- "type": "array",
37
- "items": {
38
- "type": "object",
39
- "additionalProperties": true,
40
- "required": [
41
- "bbox",
42
- "category"
43
- ],
44
- "properties": {
45
- "bbox": {
46
- "type": "array",
47
- "minItems": 4,
48
- "maxItems": 4,
49
- "items": {
50
- "type": "number"
51
- }
52
- },
53
- "category": {
54
- "type": "string",
55
- "minLength": 1,
56
- "pattern": ".*\\S.*"
57
- },
58
- "text": {
59
- "type": "string"
60
- }
61
- }
62
- }
63
- }
64
- }
65
- }
@@ -1,136 +0,0 @@
1
- import { hostSchema, readHostInput, editorActions } from "./host-input.js";
2
- import { jsonOutput, bindAction, bindPreparedAction } from "./action-binding.js";
3
- import { contractSchema } from "../contracts/schema.js";
4
- import { CliUsageError } from "./errors.js";
5
- import { productText as text } from "../product/text.js";
6
- function editorApplyInputSchema() {
7
- const { $defs, ...actionArray } = contractSchema("editor.apply", "input");
8
- return {
9
- type: "object", additionalProperties: false, required: ["actions"], properties: { actions: actionArray },
10
- $defs: Object.fromEntries(Object.entries($defs)
11
- .map(([name, definition]) => [name, { ...definition, additionalProperties: true }]))
12
- };
13
- }
14
- export function registerEditorCommands(program, runtime) {
15
- const editor = program.command("editor")
16
- .description(text(runtime.product, "连接并操作 AI+ Editor", "Connect to and operate insMind Editor"))
17
- .helpCommand(false);
18
- editor.addHelpText("after", [
19
- "",
20
- text(runtime.product, "对象是已连接作品中的元素。用户提供附件图片/媒体链接并要求改字、分层、矢量化或其他图片处理时,先从 tool list 发现能力;无需为了这些操作新建 Board。", "This group operates elements in a connected work. For attached images or media links needing text replacement, decomposition, vectorization or other processing, discover tool list first; these operations do not require a new Board."),
21
- text(runtime.product, "操作一个当前 Session、当前 Page 的直属 Shape 和绑定 Connector;单操作者串行执行。", "Operate one current Session and its Page's direct Shapes and bound Connectors, serially with one operator."),
22
- text(runtime.product, "元素类型与字段以 editor apply --schema 为准;Schema 查询无需登录或连接 Editor。", "Discover element types and fields with editor apply --schema; no login or Editor connection is required."),
23
- text(runtime.product, "当前不支持嵌套元素、自由/半绑定 Connector、页面或选择修改;UNSUPPORTED_PAGE_CONTENT 时保留原作品并换用空白或专用 Page。", "Nested elements, free/half-bound Connectors, page and selection changes are unsupported. On UNSUPPORTED_PAGE_CONTENT, preserve the work and use a blank or dedicated Page."),
24
- text(runtime.product, "流程:connect → snapshot → apply → snapshot/screenshot 复查 → 按用户授权 save → disconnect。apply 不代替 save。只预览/暂不保存时停在预览;用户要求断开就执行 disconnect,断开不隐含保存。", "Workflow: connect → snapshot → apply → review snapshot/screenshot → save as authorized → disconnect. Apply does not replace Save. For preview-only requests stop at preview; on a request to disconnect, execute disconnect without implicitly saving."),
25
- text(runtime.product, "EDITOR_BUSY 时等待原命令结束;写入超时、取消或断连时,先重新连接同一作品并检查真实状态,不直接重试写入。", "On EDITOR_BUSY, wait for the original command. After a write times out, is cancelled or disconnects, reconnect to the same work and inspect its state before deciding what to do."),
26
- ""
27
- ].join("\n"));
28
- const connect = leaf(editor.command("connect"))
29
- .description(text(runtime.product, "打开并连接一个 AI+ Editor 作品", "Open and connect to an Editor work"))
30
- .argument("[target]", text(runtime.product, "已有作品的 ID 或完整 URL;留空会新建线上 Board", "existing work ID or full URL; omitting it creates a new production Board"));
31
- connect.addHelpText("after", [
32
- "",
33
- text(runtime.product, "继续已有作品时,传数字作品 ID 或完整 HTTP(S) URL。还没有目标就先向用户索取作品链接或 ID。用户要求新建时才省略 target。", "To continue an existing work, pass its numeric ID or supported insMind production Editor URL. If the target is missing, ask the user for the link or ID. Omit target only when the user requests a new Board."),
34
- text(runtime.product, "会打开浏览器并替换旧 Session;浏览器登录、加载、Board 类型、编辑/保存权限与页面内容检查通过后才成功。CLI 登录不能替代浏览器登录。", "Opens the browser and replaces the old Session. Browser login, loading, Board type, edit/save permission and page-content checks must pass. CLI credentials do not replace browser login."),
35
- text(runtime.product, "输出 JSON {target},不含连接凭证。连接失败时停止写入,让用户在页面处理登录或权限,再重新连接。", "Returns JSON {target} without connection credentials. On failure, stop writing and let the user resolve browser login or permissions before reconnecting."),
36
- text(runtime.product, "页面切换作品会断开 Session;EDITOR_NOT_READY、EDITOR_SESSION_NOT_FOUND 或 EDITOR_NOT_CONNECTED 时确认目标后重连,不轮询旧 Session。", "Switching works disconnects the Session. On EDITOR_NOT_READY, EDITOR_SESSION_NOT_FOUND or EDITOR_NOT_CONNECTED, verify the target and reconnect instead of polling the old Session."),
37
- ""
38
- ].join("\n"));
39
- jsonOutput(connect);
40
- bindPreparedAction(connect, "none", async (signal) => {
41
- signal.throwIfAborted();
42
- const target = connect.processedArgs[0];
43
- const input = typeof target === "string" ? { target } : {};
44
- runtime.validators.editorConnectInput(input);
45
- return { handled: false, input };
46
- }, async (_context, input, signal) => {
47
- const result = await runtime.telemetry.stage("editor.connect", () => runtime.editor.connect({ input, signal }));
48
- writeJson(runtime, result);
49
- });
50
- const disconnect = leaf(editor.command("disconnect"))
51
- .description(text(runtime.product, "断开当前 Editor 连接", "Disconnect the current Editor"));
52
- disconnect.addHelpText("after", `\n${text(runtime.product, "输出 JSON {disconnected},解除当前 CLI 会话连接,不保存作品、不关闭浏览器页面。需要保留修改且已获保存授权时先 save;用户只要求断开或明确不保存时直接断开,并说明未保存状态。", "Returns JSON {disconnected}, ending the CLI session without saving the work or closing its browser page. Save first only when persistence is intended and authorized; if the user requests only disconnection or no save, disconnect and state what remains unsaved.")}\n`);
53
- jsonOutput(disconnect);
54
- bindAction(disconnect, "none", async (_context, signal) => {
55
- writeJson(runtime, await runtime.telemetry.stage("editor.disconnect", () => runtime.editor.disconnect({ signal })));
56
- });
57
- const snapshot = leaf(editor.command("snapshot"))
58
- .description(text(runtime.product, "读取当前作品快照", "Read the current work snapshot"));
59
- snapshot.addHelpText("after", [
60
- "",
61
- text(runtime.product, "输出 JSON {elements, selectedIds};selectedIds 只读。元素字段和类型见 editor apply --schema。", "Returns JSON {elements, selectedIds}; selectedIds is read-only. Discover element fields and types with editor apply --schema."),
62
- text(runtime.product, "修改时以最新 Snapshot 中的完整元素为基础;每次 apply 后重新读取。UNSUPPORTED_PAGE_CONTENT 时停止并保留原作品。", "Base changes on complete elements from the latest Snapshot and read again after every Apply. On UNSUPPORTED_PAGE_CONTENT, stop and preserve the work."),
63
- ""
64
- ].join("\n"));
65
- jsonOutput(snapshot);
66
- bindAction(snapshot, "none", async (_context, signal) => {
67
- writeJson(runtime, await runtime.telemetry.stage("editor.snapshot", () => runtime.editor.snapshot({ signal })));
68
- });
69
- const apply = leaf(editor.command("apply"))
70
- .description(text(runtime.product, "按顺序应用元素操作", "Apply element operations in order"))
71
- .option("--schema", text(runtime.product, "输出输入 Schema,不执行操作", "output the input Schema without executing an operation"))
72
- .option("--input <file|->", text(runtime.product, "从文件或标准输入读取 JSON", "read JSON from a file or stdin"));
73
- apply.addHelpText("after", [
74
- "",
75
- text(runtime.product, "--schema 与 --input 必须且只能选择一个。Schema 为本地契约,不连接 Editor;执行成功输出 JSON {appliedCount}。", "Choose exactly one of --schema and --input. Schema reads the local contract without connecting to Editor; successful execution returns JSON {appliedCount}."),
76
- text(runtime.product, "先保存完整 JSON,再用 --input request.json 执行;--input - 必须在同一条 shell 命令中经管道或重定向提供完整 JSON,不交互填参。", "Save complete JSON before using --input request.json. With --input -, pipe or redirect complete JSON in the same shell command; input is not an interactive form."),
77
- text(runtime.product, "输入对象包含 host_application 和按序执行的 actions 数组;类型、必填字段与可选值见 --schema。使用简短语义 ID;create ID 必须唯一,Connector 可引用本批次更早创建的 Shape。", "Input is an object with host_application and an ordered actions array; discover types, required fields and choices with --schema. Use short semantic IDs. Create IDs must be unique; a Connector may reference a Shape created earlier in the batch."),
78
- text(runtime.product, "update 提交完整元素而非 patch,不改变 id 或 _type。delete 要求 ID 存在;删除 Shape 同时删除绑定的 Connector。", "Update requires the full element, not a patch, without changing id or _type. Delete requires an existing ID; deleting a Shape also deletes its bound Connectors."),
79
- text(runtime.product, "Shape 的 x/y 为 Page 左上角坐标,w/h 大于 0;数值必须有限。颜色用 #RRGGBB 或 #RRGGBBAA,仅 stroke 可为 null。Connector 用 fromId/toId 表达有方向的 Shape 关系。", "Shape x/y locate its top-left corner in Page coordinates; w/h must exceed zero and numbers must be finite. Colors use #RRGGBB or #RRGGBBAA; only stroke accepts null. Connector fromId/toId express a directed Shape relationship."),
80
- text(runtime.product, "整批先预检,再在可回滚事务中应用;INVALID_ACTIONS 时修正输入,APPLY_FAILED 时读 Snapshot 确认回滚。EDITOR_ROLLBACK_FAILED 时停止 apply/save,只读检查并报告。", "The batch is checked before one rollback-capable transaction. Correct INVALID_ACTIONS; on APPLY_FAILED read a Snapshot to confirm rollback. On EDITOR_ROLLBACK_FAILED, stop apply/save, inspect read-only and report."),
81
- text(runtime.product, "成功不表示已保存或视觉正确;读取新 Snapshot,涉及布局/文字/连线时查看截图。只预览时交付截图且不 save;需要持久化并已获授权时再显式 save。超时、取消或断连后先检查真实状态,不重复提交。", "Success proves neither persistence nor correct rendering. Read a new Snapshot and view a screenshot for layout/text/connectors. Deliver preview-only requests without save; explicitly save when persistence is intended and authorized. Inspect real state after timeout, cancellation or disconnection instead of resubmitting."),
82
- ""
83
- ].join("\n"));
84
- jsonOutput(apply);
85
- bindPreparedAction(apply, "none", async (signal) => {
86
- signal.throwIfAborted();
87
- const options = apply.opts();
88
- if (Number(options.schema === true) + Number(options.input !== undefined) !== 1)
89
- throw new CliUsageError();
90
- if (options.schema === true) {
91
- await runtime.telemetry.stage("output", () => { writeJson(runtime, hostSchema(runtime, editorApplyInputSchema())); });
92
- return { handled: true };
93
- }
94
- const input = editorActions(readHostInput(runtime, await runtime.jsonInput.read(options.input, signal)));
95
- return { handled: false, input };
96
- }, async (_context, input, signal) => {
97
- writeJson(runtime, await runtime.telemetry.stage("editor.apply", () => runtime.editor.apply({ input, signal })));
98
- }, {
99
- operation: "editor.apply",
100
- mode: () => apply.opts().schema === true ? "schema" : "execute"
101
- });
102
- const screenshot = leaf(editor.command("screenshot"))
103
- .description(text(runtime.product, "导出当前作品 PNG 截图", "Export a PNG screenshot of the current work"))
104
- .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
105
- screenshot.addHelpText("after", `\n${text(runtime.product, "将当前作品截图写入本机 PNG;--json 输出 {path},path 为绝对路径。打开实际图片检查文字、布局与连线,不以文件存在代替视觉验收。", "Writes a PNG screenshot locally; --json returns {path} with an absolute path. View the actual image to check text, layout and connectors; file existence is not visual verification.")}\n`);
106
- bindAction(screenshot, "none", async (_context, signal) => {
107
- const result = await runtime.telemetry.stage("editor.screenshot", () => runtime.editor.screenshot({ signal }));
108
- runtime.presenter.result(result, {
109
- json: screenshot.opts().json === true,
110
- view: value => text(runtime.product, `截图已保存至 ${value.path}`, `Screenshot saved to ${value.path}`)
111
- });
112
- });
113
- const save = leaf(editor.command("save"))
114
- .description(text(runtime.product, "保存当前 AI+ Editor 作品", "Save the current Editor work"))
115
- .option("--json", text(runtime.product, "输出 JSON", "output JSON"));
116
- save.addHelpText("after", [
117
- "",
118
- text(runtime.product, "等待真实持久化完成;--json 输出 {workId, url}。新 Board 首次保存创建作品 ID;原样交付公开 url,保留环境参数。", "Waits for real persistence; --json returns {workId, url}. A new Board gets its work ID on first save. Deliver the public url unchanged, retaining environment parameters."),
119
- text(runtime.product, "Save 最长等待 5 分 30 秒,其他 Editor RPC 默认 1 分钟;继续等待原命令,保持串行。成功前不得报告已保存。", "Save waits up to 5 minutes 30 seconds; other Editor RPCs default to one minute. Keep waiting on the original command and run serially. Do not report persistence before success."),
120
- text(runtime.product, "SAVE_FAILED 时保留 Session 并处理明确原因;超时、取消或断连不表示未保存,先重连同一作品检查真实状态。EDITOR_ROLLBACK_FAILED 时不得继续保存。", "On SAVE_FAILED retain the Session and resolve the stated cause. Timeout, cancellation or disconnection does not prove failure to save; reconnect to the same work and inspect first. Do not save after EDITOR_ROLLBACK_FAILED."),
121
- ""
122
- ].join("\n"));
123
- bindAction(save, "none", async (_context, signal) => {
124
- const result = await runtime.telemetry.stage("editor.save", () => runtime.editor.save({ signal }));
125
- runtime.presenter.result(result, {
126
- json: save.opts().json === true,
127
- view: value => text(runtime.product, `作品已保存:${value.url}`, `Work saved: ${value.url}`)
128
- });
129
- });
130
- }
131
- function leaf(command) {
132
- return command.allowExcessArguments(false);
133
- }
134
- function writeJson(runtime, value) {
135
- runtime.io.writeOut(`${JSON.stringify(value)}\n`);
136
- }