nodecanvas-cli 0.1.0__tar.gz → 0.2.0__tar.gz
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.
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/.claude-plugin/plugin.json +1 -1
- nodecanvas_cli-0.2.0/.gitattributes +3 -0
- nodecanvas_cli-0.2.0/CHANGELOG.md +55 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/PKG-INFO +15 -5
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/README.md +14 -4
- nodecanvas_cli-0.2.0/bin/nodecanvas-cli +43 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/pyproject.toml +4 -1
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/skills/nodecanvas-cli/SKILL.md +12 -7
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/skills/nodecanvas-cli/references/ops.md +3 -0
- nodecanvas_cli-0.2.0/skills/nodecanvas-cli/scripts/nodecanvas-cli +43 -0
- nodecanvas_cli-0.2.0/src/nodecanvas_cli/__init__.py +1 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/assets.py +105 -18
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/cli.py +11 -5
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/config.py +5 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/csharp.py +51 -3
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/fsjson.py +2 -1
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/lint.py +29 -1
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/mcp_server.py +28 -5
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/ops.py +98 -15
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/refactor.py +2 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/scaffold.py +4 -3
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/typenames.py +66 -2
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/workspace.py +9 -3
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/yamlscalar.py +3 -1
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_apply.py +73 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_assets.py +55 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_codec.py +16 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_csharp.py +15 -0
- nodecanvas_cli-0.2.0/tests/test_errors.py +42 -0
- nodecanvas_cli-0.2.0/tests/test_launcher.py +102 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_lint.py +13 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_mcp.py +18 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_scaffold.py +10 -0
- nodecanvas_cli-0.2.0/tests/test_typenames.py +16 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/uv.lock +1 -1
- nodecanvas_cli-0.1.0/CHANGELOG.md +0 -20
- nodecanvas_cli-0.1.0/skills/nodecanvas-cli/scripts/nodecanvas-cli +0 -15
- nodecanvas_cli-0.1.0/src/nodecanvas_cli/__init__.py +0 -1
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/.claude-plugin/marketplace.json +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/.github/workflows/ci.yml +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/.github/workflows/release.yml +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/.gitignore +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/LICENSE +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/scripts/roundtrip_check.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/__main__.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/bindings.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/build.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/builtin.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/container.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/dialogue.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/discover.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/explain.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/layout.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/model.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/notation.txt +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/owners.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/project.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/refs.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/render.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/schema.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/spec.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/unity_verify.cs.txt +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/verify.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/src/nodecanvas_cli/views.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/conftest.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/generate.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Blackboards/Shared.asset +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Blackboards/Shared.asset.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Game/Bot.cs +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Game/Bot.cs.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Game/GuardOwner.cs +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Game/GuardOwner.cs.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Graphs/Bot_BT.asset +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Graphs/Bot_BT.asset.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Graphs/Bot_FSM.asset +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Graphs/Bot_FSM.asset.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Graphs/Broken_BT.asset +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Graphs/Broken_BT.asset.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Graphs/Patrol_BT.asset +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Graphs/Patrol_BT.asset.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Graphs/Sub_BT.asset +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Graphs/Sub_BT.asset.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Graphs/Talk_DT.asset +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Graphs/Talk_DT.asset.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Prefabs/Guard.prefab +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Prefabs/Guard.prefab.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Prefabs/Sentry.prefab +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Prefabs/Sentry.prefab.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Scenes/World.unity +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Scenes/World.unity.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Stubs/NodeCanvasStubs.cs +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/Assets/Stubs/NodeCanvasStubs.cs.meta +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/fixtures/project/ProjectSettings/ProjectVersion.txt +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/snapshots/Bot_BT.txt +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/snapshots/Bot_FSM.txt +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/snapshots/Broken_BT.txt +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/snapshots/Patrol_BT.txt +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/snapshots/Sentry.txt +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/snapshots/Sub_BT.txt +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/snapshots/Talk_DT.txt +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_dialogue.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_explain.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_owners.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_read.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_refactor.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_spec.py +0 -0
- {nodecanvas_cli-0.1.0 → nodecanvas_cli-0.2.0}/tests/test_verify.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodecanvas-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Read, search, lint and edit NodeCanvas graphs (Behaviour Trees, FSMs, Dialogue Trees) in Unity projects through the nodecanvas-cli command, without opening Unity.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aleksandr Esipov"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 — 2026-10-16
|
|
4
|
+
|
|
5
|
+
- Claude Code plugin: `bin/nodecanvas-cli` puts the command on the agent's PATH (Claude Code 2.1.91+),
|
|
6
|
+
so plugin users no longer call the launcher by its full path.
|
|
7
|
+
- Launcher: works through symlinks, skips interpreters older than Python 3.9 (`NODECANVAS_PYTHON` overrides),
|
|
8
|
+
and keeps LF line endings on Windows checkouts (`.gitattributes`).
|
|
9
|
+
- `apply`: `var-set` without `value` (e.g. only `public`) keeps the current value instead of failing with
|
|
10
|
+
a TypeError.
|
|
11
|
+
- `apply`: the before/after diff gets a `vars:` section with added, removed, renamed, retyped and revalued
|
|
12
|
+
blackboard variables and public/private changes.
|
|
13
|
+
- `new --from --private-vars` and `copy --public-vars` take optional, repeatable name globs
|
|
14
|
+
(`--private-vars "Under attack *"`) to set visibility per variable; a glob that matches nothing is reported.
|
|
15
|
+
The MCP `new_graph` and `copy` tools get `private_vars` / `public_vars`.
|
|
16
|
+
- `new`, `extract`: with `--project` (and in the MCP server), a relative path started outside the project is taken
|
|
17
|
+
from the project root instead of failing with "must be inside the Unity project".
|
|
18
|
+
- `lint`: `name-mismatch` warning when a graph asset's `m_Name` differs from its file name, which Unity
|
|
19
|
+
otherwise reports only on import.
|
|
20
|
+
- MCP server: concurrent tool calls no longer mix up or lose each other's output.
|
|
21
|
+
- Saving several graphs of one scene/prefab (`refactor`, `dt import`, `dt export --assign-uids`) no longer
|
|
22
|
+
fails half-way after the first graph changed the file's line count.
|
|
23
|
+
- `copy`, `extract`, `inline`, `new --from`: object references inside nodes and tasks (a statement's audio,
|
|
24
|
+
`GameObject`/`Material`/… fields and parameters) are remapped to the destination's `_objectReferences`.
|
|
25
|
+
- Long dialogue texts with double spaces keep them: lines are no longer folded after a space.
|
|
26
|
+
- Graphs with `Infinity`/`NaN` float values can be edited.
|
|
27
|
+
- Non-ASCII `[Name]`, `[Category]`, `[Description]` strings in C# sources are read correctly.
|
|
28
|
+
- `apply`: a `MultipleChoiceNode`'s choices follow their connections on `disconnect`, `remove`, `move` and
|
|
29
|
+
`connect`; `choice-add` without `to` adds an unlinked choice; new `choice-remove` op.
|
|
30
|
+
- Bad input (invalid `nodecanvas-cli.json`, a missing ops file, a graph name equal to a folder, `refactor
|
|
31
|
+
retarget` without `Type.Method`) ends in `error:` instead of a traceback; `diff --rev` refuses option-like
|
|
32
|
+
revisions.
|
|
33
|
+
- `scaffold --dir` with `--project` resolves a relative folder from the project root.
|
|
34
|
+
- Enum initializers in C# sources are evaluated without `eval` and with bounded values.
|
|
35
|
+
- New `$type`s name the right Unity module for audio, physics, 2D physics, animation, particle, UI, text,
|
|
36
|
+
terrain and video types (not always `UnityEngine.CoreModule`), so Unity does not rewrite them on save.
|
|
37
|
+
|
|
38
|
+
## 0.1.0 — 2026-10-12
|
|
39
|
+
|
|
40
|
+
First public release.
|
|
41
|
+
|
|
42
|
+
- `list`, `show`, `vars`, `node`, `diff`: compact views of Behaviour Trees, FSMs and Dialogue Trees in graph
|
|
43
|
+
assets and in graphs bound to GraphOwners in prefabs and scenes.
|
|
44
|
+
- `refs`, `why`, `paths`, `stats`: reverse lookup of members, subtrees, variables and task types across all
|
|
45
|
+
graphs; conditions on the way to a node; every call of a member or write of a variable.
|
|
46
|
+
- `lint`: missing types, dangling blackboard references, broken reflection bindings, subgraph mappings,
|
|
47
|
+
connection limits, unreachable nodes, owner and global variables.
|
|
48
|
+
- `apply`: atomic, validated batches of edit operations with short value forms and `--dry-run` diffs;
|
|
49
|
+
`new`, `extract`, `inline`, `copy`, `refactor rename-member|rename-type|retarget`, `scaffold`.
|
|
50
|
+
- `dt export` / `dt import` / `dt lint`: dialogue lines and translations to CSV/JSON and back.
|
|
51
|
+
- `owners`, `blackboards`, `types`, `members`.
|
|
52
|
+
- `verify --unity`: load the edited graphs in the open Unity Editor and report what NodeCanvas sees.
|
|
53
|
+
- `mcp`: stdio MCP server (`nodecanvas-cli[mcp]`, Python 3.10+).
|
|
54
|
+
- Claude Code plugin with a skill and a bundled launcher.
|
|
55
|
+
- Byte-exact round-trip of unchanged graphs; Unity's YAML folding and FullSerializer key order on save.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: nodecanvas-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Read, query, lint and edit NodeCanvas graphs (Behaviour Trees, FSMs, Dialogue Trees) in Unity projects from the command line
|
|
5
5
|
Project-URL: Homepage, https://github.com/Primeer/nodecanvas-cli
|
|
6
6
|
Project-URL: Issues, https://github.com/Primeer/nodecanvas-cli/issues
|
|
@@ -36,6 +36,8 @@ FSMs and Dialogue Trees — in a Unity project from the command line, without op
|
|
|
36
36
|
|
|
37
37
|
Built for coding agents (it ships as a Claude Code plugin) and just as usable by hand.
|
|
38
38
|
|
|
39
|
+

|
|
40
|
+
|
|
39
41
|
NodeCanvas stores a graph as one long JSON string inside a Unity YAML asset. A 120-node behaviour tree
|
|
40
42
|
is ~85 KB of folded JSON with GUID-linked variables and index-linked nodes. `nodecanvas-cli` shows the same tree
|
|
41
43
|
in ~10 KB of readable text, answers "where is this used?", and applies edits as validated batches that
|
|
@@ -66,7 +68,7 @@ vars: Self:Bot(pub) Target:Unit Alert:bool Cool time:float Speed:float
|
|
|
66
68
|
this finds them.
|
|
67
69
|
- **lint** — missing task/variable types, dangling blackboard references, reflection bindings to members
|
|
68
70
|
that no longer exist, missing subgraphs and stale variable mappings, too many children for a node
|
|
69
|
-
type, unreachable nodes.
|
|
71
|
+
type, unreachable nodes, graph assets whose `m_Name` differs from the file name.
|
|
70
72
|
- **apply** — atomic batches of edit operations: add / remove / move / wrap / unwrap / replace nodes, set
|
|
71
73
|
fields, connect and disable, blackboard variables, subgraph mappings, FSM transitions, dialogue
|
|
72
74
|
choices. Short value forms (`"$Var"`, enum names, `[x, y, z]`, `{"call": "Type.Method", ...}`) are
|
|
@@ -99,9 +101,6 @@ uvx --from git+https://github.com/Primeer/nodecanvas-cli nodecanvas-cli --help
|
|
|
99
101
|
python -m nodecanvas_cli --help # from a checkout, with src/ on PYTHONPATH
|
|
100
102
|
```
|
|
101
103
|
|
|
102
|
-
The Claude Code plugin also bundles a launcher, `skills/nodecanvas-cli/scripts/nodecanvas-cli`, which runs the CLI
|
|
103
|
-
from the plugin's own sources with any Python 3.9+.
|
|
104
|
-
|
|
105
104
|
### Claude Code plugin
|
|
106
105
|
|
|
107
106
|
The repository is also a Claude Code plugin marketplace containing the `nodecanvas-cli` plugin, which adds a
|
|
@@ -112,6 +111,17 @@ skill that teaches the agent when and how to use the CLI:
|
|
|
112
111
|
/plugin install nodecanvas-cli@nodecanvas-cli
|
|
113
112
|
```
|
|
114
113
|
|
|
114
|
+
The plugin also puts `nodecanvas-cli` on the agent's PATH (Claude Code 2.1.91+), so no separate install is needed:
|
|
115
|
+
its `bin/` launcher runs the CLI from the plugin's own sources with any Python 3.9+, always in step with the skill.
|
|
116
|
+
The launcher is a POSIX `sh` script — it works on macOS, Linux, WSL and in Git Bash on Windows; it can also be
|
|
117
|
+
symlinked into a directory on your PATH. Set `NODECANVAS_PYTHON` to pick the interpreter. Older Claude Code
|
|
118
|
+
versions and agents that load the skill on its own can call `skills/nodecanvas-cli/scripts/nodecanvas-cli`.
|
|
119
|
+
|
|
120
|
+
Install the CLI with pipx as well when you want it in your own terminal or as an MCP server, or when the launcher
|
|
121
|
+
does not fit (native Windows shells without `sh`): pipx creates a regular `nodecanvas-cli` executable, `.exe` on
|
|
122
|
+
Windows, and the agent uses it the same way — whichever comes first on PATH wins. Update it with
|
|
123
|
+
`pipx upgrade nodecanvas-cli` together with the plugin, so the skill and the CLI stay on the same version.
|
|
124
|
+
|
|
115
125
|
### MCP server (Cursor, Codex, Gemini and other agents)
|
|
116
126
|
|
|
117
127
|
```bash
|
|
@@ -5,6 +5,8 @@ FSMs and Dialogue Trees — in a Unity project from the command line, without op
|
|
|
5
5
|
|
|
6
6
|
Built for coding agents (it ships as a Claude Code plugin) and just as usable by hand.
|
|
7
7
|
|
|
8
|
+

|
|
9
|
+
|
|
8
10
|
NodeCanvas stores a graph as one long JSON string inside a Unity YAML asset. A 120-node behaviour tree
|
|
9
11
|
is ~85 KB of folded JSON with GUID-linked variables and index-linked nodes. `nodecanvas-cli` shows the same tree
|
|
10
12
|
in ~10 KB of readable text, answers "where is this used?", and applies edits as validated batches that
|
|
@@ -35,7 +37,7 @@ vars: Self:Bot(pub) Target:Unit Alert:bool Cool time:float Speed:float
|
|
|
35
37
|
this finds them.
|
|
36
38
|
- **lint** — missing task/variable types, dangling blackboard references, reflection bindings to members
|
|
37
39
|
that no longer exist, missing subgraphs and stale variable mappings, too many children for a node
|
|
38
|
-
type, unreachable nodes.
|
|
40
|
+
type, unreachable nodes, graph assets whose `m_Name` differs from the file name.
|
|
39
41
|
- **apply** — atomic batches of edit operations: add / remove / move / wrap / unwrap / replace nodes, set
|
|
40
42
|
fields, connect and disable, blackboard variables, subgraph mappings, FSM transitions, dialogue
|
|
41
43
|
choices. Short value forms (`"$Var"`, enum names, `[x, y, z]`, `{"call": "Type.Method", ...}`) are
|
|
@@ -68,9 +70,6 @@ uvx --from git+https://github.com/Primeer/nodecanvas-cli nodecanvas-cli --help
|
|
|
68
70
|
python -m nodecanvas_cli --help # from a checkout, with src/ on PYTHONPATH
|
|
69
71
|
```
|
|
70
72
|
|
|
71
|
-
The Claude Code plugin also bundles a launcher, `skills/nodecanvas-cli/scripts/nodecanvas-cli`, which runs the CLI
|
|
72
|
-
from the plugin's own sources with any Python 3.9+.
|
|
73
|
-
|
|
74
73
|
### Claude Code plugin
|
|
75
74
|
|
|
76
75
|
The repository is also a Claude Code plugin marketplace containing the `nodecanvas-cli` plugin, which adds a
|
|
@@ -81,6 +80,17 @@ skill that teaches the agent when and how to use the CLI:
|
|
|
81
80
|
/plugin install nodecanvas-cli@nodecanvas-cli
|
|
82
81
|
```
|
|
83
82
|
|
|
83
|
+
The plugin also puts `nodecanvas-cli` on the agent's PATH (Claude Code 2.1.91+), so no separate install is needed:
|
|
84
|
+
its `bin/` launcher runs the CLI from the plugin's own sources with any Python 3.9+, always in step with the skill.
|
|
85
|
+
The launcher is a POSIX `sh` script — it works on macOS, Linux, WSL and in Git Bash on Windows; it can also be
|
|
86
|
+
symlinked into a directory on your PATH. Set `NODECANVAS_PYTHON` to pick the interpreter. Older Claude Code
|
|
87
|
+
versions and agents that load the skill on its own can call `skills/nodecanvas-cli/scripts/nodecanvas-cli`.
|
|
88
|
+
|
|
89
|
+
Install the CLI with pipx as well when you want it in your own terminal or as an MCP server, or when the launcher
|
|
90
|
+
does not fit (native Windows shells without `sh`): pipx creates a regular `nodecanvas-cli` executable, `.exe` on
|
|
91
|
+
Windows, and the agent uses it the same way — whichever comes first on PATH wins. Update it with
|
|
92
|
+
`pipx upgrade nodecanvas-cli` together with the plugin, so the skill and the CLI stay on the same version.
|
|
93
|
+
|
|
84
94
|
### MCP server (Cursor, Codex, Gemini and other agents)
|
|
85
95
|
|
|
86
96
|
```bash
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Runs the nodecanvas-cli command bundled with this plugin (no installation needed; Python 3.9+).
|
|
3
|
+
# The same file lives in bin/ and skills/nodecanvas-cli/scripts/; tests keep them identical.
|
|
4
|
+
self=$0
|
|
5
|
+
while [ -L "$self" ]; do
|
|
6
|
+
link=$(readlink -- "$self")
|
|
7
|
+
case $link in
|
|
8
|
+
/*) self=$link ;;
|
|
9
|
+
*) self=$(dirname -- "$self")/$link ;;
|
|
10
|
+
esac
|
|
11
|
+
done
|
|
12
|
+
here=$(CDPATH= cd -- "$(dirname -- "$self")" && pwd -P)
|
|
13
|
+
for src in "$here/../src" "$here/../../../src"; do
|
|
14
|
+
[ -d "$src/nodecanvas_cli" ] && break
|
|
15
|
+
done
|
|
16
|
+
if [ ! -d "$src/nodecanvas_cli" ]; then
|
|
17
|
+
echo "nodecanvas-cli: bundled sources not found next to $here; install with 'pipx install nodecanvas-cli'" >&2
|
|
18
|
+
exit 2
|
|
19
|
+
fi
|
|
20
|
+
usable() {
|
|
21
|
+
command -v "$1" >/dev/null 2>&1 &&
|
|
22
|
+
"$1" -c 'import sys; sys.exit(sys.version_info < (3, 9))' >/dev/null 2>&1
|
|
23
|
+
}
|
|
24
|
+
if [ -n "${NODECANVAS_PYTHON:-}" ]; then
|
|
25
|
+
py=$NODECANVAS_PYTHON
|
|
26
|
+
if ! usable "$py"; then
|
|
27
|
+
echo "nodecanvas-cli: NODECANVAS_PYTHON=$py is not a Python 3.9+ interpreter" >&2
|
|
28
|
+
exit 2
|
|
29
|
+
fi
|
|
30
|
+
else
|
|
31
|
+
py=
|
|
32
|
+
for candidate in python3 python3.14 python3.13 python3.12 python3.11 python3.10 python3.9 py python; do
|
|
33
|
+
if usable "$candidate"; then
|
|
34
|
+
py=$candidate
|
|
35
|
+
break
|
|
36
|
+
fi
|
|
37
|
+
done
|
|
38
|
+
if [ -z "$py" ]; then
|
|
39
|
+
echo "nodecanvas-cli: Python 3.9+ is required (set NODECANVAS_PYTHON to its path)" >&2
|
|
40
|
+
exit 2
|
|
41
|
+
fi
|
|
42
|
+
fi
|
|
43
|
+
PYTHONPATH="$src${PYTHONPATH:+:$PYTHONPATH}" exec "$py" -m nodecanvas_cli "$@"
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "nodecanvas-cli"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2.0"
|
|
8
8
|
description = "Read, query, lint and edit NodeCanvas graphs (Behaviour Trees, FSMs, Dialogue Trees) in Unity projects from the command line"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -39,6 +39,9 @@ nodecanvas-cli = "nodecanvas_cli.cli:main"
|
|
|
39
39
|
mcp = ["mcp>=2.3; python_version >= '3.10'"]
|
|
40
40
|
dev = ["pytest>=7", "mcp>=2.3; python_version >= '3.10'"]
|
|
41
41
|
|
|
42
|
+
[tool.hatch.build.targets.sdist]
|
|
43
|
+
exclude = ["docs"]
|
|
44
|
+
|
|
42
45
|
[tool.hatch.build.targets.wheel]
|
|
43
46
|
packages = ["src/nodecanvas_cli"]
|
|
44
47
|
|
|
@@ -15,9 +15,11 @@ format Unity produces.
|
|
|
15
15
|
|
|
16
16
|
Run commands from anywhere inside the Unity project (or pass `--project <root>`). Use the first that works:
|
|
17
17
|
|
|
18
|
-
1. `nodecanvas-cli <command> ...` —
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
1. `nodecanvas-cli <command> ...` — on PATH when the skill comes with the Claude Code plugin (2.1.91+), or after
|
|
19
|
+
`pipx install nodecanvas-cli`.
|
|
20
|
+
2. `<this skill's base directory>/scripts/nodecanvas-cli <command> ...` — the same bundled CLI by path;
|
|
21
|
+
needs only Python 3.9+ (`NODECANVAS_PYTHON` picks the interpreter). The base directory is shown when this
|
|
22
|
+
skill loads.
|
|
21
23
|
3. `uvx nodecanvas-cli <command> ...` — once the package is on PyPI.
|
|
22
24
|
|
|
23
25
|
Below, `nodecanvas-cli` stands for whichever of these works.
|
|
@@ -120,14 +122,15 @@ arity, so overload changes are visible in `show` and `diff`.
|
|
|
120
122
|
- `nodecanvas-cli new Assets/.../X_BehaviourTree.asset --kind bt|fsm|dt [--var "Name:type[=value][:pub]"]
|
|
121
123
|
[--from <graph>:<node>]` creates a graph with its `.meta` (new GUID), optionally starting with a copy
|
|
122
124
|
of a subtree; with `--from` the copied variables are public, like `extract` makes them, so the graph
|
|
123
|
-
is ready to be used as a SubTree
|
|
125
|
+
is ready to be used as a SubTree. `--private-vars` keeps them all private; `--private-vars "Under attack *"`
|
|
126
|
+
(a name glob, repeatable) keeps only the matching ones private, e.g. the graph's local state. `--allow-outside` permits a path outside `Assets/`/`Packages/` for experiments.
|
|
124
127
|
- `nodecanvas-cli extract <graph> <node> Assets/.../Part_BehaviourTree.asset [--name N]` moves a BT subtree into
|
|
125
128
|
a new SubTree asset and puts a SubTree node in its place. Variables the subtree uses become public
|
|
126
129
|
variables of the new graph and are mapped automatically (`←` read, `→` written, `↔` both).
|
|
127
130
|
- `nodecanvas-cli inline <graph> <subtree-node>` is the reverse.
|
|
128
131
|
- `nodecanvas-cli copy <src> <node> <dst|.> <parent|root> [--index i] [--create-vars]` copies a subtree
|
|
129
132
|
(`root` makes it the root of an empty graph); variables are matched by name and type in the
|
|
130
|
-
destination. Variables created by `--create-vars` are private unless `--public-vars` is given, and keep their ids from the source graph (a new id only
|
|
133
|
+
destination. Variables created by `--create-vars` are private unless `--public-vars` is given (all of them, or `--public-vars "<glob>"` for the matching ones), and keep their ids from the source graph (a new id only
|
|
131
134
|
on collision), so mappings that pointed at them keep working.
|
|
132
135
|
|
|
133
136
|
## Dialogue texts
|
|
@@ -159,7 +162,8 @@ drops the TODO comments (for projects that do not want comments).
|
|
|
159
162
|
the blackboard, reflection bindings to members that no longer exist, unassigned or missing subgraphs,
|
|
160
163
|
stale subgraph variable mappings, arguments whose stored or variable type does not fit the bound
|
|
161
164
|
overload (`arg-type-mismatch`, with a `fix:` op when another overload fits), subgraph mappings between
|
|
162
|
-
variables of different types, too many children for a node type,
|
|
165
|
+
variables of different types, too many children for a node type, unreachable nodes, and graph assets whose
|
|
166
|
+
`m_Name` differs from the file name (`name-mismatch`, warning — e.g. after renaming the file outside Unity). It exits with 1 when there are errors. Run it
|
|
163
167
|
after C# refactors that touch types used by graphs.
|
|
164
168
|
|
|
165
169
|
Owners and blackboards: `missing-global-var` (warning) — `$Name/Var` has no GlobalBlackboard
|
|
@@ -204,7 +208,8 @@ wrappers); it changes files, so use it only when asked.
|
|
|
204
208
|
enum values) or `nodecanvas-cli types --role action|condition|bt|composite|decorator|fsm|dt`.
|
|
205
209
|
For reflection tasks: `nodecanvas-cli members <Type> [filter]` lists callable properties/methods.
|
|
206
210
|
3. Write a JSON array of operations and run `nodecanvas-cli apply <graph> ops.json --dry-run` (or `-` for stdin).
|
|
207
|
-
Read the printed before/after diff
|
|
211
|
+
Read the printed before/after diff (blackboard changes follow it as `vars:` lines: `+`/`-` added or removed,
|
|
212
|
+
`~` renamed, retyped, new value, public/private) and the `layout:` summary under it — it says how many nodes were
|
|
208
213
|
placed, moved by the edit, and which existing subtrees were shifted (and by how much) to make room.
|
|
209
214
|
Add `--positions` to see coordinates in the diff. Then run again without `--dry-run`.
|
|
210
215
|
4. `nodecanvas-cli show <graph>` again to get the new ids before the next batch.
|
|
@@ -132,6 +132,9 @@ Use `set` with `"from"`/`"to"` and `"path": "_condition"` to change a transition
|
|
|
132
132
|
| Op | Fields | Notes |
|
|
133
133
|
|---|---|---|
|
|
134
134
|
| `choice-add` | `node`, `text`, `to`?, `condition`?, `meta`?, `index`? | Adds a choice to a `MultipleChoiceNode` and, with `to`, connects it. |
|
|
135
|
+
| `choice-remove` | `node`, `choice` | Removes choice number `choice` (1-based, as `show` numbers them) and its connection. |
|
|
136
|
+
|
|
137
|
+
Choices are matched to connections by position. A choice without a connection stays after the linked ones: `choice-add` without `to` appends one, `disconnect`/`remove` of a choice's target keeps its text as an unlinked choice, and the next `connect` from the node takes the first unlinked choice.
|
|
135
138
|
|
|
136
139
|
Statements: `{"$type": "StatementNode", "_actorName": "Guard", "statement": {"_text": "Hi"}}`.
|
|
137
140
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Runs the nodecanvas-cli command bundled with this plugin (no installation needed; Python 3.9+).
|
|
3
|
+
# The same file lives in bin/ and skills/nodecanvas-cli/scripts/; tests keep them identical.
|
|
4
|
+
self=$0
|
|
5
|
+
while [ -L "$self" ]; do
|
|
6
|
+
link=$(readlink -- "$self")
|
|
7
|
+
case $link in
|
|
8
|
+
/*) self=$link ;;
|
|
9
|
+
*) self=$(dirname -- "$self")/$link ;;
|
|
10
|
+
esac
|
|
11
|
+
done
|
|
12
|
+
here=$(CDPATH= cd -- "$(dirname -- "$self")" && pwd -P)
|
|
13
|
+
for src in "$here/../src" "$here/../../../src"; do
|
|
14
|
+
[ -d "$src/nodecanvas_cli" ] && break
|
|
15
|
+
done
|
|
16
|
+
if [ ! -d "$src/nodecanvas_cli" ]; then
|
|
17
|
+
echo "nodecanvas-cli: bundled sources not found next to $here; install with 'pipx install nodecanvas-cli'" >&2
|
|
18
|
+
exit 2
|
|
19
|
+
fi
|
|
20
|
+
usable() {
|
|
21
|
+
command -v "$1" >/dev/null 2>&1 &&
|
|
22
|
+
"$1" -c 'import sys; sys.exit(sys.version_info < (3, 9))' >/dev/null 2>&1
|
|
23
|
+
}
|
|
24
|
+
if [ -n "${NODECANVAS_PYTHON:-}" ]; then
|
|
25
|
+
py=$NODECANVAS_PYTHON
|
|
26
|
+
if ! usable "$py"; then
|
|
27
|
+
echo "nodecanvas-cli: NODECANVAS_PYTHON=$py is not a Python 3.9+ interpreter" >&2
|
|
28
|
+
exit 2
|
|
29
|
+
fi
|
|
30
|
+
else
|
|
31
|
+
py=
|
|
32
|
+
for candidate in python3 python3.14 python3.13 python3.12 python3.11 python3.10 python3.9 py python; do
|
|
33
|
+
if usable "$candidate"; then
|
|
34
|
+
py=$candidate
|
|
35
|
+
break
|
|
36
|
+
fi
|
|
37
|
+
done
|
|
38
|
+
if [ -z "$py" ]; then
|
|
39
|
+
echo "nodecanvas-cli: Python 3.9+ is required (set NODECANVAS_PYTHON to its path)" >&2
|
|
40
|
+
exit 2
|
|
41
|
+
fi
|
|
42
|
+
fi
|
|
43
|
+
PYTHONPATH="$src${PYTHONPATH:+:$PYTHONPATH}" exec "$py" -m nodecanvas_cli "$@"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.0"
|
|
@@ -4,11 +4,12 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import copy
|
|
6
6
|
import difflib
|
|
7
|
+
import fnmatch
|
|
7
8
|
import re
|
|
8
9
|
import sys
|
|
9
10
|
import uuid
|
|
10
11
|
from pathlib import Path
|
|
11
|
-
from typing import Dict, List, Optional, Tuple
|
|
12
|
+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
12
13
|
|
|
13
14
|
from . import fsjson
|
|
14
15
|
from .container import ObjectRef, UnityFile
|
|
@@ -158,8 +159,14 @@ def _check_new_path(ws, rel: str, allow_outside: bool = False) -> None:
|
|
|
158
159
|
|
|
159
160
|
|
|
160
161
|
def _rel(ws, path: str) -> str:
|
|
162
|
+
"""Relative paths are taken from the current directory inside the project, from its root otherwise
|
|
163
|
+
(``--project``, the MCP server)."""
|
|
161
164
|
p = Path(path)
|
|
162
|
-
|
|
165
|
+
if not p.is_absolute():
|
|
166
|
+
cwd = Path.cwd().resolve()
|
|
167
|
+
root = Path(ws.project.root).resolve()
|
|
168
|
+
p = (cwd if cwd == root or root in cwd.parents else root) / p
|
|
169
|
+
return ws.project.rel(p)
|
|
163
170
|
|
|
164
171
|
|
|
165
172
|
# ---------------------------------------------------------------------- copying subtrees
|
|
@@ -215,8 +222,59 @@ def _owner_type(node: dict, path: Tuple) -> str:
|
|
|
215
222
|
return t
|
|
216
223
|
|
|
217
224
|
|
|
225
|
+
def object_ref_slots(ws, g: Graph, node: dict) -> List[Tuple[Any, Any]]:
|
|
226
|
+
"""``(container, key)`` of every int in ``node`` that indexes the graph's ``_objectReferences``:
|
|
227
|
+
fields of a UnityEngine.Object type (also inside BBParameters, lists, nested classes and tasks),
|
|
228
|
+
found by the field types in the sources."""
|
|
229
|
+
from .render import _bb_inner, _elem_type
|
|
230
|
+
|
|
231
|
+
schema, r = ws.schema, ws.renderer(g)
|
|
232
|
+
out: Dict[Tuple[int, Any], Tuple[Any, Any]] = {}
|
|
233
|
+
|
|
234
|
+
def is_object(t: Optional[str], ctx) -> bool:
|
|
235
|
+
return bool(t) and "<" not in t and not t.endswith("[]") and r._is_unity_object(t, ctx)
|
|
236
|
+
|
|
237
|
+
def visit(v: Any, t: Optional[str], ctx, holder: Any, key: Any) -> None:
|
|
238
|
+
if isinstance(v, bool) or v is None:
|
|
239
|
+
return
|
|
240
|
+
if isinstance(v, int):
|
|
241
|
+
if is_object(t, ctx):
|
|
242
|
+
out[(id(holder), key)] = (holder, key)
|
|
243
|
+
return
|
|
244
|
+
if isinstance(v, list):
|
|
245
|
+
et = _elem_type(t)
|
|
246
|
+
for i, x in enumerate(v):
|
|
247
|
+
visit(x, et, ctx, v, i)
|
|
248
|
+
return
|
|
249
|
+
if not isinstance(v, dict):
|
|
250
|
+
return
|
|
251
|
+
if "$content" in v:
|
|
252
|
+
visit(v["$content"], v.get("$type") or t, ctx, v, "$content")
|
|
253
|
+
return
|
|
254
|
+
if "_value" in v and (_bb_inner(t) or "_type" in v or (t or "").startswith("BBObjectParameter")):
|
|
255
|
+
if not (v.get("_name") or v.get("_targetVariableID")):
|
|
256
|
+
inner = v.get("_type") or _bb_inner(t)
|
|
257
|
+
visit(v["_value"], inner.split(",")[0] if inner else None, ctx, v, "_value")
|
|
258
|
+
return
|
|
259
|
+
dt = v.get("$type") or t
|
|
260
|
+
decl = schema.find(dt) if dt else None
|
|
261
|
+
if decl is None and dt:
|
|
262
|
+
decl = schema.find_simple(simple_name(dt).split("<")[0], ctx)
|
|
263
|
+
fields = {n: (f, c) for n, f, c in schema.ordered_fields(decl.full_name)} if decl is not None else {}
|
|
264
|
+
for k, x in v.items():
|
|
265
|
+
f = fields.get(k)
|
|
266
|
+
visit(x, f[0].type if f else None, f[1] if f else ctx, v, k)
|
|
267
|
+
|
|
268
|
+
visit(node, None, None, None, None)
|
|
269
|
+
for k in NESTED_KEYS: # subgraph references, even when the node type is not in the sources
|
|
270
|
+
v = node.get(k)
|
|
271
|
+
if isinstance(v, dict) and isinstance(v.get("_value"), int):
|
|
272
|
+
out[(id(v), "_value")] = (v, "_value")
|
|
273
|
+
return list(out.values())
|
|
274
|
+
|
|
275
|
+
|
|
218
276
|
def clone(
|
|
219
|
-
src: Graph, dst: Graph, nodes: List[dict], var_map: Dict[str, dict], keep_uid: bool = True
|
|
277
|
+
ws, src: Graph, dst: Graph, nodes: List[dict], var_map: Dict[str, dict], keep_uid: bool = True
|
|
220
278
|
) -> Tuple[List[dict], List[dict]]:
|
|
221
279
|
"""Deep-copy ``nodes`` (with their internal connections) for ``dst``: variable ids and object refs remapped.
|
|
222
280
|
|
|
@@ -234,11 +292,10 @@ def clone(
|
|
|
234
292
|
d["_targetVariableID"] = var_map[vid]["_id"]
|
|
235
293
|
if "_name" in d:
|
|
236
294
|
d["_name"] = var_map[vid]["_name"]
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
v["_value"] = dst.ref_index(ref) if ref is not None and not ref.is_null else 0
|
|
295
|
+
if src is not dst:
|
|
296
|
+
for holder, key in object_ref_slots(ws, src, c):
|
|
297
|
+
ref = src.ref(holder[key])
|
|
298
|
+
holder[key] = dst.ref_index(ref) if ref is not None and not ref.is_null else 0
|
|
242
299
|
conns = []
|
|
243
300
|
for n in nodes:
|
|
244
301
|
for c in src.out.get(src.nid(n), []):
|
|
@@ -346,9 +403,11 @@ def cmd_new(ws, a) -> int:
|
|
|
346
403
|
raise AssetError("--from takes <graph>:<node>")
|
|
347
404
|
src_name, node_ref = a.source.rsplit(":", 1)
|
|
348
405
|
src = ws.graph(src_name)
|
|
349
|
-
|
|
406
|
+
private = var_matcher(a.private_vars)
|
|
407
|
+
_, created = copy_subtree(ws, src, node_ref, g, "root", None, True, public_vars=lambda n: not private(n))
|
|
350
408
|
if created:
|
|
351
409
|
print("created variables: " + ", ".join("$" + n for n in created))
|
|
410
|
+
_warn_unmatched("--private-vars", a.private_vars, created)
|
|
352
411
|
_print_views(ws, {}, [g])
|
|
353
412
|
return _finish(ws, a, [(f, g, uuid.uuid4().hex)], [])
|
|
354
413
|
|
|
@@ -375,7 +434,7 @@ def cmd_extract(ws, a) -> int:
|
|
|
375
434
|
nv["$type"] = v["$type"]
|
|
376
435
|
sub.blackboard["_variables"][name] = nv
|
|
377
436
|
var_map[v["_id"]] = nv
|
|
378
|
-
copies, conns = clone(g, sub, nodes, var_map)
|
|
437
|
+
copies, conns = clone(ws, g, sub, nodes, var_map)
|
|
379
438
|
sub.data["nodes"] = copies
|
|
380
439
|
sub.data["connections"] = conns
|
|
381
440
|
sub.reindex()
|
|
@@ -450,7 +509,7 @@ def cmd_inline(ws, a) -> int:
|
|
|
450
509
|
var_map[v["_id"]] = nv
|
|
451
510
|
created_vars.append(new_name)
|
|
452
511
|
nodes = subtree_nodes(sub, sub.prime)
|
|
453
|
-
copies, conns = clone(sub, g, nodes, var_map)
|
|
512
|
+
copies, conns = clone(ws, sub, g, nodes, var_map)
|
|
454
513
|
ed = Editor(ws, g)
|
|
455
514
|
parent = (g.parents(node) or [None])[0]
|
|
456
515
|
old_pos = ed.lay.pos(node)
|
|
@@ -489,10 +548,11 @@ def copy_subtree(
|
|
|
489
548
|
parent_ref: str,
|
|
490
549
|
index: Optional[int],
|
|
491
550
|
create_vars: bool,
|
|
492
|
-
public_vars: bool = False,
|
|
551
|
+
public_vars: Union[bool, Callable[[str], bool]] = False,
|
|
493
552
|
):
|
|
494
553
|
"""Copy ``src``'s subtree at ``node_ref`` under ``parent_ref`` in ``dst`` (``root``: as the root of an
|
|
495
|
-
empty graph).
|
|
554
|
+
empty graph). ``public_vars`` says which created variables are public: all, none, or by name.
|
|
555
|
+
Returns ``(editor, created variable names)``."""
|
|
496
556
|
from .ops import Editor, OpError
|
|
497
557
|
|
|
498
558
|
root = src.node(node_ref)
|
|
@@ -522,14 +582,14 @@ def copy_subtree(
|
|
|
522
582
|
for v in missing:
|
|
523
583
|
nv = copy.deepcopy(v)
|
|
524
584
|
nv.pop("_isPublic", None)
|
|
525
|
-
if public_vars:
|
|
585
|
+
if public_vars(v["_name"]) if callable(public_vars) else public_vars:
|
|
526
586
|
nv["_isPublic"] = True
|
|
527
587
|
nv["$type"] = nv.pop("$type")
|
|
528
588
|
if dst.var_by_id(nv["_id"]) is not None:
|
|
529
589
|
nv["_id"] = str(uuid.uuid4())
|
|
530
590
|
dst.blackboard["_variables"][nv["_name"]] = nv
|
|
531
591
|
var_map[v["_id"]] = nv
|
|
532
|
-
copies, conns = clone(src, dst, nodes, var_map, keep_uid=False)
|
|
592
|
+
copies, conns = clone(ws, src, dst, nodes, var_map, keep_uid=False)
|
|
533
593
|
ed = Editor(ws, dst)
|
|
534
594
|
was_empty = not dst.nodes
|
|
535
595
|
parent = None if as_root else (dst.node(parent_ref) if dst is not src else ed.node(parent_ref))
|
|
@@ -551,11 +611,24 @@ def copy_subtree(
|
|
|
551
611
|
return ed, [v["_name"] for v in missing]
|
|
552
612
|
|
|
553
613
|
|
|
614
|
+
def var_matcher(patterns: Optional[List[str]]) -> Callable[[str], bool]:
|
|
615
|
+
"""Name predicate for --private-vars/--public-vars: absent matches nothing, a bare flag ("*") everything."""
|
|
616
|
+
pats = patterns or []
|
|
617
|
+
return lambda name: any(fnmatch.fnmatchcase(name, p) for p in pats)
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
def _warn_unmatched(flag: str, patterns: Optional[List[str]], created: List[str]) -> None:
|
|
621
|
+
for p in patterns or []:
|
|
622
|
+
if not any(fnmatch.fnmatchcase(n, p) for n in created):
|
|
623
|
+
print(f"warning: {flag} {p!r} matches no created variable", file=sys.stderr)
|
|
624
|
+
|
|
625
|
+
|
|
554
626
|
def cmd_copy(ws, a) -> int:
|
|
555
627
|
src = ws.graph(a.src)
|
|
556
628
|
dst = src if a.dst in (a.src, ".") else ws.graph(a.dst)
|
|
557
629
|
before = {dst.loaded.slot.address: _view(ws, dst)}
|
|
558
|
-
ed, created = copy_subtree(ws, src, a.node, dst, a.parent, a.index, a.create_vars, a.public_vars)
|
|
630
|
+
ed, created = copy_subtree(ws, src, a.node, dst, a.parent, a.index, a.create_vars, var_matcher(a.public_vars))
|
|
631
|
+
_warn_unmatched("--public-vars", a.public_vars, created)
|
|
559
632
|
_print_views(ws, before, [dst])
|
|
560
633
|
summary = ed.layout_summary()
|
|
561
634
|
if summary:
|
|
@@ -587,7 +660,14 @@ def register(sub) -> None:
|
|
|
587
660
|
help="start with a copy of <graph>:<node>; its variables are created public, "
|
|
588
661
|
"like extract does, so the graph is ready to be a SubTree",
|
|
589
662
|
)
|
|
590
|
-
s.add_argument(
|
|
663
|
+
s.add_argument(
|
|
664
|
+
"--private-vars",
|
|
665
|
+
action="append",
|
|
666
|
+
nargs="?",
|
|
667
|
+
const="*",
|
|
668
|
+
metavar="PATTERN",
|
|
669
|
+
help="with --from: create the variables private; with a name glob (repeatable), only the matching ones",
|
|
670
|
+
)
|
|
591
671
|
s.add_argument("--dry-run", action="store_true")
|
|
592
672
|
s.add_argument("--force", action="store_true")
|
|
593
673
|
s.add_argument(
|
|
@@ -621,7 +701,14 @@ def register(sub) -> None:
|
|
|
621
701
|
s.add_argument("parent", help="node in the destination to attach the copy to, or 'root' for an empty graph")
|
|
622
702
|
s.add_argument("--index", type=int)
|
|
623
703
|
s.add_argument("--create-vars", action="store_true", help="create missing variables in the destination")
|
|
624
|
-
s.add_argument(
|
|
704
|
+
s.add_argument(
|
|
705
|
+
"--public-vars",
|
|
706
|
+
action="append",
|
|
707
|
+
nargs="?",
|
|
708
|
+
const="*",
|
|
709
|
+
metavar="PATTERN",
|
|
710
|
+
help="make variables created by --create-vars public; with a name glob (repeatable), only the matching ones",
|
|
711
|
+
)
|
|
625
712
|
s.add_argument("--dry-run", action="store_true")
|
|
626
713
|
s.add_argument("--force", action="store_true")
|
|
627
714
|
s.set_defaults(func=_guard(cmd_copy))
|
|
@@ -180,6 +180,9 @@ def cmd_diff(ws: Workspace, a) -> int:
|
|
|
180
180
|
from .container import UnityFile
|
|
181
181
|
from .model import Graph
|
|
182
182
|
|
|
183
|
+
if a.rev.startswith("-"):
|
|
184
|
+
print(f"error: {a.rev!r} is not a revision", file=sys.stderr)
|
|
185
|
+
return 1
|
|
183
186
|
g = ws.graph(a.graph, a.kind)
|
|
184
187
|
slot = g.loaded.slot
|
|
185
188
|
try:
|
|
@@ -306,22 +309,25 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
306
309
|
|
|
307
310
|
def main(argv: Optional[List[str]] = None) -> int:
|
|
308
311
|
args = build_parser().parse_args(argv)
|
|
309
|
-
try:
|
|
310
|
-
ws = Workspace(args.project)
|
|
311
|
-
except ProjectError as e:
|
|
312
|
-
print(f"error: {e}", file=sys.stderr)
|
|
313
|
-
return 2
|
|
314
312
|
from .assets import AssetError
|
|
315
313
|
from .build import BuildError
|
|
316
314
|
from .config import ConfigError
|
|
317
315
|
from .ops import OpError
|
|
318
316
|
from .refactor import RefactorError
|
|
319
317
|
|
|
318
|
+
try:
|
|
319
|
+
ws = Workspace(args.project)
|
|
320
|
+
except (ProjectError, ConfigError) as e:
|
|
321
|
+
print(f"error: {e}", file=sys.stderr)
|
|
322
|
+
return 2
|
|
320
323
|
try:
|
|
321
324
|
return args.func(ws, args) or 0
|
|
322
325
|
except (GraphError, ContainerError, BuildError, OpError, AssetError, RefactorError, ConfigError) as e:
|
|
323
326
|
print(f"error: {e}", file=sys.stderr)
|
|
324
327
|
return 1
|
|
328
|
+
except OSError as e:
|
|
329
|
+
print(f"error: {e.filename or ''}{': ' if e.filename else ''}{e.strerror or e}", file=sys.stderr)
|
|
330
|
+
return 1
|
|
325
331
|
finally:
|
|
326
332
|
ws.close()
|
|
327
333
|
|
|
@@ -41,6 +41,11 @@ def load(root: Path) -> Config:
|
|
|
41
41
|
raw = json.loads(path.read_text(encoding="utf-8"))
|
|
42
42
|
except ValueError as e:
|
|
43
43
|
raise ConfigError(f"{path}: invalid JSON: {e}") from e
|
|
44
|
+
if not isinstance(raw, dict):
|
|
45
|
+
raise ConfigError(f"{path}: expected a JSON object")
|
|
46
|
+
for section in ("layout", "scaffold"):
|
|
47
|
+
if not isinstance(raw.get(section) or {}, dict):
|
|
48
|
+
raise ConfigError(f"{path}: {section} must be an object")
|
|
44
49
|
for k, v in (raw.get("layout") or {}).items():
|
|
45
50
|
if not hasattr(layout, k):
|
|
46
51
|
raise ConfigError(f"{path}: unknown layout setting {k!r}")
|