vscode-behavior3 2.1.3 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,212 +1,185 @@
1
1
  # Behavior3 Editor
2
2
 
3
- VS Code behavior tree visual editor for game AI workflows.
3
+ VS Code custom editor for Behavior3 JSON behavior trees. It combines a visual graph canvas, an Inspector, project scaffolding, and build/check/batch scripting for game AI workflows.
4
4
 
5
5
  ## Related Projects
6
6
 
7
- - **[behavior3-ts](https://github.com/codetypess/behavior3-ts)** - TypeScript Runtime Library
8
- - **[behavior3lua](https://github.com/zhandouxiaojiji/behavior3lua)** - Lua Runtime
7
+ - **[behavior3-ts](https://github.com/codetypess/behavior3-ts)** - TypeScript runtime library
8
+ - **[behavior3lua](https://github.com/zhandouxiaojiji/behavior3lua)** - Lua runtime
9
9
 
10
- ## Editor Preview
10
+ ## Preview
11
11
 
12
12
  ![Behavior3 Editor Preview](media/images/pic.png)
13
13
 
14
- The editor provides an intuitive visual interface for designing and managing behavior trees. See the screenshot above for the full editing experience with node canvas, inspector panel, and tree organization.
15
-
16
14
  ## Features
17
15
 
18
- - Visual canvas editor (drag, connect, organize nodes)
19
- - Built-in inspector panel for node/tree properties
16
+ - Visual graph editor for Behavior3 trees and reachable subtrees
17
+ - Inspector in `sidebar` or `embedded` mode
18
+ - Explorer `Behavior3` submenu for project, tree, and script scaffolding
19
+ - Build, debug build, checker scripts, and project batch processing
20
20
  - Custom node definitions via `.b3-setting`
21
- - One-click build command in editor title bar
22
- - Optional expression validation for node args
23
- - Auto theme adaptation (dark/light)
21
+ - Expression and node-argument validation
22
+ - Theme-aware UI for dark and light VS Code themes
24
23
 
25
24
  ## Quick Start
26
25
 
27
- ### Open a tree file
26
+ ### Open a tree
27
+
28
+ - Right-click a Behavior3 `.json` file in Explorer
29
+ - Select **Open With** -> **Behavior3 Editor**
28
30
 
29
- - Right-click a tree `.json` file in Explorer
30
- - Select **Open With** → **Behavior3 Editor**
31
+ ### Create project files
31
32
 
32
- ### Create a new project
33
+ From a folder's Explorer `Behavior3` submenu you can run:
33
34
 
34
- - Right-click a folder in Explorer
35
- - Run **Behavior Tree: Create Project**
35
+ - **Create Project**
36
+ - **Create Behavior Tree File**
37
+ - **Create Build Script**
38
+ - **Create Batch Script**
39
+ - **Create Checker Script**
40
+ - **Run Script as Batch Process**
36
41
 
37
- ### Configure nodes
42
+ `Run Script as Batch Process` is also available on `.ts`, `.mts`, `.js`, and `.mjs` files. Running it from a folder lets you choose a script first; running it from a script file runs that script directly.
38
43
 
39
- Create a `.b3-setting` file in workspace:
44
+ ### Configure node definitions
45
+
46
+ Create a `.b3-setting` file in the workspace:
40
47
 
41
48
  ```json
42
49
  [
43
- {
44
- "name": "MyAction",
45
- "type": "Action",
46
- "desc": "Does something useful",
47
- "args": [{ "name": "duration", "type": "float", "desc": "Duration in seconds" }]
48
- },
49
- {
50
- "name": "CheckScore",
51
- "type": "Condition",
52
- "desc": "Checks whether the score matches the rule",
53
- "args": [{ "name": "value", "type": "expr", "desc": "Expression" }]
54
- }
50
+ {
51
+ "name": "MyAction",
52
+ "type": "Action",
53
+ "desc": "Does something useful",
54
+ "args": [{ "name": "duration", "type": "float", "desc": "Duration in seconds" }]
55
+ },
56
+ {
57
+ "name": "CheckScore",
58
+ "type": "Condition",
59
+ "desc": "Checks whether the score matches the rule",
60
+ "args": [{ "name": "value", "type": "expr", "desc": "Expression" }]
61
+ }
55
62
  ]
56
63
  ```
57
64
 
58
- ### Build
59
-
60
- Click **Build** in the editor title bar.
65
+ ### Configure workspace behavior
61
66
 
62
- ### Command Line Build
63
-
64
- The npm package exposes a `behavior3-build` command for CI and project scripts:
65
-
66
- ```bash
67
- npm install -D vscode-behavior3
68
- ```
67
+ Use a `.b3-workspace` file to register build and checker scripts:
69
68
 
70
69
  ```json
71
70
  {
72
- "scripts": {
73
- "build:behavior": "behavior3-build --project ./workdir/hero.json --output ./dist/behavior3"
74
- }
71
+ "settings": {
72
+ "checkExpr": true,
73
+ "buildScript": "scripts/build.ts",
74
+ "checkScripts": ["scripts/checkers/**/*.ts"]
75
+ }
75
76
  }
76
77
  ```
77
78
 
78
- You can also run it without adding a script:
79
-
80
- ```bash
81
- npm exec -- behavior3-build --project ./workdir/hero.json --output ./dist/behavior3
82
- ```
83
-
84
- Or run it without installing first:
79
+ `buildScript` and `checkScripts` are resolved relative to the `.b3-workspace` file. See [sample/workspace.b3-workspace](sample/workspace.b3-workspace) for a complete sample.
85
80
 
86
- ```bash
87
- npx --package vscode-behavior3 behavior3-build --project ./workdir/hero.json --output ./dist/behavior3
88
- ```
81
+ ## Inspector Modes
89
82
 
90
- Publishing flow:
83
+ Set `behavior3.inspectorMode` to choose the active Inspector presentation:
91
84
 
92
- ```bash
93
- npm login
94
- npm whoami
95
- npm version patch
96
- npm run pack:npm
97
- npm run publish:npm
98
- ```
85
+ - `sidebar`: show the Inspector in the dedicated Behavior3 side view
86
+ - `embedded`: show the Inspector inside the main editor webview
99
87
 
100
- `npm run pack:npm` performs the same prepack checks as publishing and prints the
101
- tarball contents without publishing.
88
+ Both modes share the same document semantics and commands. Only the presentation changes.
102
89
 
103
- ### Build Script (`.b3-workspace`)
90
+ ## Build, Batch, and Check Scripts
104
91
 
105
- `settings.buildScript` supports ESM scripts:
92
+ Behavior3 supports ESM JavaScript and TypeScript scripts:
106
93
 
107
94
  - JavaScript: `.js`, `.mjs`
108
95
  - TypeScript: `.ts`, `.mts` (runtime transpile, no type-check)
109
96
 
110
- TypeScript build scripts can import other local TypeScript files with explicit
111
- extensions:
97
+ When importing local TypeScript helpers, use explicit extensions such as `./helper.ts`.
98
+ The `behavior3` decorator namespace is provided by the runtime, so script files only need type imports from `vscode-behavior3/build`.
112
99
 
113
- ```ts
114
- import { helper } from "./helper.ts";
115
- ```
100
+ All script types can import authoring types from `vscode-behavior3/build`. Example scripts are available in:
116
101
 
117
- To debug TypeScript build scripts, launch the CLI with Node inspector and enable
118
- build-script debug mode:
102
+ - [sample/scripts/build.ts](sample/scripts/build.ts)
103
+ - [sample/scripts/batch.ts](sample/scripts/batch.ts)
104
+ - [sample/scripts/checkers/positive.ts](sample/scripts/checkers/positive.ts)
119
105
 
120
- ```bash
121
- BEHAVIOR3_BUILD_DEBUG=1 node --inspect-brk dist/build-cli.js --output /tmp/b3build --project sample/workdir/hero.json
122
- ```
106
+ ### Build Scripts
123
107
 
124
- This emits inline source maps and creates temporary `.runtime.*.mjs` files next
125
- to the build script while the build runs so breakpoints in `build.ts` and
126
- imported helper files can bind. The runtime files are removed after the build
127
- completes; if the build script fails to load, they are left in place for
128
- inspection. Editor debug builds also clean runtime files when the debug session
129
- terminates.
130
- Inside the editor, `Ctrl+B`/`Cmd+B` builds normally, while
131
- `Ctrl+Shift+B`/`Cmd+Shift+B` starts a VS Code Node debug session for the build.
108
+ Build scripts are declared with `@behavior3.build` and can transform build output without rewriting source trees.
132
109
 
133
- Example:
110
+ ```ts
111
+ import type { BuildEnv, BuildScript } from "vscode-behavior3/build";
134
112
 
135
- ```json
136
- {
137
- "settings": {
138
- "checkExpr": true,
139
- "buildScript": "scripts/build.ts",
140
- "checkScripts": ["scripts/checkers/**/*.ts"]
141
- }
113
+ @behavior3.build
114
+ export class ProjectBuild implements BuildScript {
115
+ constructor(private readonly env: BuildEnv) {}
142
116
  }
143
117
  ```
144
118
 
145
- `settings.checkScripts` is optional and loads additional checker-only scripts
146
- relative to the `.b3-workspace` directory. Matching scripts are scanned for
147
- exported `@behavior3.check("name")` classes and are used by both the editor
148
- Inspector validation and project builds. Generated `.runtime.*.mjs`, `.d.ts`,
149
- `node_modules`, `dist`, and `build` paths are ignored.
119
+ Supported hooks:
150
120
 
151
- All build hooks receive `env`:
121
+ - `onProcessTree(tree, path, errors)`
122
+ - `onProcessNode(node, errors)`
123
+ - `onWriteFile(path, tree)`
124
+ - `onComplete(status)`
125
+
126
+ ### Batch Scripts
152
127
 
153
- - `env.fs`: Node `fs`
154
- - `env.path`: full path helper object (all methods exposed)
155
- - `env.workdir`: resolved workspace directory
156
- - `env.nodeDefs`: loaded node definitions map
157
- - `env.logger`: `log/debug/info/warn/error`
128
+ Batch scripts are declared with `@behavior3.batch` and are used by **Run Script as Batch Process** to rewrite source trees in place across the current project.
158
129
 
159
- Use an exported `@behavior3.build` class. The decorator is provided by the build
160
- runtime, so no value import is required. The extension constructs the class once
161
- with `env`, then calls methods:
130
+ Supported hooks:
162
131
 
163
- - `constructor(env)`
164
132
  - `shouldUpgradeTree(path, tree)`
165
133
  - `onProcessTree(tree, path, errors)`
166
134
  - `onProcessNode(node, errors)`
167
135
  - `onWriteFile(path, tree)`
168
136
  - `onComplete(status)`
169
137
 
170
- ```ts
171
- import type { BuildEnv, TreeData } from "vscode-behavior3/build";
138
+ ### Checker Scripts
172
139
 
173
- @behavior3.build
174
- export class ProjectBuild {
175
- constructor(private readonly env: BuildEnv) {}
140
+ Checker scripts register custom argument validators with `@behavior3.check("name")`. They are used by both Inspector validation and project builds.
176
141
 
177
- onProcessTree(tree: TreeData) {
178
- this.env.logger.info("building", tree.name);
179
- return tree;
180
- }
181
- }
182
- ```
142
+ For compatibility, supported script files may still export classes through named `Hook`, `BuildHook`, `BatchHook`, or `default`, but the decorator-based forms above are the canonical APIs.
183
143
 
184
- For compatibility, supported script files may still export a class via named
185
- `Hook` or `default`.
144
+ ## Build and Debug
186
145
 
187
- For TypeScript authoring hints, import build script types from
188
- `vscode-behavior3/build`. See `sample/scripts/build.ts` for a complete example.
146
+ - Click **Build** in the editor title bar, or press `Ctrl/Cmd+B`
147
+ - Press `Ctrl/Cmd+Shift+B` to start a debug build session
189
148
 
190
- ### Project Batch Processing
149
+ The npm package also exposes a `behavior3-build` command for CI and project scripts:
191
150
 
192
- Use `Batch Process Behavior Trees` to pick a script on demand and apply it to
193
- every behavior tree source file in the current project. The script can be
194
- TypeScript with local `import` statements, just like build scripts.
151
+ ```bash
152
+ npm install -D vscode-behavior3
153
+ ```
195
154
 
196
- ## Extension Settings
155
+ ```json
156
+ {
157
+ "scripts": {
158
+ "build:behavior": "behavior3-build --project ./workdir/hero.json --output ./dist/behavior3"
159
+ }
160
+ }
161
+ ```
197
162
 
198
- | Setting | Type | Default | Description |
199
- | --------------------- | ------- | -------- | ---------------------------------------------------------------- |
200
- | `behavior3.checkExpr` | boolean | `true` | Enable expression syntax validation for expression-type args. |
201
- | `behavior3.language` | string | `"auto"` | Editor UI language. Options:`auto` (follow VS Code), `zh`, `en`. |
163
+ You can also run it directly:
202
164
 
203
- ## Inspector
165
+ ```bash
166
+ npm exec -- behavior3-build --project ./workdir/hero.json --output ./dist/behavior3
167
+ ```
204
168
 
205
- Inspector is available in the dedicated `behavior3` sidebar and supports direct editing.
169
+ Or without installing first:
206
170
 
207
- - Select a node to edit node fields (`args`, `input`, `output`, `desc`, `debug`, `disabled`)
208
- - Click empty canvas to edit tree fields (`name`, `desc`, `vars`, `import`, `group`)
209
- - Opening a Behavior3 tree or changing the graph selection will automatically reveal the matching Inspector context
171
+ ```bash
172
+ npx --package vscode-behavior3 behavior3-build --project ./workdir/hero.json --output ./dist/behavior3
173
+ ```
174
+
175
+ ## Extension Settings
176
+
177
+ | Setting | Type | Default | Description |
178
+ | --------------------------- | --------- | ----------- | ------------------------------------------------------------------------ |
179
+ | `behavior3.checkExpr` | `boolean` | `true` | Enable expression validation for expression-type args. |
180
+ | `behavior3.language` | `string` | `"auto"` | UI language: `auto`, `zh`, or `en`. |
181
+ | `behavior3.subtreeEditable` | `boolean` | `true` | Allow editing supported subtree content from the current editor context. |
182
+ | `behavior3.inspectorMode` | `string` | `"sidebar"` | Choose whether the Inspector is shown in `sidebar` or `embedded` mode. |
210
183
 
211
184
  ## Keyboard Shortcuts
212
185
 
@@ -224,14 +197,22 @@ Inspector is available in the dedicated `behavior3` sidebar and supports direct
224
197
  | `Ctrl/Cmd+B` | Build |
225
198
  | `F4` | Toggle Text / Behavior3 editor |
226
199
 
200
+ ## Docs
201
+
202
+ - [docs/README.md](docs/README.md) - documentation entry point
203
+ - [docs/spec-driven-development.md](docs/spec-driven-development.md) - SDD workflow
204
+ - [docs/spec/README.md](docs/spec/README.md) - baseline spec map and work-item index
205
+ - [sample/](sample) - sample workspace, trees, and scripts
206
+
227
207
  ## Development
228
208
 
229
- - Output logs: **View Output** channel **Behavior3**
209
+ - Output logs: **View -> Output** -> **Behavior3**
230
210
  - Webview logs are also available in DevTools
231
211
 
232
212
  ## Requirements
233
213
 
234
- - VS Code 1.85.0+
214
+ - VS Code `^1.105.0`
215
+ - Node `>=20.19` for the CLI and TypeScript script runtime
235
216
 
236
217
  ## License
237
218
 
package/build.d.ts CHANGED
@@ -2,9 +2,14 @@ import type { BuildRuntime } from "./webview/shared/b3build-model";
2
2
  export type { NodeDef } from "behavior3";
3
3
  export type { NodeData, TreeData } from "./webview/shared/b3type";
4
4
  export type {
5
+ BatchDecorator,
6
+ BatchHook,
7
+ BatchHookClass,
8
+ BatchScript,
5
9
  BuildEnv,
6
10
  CheckDecorator,
7
11
  BuildDecorator,
12
+ BuildHook,
8
13
  BuildHookClass,
9
14
  BuildLogger,
10
15
  BuildRuntime,