@dsh-mobile/mobile-remote 3.3.1 → 3.4.1-beta.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.
- package/README.md +9 -5
- package/docs/PRIVACY-POLICY.en.md +10 -3
- package/docs/PRIVACY-POLICY.md +10 -3
- package/docs/USER-GUIDE.zh-CN.md +1 -0
- package/lib/account-usage-query.js +60 -60
- package/lib/account-usage.js +10 -10
- package/lib/api-helpers.js +109 -109
- package/lib/assistant-prefs.js +82 -59
- package/lib/auto-config.js +65 -65
- package/lib/backup.js +117 -117
- package/lib/break-reminder.js +45 -45
- package/lib/client.js +93 -93
- package/lib/config.js +234 -218
- package/lib/git-read-bundled-provider.js +12 -12
- package/lib/git-read-service.js +5 -5
- package/lib/host-compat.js +84 -84
- package/lib/http-util.js +17 -17
- package/lib/index.js +1534 -1534
- package/lib/memory/context.js +44 -44
- package/lib/memory/decay.js +93 -93
- package/lib/memory/extract.js +77 -77
- package/lib/memory/routes.js +33 -33
- package/lib/memory/store.js +196 -196
- package/lib/notify-copy.js +93 -93
- package/lib/permission-guide.js +86 -86
- package/lib/persona-cards.js +73 -65
- package/lib/phone-action-args.js +175 -0
- package/lib/phone-actions.js +227 -0
- package/lib/phone-announce.js +58 -0
- package/lib/proactive-material.js +42 -42
- package/lib/proactive.js +121 -121
- package/lib/protected-paths.js +79 -79
- package/lib/protocol.js +61 -26
- package/lib/push.js +29 -29
- package/lib/rate-limit.js +16 -16
- package/lib/relay/connector.js +246 -102
- package/lib/relay/crypto.js +15 -15
- package/lib/relay/devices.js +36 -36
- package/lib/relay/fingerprint.js +34 -34
- package/lib/relay/identity.js +26 -26
- package/lib/relay/mux.js +60 -46
- package/lib/relay/noise.js +40 -40
- package/lib/relay/on-demand.js +33 -33
- package/lib/relay/p2p.js +239 -0
- package/lib/relay/pairing.js +24 -24
- package/lib/relay/phone.js +62 -40
- package/lib/relay/serve.js +21 -21
- package/lib/relay/signal.js +69 -0
- package/lib/relay/ws-server.js +32 -32
- package/lib/reminders.js +15 -15
- package/lib/rpc-adapter.js +43 -43
- package/lib/session-list.js +31 -31
- package/lib/session-rotation.js +95 -95
- package/lib/session-title-cache.js +35 -35
- package/lib/session-title-refresh.js +51 -51
- package/lib/timeline.js +140 -140
- package/lib/turn-outline.js +104 -104
- package/package.json +3 -13
package/lib/protected-paths.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
27
|
import { lstatSync, readdirSync, realpathSync, statSync, unlinkSync } from "node:fs";
|
|
28
28
|
import { homedir } from "node:os";
|
|
29
29
|
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
@@ -33,12 +33,12 @@ const caseInsensitive = process.platform === "darwin" || process.platform === "w
|
|
|
33
33
|
const norm = (p) => (caseInsensitive ? p.normalize("NFC").toLowerCase() : p.normalize("NFC"));
|
|
34
34
|
const idOf = (st) => `${st.dev}:${st.ino}`;
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
42
|
export function realPathOf(path) {
|
|
43
43
|
let current = resolve(path);
|
|
44
44
|
const rest = [];
|
|
@@ -57,20 +57,20 @@ export function realPathOf(path) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
|
|
61
61
|
export function protectedRoots(env = process.env, home = homedir()) {
|
|
62
62
|
const dshHome = typeof env.DSH_HOME === "string" && env.DSH_HOME.trim() !== "" ? env.DSH_HOME : join(home, ".dsh");
|
|
63
63
|
return [dshHome, mobileRemoteStateDir(env, home)].map((root) => realPathOf(root));
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
function rootIds(roots) {
|
|
68
68
|
const ids = new Set();
|
|
69
69
|
for (const root of roots) {
|
|
70
70
|
try {
|
|
71
71
|
ids.add(idOf(statSync(root)));
|
|
72
72
|
} catch {
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
return ids;
|
|
@@ -81,11 +81,11 @@ const underDevice = (p) => {
|
|
|
81
81
|
const f = norm(p);
|
|
82
82
|
return DEVICE_ROOTS.some((d) => f === d || f.startsWith(`${d}/`));
|
|
83
83
|
};
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
89
|
export function isDeviceOrProcPath(path) {
|
|
90
90
|
if (process.platform === "win32") return false;
|
|
91
91
|
if (underDevice(resolve(path))) return true;
|
|
@@ -101,14 +101,14 @@ export function isDeviceOrProcPath(path) {
|
|
|
101
101
|
try {
|
|
102
102
|
ids.add(idOf(statSync(d)));
|
|
103
103
|
} catch {
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
for (let current = real; ; ) {
|
|
108
108
|
try {
|
|
109
109
|
if (ids.has(idOf(statSync(current)))) return true;
|
|
110
110
|
} catch {
|
|
111
|
-
|
|
111
|
+
|
|
112
112
|
}
|
|
113
113
|
const parent = dirname(current);
|
|
114
114
|
if (parent === current) return false;
|
|
@@ -116,19 +116,19 @@ export function isDeviceOrProcPath(path) {
|
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
|
|
120
120
|
export function isProtectedPath(target, roots = protectedRoots()) {
|
|
121
121
|
if (isDeviceOrProcPath(target)) return true;
|
|
122
122
|
let real;
|
|
123
123
|
try {
|
|
124
124
|
real = realPathOf(target);
|
|
125
125
|
} catch {
|
|
126
|
-
return true;
|
|
126
|
+
return true;
|
|
127
127
|
}
|
|
128
|
-
|
|
128
|
+
|
|
129
129
|
const r = norm(real);
|
|
130
130
|
if (roots.some((root) => r === norm(root) || r.startsWith(norm(root).endsWith(sep) ? norm(root) : `${norm(root)}${sep}`))) return true;
|
|
131
|
-
|
|
131
|
+
|
|
132
132
|
const ids = rootIds(roots);
|
|
133
133
|
if (ids.size === 0) return false;
|
|
134
134
|
let current = real;
|
|
@@ -136,7 +136,7 @@ export function isProtectedPath(target, roots = protectedRoots()) {
|
|
|
136
136
|
try {
|
|
137
137
|
if (ids.has(idOf(statSync(current)))) return true;
|
|
138
138
|
} catch {
|
|
139
|
-
|
|
139
|
+
|
|
140
140
|
}
|
|
141
141
|
const parent = dirname(current);
|
|
142
142
|
if (parent === current) return false;
|
|
@@ -144,13 +144,13 @@ export function isProtectedPath(target, roots = protectedRoots()) {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
154
|
export function protectedFileIds(roots = protectedRoots()) {
|
|
155
155
|
const [dshHome, stateDir] = roots;
|
|
156
156
|
const ids = rootIds(roots);
|
|
@@ -168,7 +168,7 @@ export function protectedFileIds(roots = protectedRoots()) {
|
|
|
168
168
|
ids.add(idOf(st));
|
|
169
169
|
if (st.isDirectory() && depth > 0) walk(path, depth - 1);
|
|
170
170
|
} catch {
|
|
171
|
-
|
|
171
|
+
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
};
|
|
@@ -177,16 +177,16 @@ export function protectedFileIds(roots = protectedRoots()) {
|
|
|
177
177
|
return ids;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
|
|
180
|
+
|
|
181
181
|
const SKIP_DIRS = new Set(["node_modules", ".pnpm-store", ".git"]);
|
|
182
|
-
|
|
182
|
+
|
|
183
183
|
export const FULL_WALK_LIMIT = 100_000;
|
|
184
184
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
190
|
export function allProtectedIds(roots = protectedRoots(), limit = FULL_WALK_LIMIT) {
|
|
191
191
|
const ids = rootIds(roots);
|
|
192
192
|
let seen = 0;
|
|
@@ -207,17 +207,17 @@ export function allProtectedIds(roots = protectedRoots(), limit = FULL_WALK_LIMI
|
|
|
207
207
|
ids.add(idOf(st));
|
|
208
208
|
if (st.isDirectory() && depth < 32 && !SKIP_DIRS.has(entry.name)) stack.push([path, depth + 1]);
|
|
209
209
|
} catch {
|
|
210
|
-
|
|
210
|
+
|
|
211
211
|
}
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
return ids;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
221
|
export function isProtectedFile(st, ids) {
|
|
222
222
|
if (!st) return false;
|
|
223
223
|
const id = idOf(st);
|
|
@@ -229,11 +229,11 @@ export function isProtectedFile(st, ids) {
|
|
|
229
229
|
return false;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
237
|
export function isStillAt(target, st, roots = protectedRoots()) {
|
|
238
238
|
try {
|
|
239
239
|
const real = realPathOf(target);
|
|
@@ -244,11 +244,11 @@ export function isStillAt(target, st, roots = protectedRoots()) {
|
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
|
|
252
252
|
export function removeCreatedEntry(target, st, roots = protectedRoots()) {
|
|
253
253
|
if (!st) return false;
|
|
254
254
|
const name = basename(target);
|
|
@@ -257,7 +257,7 @@ export function removeCreatedEntry(target, st, roots = protectedRoots()) {
|
|
|
257
257
|
try {
|
|
258
258
|
dirs.push(dirname(realPathOf(target)));
|
|
259
259
|
} catch {
|
|
260
|
-
|
|
260
|
+
|
|
261
261
|
}
|
|
262
262
|
const stack = roots.filter(Boolean).map((r) => [r, 0]);
|
|
263
263
|
let seen = 0;
|
|
@@ -283,7 +283,7 @@ export function removeCreatedEntry(target, st, roots = protectedRoots()) {
|
|
|
283
283
|
return true;
|
|
284
284
|
}
|
|
285
285
|
} catch {
|
|
286
|
-
|
|
286
|
+
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
return false;
|
package/lib/protocol.js
CHANGED
|
@@ -1,39 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
19
21
|
|
|
20
22
|
export const PROTOCOL = Object.freeze({ min: 1, max: 1 });
|
|
21
23
|
|
|
22
24
|
export const FEATURES = Object.freeze([
|
|
23
|
-
|
|
25
|
+
|
|
24
26
|
"persona-cards",
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
28
30
|
"lan-noise",
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
"p2p-signal",
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
"standby",
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
const dynamicFeatures = new Map();
|
|
46
|
+
|
|
47
|
+
export const DYNAMIC_FEATURES = Object.freeze([
|
|
48
|
+
|
|
49
|
+
"p2p",
|
|
29
50
|
]);
|
|
51
|
+
export function registerFeature(name) {
|
|
52
|
+
if (!DYNAMIC_FEATURES.includes(name)) throw new Error(`not a dynamic feature: ${name}`);
|
|
53
|
+
dynamicFeatures.set(name, (dynamicFeatures.get(name) ?? 0) + 1);
|
|
54
|
+
let done = false;
|
|
55
|
+
return () => {
|
|
56
|
+
if (done) return;
|
|
57
|
+
done = true;
|
|
58
|
+
const n = (dynamicFeatures.get(name) ?? 1) - 1;
|
|
59
|
+
if (n <= 0) dynamicFeatures.delete(name);
|
|
60
|
+
else dynamicFeatures.set(name, n);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const PHONE_ACTIONS_FEATURE = "phone-actions";
|
|
65
|
+
|
|
30
66
|
|
|
31
|
-
/** Apps older than this can't work with this plugin (none so far). */
|
|
32
67
|
export const MIN_APP_VERSION = "3.0.0";
|
|
33
68
|
|
|
34
|
-
|
|
35
|
-
export const protocolInfo = () => ({
|
|
69
|
+
|
|
70
|
+
export const protocolInfo = (extraFeatures = []) => ({
|
|
36
71
|
protocol: { min: PROTOCOL.min, max: PROTOCOL.max },
|
|
37
|
-
features: [...FEATURES],
|
|
72
|
+
features: [...FEATURES, ...dynamicFeatures.keys(), ...extraFeatures],
|
|
38
73
|
minAppVersion: MIN_APP_VERSION,
|
|
39
74
|
});
|
package/lib/push.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
20
|
export function ntfyPublish(url, payload = {}) {
|
|
21
21
|
const parsed = new URL(url);
|
|
22
22
|
const segments = parsed.pathname.split("/").filter((segment) => segment !== "");
|
|
@@ -28,33 +28,33 @@ export function ntfyPublish(url, payload = {}) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
export async function pushToChannel(logger, target, kind, kindLabel, title, detail, sessionId) {
|
|
33
33
|
const desp = detail || "详情请在 DSH Remote App 中查看";
|
|
34
34
|
let url = target.url;
|
|
35
35
|
const headers = { "user-agent": "dsh-mobile-remote" };
|
|
36
36
|
let init;
|
|
37
37
|
if (target.format === "serverchan") {
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
const params = new URLSearchParams({ title: `${kindLabel} · ${title}`, desp });
|
|
40
40
|
init = { method: "POST", headers: { ...headers, "content-type": "application/x-www-form-urlencoded" }, body: params.toString() };
|
|
41
41
|
} else if (target.format === "ntfy") {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
45
|
const publish = ntfyPublish(url, { title: `${kindLabel} · ${title}`, message: desp });
|
|
46
46
|
url = publish.url;
|
|
47
47
|
init = { method: "POST", headers: { ...headers, "content-type": "application/json" }, body: publish.body };
|
|
48
48
|
} else if (target.format === "bark") {
|
|
49
49
|
init = { method: "POST", headers: { ...headers, "content-type": "application/json" }, body: JSON.stringify({ title: `${kindLabel} · ${title}`, body: desp }) };
|
|
50
50
|
} else if (target.format === "wecom") {
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
init = { method: "POST", headers: { ...headers, "content-type": "application/json" }, body: JSON.stringify({ msgtype: "text", text: { content: `${kindLabel} · ${title}\n${desp}` } }) };
|
|
53
53
|
} else {
|
|
54
54
|
init = { method: "POST", headers: { ...headers, "content-type": "application/json" }, body: JSON.stringify({ kind, title, detail: desp, sessionId, time: Date.now() }) };
|
|
55
55
|
}
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
|
|
57
|
+
|
|
58
58
|
const pushOnce = async () => {
|
|
59
59
|
try {
|
|
60
60
|
return await fetch(url, { ...init, signal: AbortSignal.timeout(15_000) });
|
|
@@ -65,8 +65,8 @@ export async function pushToChannel(logger, target, kind, kindLabel, title, deta
|
|
|
65
65
|
};
|
|
66
66
|
const response = await pushOnce();
|
|
67
67
|
if (!response.ok) {
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
|
|
69
|
+
|
|
70
70
|
const text = (await response.text().catch(() => "")).trim().slice(0, 300);
|
|
71
71
|
throw new Error(`HTTP ${response.status}${text ? `: ${text}` : "(空响应体)"}`);
|
|
72
72
|
}
|
package/lib/rate-limit.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
9
|
export function createLoginRateLimiter(overrides) {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
|
|
11
|
+
|
|
12
12
|
const rateLimitCfg = { maxFailures: 10, windowMs: 60_000, blockMs: 60_000, ...(overrides ?? {}) };
|
|
13
|
-
const rateBuckets = new Map();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const rateBuckets = new Map();
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
18
|
const rateBlocked = (ip) => {
|
|
19
19
|
const b = rateBuckets.get(ip);
|
|
20
20
|
if (b === undefined || b.blockedUntil === undefined) return false;
|
|
@@ -31,7 +31,7 @@ export function createLoginRateLimiter(overrides) {
|
|
|
31
31
|
}
|
|
32
32
|
b.count++;
|
|
33
33
|
if (b.count >= rateLimitCfg.maxFailures) b.blockedUntil = now + rateLimitCfg.blockMs;
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
if (rateBuckets.size > 512) {
|
|
36
36
|
const oldest = [...rateBuckets.entries()]
|
|
37
37
|
.sort((x, y) => x[1].windowStart - y[1].windowStart)
|