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.
- package/README.md +117 -33
- package/README.zh-CN.md +102 -31
- package/dist/builder/manager.js +25 -2
- package/dist/cli.js +326 -46
- package/dist/config.js +1 -1
- package/dist/daemon/server.js +150 -9
- package/dist/daemon/target-registry.js +3 -0
- package/dist/processing/manager.js +265 -0
- package/dist/processing/tools.js +97 -0
- package/dist/snippets.js +27 -0
- package/dist/workspace/json-sync.js +821 -0
- package/dist/workspace/manager.js +1973 -326
- package/extension/icons/icon-128.png +0 -0
- package/extension/icons/icon-16.png +0 -0
- package/extension/icons/icon-256.png +0 -0
- package/extension/icons/icon-32.png +0 -0
- package/extension/icons/icon-48.png +0 -0
- package/extension/isolated.js +48 -0
- package/extension/main.js +708 -39
- package/extension/manifest.json +60 -10
- package/extension/popup.html +33 -2
- package/extension/popup.js +142 -11
- package/extension/service-worker.js +124 -1
- package/package.json +19 -18
- package/skills/claude/playcanvas-agent-bridge-cli/SKILL.md +85 -30
- package/skills/codex/playcanvas-agent-bridge-cli/SKILL.md +70 -49
- package/skills/cursor/playcanvas-agent-bridge-cli.mdc +67 -28
- package/skills/windsurf/playcanvas-agent-bridge-cli.md +66 -28
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { activeTools, installTools, TOOLS_ROOT } from "./processing/tools.js";
|
|
2
3
|
import { spawn } from "node:child_process";
|
|
3
4
|
import { realpathSync } from "node:fs";
|
|
4
|
-
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
|
5
|
+
import { readFile, writeFile, mkdir, stat } from "node:fs/promises";
|
|
6
|
+
import { createConnection } from "node:net";
|
|
5
7
|
import { homedir } from "node:os";
|
|
6
8
|
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
9
|
import { fileURLToPath } from "node:url";
|
|
8
10
|
import { CONFIG_DIR, DEFAULT_FRONTEND_PORT, DEFAULT_HOST, DEFAULT_PORT, EXTENSION_INSTALL_DIR, VERSION, copyDir, findPackageRoot, readOrCreateSession, readSessionIfExists, } from "./config.js";
|
|
9
11
|
import { createDaemonServer } from "./daemon/server.js";
|
|
10
12
|
import { FrontendError, getFrontendStatus, installFrontend, listFrontends, removeFrontend, useFrontend, } from "./frontend/store.js";
|
|
11
|
-
import { assetDeleteSnippet, assetFolderEnsureSnippet, assetCreateManySnippet, assetGetSnippet, assetInstantiateTemplateSnippet, assetListSnippet, entityAddComponentsSnippet, entityAddComponentSnippet, entityAddScriptSnippet, entityCreateManySnippet, entityCreateSnippet, entityDeleteSnippet, entityDuplicateSnippet, entityGetSnippet, entityListSnippet, entityPatchManySnippet, entityPatchSnippet, entityReparentSnippet, entityRemoveComponentsSnippet, entityRemoveComponentSnippet, entitySetMaterialSnippet, materialCreateSnippet, materialPatchSnippet, sceneSettingsGetSnippet, sceneSettingsPatchSnippet, scriptCreateSnippet, scriptParseSnippet, scriptSetTextSnippet, scriptUpsertSnippet, storeDownloadSnippet, storeGetSnippet, storeSearchSnippet, templateApplySnippet, templateCreateSnippet, templateOverridesSnippet, } from "./snippets.js";
|
|
13
|
+
import { assetDeleteSnippet, assetFolderEnsureSnippet, assetCreateManySnippet, assetGetSnippet, assetInstantiateTemplateSnippet, assetListSnippet, entityAddComponentsSnippet, entityAddComponentSnippet, entityAddScriptSnippet, entityCreateManySnippet, entityCreateSnippet, entityDeleteSnippet, entityDuplicateSnippet, entityGetSnippet, entityListSnippet, entityPatchManySnippet, entityPatchSnippet, entityReparentSnippet, entityRemoveComponentsSnippet, entityRemoveComponentSnippet, entitySetMaterialSnippet, materialCreateSnippet, materialPatchSnippet, sceneSettingsGetSnippet, sceneManageSnippet, sceneSettingsPatchSnippet, scriptCreateSnippet, scriptParseSnippet, scriptSetTextSnippet, scriptUpsertSnippet, storeDownloadSnippet, storeGetSnippet, storeSearchSnippet, templateApplySnippet, templateCreateSnippet, templateOverridesSnippet, } from "./snippets.js";
|
|
12
14
|
import { fail, ok } from "./shared/protocol.js";
|
|
13
15
|
function parseArgs(argv) {
|
|
14
16
|
const parsed = { _: [], flags: {} };
|
|
@@ -284,6 +286,8 @@ function listEnvelope(raw) {
|
|
|
284
286
|
}
|
|
285
287
|
function inferAssetType(path) {
|
|
286
288
|
const ext = extname(path).toLowerCase();
|
|
289
|
+
if ([".glb", ".fbx", ".obj"].includes(ext))
|
|
290
|
+
return "scene";
|
|
287
291
|
if ([".png", ".jpg", ".jpeg", ".webp", ".gif", ".bmp", ".tga"].includes(ext))
|
|
288
292
|
return "texture";
|
|
289
293
|
if ([".mp3", ".wav", ".ogg", ".m4a"].includes(ext))
|
|
@@ -380,18 +384,22 @@ async function uploadAsset(args, spec) {
|
|
|
380
384
|
preload: spec.preload !== false,
|
|
381
385
|
}, 120000);
|
|
382
386
|
}
|
|
387
|
+
function bunVersionSupported(version) {
|
|
388
|
+
const [major, minor] = version.split(".").map(Number);
|
|
389
|
+
return major > 1 || (major === 1 && minor >= 4);
|
|
390
|
+
}
|
|
383
391
|
async function doctor() {
|
|
384
392
|
const session = await readSessionIfExists();
|
|
385
393
|
const checks = [];
|
|
386
394
|
const nextActions = [];
|
|
387
|
-
const
|
|
395
|
+
const bunVersion = process.versions.bun;
|
|
388
396
|
let daemonOk = false;
|
|
389
397
|
let connectedExtensionVersionsOk = true;
|
|
390
398
|
checks.push({
|
|
391
|
-
name: "
|
|
392
|
-
ok:
|
|
393
|
-
version: process.version,
|
|
394
|
-
message:
|
|
399
|
+
name: "bun",
|
|
400
|
+
ok: !!bunVersion && bunVersionSupported(bunVersion),
|
|
401
|
+
version: bunVersion || process.version,
|
|
402
|
+
message: bunVersion && bunVersionSupported(bunVersion) ? "Bun version is supported." : "Bun 1.4.0 or newer is required.",
|
|
395
403
|
});
|
|
396
404
|
if (!session) {
|
|
397
405
|
nextActions.push("Run pcbridge install-extension to create a local session token.");
|
|
@@ -504,7 +512,7 @@ async function doctor() {
|
|
|
504
512
|
}
|
|
505
513
|
return ok({
|
|
506
514
|
version: VERSION,
|
|
507
|
-
healthy:
|
|
515
|
+
healthy: !!bunVersion && bunVersionSupported(bunVersion) &&
|
|
508
516
|
daemonOk &&
|
|
509
517
|
extensionExists &&
|
|
510
518
|
generatedExtensionVersion === VERSION &&
|
|
@@ -523,40 +531,182 @@ async function pathExists(path) {
|
|
|
523
531
|
return false;
|
|
524
532
|
}
|
|
525
533
|
}
|
|
534
|
+
async function resolveDaemonWorkspace(args) {
|
|
535
|
+
const hasWorkspace = Object.prototype.hasOwnProperty.call(args.flags, "workspace");
|
|
536
|
+
const requested = flagString(args, "workspace")?.trim();
|
|
537
|
+
if (hasWorkspace && !requested) {
|
|
538
|
+
throw new Error("daemon --workspace requires a directory.");
|
|
539
|
+
}
|
|
540
|
+
const workspaceRoot = resolve(requested || process.cwd());
|
|
541
|
+
let info;
|
|
542
|
+
try {
|
|
543
|
+
info = await stat(workspaceRoot);
|
|
544
|
+
}
|
|
545
|
+
catch {
|
|
546
|
+
throw new Error(`Daemon workspace does not exist: ${workspaceRoot}`);
|
|
547
|
+
}
|
|
548
|
+
if (!info.isDirectory()) {
|
|
549
|
+
throw new Error(`Daemon workspace is not a directory: ${workspaceRoot}`);
|
|
550
|
+
}
|
|
551
|
+
return workspaceRoot;
|
|
552
|
+
}
|
|
553
|
+
function daemonLog(args, message) {
|
|
554
|
+
if (flagBool(args, "json")) {
|
|
555
|
+
process.stderr.write(`${JSON.stringify({ time: new Date().toISOString(), message })}\n`);
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
process.stderr.write(`[pcbridge] ${message}\n`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
async function runDaemon(args, workspaceRoot, restarted) {
|
|
562
|
+
const session = await readOrCreateSession();
|
|
563
|
+
const port = session.port || DEFAULT_PORT;
|
|
564
|
+
const server = createDaemonServer({
|
|
565
|
+
host: DEFAULT_HOST,
|
|
566
|
+
port,
|
|
567
|
+
token: session.token,
|
|
568
|
+
workspaceRoot,
|
|
569
|
+
log: (message) => daemonLog(args, message),
|
|
570
|
+
});
|
|
571
|
+
try {
|
|
572
|
+
await server.listen();
|
|
573
|
+
}
|
|
574
|
+
catch (error) {
|
|
575
|
+
print(fail("PORT_BUSY", `Cannot listen on ${DEFAULT_HOST}:${port}. ${String(error)}`));
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
const handleSignal = (signal) => {
|
|
579
|
+
daemonLog(args, `received ${signal}; stopping daemon`);
|
|
580
|
+
void server.close().catch((error) => {
|
|
581
|
+
daemonLog(args, `daemon shutdown failed: ${String(error)}`);
|
|
582
|
+
process.exitCode = 1;
|
|
583
|
+
});
|
|
584
|
+
};
|
|
585
|
+
const handleSigint = () => handleSignal("SIGINT");
|
|
586
|
+
const handleSigterm = () => handleSignal("SIGTERM");
|
|
587
|
+
process.once("SIGINT", handleSigint);
|
|
588
|
+
process.once("SIGTERM", handleSigterm);
|
|
589
|
+
print(ok({
|
|
590
|
+
version: VERSION,
|
|
591
|
+
host: DEFAULT_HOST,
|
|
592
|
+
port,
|
|
593
|
+
workspaceRoot,
|
|
594
|
+
restarted,
|
|
595
|
+
extensionPath: EXTENSION_INSTALL_DIR,
|
|
596
|
+
frontend: await server.frontend.status(),
|
|
597
|
+
}));
|
|
598
|
+
try {
|
|
599
|
+
await server.closed;
|
|
600
|
+
}
|
|
601
|
+
finally {
|
|
602
|
+
process.off("SIGINT", handleSigint);
|
|
603
|
+
process.off("SIGTERM", handleSigterm);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
function isPortListening(port) {
|
|
607
|
+
return new Promise((resolveListening) => {
|
|
608
|
+
const socket = createConnection({ host: DEFAULT_HOST, port });
|
|
609
|
+
let settled = false;
|
|
610
|
+
const finish = (listening) => {
|
|
611
|
+
if (settled)
|
|
612
|
+
return;
|
|
613
|
+
settled = true;
|
|
614
|
+
socket.destroy();
|
|
615
|
+
resolveListening(listening);
|
|
616
|
+
};
|
|
617
|
+
socket.setTimeout(500);
|
|
618
|
+
socket.once("connect", () => finish(true));
|
|
619
|
+
socket.once("error", () => finish(false));
|
|
620
|
+
socket.once("timeout", () => finish(true));
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
async function waitForPortRelease(port, timeoutMs = 10000) {
|
|
624
|
+
const deadline = Date.now() + timeoutMs;
|
|
625
|
+
while (Date.now() < deadline) {
|
|
626
|
+
if (!await isPortListening(port))
|
|
627
|
+
return true;
|
|
628
|
+
await new Promise((resolveWait) => setTimeout(resolveWait, 50));
|
|
629
|
+
}
|
|
630
|
+
return !await isPortListening(port);
|
|
631
|
+
}
|
|
632
|
+
async function stopDaemon() {
|
|
633
|
+
const session = await readOrCreateSession();
|
|
634
|
+
const port = session.port || DEFAULT_PORT;
|
|
635
|
+
let health;
|
|
636
|
+
try {
|
|
637
|
+
health = await fetchDaemon("/health");
|
|
638
|
+
}
|
|
639
|
+
catch (error) {
|
|
640
|
+
if (error instanceof DaemonConnectionError &&
|
|
641
|
+
error.diagnosis.code === "DAEMON_NOT_LISTENING") {
|
|
642
|
+
return ok({ stopped: false, alreadyStopped: true, host: DEFAULT_HOST, port });
|
|
643
|
+
}
|
|
644
|
+
if (error instanceof DaemonConnectionError) {
|
|
645
|
+
return fail(error.diagnosis.code, error.diagnosis.message, undefined, { nextAction: error.diagnosis.nextAction });
|
|
646
|
+
}
|
|
647
|
+
return fail("DAEMON_UNREACHABLE", String(error));
|
|
648
|
+
}
|
|
649
|
+
if (!health.ok) {
|
|
650
|
+
if (health.error.code === "DAEMON_INVALID_RESPONSE") {
|
|
651
|
+
return fail("NOT_PCBRIDGE_DAEMON", `The listener on ${DEFAULT_HOST}:${port} is not a pcbridge daemon; it was not stopped.`);
|
|
652
|
+
}
|
|
653
|
+
return health;
|
|
654
|
+
}
|
|
655
|
+
const healthData = health.data && typeof health.data === "object" && !Array.isArray(health.data)
|
|
656
|
+
? health.data
|
|
657
|
+
: {};
|
|
658
|
+
if (healthData.service !== "pcbridge-daemon") {
|
|
659
|
+
if (typeof healthData.version === "string" && typeof healthData.workspaceRoot === "string") {
|
|
660
|
+
return fail("DAEMON_SHUTDOWN_UNSUPPORTED", "The running pcbridge daemon does not support authenticated shutdown. Stop it once with Ctrl+C, then start the updated daemon.");
|
|
661
|
+
}
|
|
662
|
+
return fail("NOT_PCBRIDGE_DAEMON", `The listener on ${DEFAULT_HOST}:${port} is not a restartable pcbridge daemon; it was not stopped.`);
|
|
663
|
+
}
|
|
664
|
+
let response;
|
|
665
|
+
try {
|
|
666
|
+
response = await fetchDaemon("/shutdown", { method: "POST" });
|
|
667
|
+
}
|
|
668
|
+
catch (error) {
|
|
669
|
+
if (error instanceof DaemonConnectionError) {
|
|
670
|
+
return fail(error.diagnosis.code, error.diagnosis.message);
|
|
671
|
+
}
|
|
672
|
+
return fail("DAEMON_STOP_FAILED", String(error));
|
|
673
|
+
}
|
|
674
|
+
if (!response.ok)
|
|
675
|
+
return response;
|
|
676
|
+
if (!await waitForPortRelease(port)) {
|
|
677
|
+
return fail("DAEMON_STOP_TIMEOUT", `pcbridge daemon accepted shutdown, but ${DEFAULT_HOST}:${port} is still occupied. No process was forcefully terminated.`);
|
|
678
|
+
}
|
|
679
|
+
return ok({
|
|
680
|
+
stopped: true,
|
|
681
|
+
alreadyStopped: false,
|
|
682
|
+
host: DEFAULT_HOST,
|
|
683
|
+
port,
|
|
684
|
+
previousVersion: healthData.version || null,
|
|
685
|
+
previousWorkspaceRoot: healthData.workspaceRoot || null,
|
|
686
|
+
});
|
|
687
|
+
}
|
|
526
688
|
async function daemon(args) {
|
|
527
689
|
const subcommand = args._[1] || "status";
|
|
528
|
-
if (subcommand === "start") {
|
|
529
|
-
|
|
530
|
-
const server = createDaemonServer({
|
|
531
|
-
host: DEFAULT_HOST,
|
|
532
|
-
port: session.port || DEFAULT_PORT,
|
|
533
|
-
token: session.token,
|
|
534
|
-
workspaceRoot: process.cwd(),
|
|
535
|
-
log: (message) => {
|
|
536
|
-
if (flagBool(args, "json")) {
|
|
537
|
-
process.stderr.write(`${JSON.stringify({ time: new Date().toISOString(), message })}\n`);
|
|
538
|
-
}
|
|
539
|
-
else {
|
|
540
|
-
process.stderr.write(`[pcbridge] ${message}\n`);
|
|
541
|
-
}
|
|
542
|
-
},
|
|
543
|
-
});
|
|
690
|
+
if (subcommand === "start" || subcommand === "restart") {
|
|
691
|
+
let workspaceRoot;
|
|
544
692
|
try {
|
|
545
|
-
await
|
|
693
|
+
workspaceRoot = await resolveDaemonWorkspace(args);
|
|
546
694
|
}
|
|
547
695
|
catch (error) {
|
|
548
|
-
print(fail("
|
|
549
|
-
process.exitCode = 1;
|
|
696
|
+
print(fail("INVALID_WORKSPACE", String(error)));
|
|
550
697
|
return;
|
|
551
698
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
699
|
+
if (subcommand === "restart") {
|
|
700
|
+
const stopped = await stopDaemon();
|
|
701
|
+
if (!stopped.ok) {
|
|
702
|
+
print(stopped);
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
await runDaemon(args, workspaceRoot, subcommand === "restart");
|
|
707
|
+
}
|
|
708
|
+
else if (subcommand === "stop") {
|
|
709
|
+
print(await stopDaemon());
|
|
560
710
|
}
|
|
561
711
|
else if (subcommand === "status") {
|
|
562
712
|
try {
|
|
@@ -686,39 +836,49 @@ function openChromeExtensions() {
|
|
|
686
836
|
}
|
|
687
837
|
async function installSkill(args) {
|
|
688
838
|
const agent = flagString(args, "agent", "codex") || "codex";
|
|
839
|
+
const supportedAgents = new Set(["codex", "claude", "cursor", "windsurf"]);
|
|
840
|
+
if (agent !== "all" && !supportedAgents.has(agent)) {
|
|
841
|
+
return fail("UNKNOWN_AGENT", `Unsupported agent: ${agent}. Use codex, claude, cursor, windsurf, or all.`);
|
|
842
|
+
}
|
|
843
|
+
const hasCustomPath = Object.prototype.hasOwnProperty.call(args.flags, "path");
|
|
844
|
+
const customPath = flagString(args, "path")?.trim();
|
|
845
|
+
if (hasCustomPath && !customPath) {
|
|
846
|
+
return fail("INVALID_REQUEST", "install-skill --path requires a parent directory.");
|
|
847
|
+
}
|
|
848
|
+
if (customPath && agent === "all") {
|
|
849
|
+
return fail("INVALID_REQUEST", "install-skill --path requires one explicit agent, not --agent all.");
|
|
850
|
+
}
|
|
851
|
+
const customParent = customPath ? resolve(customPath) : null;
|
|
689
852
|
const root = await findPackageRoot();
|
|
690
853
|
const installed = [];
|
|
691
854
|
const agents = agent === "all" ? ["codex", "claude", "cursor", "windsurf"] : [agent];
|
|
692
855
|
for (const item of agents) {
|
|
693
856
|
if (item === "codex") {
|
|
694
|
-
const dest = join(process.env.CODEX_HOME || join(homedir(), ".codex"), "skills");
|
|
857
|
+
const dest = customParent || join(process.env.CODEX_HOME || join(homedir(), ".codex"), "skills");
|
|
695
858
|
const source = join(root, "skills", "codex", "playcanvas-agent-bridge-cli");
|
|
696
859
|
const target = join(dest, "playcanvas-agent-bridge-cli");
|
|
697
860
|
await copyDir(source, target, { clean: true });
|
|
698
861
|
installed.push({ agent: item, path: target });
|
|
699
862
|
}
|
|
700
863
|
else if (item === "claude") {
|
|
701
|
-
const target = join(homedir(), ".claude", "skills", "playcanvas-agent-bridge-cli");
|
|
864
|
+
const target = join(customParent || join(homedir(), ".claude", "skills"), "playcanvas-agent-bridge-cli");
|
|
702
865
|
await copyDir(join(root, "skills", "claude", "playcanvas-agent-bridge-cli"), target, {
|
|
703
866
|
clean: true,
|
|
704
867
|
});
|
|
705
868
|
installed.push({ agent: item, path: target });
|
|
706
869
|
}
|
|
707
870
|
else if (item === "cursor") {
|
|
708
|
-
const target = join(homedir(), ".cursor", "rules", "playcanvas-agent-bridge-cli.mdc");
|
|
871
|
+
const target = join(customParent || join(homedir(), ".cursor", "rules"), "playcanvas-agent-bridge-cli.mdc");
|
|
709
872
|
await mkdir(dirname(target), { recursive: true });
|
|
710
873
|
await writeFile(target, await readFile(join(root, "skills", "cursor", "playcanvas-agent-bridge-cli.mdc")));
|
|
711
874
|
installed.push({ agent: item, path: target });
|
|
712
875
|
}
|
|
713
876
|
else if (item === "windsurf") {
|
|
714
|
-
const target = join(homedir(), ".windsurf", "rules", "playcanvas-agent-bridge-cli.md");
|
|
877
|
+
const target = join(customParent || join(homedir(), ".windsurf", "rules"), "playcanvas-agent-bridge-cli.md");
|
|
715
878
|
await mkdir(dirname(target), { recursive: true });
|
|
716
879
|
await writeFile(target, await readFile(join(root, "skills", "windsurf", "playcanvas-agent-bridge-cli.md")));
|
|
717
880
|
installed.push({ agent: item, path: target });
|
|
718
881
|
}
|
|
719
|
-
else {
|
|
720
|
-
return fail("UNKNOWN_AGENT", `Unsupported agent: ${item}. Use codex, claude, cursor, windsurf, or all.`);
|
|
721
|
-
}
|
|
722
882
|
}
|
|
723
883
|
return ok(installed);
|
|
724
884
|
}
|
|
@@ -1188,6 +1348,15 @@ async function handleScript(args) {
|
|
|
1188
1348
|
}
|
|
1189
1349
|
async function handleScene(args) {
|
|
1190
1350
|
const subcommand = args._[1];
|
|
1351
|
+
if (["list", "create", "open"].includes(subcommand)) {
|
|
1352
|
+
const name = flagString(args, "name");
|
|
1353
|
+
const id = flagString(args, "id");
|
|
1354
|
+
if (subcommand === "create" && !name)
|
|
1355
|
+
return fail("INVALID_REQUEST", "scene create requires --name.");
|
|
1356
|
+
if (subcommand === "open" && !id)
|
|
1357
|
+
return fail("INVALID_REQUEST", "scene open requires --id.");
|
|
1358
|
+
return rpcEval(args, sceneManageSnippet(), { action: subcommand, name: name || null, id: id || null }, 60000);
|
|
1359
|
+
}
|
|
1191
1360
|
if (subcommand === "settings" && (args._[2] || "get") === "get") {
|
|
1192
1361
|
return rpcEval(args, sceneSettingsGetSnippet());
|
|
1193
1362
|
}
|
|
@@ -1398,9 +1567,24 @@ async function handleWorkspace(args) {
|
|
|
1398
1567
|
rootDirectory: data.rootDirectory || null,
|
|
1399
1568
|
projectDirectory: data.projectDirectory || null,
|
|
1400
1569
|
assetsDirectory: data.assetsDirectory || null,
|
|
1570
|
+
scenesDirectory: data.scenesDirectory || null,
|
|
1401
1571
|
tmpDirectory: data.tmpDirectory || null,
|
|
1402
1572
|
});
|
|
1403
1573
|
}
|
|
1574
|
+
if (subcommand === "settings") {
|
|
1575
|
+
const rawLimit = flagString(args, "eager-max-mb") || flagString(args, "limit-mb");
|
|
1576
|
+
if (!rawLimit) {
|
|
1577
|
+
return fetchDaemon("/workspace/settings");
|
|
1578
|
+
}
|
|
1579
|
+
const mb = Number(rawLimit);
|
|
1580
|
+
if (!Number.isFinite(mb) || mb < 1 || mb > 10) {
|
|
1581
|
+
return fail("INVALID_REQUEST", "workspace settings --eager-max-mb must be between 1 and 10.");
|
|
1582
|
+
}
|
|
1583
|
+
return fetchDaemon("/workspace/settings", {
|
|
1584
|
+
method: "POST",
|
|
1585
|
+
body: JSON.stringify({ eagerMaxMb: Math.round(mb) }),
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1404
1588
|
if (subcommand === "sync") {
|
|
1405
1589
|
return fetchDaemon("/workspace/sync", {
|
|
1406
1590
|
method: "POST",
|
|
@@ -1445,12 +1629,80 @@ async function handleBuilder(args) {
|
|
|
1445
1629
|
}
|
|
1446
1630
|
return fail("UNKNOWN_COMMAND", `Unknown builder command: ${subcommand}`);
|
|
1447
1631
|
}
|
|
1632
|
+
async function handleProcessing(args) {
|
|
1633
|
+
const action = args._[1] || "status";
|
|
1634
|
+
if (action === "install") {
|
|
1635
|
+
const source = args._[2];
|
|
1636
|
+
if (!source)
|
|
1637
|
+
return fail("INVALID_REQUEST", "processing install requires a trusted release manifest path or HTTPS URL.");
|
|
1638
|
+
return ok(await installTools(source));
|
|
1639
|
+
}
|
|
1640
|
+
if (action === "enable" || action === "disable") {
|
|
1641
|
+
await mkdir(TOOLS_ROOT, { recursive: true });
|
|
1642
|
+
if (action === "enable")
|
|
1643
|
+
await activeTools();
|
|
1644
|
+
const memoryMb = Number(flagString(args, "memory-mb", "1024"));
|
|
1645
|
+
const timeoutMs = Number(flagString(args, "timeout-ms", "600000"));
|
|
1646
|
+
if (!Number.isInteger(memoryMb) || memoryMb < 64 || memoryMb > 1024 || !Number.isInteger(timeoutMs) || timeoutMs < 1000 || timeoutMs > 600000)
|
|
1647
|
+
return fail("INVALID_REQUEST", "memory-mb must be 64..1024; timeout-ms must be 1000..600000.");
|
|
1648
|
+
const settings = { enabled: action === "enable", memoryBytes: memoryMb * 1024 * 1024, timeoutMs };
|
|
1649
|
+
await writeFile(join(TOOLS_ROOT, "settings.json"), JSON.stringify(settings));
|
|
1650
|
+
return ok(settings);
|
|
1651
|
+
}
|
|
1652
|
+
if (action === "status")
|
|
1653
|
+
return fetchDaemon("/processing/capabilities", { method: "POST", body: JSON.stringify({ target: flagString(args, "target", "current") }) });
|
|
1654
|
+
return fail("UNKNOWN_COMMAND", `Unknown processing command: ${action}`);
|
|
1655
|
+
}
|
|
1656
|
+
async function handleImportJob(args) {
|
|
1657
|
+
const action = args._[1] || "list";
|
|
1658
|
+
const id = flagString(args, "job");
|
|
1659
|
+
if (["status", "cancel", "retry", "wait"].includes(action) && !id)
|
|
1660
|
+
return fail("INVALID_REQUEST", "--job is required.");
|
|
1661
|
+
const params = { action, jobId: id || null };
|
|
1662
|
+
if (action === "submit") {
|
|
1663
|
+
const assetId = flagString(args, "asset");
|
|
1664
|
+
const kind = flagString(args, "kind", "model");
|
|
1665
|
+
if (!assetId || !["model", "texture"].includes(kind || ""))
|
|
1666
|
+
return fail("INVALID_REQUEST", "submit requires --asset and --kind model|texture.");
|
|
1667
|
+
params.assetId = assetId;
|
|
1668
|
+
params.kind = kind || "model";
|
|
1669
|
+
params.options = objectJson(await readJsonFlag(args, "json"), "import options");
|
|
1670
|
+
}
|
|
1671
|
+
if (action !== "wait")
|
|
1672
|
+
return rpcCall(args, "bridge:importJob", params);
|
|
1673
|
+
const timeout = readTimeoutMs(args, 120000);
|
|
1674
|
+
if (timeout === null)
|
|
1675
|
+
return invalidTimeoutEnvelope();
|
|
1676
|
+
const deadline = Date.now() + timeout;
|
|
1677
|
+
while (Date.now() < deadline) {
|
|
1678
|
+
const result = await rpcCall(args, "bridge:importJob", { action: "status", jobId: id }, 15000, false);
|
|
1679
|
+
if (!result.ok)
|
|
1680
|
+
return result;
|
|
1681
|
+
const job = result.data;
|
|
1682
|
+
if (["failed", "cancelled"].includes(String(job.status)))
|
|
1683
|
+
return fail("IMPORT_" + String(job.status).toUpperCase(), String(job.error || job.status), undefined, job);
|
|
1684
|
+
if (job.status === "complete") {
|
|
1685
|
+
let workspace = { state: "not-requested" };
|
|
1686
|
+
if (flagBool(args, "sync-workspace")) {
|
|
1687
|
+
const synced = await fetchDaemon("/workspace/sync", { method: "POST", body: JSON.stringify({ target: flagString(args, "target", "current") }) });
|
|
1688
|
+
if (!synced.ok)
|
|
1689
|
+
return synced;
|
|
1690
|
+
workspace = synced.data;
|
|
1691
|
+
}
|
|
1692
|
+
return ok({ job, published: true, workspace });
|
|
1693
|
+
}
|
|
1694
|
+
await new Promise(resolve => setTimeout(resolve, 500));
|
|
1695
|
+
}
|
|
1696
|
+
return fail("IMPORT_WAIT_TIMEOUT", "Task is still pending; query the same job before submitting another.");
|
|
1697
|
+
}
|
|
1448
1698
|
function help(group = "overview") {
|
|
1449
1699
|
const groups = {
|
|
1450
1700
|
overview: [
|
|
1451
1701
|
"pcbridge help core",
|
|
1452
1702
|
"pcbridge help workspace",
|
|
1453
1703
|
"pcbridge help builder",
|
|
1704
|
+
"pcbridge help processing",
|
|
1705
|
+
"pcbridge help import",
|
|
1454
1706
|
"pcbridge help frontend",
|
|
1455
1707
|
"pcbridge help target",
|
|
1456
1708
|
"pcbridge help entity",
|
|
@@ -1468,8 +1720,11 @@ function help(group = "overview") {
|
|
|
1468
1720
|
core: [
|
|
1469
1721
|
"pcbridge doctor",
|
|
1470
1722
|
"pcbridge install-extension",
|
|
1471
|
-
"pcbridge install-skill --agent codex|claude|cursor|windsurf|all",
|
|
1472
|
-
"
|
|
1723
|
+
"pcbridge install-skill --agent codex|claude|cursor|windsurf|all [--path <parent_directory>]",
|
|
1724
|
+
"--path is allowed only with one agent and appends the standard skill/rule name.",
|
|
1725
|
+
"pcbridge daemon start [--workspace <directory>]",
|
|
1726
|
+
"pcbridge daemon restart [--workspace <directory>]",
|
|
1727
|
+
"pcbridge daemon stop",
|
|
1473
1728
|
"pcbridge daemon status",
|
|
1474
1729
|
"pcbridge targets",
|
|
1475
1730
|
"pcbridge version",
|
|
@@ -1483,9 +1738,25 @@ function help(group = "overview") {
|
|
|
1483
1738
|
workspace: [
|
|
1484
1739
|
"pcbridge workspace status --target editor:<sceneId>",
|
|
1485
1740
|
"pcbridge workspace path --target editor:<sceneId>",
|
|
1741
|
+
"pcbridge workspace settings [--eager-max-mb <1..10>]",
|
|
1486
1742
|
"pcbridge workspace sync --target editor:<sceneId>",
|
|
1487
1743
|
"pcbridge workspace pull --target editor:<sceneId> --asset <assetId>",
|
|
1488
|
-
"
|
|
1744
|
+
"daemon start/restart uses --workspace when provided, otherwise the current directory.",
|
|
1745
|
+
],
|
|
1746
|
+
processing: [
|
|
1747
|
+
"pcbridge processing install <trusted-release.json-path-or-https-url>",
|
|
1748
|
+
"pcbridge processing enable [--memory-mb 1024] [--timeout-ms 600000]",
|
|
1749
|
+
"pcbridge processing disable",
|
|
1750
|
+
"pcbridge processing status --target editor:<sceneId>",
|
|
1751
|
+
"Selfhost only. Tools are opt-in; unavailable local compute falls back to server.",
|
|
1752
|
+
],
|
|
1753
|
+
import: [
|
|
1754
|
+
"pcbridge import submit --asset <source_asset_id> --kind model|texture [--json options.json] --target editor:<sceneId>",
|
|
1755
|
+
"pcbridge import list --target editor:<sceneId>",
|
|
1756
|
+
"pcbridge import status|cancel|retry --job <id> --target editor:<sceneId>",
|
|
1757
|
+
"pcbridge import wait --job <id> [--timeout-ms 120000] [--sync-workspace] --target editor:<sceneId>",
|
|
1758
|
+
"Complete means server publication. --sync-workspace separately waits for local metadata synchronization.",
|
|
1759
|
+
"New files use the existing asset upload command; model uploads create the same import jobs.",
|
|
1489
1760
|
],
|
|
1490
1761
|
builder: [
|
|
1491
1762
|
"pcbridge builder start --target editor:<sceneId> --asset <template_asset_id> [--suffix '-${time}'] [--prefix assets]",
|
|
@@ -1553,6 +1824,9 @@ function help(group = "overview") {
|
|
|
1553
1824
|
],
|
|
1554
1825
|
scene: [
|
|
1555
1826
|
"pcbridge scene settings get --target editor:<sceneId>",
|
|
1827
|
+
"pcbridge scene list --target editor:<sceneId>",
|
|
1828
|
+
"pcbridge scene create --name <name> --target editor:<sceneId>",
|
|
1829
|
+
"pcbridge scene open --id <sceneId> --target editor:<sceneId>",
|
|
1556
1830
|
"pcbridge scene settings patch --target editor:<sceneId> --json ./scene-settings.json",
|
|
1557
1831
|
"pcbridge scene settings patch --target editor:<sceneId> --set render.fog='\"linear\"' --set physics.gravity='[0,-9.8,0]'",
|
|
1558
1832
|
],
|
|
@@ -1637,6 +1911,12 @@ async function main() {
|
|
|
1637
1911
|
else if (command === "install-skill") {
|
|
1638
1912
|
print(await installSkill(args));
|
|
1639
1913
|
}
|
|
1914
|
+
else if (command === "processing") {
|
|
1915
|
+
print(await handleProcessing(args));
|
|
1916
|
+
}
|
|
1917
|
+
else if (command === "import") {
|
|
1918
|
+
print(await handleImportJob(args));
|
|
1919
|
+
}
|
|
1640
1920
|
else if (command === "frontend") {
|
|
1641
1921
|
print(await handleFrontend(args));
|
|
1642
1922
|
}
|
package/dist/config.js
CHANGED
|
@@ -4,7 +4,7 @@ import { existsSync } from "node:fs";
|
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
export const VERSION = "0.6.
|
|
7
|
+
export const VERSION = "0.6.2";
|
|
8
8
|
export const DEFAULT_HOST = "127.0.0.1";
|
|
9
9
|
export const DEFAULT_PORT = 17329;
|
|
10
10
|
export const DEFAULT_FRONTEND_PORT = 3487;
|