mindwire 0.1.38 → 0.1.40

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 (39) hide show
  1. package/README.md +16 -0
  2. package/dist/{chunk-CKTVMUS4.js → chunk-BJL5K6M7.js} +50 -16
  3. package/dist/chunk-BJL5K6M7.js.map +1 -0
  4. package/dist/chunk-ZP7F7LP7.js +306 -0
  5. package/dist/chunk-ZP7F7LP7.js.map +1 -0
  6. package/dist/cli.js +499 -250
  7. package/dist/cli.js.map +1 -1
  8. package/dist/computer/dashboard.d.ts +1 -0
  9. package/dist/computer/desktop.d.ts +17 -0
  10. package/dist/computer/directory-http.d.ts +1 -1
  11. package/dist/computer/discovery.d.ts +22 -0
  12. package/dist/computer/inspection.d.ts +30 -0
  13. package/dist/computer/lifecycle.d.ts +4 -2
  14. package/dist/computer/runtime-version.d.ts +6 -0
  15. package/dist/computer/service-update.d.ts +26 -0
  16. package/dist/computer/setup-prompt.d.ts +2 -0
  17. package/dist/computer/startup.d.ts +7 -0
  18. package/dist/computer/terminal-ui.d.ts +9 -0
  19. package/dist/computer.d.ts +2 -0
  20. package/dist/{connection-change-5F4WNCYV.js → connection-change-7ZV6O75Q.js} +3 -3
  21. package/dist/{connection-change-5F4WNCYV.js.map → connection-change-7ZV6O75Q.js.map} +1 -1
  22. package/dist/{controller-3SZI7TBW.js → controller-FBMGMSLM.js} +67 -9
  23. package/dist/controller-FBMGMSLM.js.map +1 -0
  24. package/dist/{controller-handoff-KV7WRDAI.js → controller-handoff-CJKXUFQI.js} +3 -3
  25. package/dist/{controller-handoff-KV7WRDAI.js.map → controller-handoff-CJKXUFQI.js.map} +1 -1
  26. package/dist/daemon-binary.d.ts +2 -0
  27. package/dist/index.cjs +41 -7
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.js +41 -7
  31. package/dist/index.js.map +1 -1
  32. package/dist/project-sync.d.ts +29 -0
  33. package/dist/surfaces.d.ts +20 -1
  34. package/dist/types.d.ts +2 -0
  35. package/package.json +1 -1
  36. package/dist/chunk-CKTVMUS4.js.map +0 -1
  37. package/dist/chunk-QODJKRFK.js +0 -20
  38. package/dist/chunk-QODJKRFK.js.map +0 -1
  39. package/dist/controller-3SZI7TBW.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { readJSON, processIdentity, writeJSON, processStateAlive } from './chunk-CKTVMUS4.js';
1
+ import { readJSON, processIdentity, writeJSON, processStateAlive } from './chunk-BJL5K6M7.js';
2
2
  import './chunk-PFYKJ6LX.js';
3
3
  import { execFile } from 'child_process';
4
4
  import * as path from 'path';
@@ -67,5 +67,5 @@ async function handoffController(directory, state, config, info) {
67
67
  }
68
68
 
69
69
  export { handoffController };
70
- //# sourceMappingURL=controller-handoff-KV7WRDAI.js.map
71
- //# sourceMappingURL=controller-handoff-KV7WRDAI.js.map
70
+ //# sourceMappingURL=controller-handoff-CJKXUFQI.js.map
71
+ //# sourceMappingURL=controller-handoff-CJKXUFQI.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/computer/controller-handoff.ts"],"names":["route","delay"],"mappings":";;;;;;;AAQA,IAAM,OAAA,GAAU,UAAU,QAAQ,CAAA;AAElC,eAAe,iBAAA,CAAkB,KAAa,SAAA,EAAsG;AAClJ,EAAA,MAAM,QAAA,GAAW,MAAM,eAAA,CAAgB,GAAG,CAAA;AAC1C,EAAA,IAAI,CAAC,QAAA,EAAU,MAAM,IAAI,MAAM,wDAAwD,CAAA;AACvF,EAAA,IAAI,OAAA,EAAiB,QAAA;AACrB,EAAA,IAAI,OAAA,CAAQ,aAAa,OAAA,EAAS;AAChC,IAAA,MAAM,SAAS,MAAM,OAAA;AAAA,MAAQ,gBAAA;AAAA,MAAkB;AAAA,QAAC,YAAA;AAAA,QAAc,iBAAA;AAAA,QAAmB,UAAA;AAAA,QAC/E,CAAA,sDAAA,EAAyD,GAAG,CAAA,iEAAA,EAAoE,GAAG,CAAA,wIAAA;AA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,MAAAA,CAAM,SAAS,WAAW,CAAA;AAClE,IAAA,MAAM,UAAA,GAAa,UAAA,CAAW,MAAA,KAAW,CAAA,GAAI,MAAM,gBAAgB,UAAA,CAAW,CAAC,CAAA,CAAG,GAAG,CAAA,GAAI,MAAA;AACzF,IAAA,IAAI,KAAA,IAAS,UAAA,EAAY,MAAM,SAAA,CAAU,SAAA,EAAW;AAAA,MAClD,KAAA,EAAO,UAAA;AAAA,MAAY,MAAM,IAAA,CAAK,aAAA;AAAA,MAAe,OAAA,EAAS,IAAA,CAAK,SAAA,CAAU,MAAA,CAAO,KAAK,CAAA;AAAA,MAAG;AAAA,KACrF,CAAA;AAAA,EACH;AACA,EAAA,IAAI,CAAC,MAAM,iBAAA,CAAkB,QAAQ,GAAG,MAAM,IAAI,MAAM,wDAAwD,CAAA;AAChH,EAAA,OAAA,CAAQ,IAAA,CAAK,QAAA,CAAS,GAAA,EAAK,SAAS,CAAA;AACpC,EAAA,KAAA,IAAS,OAAA,GAAU,CAAA,EAAG,OAAA,GAAU,EAAA,EAAI,OAAA,EAAA,EAAW;AAC7C,IAAA,IAAI,CAAC,MAAM,iBAAA,CAAkB,QAAQ,CAAA,EAAG;AACxC,IAAA,MAAMC,WAAM,EAAE,CAAA;AAAA,EAChB;AACA,EAAA,MAAM,IAAI,MAAM,qEAAqE,CAAA;AACvF","file":"controller-handoff-KV7WRDAI.js","sourcesContent":["import { execFile } from \"node:child_process\";\nimport * as path from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { setTimeout as delay } from \"node:timers/promises\";\nimport type { ComputerInfo } from \"../computer.js\";\nimport { readJSON, writeJSON, type ComputerConfig, type ControllerState } from \"./lifecycle.js\";\nimport { processIdentity, processStateAlive, type ProcessIdentity } from \"./process.js\";\n\nconst execute = promisify(execFile);\n\nasync function controllerProcess(pid: number, directory: string): Promise<{ identity: ProcessIdentity; children: { pid: number; name: string }[] }> {\n const identity = await processIdentity(pid);\n if (!identity) throw new Error(\"The computer controller changed. Retry the connection.\");\n let command: string, children: { pid: number; name: string }[];\n if (process.platform === \"win32\") {\n const result = await execute(\"powershell.exe\", [\"-NoProfile\", \"-NonInteractive\", \"-Command\",\n `$p=Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}'; $c=@(Get-CimInstance Win32_Process -Filter 'ParentProcessId = ${pid}'); @{command=$p.CommandLine; children=@($c | ForEach-Object { @{pid=$_.ProcessId; name=$_.Name} })} | ConvertTo-Json -Depth 4 -Compress`],\n { timeout: 5000, windowsHide: true });\n const value = JSON.parse(result.stdout);\n command = String(value.command ?? \"\").replaceAll('\"', \"\");\n children = value.children;\n } else {\n const [args, processes] = await Promise.all([\n execute(\"/bin/ps\", [\"-p\", String(pid), \"-o\", \"args=\"], { timeout: 3000 }),\n execute(\"/bin/ps\", [\"-axo\", \"pid=,ppid=,comm=\"], { timeout: 3000 }),\n ]);\n command = args.stdout.trim();\n children = processes.stdout.split(\"\\n\").flatMap(line => {\n const match = line.trim().match(/^(\\d+)\\s+(\\d+)\\s+(.+)$/);\n return match && Number(match[2]) === pid ? [{ pid: Number(match[1]), name: path.basename(match[3]!) }] : [];\n });\n }\n // Old releases recorded only a PID. Verify the actual controller command before\n // signalling it; a reused PID must never affect an unrelated process.\n if (!command.endsWith(`dist${path.sep}cli.js _serve --state-dir ${directory}`)\n || !/(?:^|[\\/\\\\])(?:node|bun)(?:\\.exe)?\\s/.test(command)) {\n throw new Error(\"Couldn't verify the old Mindwire controller. Restart Mindwire on the computer before connecting.\");\n }\n if ((await processIdentity(pid))?.start !== identity.start) throw new Error(\"The computer controller changed. Retry the connection.\");\n return { identity, children };\n}\n\n/** Hand off an old CLI controller without stopping the daemon or its terminals.\n * Its graceful shutdown deliberately closes both children, so only the verified\n * supervisor is terminated; the new controller adopts the existing children. */\nexport async function handoffController(directory: string, state: ControllerState, config: ComputerConfig, info: ComputerInfo): Promise<void> {\n const { identity, children } = await controllerProcess(state.pid, directory);\n if (state.start && state.start !== identity.start) throw new Error(\"The computer controller changed. Retry the connection.\");\n const relayFile = path.join(directory, \"computer-relay.json\");\n if (!await readJSON(relayFile)) {\n // Releases before process adoption didn't record the provider child. Capture\n // just that controller's unique helper before it becomes an orphan.\n const executable = config.relay.kind === \"cloudflare\" ? \"cloudflared\" : config.relay.kind === \"ngrok\" ? \"ngrok\" : undefined;\n const candidates = executable ? children.filter(child => child.name === executable || child.name === executable + \".exe\") : [];\n const route = info.routes.find(route => route.kind === \"websocket\");\n const relayOwner = candidates.length === 1 ? await processIdentity(candidates[0]!.pid) : undefined;\n if (route && relayOwner) await writeJSON(relayFile, {\n owner: relayOwner, port: info.websocketPort, options: JSON.stringify(config.relay), route,\n });\n }\n if (!await processStateAlive(identity)) throw new Error(\"The computer controller changed. Retry the connection.\");\n process.kill(identity.pid, \"SIGKILL\");\n for (let attempt = 0; attempt < 40; attempt++) {\n if (!await processStateAlive(identity)) return;\n await delay(50);\n }\n throw new Error(\"The old Mindwire controller is still exiting. Retry the connection.\");\n}\n"]}
1
+ {"version":3,"sources":["../src/computer/controller-handoff.ts"],"names":["route","delay"],"mappings":";;;;;;;AAQA,IAAM,OAAA,GAAU,UAAU,QAAQ,CAAA;AAElC,eAAe,iBAAA,CAAkB,KAAa,SAAA,EAAsG;AAClJ,EAAA,MAAM,QAAA,GAAW,MAAM,eAAA,CAAgB,GAAG,CAAA;AAC1C,EAAA,IAAI,CAAC,QAAA,EAAU,MAAM,IAAI,MAAM,wDAAwD,CAAA;AACvF,EAAA,IAAI,OAAA,EAAiB,QAAA;AACrB,EAAA,IAAI,OAAA,CAAQ,aAAa,OAAA,EAAS;AAChC,IAAA,MAAM,SAAS,MAAM,OAAA;AAAA,MAAQ,gBAAA;AAAA,MAAkB;AAAA,QAAC,YAAA;AAAA,QAAc,iBAAA;AAAA,QAAmB,UAAA;AAAA,QAC/E,CAAA,sDAAA,EAAyD,GAAG,CAAA,iEAAA,EAAoE,GAAG,CAAA,wIAAA;AAAA,OAA0I;AAAA,MAC/Q,EAAE,OAAA,EAAS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A,MAAM,UAAA,GAAa,UAAA,CAAW,MAAA,KAAW,CAAA,GAAI,MAAM,gBAAgB,UAAA,CAAW,CAAC,CAAA,CAAG,GAAG,CAAA,GAAI,MAAA;AACzF,IAAA,IAAI,KAAA,IAAS,UAAA,EAAY,MAAM,SAAA,CAAU,SAAA,EAAW;AAAA,MAClD,KAAA,EAAO,UAAA;AAAA,MAAY,MAAM,IAAA,CAAK,aAAA;AAAA,MAAe,OAAA,EAAS,IAAA,CAAK,SAAA,CAAU,MAAA,CAAO,KAAK,CAAA;AAAA,MAAG;AAAA,KACrF,CAAA;AAAA,EACH;AACA,EAAA,IAAI,CAAC,MAAM,iBAAA,CAAkB,QAAQ,GAAG,MAAM,IAAI,MAAM,wDAAwD,CAAA;AAChH,EAAA,OAAA,CAAQ,IAAA,CAAK,QAAA,CAAS,GAAA,EAAK,SAAS,CAAA;AACpC,EAAA,KAAA,IAAS,OAAA,GAAU,CAAA,EAAG,OAAA,GAAU,EAAA,EAAI,OAAA,EAAA,EAAW;AAC7C,IAAA,IAAI,CAAC,MAAM,iBAAA,CAAkB,QAAQ,CAAA,EAAG;AACxC,IAAA,MAAMC,WAAM,EAAE,CAAA;AAAA,EAChB;AACA,EAAA,MAAM,IAAI,MAAM,qEAAqE,CAAA;AACvF","file":"controller-handoff-CJKXUFQI.js","sourcesContent":["import { execFile } from \"node:child_process\";\nimport * as path from \"node:path\";\nimport { promisify } from \"node:util\";\nimport { setTimeout as delay } from \"node:timers/promises\";\nimport type { ComputerInfo } from \"../computer.js\";\nimport { readJSON, writeJSON, type ComputerConfig, type ControllerState } from \"./lifecycle.js\";\nimport { processIdentity, processStateAlive, type ProcessIdentity } from \"./process.js\";\n\nconst execute = promisify(execFile);\n\nasync function controllerProcess(pid: number, directory: string): Promise<{ identity: ProcessIdentity; children: { pid: number; name: string }[] }> {\n const identity = await processIdentity(pid);\n if (!identity) throw new Error(\"The computer controller changed. Retry the connection.\");\n let command: string, children: { pid: number; name: string }[];\n if (process.platform === \"win32\") {\n const result = await execute(\"powershell.exe\", [\"-NoProfile\", \"-NonInteractive\", \"-Command\",\n `$p=Get-CimInstance Win32_Process -Filter 'ProcessId = ${pid}'; $c=@(Get-CimInstance Win32_Process -Filter 'ParentProcessId = ${pid}'); @{command=$p.CommandLine; children=@($c | ForEach-Object { @{pid=$_.ProcessId; name=$_.Name} })} | ConvertTo-Json -Depth 4 -Compress`],\n { timeout: 5000, windowsHide: true });\n const value = JSON.parse(result.stdout);\n command = String(value.command ?? \"\").replaceAll('\"', \"\");\n children = value.children;\n } else {\n const [args, processes] = await Promise.all([\n execute(\"/bin/ps\", [\"-p\", String(pid), \"-o\", \"args=\"], { timeout: 3000 }),\n execute(\"/bin/ps\", [\"-axo\", \"pid=,ppid=,comm=\"], { timeout: 3000 }),\n ]);\n command = args.stdout.trim();\n children = processes.stdout.split(\"\\n\").flatMap(line => {\n const match = line.trim().match(/^(\\d+)\\s+(\\d+)\\s+(.+)$/);\n return match && Number(match[2]) === pid ? [{ pid: Number(match[1]), name: path.basename(match[3]!) }] : [];\n });\n }\n // Old releases recorded only a PID. Verify the actual controller command before\n // signalling it; a reused PID must never affect an unrelated process.\n if (!command.endsWith(`dist${path.sep}cli.js _serve --state-dir ${directory}`)\n || !/(?:^|[\\/\\\\])(?:node|bun)(?:\\.exe)?\\s/.test(command)) {\n throw new Error(\"Couldn't verify the old Mindwire controller. Restart Mindwire on the computer before connecting.\");\n }\n if ((await processIdentity(pid))?.start !== identity.start) throw new Error(\"The computer controller changed. Retry the connection.\");\n return { identity, children };\n}\n\n/** Hand off an old CLI controller without stopping the daemon or its terminals.\n * Its graceful shutdown deliberately closes both children, so only the verified\n * supervisor is terminated; the new controller adopts the existing children. */\nexport async function handoffController(directory: string, state: ControllerState, config: ComputerConfig, info: ComputerInfo): Promise<void> {\n const { identity, children } = await controllerProcess(state.pid, directory);\n if (state.start && state.start !== identity.start) throw new Error(\"The computer controller changed. Retry the connection.\");\n const relayFile = path.join(directory, \"computer-relay.json\");\n if (!await readJSON(relayFile)) {\n // Releases before process adoption didn't record the provider child. Capture\n // just that controller's unique helper before it becomes an orphan.\n const executable = config.relay.kind === \"cloudflare\" ? \"cloudflared\" : config.relay.kind === \"ngrok\" ? \"ngrok\" : undefined;\n const candidates = executable ? children.filter(child => child.name === executable || child.name === executable + \".exe\") : [];\n const route = info.routes.find(route => route.kind === \"websocket\");\n const relayOwner = candidates.length === 1 ? await processIdentity(candidates[0]!.pid) : undefined;\n if (route && relayOwner) await writeJSON(relayFile, {\n owner: relayOwner, port: info.websocketPort, options: JSON.stringify(config.relay), route,\n });\n }\n if (!await processStateAlive(identity)) throw new Error(\"The computer controller changed. Retry the connection.\");\n process.kill(identity.pid, \"SIGKILL\");\n for (let attempt = 0; attempt < 40; attempt++) {\n if (!await processStateAlive(identity)) return;\n await delay(50);\n }\n throw new Error(\"The old Mindwire controller is still exiting. Retry the connection.\");\n}\n"]}
@@ -8,6 +8,8 @@ export interface EnsureDaemonBinaryOptions {
8
8
  /** Override for tests or a private GitHub Releases mirror. */
9
9
  releaseBaseUrl?: string;
10
10
  fetch?: typeof fetch;
11
+ /** Managed updates must not substitute a different release when an asset is missing. */
12
+ exactVersion?: boolean;
11
13
  }
12
14
  /** Ensure the SDK-matched daemon binary is present locally and return its executable path. */
13
15
  export declare function ensureDaemonBinary(opts?: EnsureDaemonBinaryOptions): Promise<string>;
package/dist/index.cjs CHANGED
@@ -567,6 +567,18 @@ var ProjectSyncError = class extends exports.MindwireError {
567
567
  };
568
568
  var active = (o) => ["queued", "exporting", "preparing", "applying"].includes(o.status);
569
569
  var prefix = "/workspace/sync";
570
+ var selectionPaths = (paths = []) => {
571
+ const sorted = [...new Set(paths.map((path) => path.replace(/\/$/, "")))].sort();
572
+ const selected = new Set(sorted);
573
+ return sorted.filter((path) => {
574
+ let parent = path;
575
+ while (parent.includes("/")) {
576
+ parent = parent.slice(0, parent.lastIndexOf("/"));
577
+ if (selected.has(parent)) return false;
578
+ }
579
+ return true;
580
+ });
581
+ };
570
582
  function delay(ms, signal) {
571
583
  signal?.throwIfAborted();
572
584
  return new Promise((resolve, reject) => {
@@ -589,7 +601,16 @@ var ProjectSyncApi = class {
589
601
  }
590
602
  mw;
591
603
  flights = /* @__PURE__ */ new Map();
592
- export(request, options = {}) {
604
+ async requireSelectionSupport() {
605
+ if (((await this.mw.health()).projectSyncVersion ?? 0) < 2)
606
+ throw new exports.MindwireError("Update Mindwire on both workspaces to review and switch selected project files.");
607
+ }
608
+ async preview(request, options = {}) {
609
+ await this.requireSelectionSupport();
610
+ return this.mw.http.request("POST", `${prefix}/preview`, { body: request, ...options });
611
+ }
612
+ async export(request, options = {}) {
613
+ await this.requireSelectionSupport();
593
614
  return this.mw.http.request("POST", `${prefix}/exports`, { body: request, ...options });
594
615
  }
595
616
  import(request, options = {}) {
@@ -674,6 +695,7 @@ var ProjectSyncApi = class {
674
695
  * throws ProjectSyncError carrying the complete conflict/recovery operation.
675
696
  */
676
697
  switchTo(target, request, options = {}) {
698
+ request = { ...request, includeIgnored: selectionPaths(request.includeIgnored) };
677
699
  const intent = JSON.stringify(request);
678
700
  const old = this.flights.get(request.id);
679
701
  if (old) {
@@ -689,7 +711,8 @@ var ProjectSyncApi = class {
689
711
  if (!(error instanceof exports.ApiError) || error.status !== 404) throw error;
690
712
  }
691
713
  if (accepted) {
692
- if ((accepted.path ?? "") !== (request.path ?? "")) throw new exports.MindwireError("This sync ID belongs to a different destination folder.");
714
+ if ((accepted.path ?? "") !== (request.path ?? "") || (accepted.selectionToken ?? "") !== (request.selectionToken ?? "") || JSON.stringify(selectionPaths(accepted.includeIgnored)) !== JSON.stringify(request.includeIgnored))
715
+ throw new exports.MindwireError("This sync ID belongs to a different destination folder or file selection.");
693
716
  const operation = await target.wait(accepted.id, {
694
717
  signal: options.signal,
695
718
  onUpdate: (operation2) => options.onProgress?.({ phase: "apply", transferredBytes: 0, operation: operation2 })
@@ -698,11 +721,11 @@ var ProjectSyncApi = class {
698
721
  return operation;
699
722
  }
700
723
  const health = await Promise.all([this.mw.health(), target.mw.health()]);
701
- if (health.some((h) => (h.projectSyncVersion ?? 0) < 1)) throw new exports.MindwireError("Update Mindwire on both workspaces to switch this project.");
724
+ if (health.some((h) => (h.projectSyncVersion ?? 0) < 2)) throw new exports.MindwireError("Update Mindwire on both workspaces to review and switch selected project files.");
702
725
  let bytes = 0;
703
726
  const emit2 = (phase, operation) => options.onProgress?.({ phase, transferredBytes: bytes, operation });
704
727
  emit2("checkpoint");
705
- let o = await this.export({ id: `${request.id}-export`, projectId: request.projectId }, options);
728
+ let o = await this.export({ id: `${request.id}-export`, projectId: request.projectId, includeIgnored: request.includeIgnored, selectionToken: request.selectionToken }, options);
706
729
  o = await this.wait(o.id, { signal: options.signal, onUpdate: (value) => emit2("checkpoint", value) });
707
730
  if (o.status !== "succeeded" || !o.resultCheckpointId) throw new ProjectSyncError(o);
708
731
  emit2("transfer");
@@ -710,7 +733,7 @@ var ProjectSyncApi = class {
710
733
  bytes += n;
711
734
  emit2("transfer");
712
735
  } });
713
- o = await target.import({ id: `${request.id}-import`, checkpointId: o.resultCheckpointId, path: request.path }, options);
736
+ o = await target.import({ id: `${request.id}-import`, checkpointId: o.resultCheckpointId, path: request.path, includeIgnored: request.includeIgnored, selectionToken: request.selectionToken }, options);
714
737
  o = await target.wait(o.id, { signal: options.signal, onUpdate: (value) => emit2("apply", value) });
715
738
  if (o.status !== "succeeded") throw new ProjectSyncError(o);
716
739
  return o;
@@ -947,6 +970,17 @@ var SurfacesApi = class {
947
970
  bind(binding) {
948
971
  return this.mw.http.request("PUT", "/surfaces/desktop/binding", { body: binding });
949
972
  }
973
+ localStatus() {
974
+ return this.mw.http.request("GET", "/surfaces/desktop/local");
975
+ }
976
+ /** Local CLI only. The separate 0600 control credential is not part of phone pairing. */
977
+ configureLocal(settings, localControlToken) {
978
+ if (!localControlToken) throw new Error("Run mindwire desktop on your Mac to manage desktop access.");
979
+ return this.mw.http.request("PUT", "/surfaces/desktop/local", {
980
+ body: settings,
981
+ headers: { "X-Mindwire-Local-Control": localControlToken }
982
+ });
983
+ }
950
984
  open(request) {
951
985
  return this.mw.http.request("POST", "/surfaces/desktop/sessions", { body: request });
952
986
  }
@@ -1167,7 +1201,7 @@ init_errors();
1167
1201
  init_errors();
1168
1202
 
1169
1203
  // src/version.ts
1170
- var SDK_VERSION = "0.1.38" ;
1204
+ var SDK_VERSION = "0.1.40" ;
1171
1205
  function versionAtLeast(actual, desired) {
1172
1206
  if (actual === desired) return true;
1173
1207
  if (!actual || !/^\d+\.\d+\.\d+$/.test(actual) || !/^\d+\.\d+\.\d+$/.test(desired)) return false;
@@ -1218,7 +1252,7 @@ async function ensureDaemonBinary(opts = {}) {
1218
1252
  if (!request) throw new exports.MindwireError("mindwire: fetch is unavailable; set daemonBin or MINDWIRE_DAEMON");
1219
1253
  const [checksums, binary] = await Promise.all([request(`${release}/checksums.txt`), request(`${release}/${asset}`)]);
1220
1254
  if (!checksums.ok || !binary.ok) {
1221
- if (!opts.releaseBaseUrl && !proc.process?.env?.MINDWIRE_RELEASE_BASE_URL) {
1255
+ if (!opts.exactVersion && !opts.releaseBaseUrl && !proc.process?.env?.MINDWIRE_RELEASE_BASE_URL) {
1222
1256
  const latest = await request("https://api.github.com/repos/oblien/mindwire/releases/latest");
1223
1257
  if (latest.ok) {
1224
1258
  const tag = (await latest.json()).tag_name;