@dsh-mobile/mobile-remote 3.3.0 → 3.4.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/FAQ.md +2 -2
- package/LICENSE +0 -0
- package/README.md +13 -8
- package/docs/PRIVACY-POLICY.en.md +26 -18
- package/docs/PRIVACY-POLICY.md +26 -18
- package/docs/SUPPORT.md +1 -1
- package/docs/TERMS-OF-SERVICE.en.md +5 -3
- package/docs/TERMS-OF-SERVICE.md +5 -3
- package/docs/USER-GUIDE.zh-CN.md +7 -6
- package/lib/account-usage-query.js +60 -60
- package/lib/account-usage.js +10 -10
- package/lib/api-helpers.js +114 -110
- package/lib/assistant-prefs.js +119 -76
- package/lib/auto-config.js +65 -65
- package/lib/backup.js +159 -123
- package/lib/break-reminder.js +45 -45
- package/lib/client.js +336 -138
- package/lib/config.js +234 -218
- package/lib/git-read-bundled-provider.js +27 -7
- 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 +1670 -1511
- package/lib/memory/context.js +45 -40
- 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 +239 -192
- package/lib/notify-copy.js +93 -93
- package/lib/permission-guide.js +86 -86
- package/lib/persona-cards.js +73 -61
- 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 +122 -119
- package/lib/protected-paths.js +205 -45
- package/lib/protocol.js +62 -23
- package/lib/push.js +29 -29
- package/lib/rate-limit.js +16 -16
- package/lib/relay/connector.js +334 -81
- package/lib/relay/crypto.js +15 -15
- package/lib/relay/devices.js +64 -32
- 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 +36 -31
- package/lib/relay/p2p.js +239 -0
- package/lib/relay/pairing.js +54 -15
- package/lib/relay/phone.js +63 -39
- package/lib/relay/serve.js +21 -21
- package/lib/relay/signal.js +69 -0
- package/lib/relay/ws-server.js +245 -0
- 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 +11 -18
package/lib/api-helpers.js
CHANGED
|
@@ -1,40 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
5
|
import { extname } from "node:path";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const REDACT_PATH_PATTERN = /(?:\/[
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const REDACT_PATH_PATTERN = /(?:\/[\p{L}\p{N}\p{M}_.~@+-]+){2,}|[A-Za-z]:\\[^\s"']*/gu;
|
|
13
|
+
|
|
14
|
+
const REDACT_QUOTED_PATH = /(['"`])(?:\/|[A-Za-z]:\\)[^'"`\n]*\1/g;
|
|
13
15
|
|
|
14
16
|
export function redactPathText(value) {
|
|
15
|
-
return String(value ?? "")
|
|
17
|
+
return String(value ?? "")
|
|
18
|
+
.replace(REDACT_QUOTED_PATH, "$1<redacted>$1")
|
|
19
|
+
.replace(REDACT_PATH_PATTERN, "<redacted>");
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
24
28
|
export const FILE_RANGE_CAPABILITIES = {
|
|
25
29
|
version: 1,
|
|
26
30
|
supported: true,
|
|
27
31
|
};
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
|
|
30
34
|
export function requestHeaderText(req, name) {
|
|
31
35
|
const raw = req?.headers?.[name];
|
|
32
36
|
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
33
37
|
return typeof value === "string" ? value : "";
|
|
34
38
|
}
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
|
|
41
|
+
|
|
38
42
|
export function clampText(text, max) {
|
|
39
43
|
text = text === undefined || text === null ? "" : String(text);
|
|
40
44
|
if (text.length <= max) return text;
|
|
@@ -43,7 +47,7 @@ export function clampText(text, max) {
|
|
|
43
47
|
return keep > 0 ? `${text.slice(0, keep)}${suffix}` : text.slice(0, max);
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
|
|
47
51
|
const FILE_MIME = {
|
|
48
52
|
".txt": "text/plain; charset=utf-8", ".md": "text/markdown; charset=utf-8", ".json": "application/json",
|
|
49
53
|
".pdf": "application/pdf", ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg",
|
|
@@ -57,11 +61,11 @@ const FILE_MIME = {
|
|
|
57
61
|
|
|
58
62
|
export const fileMimeOf = (name) => FILE_MIME[extname(name).toLowerCase()] ?? "application/octet-stream";
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
65
69
|
export const mapBounded = async (items, width, worker) => {
|
|
66
70
|
const list = [...items];
|
|
67
71
|
if (list.length === 0) return [];
|
|
@@ -75,34 +79,34 @@ export const mapBounded = async (items, width, worker) => {
|
|
|
75
79
|
results[index] = await worker(list[index], index);
|
|
76
80
|
}
|
|
77
81
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
82
86
|
const settled = await Promise.allSettled(Array.from({ length: Math.min(width, list.length) }, run));
|
|
83
87
|
const failed = settled.find((entry) => entry.status === "rejected");
|
|
84
88
|
if (failed) throw failed.reason;
|
|
85
89
|
return results;
|
|
86
90
|
};
|
|
87
91
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
106
110
|
export const orderQrAddresses = (ips) => {
|
|
107
111
|
const rankOf = (ip) => {
|
|
108
112
|
const o = String(ip).split(".").map(Number);
|
|
@@ -116,18 +120,18 @@ export const orderQrAddresses = (ips) => {
|
|
|
116
120
|
const rank = rankOf(ip);
|
|
117
121
|
return rank === 0 || rank === 1;
|
|
118
122
|
});
|
|
119
|
-
|
|
123
|
+
|
|
120
124
|
const adjusted = (ip) => (rankOf(ip) === 2 && !hasLanPrivate ? 0 : rankOf(ip));
|
|
121
125
|
return [...ips].sort((a, b) => adjusted(a) - adjusted(b));
|
|
122
126
|
};
|
|
123
127
|
|
|
124
|
-
|
|
128
|
+
|
|
125
129
|
export function receiptExpired(at, now, ttl = 15 * 60 * 1000) {
|
|
126
130
|
return now - at > ttl;
|
|
127
131
|
}
|
|
128
132
|
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
|
|
134
|
+
|
|
131
135
|
export function pruneReceiptMap(receipts, now = Date.now(), ttl = 15 * 60 * 1000, max = 2000) {
|
|
132
136
|
let changed = false;
|
|
133
137
|
for (const [k, v] of receipts) {
|
|
@@ -137,27 +141,27 @@ export function pruneReceiptMap(receipts, now = Date.now(), ttl = 15 * 60 * 1000
|
|
|
137
141
|
return changed;
|
|
138
142
|
}
|
|
139
143
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
145
149
|
export function normalizeServerPath(p, platform = process.platform) {
|
|
146
150
|
if (typeof p !== "string") return p;
|
|
147
151
|
return platform === "win32" ? p.replaceAll("/", "\\") : p.replaceAll("\\", "/");
|
|
148
152
|
}
|
|
149
153
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
161
165
|
export function validateQuestionAnswers(questions, answers) {
|
|
162
166
|
if (!Array.isArray(questions) || questions.length === 0) {
|
|
163
167
|
return { ok: false, code: "question-answer-invalid", detail: "问询条目缺少 questions" };
|
|
@@ -167,7 +171,7 @@ export function validateQuestionAnswers(questions, answers) {
|
|
|
167
171
|
}
|
|
168
172
|
const byId = new Map();
|
|
169
173
|
for (const answer of answers) {
|
|
170
|
-
|
|
174
|
+
|
|
171
175
|
if (!answer || typeof answer !== "object" || typeof answer.id !== "string" || byId.has(answer.id)) {
|
|
172
176
|
return { ok: false, code: "question-answer-invalid", detail: "答案 id 无效或重复" };
|
|
173
177
|
}
|
|
@@ -179,8 +183,8 @@ export function validateQuestionAnswers(questions, answers) {
|
|
|
179
183
|
}
|
|
180
184
|
const answer = byId.get(question.id);
|
|
181
185
|
if (!answer) return { ok: false, code: "question-answer-invalid", detail: `缺少问题 ${question.id} 的答案` };
|
|
182
|
-
|
|
183
|
-
|
|
186
|
+
|
|
187
|
+
|
|
184
188
|
if (!Object.hasOwn(answer, "selected") || !Array.isArray(answer.selected)) {
|
|
185
189
|
return { ok: false, code: "question-answer-invalid", detail: `问题 ${question.id} 的 selected 无效` };
|
|
186
190
|
}
|
|
@@ -217,14 +221,14 @@ export function validateQuestionAnswers(questions, answers) {
|
|
|
217
221
|
return { ok: true };
|
|
218
222
|
}
|
|
219
223
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
228
232
|
export const classifyFetchFailure = (err) => {
|
|
229
233
|
const name = typeof err?.name === "string" ? err.name : "";
|
|
230
234
|
const code = typeof err?.code === "string" ? err.code : (typeof err?.cause?.code === "string" ? err.cause.code : "");
|
|
@@ -234,9 +238,9 @@ export const classifyFetchFailure = (err) => {
|
|
|
234
238
|
if (code === "ECONNREFUSED") return "connection-refused";
|
|
235
239
|
if (code === "ECONNRESET") return "connection-reset";
|
|
236
240
|
if (code === "UND_ERR_SOCKET") return "socket-error";
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
240
244
|
if (code === "OPENAI_CODEX_REAUTH_REQUIRED") return "reauth-required";
|
|
241
245
|
const status = Number.isInteger(err?.status)
|
|
242
246
|
? err.status
|
|
@@ -244,13 +248,13 @@ export const classifyFetchFailure = (err) => {
|
|
|
244
248
|
if (status !== undefined && status >= 400 && status <= 599) {
|
|
245
249
|
return status === 429 ? "rate-limited" : "http-error";
|
|
246
250
|
}
|
|
247
|
-
|
|
248
|
-
|
|
251
|
+
|
|
252
|
+
|
|
249
253
|
if (name === "TypeError") return "invalid-request";
|
|
250
254
|
return "unreachable";
|
|
251
255
|
};
|
|
252
256
|
|
|
253
|
-
|
|
257
|
+
|
|
254
258
|
const FAILURE_SUMMARY = {
|
|
255
259
|
timeout: "请求超时",
|
|
256
260
|
"connect-timeout": "连接超时",
|
|
@@ -259,34 +263,34 @@ const FAILURE_SUMMARY = {
|
|
|
259
263
|
"connection-reset": "连接被重置",
|
|
260
264
|
"socket-error": "连接异常中断",
|
|
261
265
|
"invalid-request": "请求构造被拒(可能是凭据或地址形态问题)",
|
|
262
|
-
|
|
266
|
+
|
|
263
267
|
"reauth-required": "需重新登录",
|
|
264
268
|
"rate-limited": "请求被限流",
|
|
265
269
|
"http-error": "服务端返回错误",
|
|
266
270
|
unreachable: "网络不可达",
|
|
267
271
|
};
|
|
268
272
|
|
|
269
|
-
|
|
273
|
+
|
|
270
274
|
export const safeFailureReason = (err) => {
|
|
271
275
|
const code = classifyFetchFailure(err);
|
|
272
276
|
return `${code}(${FAILURE_SUMMARY[code] ?? FAILURE_SUMMARY.unreachable})`;
|
|
273
277
|
};
|
|
274
278
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
290
294
|
export const requestAbort = (res) => {
|
|
291
295
|
const ac = new AbortController();
|
|
292
296
|
res.once("close", () => {
|
|
@@ -295,14 +299,14 @@ export const requestAbort = (res) => {
|
|
|
295
299
|
return ac.signal;
|
|
296
300
|
};
|
|
297
301
|
|
|
298
|
-
/** 插件主体。 */
|
|
299
302
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
|
|
306
310
|
export const parseByteRange = (value, size) => {
|
|
307
311
|
const text = String(value ?? "").trim();
|
|
308
312
|
if (text === "") return null;
|
|
@@ -321,7 +325,7 @@ export const parseByteRange = (value, size) => {
|
|
|
321
325
|
if (!Number.isSafeInteger(end) || end < start) return { invalid: true };
|
|
322
326
|
return { start, end: Math.min(end, size - 1) };
|
|
323
327
|
};
|
|
324
|
-
|
|
328
|
+
|
|
325
329
|
export const ifNoneMatch = (req, etag) => {
|
|
326
330
|
if (!etag) return false;
|
|
327
331
|
const raw = requestHeaderText(req, "if-none-match");
|
package/lib/assistant-prefs.js
CHANGED
|
@@ -1,100 +1,137 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
14
|
import { readFileSync, writeFileSync, renameSync, mkdirSync } from "node:fs";
|
|
15
15
|
import { join } from "node:path";
|
|
16
16
|
import { parseHm } from "./notify-copy.js";
|
|
17
17
|
|
|
18
18
|
const MODES = ["work", "life"];
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
const PERSONA_CARD_ID = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
21
21
|
const PERSONAS = ["colleague", "character"];
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const NO_PERSONA_ID = "none";
|
|
24
|
+
|
|
25
|
+
const UNPICKED_LEGACY_CARDS = ["workaholic", "life-assistant"];
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
29
33
|
function validWindow(start, end) {
|
|
30
34
|
return parseHm(start) !== null && parseHm(end) !== null;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
38
42
|
export function createAssistantPrefs({ dir, defaults }) {
|
|
39
43
|
const file = join(dir, "assistant.json");
|
|
40
|
-
let cached = null;
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
let explicit = null;
|
|
60
|
+
|
|
61
|
+
function readExplicit() {
|
|
62
|
+
if (explicit) return explicit;
|
|
63
|
+
let raw;
|
|
45
64
|
try {
|
|
46
|
-
|
|
47
|
-
// 安静时段单独校验:文件里可能是旧版本写的、也可能是手改坏的。
|
|
48
|
-
// 只有两个端点都合法才采用,否则整体回落到配置值——半个窗口比没有更糟。
|
|
49
|
-
const quiet = raw?.quietHours;
|
|
50
|
-
const quietOk =
|
|
51
|
-
quiet && validWindow(quiet.start, quiet.end)
|
|
52
|
-
? { start: quiet.start, end: quiet.end }
|
|
53
|
-
: fallback.quietHours;
|
|
54
|
-
cached = {
|
|
55
|
-
mode: MODES.includes(raw?.mode) ? raw.mode : fallback.mode,
|
|
56
|
-
persona: PERSONAS.includes(raw?.persona) ? raw.persona : fallback.persona,
|
|
57
|
-
quietHours: quietOk
|
|
58
|
-
? { start: quietOk.start, end: quietOk.end }
|
|
59
|
-
: { start: "23:30", end: "08:30" },
|
|
60
|
-
// T-15: the user's own off switch for the break reminder (on unless they turned it off).
|
|
61
|
-
breakReminder: typeof raw?.breakReminder === "boolean" ? raw.breakReminder : true,
|
|
62
|
-
// T-31: the active persona card (an id). Absent = the old colleague/character switch decides.
|
|
63
|
-
...(PERSONA_CARD_ID.test(raw?.personaCard ?? "") ? { personaCard: raw.personaCard } : {}),
|
|
64
|
-
};
|
|
65
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
65
66
|
} catch {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
raw = null;
|
|
68
|
+
}
|
|
69
|
+
const legacy = raw && !(raw.v >= 2);
|
|
70
|
+
const preNoCardDefault = raw && !(raw.v >= 3);
|
|
71
|
+
const e = {};
|
|
72
|
+
if (raw && typeof raw === "object") {
|
|
73
|
+
if (MODES.includes(raw.mode)) e.mode = raw.mode;
|
|
74
|
+
if (PERSONAS.includes(raw.persona)) e.persona = raw.persona;
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
const quiet = raw.quietHours;
|
|
78
|
+
if (quiet && validWindow(quiet.start, quiet.end)) e.quietHours = { start: quiet.start, end: quiet.end };
|
|
79
|
+
if (typeof raw.breakReminder === "boolean" && !(legacy && raw.breakReminder === true)) e.breakReminder = raw.breakReminder;
|
|
80
|
+
|
|
81
|
+
if (
|
|
82
|
+
PERSONA_CARD_ID.test(raw.personaCard ?? "") &&
|
|
83
|
+
raw.personaCard !== NO_PERSONA_ID &&
|
|
84
|
+
!(preNoCardDefault && UNPICKED_LEGACY_CARDS.includes(raw.personaCard))
|
|
85
|
+
) {
|
|
86
|
+
e.personaCard = raw.personaCard;
|
|
87
|
+
}
|
|
73
88
|
}
|
|
74
|
-
|
|
89
|
+
explicit = e;
|
|
90
|
+
return explicit;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
function effective() {
|
|
95
|
+
const e = readExplicit();
|
|
96
|
+
const fallback = defaults();
|
|
97
|
+
return {
|
|
98
|
+
mode: e.mode ?? fallback.mode,
|
|
99
|
+
persona: e.persona ?? fallback.persona,
|
|
100
|
+
quietHours: { ...(e.quietHours ?? fallback.quietHours ?? { start: "23:30", end: "08:30" }) },
|
|
101
|
+
|
|
102
|
+
breakReminder: e.breakReminder ?? true,
|
|
103
|
+
...(e.personaCard ? { personaCard: e.personaCard } : {}),
|
|
104
|
+
};
|
|
75
105
|
}
|
|
76
106
|
|
|
77
107
|
function save(next) {
|
|
78
108
|
mkdirSync(dir, { recursive: true });
|
|
79
|
-
|
|
109
|
+
|
|
80
110
|
const tmp = `${file}.tmp`;
|
|
81
|
-
writeFileSync(tmp, JSON.stringify(next, null, 2), "utf8");
|
|
111
|
+
writeFileSync(tmp, JSON.stringify({ v: 3, ...next }, null, 2), "utf8");
|
|
82
112
|
renameSync(tmp, file);
|
|
83
|
-
|
|
113
|
+
explicit = next;
|
|
84
114
|
}
|
|
85
115
|
|
|
86
116
|
return {
|
|
87
117
|
file,
|
|
88
|
-
/** 当前有效的模式与人格。 */
|
|
89
|
-
get: () => ({ ...load() }),
|
|
90
118
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
119
|
+
get: () => effective(),
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
breakReminderSetByApp: () => typeof readExplicit().breakReminder === "boolean",
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
95
132
|
set(patch) {
|
|
96
|
-
const
|
|
97
|
-
const next = { ...
|
|
133
|
+
const before = JSON.stringify(effective());
|
|
134
|
+
const next = { ...readExplicit() };
|
|
98
135
|
if (patch?.mode !== undefined) {
|
|
99
136
|
if (!MODES.includes(patch.mode)) {
|
|
100
137
|
throw new Error(`mode 必须是 ${MODES.join(" / ")}`);
|
|
@@ -111,31 +148,37 @@ export function createAssistantPrefs({ dir, defaults }) {
|
|
|
111
148
|
const start = patch.quietHours?.start;
|
|
112
149
|
const end = patch.quietHours?.end;
|
|
113
150
|
if (!validWindow(start, end)) {
|
|
114
|
-
|
|
151
|
+
|
|
115
152
|
throw new Error("quietHours 必须是 {start: \"HH:MM\", end: \"HH:MM\"}");
|
|
116
153
|
}
|
|
117
154
|
next.quietHours = { start, end };
|
|
118
155
|
}
|
|
119
156
|
if (patch?.personaCard !== undefined) {
|
|
120
|
-
if (
|
|
121
|
-
|
|
157
|
+
if (patch.personaCard === null || patch.personaCard === NO_PERSONA_ID) {
|
|
158
|
+
|
|
159
|
+
delete next.personaCard;
|
|
160
|
+
} else if (typeof patch.personaCard !== "string" || !PERSONA_CARD_ID.test(patch.personaCard)) {
|
|
161
|
+
throw new Error('personaCard 必须是人格卡的 id 或 "none" / personaCard must be a persona card id or "none"');
|
|
162
|
+
} else {
|
|
163
|
+
next.personaCard = patch.personaCard;
|
|
122
164
|
}
|
|
123
|
-
next.personaCard = patch.personaCard;
|
|
124
165
|
}
|
|
125
166
|
if (patch?.breakReminder !== undefined) {
|
|
126
167
|
if (typeof patch.breakReminder !== "boolean") throw new Error("breakReminder 必须是 true / false");
|
|
127
168
|
next.breakReminder = patch.breakReminder;
|
|
128
169
|
}
|
|
129
|
-
|
|
130
|
-
|
|
170
|
+
const explicitChanged = JSON.stringify(next) !== JSON.stringify(readExplicit());
|
|
171
|
+
if (explicitChanged) save(next);
|
|
172
|
+
const after = effective();
|
|
173
|
+
return { ...after, changed: JSON.stringify(after) !== before };
|
|
131
174
|
},
|
|
132
175
|
};
|
|
133
176
|
}
|
|
134
177
|
|
|
135
|
-
// personaBrief was removed with T-31 (D8): the active persona card's own text is the only
|
|
136
|
-
// persona text the model sees (lib/persona-cards.js, personaPromptText).
|
|
137
178
|
|
|
138
|
-
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
139
182
|
export function modeBrief(mode) {
|
|
140
183
|
if (mode === "life") {
|
|
141
184
|
return [
|