diff --git a/.codex-plugin/plugin.json b/.codex-plugin/plugin.json index 0dd67c6..a3904c0 100644 --- a/.codex-plugin/plugin.json +++ b/.codex-plugin/plugin.json @@ -24,6 +24,7 @@ "shader-graph" ], "skills": "./skills/", + "hooks": {}, "requires_local_executor": true, "interface": { "displayName": "Unity", diff --git a/.github/README.md b/.github/README.md index 9affb3b..6307a52 100644 --- a/.github/README.md +++ b/.github/README.md @@ -175,6 +175,23 @@ For what each skill covers and how to prompt it, see [About Unity's plugin](https://docs.unity.com/en-us/ai/unity-plugin/about-unity-plugin), or browse the [skills](../skills/using-unity/references/). +## What the plugin adds to a session + +Besides the skill, the plugin adds one sentence at the start of each session. It tells your agent +to load `using-unity` first when you're working on a Unity project or starting a new game project, +so a request that doesn't mention Unity still reaches the right skill. The sentence is added in +every folder, not only in Unity projects. + +How it arrives depends on the agent: + +- **Claude Code**: a `SessionStart` hook in `hooks/hooks.json`. It runs one `echo` command that + prints the sentence, and nothing else. +- **GitHub Copilot CLI**: a plugin rule, `com.github.copilot/rules/unity.mdc`. + `copilot instruction list` shows it under "Plugin instructions". +- **Antigravity**: a plugin rule, `rules/AGENTS.md`. `agy plugin list` counts it in the plugin's + components. +- **Codex** and **Grok**: nothing is added. They find `using-unity` from the skill list. + ## Works best with the Unity CLI Many skills drive your open Unity Editor directly: they create GameObjects, change import settings, run C# in the Editor, and check the result, instead of hand-editing scene and asset files. They do this through the [Unity CLI](https://docs.unity.com/en-us/unity-cli), Unity's command-line tool, which also installs Editors, creates and opens projects, and runs builds and tests. diff --git a/com.github.copilot/rules/unity.mdc b/com.github.copilot/rules/unity.mdc new file mode 100644 index 0000000..bfd2ef3 --- /dev/null +++ b/com.github.copilot/rules/unity.mdc @@ -0,0 +1,5 @@ +--- +description: Unity skills +alwaysApply: true +--- +If you're working on a Unity project, or the user is starting a new game project, always load the using-unity skill first: it has references for every part of game development with Unity and its ecosystem. Check its references against each request, even when the request doesn't explicitly mention Unity. diff --git a/hooks/hooks.json b/hooks/hooks.json new file mode 100644 index 0000000..9a507c6 --- /dev/null +++ b/hooks/hooks.json @@ -0,0 +1,15 @@ +{ + "hooks": { + "SessionStart": [ + { + "matcher": "startup|clear|compact", + "hooks": [ + { + "type": "command", + "command": "echo '{\"hookSpecificOutput\":{\"hookEventName\":\"SessionStart\",\"additionalContext\":\"If you\\u0027re working on a Unity project, or the user is starting a new game project, always load the using-unity skill first: it has references for every part of game development with Unity and its ecosystem. Check its references against each request, even when the request doesn\\u0027t explicitly mention Unity.\"}}'" + } + ] + } + ] + } +} diff --git a/plugin.json b/plugin.json new file mode 100644 index 0000000..9f6bba9 --- /dev/null +++ b/plugin.json @@ -0,0 +1,27 @@ +{ + "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json", + "name": "unity", + "version": "0.1.10-beta", + "description": "Unity's official plugin for coding agents, with curated skills for game development, monetization, and performance optimization.", + "author": { + "name": "Unity Technologies", + "url": "https://unity.com" + }, + "homepage": "https://unity.com", + "repository": "https://github.com/Unity-Technologies/unity-agent-plugin", + "license": "LicenseRef-Unity-Companion-License", + "keywords": [ + "unity", + "gamedev", + "game-development", + "ui-toolkit", + "ugui", + "2d", + "tilemap", + "in-app-purchases", + "monetization", + "localization", + "multiplayer", + "shader-graph" + ] +} diff --git a/rules/AGENTS.md b/rules/AGENTS.md new file mode 100644 index 0000000..91c47f2 --- /dev/null +++ b/rules/AGENTS.md @@ -0,0 +1 @@ +If you're working on a Unity project, or the user is starting a new game project, always load the using-unity skill first: it has references for every part of game development with Unity and its ecosystem. Check its references against each request, even when the request doesn't explicitly mention Unity. diff --git a/scripts/build-codex-zip.mts b/scripts/build-codex-zip.mts index 4bc1aa3..0398f65 100644 --- a/scripts/build-codex-zip.mts +++ b/scripts/build-codex-zip.mts @@ -4,11 +4,26 @@ // node scripts/build-codex-zip.mts writes dist/unity-codex-.zip // // Run it on a clean checkout of merged main, after the version bump. The zip holds one folder, -// `unity`, with the skills (no evals/ or tests/), both manifests, the README, the license and -// the logos the manifests reference. It refuses to build if the manifests disagree on -// the version or drift from scripts/plugin-metadata.json. +// `unity`, with the skills (no evals/ or tests/), the root plugin.json, the Codex manifest, the +// README, the license and the logos the Codex manifest references. It refuses to build if the +// manifests disagree on the name or version, or drift from scripts/plugin-metadata.json. +// +// The directory takes the package's identity (name, version, description, author) from the root +// plugin.json and everything else from .codex-plugin/plugin.json, because the root manifest has +// no extensions.com.openai. Files for other clients stay out: .claude-plugin/, hooks/, rules/ +// and com.github.copilot/. import { execFileSync } from 'node:child_process'; -import { cpSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync } from 'node:fs'; +import { + cpSync, + existsSync, + mkdirSync, + mkdtempSync, + readdirSync, + readFileSync, + rmSync, + statSync, + writeFileSync, +} from 'node:fs'; import { tmpdir } from 'node:os'; import { basename, join, resolve } from 'node:path'; @@ -22,23 +37,25 @@ execFileSync(process.execPath, [join(root, 'scripts/sync-manifests.mts'), '--che cwd: root, stdio: 'inherit', }); -const manifests = ['.codex-plugin/plugin.json', '.claude-plugin/plugin.json']; +const manifests = ['plugin.json', '.codex-plugin/plugin.json']; +const names = new Set(); for (const file of manifests) { - const { version } = JSON.parse(readFileSync(join(root, file), 'utf8')) as { version: string }; + const { name, version } = JSON.parse(readFileSync(join(root, file), 'utf8')) as { name: string; version: string }; if (version !== meta.version) fail(`${file} is at ${version}, expected ${meta.version}`); + names.add(name); } +if (names.size !== 1) fail(`${manifests.join(' and ')} disagree on the name: ${[...names].join(', ')}`); // 2. Stage the package as /unity. const excluded = new Set(['evals', 'tests', '.DS_Store', 'Thumbs.db']); const contents = [ 'skills', + 'plugin.json', '.codex-plugin', - '.claude-plugin', 'README.md', 'LICENSE.md', 'assets/unity.svg', 'assets/unity-small.svg', - 'assets/unity-tile.svg', // the icon .claude-plugin/plugin.json points to ]; const stage = mkdtempSync(join(tmpdir(), 'unity-codex-')); const pkg = join(stage, 'unity'); @@ -52,6 +69,17 @@ try { }); } + // The Codex manifest sets "hooks": {} so that a git install never picks up hooks/hooks.json, + // which is Claude Code's. The zip has no hooks/ folder, so the key has nothing to switch off + // here, and the plugin directory takes no plugins with lifecycle hooks. Leave it out, so the + // uploaded manifest declares none. + const codexManifest = join(pkg, '.codex-plugin/plugin.json'); + const { hooks, ...packed } = JSON.parse(readFileSync(codexManifest, 'utf8')) as Record; + if (hooks !== undefined && JSON.stringify(hooks) !== '{}') { + fail('.codex-plugin/plugin.json declares hooks; the plugin directory takes no plugins with lifecycle hooks'); + } + writeFileSync(codexManifest, `${JSON.stringify(packed, null, 2)}\n`); + // 3. Check what was staged before zipping it. const skills = readdirSync(join(pkg, 'skills')).filter((d) => existsSync(join(pkg, 'skills', d, 'SKILL.md')), diff --git a/scripts/plugin-metadata.json b/scripts/plugin-metadata.json index 00b4c61..531e2af 100644 --- a/scripts/plugin-metadata.json +++ b/scripts/plugin-metadata.json @@ -21,5 +21,6 @@ "localization", "multiplayer", "shader-graph" - ] + ], + "nudge": "If you're working on a Unity project, or the user is starting a new game project, always load the using-unity skill first: it has references for every part of game development with Unity and its ecosystem. Check its references against each request, even when the request doesn't explicitly mention Unity." } diff --git a/scripts/sync-manifests.mts b/scripts/sync-manifests.mts index 41f961c..1dc694e 100644 --- a/scripts/sync-manifests.mts +++ b/scripts/sync-manifests.mts @@ -8,7 +8,11 @@ // To release, change "version" in plugin-metadata.json and run the script without --check. // Platform-only fields (descriptions, the Codex interface block, Antigravity prompts) stay in // each manifest and are not touched. -import { readFileSync, writeFileSync } from 'node:fs'; +// +// It also writes the session-start nudge ("nudge" in plugin-metadata.json) into the three files +// that deliver it, so they always carry the same sentence. See `nudgeFiles` below. +import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'; +import { dirname } from 'node:path'; type Json = string | number | boolean | null | Json[] | { [key: string]: Json }; type JsonObject = { [key: string]: Json }; @@ -21,6 +25,7 @@ interface Metadata { license: string; category: string; keywords: string[]; + nudge: string; } interface Marketplace extends JsonObject { @@ -34,6 +39,14 @@ const shared = ['version', 'author', 'homepage', 'repository', 'license', 'keywo // Each target names a manifest and where each shared key lives in it. const targets: { file: string; set: (manifest: JsonObject) => void }[] = [ { file: '.claude-plugin/plugin.json', set: (m) => assign(m, shared) }, + { + // The Agent Plugins manifest at the plugin root. Copilot CLI reads com.github.copilot/ only + // when it exists, Grok reads it before .claude-plugin/plugin.json, and OpenAI's plugin + // directory takes the package's identity from it. It has no extensions.com.openai, so + // Codex and the directory still read their settings from .codex-plugin/plugin.json. + file: 'plugin.json', + set: (m) => assign(m, shared), + }, { file: '.codex-plugin/plugin.json', set: (m) => { @@ -107,6 +120,63 @@ for (const { file, set } of targets) { else writeFileSync(file, after); } +// The session-start nudge: one sentence telling the agent to open using-unity first, delivered +// in each client's own form. +// hooks/hooks.json Claude Code: a SessionStart hook prints it as additionalContext. +// The matcher leaves out resume, where the saved text is replayed. +// com.github.copilot/rules/unity.mdc Copilot CLI: an always-on plugin rule. +// rules/AGENTS.md Antigravity: an always-on plugin rule. +// Codex and Grok get none. A Codex plugin hook needs the user's approval again after every +// plugin update, so .codex-plugin/plugin.json sets "hooks": {} to keep Codex from picking up +// hooks/hooks.json. Grok runs hooks/hooks.json and ignores what a SessionStart hook prints. +const nudgeFiles: { file: string; content: string }[] = [ + { + file: 'hooks/hooks.json', + content: `${JSON.stringify( + { + hooks: { + SessionStart: [ + { matcher: 'startup|clear|compact', hooks: [{ type: 'command', command: nudgeCommand(meta.nudge) }] }, + ], + }, + }, + null, + 2, + )}\n`, + }, + { + // Copilot CLI lists the rule only with a description and alwaysApply: true, in a .mdc file. + file: 'com.github.copilot/rules/unity.mdc', + content: `---\ndescription: Unity skills\nalwaysApply: true\n---\n${meta.nudge}\n`, + }, + { file: 'rules/AGENTS.md', content: `${meta.nudge}\n` }, +]; + +// The hook command runs in sh, Git Bash or PowerShell, whichever the client picks on the +// user's machine, with no program or file it could depend on. A single-quoted `echo` is the +// one form all of them print unchanged. An apostrophe would end the quoting, so it is written +// as the JSON escape \u0027, which the client decodes. +function nudgeCommand(text: string): string { + if (/[\\"\r\n]/.test(text)) { + throw new Error( + '"nudge" in scripts/plugin-metadata.json has a backslash, a double quote or a line break. ' + + 'Shells disagree on how `echo` prints those, so the hook would break in some of them. Reword it.', + ); + } + const output = JSON.stringify({ hookSpecificOutput: { hookEventName: 'SessionStart', additionalContext: text } }); + return `echo '${output.replaceAll("'", '\\u0027')}'`; +} + +for (const { file, content } of nudgeFiles) { + const before = existsSync(file) ? readFileSync(file, 'utf8').replace(/\r\n/g, '\n') : null; + if (before === content) continue; + if (check) drifted.push(file); + else { + mkdirSync(dirname(file), { recursive: true }); + writeFileSync(file, content); + } +} + // The sample `codex plugin list`, `agy plugin list` and `copilot plugin list` output in the // README shows the version. Only those three lines are matched, so other version numbers in // the README are left alone. diff --git a/skills/using-unity/SKILL.md b/skills/using-unity/SKILL.md index 80d5761..8964918 100644 --- a/skills/using-unity/SKILL.md +++ b/skills/using-unity/SKILL.md @@ -21,7 +21,7 @@ A skill's own files are in its folder, `references//`. When the skill give A skill may tell you to use, load or check for another skill by name, for example "use the `unity-cli` skill" or "check that `ui` is in your client's skills". Every skill in the index below is installed with this one, though only `using-unity` is listed in your client's skills. Treat each of them as available: when a skill names one, read its file from the index and follow it, and don't offer to install it. Where a skill's files mention its `SKILL.md`, that is its `.md` file here. -## Index (33 skills, A to Z) +## Index (35 skills, A to Z) - **build-gtk**: Builds graph tools with Unity Graph Toolkit (GTK) on 6.6+, state machines on 6.7+, and importers for runtime assets. Use this skill for graph, node or state machine editors, or GraphView migrations. Not for Shader Graph, VFX Graph or Animator. File: `references/build-gtk/build-gtk.md` - **build-live-game**: Builds and operates a live game backend on Unity Gaming Services. Make sure to use this skill when the user wants sign-in or sign-in checks, trusted server-side game logic, player progress, remote config, achievements, battle passes or leaderboards. File: `references/build-live-game/build-live-game.md` @@ -46,11 +46,13 @@ A skill may tell you to use, load or check for another skill by name, for exampl - **optimize-audio**: Optimizes audio memory, CPU cost, and playback quality through import settings and mixer configuration. Use when asked to reduce audio memory or Audio Mixer CPU cost, change clip Load Types, sample rates or codecs, or force 3D audio to mono. File: `references/optimize-audio/optimize-audio.md` - **optimize-text-mesh-pro**: Optimizes TextMeshPro rendering, memory, and font setup, including font asset stacks, fallback atlases, SDF quality, and worldspace text. Use when the user asks about TextMeshPro font assets, CJK font fallbacks, or TMP memory, build size, quality or performance, not about translating text. File: `references/optimize-text-mesh-pro/optimize-text-mesh-pro.md` - **optimize-web**: Optimizes Unity WebGL and WebGPU builds for smaller downloads, faster loading, and smoother browser performance. Use when asked to shrink a web build, speed up its load, or fix stutter, memory or battery problems in the browser. File: `references/optimize-web/optimize-web.md` +- **project-auditor-fixes**: Runs a Project Auditor scan on a Unity project and fixes the reported issues in small, reviewable batches. Use when asked to audit a Unity project and fix the code, asset or settings issues Project Auditor finds. File: `references/project-auditor-fixes/project-auditor-fixes.md` - **route-audio-to-mixer-groups**: Routes Audio Sources into existing Audio Mixer Groups, classifying each source by what it plays. Use when the user asks about cleaning up mixer assignments, routing audio through a mixer, or which group a sound belongs in. File: `references/route-audio-to-mixer-groups/route-audio-to-mixer-groups.md` - **setup-vivox-voice-chat**: Adds and configures in-game voice and text chat with Unity Vivox. Use when asked to add voice or text chat to a multiplayer game, such as team channels, proximity voice, mute controls or private messages. File: `references/setup-vivox-voice-chat/setup-vivox-voice-chat.md` - **shader-graph-create-custom-node**: Generates custom Shader Graph nodes from HLSL code by reflection. Use when asked for a new Shader Graph node, or to make existing HLSL work as a reflected function node. File: `references/shader-graph-create-custom-node/shader-graph-create-custom-node.md` - **sprite-editor**: Edits sprite rectangles, names, borders, pivots, outlines, and slicing in a texture's import data by generating C# Editor scripts. Use when asked to slice a sprite sheet or change sprite pivots, borders, or outlines by script. File: `references/sprite-editor/sprite-editor.md` - **sprite-segment-3x3grid**: Segments a Sprite texture into a 3x3 grid and outputs a pattern of cells matching the center cell's color. Use when asked to analyze, compare, or document a sprite's structure or color distribution. File: `references/sprite-segment-3x3grid/sprite-segment-3x3grid.md` +- **transform-cli**: Drives the Asset Transformer SDK (Pixyz) with Transform CLI, outside the Unity Editor. Make sure to use this skill when the user asks to convert (e.g. STEP to GLB), optimize, render or export CAD or 3D files, run a pxz script, or test an SDK build. File: `references/transform-cli/transform-cli.md` - **unity-cli**: Controls Unity Editors and projects from the command line, including a running Editor. Make sure to use this skill when the user asks to install or manage Editors, licenses, or projects, set up version control, build, test, edit scenes, run C#, look up the scripting API or manual for the project's Unity version, or run any unity command. File: `references/unity-cli/unity-cli.md` - **unity-package-management**: Adds, removes, upgrades, and finds Unity (UPM) packages from outside the Editor. Use for package installs, checking package IDs and versions, or choosing which packages a game needs. File: `references/unity-package-management/unity-package-management.md` - **unity-pipeline**: Controls a Unity Editor or dev Player through the com.unity.pipeline package to compile, run tests, evaluate C#, method-reload code, enter Play Mode and capture screenshots. Make sure to use this skill when the user asks to drive, test, debug or inspect a running Unity Editor or Player from the command line. File: `references/unity-pipeline/unity-pipeline.md` diff --git a/skills/using-unity/references/project-auditor-fixes/SECURITY.md b/skills/using-unity/references/project-auditor-fixes/SECURITY.md new file mode 100644 index 0000000..570d7f1 --- /dev/null +++ b/skills/using-unity/references/project-auditor-fixes/SECURITY.md @@ -0,0 +1,16 @@ +# Security notes: project-auditor-fixes + +This skill has the agent read state from the user's open Unity Editor through `unity command script eval` when it checks a suspected fault in Play mode while fixing Project Auditor issues. Automated skill scanners flag running code in the Editor as a powerful capability. It is intentional, and it is limited by the safeguards below. + +## Accepted risks + +| Risk | Capability | Why it is accepted | +|---|---|---| +| `SEC_POWER_CAP` | Runs C# in the user's open Editor through `unity command script eval` | It only reaches the Editor the user already has open, on their own machine, as that user, so it grants nothing they couldn't do themselves. `script eval` sits behind the Pipeline capability gate. No code fetched from a remote source is run. | + +## Mitigations + +- **Only the user's own Editor.** `unity command script eval` talks to the Editor open on this machine. It can't reach another machine or another user's Editor. +- **Capability gate.** `script eval` is only available when the project's Pipeline package provides it. +- **No remote code.** The agent runs C# it writes itself to read Editor state. Nothing downloaded from outside is executed. +- **Read only, once.** The skill enters Play mode at most once, to chase a fault it already suspects, and reads state instead of adding logging or verification code to the user's scripts. It creates a restore point before it changes the project. diff --git a/skills/using-unity/references/project-auditor-fixes/project-auditor-fixes.md b/skills/using-unity/references/project-auditor-fixes/project-auditor-fixes.md new file mode 100644 index 0000000..80ac39d --- /dev/null +++ b/skills/using-unity/references/project-auditor-fixes/project-auditor-fixes.md @@ -0,0 +1,156 @@ +--- +name: project-auditor-fixes +description: "Runs a Project Auditor scan on a Unity project and fixes the reported issues in small, reviewable batches. Use when asked to audit a Unity project and fix the code, asset or settings issues Project Auditor finds." +--- + +Using Project Auditor +Project Auditor carries out a static analysis scan of the Unity Project and reports a list of CSV issues that may be fixed. Trigger, poll, read. + +## Important + +- Use the unity cli (`unity command --format json`) and the `unity-cli` and `unity-pipeline` skills for each step. +- Run C# with `unity command script eval --code ''`. Don't use `using` directives or unqualified types in the snippet. The compiler reads using `UnityEngine` and a bare AssetDatabase, Volume, or Object causes errors (CS0246 / CS0103 / CS0104). `return` what you want to read; it arrives at `data.result.result`. +- Create a restore point you can roll back to if your changes fail. +- Do only what's asked. Don't change unrelated assets or files. +- Never leave verification code in the user's script. Never build logging or detection they didn't ask for. See [Final step](#final-step). +- Avoid long explanations. + +## Step 1 + +Before you go forward with a workflow or diagnosis: + +1. Open and read the [documentation page(s)](#full-topic-map) that cover the specific subject related to what you intend to do or fix and check if you've missed anything. +2. Name the file(s) you read in your response. + +This is because your training knowledge about Unity might be out of date, incorrect, or for the wrong Unity version. + +## Full topic map + +The docs location depends on the project's Unity version, because Project Auditor is part of the Editor from Unity 6000.4, and a separate package (`com.unity.project-auditor`) in earlier versions. Check the Unity version first: + +- **Unity 6000.4 and later**: If the Editor install folder has a `Data/Documentation` folder (eg `...Unity/Hub/Editor/6000.6.0b2/Editor/Data/Documentation`), read the html files from the `en/Manual/project-auditor` folder. Otherwise the docs pages are online at `https://docs.unity.com/en-us/engine//manual/analysis/project-auditor.md`. docs.unity.com has no 6000.4 pages, so for 6000.4 use `https://docs.unity3d.com/6000.4/Documentation/Manual/project-auditor/` instead. +- **Earlier versions**: The docs pages are local markdown conversions of the Unity Manual, stored at `/Library/PackageCache/com.unity.project-auditor@*/`. Read only the .md files in that specific `PackageCache` subfolder. You must not look at non-.md files, or look outside at other Library or PackageCache folders, otherwise it takes too much time. If that folder has no `.md` files, use `https://docs.unity3d.com/Packages/com.unity.project-auditor@/manual/` instead. + +Prefer fetching the page directly (for example `WebFetch`) over searching (for example `WebSearch`) — faster and lands on the exact reference. Only fetch what you need, and only search if you don't have the exact URL. Replace `` with the following before fetching: + +- **docs.unity3d.com**: The Unity version, eg `6000.6` +- **Package on docs.unity3d.com**: The package version, eg `@6.6` or `@2.0`. Check the package version if unsure. +- **Engine on docs.unity.com**: The Unity version, eg `6000.3` +- **docs.unity.com**: The product version, eg `7000.0` + +Before fetching, check that `` is listed as a `## Version` heading in https://docs.unity.com/en-us/engine/llms.txt. If it isn't, use the docs.unity3d.com Manual instead. The two sites use different page names, so don't reuse the paths below. Instead, find each page by its title in `https://docs.unity3d.com//Documentation/Manual/docdata/toc.js`, then fetch `https://docs.unity3d.com//Documentation/Manual/.html`, where `` is the `link` value next to the title. + +Read the Unity major.minor from `ProjectSettings/ProjectVersion.txt` (for example `6000.5` from `6000.5.0f1`, because the full build number gives a 404), and each package's major.minor from `Packages/packages-lock.json` (for example `1.0` for `com.unity.project-auditor`). + +- [Project Auditor introduction](https://docs.unity.com/en-us/engine//manual/analysis/project-auditor/introduction.md) — local `project-auditor/project-auditor-introduction.html`, package `project-auditor-introduction.md`: the issue areas Project Auditor reports, and the window. +- [Analyze your project](https://docs.unity.com/en-us/engine//manual/analysis/project-auditor/analyze-project.md) — local `project-auditor/analyze-project.html`, package `analyze-project.md`: run an analysis, install the rules package, load reports. +- [Project issues introduction](https://docs.unity.com/en-us/engine//manual/analysis/project-auditor/project-issues/introduction.md) — local `project-auditor/project-issues-introduction.html`, package `project-issues-introduction.md`: common project issues and resources for fixing them. +- [Domain reloading issues](https://docs.unity.com/en-us/engine//manual/analysis/project-auditor/project-issues/domain-reloading-issues.md) — local `project-auditor/domain-reloading-issues.html`, package `domain-reloading-issues.md`: how domain reloading affects your project, and code fixes. + +### API reference + +The Project Auditor API is `Unity.ProjectAuditor.Editor`. Fixes can also change any Engine API (`UnityEngine`/`UnityEditor`) the reported code uses. In Unity 6000.4 and later, both are part of the Unity Engine. They are versioned by Unity version, so check the project's Unity version before relying on a specific class or method. + +1. Use the `unity-cli` skill to check the project's Unity version. +2. If the Editor install folder has a `Data/Documentation` folder (e.g. `.../Unity/Hub/Editor/6000.6.0b2/Editor/Data/Documentation`), grep the html files in the `en/ScriptReference` folder inside, and skip the remaining steps. +3. Otherwise, fetch and cache `https://docs.unity3d.com//Documentation/ScriptReference/xrefmap.yml` (replace `` with the Unity version, e.g. `6000.3`). This file lists every public API member's fully qualified name as a `uid` (e.g. `uid: 'UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3)'`). +4. Grep the yml file locally for a class or method instead of refetching per lookup. The file is large (about 6 MB), so don't read the whole file. +5. Convert the `uid` to a markdown page: remove the parameters in brackets, lowercase it, replace `.` with `/`, and add `.md`. Then fetch `https://docs.unity.com/en-us/engine//script-reference/`. For example, `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3)` => `https://docs.unity.com/en-us/engine/6000.3/script-reference/unityengine/rigidbody/addforce.md`. All overloads are on the same page. + - Constructors use `ctor` (e.g. `unityengine/vector3/ctor.md`), and indexers use `item` (e.g. `unityengine/vector3/item.md`). + - For operators, fetch the class page (e.g. `unityengine/vector3.md`) and follow its link. + - Links inside the pages start with `/engine/`. Add `https://docs.unity.com/en-us` before them. + - If the page doesn't exist for that Unity version, use the `href` in the `xrefmap.yml` entry instead (e.g. `href: 'Rigidbody.AddForce.html'` => `https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Rigidbody.AddForce.html`). + +Always use the docs for the project's Unity version rather than relying on training knowledge, since APIs are frequently marked obsolete between versions. + +In versions earlier than 6000.4, `Unity.ProjectAuditor.Editor` is part of the `com.unity.project-auditor` package and is versioned by package version. Read the version from `Packages/packages-lock.json`, fetch and cache `https://docs.unity3d.com/Packages/com.unity.project-auditor@/xrefmap.yml`, and grep it locally for a class or method instead of refetching per lookup. Don't read the whole file. + +## Procedure + +1. Get the project context: the Unity version from `ProjectSettings/ProjectVersion.txt`, and the `com.unity.project-auditor` or `com.unity.project-auditor-rules` version from `Packages/packages-lock.json`. If a value is missing, assume the latest Unity 6 version and the latest package version, name that assumption in your report, and carry on. If there's no project or Editor you can run the scan in, give the user the steps below for their project instead of stopping. +2. Read the [docs pages](#full-topic-map) for the issue types you intend to fix. +3. Check the [Prerequisites](#prerequisites), then follow [Best Practice](#best-practice) and the [Recipe](#recipe). +4. Run the test case again and compare it with the result from before your changes. +5. Do the checks in [Final step](#final-step). +6. Give the user the [Final report](#final-report), including which issues you fixed, and whether the checks passed. + +## Prerequisites +To use Project Auditor you'll need the Unity CLI installed - see the unity-cli skill for more details. +Once you have that, the `diagnostics run_audit` and `diagnostics audit_status` commands run Project Auditor checks. + +```bash +unity command diagnostics run_audit # optional: --categories Code,ProjectSetting --output my.csv +unity command diagnostics audit_status # repeat until a terminal status is returned +``` + +`diagnostics audit_status` terminal status are `completed` (with `csvPath` + `issueCount`), `failed`, `unavailable`, and +`interrupted` (a domain reload killed the scan — just re-run `diagnostics run_audit`). Polling is responsive while a +scan compiles assemblies and is busy on the main thread. You can only run one scan at a time: a second `diagnostics run_audit` +returns `busy`. There is no cancel — stop polling to abandon a scan. + +The output CSV has columns: `Category, Severity, Areas, Description, RelativePath, Line, DescriptorId, Recommendation` +(these are diagnostics only, so every row is something to fix; `Recommendation` says how to do it). + +> **Requires Project Auditor plus its rules.** `unavailable` means the Editor has no Project Auditor, +> or it has no analysis rules — in a built-in-module Editor the rules live in the separate +> `com.unity.project-auditor-rules` package (`unity command package add --identifier +> com.unity.project-auditor-rules --confirm true`). Read the `message` field; the command never reports +> an empty `completed` scan that would look like a clean project. + +## Gotchas + +- **`editor set_auto_tick` first.** Without it, recompile and tests can hang while the editor is + unfocused. The package's watchdog relies on the tick loop staying alive. +- **Method reload needs the game running.** `script.methodreload reload` applies to a live + game — enter Editor Play Mode (`unity command editor.playmode start`) first, or run a dev Player. +- **Player-only commands need a dev Player.** `console write`, `runtime set_time_scale`, `runtime status`, etc. hit + the Runtime server, which does not run in the Editor. +- **Async commands poll.** `recompile`→`recompile_status`, `run_tests --async_tests`→ + `test_status`. Never assume completion from the trigger call's response. +- **Target a specific instance** with `--instance host:port` or `--project-path ` + when more than one is running. + +## Best Practice + +When fixing a list of issues it's best practice to have a test case to make sure things are still working correctly. This might be a particular scene to open and start play mode, or a particular platform to build and run. If this isn’t present and there are no instructions, suggest a test case to the user and ask for confirmation. Run the test case before and after changes to make sure the project is still working. + +As you work, commit your changes in line with the user's version control setup. Wherever possible, commit step-by-step, breaking things down into changes that a user can easily understand. + +## Recipe +1. Make sure the project opens cleanly (with no compile or other errors in the Editor). If there are issues present, check with the user; they may know about them and want to ignore them. Run the test case and make sure you know what state it's in, fixing things if necessary. +2. Check the working tree first. If it has uncommitted changes you didn't make, ask the user how to preserve them (commit, stash or leave them), then create a scoped rollback point (a commit of only your own starting state, or a branch) so the process starts from a known version control state. +3. Open the project in the Unity Editor. Then use Unity CLI to run the audit command. +4. Group the issues by file and by type. +5. Choose a type of issue to work through one group or file at a time. +5.a. Default to fixing settings issues on assets or the projects by type. +5.b. Default to fixing code issues by file and subfolder. +5.c. However, it’s important to fix issues in human manageable and reviewable batches. +5.c.i. Making the same small change across a large number of files (for example, switching a boolean setting across many textures) is probably best done in one commit, or a commit per subfolder. +5.c.ii. When making code changes, make sure the code compiles between each commit. +5.d. Make changes based on the recommendations from Project Auditor. Commit each change once there are no errors in the editor. + +## Final step + +Do the following checks: + +1. Check the project has zero console errors. Use `console status` for counts. +2. Stop there unless the user asked you to prove it works or you suspect a specific fault. +3. If you do enter Play mode, do it once only to chase a fault you already suspect. Read the world through `script eval` rather than adding logging. Take no screenshots as they take too much time. + +If a check fails, go back and reread the [docs pages](#full-topic-map) to find out what you missed. + +## Final report + +Give the user a concise but not dense checklist of what you did and why, including any incidental side effects (for example, settings you toggled to test something, or temporary files you created). If the user needs to follow up with more steps or decisions, list them. For example: + +``` +I made the following changes: + +[✓] Created a `ColorChange.cs` script. + +Follow these steps to see the effect: + +1. Drag the script onto a GameObject in the Hierarchy window. +2. Enter Play mode to see the color change effect. +3. Use the `Speed` property in the Inspector window to change the speed the color changes. +``` diff --git a/skills/using-unity/references/transform-cli/SECURITY.md b/skills/using-unity/references/transform-cli/SECURITY.md new file mode 100644 index 0000000..14cb8a7 --- /dev/null +++ b/skills/using-unity/references/transform-cli/SECURITY.md @@ -0,0 +1,18 @@ +# Security notes: transform-cli + +This skill has the agent run Python against the Asset Transformer SDK in a Transform CLI session on the user's machine, through `run code`, `run file` and `workflow run`. It can also install a shared workflow file from an `https://` URL with `workflow install`. Running generated code is a powerful capability. It is intentional, and it is limited by the safeguards below. + +## Accepted risks + +| Risk | Capability | Why it is accepted | +|---|---|---| +| `SEC_POWER_CAP` | Runs agent-written Python, and workflow files, in a local Transform CLI session through `run code`, `run file` and `workflow run` | A session is a Python process on the user's own machine, running as that user, so a script can do what that user's account can do and no more, as a Python script the user ran with the SDK could. The skill uses a dedicated command when one covers the step, and keeps scripts for SDK calls no command makes. | + +## Mitigations + +- **Bounded by the user's own permissions, not sandboxed.** A script is ordinary Python: it can read and write what the user can and open network connections. The agent writes scripts for the user's task, and runs a downloaded workflow only when the user gave its source. +- **Commands before scripts.** The skill runs a named command (`scene`, `algo`, `occurrence`, `material`) when one covers the step, so most work never runs free-form code. +- **A shared workflow is code, trusted on purpose.** The skill installs one only from a URL or path the user gives, never one it finds itself. `workflow install` accepts `--sha256` to pin the exact file, refuses to replace a file edited since it was installed without `--force`, and records where each file came from (`workflow show`). `workflow check` checks only a workflow's SDK calls against the loaded SDK; it doesn't make the code safe to run. +- **A workflow the user didn't name runs only with their agreement.** A project's or the user's own workflow file outranks a built-in of the same name, so before running a workflow whose `origin` (`workflow show`) isn't `built-in` and that the user didn't name, the skill shows them its path and waits for their agreement. +- **The source model is never overwritten.** Exports go to a new path, so re-importing the source into a fresh session undoes any run. +- **Machine-wide changes need the user.** The skill asks before `license activate` or `license server set`, and `license activate` needs the user's own administrator approval. diff --git a/skills/using-unity/references/transform-cli/references/exit-codes.md b/skills/using-unity/references/transform-cli/references/exit-codes.md new file mode 100644 index 0000000..cb99d24 --- /dev/null +++ b/skills/using-unity/references/transform-cli/references/exit-codes.md @@ -0,0 +1,61 @@ +# Exit codes and the JSON envelope + +Relative paths in this file resolve to the skill directory, the folder above `references/`. + +The exit codes are the Unity CLI's, so `unity transform` and `transform` agree: + +| Code | Means | Examples (`errors[].code`) | +|---|---|---| +| `0` | Success | | +| `1` | The CLI could not do its own job | `SESSION_START_FAILED`, `HOST_EXITED`, `BRIDGE_UNREACHABLE`, `BRIDGE_TIMEOUT`, `SESSION_REGISTRY_INVALID`, `CONFIG_INVALID`, `FILESYSTEM_ERROR`, `INTERNAL_ERROR` | +| `2` | Bad arguments | `INVALID_COMMAND_ARGS` (also a file or skill copy in the way that `--force` replaces: ask the user before adding it), `SDK_INVALID` (a folder given as an SDK that isn't one) | +| `3` | A credential was rejected | `AUTH_FAILED` | +| `4` | Something must be set up first | `NO_SESSION`, `NO_SDK`, `NO_RUNTIME`, `MISSING_LIBRARY`, `NO_LICENSE`, `SDK_SHARED_MEMORY_LEFT`, `SDK_UNSUPPORTED`, `SESSION_OUTDATED`, `WORKFLOW_EMPTY_SCENE` | +| `6` | The operation failed | `SCRIPT_FAILED`, `COMMAND_FAILED`, `SESSION_NOT_FOUND`, `NO_GPU`, `WORKFLOW_BROKEN` and the others below | +| `7` | A service could not be reached, or the SDK's instance limit is full; a retry may help | `NETWORK_UNREACHABLE`, `SDK_INSTANCE_LIMIT` | +| `130` | Stopped by Ctrl+C | `INTERRUPTED` | +| `143` | Stopped by SIGTERM (macOS and Linux) | `TERMINATED` | + +The other exit-6 codes, by what they are about: + +| Area | Codes | +|---|---| +| Sessions | `SESSION_ISOLATED` (`session use` on a session `run --isolated` owns), `AMBIGUOUS_SESSION` (a name several running sessions carry: pass one of the ids in `data.candidates`), `SESSIONS_RUNNING` (`upgrade` while sessions run) | +| Files and the scene | `FILE_NOT_FOUND` (a script, model or license file the command needs), `OCCURRENCE_NOT_FOUND`, `MATERIAL_NOT_FOUND`, `STEP_NOT_FOUND` (`scene undo --to` / `scene redo --to` names no step in that stack: pick one from `data.candidates`, newest first) | +| The UI | `UI_ATTACH_FAILED`: the UI didn't open and the session is still headless and usable | +| SDKs | `SDK_NOT_FOUND`, `SDK_IN_USE` (a running session uses it, or it is the default), `API_NOT_FOUND` (`sdk api .` names nothing: try `data.candidates`, or with several names each `data.notFound[].candidates`), `VERSION_NOT_FOUND`, `DOWNLOAD_FAILED`, `CHECKSUM_MISMATCH`, `RUNTIME_SETUP_FAILED` | +| Licensing and the machine | `LICENSE_SERVER_UNREACHABLE`, `DOCTOR_FAILED` (`doctor --ci` found a blocking problem) | +| Workflows | `WORKFLOW_NOT_FOUND`, `WORKFLOW_INVALID`, `WORKFLOW_BROKEN` | +| The install | `UPGRADE_UNSUPPORTED` (`upgrade` can't update this install: `data.upgradeWith` names what can, `unity plugin upgrade transform` under the Unity CLI or `git pull` in a source checkout, and is `null` where no build is published for the platform), `SKILL_INSTALL_UNSUPPORTED` (use `unity skill install`: `data.installCommands` gives the command for each client asked for, `--local` for the project) | + +## The envelope + +Under `--json` (or `--format json`, the Unity CLI's spelling) every command prints one envelope on stdout, success or failure, and nothing a script should read on stderr: + +```json +{ "success": false, "command": "run", "data": { "output": "Exception: ValueError: boom\n..." }, + "errors": [{ "code": "SCRIPT_FAILED", "message": "Exception: ValueError: boom" }], "warnings": [] } +``` + +- Switch on `errors[].code`, never on the message, because the wording changes between releases. +- A failure keeps what helps fix it in `data`: a failed script's output and traceback in `data.output`, the running sessions in `data.candidates` when the one named doesn't exist, the materials of that name in `data.candidates` when a material name matches several, or the closest command in `data.suggestion` and the others at that level in `data.candidates` for a mistyped one (a command that closes, resets, clears, deletes, removes or uninstalls something, or activates a license or upgrades the CLI, only for a single typo of its name; a removed spelling suggests its replacement, which can be in another group). +- `command` is the command group that ran (`run`, `scene`), and `null` when the command line names none that exists. +- Advisories go in `warnings`, never on stderr. +- A command stopped by Ctrl+C or SIGTERM prints the `INTERRUPTED` or `TERMINATED` envelope under `--json`. On macOS and Linux it then dies by the signal, so a shell reports `130` or `143` and a parent that reads the wait status (Python's `subprocess`, Node's `child_process`) sees the signal; on Windows, Ctrl+C exits `130`. An isolated session the command started is closed first; other sessions keep running. + +## Acting on a failure + +| Exit | Code (`errors[0].code`) | Cause | Action | +|---|---|---|---| +| `6` | `SCRIPT_FAILED` | The script raised inside the SDK; its traceback is in `data.output`. | Fix the Python. Don't restart the session, because it is healthy. | +| `6` | `NO_GPU` | The operation renders and the machine has no graphics driver. | Skip the step and say so in the report. | +| `6` | `SESSION_NOT_FOUND` | The session named isn't running; the message says whether it was closed or its host exited. | If its host exited, read `session logs --session --all` for why. If you created it, create it again and re-import; otherwise tell the user. Don't switch to one of `data.candidates`, because they may be other jobs'. | +| `1` | `HOST_EXITED`, `SESSION_START_FAILED`, `BRIDGE_UNREACHABLE` | The host or its bridge failed. | Read `unity transform session logs --session --all`, then run `unity transform doctor --json`. | +| `2` | `INVALID_COMMAND_ARGS` | The arguments are wrong for this build. | Read ` --help` and fix the arguments. | +| `4` | `NO_LICENSE` | The SDK has no license to run with. | Run `license status --json` (exit 0 with `licensed: false` and the SDK's reason in `invalidReasons`) and tell the user. Ask before `license server set ` (a floating license, the usual way) or `license activate ` (a license file), because both change the machine's license. | +| `4` | `SDK_SHARED_MEMORY_LEFT` | Shared-memory objects an earlier SDK process left are in the way (on macOS, usually root's, left by the license installers an earlier `license activate` ran under `sudo`); the license itself may be fine. | Don't run `license activate`. Tell the user: once no session (`unity transform session list`) and no other program using the SDK runs, the command the message names removes them (it needs root, so ask first), or restarting the machine does. | +| `6` | `LICENSE_SERVER_UNREACHABLE` | The floating license server set can't be reached (no connection to its host and port); the SDK's reason is in the message. A server that answered and gave no seat is `NO_LICENSE` instead, and `license server status` answers it with exit 0, `reachable: true` and `licensed: false`. | Tell the user the reason. Ask before `license server set ` with the right address or `license server unset`, because both change the machine's license. | +| `4` | `NO_SESSION`, `NO_SDK`, `NO_RUNTIME`, `MISSING_LIBRARY` | Something must be set up first. | Do the setup the message names, such as starting a session or installing an SDK. | +| `6` | `UPGRADE_UNSUPPORTED` | `upgrade` can't update this install; `data.upgradeWith` names what can. | Tell the user to run it (`unity plugin upgrade transform` under the Unity CLI). Don't retry `upgrade` or replace the install another way. | +| `7` | `NETWORK_UNREACHABLE` | A service could not be reached. | Retry once, then tell the user. | +| `7` | `SDK_INSTANCE_LIMIT` | The SDK already runs as many times on this machine as its license allows; the license itself is fine. | Close a session you started and no longer need, then retry. Don't close sessions you didn't start, because they may be other jobs'; tell the user instead. Don't touch the license. | diff --git a/skills/using-unity/references/transform-cli/references/named-sdks.md b/skills/using-unity/references/transform-cli/references/named-sdks.md new file mode 100644 index 0000000..3c0a7f6 --- /dev/null +++ b/skills/using-unity/references/transform-cli/references/named-sdks.md @@ -0,0 +1,44 @@ +# Named SDKs + +Relative paths in this file resolve to the skill directory, the folder above `references/`. + +Every SDK the CLI knows has a name, and the name is what you type. Run `unity transform sdk --help` and `unity transform sdk --help` for the flags this build takes. + +## Scopes + +| Scope | Command | Lifetime | +|---|---|---| +| Global default | `unity transform sdk use ` | Until changed | +| One session | `unity transform session new --sdk ` | That host's life | +| One run | `unity transform run file x.py --isolated --sdk ` | The session the run creates (`--isolated`, or none running), closed after it; in a running session `--sdk` is ignored with a warning | + +## Get an SDK + +1. Run `unity transform sdk status --json` to see what is installed. +2. If the user wants the newest published build, run `unity transform sdk install`. It downloads, verifies, names the build after its version and makes it the default. +3. If the user already has an SDK folder (a local build, for example), run `unity transform sdk install --path --name `. It registers the folder in place and copies nothing, so a dev build keeps tracking its own rebuilds. `` is the SDK root or its `bin/`; a folder with no `pxz.pyd` / `pxz.so` fails with `SDK_INVALID` (exit 2). The name can't be a version (such as `2026.5.0.0`) or `latest`, because a download claims those: use `2026.5.0.0-local` or `dev`. +4. Run `unity transform sdk status --json` again and check the name appears with the expected path, and its Python runtime is `ready`. A `missing` runtime comes with the command that sets it up without downloading the SDK again. + +`sdk install` makes the new SDK the default; `--no-use` keeps the current default. Pass `--no-use` when the user only wants to try or compare a build, because every later session started without `--sdk` would otherwise run it. `sdk status` checks for a newer published build every time it runs (`updateAvailable`, `latest` in `data`); the other commands read a cache refreshed at most once a day. The CLI's own downloads go through `HTTPS_PROXY` / `HTTP_PROXY` / `ALL_PROXY` and honor `NO_PROXY`, read from the process environment only, not `~/.transform/.env`. + +## Rules + +- A string that could be a name or a path is read as a name first, because a stray `./dev` folder must not hijack the `dev` SDK. +- `sdk api` reads `--sdk `, else the SDK of the session `--session` names, else the default SDK, so pass `--session ` to read the build your session runs. It needs no session and never waits on a busy one. `sdk api ` lists a module. `sdk api ...` answers several names in full from one start of the SDK, so look a script's calls up together. `sdk guide` is the same text for every build; with `--session ` it also names that session's SDK version. +- `sdk install` and `sdk use` don't re-point running sessions, because a host keeps its SDK for life. Close and recreate the sessions they name, otherwise you are testing the old build. +- `sdk uninstall` on a `managed` SDK deletes its files; on a `linked` SDK it only forgets the name. Check the kind in `sdk status` before uninstalling. Neither is removed while a session uses it, nor the default without `--force` (`SDK_IN_USE`). + +## Licenses + +Downloading a build doesn't license it, and a session checks its license as it starts. One license covers every SDK build on the machine, so a new build needs no license step. + +If a session fails at startup with `NO_LICENSE`, run `unity transform license status --json` and tell the user what it reports. Both fixes change their machine, so ask first: + +1. Usually: a floating license from the organization's license server, `unity transform license server set ` (FlexLM by default; `--type pixyz` or `--type unity` for others), then `unity transform license server status` to check it gives a seat: `reachable: true, licensed: true` if it does, `licensed: false` with the SDK's reason (exit 0) if it answered with no seat, `LICENSE_SERVER_UNREACHABLE` (exit 6) if it can't be reached. `license server unset` goes back to the installed license: a session's server replaces the machine's license file, and `unset` puts back the copy kept in `~/.transform/license-backup`. +2. Otherwise: a license file the user received, installed with `unity transform license activate ` (a `.lic`, or a `.bin` activation file; the path is positional). It needs administrator rights, a UAC prompt or `sudo`, so with prompts forbidden, or under `--json` on macOS and Linux, it fails: the user runs it themselves from an elevated terminal, or after `sudo -v` on macOS and Linux. Never copy a license file into the SDK's license folder by hand. + +## Validate a local SDK build + +1. Register each build under its own name, with `--no-use` so the user's default SDK stays as it was: `unity transform sdk install --path --name before --no-use` and `unity transform sdk install --path --name after --no-use`. +2. Create one session per build: `unity transform session new --name a --sdk before` and `unity transform session new --name b --sdk after`. +3. Run the same steps against both with explicit `--session`, and compare `scene info --json` output. diff --git a/skills/using-unity/references/transform-cli/references/scene-editing.md b/skills/using-unity/references/transform-cli/references/scene-editing.md new file mode 100644 index 0000000..374d6d0 --- /dev/null +++ b/skills/using-unity/references/transform-cli/references/scene-editing.md @@ -0,0 +1,63 @@ +# Editing the scene tree + +Relative paths in this file resolve to the skill directory, the folder above `references/`. + +- [Target one part](#target-one-part) +- [Delete and merge](#delete-and-merge) +- [Move, reparent and rename](#move-reparent-and-rename) +- [Flatten the hierarchy](#flatten-the-hierarchy) +- [Hide, show, pivots and instances](#hide-show-pivots-and-instances) +- [Create and duplicate](#create-and-duplicate) +- [Undo](#undo) + +Each command below that changes the scene is one undo step, so `scene undo` takes it back. Lookups (`occurrence find`, `metadata find`) and `--dry-run` previews change nothing and add no undo step, so don't count them when you undo. A command that fails adds no undo step either: it takes back what it did before it failed. Each `run file` / `run code`, and each step of a `workflow run`, that changed the scene is one undo step too; one that changed nothing, because it only read or printed, or raised before any change, adds none. Run `unity transform occurrence --help` and `unity transform scene compress --help` for the flags this build takes. + +## Target one part + +If the user wants to change one part of an assembly, find it first (`occurrence find --name ` or `metadata find --key --value `), then pass its id as `--occurrence` to the `algo` command, because without it the command works on the whole scene. The SDK runs `metadata find`'s regex, so it refuses (exit 2) a named group `(?P…)`, a lookbehind, a comment `(?#…)`, an inline flag, or repeats that write out more than 10000 characters (`a{20000}`); write `--ignore-case` rather than `(?i)`. + +`algo remove-occluded`, `algo tessellate`, `scene create` and `occurrence set-transform` refuse a value outside the range their `--help` gives (a `--resolution`, `--max-angle` below 1, `--subdivisions`, a huge `--scale`), with `INVALID_COMMAND_ARGS` (exit 2) before the session is touched: values past it crashed or stalled the session. Pick a value inside the range rather than retrying. On a large model, `tessellate` also refuses (exit 2) a value whose estimated memory the machine can't spare; `data.largest` is the finest that fits, so retry with it (or with `--occurrence` on part of the scene). `tessellate` at its defaults isn't checked; a finer value is also held to about 8 GB. + +UVs come from the `generate-uv` workflow, not an `algo` command: `workflow run generate-uv` projects UVs onto the parts, packs the islands and fits them to 0-1, on channel 0, across the whole scene, or with `--param occurrence=` on that occurrence and everything under it. `--param projection=` picks the shape they are projected onto, fitted to the model: `aabb` (the default: its bounding box), `cubic-aabb` (the same at one scale on each axis), `mbb` (its smallest bounding box, turned to fit), `cylinder` or `sphere`; pick the one closest to the part's shape. `--param channel=` (0-7), `resolution=` (64-4096 px, default 1024) and `padding=` (px, at most 32768 / resolution) set the rest. A padding too large for the resolution, an occurrence that isn't in the scene, or a resolution the machine can't spare the memory for (measured on the occurrence alone, so `occurrence=` on part of the scene is the way out) fails the run (exit 6) before the scene changes, naming what fits. Each of its steps (`project`, `pack`, `normalize`) that changed the scene is one undo step: to take the run back, `scene undo --steps ` with `n` the sum of `undoSteps` in `data.steps` (3 when every step ran, 0 when it was refused or found no triangles), never a fixed 3. To unwrap or merge islands first, or to project onto a shape you place, `workflow copy generate-uv --as ` and edit the copy. + +`algo normals`, `decimate` and `remove-occluded`, and the `generate-uv` workflow, need triangles: on CAD not yet tessellated they change nothing and warn (`There are no triangles to work on`, or from the workflow `No step had any triangles to work on`), so run `algo tessellate` first. Where only some parts have triangles (a STEP file that carries a mesh for some parts, or CAD imported beside a mesh), `normals` and the `generate-uv` workflow work on those, exit 0, and warn (` of parts had no triangles to work on`). `normals` reports `created` true, `data.skipped` (the parts left unchanged, `{ occurrenceId, name }`; `null` when no part had triangles) and `data.partCount` (every part); the workflow lists the parts it left in its output (`data.output`), after `Left unchanged, with no triangles:`. Check `warnings` rather than the flag: run `algo tessellate`, then the same command again. `algo tessellate` gives every part that has CAD surfaces a mesh at the settings you pass, replacing one it already has; when the triangle count doesn't change it warns: there were no CAD surfaces, or those settings give as many triangles as before. + +An `.obj` file carries no unit: `scene export` writes millimeters and `scene import` reads `.obj` as centimeters, so an `.obj` round trip comes back 10 times larger (the export warns). Use `.glb` or `.fbx` when the file comes back into a session; if the user must use `.obj`, run `occurrence set-transform --scale 0.1` on the occurrence `scene import` reported: it holds the file's parts at scale 1, and the 10 sits on the parts under it (`--scale` sets the scale, it doesn't multiply it). + +## Delete and merge + +If the user asks to delete or merge parts, run `occurrence delete` or `occurrence merge` with `--dry-run` first, then again without it, only for the parts the user named, because neither asks before it changes the scene. + +To cut draw calls, use `occurrence merge --by material` (or `assembly`, `final-assembly`, `name`, `level --max-level `), because it groups and merges in one call instead of one per group. Its dry run gives the parts in scope, not the groups the SDK will make. + +## Move, reparent and rename + +If the user asks to move, rotate, scale, reparent or rename a part, use `occurrence set-transform`, `occurrence set-parent` or `occurrence rename` instead of a script, because each reports the value it replaced. + +- `set-transform` is local to the parent, in mm and degrees, and rotates about X, then Y, then Z. Any of `--position`, `--rotation` and `--scale` you leave out stays. A mirror reads back as at most one negative scale (two negative axes are a 180° turn, shown in the rotation), so setting the rotation or the scale alone keeps it. +- `set-parent` keeps the part where it is in the world unless you pass `--keep-local`. On a prototype, its instances keep their place too: each gets the local matrix it had as its own, so later transforms of the prototype no longer move them. + +## Flatten the hierarchy + +If the scene tree is deep after a CAD import, or the user asks to flatten or simplify the hierarchy, run `scene compress --dry-run`, then `scene compress`, because it removes the occurrences that hold no part and have one child or none, and keeps instances shared. + +- Add `--rake` only when the user wants every part directly under one parent, because it drops the assembly structure. +- Pass `--occurrence` to limit it to one sub-assembly, and use `data.resultOccurrenceId` afterwards, because an occurrence left with one child is replaced by it. + +## Hide, show, pivots and instances + +If the user asks to hide or show parts, recentre a pivot, or edit one copy of an instanced part, use `occurrence hide`, `occurrence show`, `occurrence set-pivot --to center|origin` or `occurrence make-unique` instead of a script, because each is one undo step. A hidden part keeps its triangle count in every count and in the `--min-triangles` / `--max-triangles` filters, so hiding a part never makes it look empty. A point cloud or a curve-only part has no triangles but isn't empty: `--max-triangles` never matches it, and deleting one reports its points and lines. + +Tell the user when `set-pivot` warns that it made instances unique, because each copy then has its own geometry, which costs memory and file size. + +`metadata set` on an instance that shows its prototype's metadata (`source: prototype`) gives the instance a copy of those entries plus the new ones (`source: instance`): later changes to the prototype's metadata no longer reach it. + +## Create and duplicate + +If the user wants an empty group to move parts into, or a copy of a part, use `occurrence create --name ` or `occurrence duplicate `, because each reports the new ids. + +Pass `--instance` only when the copies should share geometry, because editing one instance changes them all. + +## Undo + +If a step made the scene worse, such as a decimate that went too far, run `scene undo` instead of re-importing, because the steps before it stay as they were. Run `scene history` for the step names, newest first, then `scene undo --to ` to make that step the latest one again, or `--steps ` to undo the newest `n`. To try another setting on the model as imported, such as a second decimate ratio, run `scene undo --to "scene import"` rather than `session reset` and a fresh import, because importing a large file again is slow. Then look ids up again, because a later command may reuse an id the undo freed. `--to` takes the exact step name; one that isn't in the history is refused with `STEP_NOT_FOUND` (exit 6) and undoes nothing, so pick a name from `data.candidates`; a session an older CLI started refuses `--to` with `SESSION_OUTDATED`, so use `--steps` there. diff --git a/skills/using-unity/references/transform-cli/references/sessions.md b/skills/using-unity/references/transform-cli/references/sessions.md new file mode 100644 index 0000000..979094b --- /dev/null +++ b/skills/using-unity/references/transform-cli/references/sessions.md @@ -0,0 +1,61 @@ +# Sessions + +Relative paths in this file resolve to the skill directory, the folder above `references/`. + +A session is a detached host that owns one scene and outlives the CLI call that made it. Run `unity transform session --help` for the commands this build has. + +A session's name (`session new --name`) uses letters, digits, `.`, `_` and `-`, can't start with `ses_`, and must be unique among running sessions: `session new` refuses a taken name with `INVALID_COMMAND_ARGS` (exit 2). Every command that takes a session accepts the id or the name. + +## Which session a command uses + +1. `--session `, when given. +2. Else the session `TRANSFORM_SESSION` names. A session it names that isn't running is `SESSION_NOT_FOUND`, never a fallback to the active one. +3. Else the active session: the one `session new` last started, or the one `session use ` picked. When it closes, the newest session still running becomes active; when its host dies, the next command warns (in `warnings`) before it uses another, so check `data.sessionId` against the session you expect. `session info` with no `--session` shows which one it is, and `session list` marks it. +4. Else `NO_SESSION` (exit 4). + +A session that `--session` names and isn't running is `SESSION_NOT_FOUND` (exit 6), and the message says whether it was closed or its host exited; `session logs --session --all` still reads its log. + +Every result names the session it used in `data.sessionId`, and a person sees `Using session ` on stderr. + +## Who creates and closes sessions + +| Command | Creates a session | Closes it | +|---|---|---| +| `session new` | Yes, and makes it active unless `TRANSFORM_SESSION` is set | No | +| `run file` / `run code` without `--session` | Only with `--isolated`, or when no session is running at all and `TRANSFORM_SESSION` is unset | Only the one it created | +| `run file` / `run code` with `--session` | No | No | +| Every other command | No: it needs a running session | No | +| `session close --session ` | No | That session | + +An isolated session is never active, so a loop of `run file … --isolated` over many files can't mix scenes or leave hosts behind: its host also stops if the `run` is killed, and `session close --all` closes one whose `run` is gone (it skips one whose `run` still goes). `--isolated` with `--session` is refused (exit 2). One run that loops over several files shares one scene, so clear it between files or run once per file. + +## Agents side by side + +The active session is shared by every process of the same user, so it can change under an agent that relies on it. Launch each agent with `TRANSFORM_SESSION=` in its environment, or pass `--session ` on every call. Environment variables are per process, so each agent keeps its own. While `TRANSFORM_SESSION` is set, `session new` leaves the active session as it is. `~/.transform/.env` doesn't set it, because every process shares that file. + +A session runs one command at a time; a command sent while another runs queues behind it. A command that waits says so on stderr (`Session is busy running …`). `session reset` gives up after 30 seconds and `ui open` / `ui close` after 10 with `BRIDGE_TIMEOUT`; a request whose CLI gave up or was stopped leaves the queue and never runs. `session list` shows such a session as `busy`, with the command it runs and for how long (`running` in `--json`), because `info` and `ping` still answer. A `busy` with no command means the host is alive but didn't answer `info` in time (a long SDK call, or a window opening); `unreachable` is kept for a host the CLI can't connect to. `busy` means a command has not returned, not that it is making progress: a hung script stays `busy`. `session close` without `--force` stops a session that doesn't answer within about 5 seconds, because it is still running a command, and that command doesn't finish (`data.terminated: true`, with a warning); one that answers gets up to 5 more seconds to exit; `--force` stops it at once. Closing discards the scene, the running command and the queue, and a busy session can't export first. So if your own session shows `busy`, watch `session logs --session --follow`, and close it only once it has clearly hung. Leave a busy session you don't own alone. + +## Where a session runs + +A session runs in `~/.transform`, so a relative path inside a script (`pxz.io.importScene("model.step")`) resolves there. Write absolute paths in `pxz` calls. A path given to a command, such as `scene import .\model.step` or `run file .\fix.py`, resolves where you run the command. A script's own arguments, after `--` (`run file .\convert.py -- --input C:\in\a.step`), reach it as typed, so pass absolute paths there too. An `argparse` script runs unchanged, as `__main__` with `__file__` set, and `sys.exit(0)` succeeds. A `SIGINT` the script sends (`signal.raise_signal`, `_thread.interrupt_main`) doesn't stop it or the session: the script runs to its end, then fails with `SCRIPT_FAILED` and a `KeyboardInterrupt`. Put every CLI option, `--json` included, before the `--` (`run file x.py --session --json -- --input C:\in\a.step`), because everything after it is the script's `sys.argv[1:]`. + +## Starting over and keeping a scene + +- To try something again on the same model, such as another decimate ratio, run `scene undo --to "scene import"` instead of resetting, because it keeps the import and importing a large file again is slow (the Undo section of scene-editing.md). +- To start over on a new model in the same session, run `session reset`, because it clears the scene, its materials and the script variables. Run `scene clear` instead only when a later script needs variables an earlier one set, because it deletes the occurrences and resets the scene root (its name, transform, visibility, material and metadata), and keeps the materials and the script variables. +- To keep the scene past `session close`, save it with `scene export ` (always the whole scene: `--occurrence` is refused for `.pxz`) and load it later with `scene open `. Warn the user before `scene open`, because it replaces the whole scene and clears the undo history, even when the file fails to open. + +## The UI + +`ui open` builds the SDK's interactive UI, a real window on the session's scene, and costs about 450 MB; `ui close` destroys it. `session new --ui` opens it at startup. Whoever is at the UI can edit the scene and run operations in it, and the session's commands see those changes. `session list` and `session info` report the session's `mode` as `headless` or `ui`. A session starts headless and needs no GPU or display; `scene screenshot` renders offscreen. A failed attach leaves the session headless and still running scripts; `session info` reports why in `uiError`. Only `ui open` needs the SDK's `pxzui` and write access to the SDK folder (pxzui writes `callback_manager.py` there as it opens), so a read-only SDK folder or a registered build without its UI breaks `ui open`, never the session's start. A downloaded build always has its UI; a registered one whose `pxzui` the session can't find (in `/PixyzUI/`, or a `PixyzUI` / `UI` folder near the SDK) takes `session new --pxzui `. + +- Don't open the UI just to take a screenshot, because `scene screenshot` renders offscreen. +- While the UI is open, run `scene info` again before relying on an earlier reading, because the user can edit the scene and run operations in it. +- If `ui open` reports the session is still headless, read `uiError` from `session info` and keep working headless without respawning, because a failed attach leaves the session fully usable. +- If the user refers to "these parts" or "what I picked" in the UI, run `selection get` for their ids. Use `selection set ` to show the user parts you found. + +When every Vulkan device renders on the CPU, as inside WSL, where Ubuntu 22.04 has only `llvmpipe`, `ui open` refuses with `UI_ATTACH_FAILED` and the session stays headless, because a window on that renderer crashed the session host. Screenshots still work there but take up to a minute, and the CLI waits for them and warns that the render ran on the CPU; `session info` reports the renderer as `softwareRenderer`. To look at the scene from WSL, use the Windows build (`transform.exe`), which takes `/mnt/c/...` paths as `C:\...`. So when `ui open` refuses for this reason, keep working headless, tell the user to look on a machine with a GPU, and don't treat a slow screenshot as a hang. + +On a Windows laptop with an integrated and a discrete GPU, a window on the integrated GPU crashed the session host, so the session's `python.exe` has to be set to High performance in Settings > System > Display > Graphics. `session new` sets it for the CLI's own Python (under `~/.transform/runtimes`) when that `python.exe` has no setting yet, and says so on stderr; it never changes an interpreter other programs share. When it has another one, which the CLI leaves alone, or the session predates the CLI that sets it, `ui open` refuses with `UI_ATTACH_FAILED`; the message names the `python.exe`, and the setting takes effect for a new session. + +On macOS with SDK 2026.6 or earlier, building the window crashed the session host, so `ui open` refuses with `UI_ATTACH_FAILED` and `session new --ui` starts headless with `uiError` set; the session keeps its scene. Keep working headless, and don't retry. diff --git a/skills/using-unity/references/transform-cli/references/troubleshooting.md b/skills/using-unity/references/transform-cli/references/troubleshooting.md new file mode 100644 index 0000000..b78f432 --- /dev/null +++ b/skills/using-unity/references/transform-cli/references/troubleshooting.md @@ -0,0 +1,72 @@ +# Troubleshooting + +Relative paths in this file resolve to the skill directory, the folder above `references/`. + +Run `unity transform doctor --json` first: it checks the SDK, its runtime, the libraries it needs, a session start, the license and the GPU, and each failed check names its fix. Then read the per-session log: `unity transform session logs --session --all` (also after the session closed), or `~/.transform/logs/.log`. It holds each CLI command (`[cli …]` lines) and each script's source next to what the SDK printed. The host's stdout, stderr and tracebacks go there and nowhere else. `run file` / `run code` also stream it to stderr while the script runs (not under `--json`). + +When neither explains the failure and it looks like a bug in the CLI or the SDK rather than in the script, suggest the user report it with `unity bug --area transform` (Unity CLI 1.0.0-beta.15 or later). It sends their system information and logs to Unity, so don't run it without asking. Give the user the id of the session that failed (`data.sessionId`) to put in the description. Installed through the Unity CLI, the report carries the end of the 5 most recently written session logs, which may not include that one; with a standalone install, it carries none. Then suggest attaching the end of that session's log: save it with `unity transform session logs --session --tail 5000` and pass the file to `--attachments`. Never suggest attaching `~/.transform/logs/.log` itself: an attachment is sent whole and unredacted, and a log can run to hundreds of MB. The log holds each script's source and the file paths it used. + +| Error text | Root cause | Resolution | +|---|---|---| +| `The host of session exited before its bridge on port came up.` (`SESSION_START_FAILED`, exit 1) | The host crashed while starting. The error ends with the log's tail. | Read the traceback, or `session logs --session --all`, and fix what it names. A missing license or system library is reported as `NO_LICENSE` / `MISSING_LIBRARY` instead. | +| `The host of session did not become ready on port .` (`SESSION_START_FAILED`, exit 1) | The host stayed alive but didn't answer within 60 seconds (not configurable), so the CLI stopped it: usually a slow or unreachable floating license server, or antivirus scanning the SDK on first load. | Retry once. If it times out again with a floating license, run `unity transform license server status`; the log tail shows how far startup got. | +| `The Asset Transformer SDK could not load: is missing` (`MISSING_LIBRARY`) | Linux only: `pxz.so` links system libraries this machine lacks. | Tell the user which packages the message names. `liblber-2.5.so.0` means Ubuntu 24.04, which lacks OpenLDAP 2.5, with SDK 2026.5 or earlier: install SDK 2026.6 or later (`unity transform sdk install`), which brings its own, or run in an `ubuntu:22.04` container. | +| `The Asset Transformer SDK needs the Microsoft Visual C++ Redistributable (x64)` | Windows only: the SDK's DLLs need the VC++ runtime. | Tell the user to run the `vc_redist.x64.exe` the message names, from the SDK's `bin\` folder; it needs administrator rights. | +| `Not an Asset Transformer SDK install (no pxz.pyd/pxz.so under ...)` (`SDK_INVALID`, exit 2) | The path has no `bin/pxz.pyd` (Windows) or `bin/pxz.so` (Linux/macOS). | Point at the SDK root or its `bin/` folder. | +| `This SDK has no Python runtime yet` (`NO_RUNTIME`, exit 4) | A release build found no runtime for this SDK: its setup failed, a registered build's `PixyzUI/requirements.txt` changed, or `~/.transform/runtimes` was deleted. | Run the `sdk install` command the message names, the same one `unity transform sdk status` prints beside each SDK whose runtime is `missing`. Nothing is downloaded twice. | +| `The SDK is registered, but setting up its Python runtime failed`, with a connection or download error | No network to Unity's Artifactory (`unity3ddist.jfrog.io`), or GitHub/PyPI for anything not mirrored there (`imgui-bundle` always comes from PyPI), often behind a proxy. | Set `HTTPS_PROXY` (and `PIP_INDEX_URL` for an internal PyPI mirror) in the shell's environment, not `~/.transform/.env`, which these aren't read from, then re-run the same `install`. The CLI's own downloads also honor `HTTP_PROXY`, `ALL_PROXY` and `NO_PROXY`. | +| The same error, naming a package with no build for this platform | The setup installs only prebuilt wheels, and that package has none here. | No fix: tell the user, with the package name, and suggest reporting it. | +| `CHECKSUM_MISMATCH` from `sdk install` | The download didn't match Artifactory's checksum and was deleted. | Retry once. If it fails again, a proxy between the machine and Artifactory is the usual cause: tell the user. | +| `A file in the runtime is past Windows' 260-character path limit` | Windows only: the home folder's path is so long that a package file under `~/.transform/runtimes` passes MAX_PATH, and long paths are off. | Tell the user to enable long paths (`LongPathsEnabled` = 1, as an administrator) or use a shorter home folder, then re-run the same `install`. | +| `Failed to spawn session host: 'uv' was not found on PATH` | A source checkout runs the host through uv. | Install uv, or use a release build. | +| `Could not open the UI for ; it is still running headless.` (`UI_ATTACH_FAILED`, exit 6) | The attach failed: a registered SDK without its `pxzui`, no display, no graphics driver, or an SDK folder the user can't write to (pxzui writes `callback_manager.py` there as it opens; a read-only SDK folder breaks only `ui open`, never a session's start). The session is fine. | Read `uiError` from `unity transform session info --session --json` and keep working headless. Tell the user the fix it names: `session new --pxzui ` for a UI elsewhere, a desktop session or X forwarding for no display, write access to the SDK folder. | +| `The only Vulkan device here renders on the CPU (...), and a window on one can crash the session, so none is opened.` | The machine has only a software Vulkan renderer (`llvmpipe`), as WSL does. The session is fine. | Keep working headless; screenshots still work, slowly. To look at the scene, use a machine with a GPU, or the Windows build from WSL. | +| `This machine has an integrated and a discrete GPU (...), and a window crashes the session unless Windows runs it on the discrete one, so none is opened.` | A Windows laptop with two GPUs, and the session's `python.exe` has a graphics preference other than High performance (`session new` sets High performance only where there is none). The session is fine. `doctor` warns with the same text in its `ui` check. | Keep working headless. For a window, tell the user to set that `python.exe` (the message names it) to High performance in Settings > System > Display > Graphics, then start a new session. | +| `The Asset Transformer SDK for macOS has a bug that crashes the session as it builds a window, so none is opened.` | `ui open` or `session new --ui` on macOS with SDK 2026.6 or earlier, whose window crashes the session host. The session is fine and keeps its scene. `doctor` warns with the same text in its `ui` check. | Keep working headless: scripts, scene commands and screenshots work. Don't retry `ui open`. To look at the scene, tell the user to use a later macOS SDK release once one exists, or Windows or Linux. | +| The UI is a menu bar over a black viewport | pxzui saved a broken layout on an earlier teardown. | Run `ui close` then `ui open`: the host renames the broken layout (`.broken`) before attaching. If it persists, tell the user to close the UI and delete `%APPDATA%\PixyzSDK\PixyzUI_v.ini` (Windows) or `~/PixyzSDK/PixyzUI_v.ini` (macOS, Linux). | +| `This operation renders, and no OpenGL context could be created here` (`NO_GPU`) | No usable graphics driver. | Skip the screenshot and `algo remove-occluded`; everything else works, `algo decimate` included. On Linux, Mesa's software renderers (lavapipe from `mesa-vulkan-drivers`, and llvmpipe) let them render on the CPU, at 30 to 60 s a screenshot: suggest it to the user. Don't call `view` functions from `run code` / `run file` there: without a driver they can end the session, and only `scene screenshot` and `algo remove-occluded` check for one first. | +| `The import of added no geometry, only empty occurrences …` (`COMMAND_FAILED`, exit 6) | `scene import --clear` (or `workflow run --input`) read nothing from the file: it is empty or damaged. The scene is left as it was. Without `--clear`, the same file imports as an empty occurrence, with a warning. | Check the file, or export it again from its source; don't retry it unchanged. | +| `The export also removed line(s) (curves) from the session's scene …` (warning) | The SDK's `.pdf` / `.prc` writer deletes the lines it writes from the live scene, and no undo step brings them back. The file is fine. | Export every other format you need first, or re-open the model (`scene open` / `scene import --clear`) after a `.pdf` or `.prc` export. | +| `This SDK doesn't import '' files. 'scene formats --import' lists the formats it reads.` (`INVALID_COMMAND_ARGS`, exit 2) | The loaded SDK build reads no format with that extension. No flag changes what a build imports. | Run `scene formats --import --session --json` and tell the user which formats this SDK reads. | +| None: a command succeeds and `scene info` counts don't change | Some algorithms report success and change nothing until the scene is prepared, such as `filletMesh` until lines of interest are marked (`identifySharpEdges` or `identifyLinesOfInterest`). | Read the call with `sdk api`, run the step it needs first, and compare the counts again. | +| `The Asset Transformer SDK keeps relaunching PiXYZFinishInstall` (`NO_LICENSE`) | Linux: a license file was copied into the SDK's license folder by hand, before the SDK's one-time setup step ran; the step then relaunches itself. | Tell the user to move the file out of the folder the message names, then run `unity transform license activate `; it changes their machine, so ask first. With the file still in the folder, `license activate` refuses with `The license folder (…) already holds …` (`NO_LICENSE`); the remedy is the same. | +| `The Asset Transformer SDK can't start another instance on this machine` (`SDK_INSTANCE_LIMIT`, exit 7) | The machine already runs as many SDK instances as its license allows (sessions, or other programs using the SDK). The license itself is fine. | Close a session you started and no longer need (`unity transform session list`, then `session close --session `) and retry. If none is yours, tell the user; don't close other jobs' sessions, and don't run `license activate`. | +| `The SDK's license installers left … taken in /dev/shm (…)` (warning, or the end of a `license activate` error) | Linux: the SDK counts its slot files in `/dev/shm`, not running instances, and `license activate` kept slots its installers left because it couldn't prove no process holds them. Until they go, sessions can fail with `SDK_INSTANCE_LIMIT`. | Tell the user: once no session (`unity transform session list`) and no other program using the SDK runs, the `rm -f` command the message names frees them. It needs root, so ask first; don't run it while other jobs' sessions run. | +| `The Asset Transformer SDK can't create its shared memory: Create shared memory failed` (`SDK_SHARED_MEMORY_LEFT`, exit 4), or on macOS the warning `The SDK's license installers left … taken in shared memory (…)` | Shared-memory objects of the SDK's names are left from an earlier process and the SDK can't open them: on macOS, root's, left by the license installers that `license activate` ran under `sudo`. The license itself may be fine. | Don't run `license activate`. Tell the user: once no session (`unity transform session list`) and no other program using the SDK runs, the command the message names removes them (it needs root, so ask first), or restarting the machine does. | +| `The Asset Transformer SDK has no license to run with` (`NO_LICENSE`) | The session checked its license as it started and found none, an expired one, one for another machine, or a license server that answered and refused (no free seat, a license file it can't write, no FlexLM on this platform). | Run `unity transform license status` and tell the user its `why not:` line and `valid:` dates. Both fixes change their machine, so ask first: usually `license server set ` for the organization's floating license server, else `license activate ` for a license file they received. | +| `The floating license server didn't answer` (`LICENSE_SERVER_UNREACHABLE`, exit 6) | The session couldn't connect to the license server set with `license server set`: a host name that doesn't resolve, a wrong port, a server that isn't running, or a firewall. The SDK's reason follows the text. A server that takes the connection but refuses (no free seat, a license file the SDK can't write, a platform without FlexLM) is `NO_LICENSE` with the SDK's reason instead, and so is a FlexLM server whose vendor daemon's port alone is blocked: only the port set is tried. | Tell the user the reason, and ask before any change: `license server set ` with the right address, or `license server unset` to go back to the license installed on the machine. | +| `The license file still names the license server ` (warning from `license server unset`) | A session an earlier CLI started took a seat from the server, and the SDK replaced the machine's license file with one naming the server; that CLI kept no copy, so `unset` can't put it back. New sessions keep using the server. | Tell the user; the fix changes their machine, so ask first: `unity transform license activate ` with their license file. | +| ` needs elevation, which asks for approval, and prompts are forbidden here (UNITY_NON_INTERACTIVE)` (`COMMAND_FAILED`), or on macOS and Linux ` needs administrator rights, and sudo needs your password for them, which it can't ask for: ` (`COMMAND_FAILED`, `data.reason` `noTerminal`, `json` or `promptsForbidden`) | `license activate` needs a UAC prompt (Windows) or `sudo` with a password (macOS, Linux), and can't ask: prompts are forbidden, or on macOS and Linux it ran under `--json` or with no terminal (often the case when you run it). | Tell the user to run `license activate ` themselves: from a terminal opened with Run as administrator on Windows, or in a terminal on macOS and Linux, after `sudo -v` there if prompts are forbidden or it runs with `--json` (in CI, as root or with passwordless `sudo`). It changes their machine. | +| `No session is running. Start one with 'unity transform session new'` (`NO_SESSION`) | Only `run file` / `run code` create a session. | Run `unity transform session new --name ` first, then pass `--session `. | +| `Session was started by an older CLI that would run the script without its arguments` (`SESSION_OUTDATED`) | `run file` / `run code` got arguments after `--`, and the session's host predates them. | Start a new session (`session new --name `) and re-import the source, or pass `--isolated` for a one-shot script. | +| `Exception: SystemExit: (exit code 2)` (`SCRIPT_FAILED`) | The script's `argparse` refused the arguments after `--`; the message is argparse's, and its usage line is in `data.output`. | Fix the arguments; `-- --help` prints the script's own usage. The session is fine. | +| `Exception: NameError: name '' is not defined` or `SyntaxError` (`SCRIPT_FAILED`) from `run code` in Windows PowerShell, on a word that was in double quotes | Windows PowerShell drops every `"` from an argument it passes to a program, so the host ran different code. | Send the code on stdin instead: run `$OutputEncoding = [System.Text.UTF8Encoding]::new()`, so a character outside ASCII doesn't arrive as `?`, then pipe a PowerShell here-string (`@'` ... `'@`) to `unity transform run code - --session --json`. Don't write a file for it. | +| ` sessions are named ''` (`AMBIGUOUS_SESSION`) | Several running sessions carry that name (started by an older CLI, which allowed it). | Pass the id of yours from `data.candidates`. | +| `~/.transform/sessions.json can't be read` (`SESSION_REGISTRY_INVALID`, exit 1) | The file listing the running sessions is damaged. No command rewrites it, so no session is lost by mistake. | Tell the user: the file has to be fixed or moved aside by hand, and the hosts it listed stopped by hand. | +| `~/.transform/sdks.json can't be read` or `~/.transform/config.json can't be read` (`CONFIG_INVALID`, exit 1) | The list of SDK names, or the settings (default SDK, license server, update check), is damaged, for example cut short. No command rewrites it, so nothing in it is lost by mistake. A file saved with a byte order mark is read. | Tell the user the file in `data.configFile` has to be fixed or moved aside by hand. Moved aside, register the SDKs again (`sdk install --path --name `) and set the default (`sdk use`). | +| `No session with id or name ''`, `Session is no longer running: …`, or `TRANSFORM_SESSION names '', which is not running` (`SESSION_NOT_FOUND`) | That session never ran here, or it stopped: the message says whether it was closed or its host exited, and names the log. | If its host exited, read `session logs --session --all` for why. If you created it, create it again and re-import the source; otherwise tell the user. Don't switch to one of `data.candidates`, because they may belong to other jobs. | +| `option '--session ' argument missing` (`INVALID_COMMAND_ARGS`) | An option's value started with `--`, often an empty variable (`--session $S --json`). A value can't start with `--` unless written with `=`. | Pass the value; one that starts with `--` goes as `--name=--value`. | +| `'session close --all' asks before it changes anything, and can't ask here` (`INVALID_COMMAND_ARGS`) | It confirms only on a terminal, never under `--json`, without a terminal, or with `UNITY_NON_INTERACTIVE`. | It closes other jobs' sessions too. Close only the sessions you opened, by `--session `; use `--all --dry-run` to list them, and `--all --yes` only when the user asks for every session closed. | +| `Using session .` on stderr | The command used the active session because none was named. | Pass `--session ` to choose; `session use ` changes the default. | +| `session list` shows `busy` with no command | The host is alive but didn't answer `info` within 1.5 s: a long SDK call, or a window being opened. Treat it as busy, not dead. | Run `session list` again; if it stays that way, read `unity transform session logs --session --follow`. | +| `session list` shows `busy: