mindwire 0.1.29 → 0.1.32

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.
@@ -79,7 +79,16 @@ function computerPairingURI(invitation) {
79
79
  }
80
80
 
81
81
  // src/version.ts
82
- var SDK_VERSION = "0.1.29" ;
82
+ var SDK_VERSION = "0.1.32" ;
83
+ function versionAtLeast(actual, desired) {
84
+ if (actual === desired) return true;
85
+ if (!actual || !/^\d+\.\d+\.\d+$/.test(actual) || !/^\d+\.\d+\.\d+$/.test(desired)) return false;
86
+ const a = actual.split(".").map(Number), b = desired.split(".").map(Number);
87
+ for (let i = 0; i < 3; i++) {
88
+ if (a[i] !== b[i]) return a[i] > b[i];
89
+ }
90
+ return true;
91
+ }
83
92
 
84
93
  // src/daemon-binary.ts
85
94
  function supported(platform, arch) {
@@ -742,6 +751,10 @@ var WorkspaceApi = class {
742
751
  snapshot(options = {}) {
743
752
  return this.mw.http.request("GET", "/workspace", { query: options });
744
753
  }
754
+ /** Read the saved icon, or preview a candidate relative path within the project. Requires projectIconsVersion >= 1. */
755
+ projectIcon(projectId, path2) {
756
+ return this.mw.http.request("GET", `/workspace/projects/${encodeURIComponent(projectId)}/icon`, { query: { path: path2 } });
757
+ }
745
758
  /** Start an operation owned by the daemon. The same ID/payload returns the existing operation. */
746
759
  createProject(request) {
747
760
  return this.mw.http.request("POST", "/workspace/projects", { body: request });
@@ -798,7 +811,7 @@ var GitAccessApi = class {
798
811
  run(projectId, operation, auth) {
799
812
  return this.mw.http.request("POST", `/workspace/projects/${encodeURIComponent(projectId)}/git/${operation}`, { body: { auth } });
800
813
  }
801
- /** Requires health.gitOperationsVersion >= 1 (>= 2 for branches, >= 4 for restore_commit). Acceptance persists before Git runs;
814
+ /** Requires health.gitOperationsVersion >= 1 (>= 2 for switch/create, >= 4 for restore_commit, >= 5 for rename/delete). Acceptance persists before Git runs;
802
815
  * disconnecting only detaches the client. The same ID/intent never runs twice.
803
816
  */
804
817
  start(projectId, request) {
@@ -808,7 +821,7 @@ var GitAccessApi = class {
808
821
  const result = await this.mw.http.request(
809
822
  "GET",
810
823
  `/workspace/projects/${encodeURIComponent(projectId)}/git/operations`,
811
- { query: { active: activeOnly, actionsVersion: 4 } }
824
+ { query: { active: activeOnly, actionsVersion: 5 } }
812
825
  );
813
826
  return result.operations;
814
827
  }
@@ -1884,6 +1897,7 @@ async function acquireProcessLock(file, options = {}) {
1884
1897
  }
1885
1898
 
1886
1899
  // src/computer/lifecycle.ts
1900
+ var CONTROLLER_PROTOCOL = 2;
1887
1901
  var defaultStateDirectory = () => path.join(homedir(), ".mindwire", "computer");
1888
1902
  var defaultComputerConfig = () => ({ directory: homedir(), bind: "0.0.0.0", sshPort: 8791, websocketPort: 8792, relay: { kind: "cloudflare" } });
1889
1903
  async function readJSON(file) {
@@ -1938,41 +1952,48 @@ async function ensureComputer(directory, cliPath, patch = {}, onProgress, option
1938
1952
  const configPath = path.join(directory, "computer-config.json");
1939
1953
  const previous = await readJSON(configPath);
1940
1954
  const config = { ...defaultComputerConfig(), ...previous, ...patch };
1955
+ const requestedAt = resume ? Date.now() : 0;
1956
+ if (resume) await writeJSON(path.join(directory, "computer-check.json"), { requestedAt });
1957
+ const compatible = (controller) => (controller?.protocol ?? 0) >= CONTROLLER_PROTOCOL && versionAtLeast(controller?.cliVersion, SDK_VERSION);
1941
1958
  let launchedPID;
1942
1959
  let launchFailure;
1943
1960
  const waitUntilReady = async () => {
1944
1961
  let phase;
1962
+ let lastState;
1945
1963
  for (let attempt = 0; attempt < 1200; attempt++) {
1946
1964
  options.signal?.throwIfAborted();
1947
1965
  const controller = await readJSON(path.join(directory, "computer-controller.json"));
1966
+ lastState = controller;
1948
1967
  if (launchFailure) throw launchFailure;
1949
1968
  if (launchedPID && controller?.pid !== launchedPID) {
1950
1969
  await setTimeout$1(250);
1951
1970
  continue;
1952
1971
  }
1953
1972
  if (controller?.error && !controller.recovering) throw new Error(controller.error);
1954
- if (controller?.ready && await processStateAlive(controller)) return computerClient(directory);
1973
+ if (controller?.ready && compatible(controller) && (controller.checkedAt ?? 0) >= requestedAt && await processStateAlive(controller)) return computerClient(directory);
1955
1974
  if (controller?.phase && controller.phase !== phase) {
1956
1975
  phase = controller.phase;
1957
1976
  onProgress?.(phase);
1958
1977
  }
1959
1978
  await setTimeout$1(250);
1960
1979
  }
1961
- throw new Error(`Mindwire did not finish starting. Inspect ${path.join(directory, "computer.log")}.`);
1980
+ const lastStep = lastState?.errorCode === "dns" ? "Your DNS resolver still cannot find the tunnel address." : lastState?.error ?? phase ?? "The background service hasn't reported readiness.";
1981
+ const recovering = lastState?.recovering && await processStateAlive(lastState).catch(() => false);
1982
+ throw new Error(`Mindwire's connection is not ready. ${lastStep}${recovering ? " Background recovery continues." : ""} Run mindwire status for the current state, then mindwire connect to retry.`);
1962
1983
  };
1963
1984
  if (current) {
1964
1985
  if (Object.keys(patch).some((key) => JSON.stringify(config[key]) !== JSON.stringify(previous?.[key]))) {
1965
1986
  throw new Error("Mindwire is running with different connection settings. Run mindwire stop when idle, then retry with the new settings.");
1966
1987
  }
1967
1988
  const controller = await readJSON(path.join(directory, "computer-controller.json"));
1968
- if (await processStateAlive(controller)) return waitUntilReady();
1989
+ if (compatible(controller) && await processStateAlive(controller)) return waitUntilReady();
1969
1990
  }
1970
1991
  const lockPath = path.join(directory, "launch.lock");
1971
1992
  const lock = await acquireProcessLock(lockPath, {
1972
1993
  signal: options.signal,
1973
1994
  onWait: async () => {
1974
1995
  const controller = await readJSON(path.join(directory, "computer-controller.json"));
1975
- if (await processStateAlive(controller)) {
1996
+ if (compatible(controller) && await processStateAlive(controller)) {
1976
1997
  const saved = await readJSON(configPath);
1977
1998
  if (Object.keys(patch).some((key) => JSON.stringify(patch[key]) !== JSON.stringify(saved?.[key]))) {
1978
1999
  throw new Error("Another start used different connection settings. Stop Mindwire when idle before changing them.");
@@ -1996,9 +2017,15 @@ async function ensureComputer(directory, cliPath, patch = {}, onProgress, option
1996
2017
  throw new Error("Another start used different connection settings. Stop Mindwire when idle before changing them.");
1997
2018
  }
1998
2019
  const controller2 = await readJSON(path.join(directory, "computer-controller.json"));
1999
- if (await processStateAlive(controller2)) return waitUntilReady();
2020
+ if (compatible(controller2) && await processStateAlive(controller2)) return waitUntilReady();
2021
+ }
2022
+ let controller = await readJSON(path.join(directory, "computer-controller.json"));
2023
+ if (existing && controller && !compatible(controller) && await processStateAlive(controller)) {
2024
+ onProgress?.("Refreshing the background connection service\u2026");
2025
+ const { handoffController } = await import('./controller-handoff-7S6SKFHX.js');
2026
+ await handoffController(directory, controller, config, await existing.computer.info());
2027
+ controller = void 0;
2000
2028
  }
2001
- const controller = await readJSON(path.join(directory, "computer-controller.json"));
2002
2029
  if (await processStateAlive(controller)) {
2003
2030
  if (controller?.error && !controller.recovering) throw new Error(controller.error);
2004
2031
  } else {
@@ -2029,7 +2056,7 @@ async function ensureComputer(directory, cliPath, patch = {}, onProgress, option
2029
2056
  }
2030
2057
  }
2031
2058
  async function superviseComputer(directory) {
2032
- const controller = await import('./controller-MNMIJHH5.js');
2059
+ const controller = await import('./controller-CHJ5MMZS.js');
2033
2060
  await controller.superviseComputer(directory);
2034
2061
  }
2035
2062
  async function stopComputer(directory, force = false) {
@@ -2053,6 +2080,6 @@ async function stopComputer(directory, force = false) {
2053
2080
  throw new Error("Mindwire is still stopping. Check computer.log.");
2054
2081
  }
2055
2082
 
2056
- export { SDK_VERSION, acquireProcessLock, adoptProcess, computerClient, computerPairingQRData, computerPairingURI, currentProcessIdentity, defaultStateDirectory, directRoutes, ensureComputer, ensureDaemonBinary, ownChild, processIdentity, processStateAlive, readJSON, stopComputer, superviseComputer, writeJSON };
2057
- //# sourceMappingURL=chunk-QPZMGVY7.js.map
2058
- //# sourceMappingURL=chunk-QPZMGVY7.js.map
2083
+ export { CONTROLLER_PROTOCOL, SDK_VERSION, acquireProcessLock, adoptProcess, computerClient, computerPairingQRData, computerPairingURI, currentProcessIdentity, defaultStateDirectory, directRoutes, ensureComputer, ensureDaemonBinary, ownChild, processIdentity, processStateAlive, readJSON, stopComputer, superviseComputer, writeJSON };
2084
+ //# sourceMappingURL=chunk-5X5PAFM7.js.map
2085
+ //# sourceMappingURL=chunk-5X5PAFM7.js.map