@kevlns/u-cli-mod 0.1.3 → 0.2.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.
- package/AGENTS.md +10 -2
- package/README.md +19 -7
- package/dist/cli.js +16 -2
- package/dist/commands/doctor.d.ts +4 -0
- package/dist/commands/doctor.js +61 -5
- package/dist/commands/exec.d.ts +34 -0
- package/dist/commands/exec.js +150 -5
- package/dist/installer.js +1 -0
- package/package.json +2 -2
- package/v-cli.plugin.json +8 -3
package/AGENTS.md
CHANGED
|
@@ -15,25 +15,33 @@
|
|
|
15
15
|
- `u-cli-mod pipeline install <project>` - 事务式安装适配包(自动备份/回滚/receipt)
|
|
16
16
|
- `u-cli-mod exec <project> -- <pipeline-args>` - 执行 Pipeline 命令(工具统一绑定 `--project-path`)
|
|
17
17
|
- Pipeline 命令全集见文末「Pipeline 工具清单」(适配版 `com.unity.pipeline` 共 154 个命令,按领域分组)
|
|
18
|
+
- `u-cli-mod exec <project> [--wait <秒>] -- <pipeline-args>` - 长任务默认 5s 后让出控制权,结果用对应的 `command <name>_status` 轮询
|
|
18
19
|
- `u-cli-mod routes` / `u-cli-mod cache clean` - 路由表 / 缓存清理
|
|
19
20
|
|
|
20
21
|
## 使用规范(Agent 必须遵守)
|
|
21
22
|
|
|
22
|
-
1. **首次对某工程执行 `exec`
|
|
23
|
+
1. **首次对某工程执行 `exec` 前**,必须检查 `doctor` 的 `cli.state="valid"`、`pipeline.state="current"` 且 `pipeline.installed=true`。`doctor` 退出成功仅表示诊断完成,不代表工程已就绪;`pipeline.present=true` 也只表示包存在。`missing` 时先跑 `setup`;`outdated`/`invalid` 时先关闭目标 Editor,再通过 `pipeline install <project> --force` 备份并更新。升级 npm 包不会自动更新工程内适配包,不要直接 `exec`。
|
|
23
24
|
2. **禁止在 `exec` 参数中传入任何 `--project-path` 变体**(`-projectPath`、`--project_path`、大小写混合、`=` 形式等)——目标工程由工具统一绑定,传入即报错是预期保护,不要尝试绕过。
|
|
24
25
|
3. **运行中的 Unity Editor 是 fail-closed**:安装被阻止时引导用户先关闭目标工程的 Editor;除非用户显式要求,不得使用 `--allow-running-editor` 绕过。
|
|
25
26
|
4. **安装是事务式的**(staging → 校验 → 备份 → 替换 → 再校验 → receipt,失败自动回滚):不要手动清理工程内 `Packages/com.unity.pipeline` 或 `Library/editor-pipeline-cli`。
|
|
26
27
|
5. **版本路由是精确匹配**(`m_EditorVersion` + revision 同时一致),没有"就近版本"回退;工程版本不在路由表内时如实报告支持列表,不得猜测、不得改写 `ProjectVersion.txt`。
|
|
27
28
|
6. `exec` 每次调用前都会重新校验 CLI 哈希(防篡改),属正常行为;校验失败按提示跑 `u-cli-mod cli install --force` 修复即可。
|
|
29
|
+
7. **读取 Editor 当前 Console 首选 `command read_console`**,`get_console_logs` 是兼容别名;`command console` 读取回调捕获流,适合 `since`/cursor 跟随,但不能代替原生 Console 快照。工具必须经 `command <名>` 调用。若实际 schema 中缺少 `read_console`,先检查 `doctor` 的 `patchVersion`/`installedPatchVersion` 和 `state`,不要将其误认成 `console` 的别名。
|
|
28
30
|
|
|
31
|
+
8. **长任务默认不阻塞**:`run_tests` 只等待 5 秒,到点后任务仍在 Editor 内继续执行,工具打印输出日志路径并立即返回(退出码 0)。此时**不要重复发起同一命令**,改用 `command test_status` 轮询结果;需要同步拿到完整 `Summary` 时传 `--wait <秒>`,并优先用 `--filter <命名空间或类名>` 缩小范围(通常数秒内即可同步返回)。
|
|
29
32
|
## 典型流程
|
|
30
33
|
|
|
31
34
|
```bash
|
|
32
35
|
u-cli-mod doctor <project> # 1. 体检(只读)
|
|
33
36
|
u-cli-mod setup <project> # 2. 就绪(CLI + 适配包)
|
|
34
37
|
u-cli-mod exec <project> -- command editor_status # 3. 执行
|
|
38
|
+
u-cli-mod exec <project> -- command run_tests --mode EditMode --filter <命名空间或类名> # 小范围:同步返回 Summary
|
|
39
|
+
u-cli-mod exec <project> -- command run_tests --mode EditMode # 全量:5s 后让出,轮询 test_status
|
|
40
|
+
u-cli-mod exec <project> -- command read_console --types error,warning --count 100
|
|
35
41
|
```
|
|
36
42
|
|
|
43
|
+
`doctor.pipeline` 的 `patchVersion` 为当前路由要求的补丁版本,`installedPatchVersion` 为 receipt 记录的版本(旧 receipt 也兼容,未知为 null);`state` 为 `missing | outdated | invalid | current`。只有完整 expected-tree 校验通过且没有旧 patch receipt 时才返回 `installed=true`;`sourceReady` 同样经过文件树校验。
|
|
44
|
+
|
|
37
45
|
## Pipeline 工具清单
|
|
38
46
|
|
|
39
47
|
> 安装的 `com.unity.pipeline`(适配版 0.5.0-exp.1)共 **154** 个命令,经 `u-cli-mod exec <project> -- command <名> [参数]` 透传执行;参数全集以 `exec <project> -- command <名> --help` 为准。
|
|
@@ -226,4 +234,4 @@ u-cli-mod exec <project> -- command editor_status # 3. 执行
|
|
|
226
234
|
|
|
227
235
|
### Authoring 根路径
|
|
228
236
|
- `get_authoring_root` — Get the base folder (under Assets/) that bare authoring paths resolve against.
|
|
229
|
-
- `set_authoring_root` — Set the base folder (under Assets/) that bare authoring paths resolve against and are confined to. Use 'Assets' for full project access.
|
|
237
|
+
- `set_authoring_root` — Set the base folder (under Assets/) that bare authoring paths resolve against and are confined to. Use 'Assets' for full project access.
|
package/README.md
CHANGED
|
@@ -50,6 +50,8 @@ u-cli-mod setup <project> # CLI + 适配包一键就绪(推荐首次入口
|
|
|
50
50
|
u-cli-mod routes # 列出支持的 Editor 路由
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
+
升级 npm 包不会自动替换已有工程的 `Packages/com.unity.pipeline`。检查 `doctor` 的 `pipeline.state`:只有 `current` 且 `installed=true` 才表示当前补丁完整;`outdated`/`invalid` 时关闭目标 Unity Editor 后执行 `u-cli-mod pipeline install <project> --force`(自动备份)。`patchVersion` 是路由要求,`installedPatchVersion` 来自安装 receipt;仅看到上游版本 `0.5.0-exp.1` 或诊断退出码 0 不代表适配包已更新。
|
|
54
|
+
|
|
53
55
|
## Usage
|
|
54
56
|
|
|
55
57
|
> 示例中的 `<project>` 指代你的 Unity 工程目录,请替换为实际路径。
|
|
@@ -76,6 +78,14 @@ u-cli-mod setup <project>
|
|
|
76
78
|
# 执行 Unity Pipeline 命令(自动绑定目标工程)
|
|
77
79
|
u-cli-mod exec <project> -- command editor_status
|
|
78
80
|
u-cli-mod exec <project> -- command get_scene_hierarchy
|
|
81
|
+
u-cli-mod exec <project> -- command read_console --types error,warning --count 100
|
|
82
|
+
|
|
83
|
+
# 长任务(run_tests)默认等待 5s 后让出控制权,任务继续在 Editor 内执行
|
|
84
|
+
u-cli-mod exec <project> -- command run_tests --mode EditMode
|
|
85
|
+
# 随后轮询结果
|
|
86
|
+
u-cli-mod exec <project> -- command test_status
|
|
87
|
+
# 需要同步拿到完整 Summary 时放宽等待上限(秒)
|
|
88
|
+
u-cli-mod exec <project> --wait 120 -- command run_tests --mode EditMode --filter Game.AI.Tests
|
|
79
89
|
|
|
80
90
|
# 清理缓存
|
|
81
91
|
u-cli-mod cache clean
|
|
@@ -83,12 +93,14 @@ u-cli-mod cache clean
|
|
|
83
93
|
|
|
84
94
|
`exec` 会把 `--project-path <工程>` 追加到 Unity CLI 参数末尾;传入任何形式的 `--project-path`(含 `-projectPath`、`--projectPath`、大小写混合)会直接报错。
|
|
85
95
|
|
|
96
|
+
长任务(`run_tests`)默认只等待 5 秒:到点后任务仍在 Unity Editor 内继续执行,工具打印输出日志路径并立即返回(退出码 0);结果用 `command test_status` 轮询,需要同步等待时用 `--wait <秒>`(`0` = 立即返回)。
|
|
97
|
+
|
|
86
98
|
## 原理
|
|
87
99
|
|
|
88
100
|
1. 读取目标工程 `ProjectSettings/ProjectVersion.txt`,要求 `m_EditorVersion` 与 `m_EditorVersionWithRevision` **同时存在且与路由完全一致**(fail-closed,无通配、无“最近版本”回退)。
|
|
89
101
|
2. 按路由下载固定版本的 Unity CLI:HTTPS 白名单(仅 Unity 官方 CDN),校验固定 SHA-256 + 文件大小 + Authenticode 签名主体与证书指纹,临时文件原子更名为最终文件。
|
|
90
102
|
3. 按路由下载固定版本的 `com.unity.pipeline` tgz:固定 SHA-256(主)+ SHA-1(交叉),安全解包(解包前逐项拒绝绝对路径、`..`、符号/硬链接等非常规条目)。
|
|
91
|
-
4. 在**用户缓存**中确定性转换:`package.json` 最低 Unity 版本、`PhysicsMaterial` 兼容、`rawRenderQueue`
|
|
103
|
+
4. 在**用户缓存**中确定性转换:`package.json` 最低 Unity 版本、`PhysicsMaterial` 兼容、`rawRenderQueue` 读取兼容、基于 `UnityEditor.LogEntries` 的 `read_console`、Roslyn DLL 的 `.meta` 转为 Unity 2022 格式(保留 GUID)、删除 `Tests` 源码与失效签名文件;输出必须与 `routes/expected-tree/*.json`(含 `Tests.meta` 共 385 个文件)逐字节一致。
|
|
92
104
|
5. 事务式安装到 `Packages/com.unity.pipeline`:staging → 校验 → 备份 → 替换 → 再校验 → receipt;任一步失败自动回滚。运行中的 Unity Editor 会 fail-closed 阻止安装。
|
|
93
105
|
6. `exec` 每次调用前重新校验 CLI 哈希,并**禁止任何 `--project-path` 变体覆盖目标工程**。
|
|
94
106
|
|
|
@@ -106,12 +118,12 @@ u-cli-mod cache clean
|
|
|
106
118
|
### 单元测试与打包守卫
|
|
107
119
|
|
|
108
120
|
```bash
|
|
109
|
-
npm run check # build + lint +
|
|
121
|
+
npm run check # build + lint + vitest 测试 + pack guard
|
|
110
122
|
```
|
|
111
123
|
|
|
112
124
|
`pack:guard` 会执行真实 `npm pack`(含文件清单校验),断言发布包:
|
|
113
125
|
|
|
114
|
-
- 包名为 `@kevlns/u-cli-mod`,tgz 文件名精确为 `kevlns-u-cli-mod-0.
|
|
126
|
+
- 包名为 `@kevlns/u-cli-mod`,tgz 文件名精确为 `kevlns-u-cli-mod-0.2.0.tgz`(与 package.json 版本一致);
|
|
115
127
|
- `files` 必须包含 `v-cli.plugin.json`,且清单身份字段(schemaVersion/package/command/bin/platforms)与包一致;
|
|
116
128
|
- 不出现:
|
|
117
129
|
|
|
@@ -142,7 +154,7 @@ npm run e2e:windows # 完整 Unity E2E(真实下载/转换/编译/命
|
|
|
142
154
|
|
|
143
155
|
- `preflight:runner` 只读,不下载/注册 Runner;结果 JSON 输出到 stdout。
|
|
144
156
|
- `e2e:windows` 使用**隔离缓存**(干净环境)或显式复用已验证缓存,创建 `<临时目录>/u-cli-mod-e2e/` 下独立临时工程,全部结束后杀掉它启动的所有 Unity 进程并清理临时工程;报告写入 `<临时目录>/u-cli-mod-e2e-report.json`(分别可用 `EPC_E2E_ROOT`、`EPC_E2E_REPORT` 覆盖)。
|
|
145
|
-
- 验收指标:200 次只读调用 100% 成功并记录 P50/P95
|
|
157
|
+
- 验收指标:200 次只读调用 100% 成功并记录 P50/P95、`read_console` 原生 Console 历史读取与统一清理、20 轮资源修改、5 次 Domain Reload 首次恢复、强杀重启恢复、双工程显式路由 60 次无误选、运行中 Editor 防护与 `--project-path` 覆盖拒绝。
|
|
146
158
|
|
|
147
159
|
详细说明见 `docs/SELF_HOSTED_RUNNER.md`。
|
|
148
160
|
|
|
@@ -179,9 +191,9 @@ kevlns 工具家族共享同一套发布约定(tag 驱动、CI 护栏、MIT)
|
|
|
179
191
|
|
|
180
192
|
| Package | Purpose | Status |
|
|
181
193
|
| --- | --- | --- |
|
|
182
|
-
| [`v-cli`](https://github.com/kevlns/v-cli) | 个人工具箱 CLI | v0.2.
|
|
194
|
+
| [`v-cli`](https://github.com/kevlns/v-cli) | 个人工具箱 CLI | v0.2.3 |
|
|
183
195
|
| [`xlmerge`](https://github.com/kevlns/xlmerge) | Git 中 .xlsx/.xlsm 冲突可视化解决工具 | v1.2.2 |
|
|
184
|
-
| [`u-cli-mod`](https://github.com/kevlns/u-cli-mod) | Unity 精确版本路由 + CLI + pipeline 包(Windows-first,本仓库) | v0.
|
|
196
|
+
| [`u-cli-mod`](https://github.com/kevlns/u-cli-mod) | Unity 精确版本路由 + CLI + pipeline 包(Windows-first,本仓库) | v0.2.0 |
|
|
185
197
|
|
|
186
198
|
## Compatibility
|
|
187
199
|
|
|
@@ -207,4 +219,4 @@ For bugs and feature requests, use [GitHub Issues](https://github.com/kevlns/u-c
|
|
|
207
219
|
|
|
208
220
|
Part of the **kevlns** tool family.
|
|
209
221
|
|
|
210
|
-
</div>
|
|
222
|
+
</div>
|
package/dist/cli.js
CHANGED
|
@@ -6,7 +6,7 @@ import { runRoutes } from './commands/routesCmd.js';
|
|
|
6
6
|
import { runCliInstall } from './commands/cliInstall.js';
|
|
7
7
|
import { runPipelineInstall } from './commands/pipelineInstall.js';
|
|
8
8
|
import { runSetup } from './commands/setup.js';
|
|
9
|
-
import { runExec } from './commands/exec.js';
|
|
9
|
+
import { runExec, extractWaitOption } from './commands/exec.js';
|
|
10
10
|
import { runCacheClean } from './commands/cacheClean.js';
|
|
11
11
|
import { readFileSync } from 'node:fs';
|
|
12
12
|
import { join, dirname } from 'node:path';
|
|
@@ -24,6 +24,17 @@ function packageVersion() {
|
|
|
24
24
|
function printJson(value) {
|
|
25
25
|
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
26
26
|
}
|
|
27
|
+
/** Non-negative seconds for --wait; undefined keeps the wrapper default. */
|
|
28
|
+
function parseWaitSeconds(raw) {
|
|
29
|
+
if (raw === undefined) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const value = Number(raw);
|
|
33
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
34
|
+
throw new CliError(`--wait 需要非负秒数,收到:${raw}`);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
27
38
|
export function buildProgram() {
|
|
28
39
|
const program = new Command();
|
|
29
40
|
program
|
|
@@ -94,6 +105,7 @@ export function buildProgram() {
|
|
|
94
105
|
.command('exec <project>')
|
|
95
106
|
.description('调用路由 CLI 执行 Unity Pipeline 命令;--project-path 由工具统一绑定')
|
|
96
107
|
.option('--download-if-missing', 'CLI 缺失时自动下载')
|
|
108
|
+
.option('--wait <seconds>', '长任务等待上限(秒):到点后任务在 Editor 内继续,立即返回;0 = 立即返回')
|
|
97
109
|
.allowUnknownOption(true)
|
|
98
110
|
.allowExcessArguments(true)
|
|
99
111
|
.passThroughOptions(true);
|
|
@@ -105,8 +117,10 @@ export function buildProgram() {
|
|
|
105
117
|
// only ever receive the real pipeline args, and the project-path override
|
|
106
118
|
// rejection below stays fully intact.
|
|
107
119
|
const passthroughArgs = extra.filter((arg) => arg !== '--');
|
|
108
|
-
const
|
|
120
|
+
const forwarded = extractWaitOption(passthroughArgs);
|
|
121
|
+
const { exitCode } = await runExec(project, forwarded.args, {
|
|
109
122
|
downloadIfMissing: opts.downloadIfMissing,
|
|
123
|
+
waitSeconds: forwarded.waitSeconds ?? parseWaitSeconds(opts.wait),
|
|
110
124
|
});
|
|
111
125
|
process.exitCode = exitCode;
|
|
112
126
|
});
|
|
@@ -14,8 +14,12 @@ export declare function runDoctor(projectPath: string, options?: DoctorOptions):
|
|
|
14
14
|
};
|
|
15
15
|
pipeline: {
|
|
16
16
|
version: string;
|
|
17
|
+
patchVersion: number;
|
|
17
18
|
sourceReady: boolean;
|
|
19
|
+
present: boolean;
|
|
18
20
|
installed: boolean;
|
|
21
|
+
state: string;
|
|
22
|
+
installedPatchVersion: number | null;
|
|
19
23
|
};
|
|
20
24
|
unityProcesses: string[];
|
|
21
25
|
supportedVersions: string[];
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
|
+
import { readFile } from 'node:fs/promises';
|
|
2
3
|
import { join } from 'node:path';
|
|
3
4
|
import { readProjectInfo } from '../projectVersion.js';
|
|
4
|
-
import { resolveRouteForProject, listEditorVersions } from '../routes.js';
|
|
5
|
+
import { resolveRouteForProject, listEditorVersions, loadExpectedTree } from '../routes.js';
|
|
5
6
|
import { cliBinaryPath, generatedPackageDir } from '../paths.js';
|
|
6
|
-
import { sha256File } from '../integrity.js';
|
|
7
|
+
import { compareTree, sha256File } from '../integrity.js';
|
|
7
8
|
import { queryUnityProcesses } from '../unityGuard.js';
|
|
9
|
+
async function readInstalledPatchVersion(receiptPath) {
|
|
10
|
+
if (!existsSync(receiptPath))
|
|
11
|
+
return null;
|
|
12
|
+
try {
|
|
13
|
+
const receipt = JSON.parse(await readFile(receiptPath, 'utf8'));
|
|
14
|
+
if (Number.isInteger(receipt.patchVersion) && Number(receipt.patchVersion) >= 0) {
|
|
15
|
+
return Number(receipt.patchVersion);
|
|
16
|
+
}
|
|
17
|
+
if (typeof receipt.source === 'string') {
|
|
18
|
+
const match = /\(patched\s+(\d+)\)/i.exec(receipt.source);
|
|
19
|
+
if (match?.[1])
|
|
20
|
+
return Number.parseInt(match[1], 10);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
// Unknown receipt metadata never bypasses the package tree verification.
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
async function packageTreeMatches(root, expected) {
|
|
29
|
+
if (!existsSync(root))
|
|
30
|
+
return false;
|
|
31
|
+
try {
|
|
32
|
+
return (await compareTree(root, expected)).ok;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
8
38
|
export async function runDoctor(projectPath, options = {}) {
|
|
9
39
|
const project = readProjectInfo(projectPath);
|
|
10
40
|
const route = resolveRouteForProject(project);
|
|
@@ -15,8 +45,26 @@ export async function runDoctor(projectPath, options = {}) {
|
|
|
15
45
|
cliState = hash === route.cli.sha256.toLowerCase() ? 'valid' : 'hash-mismatch';
|
|
16
46
|
}
|
|
17
47
|
const generated = generatedPackageDir(project.editorVersion);
|
|
18
|
-
const
|
|
19
|
-
const
|
|
48
|
+
const expectedTree = loadExpectedTree(project.editorVersion);
|
|
49
|
+
const pipelineRoot = join(project.projectPath, 'Packages', 'com.unity.pipeline');
|
|
50
|
+
const pipelinePresent = existsSync(join(pipelineRoot, 'package.json'));
|
|
51
|
+
const receiptPath = join(project.projectPath, 'Library', 'editor-pipeline-cli', 'receipt.json');
|
|
52
|
+
const installedPatchVersion = await readInstalledPatchVersion(receiptPath);
|
|
53
|
+
const pipelineOutdated = pipelinePresent &&
|
|
54
|
+
installedPatchVersion !== null &&
|
|
55
|
+
installedPatchVersion < route.pipeline.patchVersion;
|
|
56
|
+
const pipelineTreeMatches = pipelinePresent
|
|
57
|
+
? await packageTreeMatches(pipelineRoot, expectedTree.files)
|
|
58
|
+
: false;
|
|
59
|
+
const pipelineInstalled = pipelinePresent && pipelineTreeMatches && !pipelineOutdated;
|
|
60
|
+
const pipelineState = !pipelinePresent
|
|
61
|
+
? 'missing'
|
|
62
|
+
: pipelineOutdated
|
|
63
|
+
? 'outdated'
|
|
64
|
+
: pipelineTreeMatches
|
|
65
|
+
? 'current'
|
|
66
|
+
: 'invalid';
|
|
67
|
+
const pipelineSourceReady = await packageTreeMatches(generated, expectedTree.files);
|
|
20
68
|
let editors = [];
|
|
21
69
|
if (!options.allowRunningEditor) {
|
|
22
70
|
try {
|
|
@@ -34,7 +82,15 @@ export async function runDoctor(projectPath, options = {}) {
|
|
|
34
82
|
routeSupported: true,
|
|
35
83
|
routeRevision: route.editorRevision,
|
|
36
84
|
cli: { version: route.cli.version, path: cliPath, state: cliState },
|
|
37
|
-
pipeline: {
|
|
85
|
+
pipeline: {
|
|
86
|
+
version: route.pipeline.version,
|
|
87
|
+
patchVersion: route.pipeline.patchVersion,
|
|
88
|
+
sourceReady: pipelineSourceReady,
|
|
89
|
+
present: pipelinePresent,
|
|
90
|
+
installed: pipelineInstalled,
|
|
91
|
+
state: pipelineState,
|
|
92
|
+
installedPatchVersion,
|
|
93
|
+
},
|
|
38
94
|
unityProcesses: editors,
|
|
39
95
|
supportedVersions: listEditorVersions(),
|
|
40
96
|
};
|
package/dist/commands/exec.d.ts
CHANGED
|
@@ -6,8 +6,42 @@
|
|
|
6
6
|
export declare function findProjectPathOverride(args: string[]): string | null;
|
|
7
7
|
/** The wrapper always appends its own resolved project path as the last args. */
|
|
8
8
|
export declare function buildExecArgs(cliArgs: string[], projectPath: string): string[];
|
|
9
|
+
/**
|
|
10
|
+
* Pipeline commands that block until the Editor-side work finishes.
|
|
11
|
+
* The routed Unity CLI caps that wait at 30s, and its own `--timeout` is not wired
|
|
12
|
+
* in the shipped build (verified: a full run_tests still waits ~30s with
|
|
13
|
+
* `--timeout 1`), so the wait budget belongs to this wrapper.
|
|
14
|
+
*/
|
|
15
|
+
export declare const LONG_RUNNING_PIPELINE_COMMANDS: ReadonlySet<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Long tasks hand control back after this many seconds so the caller can poll the
|
|
18
|
+
* matching status command (`test_status`) instead of blocking on the CLI wait cap.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_LONG_TASK_WAIT_SECONDS = 5;
|
|
21
|
+
/** Pipeline command name of a `command <name> ...` invocation; null when absent. */
|
|
22
|
+
export declare function extractPipelineCommandName(cliArgs: string[]): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* Wait budget (ms) for the Unity CLI child process:
|
|
25
|
+
* - an explicit `--wait` wins (0 returns immediately);
|
|
26
|
+
* - long-running pipeline commands get a short budget so callers can poll status;
|
|
27
|
+
* - null means "wait synchronously for the CLI to finish" (unchanged behaviour).
|
|
28
|
+
*/
|
|
29
|
+
export declare function resolveWaitMilliseconds(cliArgs: string[], explicitWaitSeconds?: number): number | null;
|
|
30
|
+
/**
|
|
31
|
+
* Strips the wrapper's own `--wait <seconds>` / `--wait=<seconds>` from the
|
|
32
|
+
* passthrough tail. commander copies everything after the <project> operand
|
|
33
|
+
* verbatim (passThroughOptions), so a --wait written there must be lifted here
|
|
34
|
+
* and must never leak into the Unity CLI arguments.
|
|
35
|
+
*/
|
|
36
|
+
export declare function extractWaitOption(args: string[]): {
|
|
37
|
+
args: string[];
|
|
38
|
+
waitSeconds?: number;
|
|
39
|
+
};
|
|
40
|
+
/** Exec output log of a handed-back run: project-scoped, beside the install receipts. */
|
|
41
|
+
export declare function execLogPath(projectPath: string, commandName: string | null, now?: Date): string;
|
|
9
42
|
export interface ExecOptions {
|
|
10
43
|
downloadIfMissing?: boolean;
|
|
44
|
+
waitSeconds?: number;
|
|
11
45
|
}
|
|
12
46
|
export declare function runExec(projectPath: string, cliArgs: string[], options?: ExecOptions): Promise<{
|
|
13
47
|
exitCode: number;
|
package/dist/commands/exec.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { spawnSync } from 'node:child_process';
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import { closeSync, mkdirSync, openSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
2
4
|
import { readProjectInfo } from '../projectVersion.js';
|
|
3
5
|
import { resolveRouteForProject } from '../routes.js';
|
|
4
6
|
import { verifyCliBinary, ensureCliBinary } from '../ensure.js';
|
|
@@ -21,6 +23,87 @@ export function findProjectPathOverride(args) {
|
|
|
21
23
|
export function buildExecArgs(cliArgs, projectPath) {
|
|
22
24
|
return [...cliArgs, '--project-path', projectPath];
|
|
23
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Pipeline commands that block until the Editor-side work finishes.
|
|
28
|
+
* The routed Unity CLI caps that wait at 30s, and its own `--timeout` is not wired
|
|
29
|
+
* in the shipped build (verified: a full run_tests still waits ~30s with
|
|
30
|
+
* `--timeout 1`), so the wait budget belongs to this wrapper.
|
|
31
|
+
*/
|
|
32
|
+
export const LONG_RUNNING_PIPELINE_COMMANDS = new Set(['run_tests']);
|
|
33
|
+
/**
|
|
34
|
+
* Long tasks hand control back after this many seconds so the caller can poll the
|
|
35
|
+
* matching status command (`test_status`) instead of blocking on the CLI wait cap.
|
|
36
|
+
*/
|
|
37
|
+
export const DEFAULT_LONG_TASK_WAIT_SECONDS = 5;
|
|
38
|
+
/** Pipeline command name of a `command <name> ...` invocation; null when absent. */
|
|
39
|
+
export function extractPipelineCommandName(cliArgs) {
|
|
40
|
+
const at = cliArgs.indexOf('command');
|
|
41
|
+
if (at < 0) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
const name = cliArgs[at + 1];
|
|
45
|
+
return name !== undefined && !name.startsWith('-') ? name : null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Wait budget (ms) for the Unity CLI child process:
|
|
49
|
+
* - an explicit `--wait` wins (0 returns immediately);
|
|
50
|
+
* - long-running pipeline commands get a short budget so callers can poll status;
|
|
51
|
+
* - null means "wait synchronously for the CLI to finish" (unchanged behaviour).
|
|
52
|
+
*/
|
|
53
|
+
export function resolveWaitMilliseconds(cliArgs, explicitWaitSeconds) {
|
|
54
|
+
if (explicitWaitSeconds !== undefined) {
|
|
55
|
+
return Math.max(0, Math.round(explicitWaitSeconds * 1000));
|
|
56
|
+
}
|
|
57
|
+
const name = extractPipelineCommandName(cliArgs);
|
|
58
|
+
return name !== null && LONG_RUNNING_PIPELINE_COMMANDS.has(name)
|
|
59
|
+
? DEFAULT_LONG_TASK_WAIT_SECONDS * 1000
|
|
60
|
+
: null;
|
|
61
|
+
}
|
|
62
|
+
/** Non-negative seconds for --wait; throws on anything else. */
|
|
63
|
+
function parseWaitValue(raw) {
|
|
64
|
+
const value = Number(raw);
|
|
65
|
+
if (!Number.isFinite(value) || value < 0) {
|
|
66
|
+
throw new CliError(`--wait 需要非负秒数,收到:${raw}`);
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Strips the wrapper's own `--wait <seconds>` / `--wait=<seconds>` from the
|
|
72
|
+
* passthrough tail. commander copies everything after the <project> operand
|
|
73
|
+
* verbatim (passThroughOptions), so a --wait written there must be lifted here
|
|
74
|
+
* and must never leak into the Unity CLI arguments.
|
|
75
|
+
*/
|
|
76
|
+
export function extractWaitOption(args) {
|
|
77
|
+
const rest = [];
|
|
78
|
+
let waitSeconds;
|
|
79
|
+
for (let i = 0; i < args.length; i++) {
|
|
80
|
+
const arg = args[i];
|
|
81
|
+
if (arg === undefined) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (arg === '--wait' || arg === '-wait') {
|
|
85
|
+
const value = args[i + 1];
|
|
86
|
+
if (value === undefined) {
|
|
87
|
+
throw new CliError('--wait 需要非负秒数。');
|
|
88
|
+
}
|
|
89
|
+
waitSeconds = parseWaitValue(value);
|
|
90
|
+
i++;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (arg.startsWith('--wait=')) {
|
|
94
|
+
waitSeconds = parseWaitValue(arg.slice('--wait='.length));
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
rest.push(arg);
|
|
98
|
+
}
|
|
99
|
+
return waitSeconds === undefined ? { args: rest } : { args: rest, waitSeconds };
|
|
100
|
+
}
|
|
101
|
+
/** Exec output log of a handed-back run: project-scoped, beside the install receipts. */
|
|
102
|
+
export function execLogPath(projectPath, commandName, now = new Date()) {
|
|
103
|
+
const stamp = now.toISOString().replace(/[:.]/g, '-');
|
|
104
|
+
const suffix = commandName === null ? '' : `-${commandName}`;
|
|
105
|
+
return join(projectPath, 'Library', 'editor-pipeline-cli', 'exec-logs', `${stamp}${suffix}.log`);
|
|
106
|
+
}
|
|
24
107
|
export async function runExec(projectPath, cliArgs, options = {}) {
|
|
25
108
|
const project = readProjectInfo(projectPath);
|
|
26
109
|
const route = resolveRouteForProject(project);
|
|
@@ -40,9 +123,71 @@ export async function runExec(projectPath, cliArgs, options = {}) {
|
|
|
40
123
|
// Re-verify the hash on every invocation (fail closed on tamper).
|
|
41
124
|
await verifyCliBinary(route.cli);
|
|
42
125
|
const args = buildExecArgs(cliArgs, project.projectPath);
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
|
|
126
|
+
const waitMs = resolveWaitMilliseconds(cliArgs, options.waitSeconds);
|
|
127
|
+
if (waitMs === null) {
|
|
128
|
+
const child = spawnSync(cliPath, args, { stdio: 'inherit', windowsHide: true });
|
|
129
|
+
if (child.error) {
|
|
130
|
+
throw new CliError(`CLI 执行失败:${child.error.message}`);
|
|
131
|
+
}
|
|
132
|
+
return { exitCode: child.status ?? 1 };
|
|
46
133
|
}
|
|
47
|
-
return
|
|
134
|
+
return runWithWaitBudget(cliPath, args, project.projectPath, waitMs, extractPipelineCommandName(cliArgs));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Runs the CLI under a wait budget. When the budget expires the child keeps running
|
|
138
|
+
* (the Editor-side work is independent of it) and the wrapper hands control back
|
|
139
|
+
* with the output log path, so callers can poll the matching status command.
|
|
140
|
+
*/
|
|
141
|
+
async function runWithWaitBudget(cliPath, args, projectPath, waitMs, commandName) {
|
|
142
|
+
const logPath = execLogPath(projectPath, commandName);
|
|
143
|
+
mkdirSync(dirname(logPath), { recursive: true });
|
|
144
|
+
const logFd = openSync(logPath, 'a');
|
|
145
|
+
const child = spawn(cliPath, args, { stdio: ['ignore', logFd, logFd], windowsHide: true });
|
|
146
|
+
const spawnState = { error: null };
|
|
147
|
+
child.once('error', (error) => {
|
|
148
|
+
spawnState.error = error;
|
|
149
|
+
});
|
|
150
|
+
const finished = await waitForExit(child, waitMs);
|
|
151
|
+
closeSync(logFd);
|
|
152
|
+
if (finished) {
|
|
153
|
+
if (spawnState.error !== null) {
|
|
154
|
+
throw new CliError(`CLI 执行失败:${spawnState.error.message}`);
|
|
155
|
+
}
|
|
156
|
+
process.stdout.write(readFileSync(logPath, 'utf8'));
|
|
157
|
+
return { exitCode: child.exitCode ?? 1 };
|
|
158
|
+
}
|
|
159
|
+
child.unref();
|
|
160
|
+
const label = commandName ?? 'pipeline 命令';
|
|
161
|
+
process.stderr.write(`[u-cli-mod] ${label} 仍在 Unity Editor 内继续执行:等待 ${(waitMs / 1000).toFixed(1)}s 后让出控制权(未中断)。\n` +
|
|
162
|
+
`[u-cli-mod] 结果请轮询状态命令,例如:u-cli-mod exec <project> -- command test_status\n` +
|
|
163
|
+
`[u-cli-mod] 完整输出日志:${logPath}\n` +
|
|
164
|
+
`[u-cli-mod] 需要同步等待时传 --wait <秒>(0 = 立即返回)。\n`);
|
|
165
|
+
return { exitCode: 0 };
|
|
166
|
+
}
|
|
167
|
+
/** true when the child exited inside the budget; false when the budget expired. */
|
|
168
|
+
/** true when the child exited inside the budget; false when the budget expired. */
|
|
169
|
+
function waitForExit(child, waitMs) {
|
|
170
|
+
return new Promise((resolve) => {
|
|
171
|
+
let settled = false;
|
|
172
|
+
const finish = (exited) => {
|
|
173
|
+
if (settled) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
settled = true;
|
|
177
|
+
resolve(exited);
|
|
178
|
+
};
|
|
179
|
+
const timer = setTimeout(() => finish(false), waitMs);
|
|
180
|
+
child.once('exit', () => {
|
|
181
|
+
clearTimeout(timer);
|
|
182
|
+
finish(true);
|
|
183
|
+
});
|
|
184
|
+
child.once('error', () => {
|
|
185
|
+
clearTimeout(timer);
|
|
186
|
+
finish(true);
|
|
187
|
+
});
|
|
188
|
+
if (waitMs === 0) {
|
|
189
|
+
clearTimeout(timer);
|
|
190
|
+
finish(false);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
48
193
|
}
|
package/dist/installer.js
CHANGED
|
@@ -99,6 +99,7 @@ export async function installPipeline(project, route, sourceDir, expectedTree, o
|
|
|
99
99
|
editorVersion: project.editorVersion,
|
|
100
100
|
editorRevision: project.revision,
|
|
101
101
|
pipelineVersion: route.pipeline.version,
|
|
102
|
+
patchVersion: route.pipeline.patchVersion,
|
|
102
103
|
packagePath: destination,
|
|
103
104
|
backupPath: backupPath ?? null,
|
|
104
105
|
source: `${route.pipeline.packageName}@${route.pipeline.version} (patched ${route.pipeline.patchVersion})`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevlns/u-cli-mod",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "u-cli-mod: pin exact Unity Editor version routes and install the adapted com.unity.pipeline package for Unity 2022 (Windows-first). Downloads Unity assets at runtime into the user cache; the package itself contains no Unity binaries or package source. Not an official Unity project.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -68,4 +68,4 @@
|
|
|
68
68
|
"vitest": "^3.2.7"
|
|
69
69
|
},
|
|
70
70
|
"license": "MIT"
|
|
71
|
-
}
|
|
71
|
+
}
|
package/v-cli.plugin.json
CHANGED
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
],
|
|
52
52
|
"output": {
|
|
53
53
|
"format": "json",
|
|
54
|
-
"description": "Diagnostics object: projectPath, editorVersion, editorRevision, routeSupported, routeRevision, cli {version, path, state}, pipeline {version, sourceReady, installed}, unityProcesses, supportedVersions."
|
|
54
|
+
"description": "Diagnostics object: projectPath, editorVersion, editorRevision, routeSupported, routeRevision, cli {version, path, state}, pipeline {version, patchVersion, installedPatchVersion, sourceReady, present, installed, state: missing|outdated|invalid|current}, unityProcesses, supportedVersions. installed/sourceReady require expected-tree integrity. Exit 0 means diagnostics completed, not readiness. Close the target Editor and use pipeline install --force for outdated/invalid. npm upgrades do not update project packages."
|
|
55
55
|
},
|
|
56
56
|
"exitCodes": {
|
|
57
57
|
"0": "success",
|
|
@@ -217,11 +217,15 @@
|
|
|
217
217
|
{
|
|
218
218
|
"flags": "--download-if-missing",
|
|
219
219
|
"description": "CLI 缺失时自动下载"
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
"flags": "--wait <seconds>",
|
|
223
|
+
"description": "长任务等待上限(秒):到点后任务在 Editor 内继续,立即返回;0 = 立即返回"
|
|
220
224
|
}
|
|
221
225
|
],
|
|
222
226
|
"output": {
|
|
223
227
|
"format": "text",
|
|
224
|
-
"description": "Unity CLI stdout/stderr pass through verbatim (stdio inherit); the wrapper prints no JSON of its own."
|
|
228
|
+
"description": "Unity CLI stdout/stderr pass through verbatim (stdio inherit); the wrapper prints no JSON of its own. When the wait budget expires the child keeps running and the wrapper prints the log path plus the status command to poll."
|
|
225
229
|
},
|
|
226
230
|
"exitCodes": {
|
|
227
231
|
"0": "success",
|
|
@@ -233,7 +237,8 @@
|
|
|
233
237
|
"rejects every --project-path variant (case-insensitive: --project-path, --projectPath, -projectPath, --project_path, mixed case)",
|
|
234
238
|
"always appends the resolved --project-path as the final argument; the wrapper owns project targeting",
|
|
235
239
|
"no route fallback: the project must match a pinned route exactly",
|
|
236
|
-
"the documented -- separator is consumed by the wrapper and never forwarded to the Unity CLI"
|
|
240
|
+
"the documented -- separator is consumed by the wrapper and never forwarded to the Unity CLI",
|
|
241
|
+
"long-running pipeline commands (run_tests) hand control back after 5s by default instead of blocking on the CLI 30s wait cap; the task keeps running inside the Editor — poll test_status, and pass --wait <seconds> to wait synchronously"
|
|
237
242
|
]
|
|
238
243
|
},
|
|
239
244
|
{
|