playcanvas-agent-bridge-cli 0.6.0 → 0.6.2

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.
@@ -2,15 +2,27 @@
2
2
  "manifest_version": 3,
3
3
  "name": "PlayCanvas Agent Bridge",
4
4
  "description": "Connects open PlayCanvas Editor and Launch tabs to the local pcbridge daemon.",
5
- "version": "0.6.0",
6
- "permissions": ["activeTab", "storage"],
5
+ "version": "0.6.2",
6
+ "permissions": [
7
+ "activeTab",
8
+ "storage",
9
+ "scripting"
10
+ ],
7
11
  "host_permissions": [
8
12
  "http://playcanvas.com/*",
9
13
  "https://playcanvas.com/*",
10
14
  "http://127.0.0.1/*",
11
15
  "http://localhost/*",
12
16
  "ws://127.0.0.1/*",
13
- "ws://localhost/*"
17
+ "ws://localhost/*",
18
+ "http://launch.playcanvas.com/*",
19
+ "https://launch.playcanvas.com/*",
20
+ "http://pc-editor.sightp.com/*",
21
+ "https://pc-editor.sightp.com/*",
22
+ "http://pc-launch.sightp.com/*",
23
+ "https://pc-launch.sightp.com/*",
24
+ "https://localhost/*",
25
+ "https://127.0.0.1/*"
14
26
  ],
15
27
  "action": {
16
28
  "default_popup": "popup.html",
@@ -19,14 +31,16 @@
19
31
  "16": "icons/icon-16.png",
20
32
  "32": "icons/icon-32.png",
21
33
  "48": "icons/icon-48.png",
22
- "128": "icons/icon-128.png"
34
+ "128": "icons/icon-128.png",
35
+ "256": "icons/icon-256.png"
23
36
  }
24
37
  },
25
38
  "icons": {
26
39
  "16": "icons/icon-16.png",
27
40
  "32": "icons/icon-32.png",
28
41
  "48": "icons/icon-48.png",
29
- "128": "icons/icon-128.png"
42
+ "128": "icons/icon-128.png",
43
+ "256": "icons/icon-256.png"
30
44
  },
31
45
  "background": {
32
46
  "service_worker": "service-worker.js"
@@ -37,9 +51,25 @@
37
51
  "http://playcanvas.com/editor*",
38
52
  "https://playcanvas.com/editor*",
39
53
  "http://launch.playcanvas.com/*",
40
- "https://launch.playcanvas.com/*"
54
+ "https://launch.playcanvas.com/*",
55
+ "http://pc-editor.sightp.com/editor*",
56
+ "https://pc-editor.sightp.com/editor*",
57
+ "http://pc-editor.sightp.com/launch/*",
58
+ "https://pc-editor.sightp.com/launch/*",
59
+ "http://pc-launch.sightp.com/*",
60
+ "https://pc-launch.sightp.com/*",
61
+ "http://localhost/editor/*",
62
+ "http://localhost/launch/*",
63
+ "http://127.0.0.1/editor/*",
64
+ "http://127.0.0.1/launch/*",
65
+ "https://localhost/editor/*",
66
+ "https://localhost/launch/*",
67
+ "https://127.0.0.1/editor/*",
68
+ "https://127.0.0.1/launch/*"
69
+ ],
70
+ "js": [
71
+ "main.js"
41
72
  ],
42
- "js": ["main.js"],
43
73
  "world": "MAIN",
44
74
  "run_at": "document_start"
45
75
  },
@@ -48,14 +78,34 @@
48
78
  "http://playcanvas.com/editor*",
49
79
  "https://playcanvas.com/editor*",
50
80
  "http://launch.playcanvas.com/*",
51
- "https://launch.playcanvas.com/*"
81
+ "https://launch.playcanvas.com/*",
82
+ "http://pc-editor.sightp.com/editor*",
83
+ "https://pc-editor.sightp.com/editor*",
84
+ "http://pc-editor.sightp.com/launch/*",
85
+ "https://pc-editor.sightp.com/launch/*",
86
+ "http://pc-launch.sightp.com/*",
87
+ "https://pc-launch.sightp.com/*",
88
+ "http://localhost/editor/*",
89
+ "http://localhost/launch/*",
90
+ "http://127.0.0.1/editor/*",
91
+ "http://127.0.0.1/launch/*",
92
+ "https://localhost/editor/*",
93
+ "https://localhost/launch/*",
94
+ "https://127.0.0.1/editor/*",
95
+ "https://127.0.0.1/launch/*"
96
+ ],
97
+ "js": [
98
+ "isolated.js"
52
99
  ],
53
- "js": ["isolated.js"],
54
100
  "world": "ISOLATED",
55
101
  "run_at": "document_start"
56
102
  }
57
103
  ],
58
104
  "content_security_policy": {
59
105
  "extension_pages": "script-src 'self'; object-src 'self'; connect-src http://127.0.0.1:* ws://127.0.0.1:* http://localhost:* ws://localhost:*"
60
- }
106
+ },
107
+ "optional_host_permissions": [
108
+ "http://*/*",
109
+ "https://*/*"
110
+ ]
61
111
  }
@@ -45,7 +45,7 @@
45
45
  border-radius: 8px;
46
46
  display: block;
47
47
  height: 28px;
48
- object-fit: cover;
48
+ object-fit: contain;
49
49
  width: 28px;
50
50
  }
51
51
 
@@ -123,6 +123,24 @@
123
123
  .metric strong { display: block; font-size: 14px; }
124
124
  .metric span { color: var(--muted); display: block; font-size: 9px; margin-top: 2px; text-transform: uppercase; }
125
125
 
126
+ .slider-row { padding: 0 12px 10px; }
127
+ .slider-header { align-items: center; display: flex; justify-content: space-between; margin-bottom: 5px; }
128
+ .slider-header label { color: var(--muted); font-size: 11px; }
129
+ .slider-badge {
130
+ background: var(--surface-raised);
131
+ border: 1px solid var(--border);
132
+ border-radius: 6px;
133
+ color: var(--foreground);
134
+ padding: 1px 7px;
135
+ }
136
+ input[type="range"] {
137
+ accent-color: var(--accent);
138
+ cursor: pointer;
139
+ display: block;
140
+ margin: 0;
141
+ width: 100%;
142
+ }
143
+
126
144
  .note { color: var(--muted); margin: 0; padding: 0 12px 10px; }
127
145
  .note.error { color: var(--red); }
128
146
  .actions { display: grid; gap: 7px; grid-template-columns: 1fr 1fr; padding: 0 12px 12px; }
@@ -149,7 +167,7 @@
149
167
  <body>
150
168
  <header>
151
169
  <div class="brand">
152
- <img class="brand-mark" src="icons/icon-32.png" alt="" aria-hidden="true">
170
+ <img class="brand-mark" src="icons/icon-128.png" srcset="icons/icon-128.png 1x, icons/icon-256.png 2x" alt="" aria-hidden="true">
153
171
  <div>
154
172
  <h1>PlayCanvas Agent Bridge</h1>
155
173
  <div class="version" id="version">Loading</div>
@@ -187,6 +205,13 @@
187
205
  <div class="metric"><strong id="metric-lazy">—</strong><span>Lazy</span></div>
188
206
  <div class="metric"><strong id="metric-conflicts">—</strong><span>Conflicts</span></div>
189
207
  </div>
208
+ <div class="slider-row">
209
+ <div class="slider-header">
210
+ <label for="eager-limit">Direct sync limit</label>
211
+ <span class="mono slider-badge" id="eager-limit-value">2 MB</span>
212
+ </div>
213
+ <input id="eager-limit" type="range" min="1" max="10" step="1" value="2">
214
+ </div>
190
215
  <p class="note" id="workspace-note">Waiting for a ready Editor target.</p>
191
216
  </section>
192
217
 
@@ -200,11 +225,17 @@
200
225
  <dt>Mode</dt><dd id="mode">Unavailable</dd>
201
226
  <dt>Project preference</dt><dd id="frontend-preference">Unavailable</dd>
202
227
  </dl>
228
+ <p class="note" id="frontend-note" hidden></p>
203
229
  <div class="actions">
204
230
  <button id="use-custom" class="primary" type="button">Use custom</button>
205
231
  <button id="use-official" type="button">Use official</button>
206
232
  </div>
207
233
  </section>
234
+ <section aria-labelledby="site-title">
235
+ <h2 id="site-title">Site access</h2>
236
+ <p class="note" id="site-status">Checking site permission…</p>
237
+ <button id="site-toggle" type="button" disabled>Enable on this site</button>
238
+ </section>
208
239
  </main>
209
240
  <script src="popup.js"></script>
210
241
  </body>
@@ -1,3 +1,30 @@
1
+ function clampEagerMaxMb(value) {
2
+ const parsed = Number(value);
3
+ if (!Number.isFinite(parsed)) return 2;
4
+ return Math.min(10, Math.max(1, Math.round(parsed)));
5
+ }
6
+
7
+ async function updateDaemonWorkspaceSettings(config, eagerMaxMb) {
8
+ if (!config || !config.token) return null;
9
+ try {
10
+ const host = config.host || "127.0.0.1";
11
+ const port = config.port || 17329;
12
+ const response = await fetch(`http://${host}:${port}/workspace/settings`, {
13
+ method: "POST",
14
+ headers: {
15
+ "Content-Type": "application/json",
16
+ "X-PCBridge-Token": config.token
17
+ },
18
+ body: JSON.stringify({ eagerMaxMb })
19
+ });
20
+ if (!response.ok) return null;
21
+ const envelope = await response.json();
22
+ return envelope.ok ? envelope.data : null;
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
27
+
1
28
  async function loadConfig() {
2
29
  try {
3
30
  const response = await fetch(chrome.runtime.getURL("config.json"));
@@ -84,7 +111,7 @@ async function switchFrontend(active, url, custom, projectId) {
84
111
  }
85
112
 
86
113
  function renderStatus(status, context) {
87
- const { isEditor, isLaunch, customMode, rememberedMode } = context;
114
+ const { isEditor, isSelfhostEditor, isLaunch, customMode, rememberedMode, sliderActive, fallbackEagerMaxMb } = context;
88
115
  const target = status && status.target;
89
116
  const workspace = status && status.workspace;
90
117
  const frontend = status && status.frontend;
@@ -95,13 +122,28 @@ function renderStatus(status, context) {
95
122
  const frontendStatus = document.getElementById("frontend-status");
96
123
  const workspacePath = document.getElementById("workspace-path");
97
124
  const workspaceNote = document.getElementById("workspace-note");
125
+ const frontendNote = document.getElementById("frontend-note");
98
126
  const copyPath = document.getElementById("copy-path");
99
127
  const useCustom = document.getElementById("use-custom");
100
128
  const useOfficial = document.getElementById("use-official");
129
+ const eagerLimit = document.getElementById("eager-limit");
130
+ const eagerLimitValue = document.getElementById("eager-limit-value");
131
+
132
+ if (!sliderActive) {
133
+ const effectiveMb = clampEagerMaxMb(
134
+ (workspace && workspace.eagerMaxMb) ??
135
+ (status && status.daemon && status.daemon.eagerMaxMb) ??
136
+ fallbackEagerMaxMb ??
137
+ 2
138
+ );
139
+ eagerLimit.value = String(effectiveMb);
140
+ eagerLimitValue.textContent = `${effectiveMb} MB`;
141
+ }
101
142
 
143
+ const extensionVersion = chrome.runtime.getManifest().version;
102
144
  document.getElementById("version").textContent = status && status.daemon
103
- ? `v${status.daemon.version} · ${status.daemon.targetCount} target${status.daemon.targetCount === 1 ? "" : "s"}`
104
- : "Daemon unavailable";
145
+ ? `Extension v${extensionVersion} · Daemon v${status.daemon.version} · ${status.daemon.targetCount} target${status.daemon.targetCount === 1 ? "" : "s"}`
146
+ : `Extension v${extensionVersion} · Daemon unavailable`;
105
147
 
106
148
  if (!status) {
107
149
  setStatus(overallStatus, "Offline", "danger");
@@ -115,7 +157,7 @@ function renderStatus(status, context) {
115
157
 
116
158
  document.getElementById("target").textContent = target
117
159
  ? `${target.kind === "launch" ? "Launch" : "Editor"} · ${target.ready ? "Ready" : "Initializing"}`
118
- : isEditor || isLaunch
160
+ : isEditor || isSelfhostEditor || isLaunch
119
161
  ? "Not connected"
120
162
  : "Not a PlayCanvas tab";
121
163
  document.getElementById("project").textContent = target
@@ -182,11 +224,19 @@ function renderStatus(status, context) {
182
224
  : "Waiting for a ready Editor target.";
183
225
  }
184
226
 
185
- const serverReady = Boolean(frontend && frontend.ready && frontend.server && frontend.server.listening);
227
+ const customExpected = Boolean(isEditor && (customMode || rememberedMode === "custom"));
228
+ const frontendInstalled = Boolean(frontend && frontend.ready);
229
+ const serverReady = Boolean(frontendInstalled && frontend.server && frontend.server.listening);
186
230
  setStatus(
187
231
  frontendStatus,
188
- serverReady ? "Available" : frontend && frontend.ready ? "Server stopped" : "Not installed",
189
- serverReady ? "success" : frontend && frontend.ready ? "warning" : "neutral"
232
+ serverReady
233
+ ? "Available"
234
+ : !status
235
+ ? "Daemon offline"
236
+ : frontend && frontend.ready
237
+ ? "Server stopped"
238
+ : "Not installed",
239
+ serverReady ? "success" : customExpected ? "danger" : status && frontendInstalled ? "warning" : "neutral"
190
240
  );
191
241
  document.getElementById("frontend").textContent = frontend && frontend.activeRelease
192
242
  ? frontend.activeRelease
@@ -198,18 +248,67 @@ function renderStatus(status, context) {
198
248
  ? rememberedMode === "custom" ? "Custom · remembered" : "Official · remembered"
199
249
  : isEditor ? "Follow current URL" : "Unavailable";
200
250
 
201
- useCustom.disabled = !isEditor || !serverReady || rememberedMode === "custom" || (!rememberedMode && customMode);
202
- useOfficial.disabled = !isEditor || rememberedMode === "official" || (!rememberedMode && !customMode);
251
+ const note = !customExpected || serverReady
252
+ ? ""
253
+ : !status
254
+ ? "Custom frontend unavailable: pcbridge daemon is offline."
255
+ : !frontendInstalled
256
+ ? "Custom frontend unavailable: no active frontend release is installed."
257
+ : `Custom frontend unavailable: port ${frontend.server.port} is not listening.`;
258
+ frontendNote.textContent = note;
259
+ frontendNote.hidden = !note;
260
+ frontendNote.classList.toggle("error", Boolean(note));
261
+
262
+ useCustom.disabled = !isEditor || !serverReady || customMode;
263
+ useOfficial.disabled = !isEditor || !customMode;
203
264
  }
204
265
 
205
266
  async function main() {
206
267
  const [active] = await chrome.tabs.query({ active: true, currentWindow: true });
207
268
  const url = active && active.url ? new URL(active.url) : null;
208
269
  const isEditor = isEditorUrl(url);
209
- const isLaunch = Boolean(url && url.hostname === "launch.playcanvas.com");
270
+ const isSelfhostEditor = Boolean(
271
+ url &&
272
+ (url.protocol === "https:" || url.protocol === "http:") &&
273
+ /^\/editor(?:\/|$)/.test(url.pathname)
274
+ );
275
+ const isLaunch = Boolean(
276
+ url &&
277
+ (url.hostname === "launch.playcanvas.com" ||
278
+ url.hostname === "pc-launch.sightp.com" ||
279
+ /^\/launch\//.test(url.pathname))
280
+ );
210
281
  const customMode = Boolean(isEditor && url.searchParams.has("use_local_frontend"));
282
+ const site = await sendRuntimeMessage({ type: "pcbridge:siteStatus", url: url?.href });
283
+ const siteToggle = document.getElementById("site-toggle");
284
+ const siteStatus = document.getElementById("site-status");
285
+ siteStatus.textContent = site?.enabled ? "Enabled" : "Not enabled";
286
+ siteToggle.disabled = !site?.origin || site.builtin;
287
+ siteToggle.textContent = site?.enabled ? "Disable on this site" : "Enable on this site";
288
+ siteToggle.addEventListener("click", async () => {
289
+ const enabled = !site.enabled;
290
+ if (enabled && !(await chrome.permissions.request({ origins: [site.origin] }))) return;
291
+ const result = await sendRuntimeMessage({ type: "pcbridge:setSite", url: url.href, enabled });
292
+ if (!result || result.error) { siteStatus.textContent = result?.error || "Could not update site"; return; }
293
+ site.enabled = result.enabled;
294
+ siteToggle.textContent = site.enabled ? "Disable on this site" : "Enable on this site";
295
+ siteStatus.textContent = site.enabled ? "Enabled. Refresh Editor / Launch to connect." : "Disabled. Existing connections closed.";
296
+ });
211
297
  const config = await loadConfig();
298
+ const storedWorkspaceSettings = await sendRuntimeMessage({ type: "pcbridge:getWorkspaceSettings" });
299
+ let fallbackEagerMaxMb = clampEagerMaxMb(storedWorkspaceSettings && storedWorkspaceSettings.eagerMaxMb);
212
300
  let status = await loadStatus(config, active && active.id);
301
+ if (status && storedWorkspaceSettings && storedWorkspaceSettings.pendingDaemonSync) {
302
+ const synced = await updateDaemonWorkspaceSettings(config, fallbackEagerMaxMb);
303
+ if (synced) {
304
+ await sendRuntimeMessage({
305
+ type: "pcbridge:setWorkspaceSettings",
306
+ eagerMaxMb: fallbackEagerMaxMb,
307
+ pendingDaemonSync: false
308
+ });
309
+ status = await loadStatus(config, active && active.id);
310
+ }
311
+ }
213
312
  let projectId = (status && status.target && status.target.projectId) || projectIdFromUrl(url);
214
313
  const frontendPreference = isEditor
215
314
  ? await sendRuntimeMessage({
@@ -221,12 +320,44 @@ async function main() {
221
320
  : null;
222
321
  const context = {
223
322
  isEditor,
323
+ isSelfhostEditor,
224
324
  isLaunch,
225
325
  customMode,
226
- rememberedMode: frontendPreference && frontendPreference.mode
326
+ rememberedMode: frontendPreference && frontendPreference.mode,
327
+ sliderActive: false,
328
+ fallbackEagerMaxMb
227
329
  };
228
330
  renderStatus(status, context);
229
331
 
332
+ const eagerLimit = document.getElementById("eager-limit");
333
+ const eagerLimitValue = document.getElementById("eager-limit-value");
334
+ eagerLimit.addEventListener("input", () => {
335
+ context.sliderActive = true;
336
+ const mb = clampEagerMaxMb(eagerLimit.value);
337
+ context.fallbackEagerMaxMb = mb;
338
+ eagerLimitValue.textContent = `${mb} MB`;
339
+ });
340
+ eagerLimit.addEventListener("change", async () => {
341
+ const mb = clampEagerMaxMb(eagerLimit.value);
342
+ context.fallbackEagerMaxMb = mb;
343
+ eagerLimit.value = String(mb);
344
+ eagerLimitValue.textContent = `${mb} MB`;
345
+ try {
346
+ const updated = await updateDaemonWorkspaceSettings(config, mb);
347
+ await sendRuntimeMessage({
348
+ type: "pcbridge:setWorkspaceSettings",
349
+ eagerMaxMb: mb,
350
+ pendingDaemonSync: !updated
351
+ });
352
+ if (updated) {
353
+ status = await loadStatus(config, active && active.id);
354
+ }
355
+ } finally {
356
+ context.sliderActive = false;
357
+ renderStatus(status, context);
358
+ }
359
+ });
360
+
230
361
  const copyPath = document.getElementById("copy-path");
231
362
  const useCustom = document.getElementById("use-custom");
232
363
  const useOfficial = document.getElementById("use-official");
@@ -1,8 +1,15 @@
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";
4
5
  const tabProjects = new Map();
5
6
 
7
+ function clampEagerMaxMb(value) {
8
+ const parsed = Number(value);
9
+ if (!Number.isFinite(parsed)) return 2;
10
+ return Math.min(10, Math.max(1, Math.round(parsed)));
11
+ }
12
+
6
13
  function normalizeId(value) {
7
14
  const id = String(value || "").trim();
8
15
  return /^\d+$/.test(id) ? id : null;
@@ -84,6 +91,7 @@ async function getSceneProject(sceneId) {
84
91
 
85
92
  async function resolveProjectContext({ url, tabId, projectId, sceneId } = {}) {
86
93
  const parsed = parseEditorUrl(url);
94
+ if (!parsed) return { parsed: null, projectId: null, sceneId: null };
87
95
  const resolvedSceneId = normalizeId(sceneId) || (parsed && parsed.sceneId);
88
96
  let resolvedProjectId = normalizeId(projectId) || (parsed && parsed.projectId);
89
97
 
@@ -173,6 +181,9 @@ async function requestDaemon(message, sender) {
173
181
  const method = String(message.method || "GET").toUpperCase();
174
182
  const allowed =
175
183
  (path === "/builder/jobs" && method === "POST") ||
184
+ (path === "/workspace/sync" && method === "POST") ||
185
+ (path === "/workspace/settings" && (method === "GET" || method === "POST")) ||
186
+ (/^\/processing\/(capabilities|begin|chunk|run|status|read|cancel|finish)$/.test(path) && method === "POST") ||
176
187
  (/^\/builder\/jobs\/[^/]+$/.test(path) && method === "GET");
177
188
  if (!allowed) {
178
189
  return {
@@ -181,6 +192,9 @@ async function requestDaemon(message, sender) {
181
192
  };
182
193
  }
183
194
 
195
+ if (!sender.tab || !(await siteStatus(sender.tab.url)).enabled) {
196
+ return { ok: false, error: { code: "SITE_DISABLED", message: "Site is not enabled." } };
197
+ }
184
198
  const config = await loadConfig();
185
199
  if (!config.token) {
186
200
  return {
@@ -190,7 +204,7 @@ async function requestDaemon(message, sender) {
190
204
  }
191
205
  const payload = message.body && typeof message.body === "object" ? { ...message.body } : {};
192
206
  const tabId = sender.tab && sender.tab.id;
193
- if (method === "POST" && !payload.target && Number.isInteger(tabId)) {
207
+ if (method === "POST" && Number.isInteger(tabId)) {
194
208
  payload.target = "tab:" + tabId;
195
209
  }
196
210
  const host = config.host || "127.0.0.1";
@@ -240,6 +254,25 @@ async function focusSenderTab(sender) {
240
254
  }
241
255
 
242
256
  chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
257
+ if (message && message.type === "pcbridge:siteStatus") {
258
+ siteStatus(sender.tab?.url || message.url).then(sendResponse);
259
+ return true;
260
+ }
261
+ if (message && message.type === "pcbridge:setSite" && !sender.tab) {
262
+ (async () => {
263
+ const origin = siteOrigin(message.url);
264
+ if (!origin || builtinSite(message.url)) throw new Error("This site cannot be changed.");
265
+ if (message.enabled && !(await chrome.permissions.contains({ origins: [origin] }))) throw new Error("Site permission is required.");
266
+ const sites = await readObject(chrome.storage.local, SITES_KEY);
267
+ if (message.enabled) sites[origin] = true;
268
+ else delete sites[origin];
269
+ await chrome.storage.local.set({ [SITES_KEY]: sites });
270
+ await reconcileSites();
271
+ return siteStatus(message.url);
272
+ })().then(sendResponse).catch(error => sendResponse({ error: String(error) }));
273
+ return true;
274
+ }
275
+
243
276
  if (message && message.type === "pcbridge:getTabInfo") {
244
277
  sendResponse({
245
278
  tabId: sender.tab && sender.tab.id,
@@ -284,6 +317,33 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
284
317
  return true;
285
318
  }
286
319
 
320
+ if (message && message.type === "pcbridge:getWorkspaceSettings") {
321
+ readObject(chrome.storage && chrome.storage.local, WORKSPACE_SETTINGS_KEY)
322
+ .then((stored) => sendResponse({
323
+ ok: true,
324
+ eagerMaxMb: clampEagerMaxMb(stored.eagerMaxMb),
325
+ pendingDaemonSync: Boolean(stored.pendingDaemonSync)
326
+ }))
327
+ .catch(() => sendResponse({ ok: false, eagerMaxMb: 2, pendingDaemonSync: false }));
328
+ return true;
329
+ }
330
+
331
+ if (message && message.type === "pcbridge:setWorkspaceSettings") {
332
+ const eagerMaxMb = clampEagerMaxMb(message.eagerMaxMb);
333
+ const pendingDaemonSync = Boolean(message.pendingDaemonSync);
334
+ (async () => {
335
+ if (chrome.storage && chrome.storage.local) {
336
+ await chrome.storage.local.set({
337
+ [WORKSPACE_SETTINGS_KEY]: { eagerMaxMb, pendingDaemonSync }
338
+ });
339
+ }
340
+ return { ok: true, eagerMaxMb, pendingDaemonSync };
341
+ })()
342
+ .then(sendResponse)
343
+ .catch(() => sendResponse({ ok: false, eagerMaxMb, pendingDaemonSync }));
344
+ return true;
345
+ }
346
+
287
347
  if (message && message.type === "pcbridge:getFrontendPreference") {
288
348
  getFrontendPreference({
289
349
  url: message.url || (sender.tab && sender.tab.url),
@@ -345,3 +405,66 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
345
405
  chrome.tabs.onRemoved.addListener((tabId) => {
346
406
  void forgetTabProject(tabId);
347
407
  });
408
+
409
+ // Registered scripts are reconciled with permissions on startup and revocation.
410
+ const SITES_KEY = "pcbridgeSites";
411
+ function siteOrigin(value) {
412
+ try {
413
+ const url = new URL(value);
414
+ if (!["http:", "https:"].includes(url.protocol)) return null;
415
+ return `${url.protocol}//${url.hostname}/*`;
416
+ } catch { return null; }
417
+ }
418
+ function builtinSite(value) {
419
+ try {
420
+ return [
421
+ "playcanvas.com",
422
+ "launch.playcanvas.com",
423
+ "pc-editor.sightp.com",
424
+ "pc-launch.sightp.com",
425
+ "localhost",
426
+ "127.0.0.1"
427
+ ].includes(new URL(value).hostname);
428
+ }
429
+ catch { return false; }
430
+ }
431
+ async function siteStatus(value) {
432
+ const origin = siteOrigin(value);
433
+ if (!origin) return { enabled: false, builtin: false, origin: null };
434
+ const builtin = builtinSite(value);
435
+ if (builtin) return { enabled: true, builtin, origin };
436
+ const sites = await readObject(chrome.storage.local, SITES_KEY);
437
+ const permitted = await chrome.permissions.contains({ origins: [origin] });
438
+ return { enabled: sites[origin] === true && permitted, builtin, origin };
439
+ }
440
+ let reconcileQueue = Promise.resolve();
441
+ function reconcileSites() {
442
+ reconcileQueue = reconcileQueue.catch(() => {}).then(async () => {
443
+ const sites = await readObject(chrome.storage.local, SITES_KEY);
444
+ const registered = await chrome.scripting.getRegisteredContentScripts();
445
+ const obsolete = registered.filter(s => s.id.startsWith("pcbridge-site-"));
446
+ if (obsolete.length) await chrome.scripting.unregisterContentScripts({ ids: obsolete.map(s => s.id) });
447
+ const scripts = [];
448
+ for (const [origin, enabled] of Object.entries(sites)) {
449
+ if (!enabled || !(await chrome.permissions.contains({ origins: [origin] }))) continue;
450
+ const prefix = `pcbridge-site-${scripts.length}`;
451
+ for (const world of ["MAIN", "ISOLATED"]) scripts.push({
452
+ id: `${prefix}-${world.toLowerCase()}`, matches: [origin],
453
+ js: [world === "MAIN" ? "main.js" : "isolated.js"], world,
454
+ runAt: "document_start", persistAcrossSessions: true
455
+ });
456
+ }
457
+ if (scripts.length) await chrome.scripting.registerContentScripts(scripts);
458
+ for (const tab of await chrome.tabs.query({})) {
459
+ if (!tab.url || (await siteStatus(tab.url)).enabled) continue;
460
+ await chrome.tabs.sendMessage(tab.id, { type: "pcbridge:siteDisabled" }).catch(() => {});
461
+ }
462
+ });
463
+ return reconcileQueue;
464
+ }
465
+ if (chrome.permissions && chrome.scripting) {
466
+ chrome.permissions.onRemoved.addListener(() => { void reconcileSites(); });
467
+ chrome.runtime.onStartup.addListener(() => { void reconcileSites(); });
468
+ chrome.runtime.onInstalled.addListener(() => { void reconcileSites(); });
469
+ void reconcileSites();
470
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playcanvas-agent-bridge-cli",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
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",
@@ -25,11 +25,11 @@
25
25
  "LICENSE"
26
26
  ],
27
27
  "scripts": {
28
- "build": "tsc -p tsconfig.json && node -e \"require('fs').chmodSync('dist/cli.js', 0o755)\"",
28
+ "build": "tsc -p tsconfig.json && bun -e \"require('fs').chmodSync('dist/cli.js', 0o755)\"",
29
29
  "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"
30
+ "check:version": "bun scripts/check-version.mjs",
31
+ "test": "bun run check:version && bun run build && bun test --timeout 30000 --isolate ./test",
32
+ "prepack": "bun run build"
33
33
  },
34
34
  "keywords": [
35
35
  "playcanvas",
@@ -39,27 +39,28 @@
39
39
  "agent"
40
40
  ],
41
41
  "engines": {
42
- "node": ">=20"
42
+ "bun": ">=1.4.0"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public",
46
46
  "registry": "https://registry.npmjs.org/"
47
47
  },
48
48
  "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"
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
+ "sharp": "0.34.5",
54
+ "tar": "7.5.22",
55
+ "terser": "5.50.0",
56
+ "ws": "8.21.0"
56
57
  },
57
58
  "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",
59
+ "@types/babel__core": "7.20.5",
60
+ "@types/babel__preset-env": "7.10.0",
61
+ "@types/node": "24.13.2",
62
+ "@types/ws": "8.18.1",
62
63
  "typescript": "5.8.3"
63
64
  },
64
- "packageManager": "pnpm@11.1.0"
65
+ "packageManager": "bun@1.4.0"
65
66
  }