@dsh-mobile/mobile-remote 3.2.7 → 3.3.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/FAQ.md +19 -12
- package/LICENSE +0 -0
- package/README.md +40 -40
- package/cordis.patch.yml +8 -4
- package/docs/PRIVACY-POLICY.en.md +89 -47
- package/docs/PRIVACY-POLICY.md +89 -47
- package/docs/SUPPORT.md +5 -5
- package/docs/TERMS-OF-SERVICE.en.md +5 -3
- package/docs/TERMS-OF-SERVICE.md +5 -3
- package/docs/USER-GUIDE.zh-CN.md +562 -0
- package/lib/account-usage.js +0 -0
- package/lib/api-helpers.js +6 -2
- package/lib/assistant-prefs.js +167 -0
- package/lib/auto-config.js +55 -3
- package/lib/backup.js +441 -0
- package/lib/break-reminder.js +133 -0
- package/lib/client.js +321 -77
- package/lib/config.js +96 -5
- package/lib/git-read-bundled-provider.js +32 -3
- package/lib/git-read-service.js +4 -0
- package/lib/host-compat.js +25 -0
- package/lib/http-util.js +6 -2
- package/lib/index.js +1121 -83
- package/lib/memory/context.js +81 -0
- package/lib/memory/decay.js +144 -0
- package/lib/memory/extract.js +146 -0
- package/lib/memory/routes.js +198 -0
- package/lib/memory/store.js +714 -0
- package/lib/notify-copy.js +245 -0
- package/lib/permission-guide.js +184 -0
- package/lib/persona-cards.js +366 -0
- package/lib/proactive-material.js +162 -0
- package/lib/proactive.js +372 -0
- package/lib/protected-paths.js +290 -0
- package/lib/protocol.js +39 -0
- package/lib/rate-limit.js +1 -1
- package/lib/relay/connector.js +208 -14
- package/lib/relay/devices.js +54 -8
- package/lib/relay/fingerprint.js +55 -0
- package/lib/relay/identity.js +69 -0
- package/lib/relay/on-demand.js +89 -0
- package/lib/relay/pairing.js +45 -6
- package/lib/relay/phone.js +89 -12
- package/lib/relay/ws-server.js +245 -0
- package/lib/reminders.js +140 -0
- package/lib/rpc-adapter.js +21 -2
- package/lib/session-rotation.js +198 -0
- package/lib/session-title-cache.js +0 -0
- package/lib/session-title-refresh.js +0 -0
- package/lib/timeline.js +1 -1
- package/package.json +30 -14
- package/CHANGELOG.md +0 -1383
- package/CONTRIBUTING.md +0 -61
- package/docs/00-/345/274/200/345/217/221/346/200/273/347/272/262.md +0 -432
- package/docs/01-PRD.md +0 -148
- package/docs/02-architecture.md +0 -249
- package/docs/03-api.md +0 -882
- package/docs/04-security.md +0 -110
- package/docs/05-test-cases.md +0 -376
- package/docs/06-install-run.md +0 -335
- package/docs/07-user-manual.md +0 -92
- package/docs/08-/346/211/251/345/261/225/345/274/200/345/217/221/346/214/207/345/215/227.md +0 -86
- package/docs/09-compatibility.md +0 -201
- package/docs/11-remote-relay-guide.md +0 -86
- package/docs/APP-ENCRYPTION-DESCRIPTION.md +0 -50
- package/docs/APP-ENCRYPTION-DESCRIPTION.pdf +0 -0
- package/docs/APP-REVIEW-NOTES.md +0 -105
- package/docs/BRAND-ASSETS.md +0 -142
- package/docs/COMPANION-PLAN.md +0 -199
- package/docs/STORE-LAUNCH.md +0 -341
- package/docs/STORE-LISTING.md +0 -190
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 助手偏好(模式 / 人格)的读写接口(T9)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么要这个接口:模式与人格必须**同时**作用在两个地方——
|
|
5
|
+
* 1. 推送与通知的措辞(服务端已有);
|
|
6
|
+
* 2. agent 对话时的上下文(人格决定语气、模式决定能看到哪些记忆)。
|
|
7
|
+
* 之前 App 里切换只写进了手机本地,服务端一直是默认值,于是「切成生活模式」
|
|
8
|
+
* 只改了手机上一句提示,电脑上的助手仍然拿着工作记忆在说话。这不是没做,
|
|
9
|
+
* 是做了但没生效。
|
|
10
|
+
*
|
|
11
|
+
* 落盘策略:写进 `<状态目录>/assistant.json`,重启后保持。之所以不写回
|
|
12
|
+
* `cordis.patch.yml`:那是用户手写的部署配置,插件不该去改它。
|
|
13
|
+
*/
|
|
14
|
+
import { readFileSync, writeFileSync, renameSync, mkdirSync } from "node:fs";
|
|
15
|
+
import { join } from "node:path";
|
|
16
|
+
import { parseHm } from "./notify-copy.js";
|
|
17
|
+
|
|
18
|
+
const MODES = ["work", "life"];
|
|
19
|
+
/** Persona card ids (T-31): same rule as lib/persona-cards.js validatePersonaCard. */
|
|
20
|
+
const PERSONA_CARD_ID = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
21
|
+
const PERSONAS = ["colleague", "character"];
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 安静时段的合法性判断。返回 `true` 表示两个时间点都能解析。
|
|
25
|
+
*
|
|
26
|
+
* 故意不接受「猜一个默认值」:配置写错时宁可多吵一次,
|
|
27
|
+
* 也不要把用户的通知整段吞掉(见 config.js 里同一条注释)。
|
|
28
|
+
*/
|
|
29
|
+
function validWindow(start, end) {
|
|
30
|
+
return parseHm(start) !== null && parseHm(end) !== null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {object} options
|
|
35
|
+
* @param {string} options.dir 状态目录(与 auth-token、记忆库同层)
|
|
36
|
+
* @param {() => {mode: string, persona: string, quietHours?: {start: string, end: string}}} options.defaults 配置里的默认值
|
|
37
|
+
*/
|
|
38
|
+
export function createAssistantPrefs({ dir, defaults }) {
|
|
39
|
+
const file = join(dir, "assistant.json");
|
|
40
|
+
/**
|
|
41
|
+
* Only what the app (or the user) explicitly set (A-21): the effective value of anything else is
|
|
42
|
+
* worked out on every read from the config and the defaults, so a later config change still
|
|
43
|
+
* applies. Files written before 3.3.1 (no `v: 2`) stored the merged object, so in them a
|
|
44
|
+
* `breakReminder: true` may be a default that was copied in, not the app's switch (A-13): it is not
|
|
45
|
+
* taken as explicit. Everything else in an old file is kept as explicit, as before.
|
|
46
|
+
*/
|
|
47
|
+
let explicit = null;
|
|
48
|
+
|
|
49
|
+
function readExplicit() {
|
|
50
|
+
if (explicit) return explicit;
|
|
51
|
+
let raw;
|
|
52
|
+
try {
|
|
53
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
54
|
+
} catch {
|
|
55
|
+
raw = null;
|
|
56
|
+
}
|
|
57
|
+
const legacy = raw && raw.v !== 2;
|
|
58
|
+
const e = {};
|
|
59
|
+
if (raw && typeof raw === "object") {
|
|
60
|
+
if (MODES.includes(raw.mode)) e.mode = raw.mode;
|
|
61
|
+
if (PERSONAS.includes(raw.persona)) e.persona = raw.persona;
|
|
62
|
+
// 安静时段单独校验:文件里可能是旧版本写的、也可能是手改坏的。
|
|
63
|
+
// 只有两个端点都合法才采用,否则整体回落到配置值——半个窗口比没有更糟。
|
|
64
|
+
const quiet = raw.quietHours;
|
|
65
|
+
if (quiet && validWindow(quiet.start, quiet.end)) e.quietHours = { start: quiet.start, end: quiet.end };
|
|
66
|
+
if (typeof raw.breakReminder === "boolean" && !(legacy && raw.breakReminder === true)) e.breakReminder = raw.breakReminder;
|
|
67
|
+
// T-31: the active persona card (an id). Absent = the old colleague/character switch decides.
|
|
68
|
+
if (PERSONA_CARD_ID.test(raw.personaCard ?? "")) e.personaCard = raw.personaCard;
|
|
69
|
+
}
|
|
70
|
+
explicit = e;
|
|
71
|
+
return explicit;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Explicit values over the config's defaults over the built-in defaults. */
|
|
75
|
+
function effective() {
|
|
76
|
+
const e = readExplicit();
|
|
77
|
+
const fallback = defaults();
|
|
78
|
+
return {
|
|
79
|
+
mode: e.mode ?? fallback.mode,
|
|
80
|
+
persona: e.persona ?? fallback.persona,
|
|
81
|
+
quietHours: { ...(e.quietHours ?? fallback.quietHours ?? { start: "23:30", end: "08:30" }) },
|
|
82
|
+
// T-15: the user's own off switch for the break reminder (on unless they turned it off).
|
|
83
|
+
breakReminder: e.breakReminder ?? true,
|
|
84
|
+
...(e.personaCard ? { personaCard: e.personaCard } : {}),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function save(next) {
|
|
89
|
+
mkdirSync(dir, { recursive: true });
|
|
90
|
+
// 原子写:先写临时文件再 rename,避免断电/崩溃留下半个 JSON。
|
|
91
|
+
const tmp = `${file}.tmp`;
|
|
92
|
+
writeFileSync(tmp, JSON.stringify({ v: 2, ...next }, null, 2), "utf8");
|
|
93
|
+
renameSync(tmp, file);
|
|
94
|
+
explicit = next;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
file,
|
|
99
|
+
/** 当前有效的模式与人格。 */
|
|
100
|
+
get: () => effective(),
|
|
101
|
+
/**
|
|
102
|
+
* Has the app ever sent its break-reminder switch (A-13)? Store apps up to 3.2.7 have no such
|
|
103
|
+
* switch, so for them the reminder stays off unless the PC config turns it on.
|
|
104
|
+
*/
|
|
105
|
+
breakReminderSetByApp: () => typeof readExplicit().breakReminder === "boolean",
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 改一项或两项。非法值直接拒绝,不「猜一个最近的」:
|
|
109
|
+
* 猜错会让用户以为切换成功,实际还在原来的模式里。
|
|
110
|
+
* Returns the effective prefs and `changed`: whether any effective value differs (A-20: the
|
|
111
|
+
* app's automatic re-sync on every reconnect changes nothing and is not someone's activity).
|
|
112
|
+
*/
|
|
113
|
+
set(patch) {
|
|
114
|
+
const before = JSON.stringify(effective());
|
|
115
|
+
const next = { ...readExplicit() };
|
|
116
|
+
if (patch?.mode !== undefined) {
|
|
117
|
+
if (!MODES.includes(patch.mode)) {
|
|
118
|
+
throw new Error(`mode 必须是 ${MODES.join(" / ")}`);
|
|
119
|
+
}
|
|
120
|
+
next.mode = patch.mode;
|
|
121
|
+
}
|
|
122
|
+
if (patch?.persona !== undefined) {
|
|
123
|
+
if (!PERSONAS.includes(patch.persona)) {
|
|
124
|
+
throw new Error(`persona 必须是 ${PERSONAS.join(" / ")}`);
|
|
125
|
+
}
|
|
126
|
+
next.persona = patch.persona;
|
|
127
|
+
}
|
|
128
|
+
if (patch?.quietHours !== undefined) {
|
|
129
|
+
const start = patch.quietHours?.start;
|
|
130
|
+
const end = patch.quietHours?.end;
|
|
131
|
+
if (!validWindow(start, end)) {
|
|
132
|
+
// 不静默保留旧值:用户会以为自己改成功了,夜里照样被吵醒。
|
|
133
|
+
throw new Error("quietHours 必须是 {start: \"HH:MM\", end: \"HH:MM\"}");
|
|
134
|
+
}
|
|
135
|
+
next.quietHours = { start, end };
|
|
136
|
+
}
|
|
137
|
+
if (patch?.personaCard !== undefined) {
|
|
138
|
+
if (typeof patch.personaCard !== "string" || !PERSONA_CARD_ID.test(patch.personaCard)) {
|
|
139
|
+
throw new Error("personaCard 必须是人格卡的 id / personaCard must be a persona card id");
|
|
140
|
+
}
|
|
141
|
+
next.personaCard = patch.personaCard;
|
|
142
|
+
}
|
|
143
|
+
if (patch?.breakReminder !== undefined) {
|
|
144
|
+
if (typeof patch.breakReminder !== "boolean") throw new Error("breakReminder 必须是 true / false");
|
|
145
|
+
next.breakReminder = patch.breakReminder;
|
|
146
|
+
}
|
|
147
|
+
const explicitChanged = JSON.stringify(next) !== JSON.stringify(readExplicit());
|
|
148
|
+
if (explicitChanged) save(next);
|
|
149
|
+
const after = effective();
|
|
150
|
+
return { ...after, changed: JSON.stringify(after) !== before };
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// personaBrief was removed with T-31 (D8): the active persona card's own text is the only
|
|
156
|
+
// persona text the model sees (lib/persona-cards.js, personaPromptText).
|
|
157
|
+
|
|
158
|
+
/** 模式 → 一段给模型看的说明。生活模式明确要求不提工作内容。 */
|
|
159
|
+
export function modeBrief(mode) {
|
|
160
|
+
if (mode === "life") {
|
|
161
|
+
return [
|
|
162
|
+
"当前是生活模式:不主动提项目、客户、报错、未发布的功能。",
|
|
163
|
+
"记忆里工作范围的内容这一轮看不到,也不要凭印象补出来。",
|
|
164
|
+
].join("\n");
|
|
165
|
+
}
|
|
166
|
+
return "当前是工作模式:可以使用项目与长期记忆,回答以可执行、可核对为准。";
|
|
167
|
+
}
|
package/lib/auto-config.js
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* - `lanBridge.enabled: "auto"` 仅在需要时开桥(桌面版 webserver 只听回环)。
|
|
9
9
|
* - `formatConnectionBanner` 启动时把手机 App 需要填的两项(地址 + 口令)打印出来。
|
|
10
10
|
*
|
|
11
|
-
* 向后兼容:`authToken`
|
|
11
|
+
* 向后兼容:`authToken` 为空仅在服务只有本机可达时表示「关闭认证」,否则按 `@auto` 处理(T-03,见
|
|
12
|
+
* `effectiveAuthSetting`);`lanBridge.enabled` 仍可写 true/false;
|
|
12
13
|
* 这些「自动」值只会出现在插件自带的 `cordis.patch.yml` 里,已有手写配置的用户行为不变。
|
|
13
14
|
*/
|
|
14
15
|
import { randomBytes } from "node:crypto";
|
|
@@ -32,7 +33,7 @@ export function mobileRemoteStateDir(env = process.env, home = homedir()) {
|
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* 解析 `authToken`。
|
|
35
|
-
* - 不是 `@auto`:原样返回(空串 =
|
|
36
|
+
* - 不是 `@auto`:原样返回(空串 = 关闭认证;调用方只在服务仅本机可达时才会传空串,见 effectiveAuthSetting)。
|
|
36
37
|
* - `@auto`:读 `<stateDir>/auth-token`;没有或损坏就生成新的并原子写入(0600)。
|
|
37
38
|
* 写盘失败不阻断启动:本次进程内用内存口令,但会返回 `persistError`,调用方应提示
|
|
38
39
|
* 「重启后口令会变,手机需要重新配对」。
|
|
@@ -60,6 +61,49 @@ export function resolveAuthToken(configured, { dir = mobileRemoteStateDir(), gen
|
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
/**
|
|
65
|
+
* T-03 (finding E6): whether nothing but this computer can reach the mobile API.
|
|
66
|
+
*
|
|
67
|
+
* True only when the DSH webserver listens on a loopback address and none of the ways out
|
|
68
|
+
* is on: no LAN bridge, no `trustedHosts` (a tunnel or reverse proxy), no relay (it replays
|
|
69
|
+
* phone requests into this server). An unknown webserver host counts as reachable, so the
|
|
70
|
+
* answer fails closed.
|
|
71
|
+
*/
|
|
72
|
+
export function isLoopbackOnly({ webHost, lanBridgeEnabled = false, trustedHosts = [], relayEnabled = false } = {}) {
|
|
73
|
+
if (typeof webHost !== "string" || !LOOPBACK_HOSTS.has(webHost.trim().toLowerCase())) return false;
|
|
74
|
+
if (lanBridgeEnabled || relayEnabled) return false;
|
|
75
|
+
return !(Array.isArray(trustedHosts) && trustedHosts.length > 0);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* T-03 (finding E6): the `authToken` setting to resolve.
|
|
80
|
+
*
|
|
81
|
+
* An empty token used to switch authentication off wherever the server was reachable, so a
|
|
82
|
+
* user config that replaced the shipped `"@auto"` and left the token out opened an agent with
|
|
83
|
+
* shell access to the whole LAN. Now an empty (or missing) token means "off" only when the
|
|
84
|
+
* server is loopback-only (`isLoopbackOnly`); everywhere else it is treated as `"@auto"`.
|
|
85
|
+
* A non-empty value is returned unchanged.
|
|
86
|
+
*/
|
|
87
|
+
export function effectiveAuthSetting(configured, reach = {}) {
|
|
88
|
+
if (typeof configured === "string" && configured !== "") return configured;
|
|
89
|
+
return isLoopbackOnly(reach) ? "" : AUTO;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Replace an auto-managed token with a fresh one (T-62: after a device is revoked). Written
|
|
94
|
+
* atomically over `<dir>/auth-token` (0600). Only for `@auto` tokens: a token the owner wrote
|
|
95
|
+
* into their config is theirs to change. Throws when the file cannot be written.
|
|
96
|
+
*/
|
|
97
|
+
export function rotateAuthToken({ dir = mobileRemoteStateDir(), generate = () => randomBytes(24).toString("base64url") } = {}) {
|
|
98
|
+
const file = join(dir, "auth-token");
|
|
99
|
+
const token = generate();
|
|
100
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
101
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
102
|
+
writeFileSync(tmp, `${token}\n`, { mode: 0o600 });
|
|
103
|
+
renameSync(tmp, file);
|
|
104
|
+
return { token, file };
|
|
105
|
+
}
|
|
106
|
+
|
|
63
107
|
/**
|
|
64
108
|
* 解析 `lanBridge.enabled`:true/false 原样;`"auto"` = 需要才开。
|
|
65
109
|
* 「需要」= webserver 只听回环(桌面版强制如此,手机直连不了)。web 版 webserver 已经听 0.0.0.0,
|
|
@@ -85,13 +129,21 @@ export function resolveLanBridgePort(setting, port, webPort) {
|
|
|
85
129
|
* 启动时打印给人看的「手机 App 要填的两项」。
|
|
86
130
|
* 口令只在**自动生成**时打印——那是用户唯一能第一时间拿到它的地方;用户自己写进配置的口令不进日志。
|
|
87
131
|
*/
|
|
88
|
-
|
|
132
|
+
/**
|
|
133
|
+
* T-62 (E11): an auto token is printed only on the start that generated it (`tokenNew`). Later
|
|
134
|
+
* starts say where it is saved instead: stderr often ends up in log files.
|
|
135
|
+
*/
|
|
136
|
+
export function formatConnectionBanner({ addresses, token, tokenIsAuto, tokenNew = true, tokenFile, persistError, authEnabled = true }) {
|
|
89
137
|
const [first, ...rest] = addresses;
|
|
90
138
|
const lines = ["mobile-remote ▶ 手机 App 连接信息 / Phone app connection"];
|
|
91
139
|
lines.push(` 电脑地址 Address : ${first}`);
|
|
92
140
|
for (const extra of rest) lines.push(` ${extra} (备用 alternative)`);
|
|
93
141
|
if (!authEnabled) {
|
|
94
142
|
lines.push(" 访问口令 Token : (未启用认证 / authentication is OFF)");
|
|
143
|
+
} else if (tokenIsAuto && !tokenNew) {
|
|
144
|
+
lines.push(
|
|
145
|
+
` 访问口令 Token : (已保存在 ${tokenFile ?? "状态目录"};也可在 DSH 设置页「连接移动端设备」查看 / saved in ${tokenFile ?? "the state folder"}; also shown in DSH settings)`,
|
|
146
|
+
);
|
|
95
147
|
} else if (tokenIsAuto) {
|
|
96
148
|
lines.push(` 访问口令 Token : ${token}`);
|
|
97
149
|
if (persistError) {
|