playcanvas-agent-bridge-cli 0.6.1 → 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.
Files changed (42) hide show
  1. package/README.md +148 -31
  2. package/README.zh-CN.md +137 -33
  3. package/dist/cli.js +514 -95
  4. package/dist/config.js +23 -1
  5. package/dist/daemon/server.js +336 -28
  6. package/dist/daemon/target-registry.js +3 -0
  7. package/dist/plugins/host.js +260 -0
  8. package/dist/plugins/store.js +567 -0
  9. package/dist/processing/manager.js +265 -0
  10. package/dist/processing/tools.js +97 -0
  11. package/dist/snippets.js +27 -0
  12. package/dist/updates.js +475 -0
  13. package/dist/workspace/json-sync.js +821 -0
  14. package/dist/workspace/manager.js +1973 -326
  15. package/extension/icons/icon-128.png +0 -0
  16. package/extension/icons/icon-16.png +0 -0
  17. package/extension/icons/icon-256.png +0 -0
  18. package/extension/icons/icon-32.png +0 -0
  19. package/extension/icons/icon-48.png +0 -0
  20. package/extension/isolated.js +59 -2
  21. package/extension/main.js +770 -275
  22. package/extension/manifest.json +60 -10
  23. package/extension/popup.html +115 -3
  24. package/extension/popup.js +398 -14
  25. package/extension/service-worker.js +221 -4
  26. package/package.json +18 -18
  27. package/plugins/index.json +14 -0
  28. package/plugins/tinyapp-builder/node/builder.js +589 -0
  29. package/plugins/tinyapp-builder/node/index.js +30 -0
  30. package/plugins/tinyapp-builder/package.json +13 -0
  31. package/plugins/tinyapp-builder/page/editor.js +249 -0
  32. package/plugins/tinyapp-builder/pcbridge-plugin.json +28 -0
  33. package/skills/claude/pcbridge-plugin-authoring/SKILL.md +220 -0
  34. package/skills/claude/playcanvas-agent-bridge-cli/SKILL.md +99 -43
  35. package/skills/codex/pcbridge-plugin-authoring/SKILL.md +220 -0
  36. package/skills/codex/pcbridge-plugin-authoring/agents/openai.yaml +4 -0
  37. package/skills/codex/playcanvas-agent-bridge-cli/SKILL.md +89 -62
  38. package/skills/cursor/pcbridge-plugin-authoring.mdc +221 -0
  39. package/skills/cursor/playcanvas-agent-bridge-cli.mdc +69 -33
  40. package/skills/windsurf/pcbridge-plugin-authoring.md +215 -0
  41. package/skills/windsurf/playcanvas-agent-bridge-cli.md +68 -33
  42. package/dist/builder/manager.js +0 -564
@@ -1,8 +1,70 @@
1
1
  const FRONTEND_PREFERENCES_KEY = "pcbridgeFrontendPreferences";
2
2
  const SCENE_PROJECTS_KEY = "pcbridgeSceneProjects";
3
3
  const TAB_PROJECTS_KEY = "pcbridgeTabProjects";
4
+ const WORKSPACE_SETTINGS_KEY = "pcbridgeWorkspaceSettings";
5
+ const PENDING_RELOAD_KEY = "pcbridgePendingReload";
4
6
  const tabProjects = new Map();
5
7
 
8
+ function syncUpdateBadge(updates) {
9
+ if (!chrome.action || !chrome.action.setBadgeText) return;
10
+ const hasUpdates = Boolean(updates && updates.hasUpdates);
11
+ void chrome.action.setBadgeText({ text: hasUpdates ? "↑" : "" });
12
+ if (hasUpdates && chrome.action.setBadgeBackgroundColor) {
13
+ void chrome.action.setBadgeBackgroundColor({ color: "#2563eb" });
14
+ }
15
+ }
16
+
17
+ function isPlayCanvasTabUrl(rawUrl) {
18
+ try {
19
+ const url = new URL(rawUrl);
20
+ if (!["http:", "https:"].includes(url.protocol)) return false;
21
+ if (url.hostname === "launch.playcanvas.com" || url.hostname === "pc-launch.sightp.com") {
22
+ return true;
23
+ }
24
+ return /^\/(?:editor|launch)(?:\/|$)/.test(url.pathname);
25
+ } catch {
26
+ return false;
27
+ }
28
+ }
29
+
30
+ async function reloadPlayCanvasTabs() {
31
+ if (!chrome.tabs || !chrome.tabs.query) return 0;
32
+ const tabs = await chrome.tabs.query({});
33
+ let count = 0;
34
+ for (const tab of tabs) {
35
+ if (!Number.isInteger(tab.id) || !tab.url || !isPlayCanvasTabUrl(tab.url)) continue;
36
+ const status = await siteStatus(tab.url);
37
+ if (!status.enabled) continue;
38
+ try {
39
+ if (typeof chrome.tabs.reload === "function") {
40
+ await chrome.tabs.reload(tab.id);
41
+ } else if (typeof chrome.tabs.update === "function") {
42
+ await chrome.tabs.update(tab.id, { url: tab.url });
43
+ }
44
+ count += 1;
45
+ } catch {
46
+ // Ignore tabs that closed while reloading.
47
+ }
48
+ }
49
+ return count;
50
+ }
51
+
52
+ async function consumePendingReload() {
53
+ if (!chrome.storage || !chrome.storage.local) return;
54
+ const pending = await readObject(chrome.storage.local, PENDING_RELOAD_KEY);
55
+ if (!pending || !pending.requestedAt) return;
56
+ await chrome.storage.local.set({ [PENDING_RELOAD_KEY]: {} });
57
+ if (pending.reloadTabs !== false && Date.now() - Number(pending.requestedAt) < 60000) {
58
+ await reloadPlayCanvasTabs();
59
+ }
60
+ }
61
+
62
+ function clampEagerMaxMb(value) {
63
+ const parsed = Number(value);
64
+ if (!Number.isFinite(parsed)) return 2;
65
+ return Math.min(10, Math.max(1, Math.round(parsed)));
66
+ }
67
+
6
68
  function normalizeId(value) {
7
69
  const id = String(value || "").trim();
8
70
  return /^\d+$/.test(id) ? id : null;
@@ -84,6 +146,7 @@ async function getSceneProject(sceneId) {
84
146
 
85
147
  async function resolveProjectContext({ url, tabId, projectId, sceneId } = {}) {
86
148
  const parsed = parseEditorUrl(url);
149
+ if (!parsed) return { parsed: null, projectId: null, sceneId: null };
87
150
  const resolvedSceneId = normalizeId(sceneId) || (parsed && parsed.sceneId);
88
151
  let resolvedProjectId = normalizeId(projectId) || (parsed && parsed.projectId);
89
152
 
@@ -172,8 +235,10 @@ async function requestDaemon(message, sender) {
172
235
  const path = String(message.path || "");
173
236
  const method = String(message.method || "GET").toUpperCase();
174
237
  const allowed =
175
- (path === "/builder/jobs" && method === "POST") ||
176
- (/^\/builder\/jobs\/[^/]+$/.test(path) && method === "GET");
238
+ (/^\/plugins\/[a-z0-9-]+\/actions\/[\w.-]+$/.test(path) && method === "POST") ||
239
+ (path === "/workspace/sync" && method === "POST") ||
240
+ (path === "/workspace/settings" && (method === "GET" || method === "POST")) ||
241
+ (/^\/processing\/(capabilities|begin|chunk|run|status|read|cancel|finish)$/.test(path) && method === "POST");
177
242
  if (!allowed) {
178
243
  return {
179
244
  ok: false,
@@ -181,6 +246,9 @@ async function requestDaemon(message, sender) {
181
246
  };
182
247
  }
183
248
 
249
+ if (!sender.tab || !(await siteStatus(sender.tab.url)).enabled) {
250
+ return { ok: false, error: { code: "SITE_DISABLED", message: "Site is not enabled." } };
251
+ }
184
252
  const config = await loadConfig();
185
253
  if (!config.token) {
186
254
  return {
@@ -190,7 +258,7 @@ async function requestDaemon(message, sender) {
190
258
  }
191
259
  const payload = message.body && typeof message.body === "object" ? { ...message.body } : {};
192
260
  const tabId = sender.tab && sender.tab.id;
193
- if (method === "POST" && !payload.target && Number.isInteger(tabId)) {
261
+ if (method === "POST" && Number.isInteger(tabId)) {
194
262
  payload.target = "tab:" + tabId;
195
263
  }
196
264
  const host = config.host || "127.0.0.1";
@@ -240,6 +308,25 @@ async function focusSenderTab(sender) {
240
308
  }
241
309
 
242
310
  chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
311
+ if (message && message.type === "pcbridge:siteStatus") {
312
+ siteStatus(sender.tab?.url || message.url).then(sendResponse);
313
+ return true;
314
+ }
315
+ if (message && message.type === "pcbridge:setSite" && !sender.tab) {
316
+ (async () => {
317
+ const origin = siteOrigin(message.url);
318
+ if (!origin || builtinSite(message.url)) throw new Error("This site cannot be changed.");
319
+ if (message.enabled && !(await chrome.permissions.contains({ origins: [origin] }))) throw new Error("Site permission is required.");
320
+ const sites = await readObject(chrome.storage.local, SITES_KEY);
321
+ if (message.enabled) sites[origin] = true;
322
+ else delete sites[origin];
323
+ await chrome.storage.local.set({ [SITES_KEY]: sites });
324
+ await reconcileSites();
325
+ return siteStatus(message.url);
326
+ })().then(sendResponse).catch(error => sendResponse({ error: String(error) }));
327
+ return true;
328
+ }
329
+
243
330
  if (message && message.type === "pcbridge:getTabInfo") {
244
331
  sendResponse({
245
332
  tabId: sender.tab && sender.tab.id,
@@ -260,6 +347,32 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
260
347
  return true;
261
348
  }
262
349
 
350
+ if (message && message.type === "pcbridge:reloadExtension") {
351
+ const reloadTabs = message.reloadTabs !== false;
352
+ (async () => {
353
+ if (chrome.storage && chrome.storage.local) {
354
+ await chrome.storage.local.set({
355
+ [PENDING_RELOAD_KEY]: { reloadTabs, requestedAt: Date.now() }
356
+ });
357
+ }
358
+ setTimeout(() => {
359
+ if (chrome.runtime && typeof chrome.runtime.reload === "function") {
360
+ chrome.runtime.reload();
361
+ }
362
+ }, 50);
363
+ return { ok: true, reloading: true, reloadTabs };
364
+ })()
365
+ .then(sendResponse)
366
+ .catch((error) => sendResponse({ ok: false, error: String(error) }));
367
+ return true;
368
+ }
369
+
370
+ if (message && message.type === "pcbridge:syncUpdateBadge") {
371
+ syncUpdateBadge(message.updates || null);
372
+ sendResponse({ ok: true });
373
+ return true;
374
+ }
375
+
263
376
  if (message && message.type === "pcbridge:probeDaemon") {
264
377
  loadConfig()
265
378
  .then(async (config) => {
@@ -267,9 +380,15 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
267
380
  const host = config.host || "127.0.0.1";
268
381
  const port = config.port || 17329;
269
382
  try {
270
- const response = await fetch(`http://${host}:${port}/health`, {
383
+ const response = await fetch(`http://${host}:${port}/status`, {
271
384
  headers: { "X-PCBridge-Token": config.token }
272
385
  });
386
+ if (response.ok) {
387
+ const envelope = await response.json().catch(() => null);
388
+ if (envelope && envelope.ok && envelope.data && envelope.data.updates) {
389
+ syncUpdateBadge(envelope.data.updates);
390
+ }
391
+ }
273
392
  return { reachable: response.ok };
274
393
  } catch {
275
394
  return { reachable: false };
@@ -284,6 +403,33 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
284
403
  return true;
285
404
  }
286
405
 
406
+ if (message && message.type === "pcbridge:getWorkspaceSettings") {
407
+ readObject(chrome.storage && chrome.storage.local, WORKSPACE_SETTINGS_KEY)
408
+ .then((stored) => sendResponse({
409
+ ok: true,
410
+ eagerMaxMb: clampEagerMaxMb(stored.eagerMaxMb),
411
+ pendingDaemonSync: Boolean(stored.pendingDaemonSync)
412
+ }))
413
+ .catch(() => sendResponse({ ok: false, eagerMaxMb: 2, pendingDaemonSync: false }));
414
+ return true;
415
+ }
416
+
417
+ if (message && message.type === "pcbridge:setWorkspaceSettings") {
418
+ const eagerMaxMb = clampEagerMaxMb(message.eagerMaxMb);
419
+ const pendingDaemonSync = Boolean(message.pendingDaemonSync);
420
+ (async () => {
421
+ if (chrome.storage && chrome.storage.local) {
422
+ await chrome.storage.local.set({
423
+ [WORKSPACE_SETTINGS_KEY]: { eagerMaxMb, pendingDaemonSync }
424
+ });
425
+ }
426
+ return { ok: true, eagerMaxMb, pendingDaemonSync };
427
+ })()
428
+ .then(sendResponse)
429
+ .catch(() => sendResponse({ ok: false, eagerMaxMb, pendingDaemonSync }));
430
+ return true;
431
+ }
432
+
287
433
  if (message && message.type === "pcbridge:getFrontendPreference") {
288
434
  getFrontendPreference({
289
435
  url: message.url || (sender.tab && sender.tab.url),
@@ -345,3 +491,74 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
345
491
  chrome.tabs.onRemoved.addListener((tabId) => {
346
492
  void forgetTabProject(tabId);
347
493
  });
494
+
495
+ // Registered scripts are reconciled with permissions on startup and revocation.
496
+ const SITES_KEY = "pcbridgeSites";
497
+ function siteOrigin(value) {
498
+ try {
499
+ const url = new URL(value);
500
+ if (!["http:", "https:"].includes(url.protocol)) return null;
501
+ return `${url.protocol}//${url.hostname}/*`;
502
+ } catch { return null; }
503
+ }
504
+ function builtinSite(value) {
505
+ try {
506
+ return [
507
+ "playcanvas.com",
508
+ "launch.playcanvas.com",
509
+ "pc-editor.sightp.com",
510
+ "pc-launch.sightp.com",
511
+ "localhost",
512
+ "127.0.0.1"
513
+ ].includes(new URL(value).hostname);
514
+ }
515
+ catch { return false; }
516
+ }
517
+ async function siteStatus(value) {
518
+ const origin = siteOrigin(value);
519
+ if (!origin) return { enabled: false, builtin: false, origin: null };
520
+ const builtin = builtinSite(value);
521
+ if (builtin) return { enabled: true, builtin, origin };
522
+ const sites = await readObject(chrome.storage.local, SITES_KEY);
523
+ const permitted = await chrome.permissions.contains({ origins: [origin] });
524
+ return { enabled: sites[origin] === true && permitted, builtin, origin };
525
+ }
526
+ let reconcileQueue = Promise.resolve();
527
+ function reconcileSites() {
528
+ reconcileQueue = reconcileQueue.catch(() => {}).then(async () => {
529
+ const sites = await readObject(chrome.storage.local, SITES_KEY);
530
+ const registered = await chrome.scripting.getRegisteredContentScripts();
531
+ const obsolete = registered.filter(s => s.id.startsWith("pcbridge-site-"));
532
+ if (obsolete.length) await chrome.scripting.unregisterContentScripts({ ids: obsolete.map(s => s.id) });
533
+ const scripts = [];
534
+ for (const [origin, enabled] of Object.entries(sites)) {
535
+ if (!enabled || !(await chrome.permissions.contains({ origins: [origin] }))) continue;
536
+ const prefix = `pcbridge-site-${scripts.length}`;
537
+ for (const world of ["MAIN", "ISOLATED"]) scripts.push({
538
+ id: `${prefix}-${world.toLowerCase()}`, matches: [origin],
539
+ js: [world === "MAIN" ? "main.js" : "isolated.js"], world,
540
+ runAt: "document_start", persistAcrossSessions: true
541
+ });
542
+ }
543
+ if (scripts.length) await chrome.scripting.registerContentScripts(scripts);
544
+ for (const tab of await chrome.tabs.query({})) {
545
+ if (!tab.url || (await siteStatus(tab.url)).enabled) continue;
546
+ await chrome.tabs.sendMessage(tab.id, { type: "pcbridge:siteDisabled" }).catch(() => {});
547
+ }
548
+ });
549
+ return reconcileQueue;
550
+ }
551
+ if (chrome.permissions && chrome.scripting) {
552
+ chrome.permissions.onRemoved.addListener(() => { void reconcileSites(); });
553
+ chrome.runtime.onStartup.addListener(() => { void reconcileSites(); });
554
+ chrome.runtime.onInstalled.addListener(() => {
555
+ void reconcileSites();
556
+ });
557
+ void reconcileSites();
558
+ }
559
+ if (chrome.runtime && chrome.runtime.onInstalled) {
560
+ chrome.runtime.onInstalled.addListener(() => {
561
+ void consumePendingReload();
562
+ });
563
+ }
564
+ void consumePendingReload();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playcanvas-agent-bridge-cli",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "description": "CLI-first local bridge for automating open PlayCanvas Editor tabs from AI coding agents.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -19,17 +19,20 @@
19
19
  "files": [
20
20
  "dist",
21
21
  "extension",
22
+ "plugins",
22
23
  "skills",
23
24
  "README.md",
24
25
  "README.zh-CN.md",
25
26
  "LICENSE"
26
27
  ],
27
28
  "scripts": {
28
- "build": "tsc -p tsconfig.json && node -e \"require('fs').chmodSync('dist/cli.js', 0o755)\"",
29
+ "build": "tsc -p tsconfig.json && bun -e \"require('fs').chmodSync('dist/cli.js', 0o755)\"",
29
30
  "check": "tsc -p tsconfig.json --noEmit",
30
- "check:version": "node scripts/check-version.mjs",
31
- "test": "pnpm check:version && pnpm build && node --test",
32
- "prepare": "npm run build"
31
+ "check:version": "bun scripts/check-version.mjs",
32
+ "version:bump": "bun scripts/check-version.mjs --bump",
33
+ "plugins:sync": "bun scripts/check-version.mjs --sync-plugins",
34
+ "test": "bun run check:version && bun run build && bun test --timeout 30000 --isolate ./test",
35
+ "prepack": "bun run build"
33
36
  },
34
37
  "keywords": [
35
38
  "playcanvas",
@@ -39,27 +42,24 @@
39
42
  "agent"
40
43
  ],
41
44
  "engines": {
42
- "node": ">=20"
45
+ "bun": ">=1.4.0"
43
46
  },
44
47
  "publishConfig": {
45
48
  "access": "public",
46
49
  "registry": "https://registry.npmjs.org/"
47
50
  },
51
+ "workspaces": [
52
+ "plugins/*"
53
+ ],
48
54
  "dependencies": {
49
- "@aws-sdk/client-s3": "^3.1102.0",
50
- "@babel/core": "^7.28.4",
51
- "@babel/preset-env": "^7.28.3",
52
- "dotenv": "^17.4.2",
53
- "tar": "^7.5.22",
54
- "terser": "^5.50.0",
55
- "ws": "^8.18.3"
55
+ "sharp": "0.34.5",
56
+ "tar": "7.5.22",
57
+ "ws": "8.21.0"
56
58
  },
57
59
  "devDependencies": {
58
- "@types/babel__core": "^7.20.5",
59
- "@types/babel__preset-env": "^7.10.0",
60
- "@types/node": "^24.0.4",
61
- "@types/ws": "^8.18.1",
60
+ "@types/node": "24.13.2",
61
+ "@types/ws": "8.18.1",
62
62
  "typescript": "5.8.3"
63
63
  },
64
- "packageManager": "pnpm@11.1.0"
64
+ "packageManager": "bun@1.4.0"
65
65
  }
@@ -0,0 +1,14 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "plugins": [
4
+ {
5
+ "id": "tinyapp-builder",
6
+ "name": "Tiny Builder",
7
+ "version": "1.0.0",
8
+ "apiVersion": 1,
9
+ "minPcbridgeVersion": "0.7.0",
10
+ "description": "Build a PlayCanvas Template Asset into a TinyApp bundle and upload it to S3-compatible storage.",
11
+ "subdir": "plugins/tinyapp-builder"
12
+ }
13
+ ]
14
+ }