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
package/extension/popup.js
CHANGED
|
@@ -35,12 +35,13 @@ async function loadConfig() {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
async function loadStatus(config, tabId) {
|
|
38
|
+
async function loadStatus(config, tabId, refresh = false) {
|
|
39
39
|
if (!config || !config.token) return null;
|
|
40
40
|
try {
|
|
41
41
|
const host = config.host || "127.0.0.1";
|
|
42
42
|
const port = config.port || 17329;
|
|
43
|
-
const
|
|
43
|
+
const query = `tabId=${encodeURIComponent(tabId || "")}${refresh ? "&refresh=1" : ""}`;
|
|
44
|
+
const response = await fetch(`http://${host}:${port}/status?${query}`, {
|
|
44
45
|
headers: { "X-PCBridge-Token": config.token }
|
|
45
46
|
});
|
|
46
47
|
if (!response.ok) return null;
|
|
@@ -74,6 +75,185 @@ async function sendRuntimeMessage(message) {
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
|
|
78
|
+
async function pluginRequest(config, path, body) {
|
|
79
|
+
if (!config || !config.token) {
|
|
80
|
+
return { ok: false, error: { message: "pcbridge daemon configuration is unavailable." } };
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const response = await fetch(`http://${config.host || "127.0.0.1"}:${config.port || 17329}${path}`, {
|
|
84
|
+
method: body ? "POST" : "GET",
|
|
85
|
+
headers: {
|
|
86
|
+
"Content-Type": "application/json",
|
|
87
|
+
"X-PCBridge-Token": config.token
|
|
88
|
+
},
|
|
89
|
+
body: body ? JSON.stringify(body) : undefined
|
|
90
|
+
});
|
|
91
|
+
return await response.json();
|
|
92
|
+
} catch {
|
|
93
|
+
return { ok: false, error: { message: "pcbridge daemon is offline. Run pcbridge daemon start." } };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function element(tag, className, text) {
|
|
98
|
+
const node = document.createElement(tag);
|
|
99
|
+
if (className) node.className = className;
|
|
100
|
+
if (text !== undefined) node.textContent = text;
|
|
101
|
+
return node;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function setupPlugins(config) {
|
|
105
|
+
const view = document.getElementById("view-plugins");
|
|
106
|
+
const list = document.getElementById("plugin-list");
|
|
107
|
+
const available = document.getElementById("plugin-available");
|
|
108
|
+
const note = document.getElementById("plugin-note");
|
|
109
|
+
const source = document.getElementById("plugin-source");
|
|
110
|
+
const defaultNote = note.textContent;
|
|
111
|
+
const states = {
|
|
112
|
+
active: ["Active", "success"],
|
|
113
|
+
stopped: ["Stopped", "warning"],
|
|
114
|
+
disabled: ["Disabled", "neutral"],
|
|
115
|
+
error: ["Error", "danger"]
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
function showNote(message, isError) {
|
|
119
|
+
note.textContent = message || defaultNote;
|
|
120
|
+
note.classList.toggle("error", Boolean(isError));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function run(path, body, pending) {
|
|
124
|
+
showNote(pending, false);
|
|
125
|
+
view.inert = true;
|
|
126
|
+
const result = await pluginRequest(config, path, body);
|
|
127
|
+
view.inert = false;
|
|
128
|
+
await refresh();
|
|
129
|
+
if (!result.ok) showNote(result.error.message, true);
|
|
130
|
+
return result.ok;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function action(label, handler, primary) {
|
|
134
|
+
const button = element("button", primary ? "primary" : "", label);
|
|
135
|
+
button.type = "button";
|
|
136
|
+
button.addEventListener("click", handler);
|
|
137
|
+
return button;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function installedRow(plugin) {
|
|
141
|
+
const row = element("div", "plugin");
|
|
142
|
+
const head = element("div", "plugin-head");
|
|
143
|
+
const versionLabel = plugin.updateAvailable && plugin.latestVersion
|
|
144
|
+
? `v${plugin.version || "?"} → v${plugin.latestVersion}`
|
|
145
|
+
: plugin.version
|
|
146
|
+
? `v${plugin.version}`
|
|
147
|
+
: "";
|
|
148
|
+
head.append(element("strong", "", plugin.name), element("span", "mono", versionLabel));
|
|
149
|
+
const status = element("span", "status");
|
|
150
|
+
if (plugin.updateAvailable) {
|
|
151
|
+
setStatus(status, plugin.compatible === false ? "Needs pcbridge ↑" : "Update ↑", "warning");
|
|
152
|
+
} else {
|
|
153
|
+
setStatus(status, ...states[plugin.state]);
|
|
154
|
+
}
|
|
155
|
+
head.append(status);
|
|
156
|
+
row.append(head);
|
|
157
|
+
if (plugin.description) row.append(element("p", "", plugin.description));
|
|
158
|
+
const runtimes = Object.keys(plugin.runtimes).filter((name) => plugin.runtimes[name]);
|
|
159
|
+
row.append(element("p", "mono", [plugin.id, ...runtimes, plugin.source.type].join(" · ")));
|
|
160
|
+
if (plugin.updateAvailable && plugin.compatible === false && plugin.minPcbridgeVersion) {
|
|
161
|
+
row.append(element("p", "error", `v${plugin.latestVersion} requires pcbridge v${plugin.minPcbridgeVersion}+. Update pcbridge first.`));
|
|
162
|
+
}
|
|
163
|
+
if (plugin.error) row.append(element("p", "error", plugin.error));
|
|
164
|
+
for (const page of plugin.pages || []) {
|
|
165
|
+
if (!page.ok) row.append(element("p", "error", `${page.target}: ${page.error}`));
|
|
166
|
+
}
|
|
167
|
+
const actions = element("div", "plugin-actions");
|
|
168
|
+
if (plugin.updateAvailable && plugin.compatible !== false) {
|
|
169
|
+
actions.append(
|
|
170
|
+
action("Update", () => run(`/plugins/${plugin.id}/update`, {}, `Updating ${plugin.name}…`), true)
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
actions.append(
|
|
174
|
+
plugin.enabled
|
|
175
|
+
? action("Disable", () => run(`/plugins/${plugin.id}/disable`, {}, `Disabling ${plugin.name}…`))
|
|
176
|
+
: action("Enable", () => run(`/plugins/${plugin.id}/enable`, {}, `Enabling ${plugin.name}…`), !plugin.updateAvailable),
|
|
177
|
+
action("Remove", () => run(`/plugins/${plugin.id}/remove`, {}, `Removing ${plugin.name}…`))
|
|
178
|
+
);
|
|
179
|
+
row.append(actions);
|
|
180
|
+
return row;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function availableRow(plugin) {
|
|
184
|
+
const row = element("div", "plugin");
|
|
185
|
+
const head = element("div", "plugin-head");
|
|
186
|
+
head.append(element("strong", "", plugin.name), element("span", "mono", `v${plugin.version}`));
|
|
187
|
+
row.append(head);
|
|
188
|
+
if (plugin.description) row.append(element("p", "", plugin.description));
|
|
189
|
+
if (plugin.compatible === false && plugin.minPcbridgeVersion) {
|
|
190
|
+
row.append(element("p", "error", `Requires pcbridge v${plugin.minPcbridgeVersion}+`));
|
|
191
|
+
}
|
|
192
|
+
const actions = element("div", "plugin-actions");
|
|
193
|
+
const installBtn = action("Install", () => run("/plugins/add", { source: plugin.source }, `Installing ${plugin.name}…`), true);
|
|
194
|
+
installBtn.disabled = plugin.compatible === false;
|
|
195
|
+
actions.append(installBtn);
|
|
196
|
+
row.append(actions);
|
|
197
|
+
return row;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function refresh(forceRefresh = false) {
|
|
201
|
+
const result = await pluginRequest(config, `/plugins${forceRefresh ? "?refresh=1" : ""}`);
|
|
202
|
+
const count = document.getElementById("plugin-count");
|
|
203
|
+
const updateAllBtn = document.getElementById("plugin-update-all");
|
|
204
|
+
const pluginsTab = document.getElementById("tab-plugins");
|
|
205
|
+
const plugins = result.ok && result.data && Array.isArray(result.data.plugins) ? result.data.plugins : [];
|
|
206
|
+
const offered = result.ok && result.data && Array.isArray(result.data.available) ? result.data.available : [];
|
|
207
|
+
const updatable = plugins.filter((plugin) => plugin.updateAvailable && plugin.compatible !== false);
|
|
208
|
+
const anyUpdate = plugins.filter((plugin) => plugin.updateAvailable);
|
|
209
|
+
list.replaceChildren(...plugins.map(installedRow));
|
|
210
|
+
available.replaceChildren(...offered.map(availableRow));
|
|
211
|
+
document.getElementById("plugin-empty").hidden = !result.ok || plugins.length > 0;
|
|
212
|
+
document.getElementById("plugin-available-section").hidden = offered.length === 0;
|
|
213
|
+
document.getElementById("plugin-add").disabled = !result.ok;
|
|
214
|
+
updateAllBtn.hidden = updatable.length === 0;
|
|
215
|
+
pluginsTab.textContent = anyUpdate.length > 0 ? `Plugins · ${anyUpdate.length}↑` : "Plugins";
|
|
216
|
+
if (result.ok) {
|
|
217
|
+
const enabled = plugins.filter((plugin) => plugin.enabled).length;
|
|
218
|
+
setStatus(
|
|
219
|
+
count,
|
|
220
|
+
anyUpdate.length > 0 ? `${anyUpdate.length} update${anyUpdate.length === 1 ? "" : "s"}` : `${enabled} enabled`,
|
|
221
|
+
plugins.some((plugin) => plugin.state === "error")
|
|
222
|
+
? "danger"
|
|
223
|
+
: anyUpdate.length > 0
|
|
224
|
+
? "warning"
|
|
225
|
+
: enabled
|
|
226
|
+
? "success"
|
|
227
|
+
: "neutral"
|
|
228
|
+
);
|
|
229
|
+
showNote("", false);
|
|
230
|
+
} else {
|
|
231
|
+
setStatus(count, "Unavailable", "danger");
|
|
232
|
+
showNote(result.error.message, true);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
document.getElementById("plugin-update-all").addEventListener("click", async () => {
|
|
237
|
+
await run("/plugins/update-all", {}, "Updating plugins…");
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
document.getElementById("plugin-add").addEventListener("click", async () => {
|
|
241
|
+
const value = source.value.trim();
|
|
242
|
+
if (value && await run("/plugins/add", { source: value }, "Installing plugin…")) source.value = "";
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const tabs = { bridge: document.getElementById("tab-bridge"), plugins: document.getElementById("tab-plugins") };
|
|
246
|
+
for (const [name, tab] of Object.entries(tabs)) {
|
|
247
|
+
tab.addEventListener("click", () => {
|
|
248
|
+
for (const [other, button] of Object.entries(tabs)) {
|
|
249
|
+
button.setAttribute("aria-selected", String(other === name));
|
|
250
|
+
document.getElementById(`view-${other}`).hidden = other !== name;
|
|
251
|
+
}
|
|
252
|
+
if (name === "plugins") void refresh(true);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
77
257
|
function setStatus(element, label, state) {
|
|
78
258
|
element.textContent = label;
|
|
79
259
|
element.dataset.state = state;
|
|
@@ -145,6 +325,43 @@ function renderStatus(status, context) {
|
|
|
145
325
|
? `Extension v${extensionVersion} · Daemon v${status.daemon.version} · ${status.daemon.targetCount} target${status.daemon.targetCount === 1 ? "" : "s"}`
|
|
146
326
|
: `Extension v${extensionVersion} · Daemon unavailable`;
|
|
147
327
|
|
|
328
|
+
const updateBanner = document.getElementById("update-banner");
|
|
329
|
+
const updateStatus = document.getElementById("update-status");
|
|
330
|
+
const updateNote = document.getElementById("update-note");
|
|
331
|
+
const updateApply = document.getElementById("update-apply");
|
|
332
|
+
const updates = status && status.updates;
|
|
333
|
+
const coreUpdate = updates && updates.core;
|
|
334
|
+
const versionMismatch = Boolean(status && status.daemon && status.daemon.version !== extensionVersion);
|
|
335
|
+
const pluginUpdates = (updates && Array.isArray(updates.plugins)
|
|
336
|
+
? updates.plugins.filter((item) => item.updateAvailable)
|
|
337
|
+
: []);
|
|
338
|
+
const pluginsTab = document.getElementById("tab-plugins");
|
|
339
|
+
if (pluginsTab && updates && Array.isArray(updates.plugins)) {
|
|
340
|
+
pluginsTab.textContent = pluginUpdates.length > 0 ? `Plugins · ${pluginUpdates.length}↑` : "Plugins";
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (!context.updatingCore) {
|
|
344
|
+
if (coreUpdate && coreUpdate.updateAvailable) {
|
|
345
|
+
updateBanner.hidden = false;
|
|
346
|
+
setStatus(updateStatus, `v${coreUpdate.latestVersion}`, "warning");
|
|
347
|
+
updateNote.classList.toggle("error", false);
|
|
348
|
+
updateNote.textContent = coreUpdate.canSelfUpdate
|
|
349
|
+
? `pcbridge v${coreUpdate.currentVersion} → v${coreUpdate.latestVersion} is available. Updates CLI, daemon, extension, and refreshes PlayCanvas tabs.`
|
|
350
|
+
: `pcbridge v${coreUpdate.latestVersion} is on npm (running from source v${coreUpdate.currentVersion}). Pull git changes and rebuild.`;
|
|
351
|
+
updateApply.disabled = !coreUpdate.canSelfUpdate;
|
|
352
|
+
updateApply.textContent = "Update & Reload";
|
|
353
|
+
} else if (versionMismatch || (coreUpdate && (coreUpdate.daemonRestartRequired || coreUpdate.extensionReloadRequired))) {
|
|
354
|
+
updateBanner.hidden = false;
|
|
355
|
+
setStatus(updateStatus, "Out of sync", "warning");
|
|
356
|
+
updateNote.classList.toggle("error", false);
|
|
357
|
+
updateNote.textContent = `Extension v${extensionVersion} and Daemon v${status.daemon.version} are out of sync.`;
|
|
358
|
+
updateApply.disabled = false;
|
|
359
|
+
updateApply.textContent = "Sync & Reload";
|
|
360
|
+
} else {
|
|
361
|
+
updateBanner.hidden = true;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
148
365
|
if (!status) {
|
|
149
366
|
setStatus(overallStatus, "Offline", "danger");
|
|
150
367
|
setStatus(daemonStatus, "Disconnected", "danger");
|
|
@@ -295,9 +512,13 @@ async function main() {
|
|
|
295
512
|
siteStatus.textContent = site.enabled ? "Enabled. Refresh Editor / Launch to connect." : "Disabled. Existing connections closed.";
|
|
296
513
|
});
|
|
297
514
|
const config = await loadConfig();
|
|
515
|
+
setupPlugins(config);
|
|
298
516
|
const storedWorkspaceSettings = await sendRuntimeMessage({ type: "pcbridge:getWorkspaceSettings" });
|
|
299
517
|
let fallbackEagerMaxMb = clampEagerMaxMb(storedWorkspaceSettings && storedWorkspaceSettings.eagerMaxMb);
|
|
300
|
-
let status = await loadStatus(config, active && active.id);
|
|
518
|
+
let status = await loadStatus(config, active && active.id, true);
|
|
519
|
+
if (status && status.updates) {
|
|
520
|
+
void sendRuntimeMessage({ type: "pcbridge:syncUpdateBadge", updates: status.updates });
|
|
521
|
+
}
|
|
301
522
|
if (status && storedWorkspaceSettings && storedWorkspaceSettings.pendingDaemonSync) {
|
|
302
523
|
const synced = await updateDaemonWorkspaceSettings(config, fallbackEagerMaxMb);
|
|
303
524
|
if (synced) {
|
|
@@ -325,10 +546,39 @@ async function main() {
|
|
|
325
546
|
customMode,
|
|
326
547
|
rememberedMode: frontendPreference && frontendPreference.mode,
|
|
327
548
|
sliderActive: false,
|
|
328
|
-
fallbackEagerMaxMb
|
|
549
|
+
fallbackEagerMaxMb,
|
|
550
|
+
updatingCore: false
|
|
329
551
|
};
|
|
330
552
|
renderStatus(status, context);
|
|
331
553
|
|
|
554
|
+
const updateApply = document.getElementById("update-apply");
|
|
555
|
+
const updateReloadExt = document.getElementById("update-reload-ext");
|
|
556
|
+
const updateNote = document.getElementById("update-note");
|
|
557
|
+
updateReloadExt.addEventListener("click", async () => {
|
|
558
|
+
updateReloadExt.disabled = true;
|
|
559
|
+
await sendRuntimeMessage({ type: "pcbridge:reloadExtension", reloadTabs: true });
|
|
560
|
+
window.close();
|
|
561
|
+
});
|
|
562
|
+
updateApply.addEventListener("click", async () => {
|
|
563
|
+
context.updatingCore = true;
|
|
564
|
+
updateApply.disabled = true;
|
|
565
|
+
updateReloadExt.disabled = true;
|
|
566
|
+
updateNote.classList.toggle("error", false);
|
|
567
|
+
updateNote.textContent = "Updating pcbridge, extension, and skills…";
|
|
568
|
+
const res = await pluginRequest(config, "/update", { includePlugins: true, reloadTabs: true });
|
|
569
|
+
if (!res || !res.ok) {
|
|
570
|
+
context.updatingCore = false;
|
|
571
|
+
updateApply.disabled = false;
|
|
572
|
+
updateReloadExt.disabled = false;
|
|
573
|
+
updateNote.classList.toggle("error", true);
|
|
574
|
+
updateNote.textContent = (res && res.error && res.error.message) || "Update failed.";
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
updateNote.textContent = "Reloading extension and PlayCanvas tabs…";
|
|
578
|
+
await sendRuntimeMessage({ type: "pcbridge:reloadExtension", reloadTabs: true });
|
|
579
|
+
window.close();
|
|
580
|
+
});
|
|
581
|
+
|
|
332
582
|
const eagerLimit = document.getElementById("eager-limit");
|
|
333
583
|
const eagerLimitValue = document.getElementById("eager-limit-value");
|
|
334
584
|
eagerLimit.addEventListener("input", () => {
|
|
@@ -373,6 +623,9 @@ async function main() {
|
|
|
373
623
|
|
|
374
624
|
setInterval(async () => {
|
|
375
625
|
status = await loadStatus(config, active && active.id);
|
|
626
|
+
if (status && status.updates) {
|
|
627
|
+
void sendRuntimeMessage({ type: "pcbridge:syncUpdateBadge", updates: status.updates });
|
|
628
|
+
}
|
|
376
629
|
projectId = (status && status.target && status.target.projectId) || projectIdFromUrl(url);
|
|
377
630
|
renderStatus(status, context);
|
|
378
631
|
}, 1000);
|
|
@@ -2,8 +2,63 @@ const FRONTEND_PREFERENCES_KEY = "pcbridgeFrontendPreferences";
|
|
|
2
2
|
const SCENE_PROJECTS_KEY = "pcbridgeSceneProjects";
|
|
3
3
|
const TAB_PROJECTS_KEY = "pcbridgeTabProjects";
|
|
4
4
|
const WORKSPACE_SETTINGS_KEY = "pcbridgeWorkspaceSettings";
|
|
5
|
+
const PENDING_RELOAD_KEY = "pcbridgePendingReload";
|
|
5
6
|
const tabProjects = new Map();
|
|
6
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
|
+
|
|
7
62
|
function clampEagerMaxMb(value) {
|
|
8
63
|
const parsed = Number(value);
|
|
9
64
|
if (!Number.isFinite(parsed)) return 2;
|
|
@@ -180,11 +235,10 @@ async function requestDaemon(message, sender) {
|
|
|
180
235
|
const path = String(message.path || "");
|
|
181
236
|
const method = String(message.method || "GET").toUpperCase();
|
|
182
237
|
const allowed =
|
|
183
|
-
(path
|
|
238
|
+
(/^\/plugins\/[a-z0-9-]+\/actions\/[\w.-]+$/.test(path) && method === "POST") ||
|
|
184
239
|
(path === "/workspace/sync" && method === "POST") ||
|
|
185
240
|
(path === "/workspace/settings" && (method === "GET" || method === "POST")) ||
|
|
186
|
-
(/^\/processing\/(capabilities|begin|chunk|run|status|read|cancel|finish)$/.test(path) && method === "POST")
|
|
187
|
-
(/^\/builder\/jobs\/[^/]+$/.test(path) && method === "GET");
|
|
241
|
+
(/^\/processing\/(capabilities|begin|chunk|run|status|read|cancel|finish)$/.test(path) && method === "POST");
|
|
188
242
|
if (!allowed) {
|
|
189
243
|
return {
|
|
190
244
|
ok: false,
|
|
@@ -293,6 +347,32 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
|
293
347
|
return true;
|
|
294
348
|
}
|
|
295
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
|
+
|
|
296
376
|
if (message && message.type === "pcbridge:probeDaemon") {
|
|
297
377
|
loadConfig()
|
|
298
378
|
.then(async (config) => {
|
|
@@ -300,9 +380,15 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
|
|
300
380
|
const host = config.host || "127.0.0.1";
|
|
301
381
|
const port = config.port || 17329;
|
|
302
382
|
try {
|
|
303
|
-
const response = await fetch(`http://${host}:${port}/
|
|
383
|
+
const response = await fetch(`http://${host}:${port}/status`, {
|
|
304
384
|
headers: { "X-PCBridge-Token": config.token }
|
|
305
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
|
+
}
|
|
306
392
|
return { reachable: response.ok };
|
|
307
393
|
} catch {
|
|
308
394
|
return { reachable: false };
|
|
@@ -465,6 +551,14 @@ function reconcileSites() {
|
|
|
465
551
|
if (chrome.permissions && chrome.scripting) {
|
|
466
552
|
chrome.permissions.onRemoved.addListener(() => { void reconcileSites(); });
|
|
467
553
|
chrome.runtime.onStartup.addListener(() => { void reconcileSites(); });
|
|
468
|
-
chrome.runtime.onInstalled.addListener(() => {
|
|
554
|
+
chrome.runtime.onInstalled.addListener(() => {
|
|
555
|
+
void reconcileSites();
|
|
556
|
+
});
|
|
469
557
|
void reconcileSites();
|
|
470
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.
|
|
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,6 +19,7 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
21
21
|
"extension",
|
|
22
|
+
"plugins",
|
|
22
23
|
"skills",
|
|
23
24
|
"README.md",
|
|
24
25
|
"README.zh-CN.md",
|
|
@@ -28,6 +29,8 @@
|
|
|
28
29
|
"build": "tsc -p tsconfig.json && bun -e \"require('fs').chmodSync('dist/cli.js', 0o755)\"",
|
|
29
30
|
"check": "tsc -p tsconfig.json --noEmit",
|
|
30
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",
|
|
31
34
|
"test": "bun run check:version && bun run build && bun test --timeout 30000 --isolate ./test",
|
|
32
35
|
"prepack": "bun run build"
|
|
33
36
|
},
|
|
@@ -45,19 +48,15 @@
|
|
|
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
55
|
"sharp": "0.34.5",
|
|
54
56
|
"tar": "7.5.22",
|
|
55
|
-
"terser": "5.50.0",
|
|
56
57
|
"ws": "8.21.0"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
|
-
"@types/babel__core": "7.20.5",
|
|
60
|
-
"@types/babel__preset-env": "7.10.0",
|
|
61
60
|
"@types/node": "24.13.2",
|
|
62
61
|
"@types/ws": "8.18.1",
|
|
63
62
|
"typescript": "5.8.3"
|
|
@@ -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
|
+
}
|