viveworker 0.7.0-beta.3 → 0.8.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 (34) hide show
  1. package/README.md +33 -4
  2. package/package.json +7 -3
  3. package/scripts/lib/remote-pairing/README.md +164 -0
  4. package/scripts/lib/remote-pairing/_browser-bundle-entry.mjs +86 -0
  5. package/scripts/lib/remote-pairing/audit.mjs +122 -0
  6. package/scripts/lib/remote-pairing/bridge-relay-client.mjs +737 -0
  7. package/scripts/lib/remote-pairing/control.mjs +156 -0
  8. package/scripts/lib/remote-pairing/envelope.mjs +224 -0
  9. package/scripts/lib/remote-pairing/http-dispatch.mjs +530 -0
  10. package/scripts/lib/remote-pairing/keys-core.mjs +110 -0
  11. package/scripts/lib/remote-pairing/keys.mjs +181 -0
  12. package/scripts/lib/remote-pairing/noise.mjs +436 -0
  13. package/scripts/lib/remote-pairing/orchestrator.mjs +356 -0
  14. package/scripts/lib/remote-pairing/pairings.mjs +446 -0
  15. package/scripts/lib/remote-pairing/rpc.mjs +381 -0
  16. package/scripts/moltbook-scout-auto.sh +16 -8
  17. package/scripts/share-cli.mjs +14 -130
  18. package/scripts/viveworker-bridge.mjs +1696 -223
  19. package/scripts/viveworker.mjs +27 -6
  20. package/web/app.css +727 -9
  21. package/web/app.js +1810 -232
  22. package/web/i18n.js +207 -17
  23. package/web/index.html +115 -1
  24. package/web/remote-pairing/api-router.js +873 -0
  25. package/web/remote-pairing/keys.js +237 -0
  26. package/web/remote-pairing/pairing-state.js +313 -0
  27. package/web/remote-pairing/rpc-client.js +765 -0
  28. package/web/remote-pairing/transport.js +804 -0
  29. package/web/remote-pairing/wake.js +149 -0
  30. package/web/remote-pairing-test.html +400 -0
  31. package/web/remote-pairing.bundle.js +3 -0
  32. package/web/remote-pairing.bundle.js.LEGAL.txt +15 -0
  33. package/web/remote-pairing.bundle.js.map +7 -0
  34. package/web/sw.js +190 -20
@@ -863,13 +863,16 @@ async function runStart(cliOptions) {
863
863
  }
864
864
 
865
865
  progress.update("cli.start.progress.bridge");
866
- await startDetachedBridge({
867
- envFile,
868
- logFile: resolvePath(cliOptions.logFile || defaultLogFile),
869
- pidFile,
870
- });
866
+ const alreadyHealthy = await waitForHealth(healthUrl, { attempts: 1, intervalMs: 0 });
867
+ if (!alreadyHealthy) {
868
+ await startDetachedBridge({
869
+ envFile,
870
+ logFile: resolvePath(cliOptions.logFile || defaultLogFile),
871
+ pidFile,
872
+ });
873
+ }
871
874
  progress.update("cli.start.progress.health");
872
- const healthy = await waitForHealth(healthUrl);
875
+ const healthy = alreadyHealthy || await waitForHealth(healthUrl);
873
876
  const pairingReady = healthy && rotatedPairing.rotated
874
877
  ? await waitForExpectedPairing(config.NATIVE_APPROVAL_SERVER_PUBLIC_BASE_URL || "", rotatedPairing.pairingToken)
875
878
  : true;
@@ -1691,6 +1694,11 @@ function buildLaunchAgentPlist({ label, nodePath, bridgeScript, envFile, logFile
1691
1694
  }
1692
1695
 
1693
1696
  async function startDetachedBridge({ envFile, logFile, pidFile }) {
1697
+ const existingPid = await maybeReadPid(pidFile);
1698
+ if (existingPid && isProcessRunning(existingPid)) {
1699
+ return { pid: existingPid, alreadyRunning: true };
1700
+ }
1701
+
1694
1702
  await fs.mkdir(path.dirname(logFile), { recursive: true });
1695
1703
  const logHandle = await fs.open(logFile, "a");
1696
1704
  const child = spawn(process.execPath, [bridgeScript, "--env-file", envFile], {
@@ -1700,6 +1708,7 @@ async function startDetachedBridge({ envFile, logFile, pidFile }) {
1700
1708
  child.unref();
1701
1709
  await logHandle.close();
1702
1710
  await fs.writeFile(pidFile, `${child.pid}\n`, "utf8");
1711
+ return { pid: child.pid, alreadyRunning: false };
1703
1712
  }
1704
1713
 
1705
1714
  async function maybeReadPid(pidFile) {
@@ -1712,6 +1721,18 @@ async function maybeReadPid(pidFile) {
1712
1721
  }
1713
1722
  }
1714
1723
 
1724
+ function isProcessRunning(pid) {
1725
+ if (!Number.isFinite(pid) || pid <= 0) {
1726
+ return false;
1727
+ }
1728
+ try {
1729
+ process.kill(pid, 0);
1730
+ return true;
1731
+ } catch {
1732
+ return false;
1733
+ }
1734
+ }
1735
+
1715
1736
  async function maybeReadEnvFile(filePath) {
1716
1737
  const output = {};
1717
1738
  try {