@alpsckr/unitycli 0.4.0 → 0.4.2

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 (98) hide show
  1. package/README.md +111 -299
  2. package/contracts/init-contract.json +64 -0
  3. package/contracts/instances-contract.json +49 -0
  4. package/contracts/package-assembly-closure.json +33 -0
  5. package/contracts/package-files.json +1953 -0
  6. package/dist/bridge/session-supervisor.d.ts +2 -0
  7. package/dist/bridge/session-supervisor.js +52 -19
  8. package/dist/bridge/session-supervisor.js.map +1 -1
  9. package/dist/cli-commands/command.js +33 -15
  10. package/dist/cli-commands/command.js.map +1 -1
  11. package/dist/cli-commands/init-discovery.d.ts +11 -0
  12. package/dist/cli-commands/init-discovery.js +185 -0
  13. package/dist/cli-commands/init-discovery.js.map +1 -0
  14. package/dist/cli-commands/init-help.d.ts +3 -0
  15. package/dist/cli-commands/init-help.js +41 -0
  16. package/dist/cli-commands/init-help.js.map +1 -0
  17. package/dist/cli-commands/init-skill.d.ts +10 -0
  18. package/dist/cli-commands/init-skill.js +171 -0
  19. package/dist/cli-commands/init-skill.js.map +1 -0
  20. package/dist/cli-commands/instances.d.ts +4 -0
  21. package/dist/cli-commands/instances.js +90 -0
  22. package/dist/cli-commands/instances.js.map +1 -0
  23. package/dist/cli-commands/package.d.ts +2 -2
  24. package/dist/cli-commands/package.js +97 -130
  25. package/dist/cli-commands/package.js.map +1 -1
  26. package/dist/cli-commands/skill-installer.d.ts +29 -13
  27. package/dist/cli-commands/skill-installer.js +127 -88
  28. package/dist/cli-commands/skill-installer.js.map +1 -1
  29. package/dist/cli-commands/types.d.ts +4 -0
  30. package/dist/cli.d.ts +1 -1
  31. package/dist/cli.js +46 -37
  32. package/dist/cli.js.map +1 -1
  33. package/dist/contracts/command-contract.js +1 -0
  34. package/dist/contracts/command-contract.js.map +1 -1
  35. package/dist/doctor.js +1 -1
  36. package/dist/doctor.js.map +1 -1
  37. package/dist/instances.d.ts +1 -1
  38. package/dist/instances.js +63 -38
  39. package/dist/instances.js.map +1 -1
  40. package/dist/output.d.ts +4 -4
  41. package/dist/output.js +3 -4
  42. package/dist/output.js.map +1 -1
  43. package/dist/package-manager.d.ts +47 -2
  44. package/dist/package-manager.js +267 -16
  45. package/dist/package-manager.js.map +1 -1
  46. package/dist/tools/.generated-schemas.js +2 -2
  47. package/dist/tools/.generated-schemas.js.map +1 -1
  48. package/dist/tools/commands.js +11 -4
  49. package/dist/tools/commands.js.map +1 -1
  50. package/dist/tools/dispatcher.js +1 -1
  51. package/dist/tools/dispatcher.js.map +1 -1
  52. package/dist/tools/tools/group-list.d.ts +4 -8
  53. package/dist/tools/tools/group-list.js +12 -13
  54. package/dist/tools/tools/group-list.js.map +1 -1
  55. package/dist/tools/tools/pagination.d.ts +17 -0
  56. package/dist/tools/tools/pagination.js +28 -0
  57. package/dist/tools/tools/pagination.js.map +1 -0
  58. package/dist/tools/tools/search.d.ts +3 -5
  59. package/dist/tools/tools/search.js +12 -12
  60. package/dist/tools/tools/search.js.map +1 -1
  61. package/dist/unity-project-processes.d.ts +7 -0
  62. package/dist/unity-project-processes.js +54 -0
  63. package/dist/unity-project-processes.js.map +1 -1
  64. package/docs/README.md +7 -4
  65. package/docs/architecture.md +103 -0
  66. package/docs/availability-differences.md +1 -1
  67. package/docs/command-execution.md +6 -1
  68. package/docs/development.md +91 -0
  69. package/docs/error-codes.md +21 -5
  70. package/docs/extensions.md +13 -13
  71. package/docs/target-and-instance.md +6 -4
  72. package/docs/tool-discovery.md +12 -10
  73. package/docs/tool-execution.md +3 -2
  74. package/package.json +10 -4
  75. package/schemas/init.schema.json +209 -0
  76. package/schemas/instances.schema.json +104 -0
  77. package/skills/unitycli/SKILL.md +18 -6
  78. package/skills/unitycli/manifest.json +2 -2
  79. package/skills/unitycli/references/custom-tools.md +3 -3
  80. package/skills/unitycli/references/operation-protocol.md +6 -4
  81. package/skills/unitycli/reports/output_quality_scorecard.md +1 -1
  82. package/skills/unitycli/reports/trust-report.md +1 -1
  83. package/unitypkg/Editor/Bridge/BridgeCommandRegistry.cs +1 -0
  84. package/unitypkg/Editor/Bridge/BridgeWorkQueue.cs +18 -6
  85. package/unitypkg/Editor/Infrastructure/CodeExecSupport.cs +8 -77
  86. package/unitypkg/Editor/Infrastructure/UnityCliInstanceCleanup.cs +295 -0
  87. package/unitypkg/Editor/Infrastructure/UnityCliInstanceRegistry.cs +166 -10
  88. package/unitypkg/Editor/Infrastructure/UnityCliOperationCoordinator.cs +1 -0
  89. package/unitypkg/Editor/UnityCliBridge.cs +5 -1
  90. package/unitypkg/Tests/Editor/UnityCliInstanceCleanupTests.cs +232 -0
  91. package/unitypkg/Tests/Editor/UnityCliInstancePublicationRetryTests.cs +143 -0
  92. package/unitypkg/UnityCli.Editor.asmdef +1 -5
  93. package/unitypkg/package.json +1 -1
  94. package/unitypkg/Editor/Roslyn/LICENSE.txt +0 -23
  95. package/unitypkg/Editor/Roslyn/Microsoft.CodeAnalysis.CSharp.dll +0 -0
  96. package/unitypkg/Editor/Roslyn/Microsoft.CodeAnalysis.dll +0 -0
  97. package/unitypkg/Editor/Roslyn/System.Collections.Immutable.dll +0 -0
  98. package/unitypkg/Editor/Roslyn/System.Reflection.Metadata.dll +0 -0
package/README.md CHANGED
@@ -1,389 +1,201 @@
1
1
  # UnityCLI
2
2
 
3
- CLI-first Unity 自动化工具,不是 MCP server。通过 `unitycli` 二进制命令行直接驱动 Unity Editor,无需额外协议层。
3
+ Windows-first Unity Editor automation CLI for AI agents. The executable is `unitycli`; the npm package is `@alpsckr/unitycli`; the Unity Package is `com.alpsckr.unitycli`.
4
4
 
5
- npm 包名:`@alpsckr/unitycli`
6
- 运行环境:Windows + Node.js 20+
7
- 当前方向:冻结决策 - 独立 CLI 实现、Windows-only、npm-first 安装;公开 Tool 与 CLI 控制面调用即授权。
5
+ ## Requirements
8
6
 
9
- ## Project Baseline
7
+ - Windows
8
+ - Node.js 20 or newer
9
+ - Unity 2022.3 or newer
10
+ - A Unity project when installing the Bridge
11
+ - An opened Unity Editor only when using live Unity capabilities; installation may normally close only the exact target Editor after explicit user approval
10
12
 
11
- 本节是项目基线,优先级高于本文档其他章节、历史实现、旧示例和当前代码状态。AI 和后续实现不得自行修改本节含义;如需调整,必须由项目所有者明确确认。
13
+ ## Install
12
14
 
13
- ### 1. Clean Project Semantics
14
-
15
- 本项目是开发中项目,不承担旧版本兼容义务。
16
-
17
- 项目代码、文档、命令形态和注释必须表达当前项目规范。发现旧语义、阶段性语义或兼容性语义时,应统一改为当前规范;无法干净迁移时,优先删除,而不是保留多套说法。
18
-
19
- ### 2. Top-Level CLI Shape
20
-
21
- 用户可见顶层命令分为两类:能力入口和 CLI 控制面。
22
-
23
- 能力入口只允许:
24
-
25
- - `tools`
26
- - `command`
27
-
28
- CLI控制面只允许:
29
-
30
- - `init`
31
- - `extensions`
32
- - `target`
33
- - `instances`
34
- - `doctor`
35
-
36
- Unity项目内容与Editor能力域必须进入唯一Tool catalog,例如scene、asset、game-object、prefab、editor、screenshot、package、docs、reflect、build、test、code、profiler、physics、graphics等。`tools run <tool> --input <json>`与`command <name> <business-args>`只是同一descriptor和dispatcher的两种调用语法。
37
-
38
- `target`、`instances`、`doctor` 是 CLI 自身的状态、路由和诊断控制面;它们可以作为顶层命令存在,但不得重新引入 Unity 能力域的顶层入口。
39
-
40
- 内部 Bridge、协调器和 registry 可以作为实现细节存在,但不得定义超出上述清单的用户可见顶层命令形态。
41
-
42
- 本产品只吸收必须由已打开 Unity Editor 或 development Player 提供的项目内自动化价值。auth、Unity Hub、Editor 安装或打开、Cloud、License 和 proxy 配置属于外部控制面,必须直接使用系统或官方控制面工具,不进入 Tool catalog,也不新增顶层命令。
43
-
44
- ### 3. AI-First Tool Interface
45
-
46
- 本 CLI 主要提供给 AI 使用。项目哲学不是维护一套面向人工记忆的传统命令手册,而是提供可发现、可描述、可审计的工具目录。
47
-
48
- AI 的标准流程是:
49
-
50
- ```text
51
- unitycli tools group/search
52
- unitycli tools describe <tool>
53
- unitycli tools run <tool> --input <json>
54
- unitycli command
55
- unitycli command <name> --field <value>
56
-
57
- unitycli target alias list/set/unset
58
- unitycli instances list/prune
59
- unitycli doctor
60
-
61
- unitycli extensions list/install/remove/doctor
62
- unitycli init
63
- ```
64
-
65
- 具体有哪些工具、工具参数是什么、风险边界是什么,应由AI通过本CLI内置的`tools group/search/describe`自发现。省略name的`command`只返回同一live catalog的command投影,不是第二份能力目录。
66
-
67
- ## 快速开始
15
+ Install the CLI once for the current user:
68
16
 
69
17
  ```powershell
70
- # 安装
71
18
  npm install -g @alpsckr/unitycli
19
+ ```
72
20
 
73
- # 初始化项目(安装 Bridge 包;若项目已有 .pi/.claude/.agents,则自动安装 Skill)
74
- unitycli init --project C:\path\MyProject
21
+ Start your AI in the directory where you normally work and tell it:
75
22
 
76
- # Bridge AutoStart默认开启;项目级开关位于Unity的Project Settings > UnityCLI
77
- # 修改后从下一次Domain Reload或Editor启动生效
23
+ > 执行 unitycli init help,然后照做。
78
24
 
79
- # 查看帮助
80
- unitycli --help
81
- unitycli --version
82
- ```
25
+ `init help` contains the complete AI installation protocol. Read-only discovery uses the unique current Unity project and workspace without asking you to repeat them, reports the installed and available Bridge versions, and accepts any exact Skill directory you already named. It asks only when a real choice remains, including permission to normally close the exact target Unity Editor before replacing an in-use Bridge. It never force-terminates Unity or decides an unsaved-scene prompt.
83
26
 
84
- ## 核心使用流程
27
+ ## Manual Setup
85
28
 
86
- ### 1. 发现目标实例
29
+ Read the same protocol and inspect the current directory:
87
30
 
88
31
  ```powershell
89
- # 默认只列非 offline 实例;hiddenOfflineCount 表示被隐藏数量
90
- # invalidRecordCount 出现时表示旧/坏记录已隔离,合法v3实例仍会返回
91
- unitycli instances list
92
- # 需要审计历史/offline 合法记录时显式展开
93
- unitycli instances list --all
94
-
95
- # 已知实例时,在后续每条 Bridge 命令上显式传入
96
- unitycli tools group --instance <instanceId>
97
- # 可先创建稳定别名,再继续显式传入
98
- unitycli target alias set <instanceId> my-project
99
- unitycli tools group --instance my-project
32
+ unitycli init help
33
+ unitycli init discover
100
34
  ```
101
35
 
102
- ### 2. 发现工具能力(group-first 路径)
103
-
104
- 推荐按组逐层发现,避免一次展开全量工具:
36
+ Install or repair the Bridge in one explicit Unity project. Use `--close-editor` only after the user approves normally closing that exact project:
105
37
 
106
38
  ```powershell
107
- # 第一步:查看工具分组
108
- unitycli tools group
109
-
110
- # 第二步:按组查看工具摘要
111
- unitycli tools group list camera
112
- # 或搜索关键词(使用 | 分隔多关键词,OR 匹配;PowerShell必须单引号包住整段)
113
- unitycli tools search 'screenshot|camera'
114
-
115
- # 第三步:查看工具完整描述(执行前必做)
116
- unitycli tools describe camera.screenshot
117
-
118
- # 第四步:执行工具
119
- unitycli tools run camera.screenshot --input '{"target":"Main Camera","output":"Artifacts/shot.png"}'
39
+ unitycli init package --project C:\path\UnityProject
40
+ unitycli init package --project C:\path\UnityProject --close-editor
41
+ unitycli init package --project C:\path\UnityProject --check
120
42
  ```
121
43
 
122
- ### 3. 获取只读项目信息
123
-
124
- 当前版本通过 `docs.get/search` 查询 Unity API 文档,通过 `reflect.*` 查询类型缓存;这些 Tool 仍从已连接实例的统一 catalog 发现和调用:
44
+ Install or check an exact user-selected Skill directory, including Pi:
125
45
 
126
46
  ```powershell
127
- # Unity API 文档
128
- unitycli tools run docs.get UnityEngine.Camera
129
- unitycli tools run docs.search "Render Pipeline"
130
-
131
- # 类型反射
132
- unitycli tools run reflect.type UnityEngine.Camera
133
- unitycli tools run reflect.member UnityEngine.Camera.fieldOfView
47
+ unitycli init skill --target C:\path\Workspace\.pi\skills\unitycli
48
+ unitycli init skill --target C:\path\Workspace\.pi\skills\unitycli --check
134
49
  ```
135
50
 
136
- > **注意**:项目与 Editor 状态同样通过 `tools group/search/describe/run` 发现和读取;读取型 Tool 明确声明无副作用。
137
-
138
- ### 4. 项目注册能力
139
-
140
- Unity 项目可通过异步 C# `IUnityCliTool<TReq,TRes>` 注册能力;完成编译后自动进入该实例的完整目录,与 package 内置和 Extension 能力使用同一路径:
51
+ Generic Agent Skills remain available as a preset:
141
52
 
142
53
  ```powershell
143
- # 从当前实例目录发现真实 group
144
- unitycli tools group --instance <id|projectPath|alias>
145
-
146
- # 描述并执行项目 Tool
147
- unitycli tools describe my.custom-tool --instance <id|projectPath|alias>
148
- unitycli tools run my.custom-tool --input '{"key":"value"}' --instance <id|projectPath|alias>
54
+ unitycli init skill --agent .agents --scope workspace --workspace C:\path\Workspace
55
+ unitycli init skill --agent .agents --scope workspace --workspace C:\path\Workspace --check
149
56
  ```
150
57
 
151
- > **注意**:不要假设项目能力位于 `custom` 分组。可通过 `extensions list` 查看已安装扩展,`extensions install <id>` / `extensions remove <id>` 管理扩展,`extensions doctor` 诊断扩展状态。
152
-
153
- ### 5. 使用command语法
154
-
155
- `command`按目标Tool的live `inputSchema`解析named、attached、boolean裸开关和声明顺序positional参数,然后进入与`tools run`相同的dispatcher和JSON envelope:
58
+ Install or check Claude Skills in one workspace:
156
59
 
157
60
  ```powershell
158
- # 列出当前实例可调用名称
159
- unitycli command --project-path C:\path\MyProject
160
-
161
- # native Tool使用完整Tool名
162
- unitycli command editor.compile --refresh true --includeWarnings true
163
-
164
- # [CliCommand("test")]在tools中名为UnityPipeline_test,command可用attribute原名
165
- unitycli command test --mode EditMode
166
- unitycli command UnityPipeline_test --mode EditMode
61
+ unitycli init skill --agent claude --scope workspace --workspace C:\path\Workspace
62
+ unitycli init skill --agent claude --scope workspace --workspace C:\path\Workspace --check
167
63
  ```
168
64
 
169
- 命令名和业务字段exact匹配,不做snake_case、camelCase、相似名称或语义映射。native完整精确名优先;重名attribute仍通过`UnityPipeline_`完整名调用。
170
-
171
- `com.unity.pipeline` package自身的attribute命令已由native能力矩阵吸收,不进入live目录;项目和其他Package声明的`[CliCommand]`继续正常导入。本package首次检测到Pipeline时只执行一次`AutoStart=false`持久化和当前server停服,成功后不再覆盖用户后续手动操作。
172
-
173
- ### 6. 诊断与健康检查
65
+ Install or check one user-level Skill:
174
66
 
175
67
  ```powershell
176
- # 运行完整诊断
177
- unitycli doctor
68
+ unitycli init skill --agent .agents --scope user
69
+ unitycli init skill --agent .agents --scope user --check
178
70
 
179
- # 诊断预检(通过 Bridge)
180
- unitycli tools run diagnose.preflight
71
+ unitycli init skill --agent claude --scope user
72
+ unitycli init skill --agent claude --scope user --check
181
73
  ```
182
74
 
183
- ## 安全边界
75
+ Preset workspace and user scope are separate choices. An exact `--target` is final user intent and cannot be combined with preset agent/scope options. Bridge and Skill are independently authorized effects; failure of one does not invalidate or block the other.
184
76
 
185
- | 规则 | 说明 |
186
- |------|------|
187
- | Tool 可有副作用 | 调用即授权;`destructiveHint`、`sideEffects` 与 `supportsDryRun` 仅描述风险和可选预览 |
188
- | 读取型 Tool 纯只读 | 读取型 Tool 不触发写入、import、compile、domain reload 或 PlayMode 变化 |
189
- | Extension 不能绕过 descriptor/envelope | 项目工具必须可描述、可审计、可阻断 |
190
- | 内部完整性不匹配默认阻止 | 自定义工具的 handler 代码与 descriptor 不一致时,默认阻止执行 |
77
+ ## Verify And Diagnose
191
78
 
192
- ## 安装与构建
79
+ Package and Skill checks are read-only:
193
80
 
194
81
  ```powershell
195
- # 全局安装
196
- npm install -g @alpsckr/unitycli
197
-
198
- # 本地开发
199
- npm install
200
- npm run build
201
- npm test
202
- npm link
203
- ```
204
-
205
- ## 输出格式
206
-
207
- 所有命令输出统一 JSON envelope:
208
-
209
- ```json
210
- {
211
- "ok": true,
212
- "requestId": "req-xxx",
213
- "data": { ... }
214
- }
82
+ unitycli init package --project C:\path\UnityProject --check
83
+ unitycli init skill --target C:\path\Workspace\.pi\skills\unitycli --check
84
+ unitycli init skill --agent .agents --scope workspace --workspace C:\path\Workspace --check
215
85
  ```
216
86
 
217
- 错误输出:
87
+ After the user opens or refreshes Unity, inspect registered Editor sessions:
218
88
 
219
- ```json
220
- {
221
- "ok": false,
222
- "requestId": "req-xxx",
223
- "error": {
224
- "code": "E_INSTANCE_CONFLICT",
225
- "message": "...",
226
- "transient": false,
227
- "nextActions": ["Close duplicate Editor sessions for the selected project."],
228
- "retryAfterMs": 0
229
- }
230
- }
89
+ ```powershell
90
+ unitycli instances list
91
+ unitycli instances prune --instance C:\path\UnityProject
92
+ unitycli doctor --project C:\path\UnityProject
231
93
  ```
232
94
 
233
- ## Live Editor 执行
95
+ `instances list`默认隐藏offline记录;`instances list --all`仅用于展开审计。Unity启动、编译或重载时,live命令会在本次timeout内等待当前连接ready。旧格式、损坏或不可读记录会逐文件隔离,不阻断合法实例,并通过`invalidRecordCount`返回数量;当前项目由Unity自动恢复。需要清理历史记录时运行`instances prune --instance <id|projectPath|alias>`并检查`removed`、`remaining`和`deferred`,不要手工读取或删除内部文件。
234
96
 
235
- 需要 Unity 执行的 Tool 只连接已打开的 Unity Editor,并在同一次 direct 调用中返回最终业务结果。`build.run`、`test.run`、`editor.refresh`、`code.exec` 以及需要 Editor 刷新的 Package Tool 都会等待终态;它们不创建可查询的后台任务。每个live Editor/Development Player session使用默认5/3任务池,CLI在业务请求前自动等待放行。`--timeout-ms T`分别提供最多`T`的准入等待与放行后最多`T`的执行预算;调用CLI的外层进程必须等待CLI退出,host预算至少为`2 * T + 5000`毫秒。准入`E_UNITY_BUSY`证明业务请求未发送;放行后的`E_EXECUTION_TIMEOUT`仍是outcome unknown。CLI在stdout写完或最多再等待1秒后退出。
97
+ To create a stable selector:
236
98
 
237
- `code.exec`保留完整同步C#执行能力:它不会拒绝死循环、阻塞等待或长期占用Unity主线程的代码。提交这类代码前应先判断是否确有必要;一旦开始执行,timeout只能停止CLI等待,不能中止代码,结果可能未知且Unity可能需要结束进程才能恢复。CLI进程退出也不证明Unity中的C#已停止。完整边界见`tools describe code.exec`和`docs/safety-boundaries.md`。
99
+ ```powershell
100
+ unitycli target alias set C:\path\UnityProject my-project
101
+ unitycli target alias list
102
+ ```
238
103
 
239
- ## 能力发现与执行
104
+ ## First Unity Call
240
105
 
241
- 公开能力不维护静态命令清单。Tool 的当前输入 schema、可用性、示例与调用边界以 CLI discovery 为准;结果 schema 留在内部 contract 中校验实际业务 data:
106
+ With the selected Unity project open and ready:
242
107
 
243
108
  ```powershell
244
- unitycli tools group
245
- unitycli tools group list <group>
246
- unitycli tools search <k1|k2|...>
247
- unitycli tools describe <tool-name>
248
- unitycli tools run <tool-name> --input '<json>' [--instance <id|projectPath|alias>]
109
+ unitycli tools group --instance C:\path\UnityProject
110
+ unitycli tools search 'editor|state' --instance C:\path\UnityProject
111
+ unitycli tools describe editor.state --instance C:\path\UnityProject
112
+ unitycli tools run editor.state --input '{}' --instance C:\path\UnityProject
249
113
  ```
250
114
 
251
- Tool discovery 必须绑定已连接实例;未连接时返回稳定 instance error,不返回静态或空目录。连接后完整显示 package 内置、Extension、项目注册、Editor Runtime 能力,不按 `source` 或当前模式过滤。`source` 只作内部描述/审计。`examples[].input` 是结构化业务 JSON,按需 `examples[].execution` 承载 dryRun/timeoutMs;调用方明确要求的业务值优先于schema default和example值。业务参数全部放入 `--input`、`--input-file` `--stdin`,命令控制项不混入业务 JSON。
252
-
253
- Bridge-backed Tool在Unity主线程执行。CLI使用Registry/Health v3与只读内存pulse,在一个不可变deadline内处理compile、import、domain reload和listener generation交接。mutation只允许在同一`editorSessionId`内用完全相同的请求续接;首次POST后session改变时禁止向新session重投,并返回outcome unknown的`E_EXECUTION_TIMEOUT`。`unitycli tools run editor.state --input '{}'`、`editor.dialogs`与`editor.dialog.click`使用exact frozen本地descriptor进入同一dispatcher,因此统一状态观察和弹窗恢复不依赖被阻断的Live catalog;其他Tool仍严格依赖Live catalog。
115
+ Do not guess Tool names or inputs. Discover the current catalog, read one descriptor, then call that exact Tool. `command <name>` is a schema-argument projection of the same live catalog, not a second capability system.
254
116
 
255
- ### 实例与目标
117
+ Optional extensions use their dedicated control plane:
256
118
 
257
119
  ```powershell
258
- # 默认隐藏 offline,使用 --all 展开完整集合
259
- unitycli instances list
260
- unitycli instances list --all
261
- unitycli instances prune
120
+ unitycli extensions list --project C:\path\UnityProject
121
+ unitycli extensions install <id> --project C:\path\UnityProject
122
+ unitycli extensions remove <id> --project C:\path\UnityProject
123
+ unitycli extensions doctor --project C:\path\UnityProject
262
124
  ```
263
125
 
264
- 实例文件逐个按Registry v3校验。旧格式、损坏或不可读记录不会阻断其他合法实例,也不会被兼容解析或自动删除;存在时list/prune返回`invalidRecordCount`,`doctor`报告warn。显式选择对应坏记录仍严格失败。
126
+ Discovery lists default to 20 items, allow at most 100, and continue with `pageInfo.nextCursor`:
265
127
 
266
128
  ```powershell
267
- # target 只管理 canonical project identity 的别名
268
- unitycli target alias set <projectPath|instanceId> <alias>
269
- unitycli target alias unset <alias>
270
- unitycli target alias list
129
+ unitycli tools group list <group> --page-size 20 --instance <id|projectPath|alias>
130
+ unitycli tools search '<k1|k2|...>' --page-size 20 --instance <id|projectPath|alias>
131
+ unitycli command --project-path C:\path\UnityProject --page-size 20
271
132
  ```
272
133
 
273
- 实例与目标属于 CLI 控制面,只使用顶层 `instances` / `target`;不要通过 `tools run` 包装这些控制面状态。
134
+ In PowerShell, quote pipe-separated search keywords with single quotes.
274
135
 
275
- `doctor`、`instances`、`target alias` 和 `extensions` 属于 CLI 控制面。扩展源码以 `extensions/<id>/` 组织,安装后投影到 `Packages/com.alpsckr.unitycli/Extensions/<id>/`;Extension 贡献的 Tool 仍通过统一 discovery 入口发现。
136
+ ## Output
276
137
 
277
- ## 初始化(init)
138
+ Every command returns one JSON envelope. stdout is compact single-line JSON by default; use `--pretty` only for indented output.
278
139
 
279
- `init` 安装捆绑的 `com.alpsckr.unitycli` Bridge 包到目标 Unity 项目;如果项目根目录已经存在 `.pi`、`.claude` 或 `.agents`,会自动安装对应 AI Agent Skill。也可以用 `--agent` 显式指定目标。Skill 以 `SKILL.md`、`references/**`、`scripts/**` 完整 runtime bundle 安装,`--check` 校验全部 managed 文件;更新会保留已安装 `SKILL.md` 中合法的 `FeedbackMode: off|on`。
140
+ Success:
280
141
 
281
- | 标志 | 含义 |
282
- |------|------|
283
- | *(none)* | 安装/更新 Bridge 包(copy 模式),并为已存在的 Agent 目录安装 Skill |
284
- | `--pkg-only` | 仅安装 Bridge 包,不安装 Skill |
285
- | `--skill-only [--agent <agent>]` | 仅安装 Skill;未传 `--agent` 时使用已存在的 Agent 目录 |
286
- | `--check` | 检查安装状态,不修改项目 |
287
- | `--agent <pi\|claude\|.agents,...>` | 显式指定 Skill 安装目标 |
288
-
289
- ```powershell
290
- # 默认安装 Bridge;若项目已有 .pi/.claude/.agents,则自动安装 Skill
291
- unitycli init --project C:\path\MyProject
292
-
293
- # 仅 Bridge 包
294
- unitycli init --project C:\path\MyProject --pkg-only
295
-
296
- # 显式安装 Skill 到 pi
297
- unitycli init --project C:\path\MyProject --skill-only --agent pi
298
-
299
- # 检查安装状态;未传 --agent 时同样会检查已存在的 Agent 目录
300
- unitycli init --check --project C:\path\MyProject
142
+ ```json
143
+ {"ok":true,"requestId":"req-...","data":{}}
301
144
  ```
302
145
 
303
- `FeedbackMode` 默认 `off`。改为 `on` 后,使用该 Skill 的 Agent 只在实际遇到失败、歧义、缺失、误导或成功绕过的坑点时,调用 bundle 内 recorder 写入 `%LOCALAPPDATA%\UnityCli\feedback\` 的有界 JSONL;正常调用不记录,也不联网。
304
-
305
- ## Unity Editor Bridge
146
+ Failure:
306
147
 
307
- `init` 以 copy 模式把 `com.alpsckr.unitycli` 安装到 `Packages/com.alpsckr.unitycli/`。已打开的 Unity Editor 自动注册 canonical project identity 和 Live listener;CLI 通过 `instances list` 与 `--instance` 选择唯一会话,公开接口不接受 endpoint 或 port。
308
-
309
- Bridge command、handler、journal、fingerprint、listener generation和completion contract都是内部实现,不构成第二套用户入口。mutation在首个真实effect前持久化effect barrier;effect后只有fresh business readback或artifact proof能完成。同一次调用只在`editorSessionId`不变时续接完全相同的请求;首次POST后session改变则禁止重投。无法证明终态时返回`E_EXECUTION_TIMEOUT`,调用方先观察业务状态,再作全新提交决策。
148
+ ```json
149
+ {"ok":false,"requestId":"req-...","error":{"code":"...","message":"...","nextActions":[],"transient":false,"retryAfterMs":0}}
150
+ ```
310
151
 
311
- 当前能力、Extension 依赖和 Editor/PlayMode 可用性只通过 `tools` discovery 获取,不在 README 冻结能力名清单。
152
+ Follow structured `nextActions`. With `--timeout-ms T`, use a host budget of at least `2 * T + 5000` milliseconds and wait for the unitycli process to exit. `E_EXECUTION_TIMEOUT` means no trusted terminal result; timeout does not stop Unity effects or synchronous C# already running. Inspect business state before deciding whether to submit a new mutation.
312
153
 
313
- ## 项目自定义工具(Custom Tools)
154
+ ## Update And Remove
314
155
 
315
- Unity 项目 C# 代码可通过异步 `IUnityCliTool<TReq,TRes>` 注册自定义能力。schema DTO 派生;Tool 必须声明完整 direct completion contract,并在全部可预见校验后、首个 mutation 前调用一次 `ctx.CommitEffect()`。当前接口与完整示例见 [Custom Tools](skills/unitycli/references/custom-tools.md)。
156
+ Update the global CLI, then let the AI run the installation protocol again:
316
157
 
317
158
  ```powershell
318
- unitycli tools group --instance <id|projectPath|alias>
319
- unitycli tools group list <real-group> --instance <id|projectPath|alias>
320
- unitycli tools describe my.editor-tool --instance <id|projectPath|alias>
321
- unitycli tools run my.editor-tool --input '{"message":"hello"}' --instance <id|projectPath|alias>
159
+ npm install -g @alpsckr/unitycli@latest
160
+ unitycli init help
322
161
  ```
323
162
 
324
- ### 统一 Tool target
325
-
326
- 所有能力都以 Tool 呈现。`target: "editor" | "runtime" | "both"` 只是可用性与路由约束,不是两套用户入口。
327
-
328
- `runtime` 表示 Unity gameplay/runtime layer;具体 tool 是否需要 Play Mode,由 `availabilityScope` 和 `nextActions` 说明。
163
+ To remove a workspace or user Skill, delete only the selected `unitycli` Skill directory:
329
164
 
330
- ### 安全机制
165
+ ```text
166
+ <explicit-target>/unitycli
167
+ <workspace>/.agents/skills/unitycli
168
+ <workspace>/.claude/skills/unitycli
169
+ ~/.agents/skills/unitycli
170
+ ~/.claude/skills/unitycli
171
+ ```
331
172
 
332
- - **Descriptor**:公开 describe 提供完整 inputSchema 与调用/风险信息;内部 metadata 保留 outputSchema 并校验业务结果
333
- - **Envelope**:所有输入输出必须通过统一 envelope 格式
334
- - **内部完整性校验**:handler 与 descriptor 不一致时默认阻止执行
335
- - **target-scoped availability**:工具可用性依赖目标实例和 Play Mode 状态
336
- - **禁止项**:不允许任意方法调用、反射 escape hatch、绕过 registry 直接执行
173
+ To remove the managed Bridge, first inspect the current `package.bridge-remove` descriptor and follow it:
337
174
 
338
- ## ProBuilder 扩展
175
+ ```powershell
176
+ unitycli tools describe package.bridge-remove --instance C:\path\UnityProject
177
+ ```
339
178
 
340
- ProBuilder 工具需要项目先安装精确版本 `com.unity.probuilder@5.2.4`,再安装 CLI 扩展目录;其他版本不执行基于 5.2.4 源码闭合的 mutation proof:
179
+ Remove the global CLI with:
341
180
 
342
181
  ```powershell
343
- unitycli extensions install probuilder --project <project>
344
- unitycli tools group list probuilder --instance <id|projectPath|alias>
345
- unitycli tools describe probuilder.create-shape --instance <id|projectPath|alias>
346
- unitycli tools run probuilder.create-shape --input '{"shapeType":"Cube","name":"MyCube"}' --instance <id|projectPath|alias>
182
+ npm uninstall -g @alpsckr/unitycli
347
183
  ```
348
184
 
349
- ## 风险与副作用
350
-
351
- 公开 Tool 与 CLI 控制面调用本身即授权。`destructiveHint`、`sideEffects` 和 `supportsDryRun` 让调用方了解效果与可选预览,但不会触发额外确认、预定义按钮列表或意图复核。支持 dry-run Tool 可用 `--dry-run` 返回 `plannedEffects` 而不执行实际 mutation;不使用它不会阻止调用。
352
-
353
- ## 扩展能力概览
354
-
355
- | 扩展类型 | 当前状态 | 发现方式 |
356
- |----------|---------|---------|
357
- | 项目自定义 Tool (`target=editor`) | ✅ 已实现 | 当前实例 `tools group/list/describe/run` |
358
- | 项目自定义 Tool (`target=runtime`) | ✅ 已实现 | 当前实例 `tools group/list/describe/run`;EditMode 仍显示,执行通常需 PlayMode |
359
- | 扩展包管理 | ✅ 已实现 | `extensions list/install/remove/doctor` |
360
- | ProBuilder 扩展 | ✅ 已实现 | `tools group/list/describe/run`(需要 `com.unity.probuilder@5.2.4` + `extensions install probuilder`) |
361
- | Cinemachine/VFX/URP/HDRP 扩展 | ✅ 已实现 | `tools group/list/describe/run`(需要对应 Unity package + `extensions install <id>`) |
362
-
363
- ## 更多文档
364
-
365
- - [文档索引](docs/README.md) — 当前使用、扩展与诊断文档入口
366
- - [Target 与 Instance](docs/target-and-instance.md) — 目标选择与实例管理
367
- - [工具发现](docs/tool-discovery.md) — group-first 分层发现详解
368
- - [工具执行](docs/tool-execution.md) — tools run 执行通道详解
369
- - [安全边界](docs/safety-boundaries.md) — 调用授权、风险元数据与正确性边界
370
- - [风险与副作用](docs/risk-and-side-effects.md) — destructive/dry-run 描述与可选预览
371
- - [错误码](docs/error-codes.md) — 结构化错误与 nextActions
372
- - [可用性差异](docs/availability-differences.md) — 不同实例的工具有效性
373
- - [扩展包](docs/extensions.md) — 可选扩展安装、卸载与诊断
374
- - [自定义 Tool](skills/unitycli/references/custom-tools.md) — 项目侧 Tool 注册开发
375
- - [AI Agent Skill](skills/unitycli/SKILL.md) — Agent 最小入口卡片
376
-
377
- ## 本地开发
378
-
379
- ```bash
380
- npm install
381
- npm run build
382
- npm test
383
- npm link
384
- unitycli --help
385
- ```
185
+ ## Documentation
186
+
187
+ - [Documentation index](docs/README.md)
188
+ - [Architecture and public boundaries](docs/architecture.md)
189
+ - [Local development](docs/development.md)
190
+ - [Tool discovery](docs/tool-discovery.md)
191
+ - [Tool execution](docs/tool-execution.md)
192
+ - [Command execution](docs/command-execution.md)
193
+ - [Target and instance selection](docs/target-and-instance.md)
194
+ - [Safety boundaries](docs/safety-boundaries.md)
195
+ - [Errors](docs/error-codes.md)
196
+ - [Extensions](docs/extensions.md)
197
+ - [Public AI Skill](skills/unitycli/SKILL.md)
386
198
 
387
- ## 许可证
199
+ ## License
388
200
 
389
201
  MIT
@@ -0,0 +1,64 @@
1
+ {
2
+ "version": 2,
3
+ "topLevel": "init",
4
+ "schema": "schemas/init.schema.json",
5
+ "subcommands": {
6
+ "help": {
7
+ "options": []
8
+ },
9
+ "discover": {
10
+ "options": []
11
+ },
12
+ "package": {
13
+ "options": [
14
+ "project",
15
+ "close-editor",
16
+ "check",
17
+ "timeout-ms"
18
+ ],
19
+ "required": [
20
+ "project"
21
+ ],
22
+ "checkStatuses": [
23
+ "installed",
24
+ "missing",
25
+ "damaged",
26
+ "drifted",
27
+ "conflict"
28
+ ]
29
+ },
30
+ "skill": {
31
+ "options": [
32
+ "agent",
33
+ "scope",
34
+ "workspace",
35
+ "target",
36
+ "check",
37
+ "timeout-ms"
38
+ ],
39
+ "requiredAnyOf": [
40
+ [
41
+ "target"
42
+ ],
43
+ [
44
+ "agent",
45
+ "scope"
46
+ ]
47
+ ],
48
+ "agents": [
49
+ ".agents",
50
+ "claude"
51
+ ],
52
+ "scopes": [
53
+ "workspace",
54
+ "user"
55
+ ],
56
+ "checkStatuses": [
57
+ "installed",
58
+ "missing",
59
+ "drifted",
60
+ "damaged"
61
+ ]
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "version": 1,
3
+ "topLevel": "instances",
4
+ "schema": "schemas/instances.schema.json",
5
+ "registry": {
6
+ "version": 3,
7
+ "canonicalizationVersion": 1,
8
+ "statuses": [
9
+ "ready",
10
+ "transitioning",
11
+ "blocked",
12
+ "unresponsive",
13
+ "unverifiable",
14
+ "offline",
15
+ "conflict"
16
+ ],
17
+ "readerPollMs": 100,
18
+ "writer": "unity-bridge"
19
+ },
20
+ "subcommands": {
21
+ "list": {
22
+ "options": ["all"],
23
+ "readOnly": true
24
+ },
25
+ "prune": {
26
+ "options": ["instance", "timeout-ms"],
27
+ "privateCommand": "internal.instances.prune",
28
+ "mutation": true,
29
+ "retention": {
30
+ "offlineMax": 100,
31
+ "damagedMax": 20,
32
+ "maxAgeDays": 30,
33
+ "scanLimit": 2000,
34
+ "deleteLimit": 20
35
+ }
36
+ }
37
+ },
38
+ "errors": [
39
+ "E_INSTANCE_NOT_FOUND",
40
+ "E_INSTANCE_NOT_RUNNING",
41
+ "E_INSTANCE_UNVERIFIABLE",
42
+ "E_UNITY_TRANSITION_TIMEOUT",
43
+ "E_UNITY_BUSY",
44
+ "E_EXECUTION_TIMEOUT",
45
+ "E_BRIDGE_RESPONSE_INVALID",
46
+ "E_SCHEMA_INVALID",
47
+ "BRIDGE_CONNECTION_FAILED"
48
+ ]
49
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "packageName": "com.alpsckr.unitycli",
4
+ "minimumUnityVersion": "2022.3",
5
+ "bundledAssemblies": [],
6
+ "editorProvidedAssemblies": [
7
+ {
8
+ "fileName": "Newtonsoft.Json.dll",
9
+ "assemblyName": "Newtonsoft.Json",
10
+ "minimumAssemblyVersion": "13.0.0.0",
11
+ "provider": "Unity Editor/Data/Managed",
12
+ "referencedBy": "UnityCli.Editor.asmdef"
13
+ }
14
+ ],
15
+ "compiler": {
16
+ "mode": "editor-bundled-csc-subprocess",
17
+ "monoRelativePath": "MonoBleedingEdge/bin/mono.exe",
18
+ "compilerRelativePath": "MonoBleedingEdge/lib/mono/4.5/csc.exe",
19
+ "packageOwnedRoslyn": false,
20
+ "temporaryRoot": "Library/UnityCli/code-exec-temp"
21
+ },
22
+ "conflictPolicy": {
23
+ "protectedAssemblyFileNames": [
24
+ "Newtonsoft.Json.dll"
25
+ ],
26
+ "allowedPackageProviders": [
27
+ "com.unity.nuget.newtonsoft-json"
28
+ ],
29
+ "maxDirectories": 4096,
30
+ "maxFiles": 50000,
31
+ "maxConflicts": 100
32
+ }
33
+ }