omp-mobile 0.4.3 → 0.5.1

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/src/state.mjs ADDED
@@ -0,0 +1,36 @@
1
+ /** The running daemon's state file, as `/mobile` and `omp-mobile relay` read it. */
2
+ import { readFileSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { join } from "node:path";
5
+
6
+ export const STATE_FILE = join(homedir(), ".omp-mobile", "daemon.json");
7
+
8
+ /**
9
+ * The running daemon's record, if its process is alive.
10
+ * @returns {{pid: number, version: string, url: string, pair: string, relay?: string | null, startedAt: number} | undefined}
11
+ */
12
+ export function readState(path = STATE_FILE) {
13
+ let state;
14
+ try {
15
+ state = JSON.parse(readFileSync(path, "utf8"));
16
+ } catch {
17
+ return undefined;
18
+ }
19
+ if (typeof state?.pid !== "number" || typeof state.url !== "string" || typeof state.pair !== "string") return undefined;
20
+ return alive(state.pid) ? state : undefined;
21
+ }
22
+
23
+ export function alive(pid) {
24
+ try {
25
+ process.kill(pid, 0);
26
+ return true;
27
+ } catch (error) {
28
+ // EPERM: it exists but belongs to someone else.
29
+ return error?.code === "EPERM";
30
+ }
31
+ }
32
+
33
+ /** The token inside a pairing link. */
34
+ export function tokenOf(pair) {
35
+ return new URL(pair.replace(/^omp-mobile:\/\//, "http://x/")).searchParams.get("token") ?? "";
36
+ }
package/src/takeover.mjs CHANGED
@@ -175,9 +175,21 @@ export function tellTerminal(tty, text) {
175
175
  }
176
176
  }
177
177
 
178
- /** What the terminal is told once omp left it. */
179
- export function takeoverFarewell(device) {
180
- return `omp-mobile: this session continues on ${device}. omp closed here so the phone could take it over.`;
178
+ /** A path as a shell word: quoted only when it has to be. */
179
+ export function shellWord(value) {
180
+ return /^[A-Za-z0-9_@%+=:,./-]+$/.test(value) ? value : `'${String(value).replace(/'/g, `'\\''`)}'`;
181
+ }
182
+
183
+ /**
184
+ * What the terminal is told once omp left it: where the session went, and the
185
+ * command that brings it back -- the hint leaving omp by hand also leaves.
186
+ * @param {{device: string, sessionFile: string}} leaving
187
+ */
188
+ export function takeoverFarewell({ device, sessionFile }) {
189
+ const lines = [`This session continues on the phone (${device}).`, "omp closed here so the phone could take it over."];
190
+ const file = typeof sessionFile === "string" && sessionFile !== "" ? shellWord(sessionFile) : "";
191
+ if (file !== "") lines.push("", "Resume it in this terminal with:", ` omp --resume ${file}`);
192
+ return lines.join("\n");
181
193
  }
182
194
 
183
195
  const sleep = (ms) => new Promise((resolveSleep) => setTimeout(resolveSleep, ms));
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DSH Remote contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ `dsh-remote-host.mjs` is the Host side of ds-harness-remote's relay (device pairing, the
2
+ relay control connection and its Noise IK channel), bundled from
3
+ [liguobao/ds-harness-remote](https://github.com/liguobao/ds-harness-remote) at commit
4
+ ea1c0925f8be825a5f5afac32ad2d0b2c699f7f7 with `bun build --target=node --format=esm` over an
5
+ entry that re-exports `HostPairing`, `HostServerConnection`, `ConnectionController`,
6
+ `IdentityStore`, `HostServerApi`, `ServerCredentialStore` and `SafeLogger` from
7
+ `packages/plugin/src`, and `createEvent`, `createRpcError`, `createRpcResponse` and
8
+ `MAX_SECURE_MESSAGE_BYTES` from `@dsh-remote/protocol`. Not edited here; see
9
+ `LICENSE.dsh-remote` (MIT).