playcanvas-agent-bridge-cli 0.6.2 → 0.7.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 +71 -10
- package/README.zh-CN.md +68 -10
- package/dist/cli.js +384 -89
- package/dist/config.js +23 -1
- package/dist/daemon/server.js +259 -29
- package/dist/plugins/host.js +260 -0
- package/dist/plugins/store.js +567 -0
- package/dist/updates.js +475 -0
- package/extension/isolated.js +12 -3
- package/extension/main.js +72 -246
- package/extension/manifest.json +1 -1
- package/extension/popup.html +82 -1
- package/extension/popup.js +257 -4
- package/extension/service-worker.js +99 -5
- package/package.json +7 -8
- package/plugins/index.json +14 -0
- package/plugins/tinyapp-builder/node/builder.js +589 -0
- package/plugins/tinyapp-builder/node/index.js +30 -0
- package/plugins/tinyapp-builder/package.json +13 -0
- package/plugins/tinyapp-builder/page/editor.js +249 -0
- package/plugins/tinyapp-builder/pcbridge-plugin.json +28 -0
- package/skills/claude/pcbridge-plugin-authoring/SKILL.md +220 -0
- package/skills/claude/playcanvas-agent-bridge-cli/SKILL.md +24 -18
- package/skills/codex/pcbridge-plugin-authoring/SKILL.md +220 -0
- package/skills/codex/pcbridge-plugin-authoring/agents/openai.yaml +4 -0
- package/skills/codex/playcanvas-agent-bridge-cli/SKILL.md +32 -20
- package/skills/cursor/pcbridge-plugin-authoring.mdc +221 -0
- package/skills/cursor/playcanvas-agent-bridge-cli.mdc +14 -13
- package/skills/windsurf/pcbridge-plugin-authoring.md +215 -0
- package/skills/windsurf/playcanvas-agent-bridge-cli.md +14 -13
- package/dist/builder/manager.js +0 -564
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# pcbridge Plugin Authoring
|
|
2
|
+
|
|
3
|
+
A pcbridge plugin is an optional package that users add, enable, disable, and remove
|
|
4
|
+
independently. It is **not** the Chrome extension: the extension is a fixed part of pcbridge,
|
|
5
|
+
while plugins are loaded by the pcbridge daemon and delivered to pages through that extension.
|
|
6
|
+
Different users enable different plugins (a modeller's Blender sync, a programmer's Editor
|
|
7
|
+
buttons), so never add plugin features to pcbridge core or to the extension source.
|
|
8
|
+
|
|
9
|
+
## Where plugin code runs
|
|
10
|
+
|
|
11
|
+
| Runtime | Entry in the manifest | Runs in | Use it for |
|
|
12
|
+
| --- | --- | --- | --- |
|
|
13
|
+
| node | `node` | The local pcbridge daemon (Bun) | Files, network, credentials, child processes, local apps (Blender, DCC tools), heavy work |
|
|
14
|
+
| page | `page.editor`, `page.launch` | The PlayCanvas Editor / Launch page (MAIN world) | Editor UI, `editor.api.globals` reads and writes, runtime inspection |
|
|
15
|
+
| extension | none | Isolated world, service worker, popup | Not extensible. It only relays messages and hosts the **Plugins** management tab |
|
|
16
|
+
|
|
17
|
+
Plugins cannot ship code into the extension runtime: Manifest V3 forbids running code that is not
|
|
18
|
+
packaged with the extension, and that runtime holds the daemon session token. A page script
|
|
19
|
+
therefore has no `chrome.*` API and no token; anything privileged goes through a node action.
|
|
20
|
+
|
|
21
|
+
```text
|
|
22
|
+
pcbridge plugin call <id> <action> ─┐
|
|
23
|
+
page: plugin.call(action, params) ─┴─> node: plugin.handle(action, fn)
|
|
24
|
+
node: plugin.callPage(target, name, params) ──> page: plugin.handle(name, fn)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Package layout
|
|
28
|
+
|
|
29
|
+
```text
|
|
30
|
+
my-plugin/
|
|
31
|
+
pcbridge-plugin.json # manifest (required)
|
|
32
|
+
node/index.js # optional node entry
|
|
33
|
+
page/editor.js # optional Editor page script
|
|
34
|
+
page/launch.js # optional Launch page script
|
|
35
|
+
package.json # optional; only when the node side has npm dependencies
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`pcbridge-plugin.json`:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"id": "my-plugin",
|
|
43
|
+
"name": "My Plugin",
|
|
44
|
+
"version": "1.0.0",
|
|
45
|
+
"apiVersion": 1,
|
|
46
|
+
"minPcbridgeVersion": "0.7.0",
|
|
47
|
+
"description": "One sentence shown in plugin lists.",
|
|
48
|
+
"node": "node/index.js",
|
|
49
|
+
"page": { "editor": "page/editor.js", "launch": "page/launch.js" },
|
|
50
|
+
"actions": {
|
|
51
|
+
"export": {
|
|
52
|
+
"description": "What the action does and returns.",
|
|
53
|
+
"params": { "assetId": "Asset id (required).", "format": "glb or fbx; default glb." }
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Manifest rules:
|
|
60
|
+
|
|
61
|
+
- `id`: 2-49 characters, lowercase letters, digits, and hyphens. It names the plugin in the CLI,
|
|
62
|
+
in RPC routes, and in the install directory; never change it after release.
|
|
63
|
+
- `name`, `version` (semantic version), and `apiVersion: 1` are required.
|
|
64
|
+
- `minPcbridgeVersion` (optional semantic version) declares the minimum `pcbridge` core version required to install or update this plugin.
|
|
65
|
+
- At least one of `node`, `page.editor`, `page.launch` is required. Every entry is a relative path
|
|
66
|
+
to an existing file inside the plugin directory.
|
|
67
|
+
- `actions` documents the node actions for other agents (`pcbridge plugin info <id>`). Keep it in
|
|
68
|
+
step with the `plugin.handle` calls in the node entry.
|
|
69
|
+
- Bump `version` on every released change.
|
|
70
|
+
|
|
71
|
+
## Node entry
|
|
72
|
+
|
|
73
|
+
An ES module (JavaScript or TypeScript; the daemon runs on Bun) that exports `activate(plugin)`.
|
|
74
|
+
`activate` may be async. It runs when the daemon starts and whenever the plugin is added, enabled,
|
|
75
|
+
updated, or reloaded.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
export function activate(plugin) {
|
|
79
|
+
plugin.handle("export", async (params, { target }) => {
|
|
80
|
+
if (!target || target.kind !== "editor") throw new Error("export requires an Editor target.");
|
|
81
|
+
const selection = await plugin.callPage(target, "selection");
|
|
82
|
+
return { exported: selection.length };
|
|
83
|
+
});
|
|
84
|
+
const timer = setInterval(() => { /* ... */ }, 5000);
|
|
85
|
+
plugin.onDispose(() => clearInterval(timer));
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
| Member | Purpose |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| `plugin.id`, `plugin.version`, `plugin.dir` | Identity and the absolute plugin directory |
|
|
92
|
+
| `plugin.handle(name, fn)` | Register an action. `fn(params, { target })` returns JSON-serializable data or throws an `Error` (an optional string `code` becomes the CLI error code) |
|
|
93
|
+
| `plugin.callPage(target, name, params?, timeoutMs?)` | Call a handler registered by this plugin's page script; resolves with its result |
|
|
94
|
+
| `plugin.rpc(target, method, params?, timeoutMs?)` | Call a built-in bridge method, for example `bridge:eval` with `{ code, args }` |
|
|
95
|
+
| `plugin.targets()` | Connected targets (`id`, `kind`, `ready`, `projectId`, `sceneId`, ...) for node-initiated work |
|
|
96
|
+
| `plugin.workspace.rootDir` | The daemon workspace root |
|
|
97
|
+
| `plugin.workspace.status(target)` | Workspace status, including `projectDirectory` and `tmpDirectory` |
|
|
98
|
+
| `plugin.workspace.prepareAssetFiles(target, assetIds)` | Materialize asset files locally; returns `{ projectDirectory, tmpDirectory, assets: [{ id, name, type, filename, path, hash }] }` |
|
|
99
|
+
| `plugin.workspace.prepareAssetResources(target, requests)` | Materialize auxiliary files such as texture variants: `[{ assetId, filename, url, hash? }]` |
|
|
100
|
+
| `plugin.log(message)` | Write to the daemon log |
|
|
101
|
+
| `plugin.onDispose(fn)` | Register cleanup; runs on disable, remove, reload, update, and daemon stop |
|
|
102
|
+
|
|
103
|
+
`target` in an action context is the `--target` of the CLI call, the calling tab for a page call,
|
|
104
|
+
otherwise the most recent ready target, otherwise `null`. Functions that take a target accept that
|
|
105
|
+
object or a selector string such as `tab:5` or `editor:<sceneId>`.
|
|
106
|
+
|
|
107
|
+
## Page script
|
|
108
|
+
|
|
109
|
+
A single classic script. pcbridge runs its text as the body of an async function once the target
|
|
110
|
+
is ready (Editor: `editor.api.globals` exists; Launch: the app has started in a visible tab), with
|
|
111
|
+
`plugin`, `editor`, `pc`, `pcui`, and `runtimeApp` in scope. `import` and `export` are not
|
|
112
|
+
available; bundle to one file if you need modules.
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
const button = new pcui.Button({ text: "Export selection" });
|
|
116
|
+
button.class.add("my-plugin-export");
|
|
117
|
+
editor.call("layout.toolbar").append(button);
|
|
118
|
+
button.on("click", async () => {
|
|
119
|
+
const result = await plugin.call("export", { format: "glb" });
|
|
120
|
+
console.info("[my-plugin] exported", result.exported);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
plugin.handle("selection", () =>
|
|
124
|
+
editor.api.globals.selection.items.map((item) => String(item.get("resource_id") || item.get("id"))));
|
|
125
|
+
|
|
126
|
+
plugin.onDispose(() => button.destroy());
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
| Member | Purpose |
|
|
130
|
+
| --- | --- |
|
|
131
|
+
| `plugin.id`, `plugin.version`, `plugin.kind` | Identity; `kind` is `"editor"` or `"launch"` |
|
|
132
|
+
| `plugin.handle(name, fn)` | Register a handler for `plugin.callPage` on the node side; return plain JSON |
|
|
133
|
+
| `plugin.call(action, params?, timeoutMs?)` | Call a node action of the same plugin; the target is this tab |
|
|
134
|
+
| `plugin.onDispose(fn)` | Register cleanup; runs when the plugin is disabled, removed, or its code changes |
|
|
135
|
+
|
|
136
|
+
Enabling, disabling, and reloading take effect in open pages immediately; no page refresh is
|
|
137
|
+
needed. A script whose text is unchanged is not re-run.
|
|
138
|
+
|
|
139
|
+
## Rules
|
|
140
|
+
|
|
141
|
+
1. **Split by capability.** Credentials, file paths, and network calls to other services stay in
|
|
142
|
+
node. Page scripts only touch the page. Never send secrets to a page or return them from an
|
|
143
|
+
action.
|
|
144
|
+
2. **Everything is disposable.** Whatever `activate` or a page script creates (timers, sockets,
|
|
145
|
+
servers, child processes, DOM and pcui elements, event subscriptions via `handle.unbind()`)
|
|
146
|
+
must be undone in `onDispose`. A reload must not leave duplicates.
|
|
147
|
+
3. **Top level must be fast.** Page activation times out after 10 seconds and `activate` blocks
|
|
148
|
+
other plugin operations; start long work in the background and report it through an action
|
|
149
|
+
such as `status`.
|
|
150
|
+
4. **Plain JSON across boundaries.** Never return Observers, Entities, DOM nodes, or class
|
|
151
|
+
instances. Pass asset ids and local paths instead of file contents.
|
|
152
|
+
5. **Catch errors in your own callbacks.** An uncaught exception in a node timer or socket callback
|
|
153
|
+
can stop the daemon. If a plugin prevents the daemon from starting, stop the daemon and run
|
|
154
|
+
`pcbridge plugin disable <id>`; management commands work on disk while the daemon is down.
|
|
155
|
+
6. **Namespace by plugin id.** CSS classes, `localStorage` keys, and global names start with the id.
|
|
156
|
+
7. **Feature-detect Editor and Engine APIs** and use `{ history: true }` for Editor mutations when
|
|
157
|
+
available, as in `pcbridge eval` snippets.
|
|
158
|
+
8. **Declare npm dependencies** in the plugin's own `package.json` `dependencies`. pcbridge runs
|
|
159
|
+
`bun install --production` when the plugin is added or updated. For `--link` plugins run
|
|
160
|
+
`bun install` in the directory yourself. Do not rely on pcbridge's own dependencies.
|
|
161
|
+
9. Keep plugin source outside any project `assets/` directory; the workspace watcher uploads files
|
|
162
|
+
created there.
|
|
163
|
+
|
|
164
|
+
## Develop and verify
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
pcbridge plugin add ./my-plugin --link # use the directory in place
|
|
168
|
+
pcbridge plugin list # state must be "active"; read error and pages[]
|
|
169
|
+
pcbridge plugin call my-plugin export --target editor:<sceneId> --params '{"format":"glb"}'
|
|
170
|
+
pcbridge plugin reload my-plugin # after every edit to node or page files
|
|
171
|
+
pcbridge eval --target editor:<sceneId> --code "return !!document.querySelector('.my-plugin-export')"
|
|
172
|
+
pcbridge logs get --target editor:<sceneId> --level error
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
`plugin list` and `plugin info <id>` report `state` (`active`, `error`, `disabled`, or `stopped`
|
|
176
|
+
when the daemon is not running), the node activation `error`, and one `pages[]` entry per connected
|
|
177
|
+
target with the page script result. Treat a plugin as working only when the state is `active`,
|
|
178
|
+
every `pages[]` entry is `ok`, each action returns the expected data, and the page effect is
|
|
179
|
+
confirmed with `eval` or a viewport capture. `--params-json <file>` reads parameters from a file
|
|
180
|
+
inside the project workspace.
|
|
181
|
+
|
|
182
|
+
Other management commands, also available in the extension popup under **Plugins**:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
pcbridge plugin enable|disable|remove <id>
|
|
186
|
+
pcbridge plugin update <id> # re-fetch from the recorded source, reinstall dependencies, reload
|
|
187
|
+
pcbridge plugin update --all # update all outdated installed plugins
|
|
188
|
+
pcbridge plugin list --refresh # refresh remote official plugin catalog and versions
|
|
189
|
+
pcbridge help plugin
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Distribute through GitHub
|
|
193
|
+
|
|
194
|
+
Publish the plugin directory in a public GitHub repository, at the root or in a subdirectory, and
|
|
195
|
+
tag releases. Users install and update with:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
pcbridge plugin add github:<owner>/<repo> # default branch, plugin at the root
|
|
199
|
+
pcbridge plugin add github:<owner>/<repo>/plugins/my-plugin#v1.2.0 # subdirectory, pinned tag
|
|
200
|
+
pcbridge plugin update my-plugin # same source and ref again
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
A source without `#ref` follows the default branch, so `update` picks up new commits; a pinned
|
|
204
|
+
`#ref` only changes when the plugin is removed and added again with another ref. Commit built
|
|
205
|
+
output if the plugin needs a build step, because pcbridge installs the repository files as they
|
|
206
|
+
are. Plugins run with full local and page access; tell users to add only sources they trust.
|
|
207
|
+
|
|
208
|
+
## Reference implementation
|
|
209
|
+
|
|
210
|
+
`tinyapp-builder` is the official plugin shipped with pcbridge (`pcbridge plugin add
|
|
211
|
+
tinyapp-builder`, source under `plugins/tinyapp-builder/` of the pcbridge package). It shows a
|
|
212
|
+
node entry with background jobs and npm dependencies, an Editor page script that injects an
|
|
213
|
+
Inspector panel and serves `callPage` requests, and a complete `actions` section.
|
|
214
|
+
When adding or bumping an official plugin under `plugins/<id>/`, run `bun run plugins:sync` to
|
|
215
|
+
synchronize `plugins/index.json` (`bun run check:version` enforces this).
|
|
@@ -13,19 +13,16 @@ pcbridge targets
|
|
|
13
13
|
Run `pcbridge daemon start` only for `DAEMON_NOT_LISTENING`; for `LOOPBACK_ACCESS_DENIED`, retry
|
|
14
14
|
with local-loopback permission. If no target is connected, install/reload the unpacked extension.
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
`pcbridge
|
|
18
|
-
`
|
|
19
|
-
`pcbridge
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
`
|
|
24
|
-
<original-root>` and verify `pcbridge doctor`. A daemon version without authenticated shutdown must
|
|
25
|
-
be stopped once with Ctrl+C before starting the updated daemon. Update the independently published Editor build with
|
|
16
|
+
CLI responses attach `meta.updates` when a newer `pcbridge` release, local component version mismatch,
|
|
17
|
+
or official plugin update is available. Check updates with `pcbridge update status --refresh` or
|
|
18
|
+
`pcbridge plugin list --refresh`. Apply a one-click core update with `pcbridge update` (or
|
|
19
|
+
`pcbridge update --plugins`), which upgrades the global package, refreshes installed skills,
|
|
20
|
+
rewrites `~/.pcbridge/extension`, triggers Chrome extension reload + PlayCanvas tab refresh
|
|
21
|
+
(`--no-reload-tabs` skips tab refresh), and restarts the running daemon in-place. Update official
|
|
22
|
+
plugins independently without restarting the daemon via `pcbridge plugin update <id>` or
|
|
23
|
+
`pcbridge plugin update --all` (or the extension popup **Plugins** tab). Update the independently published Editor build with
|
|
26
24
|
`pcbridge frontend update` and `frontend status`; a frontend-only update needs no daemon restart,
|
|
27
|
-
but the Editor tab must be refreshed and custom mode selected in the popup when necessary.
|
|
28
|
-
claim completion before these manual steps are confirmed.
|
|
25
|
+
but the Editor tab must be refreshed and custom mode selected in the popup when necessary.
|
|
29
26
|
|
|
30
27
|
The current directory is the default workspace root; `daemon start/restart --workspace <directory>`
|
|
31
28
|
selects it explicitly, and `daemon stop` stops the authenticated daemon. After selecting a target, run
|
|
@@ -62,6 +59,10 @@ Read schema-v3 `pcbridge.project.json.assets`: `folder` is the remote display pa
|
|
|
62
59
|
effective metadata, presence, writability, and hashes. Only collisions gain
|
|
63
60
|
`.__pc_<type>_<assetId>`. Treat that asset catalog as pcbridge-managed. Confirmed remote
|
|
64
61
|
deletions are quarantined under `tmp/trash/remote/`; `tmp/conflicts/` contains content divergence.
|
|
62
|
+
Optional features ship as plugins: `pcbridge plugin list` shows installed and available plugins with
|
|
63
|
+
their actions, and `pcbridge plugin call <id> <action> --target editor:<sceneId> --params '<json>'`
|
|
64
|
+
runs one. Use the pcbridge-plugin-authoring rule to create or change a plugin.
|
|
65
|
+
With the official `tinyapp-builder` plugin enabled (`pcbridge plugin add tinyapp-builder`),
|
|
65
66
|
Template selection exposes pcbridge Tiny Builder for direct S3 object uploads; project `.env`
|
|
66
67
|
overrides workspace-root `.env`. A build materializes every primary dependency plus texture
|
|
67
68
|
variants and additional font maps under the Asset's remote folder in `assets/`, then uploads only
|
|
@@ -74,7 +75,7 @@ For the optional published Editor build, use `pcbridge frontend install latest`,
|
|
|
74
75
|
The popup remembers that choice per project and reapplies it on later project-picker and scene
|
|
75
76
|
Editor navigations; change the remembered choice only through the popup.
|
|
76
77
|
|
|
77
|
-
Use layered help to load only the command surface you need: `pcbridge help`, then `pcbridge help core|target|workspace|processing|import|frontend|entity|asset|material|template|script|scene|store|viewport|launch|logs|eval`.
|
|
78
|
+
Use layered help to load only the command surface you need: `pcbridge help`, then `pcbridge help core|target|workspace|plugin|processing|import|frontend|entity|asset|material|template|script|scene|store|viewport|launch|logs|eval`.
|
|
78
79
|
|
|
79
80
|
Prefer local file edits for scripts, shaders, text, `*.material.json` / `*.template.json` data, and multi-property
|
|
80
81
|
edits in the active `.scene.json`. Use structured commands for Editor pipelines (`scene open`,
|