@kevlns/u-cli-mod 0.1.3 → 0.1.4

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 CHANGED
@@ -19,12 +19,13 @@
19
19
 
20
20
  ## 使用规范(Agent 必须遵守)
21
21
 
22
- 1. **首次对某工程执行 `exec` 前**,必须确保 `doctor` 通过且适配包已安装(`setup` 或 `pipeline install` 已完成);未就绪时先跑 `setup`,不要直接 `exec`。
22
+ 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
23
  2. **禁止在 `exec` 参数中传入任何 `--project-path` 变体**(`-projectPath`、`--project_path`、大小写混合、`=` 形式等)——目标工程由工具统一绑定,传入即报错是预期保护,不要尝试绕过。
24
24
  3. **运行中的 Unity Editor 是 fail-closed**:安装被阻止时引导用户先关闭目标工程的 Editor;除非用户显式要求,不得使用 `--allow-running-editor` 绕过。
25
25
  4. **安装是事务式的**(staging → 校验 → 备份 → 替换 → 再校验 → receipt,失败自动回滚):不要手动清理工程内 `Packages/com.unity.pipeline` 或 `Library/editor-pipeline-cli`。
26
26
  5. **版本路由是精确匹配**(`m_EditorVersion` + revision 同时一致),没有"就近版本"回退;工程版本不在路由表内时如实报告支持列表,不得猜测、不得改写 `ProjectVersion.txt`。
27
27
  6. `exec` 每次调用前都会重新校验 CLI 哈希(防篡改),属正常行为;校验失败按提示跑 `u-cli-mod cli install --force` 修复即可。
28
+ 7. **读取 Editor 当前 Console 首选 `command read_console`**,`get_console_logs` 是兼容别名;`command console` 读取回调捕获流,适合 `since`/cursor 跟随,但不能代替原生 Console 快照。工具必须经 `command <名>` 调用。若实际 schema 中缺少 `read_console`,先检查 `doctor` 的 `patchVersion`/`installedPatchVersion` 和 `state`,不要将其误认成 `console` 的别名。
28
29
 
29
30
  ## 典型流程
30
31
 
@@ -32,8 +33,11 @@
32
33
  u-cli-mod doctor <project> # 1. 体检(只读)
33
34
  u-cli-mod setup <project> # 2. 就绪(CLI + 适配包)
34
35
  u-cli-mod exec <project> -- command editor_status # 3. 执行
36
+ u-cli-mod exec <project> -- command read_console --types error,warning --count 100
35
37
  ```
36
38
 
39
+ `doctor.pipeline` 的 `patchVersion` 为当前路由要求的补丁版本,`installedPatchVersion` 为 receipt 记录的版本(旧 receipt 也兼容,未知为 null);`state` 为 `missing | outdated | invalid | current`。只有完整 expected-tree 校验通过且没有旧 patch receipt 时才返回 `installed=true`;`sourceReady` 同样经过文件树校验。
40
+
37
41
  ## Pipeline 工具清单
38
42
 
39
43
  > 安装的 `com.unity.pipeline`(适配版 0.5.0-exp.1)共 **154** 个命令,经 `u-cli-mod exec <project> -- command <名> [参数]` 透传执行;参数全集以 `exec <project> -- command <名> --help` 为准。
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,7 @@ 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
79
82
 
80
83
  # 清理缓存
81
84
  u-cli-mod cache clean
@@ -88,7 +91,7 @@ u-cli-mod cache clean
88
91
  1. 读取目标工程 `ProjectSettings/ProjectVersion.txt`,要求 `m_EditorVersion` 与 `m_EditorVersionWithRevision` **同时存在且与路由完全一致**(fail-closed,无通配、无“最近版本”回退)。
89
92
  2. 按路由下载固定版本的 Unity CLI:HTTPS 白名单(仅 Unity 官方 CDN),校验固定 SHA-256 + 文件大小 + Authenticode 签名主体与证书指纹,临时文件原子更名为最终文件。
90
93
  3. 按路由下载固定版本的 `com.unity.pipeline` tgz:固定 SHA-256(主)+ SHA-1(交叉),安全解包(解包前逐项拒绝绝对路径、`..`、符号/硬链接等非常规条目)。
91
- 4. 在**用户缓存**中确定性转换:`package.json` 最低 Unity 版本、`PhysicsMaterial` 兼容、`rawRenderQueue` 读取兼容、Roslyn DLL 的 `.meta` 转为 Unity 2022 格式(保留 GUID)、删除 `Tests` 源码与失效签名文件;输出必须与 `routes/expected-tree/*.json`(含 `Tests.meta` 共 385 个文件)逐字节一致。
94
+ 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
95
  5. 事务式安装到 `Packages/com.unity.pipeline`:staging → 校验 → 备份 → 替换 → 再校验 → receipt;任一步失败自动回滚。运行中的 Unity Editor 会 fail-closed 阻止安装。
93
96
  6. `exec` 每次调用前重新校验 CLI 哈希,并**禁止任何 `--project-path` 变体覆盖目标工程**。
94
97
 
@@ -106,12 +109,12 @@ u-cli-mod cache clean
106
109
  ### 单元测试与打包守卫
107
110
 
108
111
  ```bash
109
- npm run check # build + lint + 110 个 vitest 测试 + pack guard
112
+ npm run check # build + lint + vitest 测试 + pack guard
110
113
  ```
111
114
 
112
115
  `pack:guard` 会执行真实 `npm pack`(含文件清单校验),断言发布包:
113
116
 
114
- - 包名为 `@kevlns/u-cli-mod`,tgz 文件名精确为 `kevlns-u-cli-mod-0.1.2.tgz`(与 package.json 版本一致);
117
+ - 包名为 `@kevlns/u-cli-mod`,tgz 文件名精确为 `kevlns-u-cli-mod-0.1.4.tgz`(与 package.json 版本一致);
115
118
  - `files` 必须包含 `v-cli.plugin.json`,且清单身份字段(schemaVersion/package/command/bin/platforms)与包一致;
116
119
  - 不出现:
117
120
 
@@ -142,7 +145,7 @@ npm run e2e:windows # 完整 Unity E2E(真实下载/转换/编译/命
142
145
 
143
146
  - `preflight:runner` 只读,不下载/注册 Runner;结果 JSON 输出到 stdout。
144
147
  - `e2e:windows` 使用**隔离缓存**(干净环境)或显式复用已验证缓存,创建 `<临时目录>/u-cli-mod-e2e/` 下独立临时工程,全部结束后杀掉它启动的所有 Unity 进程并清理临时工程;报告写入 `<临时目录>/u-cli-mod-e2e-report.json`(分别可用 `EPC_E2E_ROOT`、`EPC_E2E_REPORT` 覆盖)。
145
- - 验收指标:200 次只读调用 100% 成功并记录 P50/P95、20 轮资源修改、5 次 Domain Reload 首次恢复、强杀重启恢复、双工程显式路由 60 次无误选、运行中 Editor 防护与 `--project-path` 覆盖拒绝。
148
+ - 验收指标:200 次只读调用 100% 成功并记录 P50/P95、`read_console` 原生 Console 历史读取与统一清理、20 轮资源修改、5 次 Domain Reload 首次恢复、强杀重启恢复、双工程显式路由 60 次无误选、运行中 Editor 防护与 `--project-path` 覆盖拒绝。
146
149
 
147
150
  详细说明见 `docs/SELF_HOSTED_RUNNER.md`。
148
151
 
@@ -179,9 +182,9 @@ kevlns 工具家族共享同一套发布约定(tag 驱动、CI 护栏、MIT)
179
182
 
180
183
  | Package | Purpose | Status |
181
184
  | --- | --- | --- |
182
- | [`v-cli`](https://github.com/kevlns/v-cli) | 个人工具箱 CLI | v0.2.1 |
185
+ | [`v-cli`](https://github.com/kevlns/v-cli) | 个人工具箱 CLI | v0.2.3 |
183
186
  | [`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.1.2 |
187
+ | [`u-cli-mod`](https://github.com/kevlns/u-cli-mod) | Unity 精确版本路由 + CLI + pipeline 包(Windows-first,本仓库) | v0.1.4 |
185
188
 
186
189
  ## Compatibility
187
190
 
@@ -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[];
@@ -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 pipelineInstalled = existsSync(join(project.projectPath, 'Packages', 'com.unity.pipeline', 'package.json'));
19
- const pipelineSourceReady = existsSync(join(generated, 'package.json'));
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: { version: route.pipeline.version, sourceReady: pipelineSourceReady, installed: pipelineInstalled },
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/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.1.3",
3
+ "version": "0.1.4",
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": {
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",