@kanadego/dsh-heartbeat 2.2.1 → 2.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/README.md +105 -311
- package/USAGE-GUIDE.md +357 -0
- package/client.js +186 -24
- package/dist/{bili-login-XQVEE4M6.js → bili-login-KDDU63Z2.js} +4 -4
- package/dist/{bindings-U2M3CO2D.js → bindings-LTSGGNIH.js} +3 -3
- package/dist/{chunk-LQKOYTRL.js → chunk-4OQXAHU5.js} +2 -2
- package/dist/{chunk-3QJJRXIR.js → chunk-5CVAW5AS.js} +11 -2
- package/dist/chunk-5CVAW5AS.js.map +1 -0
- package/dist/{chunk-IBBAISSW.js → chunk-66IUDHCY.js} +50 -1
- package/dist/chunk-66IUDHCY.js.map +1 -0
- package/dist/{chunk-3DNGY4DS.js → chunk-77UYDI2A.js} +2 -2
- package/dist/{chunk-AT32XCCI.js → chunk-AJ5JAQVB.js} +20 -3
- package/dist/chunk-AJ5JAQVB.js.map +1 -0
- package/dist/chunk-CRRN6UD3.js +389 -0
- package/dist/chunk-CRRN6UD3.js.map +1 -0
- package/dist/{chunk-ECXYNTEV.js → chunk-ERRPMYKB.js} +164 -152
- package/dist/chunk-ERRPMYKB.js.map +1 -0
- package/dist/{chunk-M72T5MZU.js → chunk-GOLMRQRW.js} +3 -2
- package/dist/{chunk-KZLVR4J7.js → chunk-IPTNSXOY.js} +2 -2
- package/dist/chunk-L54R23O2.js +262 -0
- package/dist/chunk-L54R23O2.js.map +1 -0
- package/dist/chunk-MHRAPKES.js +1081 -0
- package/dist/chunk-MHRAPKES.js.map +1 -0
- package/dist/{chunk-SIY3YHFY.js → chunk-MMI6OBEC.js} +2 -2
- package/dist/{chunk-CJK6RTMH.js → chunk-RPWQZYNW.js} +1485 -310
- package/dist/chunk-RPWQZYNW.js.map +1 -0
- package/dist/cli/index.js +244 -36
- package/dist/cli/index.js.map +1 -1
- package/dist/{focus-store-RNHBAFYS.js → focus-store-XGTPIVF6.js} +3 -3
- package/dist/{inbox-ZLX2MH7A.js → inbox-7GGEMBUD.js} +4 -4
- package/dist/index.d.ts +66 -1
- package/dist/index.js +556 -167
- package/dist/index.js.map +1 -1
- package/dist/{migrate-XFZU5EBE.js → migrate-25F53XIC.js} +6 -4
- package/dist/{orchestrator-5BHYQ77Y.js → orchestrator-4PJD7QYO.js} +25 -11
- package/dist/runtime-RGZKOFP3.js +15 -0
- package/dist/snapshot-J6LKNY57.js +27 -0
- package/dist/store-HM6ZMFKS.js +45 -0
- package/package.json +6 -3
- package/dist/chunk-3QJJRXIR.js.map +0 -1
- package/dist/chunk-AT32XCCI.js.map +0 -1
- package/dist/chunk-CJK6RTMH.js.map +0 -1
- package/dist/chunk-DLOYERAK.js +0 -87
- package/dist/chunk-DLOYERAK.js.map +0 -1
- package/dist/chunk-ECXYNTEV.js.map +0 -1
- package/dist/chunk-F2XVKX55.js +0 -413
- package/dist/chunk-F2XVKX55.js.map +0 -1
- package/dist/chunk-IBBAISSW.js.map +0 -1
- package/dist/chunk-N6SMIGYJ.js +0 -393
- package/dist/chunk-N6SMIGYJ.js.map +0 -1
- package/dist/chunk-XYBII5PR.js +0 -602
- package/dist/chunk-XYBII5PR.js.map +0 -1
- package/dist/pool-76VLAZER.js +0 -49
- package/dist/runtime-W2OWJIHY.js +0 -11
- package/dist/snapshot-SU2VGM4C.js +0 -16
- /package/dist/{bili-login-XQVEE4M6.js.map → bili-login-KDDU63Z2.js.map} +0 -0
- /package/dist/{bindings-U2M3CO2D.js.map → bindings-LTSGGNIH.js.map} +0 -0
- /package/dist/{chunk-LQKOYTRL.js.map → chunk-4OQXAHU5.js.map} +0 -0
- /package/dist/{chunk-3DNGY4DS.js.map → chunk-77UYDI2A.js.map} +0 -0
- /package/dist/{chunk-M72T5MZU.js.map → chunk-GOLMRQRW.js.map} +0 -0
- /package/dist/{chunk-KZLVR4J7.js.map → chunk-IPTNSXOY.js.map} +0 -0
- /package/dist/{chunk-SIY3YHFY.js.map → chunk-MMI6OBEC.js.map} +0 -0
- /package/dist/{focus-store-RNHBAFYS.js.map → focus-store-XGTPIVF6.js.map} +0 -0
- /package/dist/{inbox-ZLX2MH7A.js.map → inbox-7GGEMBUD.js.map} +0 -0
- /package/dist/{migrate-XFZU5EBE.js.map → migrate-25F53XIC.js.map} +0 -0
- /package/dist/{orchestrator-5BHYQ77Y.js.map → orchestrator-4PJD7QYO.js.map} +0 -0
- /package/dist/{pool-76VLAZER.js.map → runtime-RGZKOFP3.js.map} +0 -0
- /package/dist/{runtime-W2OWJIHY.js.map → snapshot-J6LKNY57.js.map} +0 -0
- /package/dist/{snapshot-SU2VGM4C.js.map → store-HM6ZMFKS.js.map} +0 -0
package/client.js
CHANGED
|
@@ -243,6 +243,7 @@ const LOCALE_NS = "heartbeat";
|
|
|
243
243
|
"profile.collapse": "收起",
|
|
244
244
|
"config.saved": "已保存(即时生效,无需重启)",
|
|
245
245
|
"config.saveFailed": "保存失败:{error}",
|
|
246
|
+
"config.readonly": "当前宿主不支持在应用内改设置,请改 data/settings/policy.json 后重启",
|
|
246
247
|
"config.interval": "心跳间隔(分钟)",
|
|
247
248
|
"config.cap": "每日表达上限(条)",
|
|
248
249
|
"config.timeInject": "时间注入间隔(分钟)",
|
|
@@ -271,6 +272,19 @@ const LOCALE_NS = "heartbeat";
|
|
|
271
272
|
"config.group.timeDesc": "给日常会话注入精确时间、在会话里挂一条心跳状态。",
|
|
272
273
|
"config.group.express": "表达",
|
|
273
274
|
"config.group.expressDesc": "心跳说话的方式与开销。",
|
|
275
|
+
"config.group.vision": "视觉识别",
|
|
276
|
+
"config.group.visionDesc": "每跳截屏识别走哪个引擎:原生让心跳 agent 自己看图,ModLens 保留为回退。",
|
|
277
|
+
"config.visionEngine": "识别引擎",
|
|
278
|
+
"config.visionEngineHint": "本设置优先于 data/settings/vision.json",
|
|
279
|
+
"config.visionEngine.follow": "跟随 vision.json(默认 auto)",
|
|
280
|
+
"config.visionEngine.auto": "自动:先原生,失败回退 ModLens",
|
|
281
|
+
"config.visionEngine.native": "只用原生(agent 自己看图)",
|
|
282
|
+
"config.visionEngine.modlens": "只用 ModLens CLI",
|
|
283
|
+
"config.group.silence": "静默收尾(实验性)",
|
|
284
|
+
"config.group.silenceDesc": "模型决定不说话时,本轮怎么收尾。",
|
|
285
|
+
"config.concludeSilent": "静默收尾开关",
|
|
286
|
+
"config.concludeSilentHint": "打开后模型不再补白,报账完成即结束本轮,界面只留思考与工具块",
|
|
287
|
+
"config.concludeSilentWarn": "若同时启用 dsh-client-auto-continue 等插件的自主循环/自动继续,空的 completed 回合可能被续跑,请先关闭那类模式",
|
|
274
288
|
"config.group.focus": "专注模式",
|
|
275
289
|
"config.group.focusDesc": "需要安静时手动暂停心跳,到点自动恢复。它是即时生效的独立开关:点按钮立刻暂停/恢复,不走下面的「保存」。",
|
|
276
290
|
"config.effect.now": "多久生效:保存后定时器立刻按新间隔重排,下一次心跳就按新间隔走(无需重启)。",
|
|
@@ -301,6 +315,7 @@ const LOCALE_NS = "heartbeat";
|
|
|
301
315
|
"section.interests": "兴趣范围",
|
|
302
316
|
"section.profile": "用户画像(只读)",
|
|
303
317
|
"section.ledger": "账本",
|
|
318
|
+
"section.corrections": "错题本",
|
|
304
319
|
"section.excerpt": "摘抄本",
|
|
305
320
|
"section.weekly": "周报",
|
|
306
321
|
"section.migrate": "换机迁移",
|
|
@@ -308,7 +323,13 @@ const LOCALE_NS = "heartbeat";
|
|
|
308
323
|
"ledger.opened": "已打开:{path}",
|
|
309
324
|
"ledger.failed": "失败:{error}",
|
|
310
325
|
"ledger.open": "一键打开账本",
|
|
311
|
-
"ledger.
|
|
326
|
+
"ledger.openDone": "打开归档",
|
|
327
|
+
"ledger.hint": "账本是心跳 agent 的待办与话题来源,可直接手编;勾掉的事项会移入归档",
|
|
328
|
+
"corrections.opened": "已打开:{path}(待复盘 {pending} 条)",
|
|
329
|
+
"corrections.failed": "失败:{error}",
|
|
330
|
+
"corrections.open": "一键打开错题本",
|
|
331
|
+
"corrections.openDone": "打开归档",
|
|
332
|
+
"corrections.hint": "我出错时记一笔,提炼进人设卡或记忆后勾掉;勾掉的会移入归档",
|
|
312
333
|
"excerpt.opened": "已打开:{path}",
|
|
313
334
|
"excerpt.failed": "失败:{error}",
|
|
314
335
|
"excerpt.open": "一键打开摘抄本",
|
|
@@ -463,6 +484,7 @@ const LOCALE_NS = "heartbeat";
|
|
|
463
484
|
"profile.collapse": "Collapse",
|
|
464
485
|
"config.saved": "Saved (takes effect immediately, no restart needed)",
|
|
465
486
|
"config.saveFailed": "Failed to save: {error}",
|
|
487
|
+
"config.readonly": "This host cannot change settings in the app — edit data/settings/policy.json and restart",
|
|
466
488
|
"config.interval": "Heartbeat interval (minutes)",
|
|
467
489
|
"config.cap": "Daily expression limit",
|
|
468
490
|
"config.timeInject": "Time injection interval (minutes)",
|
|
@@ -491,6 +513,19 @@ const LOCALE_NS = "heartbeat";
|
|
|
491
513
|
"config.group.timeDesc": "Inject precise time into everyday sessions and pin a heartbeat status there.",
|
|
492
514
|
"config.group.express": "Expression",
|
|
493
515
|
"config.group.expressDesc": "How the heartbeat talks, and what it costs.",
|
|
516
|
+
"config.group.vision": "Screen vision",
|
|
517
|
+
"config.group.visionDesc": "Which engine reads each beat's screenshot: native lets the heartbeat agent look at it itself, ModLens stays as the fallback.",
|
|
518
|
+
"config.visionEngine": "Vision engine",
|
|
519
|
+
"config.visionEngineHint": "This setting takes precedence over data/settings/vision.json",
|
|
520
|
+
"config.visionEngine.follow": "Follow vision.json (default auto)",
|
|
521
|
+
"config.visionEngine.auto": "Auto: native first, ModLens on failure",
|
|
522
|
+
"config.visionEngine.native": "Native only (agent reads the image)",
|
|
523
|
+
"config.visionEngine.modlens": "ModLens CLI only",
|
|
524
|
+
"config.group.silence": "Silent turn close (experimental)",
|
|
525
|
+
"config.group.silenceDesc": "How a beat ends when the model decides not to speak.",
|
|
526
|
+
"config.concludeSilent": "Conclude silent turn",
|
|
527
|
+
"config.concludeSilentHint": "When on, the model no longer fills the silence: once the report is filed the turn ends, leaving only the thinking and tool blocks in the UI",
|
|
528
|
+
"config.concludeSilentWarn": "If autonomous loops / auto-continue from plugins such as dsh-client-auto-continue are also enabled, the empty completed turn may be resumed — turn those modes off first",
|
|
494
529
|
"config.group.focus": "Focus mode",
|
|
495
530
|
"config.group.focusDesc": "Pause the heartbeat manually when you need quiet; it resumes automatically when time is up. This is an instant, independent switch: clicking the button pauses/resumes right away, without going through Save below.",
|
|
496
531
|
"config.effect.now": "When it takes effect: after saving, the timer is rescheduled to the new interval immediately, so the very next heartbeat follows it (no restart needed).",
|
|
@@ -521,6 +556,7 @@ const LOCALE_NS = "heartbeat";
|
|
|
521
556
|
"section.interests": "Interest scope",
|
|
522
557
|
"section.profile": "User profile (read-only)",
|
|
523
558
|
"section.ledger": "Ledger",
|
|
559
|
+
"section.corrections": "Corrections",
|
|
524
560
|
"section.excerpt": "Excerpt book",
|
|
525
561
|
"section.weekly": "Weekly report",
|
|
526
562
|
"section.migrate": "Migrate to a new machine",
|
|
@@ -528,7 +564,13 @@ const LOCALE_NS = "heartbeat";
|
|
|
528
564
|
"ledger.opened": "Opened: {path}",
|
|
529
565
|
"ledger.failed": "Failed: {error}",
|
|
530
566
|
"ledger.open": "Open the ledger",
|
|
531
|
-
"ledger.
|
|
567
|
+
"ledger.openDone": "Open archive",
|
|
568
|
+
"ledger.hint": "The ledger is the heartbeat agent's source of todos and topics, and can be edited by hand; checked-off items move to the archive",
|
|
569
|
+
"corrections.opened": "Opened: {path} ({pending} awaiting review)",
|
|
570
|
+
"corrections.failed": "Failed: {error}",
|
|
571
|
+
"corrections.open": "Open the corrections book",
|
|
572
|
+
"corrections.openDone": "Open archive",
|
|
573
|
+
"corrections.hint": "When I get something wrong, log it here; once folded into the persona card or memory, check it off — reviewed items move to the archive",
|
|
532
574
|
"excerpt.opened": "Opened: {path}",
|
|
533
575
|
"excerpt.failed": "Failed: {error}",
|
|
534
576
|
"excerpt.open": "Open the excerpt book",
|
|
@@ -547,6 +589,9 @@ const LOCALE_NS = "heartbeat";
|
|
|
547
589
|
};
|
|
548
590
|
const fill = (text, params) => String(text).replace(/\{(\w+)\}/g, (match, key) => (params && key in params ? String(params[key]) : match));
|
|
549
591
|
let localeSvc = null;
|
|
592
|
+
// 宿主能力探测结果(模块级):apply 时探一次,设置页挂载时若仍不可用再强探一次。
|
|
593
|
+
// 只记 rpc 是否可用;只升不降(见过可用之后不再因一次取不到而回落)。
|
|
594
|
+
const hostCaps = { probed: false, rpc: false };
|
|
550
595
|
const t = (key, params) => {
|
|
551
596
|
if (localeSvc) return localeSvc.bind(LOCALE_NS)(key, params);
|
|
552
597
|
const text = DICT.zh[key];
|
|
@@ -585,6 +630,20 @@ const LOCALE_NS = "heartbeat";
|
|
|
585
630
|
const getConnection = () => {
|
|
586
631
|
try { return ctx.get("connection"); } catch { return undefined; }
|
|
587
632
|
};
|
|
633
|
+
// 探测一次;force 用于设置页挂载时复探(每个挂载只探一次)。
|
|
634
|
+
// 只允许「不可用 → 可用」升级:已可用后即使这次取不到 connection 也不降级。
|
|
635
|
+
const probeHost = (opts) => {
|
|
636
|
+
const force = !!(opts && opts.force);
|
|
637
|
+
if (hostCaps.probed && !force) return hostCaps;
|
|
638
|
+
hostCaps.probed = true;
|
|
639
|
+
const conn = getConnection();
|
|
640
|
+
if (!hostCaps.rpc) {
|
|
641
|
+
hostCaps.rpc = !!(conn && conn.rpc && typeof conn.rpc.call === "function");
|
|
642
|
+
}
|
|
643
|
+
return hostCaps;
|
|
644
|
+
};
|
|
645
|
+
probeHost();
|
|
646
|
+
// connection 每次调用现取(晚注册的宿主照样能用);没有闸门缓存。
|
|
588
647
|
const rpc = async (endpoint, payload) => {
|
|
589
648
|
const conn = getConnection();
|
|
590
649
|
if (!conn || !conn.rpc || typeof conn.rpc.call !== "function") {
|
|
@@ -1185,17 +1244,38 @@ const LOCALE_NS = "heartbeat";
|
|
|
1185
1244
|
// 三代宿主(0.1.1 scope / 0.1.5 installSection / 0.1.7 profile
|
|
1186
1245
|
// 表单)行为统一,保存即时生效、无需重载。
|
|
1187
1246
|
function ConfigSection() {
|
|
1247
|
+
// 每次挂载强制重探一次(apply 时 connection 可能还没注册);这是整张卡的
|
|
1248
|
+
// 唯一重探时机——挂载后才注册 connection 的宿主,要切走再回来才会升级。
|
|
1249
|
+
// 只有「本不可用、这次探到可用」才推进 state 触发重渲染。
|
|
1250
|
+
const [, recheck] = React.useReducer((x) => x + 1, 0);
|
|
1251
|
+
const readonly = !hostCaps.rpc;
|
|
1252
|
+
React.useEffect(() => {
|
|
1253
|
+
const was = hostCaps.rpc;
|
|
1254
|
+
probeHost({ force: true });
|
|
1255
|
+
if (!was && hostCaps.rpc) recheck();
|
|
1256
|
+
}, []);
|
|
1188
1257
|
const [value, setValue] = React.useState(null);
|
|
1189
1258
|
const [loadErr, setLoadErr] = React.useState(null);
|
|
1190
1259
|
React.useEffect(() => {
|
|
1191
|
-
|
|
1192
|
-
|
|
1260
|
+
if (readonly) return;
|
|
1261
|
+
// alive 守卫与 focus.status 同款:deps 变化/卸载后旧请求迟到不许覆盖新值。
|
|
1262
|
+
let alive = true;
|
|
1263
|
+
rpc("config.get").then(
|
|
1264
|
+
(v) => { if (alive) setValue(v); },
|
|
1265
|
+
(e) => { if (alive) setLoadErr(String(e).slice(0, 100)); },
|
|
1266
|
+
);
|
|
1267
|
+
return () => { alive = false; };
|
|
1268
|
+
}, [readonly]);
|
|
1193
1269
|
const interval = value && Number(value.intervalMin) > 0 ? Number(value.intervalMin) : 60;
|
|
1194
1270
|
const cap = value && Number(value.maxDailySend) > 0 ? Number(value.maxDailySend) : 10;
|
|
1195
1271
|
const timeInject = value && value.timeInjectMin === 0 ? 0 : (value && Number(value.timeInjectMin) > 0 ? Number(value.timeInjectMin) : 25);
|
|
1196
1272
|
const statusbar = !!value && value.statusbar === true;
|
|
1197
1273
|
const idleMode = !!value && value.idleMode === true;
|
|
1198
1274
|
const tokenSaver = !!value && value.tokenSaver === true;
|
|
1275
|
+
// 视觉引擎(v2.2.1-native.1):'' = 跟随 vision.json / 内置 auto。
|
|
1276
|
+
const visionEngine = value && typeof value.visionEngine === "string" ? value.visionEngine : "";
|
|
1277
|
+
// 静默收尾(2.3.0 实验性):默认关。
|
|
1278
|
+
const concludeSilent = !!value && value.concludeSilentTurn === true;
|
|
1199
1279
|
const psyEnabled = !!value && value.psyEnabled === true;
|
|
1200
1280
|
// 静默时段(v2.2):policy 用户层字段(gate.quietHours),保存后下一跳生效。
|
|
1201
1281
|
const quietStart = value && typeof value.quietStart === "string" ? value.quietStart : "01:30";
|
|
@@ -1206,11 +1286,15 @@ const LOCALE_NS = "heartbeat";
|
|
|
1206
1286
|
const [draftStatusbar, setDraftStatusbar] = React.useState(statusbar);
|
|
1207
1287
|
const [draftIdle, setDraftIdle] = React.useState(idleMode);
|
|
1208
1288
|
const [draftTokenSaver, setDraftTokenSaver] = React.useState(tokenSaver);
|
|
1289
|
+
const [draftVisionEngine, setDraftVisionEngine] = React.useState(visionEngine);
|
|
1290
|
+
const [draftConcludeSilent, setDraftConcludeSilent] = React.useState(concludeSilent);
|
|
1209
1291
|
const [draftPsy, setDraftPsy] = React.useState(psyEnabled);
|
|
1210
1292
|
const [draftQuietStart, setDraftQuietStart] = React.useState(quietStart);
|
|
1211
1293
|
const [draftQuietEnd, setDraftQuietEnd] = React.useState(quietEnd);
|
|
1212
1294
|
const [status, setStatus] = React.useState("");
|
|
1213
|
-
|
|
1295
|
+
// 保存失败单独一行红字:不再只靠按钮旁的 status 一行灰字(issue #7)。
|
|
1296
|
+
const [saveErr, setSaveErr] = React.useState("");
|
|
1297
|
+
React.useEffect(() => { setDraftInterval(interval); setDraftCap(cap); setDraftTimeInject(timeInject); setDraftStatusbar(statusbar); setDraftIdle(idleMode); setDraftTokenSaver(tokenSaver); setDraftVisionEngine(visionEngine); setDraftConcludeSilent(concludeSilent); setDraftPsy(psyEnabled); setDraftQuietStart(quietStart); setDraftQuietEnd(quietEnd); }, [interval, cap, timeInject, statusbar, idleMode, tokenSaver, visionEngine, concludeSilent, psyEnabled, quietStart, quietEnd]);
|
|
1214
1298
|
// v2.1.0 面板改造:分组小节文案走 DICT 的 config.group.*。
|
|
1215
1299
|
// 「多久生效」依据 src/rpc.ts 的 config.set 实现判定:
|
|
1216
1300
|
// intervalMin → applyHeartbeatInterval 立即重排定时器(保存后立刻生效);
|
|
@@ -1222,9 +1306,20 @@ const LOCALE_NS = "heartbeat";
|
|
|
1222
1306
|
const [focus, setFocus] = React.useState(null);
|
|
1223
1307
|
const [draftFocusMin, setDraftFocusMin] = React.useState(30);
|
|
1224
1308
|
const [focusBusy, setFocusBusy] = React.useState(false);
|
|
1309
|
+
// 专注动作失败单独一格:不能借 status(那格会显示「已保存」),
|
|
1310
|
+
// 否则成功一次就把不相干的保存回执误清掉。
|
|
1311
|
+
const [focusErr, setFocusErr] = React.useState("");
|
|
1225
1312
|
React.useEffect(() => {
|
|
1226
|
-
|
|
1227
|
-
|
|
1313
|
+
// 只读挂载也要跑这一次首拉:只读态同样要渲染「恢复」分支,跳过它
|
|
1314
|
+
// 只读界面就永远只剩「暂停」。deps 是 [readonly],升级成可编辑后补拉一次。
|
|
1315
|
+
// alive 守卫:旧请求迟到(deps 变化或卸载)不许覆盖新一轮的状态。
|
|
1316
|
+
let alive = true;
|
|
1317
|
+
rpc("focus.status").then(
|
|
1318
|
+
(v) => { if (alive) setFocus(v); },
|
|
1319
|
+
() => { /* 旧宿主无此端点:不显示状态,按钮仍可试 */ },
|
|
1320
|
+
);
|
|
1321
|
+
return () => { alive = false; };
|
|
1322
|
+
}, [readonly]);
|
|
1228
1323
|
const toggleFocus = async (pause) => {
|
|
1229
1324
|
if (focusBusy) return;
|
|
1230
1325
|
setFocusBusy(true);
|
|
@@ -1236,13 +1331,16 @@ const LOCALE_NS = "heartbeat";
|
|
|
1236
1331
|
await rpc("focus.resume");
|
|
1237
1332
|
setFocus({ paused: false });
|
|
1238
1333
|
}
|
|
1334
|
+
// 成功只清专注自己的失败文案,不碰 status(保存回执)。
|
|
1335
|
+
setFocusErr("");
|
|
1239
1336
|
} catch (e) {
|
|
1240
|
-
|
|
1337
|
+
setFocusErr(L("config.focusFailed", { error: String(e).slice(0, 80) }));
|
|
1241
1338
|
} finally {
|
|
1242
1339
|
setFocusBusy(false);
|
|
1243
1340
|
}
|
|
1244
1341
|
};
|
|
1245
1342
|
const save = async () => {
|
|
1343
|
+
if (readonly) return;
|
|
1246
1344
|
try {
|
|
1247
1345
|
const di = Math.max(1, Math.min(1440, Math.floor(Number(draftInterval) || 0)));
|
|
1248
1346
|
const dc = Math.max(1, Math.min(50, Math.floor(Number(draftCap) || 0)));
|
|
@@ -1254,18 +1352,25 @@ const LOCALE_NS = "heartbeat";
|
|
|
1254
1352
|
statusbar: !!draftStatusbar,
|
|
1255
1353
|
idleMode: !!draftIdle,
|
|
1256
1354
|
tokenSaver: !!draftTokenSaver,
|
|
1355
|
+
visionEngine: draftVisionEngine,
|
|
1356
|
+
concludeSilentTurn: !!draftConcludeSilent,
|
|
1257
1357
|
psyEnabled: !!draftPsy,
|
|
1258
1358
|
quietStart: draftQuietStart,
|
|
1259
1359
|
quietEnd: draftQuietEnd,
|
|
1260
1360
|
});
|
|
1261
1361
|
setValue(v);
|
|
1262
1362
|
setStatus(t("config.saved"));
|
|
1363
|
+
// 成功必须清掉上一次的失败红字,否则红绿并存。
|
|
1364
|
+
setSaveErr("");
|
|
1263
1365
|
} catch (e) {
|
|
1264
|
-
setStatus(
|
|
1366
|
+
setStatus("");
|
|
1367
|
+
setSaveErr(L("config.saveFailed", { error: String(e).slice(0, 80) }));
|
|
1265
1368
|
}
|
|
1266
1369
|
};
|
|
1267
|
-
if (
|
|
1268
|
-
|
|
1370
|
+
if (!readonly) {
|
|
1371
|
+
if (loadErr && !value) return React.createElement("div", { style: hintStyle }, L("common.loadFailed", { error: loadErr }));
|
|
1372
|
+
if (!value) return React.createElement("div", { style: hintStyle }, t("common.loading"));
|
|
1373
|
+
}
|
|
1269
1374
|
// 分组小节的标题 + 一句人话说明;生效说明按 label 宽度(140 + gap 8)缩进对齐。
|
|
1270
1375
|
const groupTitle = (title, desc) => React.createElement(
|
|
1271
1376
|
"div",
|
|
@@ -1280,32 +1385,65 @@ const LOCALE_NS = "heartbeat";
|
|
|
1280
1385
|
control,
|
|
1281
1386
|
hint ? React.createElement("span", { style: hintStyle }, hint) : null),
|
|
1282
1387
|
effect ? React.createElement("div", { style: { ...hintStyle, marginLeft: 148 } }, effect) : null);
|
|
1283
|
-
|
|
1388
|
+
// 只读态拿不到真实配置:输入框空着 + 占位符,开关与引擎下拉显示「—」,
|
|
1389
|
+
// 不把兜底值(60/10/25/01:30、statusbar 关闭、follow auto)当配置事实展示。
|
|
1390
|
+
const inputValue = (draft) => (readonly ? "" : draft);
|
|
1391
|
+
const inputPlaceholder = readonly ? "—" : undefined;
|
|
1392
|
+
// 只读态下拉用一个占位选项占住选中位;真实引擎选项照常列出但不可选。
|
|
1393
|
+
const VISION_UNSET = "__unset__";
|
|
1394
|
+
// 只读态不挂 onClick:disabled 只是 DOM 闸门,程序化触发仍会改 draft。
|
|
1395
|
+
// 样式也按 (!readonly && on) 选,避免只读态整排灰底透出「都关着」的暗示。
|
|
1396
|
+
const toggleBtn = (on, set) => React.createElement("button", {
|
|
1397
|
+
style: !readonly && on ? buttonStyle : buttonGhost,
|
|
1398
|
+
disabled: readonly,
|
|
1399
|
+
onClick: readonly ? undefined : () => set(!on),
|
|
1400
|
+
}, readonly ? "—" : (on ? "☑ " + t("common.on") : "☐ " + t("common.off")));
|
|
1284
1401
|
return React.createElement(
|
|
1285
1402
|
"div",
|
|
1286
|
-
|
|
1403
|
+
{ className: "hb-config" },
|
|
1404
|
+
// ── 非 Web 宿主:设置卡只读,顶部说明改法(issue #7)──
|
|
1405
|
+
readonly
|
|
1406
|
+
? React.createElement("div", {
|
|
1407
|
+
className: "hb-configReadonly",
|
|
1408
|
+
style: { ...hintStyle, padding: "8px 10px", borderRadius: 9, border: "1px solid rgba(245,184,61,.5)", background: "rgba(245,184,61,.14)", color: "var(--dsw-alias-label-primary)", fontWeight: 600 },
|
|
1409
|
+
}, t("config.readonly"))
|
|
1410
|
+
: null,
|
|
1287
1411
|
// ── 节律 ──
|
|
1288
1412
|
groupTitle(t("config.group.rhythm"), t("config.group.rhythmDesc")),
|
|
1289
1413
|
paramRow(t("config.interval"),
|
|
1290
|
-
React.createElement("input", { style: inputStyle, type: "number", min: 1, max: 1440, value: draftInterval, onChange: (e) => setDraftInterval(e.target.value) }),
|
|
1414
|
+
React.createElement("input", { style: inputStyle, type: "number", min: 1, max: 1440, disabled: readonly, placeholder: inputPlaceholder, value: inputValue(draftInterval), onChange: (e) => setDraftInterval(e.target.value) }),
|
|
1291
1415
|
null, EFFECT_NOW),
|
|
1292
1416
|
paramRow(t("config.cap"),
|
|
1293
|
-
React.createElement("input", { style: inputStyle, type: "number", min: 1, max: 50, value: draftCap, onChange: (e) => setDraftCap(e.target.value) }),
|
|
1417
|
+
React.createElement("input", { style: inputStyle, type: "number", min: 1, max: 50, disabled: readonly, placeholder: inputPlaceholder, value: inputValue(draftCap), onChange: (e) => setDraftCap(e.target.value) }),
|
|
1294
1418
|
null, EFFECT_NEXT),
|
|
1295
1419
|
// ── 时间与状态栏 ──
|
|
1296
1420
|
groupTitle(t("config.group.time"), t("config.group.timeDesc")),
|
|
1297
1421
|
paramRow(t("config.timeInject"),
|
|
1298
|
-
React.createElement("input", { style: inputStyle, type: "number", min: 0, max: 1440, value: draftTimeInject, onChange: (e) => setDraftTimeInject(e.target.value) }),
|
|
1422
|
+
React.createElement("input", { style: inputStyle, type: "number", min: 0, max: 1440, disabled: readonly, placeholder: inputPlaceholder, value: inputValue(draftTimeInject), onChange: (e) => setDraftTimeInject(e.target.value) }),
|
|
1299
1423
|
t("config.timeInjectOff"), EFFECT_NEXT),
|
|
1300
1424
|
paramRow(t("config.quietHours"),
|
|
1301
1425
|
React.createElement(
|
|
1302
1426
|
"span",
|
|
1303
1427
|
null,
|
|
1304
|
-
React.createElement("input", { style: inputStyle, type: "time", value: draftQuietStart, onChange: (e) => setDraftQuietStart(e.target.value) }),
|
|
1428
|
+
React.createElement("input", { style: inputStyle, type: "time", disabled: readonly, value: inputValue(draftQuietStart), onChange: (e) => setDraftQuietStart(e.target.value) }),
|
|
1305
1429
|
"–",
|
|
1306
|
-
React.createElement("input", { style: inputStyle, type: "time", value: draftQuietEnd, onChange: (e) => setDraftQuietEnd(e.target.value) })),
|
|
1430
|
+
React.createElement("input", { style: inputStyle, type: "time", disabled: readonly, value: inputValue(draftQuietEnd), onChange: (e) => setDraftQuietEnd(e.target.value) })),
|
|
1307
1431
|
t("config.quietHoursHint"), EFFECT_NEXT),
|
|
1308
1432
|
paramRow(t("config.statusbar"), toggleBtn(draftStatusbar, setDraftStatusbar), t("config.statusbarHint"), EFFECT_NEXT),
|
|
1433
|
+
// ── 视觉(v2.2.1-native.1):每跳截屏识别走哪个引擎 ──
|
|
1434
|
+
groupTitle(t("config.group.vision"), t("config.group.visionDesc")),
|
|
1435
|
+
paramRow(t("config.visionEngine"),
|
|
1436
|
+
React.createElement("select", { style: { ...inputStyle, width: 230 }, "data-role": "visionEngine", disabled: readonly, value: readonly ? VISION_UNSET : draftVisionEngine, onChange: (e) => setDraftVisionEngine(e.target.value) },
|
|
1437
|
+
readonly ? React.createElement("option", { value: VISION_UNSET }, "—") : null,
|
|
1438
|
+
React.createElement("option", { value: "" }, t("config.visionEngine.follow")),
|
|
1439
|
+
React.createElement("option", { value: "auto" }, t("config.visionEngine.auto")),
|
|
1440
|
+
React.createElement("option", { value: "native" }, t("config.visionEngine.native")),
|
|
1441
|
+
React.createElement("option", { value: "modlens" }, t("config.visionEngine.modlens"))),
|
|
1442
|
+
t("config.visionEngineHint"), EFFECT_NEXT),
|
|
1443
|
+
// ── 静默收尾(2.3.0 实验性):默认关;警告始终可见 ──
|
|
1444
|
+
groupTitle(t("config.group.silence"), t("config.group.silenceDesc")),
|
|
1445
|
+
paramRow(t("config.concludeSilent"), toggleBtn(draftConcludeSilent, setDraftConcludeSilent), t("config.concludeSilentHint"), EFFECT_NEXT),
|
|
1446
|
+
React.createElement("div", { style: { ...hintStyle, marginLeft: 148, color: "#e5484d" } }, t("config.concludeSilentWarn")),
|
|
1309
1447
|
// ── 表达 ──
|
|
1310
1448
|
groupTitle(t("config.group.express"), t("config.group.expressDesc")),
|
|
1311
1449
|
paramRow(t("config.tokenSaver"), toggleBtn(draftTokenSaver, setDraftTokenSaver), t("config.tokenSaverHint"), EFFECT_NEXT),
|
|
@@ -1315,16 +1453,20 @@ const LOCALE_NS = "heartbeat";
|
|
|
1315
1453
|
groupTitle(t("config.group.focus"), t("config.group.focusDesc")),
|
|
1316
1454
|
React.createElement("div", { style: rowStyle },
|
|
1317
1455
|
React.createElement("span", { style: labelStyle }, t("config.focus")),
|
|
1318
|
-
React.createElement("input", { style: inputStyle, type: "number", min: 1, max: 1440, value: draftFocusMin, onChange: (e) => setDraftFocusMin(e.target.value) }),
|
|
1456
|
+
React.createElement("input", { style: inputStyle, type: "number", min: 1, max: 1440, disabled: readonly, placeholder: inputPlaceholder, value: inputValue(draftFocusMin), onChange: (e) => setDraftFocusMin(e.target.value) }),
|
|
1319
1457
|
React.createElement("span", { style: hintStyle }, t("config.focusMinutes")),
|
|
1458
|
+
// 只读态不挂 onClick(同 toggleBtn):disabled 只是 DOM 闸门,程序化调用会真发 focus RPC。
|
|
1320
1459
|
focus && focus.paused
|
|
1321
|
-
? React.createElement("button", { style: buttonStyle, disabled: focusBusy, onClick: () => { void toggleFocus(false); } }, t("config.focusResume"))
|
|
1322
|
-
: React.createElement("button", { style: buttonGhost, disabled: focusBusy, onClick: () => { void toggleFocus(true); } }, t("config.focusPause"))),
|
|
1460
|
+
? React.createElement("button", { style: buttonStyle, disabled: focusBusy || readonly, onClick: readonly ? undefined : () => { void toggleFocus(false); } }, t("config.focusResume"))
|
|
1461
|
+
: React.createElement("button", { style: buttonGhost, disabled: focusBusy || readonly, onClick: readonly ? undefined : () => { void toggleFocus(true); } }, t("config.focusPause"))),
|
|
1323
1462
|
React.createElement("div", { style: { ...hintStyle, marginLeft: 148 } }, focus && focus.paused ? L("config.focusPaused", { clock: focus.clock || "" }) : t("config.focusHint")),
|
|
1463
|
+
focusErr ? React.createElement("div", { className: "hb-focusError", style: { ...hintStyle, marginLeft: 148, color: "#e5484d", fontWeight: 600 } }, focusErr) : null,
|
|
1464
|
+
// ── 保存失败:设置卡里单独一行可见报错(不再静默)──
|
|
1465
|
+
saveErr ? React.createElement("div", { className: "hb-configError", style: { ...hintStyle, color: "#e5484d", fontWeight: 600 } }, saveErr) : null,
|
|
1324
1466
|
// ── 保存固定在分组最后;成功/失败提示沿用现有 status 逻辑 ──
|
|
1325
1467
|
React.createElement("div", { style: rowStyle },
|
|
1326
|
-
React.createElement("button", { style: buttonStyle, onClick: () => { void save(); } }, t("common.save")),
|
|
1327
|
-
React.createElement("span", { style: status ? { ...hintStyle, fontWeight: 600 } : hintStyle }, status || t("config.saveHint"))),
|
|
1468
|
+
React.createElement("button", { style: { ...buttonStyle, ...(readonly ? { opacity: 0.5, cursor: "not-allowed" } : null) }, disabled: readonly, title: readonly ? t("config.readonly") : undefined, onClick: () => { void save(); } }, t("common.save")),
|
|
1469
|
+
React.createElement("span", { style: status ? { ...hintStyle, fontWeight: 600 } : hintStyle }, status || (readonly ? t("config.readonly") : t("config.saveHint")))),
|
|
1328
1470
|
);
|
|
1329
1471
|
}
|
|
1330
1472
|
|
|
@@ -1447,13 +1589,27 @@ const LOCALE_NS = "heartbeat";
|
|
|
1447
1589
|
{ id: "weekly", labelKey: "panel.tab.weekly" },
|
|
1448
1590
|
{ id: "config", labelKey: "panel.tab.config" },
|
|
1449
1591
|
];
|
|
1450
|
-
// 账本 + 摘抄本:原 HeartbeatSection
|
|
1592
|
+
// 账本 + 错题本 + 摘抄本:原 HeartbeatSection 内联块原样迁出(含 rpc 调用)。
|
|
1593
|
+
// v2.3.0:账本与错题本各并排两个按钮——主按钮开 live 文件,第二个只读打开归档。
|
|
1451
1594
|
function LedgerExcerptBlocks() {
|
|
1452
1595
|
const [ledgerMsg, setLedgerMsg] = React.useState("");
|
|
1453
1596
|
const openLedger = () => rpc("ledger.open").then(
|
|
1454
1597
|
(v) => setLedgerMsg(L("ledger.opened", { path: v.path })),
|
|
1455
1598
|
(e) => setLedgerMsg(L("ledger.failed", { error: String(e).slice(0, 80) })),
|
|
1456
1599
|
);
|
|
1600
|
+
const openLedgerDone = () => rpc("ledger.openDone").then(
|
|
1601
|
+
(v) => setLedgerMsg(L("ledger.opened", { path: v.path })),
|
|
1602
|
+
(e) => setLedgerMsg(L("ledger.failed", { error: String(e).slice(0, 80) })),
|
|
1603
|
+
);
|
|
1604
|
+
const [correctionsMsg, setCorrectionsMsg] = React.useState("");
|
|
1605
|
+
const openCorrections = () => rpc("corrections.open").then(
|
|
1606
|
+
(v) => setCorrectionsMsg(L("corrections.opened", { path: v.path, pending: v.pending })),
|
|
1607
|
+
(e) => setCorrectionsMsg(L("corrections.failed", { error: String(e).slice(0, 80) })),
|
|
1608
|
+
);
|
|
1609
|
+
const openCorrectionsDone = () => rpc("corrections.openDone").then(
|
|
1610
|
+
(v) => setCorrectionsMsg(L("ledger.opened", { path: v.path })),
|
|
1611
|
+
(e) => setCorrectionsMsg(L("corrections.failed", { error: String(e).slice(0, 80) })),
|
|
1612
|
+
);
|
|
1457
1613
|
const [excerptMsg, setExcerptMsg] = React.useState("");
|
|
1458
1614
|
const openExcerpt = () => rpc("excerpt.open").then(
|
|
1459
1615
|
(v) => setExcerptMsg(L("excerpt.opened", { path: v.path })),
|
|
@@ -1465,7 +1621,13 @@ const LOCALE_NS = "heartbeat";
|
|
|
1465
1621
|
React.createElement("div", { style: blockHead }, t("section.ledger")),
|
|
1466
1622
|
React.createElement("div", { style: rowStyle },
|
|
1467
1623
|
React.createElement("button", { style: buttonStyle, onClick: () => { void openLedger(); } }, t("ledger.open")),
|
|
1624
|
+
React.createElement("button", { style: buttonGhost, onClick: () => { void openLedgerDone(); } }, t("ledger.openDone")),
|
|
1468
1625
|
React.createElement("span", { style: hintStyle }, ledgerMsg || t("ledger.hint"))),
|
|
1626
|
+
React.createElement("div", { style: blockHead }, t("section.corrections")),
|
|
1627
|
+
React.createElement("div", { style: rowStyle },
|
|
1628
|
+
React.createElement("button", { style: buttonStyle, onClick: () => { void openCorrections(); } }, t("corrections.open")),
|
|
1629
|
+
React.createElement("button", { style: buttonGhost, onClick: () => { void openCorrectionsDone(); } }, t("corrections.openDone")),
|
|
1630
|
+
React.createElement("span", { style: hintStyle }, correctionsMsg || t("corrections.hint"))),
|
|
1469
1631
|
React.createElement("div", { style: blockHead }, t("section.excerpt")),
|
|
1470
1632
|
React.createElement("div", { style: rowStyle },
|
|
1471
1633
|
React.createElement("button", { style: buttonStyle, onClick: () => { void openExcerpt(); } }, t("excerpt.open")),
|
|
@@ -11,10 +11,10 @@ import {
|
|
|
11
11
|
sessdataFromCookies,
|
|
12
12
|
sessdataFromUrl,
|
|
13
13
|
tryOpenImage
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-MMI6OBEC.js";
|
|
15
15
|
import "./chunk-OCBE2AKW.js";
|
|
16
|
-
import "./chunk-
|
|
17
|
-
import "./chunk-
|
|
16
|
+
import "./chunk-GOLMRQRW.js";
|
|
17
|
+
import "./chunk-66IUDHCY.js";
|
|
18
18
|
export {
|
|
19
19
|
BILI_SESSION_FILE_NAME,
|
|
20
20
|
GENERATE_URL,
|
|
@@ -29,4 +29,4 @@ export {
|
|
|
29
29
|
sessdataFromUrl,
|
|
30
30
|
tryOpenImage
|
|
31
31
|
};
|
|
32
|
-
//# sourceMappingURL=bili-login-
|
|
32
|
+
//# sourceMappingURL=bili-login-KDDU63Z2.js.map
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
observeTargets,
|
|
7
7
|
removeBinding,
|
|
8
8
|
saveBindings
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-77UYDI2A.js";
|
|
10
|
+
import "./chunk-66IUDHCY.js";
|
|
11
11
|
export {
|
|
12
12
|
addBinding,
|
|
13
13
|
bindingsFilePath,
|
|
@@ -17,4 +17,4 @@ export {
|
|
|
17
17
|
removeBinding,
|
|
18
18
|
saveBindings
|
|
19
19
|
};
|
|
20
|
-
//# sourceMappingURL=bindings-
|
|
20
|
+
//# sourceMappingURL=bindings-LTSGGNIH.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
atomicWriteJsonSync
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-66IUDHCY.js";
|
|
4
4
|
|
|
5
5
|
// src/core/focus-store.ts
|
|
6
6
|
import fs from "fs";
|
|
@@ -56,4 +56,4 @@ export {
|
|
|
56
56
|
clearFocusState,
|
|
57
57
|
resolveFocusUntil
|
|
58
58
|
};
|
|
59
|
-
//# sourceMappingURL=chunk-
|
|
59
|
+
//# sourceMappingURL=chunk-4OQXAHU5.js.map
|
|
@@ -10,10 +10,19 @@ function getRuntime() {
|
|
|
10
10
|
function resetRuntimeForTest() {
|
|
11
11
|
runtime = null;
|
|
12
12
|
}
|
|
13
|
+
var currentDeliveryId = "";
|
|
14
|
+
function setCurrentDeliveryId(id) {
|
|
15
|
+
currentDeliveryId = id;
|
|
16
|
+
}
|
|
17
|
+
function getCurrentDeliveryId() {
|
|
18
|
+
return currentDeliveryId;
|
|
19
|
+
}
|
|
13
20
|
|
|
14
21
|
export {
|
|
15
22
|
setRuntime,
|
|
16
23
|
getRuntime,
|
|
17
|
-
resetRuntimeForTest
|
|
24
|
+
resetRuntimeForTest,
|
|
25
|
+
setCurrentDeliveryId,
|
|
26
|
+
getCurrentDeliveryId
|
|
18
27
|
};
|
|
19
|
-
//# sourceMappingURL=chunk-
|
|
28
|
+
//# sourceMappingURL=chunk-5CVAW5AS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/runtime.ts"],"sourcesContent":["// Runtime singleton shared by all modules after the plugin entry initializes.\n\nimport type { PathGuard } from './path-guard.js';\nimport type { WorkspacePaths } from './paths.js';\nimport type { Policy } from '../config/schema.js';\n\nexport interface HeartbeatRuntime {\n paths: WorkspacePaths;\n guard: PathGuard;\n policy: Policy;\n /** Live UI flags (M7): re-read by the RPC status endpoint for the card. */\n flags: {\n statusbarEnabled(): boolean;\n timeInjectMin(): number;\n idleMode(): boolean;\n /** Token-saver (v1.7.0): pause the whole beat while the user is away. */\n tokenSaver(): boolean;\n /** Vision engine from the plugin config (v2.2.1-native.1): `auto` /\n * `native` / `modlens`, or '' = follow data/settings/vision.json and then\n * the built-in default (auto). Re-read on every beat. */\n visionEngine(): string;\n /** 2.3.0 experimental (default off): a silent seed_report concludes the\n * turn once it has landed. Read on every beat; saved live via config.set.\n * Optional so older test doubles / hosts without the ref read as false. */\n concludeSilentTurn?(): boolean;\n };\n}\n\nlet runtime: HeartbeatRuntime | null = null;\n\nexport function setRuntime(r: HeartbeatRuntime): void {\n runtime = r;\n}\n\nexport function getRuntime(): HeartbeatRuntime {\n if (!runtime) throw new Error('heartbeat runtime not initialized');\n return runtime;\n}\n\nexport function resetRuntimeForTest(): void {\n runtime = null;\n}\n\n// The delivery id of the package whose turn is currently running (2.3.0\n// experimental). seed_report is a GLOBAL tool, so without this it cannot tell\n// a stale/typo'd id from the id of the package it is answering — and only the\n// latter may end the turn. Module-level because the tool is registered once\n// and must see the live value; '' means \"no delivery turn is open\".\nlet currentDeliveryId = '';\n\nexport function setCurrentDeliveryId(id: string): void {\n currentDeliveryId = id;\n}\n\nexport function getCurrentDeliveryId(): string {\n return currentDeliveryId;\n}\n"],"mappings":";AA4BA,IAAI,UAAmC;AAEhC,SAAS,WAAW,GAA2B;AACpD,YAAU;AACZ;AAEO,SAAS,aAA+B;AAC7C,MAAI,CAAC,QAAS,OAAM,IAAI,MAAM,mCAAmC;AACjE,SAAO;AACT;AAEO,SAAS,sBAA4B;AAC1C,YAAU;AACZ;AAOA,IAAI,oBAAoB;AAEjB,SAAS,qBAAqB,IAAkB;AACrD,sBAAoB;AACtB;AAEO,SAAS,uBAA+B;AAC7C,SAAO;AACT;","names":[]}
|
|
@@ -31,6 +31,54 @@ function atomicWriteFileSync(target, data) {
|
|
|
31
31
|
function atomicWriteJsonSync(target, value) {
|
|
32
32
|
atomicWriteFileSync(target, JSON.stringify(value, null, 2));
|
|
33
33
|
}
|
|
34
|
+
function exclusiveWriteDirectSync(target, data) {
|
|
35
|
+
const fd = fs.openSync(target, "wx");
|
|
36
|
+
try {
|
|
37
|
+
fs.writeFileSync(fd, data);
|
|
38
|
+
fs.fsyncSync(fd);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
try {
|
|
41
|
+
fs.closeSync(fd);
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
fs.rmSync(target, { force: true });
|
|
46
|
+
} catch {
|
|
47
|
+
}
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
50
|
+
fs.closeSync(fd);
|
|
51
|
+
}
|
|
52
|
+
function atomicCreateFileSync(target, data) {
|
|
53
|
+
const tmp = tmpSibling(target, "x");
|
|
54
|
+
let fd = null;
|
|
55
|
+
try {
|
|
56
|
+
fd = fs.openSync(tmp, "w");
|
|
57
|
+
fs.writeFileSync(fd, data);
|
|
58
|
+
fs.fsyncSync(fd);
|
|
59
|
+
fs.closeSync(fd);
|
|
60
|
+
fd = null;
|
|
61
|
+
try {
|
|
62
|
+
fs.linkSync(tmp, target);
|
|
63
|
+
} catch (e) {
|
|
64
|
+
const code = e.code;
|
|
65
|
+
if (code === "EEXIST") return;
|
|
66
|
+
if (code === "EPERM" || code === "ENOTSUP" || code === "EACCES") {
|
|
67
|
+
exclusiveWriteDirectSync(target, data);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
} finally {
|
|
73
|
+
if (fd !== null) {
|
|
74
|
+
try {
|
|
75
|
+
fs.closeSync(fd);
|
|
76
|
+
} catch {
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
fs.rmSync(tmp, { force: true });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
34
82
|
function shredFileSync(target, passes = 3) {
|
|
35
83
|
const stat = fs.statSync(target);
|
|
36
84
|
if (!stat.isFile()) throw new Error(`shred: not a file: ${target}`);
|
|
@@ -52,7 +100,8 @@ function burnFileSync(target) {
|
|
|
52
100
|
export {
|
|
53
101
|
atomicWriteFileSync,
|
|
54
102
|
atomicWriteJsonSync,
|
|
103
|
+
atomicCreateFileSync,
|
|
55
104
|
shredFileSync,
|
|
56
105
|
burnFileSync
|
|
57
106
|
};
|
|
58
|
-
//# sourceMappingURL=chunk-
|
|
107
|
+
//# sourceMappingURL=chunk-66IUDHCY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/atomic-fs.ts"],"sourcesContent":["// Crash-safe file replacement: write to a random-suffix temp file in the SAME\n// directory as the target, then rename over it. Same-directory rename stays\n// on one volume (atomic) and Node's rename replaces existing files on Windows.\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { randomUUID, randomFillSync } from 'node:crypto';\n\nexport function tmpSibling(target: string, tag = 'w'): string {\n return path.join(\n path.dirname(target),\n `.${path.basename(target)}.${tag}-${randomUUID().slice(0, 8)}.tmp`,\n );\n}\n\nexport function atomicWriteFileSync(target: string, data: string | Uint8Array): void {\n const tmp = tmpSibling(target);\n let fd: number | null = null;\n try {\n fd = fs.openSync(tmp, 'w');\n fs.writeFileSync(fd, data);\n // 低优先级 review (2026-10-17): rename is atomic against a crash of THIS\n // process, but without a flush the renamed file can still point at blocks\n // the OS never wrote — a power loss then leaves an empty or partial file\n // where a complete one is promised. Flush before publishing.\n fs.fsyncSync(fd);\n fs.closeSync(fd);\n fd = null;\n fs.renameSync(tmp, target);\n } finally {\n if (fd !== null) {\n try { fs.closeSync(fd); } catch { /* the write path already failed */ }\n }\n fs.rmSync(tmp, { force: true });\n }\n}\n\nexport function atomicWriteJsonSync(target: string, value: unknown): void {\n atomicWriteFileSync(target, JSON.stringify(value, null, 2));\n}\n\n/** Exclusive-create fallback when hard links are unavailable (exFAT/FAT32\n * sticks, SMB/NAS mounts, link-restricted directories: EPERM / ENOTSUP /\n * EACCES). openSync('wx') is itself an O_EXCL exclusive create, so\n * concurrent-creator safety survives; what is lost is the crash-atomic\n * publication (a power loss mid-write can leave a partial file) — the same\n * exposure the pre-link writeFileSync(flag 'wx') seeding always had. A write\n * that fails (ENOSPC / EIO) removes the stub it created before rethrowing:\n * a half-written target would make every later exclusive create hit EEXIST\n * forever (N16② review 低3). A failed openSync never removes anything — the\n * file was never ours, and EEXIST is the first-creator-wins contract. */\nfunction exclusiveWriteDirectSync(target: string, data: string | Uint8Array): void {\n const fd = fs.openSync(target, 'wx');\n try {\n fs.writeFileSync(fd, data);\n fs.fsyncSync(fd);\n } catch (e) {\n try { fs.closeSync(fd); } catch { /* close must not mask the write error */ }\n try { fs.rmSync(target, { force: true }); } catch { /* best effort */ }\n throw e;\n }\n fs.closeSync(fd);\n}\n\n/** Create-if-absent with atomic publication. rename() would silently REPLACE\n * a file a concurrent writer created between our write and the rename, so\n * exclusive publication goes through a hard link instead: link fails with\n * EEXIST when the target came into existence meanwhile, which is exactly the\n * O_EXCL contract (AGENTS.md #1: every data write is atomic — \"create a\n * fresh file\" is no exception, a crash mid-write must not leave a partial\n * file that looks seeded). */\nexport function atomicCreateFileSync(target: string, data: string | Uint8Array): void {\n const tmp = tmpSibling(target, 'x');\n let fd: number | null = null;\n try {\n fd = fs.openSync(tmp, 'w');\n fs.writeFileSync(fd, data);\n fs.fsyncSync(fd);\n fs.closeSync(fd);\n fd = null;\n try {\n fs.linkSync(tmp, target);\n } catch (e) {\n const code = (e as NodeJS.ErrnoException).code;\n if (code === 'EEXIST') return; // first creator wins\n if (code === 'EPERM' || code === 'ENOTSUP' || code === 'EACCES') {\n exclusiveWriteDirectSync(target, data);\n return;\n }\n throw e;\n }\n } finally {\n if (fd !== null) {\n try { fs.closeSync(fd); } catch { /* the write path already failed */ }\n }\n fs.rmSync(tmp, { force: true });\n }\n}\n\n/** Overwrite a file's bytes with random data before unlinking. */\nexport function shredFileSync(target: string, passes = 3): void {\n const stat = fs.statSync(target);\n if (!stat.isFile()) throw new Error(`shred: not a file: ${target}`);\n const buf = Buffer.alloc(Math.max(stat.size, 1));\n for (let i = 0; i < passes; i++) {\n randomFillSync(buf);\n fs.writeFileSync(target, buf);\n }\n fs.rmSync(target, { force: true });\n}\n\n/**\n * Best-effort burn for a plaintext window: shred it when it exists, ignore it\n * when it is already gone (H-59 — `rm` alone leaves the bytes on disk).\n */\nexport function burnFileSync(target: string): void {\n try {\n shredFileSync(target);\n } catch {\n fs.rmSync(target, { force: true });\n }\n}\n"],"mappings":";AAIA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,YAAY,sBAAsB;AAEpC,SAAS,WAAW,QAAgB,MAAM,KAAa;AAC5D,SAAO,KAAK;AAAA,IACV,KAAK,QAAQ,MAAM;AAAA,IACnB,IAAI,KAAK,SAAS,MAAM,CAAC,IAAI,GAAG,IAAI,WAAW,EAAE,MAAM,GAAG,CAAC,CAAC;AAAA,EAC9D;AACF;AAEO,SAAS,oBAAoB,QAAgB,MAAiC;AACnF,QAAM,MAAM,WAAW,MAAM;AAC7B,MAAI,KAAoB;AACxB,MAAI;AACF,SAAK,GAAG,SAAS,KAAK,GAAG;AACzB,OAAG,cAAc,IAAI,IAAI;AAKzB,OAAG,UAAU,EAAE;AACf,OAAG,UAAU,EAAE;AACf,SAAK;AACL,OAAG,WAAW,KAAK,MAAM;AAAA,EAC3B,UAAE;AACA,QAAI,OAAO,MAAM;AACf,UAAI;AAAE,WAAG,UAAU,EAAE;AAAA,MAAG,QAAQ;AAAA,MAAsC;AAAA,IACxE;AACA,OAAG,OAAO,KAAK,EAAE,OAAO,KAAK,CAAC;AAAA,EAChC;AACF;AAEO,SAAS,oBAAoB,QAAgB,OAAsB;AACxE,sBAAoB,QAAQ,KAAK,UAAU,OAAO,MAAM,CAAC,CAAC;AAC5D;AAYA,SAAS,yBAAyB,QAAgB,MAAiC;AACjF,QAAM,KAAK,GAAG,SAAS,QAAQ,IAAI;AACnC,MAAI;AACF,OAAG,cAAc,IAAI,IAAI;AACzB,OAAG,UAAU,EAAE;AAAA,EACjB,SAAS,GAAG;AACV,QAAI;AAAE,SAAG,UAAU,EAAE;AAAA,IAAG,QAAQ;AAAA,IAA4C;AAC5E,QAAI;AAAE,SAAG,OAAO,QAAQ,EAAE,OAAO,KAAK,CAAC;AAAA,IAAG,QAAQ;AAAA,IAAoB;AACtE,UAAM;AAAA,EACR;AACA,KAAG,UAAU,EAAE;AACjB;AASO,SAAS,qBAAqB,QAAgB,MAAiC;AACpF,QAAM,MAAM,WAAW,QAAQ,GAAG;AAClC,MAAI,KAAoB;AACxB,MAAI;AACF,SAAK,GAAG,SAAS,KAAK,GAAG;AACzB,OAAG,cAAc,IAAI,IAAI;AACzB,OAAG,UAAU,EAAE;AACf,OAAG,UAAU,EAAE;AACf,SAAK;AACL,QAAI;AACF,SAAG,SAAS,KAAK,MAAM;AAAA,IACzB,SAAS,GAAG;AACV,YAAM,OAAQ,EAA4B;AAC1C,UAAI,SAAS,SAAU;AACvB,UAAI,SAAS,WAAW,SAAS,aAAa,SAAS,UAAU;AAC/D,iCAAyB,QAAQ,IAAI;AACrC;AAAA,MACF;AACA,YAAM;AAAA,IACR;AAAA,EACF,UAAE;AACA,QAAI,OAAO,MAAM;AACf,UAAI;AAAE,WAAG,UAAU,EAAE;AAAA,MAAG,QAAQ;AAAA,MAAsC;AAAA,IACxE;AACA,OAAG,OAAO,KAAK,EAAE,OAAO,KAAK,CAAC;AAAA,EAChC;AACF;AAGO,SAAS,cAAc,QAAgB,SAAS,GAAS;AAC9D,QAAM,OAAO,GAAG,SAAS,MAAM;AAC/B,MAAI,CAAC,KAAK,OAAO,EAAG,OAAM,IAAI,MAAM,sBAAsB,MAAM,EAAE;AAClE,QAAM,MAAM,OAAO,MAAM,KAAK,IAAI,KAAK,MAAM,CAAC,CAAC;AAC/C,WAAS,IAAI,GAAG,IAAI,QAAQ,KAAK;AAC/B,mBAAe,GAAG;AAClB,OAAG,cAAc,QAAQ,GAAG;AAAA,EAC9B;AACA,KAAG,OAAO,QAAQ,EAAE,OAAO,KAAK,CAAC;AACnC;AAMO,SAAS,aAAa,QAAsB;AACjD,MAAI;AACF,kBAAc,MAAM;AAAA,EACtB,QAAQ;AACN,OAAG,OAAO,QAAQ,EAAE,OAAO,KAAK,CAAC;AAAA,EACnC;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
atomicWriteFileSync
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-66IUDHCY.js";
|
|
4
4
|
|
|
5
5
|
// src/core/bindings.ts
|
|
6
6
|
import fs from "fs";
|
|
@@ -65,4 +65,4 @@ export {
|
|
|
65
65
|
deliverTargets,
|
|
66
66
|
observeTargets
|
|
67
67
|
};
|
|
68
|
-
//# sourceMappingURL=chunk-
|
|
68
|
+
//# sourceMappingURL=chunk-77UYDI2A.js.map
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SNAPSHOT_ARCHIVE_NAME_RE
|
|
3
|
+
} from "./chunk-ERRPMYKB.js";
|
|
1
4
|
import {
|
|
2
5
|
isEncrypted,
|
|
3
6
|
loadEncryptedText,
|
|
4
7
|
saveEncryptedText
|
|
5
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-GOLMRQRW.js";
|
|
6
9
|
|
|
7
10
|
// src/vault/migrate.ts
|
|
8
11
|
import fs from "fs";
|
|
@@ -30,6 +33,12 @@ var MIGRATE_FILES = [
|
|
|
30
33
|
"browse.json",
|
|
31
34
|
"seeds.jsonl",
|
|
32
35
|
"ledger.md",
|
|
36
|
+
// 2.3.0: books are live-only, so the archives (and the corrections book)
|
|
37
|
+
// carry memory the main rows used to. Leaving them out moves a user and
|
|
38
|
+
// silently drops the completions / the whole corrections book.
|
|
39
|
+
"ledger-done.md",
|
|
40
|
+
"corrections.md",
|
|
41
|
+
"corrections-done.md",
|
|
33
42
|
"cursors.json",
|
|
34
43
|
// v1.9.0: persona report log + topic preference stats
|
|
35
44
|
"seed_report.jsonl",
|
|
@@ -40,6 +49,7 @@ var MIGRATE_WEEKLY_RE = /^weekly\/[^/\\]+\.json$/;
|
|
|
40
49
|
function isMigratablePath(rel) {
|
|
41
50
|
if (MIGRATE_FILES.includes(rel)) return true;
|
|
42
51
|
if (MIGRATE_ARCHIVE_RE.test(rel)) return true;
|
|
52
|
+
if (SNAPSHOT_ARCHIVE_NAME_RE.test(rel)) return true;
|
|
43
53
|
if (MIGRATE_WEEKLY_RE.test(rel)) return true;
|
|
44
54
|
return false;
|
|
45
55
|
}
|
|
@@ -60,11 +70,18 @@ function collectJournalArchives(guard, paths) {
|
|
|
60
70
|
return [];
|
|
61
71
|
}
|
|
62
72
|
}
|
|
73
|
+
function collectSnapshotArchives(guard, paths) {
|
|
74
|
+
try {
|
|
75
|
+
return fs.readdirSync(guard.assert(paths.dataDir)).filter((f) => SNAPSHOT_ARCHIVE_NAME_RE.test(f));
|
|
76
|
+
} catch {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
63
80
|
function collectMigrationEntries(guard, paths) {
|
|
64
81
|
const entries = [];
|
|
65
82
|
const packed = [];
|
|
66
83
|
const missing = [];
|
|
67
|
-
const rels = [...MIGRATE_FILES, ...collectJournalArchives(guard, paths), ...collectWeeklyFiles(guard, paths)];
|
|
84
|
+
const rels = [...MIGRATE_FILES, ...collectJournalArchives(guard, paths), ...collectSnapshotArchives(guard, paths), ...collectWeeklyFiles(guard, paths)];
|
|
68
85
|
for (const rel of rels) {
|
|
69
86
|
const abs = path.join(paths.dataDir, rel);
|
|
70
87
|
let absCanon;
|
|
@@ -260,4 +277,4 @@ export {
|
|
|
260
277
|
decryptContainer,
|
|
261
278
|
applyMigrationEntries
|
|
262
279
|
};
|
|
263
|
-
//# sourceMappingURL=chunk-
|
|
280
|
+
//# sourceMappingURL=chunk-AJ5JAQVB.js.map
|