@kanadego/dsh-heartbeat 2.2.1 → 2.3.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 +108 -303
- 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-AT32XCCI.js → chunk-43Q42HWH.js} +8 -2
- package/dist/chunk-43Q42HWH.js.map +1 -0
- 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-CJK6RTMH.js → chunk-ABFO4QII.js} +896 -167
- package/dist/chunk-ABFO4QII.js.map +1 -0
- package/dist/{chunk-M72T5MZU.js → chunk-GOLMRQRW.js} +3 -2
- package/dist/{chunk-XYBII5PR.js → chunk-HSTGRQLP.js} +178 -39
- package/dist/chunk-HSTGRQLP.js.map +1 -0
- package/dist/{chunk-KZLVR4J7.js → chunk-IPTNSXOY.js} +2 -2
- package/dist/{chunk-DLOYERAK.js → chunk-JIRQ36F7.js} +3 -3
- package/dist/{chunk-ECXYNTEV.js → chunk-K47VV6IQ.js} +5 -3
- package/dist/chunk-K47VV6IQ.js.map +1 -0
- package/dist/{chunk-F2XVKX55.js → chunk-KGOC6EX4.js} +3 -3
- package/dist/{chunk-SIY3YHFY.js → chunk-MMI6OBEC.js} +2 -2
- package/dist/{chunk-N6SMIGYJ.js → chunk-QOLKUYQ3.js} +2 -2
- package/dist/cli/index.js +94 -23
- 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 +60 -1
- package/dist/index.js +468 -155
- package/dist/index.js.map +1 -1
- package/dist/{migrate-XFZU5EBE.js → migrate-6HH2ZARV.js} +4 -4
- package/dist/{orchestrator-5BHYQ77Y.js → orchestrator-OJJM5QSV.js} +20 -11
- package/dist/{pool-76VLAZER.js → pool-QTY2MI56.js} +4 -4
- package/dist/runtime-RGZKOFP3.js +15 -0
- package/dist/{snapshot-SU2VGM4C.js → snapshot-6DFNGXTR.js} +5 -5
- package/package.json +1 -1
- 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-ECXYNTEV.js.map +0 -1
- package/dist/chunk-IBBAISSW.js.map +0 -1
- package/dist/chunk-XYBII5PR.js.map +0 -1
- package/dist/runtime-W2OWJIHY.js +0 -11
- /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-DLOYERAK.js.map → chunk-JIRQ36F7.js.map} +0 -0
- /package/dist/{chunk-F2XVKX55.js.map → chunk-KGOC6EX4.js.map} +0 -0
- /package/dist/{chunk-SIY3YHFY.js.map → chunk-MMI6OBEC.js.map} +0 -0
- /package/dist/{chunk-N6SMIGYJ.js.map → chunk-QOLKUYQ3.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-6HH2ZARV.js.map} +0 -0
- /package/dist/{orchestrator-5BHYQ77Y.js.map → orchestrator-OJJM5QSV.js.map} +0 -0
- /package/dist/{pool-76VLAZER.js.map → pool-QTY2MI56.js.map} +0 -0
- /package/dist/{runtime-W2OWJIHY.js.map → runtime-RGZKOFP3.js.map} +0 -0
- /package/dist/{snapshot-SU2VGM4C.js.map → snapshot-6DFNGXTR.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
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
isEncrypted,
|
|
3
3
|
loadEncryptedText,
|
|
4
4
|
saveEncryptedText
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-GOLMRQRW.js";
|
|
6
6
|
|
|
7
7
|
// src/vault/migrate.ts
|
|
8
8
|
import fs from "fs";
|
|
@@ -30,6 +30,12 @@ var MIGRATE_FILES = [
|
|
|
30
30
|
"browse.json",
|
|
31
31
|
"seeds.jsonl",
|
|
32
32
|
"ledger.md",
|
|
33
|
+
// 2.3.0: books are live-only, so the archives (and the corrections book)
|
|
34
|
+
// carry memory the main rows used to. Leaving them out moves a user and
|
|
35
|
+
// silently drops the completions / the whole corrections book.
|
|
36
|
+
"ledger-done.md",
|
|
37
|
+
"corrections.md",
|
|
38
|
+
"corrections-done.md",
|
|
33
39
|
"cursors.json",
|
|
34
40
|
// v1.9.0: persona report log + topic preference stats
|
|
35
41
|
"seed_report.jsonl",
|
|
@@ -260,4 +266,4 @@ export {
|
|
|
260
266
|
decryptContainer,
|
|
261
267
|
applyMigrationEntries
|
|
262
268
|
};
|
|
263
|
-
//# sourceMappingURL=chunk-
|
|
269
|
+
//# sourceMappingURL=chunk-43Q42HWH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vault/migrate.ts"],"sourcesContent":["// Cross-machine migration (v1.8.0). DPAPI binds the sensitive stores to one\n// machine + account, so a new machine cannot read them — this module packs\n// the memory files into ONE passphrase-encrypted container (AES-256-GCM,\n// scrypt-derived key, node:crypto only) that can travel safely, and restores\n// them on the other side re-encrypted with the LOCAL DPAPI.\n//\n// Restore is byte-identical: for each file we record whether it was DPAPI\n// encrypted on disk (isEncrypted magic check) and write it back through the\n// same path — no per-module write semantics to keep in sync. Existing files\n// are backed up before overwrite (rule 4).\n\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport {\n createCipheriv,\n createDecipheriv,\n randomBytes,\n scryptSync,\n} from 'node:crypto';\nimport type { PathGuard } from '../core/path-guard.js';\nimport type { WorkspacePaths } from '../core/paths.js';\nimport { isEncrypted, loadEncryptedText, saveEncryptedText } from './vault.js';\n\nexport const MIGRATE_MAGIC = 'HBMIG1';\nexport const MIGRATE_VERSION = 1;\n/** scrypt cost for NEW containers (2^14 = Node's default, 16 MiB of work).\n * Reading is parameterised by the container's own kdf.N, so raising this\n * never orphans an existing export. */\nconst KDF_N = 163_84;\n/** Hard bounds for a container-supplied N: a hostile/broken container must not\n * be able to make the import allocate unbounded memory. */\nconst KDF_N_MIN = 1 << 12; // 2^12 = 4 MiB\nconst KDF_N_MAX = 1 << 16; // 2^16 = 64 MiB\n/** Node's scrypt maxmem defaults to 32 MiB, which N=2^15 already exceeds — a\n * legal container with a larger N would fail without an explicit cap. */\nconst SCRYPT_MAXMEM = 128 * 1024 * 1024;\nconst KEY_LEN = 32;\n\n/** Memory-relevant runtime files (dataDir-relative). Deliberately NOT here:\n * gate.json (machine-local counters + home session id — the new machine\n * builds its own) and screen snapshots (per-beat transients, not memory). */\nexport const MIGRATE_FILES = [\n 'profile.json',\n 'profile_snapshot.json',\n 'profile_inbox.jsonl',\n 'profile_journal.jsonl',\n 'profile_rhythm.json',\n 'sent.json',\n 'browse.json',\n 'seeds.jsonl',\n 'ledger.md',\n // 2.3.0: books are live-only, so the archives (and the corrections book)\n // carry memory the main rows used to. Leaving them out moves a user and\n // silently drops the completions / the whole corrections book.\n 'ledger-done.md',\n 'corrections.md',\n 'corrections-done.md',\n 'cursors.json',\n // v1.9.0: persona report log + topic preference stats\n 'seed_report.jsonl',\n 'preference.json',\n];\n\n/** HB-18: an import writes with the user's privileges inside data/, so the set\n * of names a container may touch is closed, not merely sanitised. Anything an\n * export can produce is here; everything else (gate.json, settings/, vault.key,\n * other modules' files) is refused. */\nconst MIGRATE_ARCHIVE_RE = /^profile_journal\\.archive-\\d+\\.jsonl$/;\nconst MIGRATE_WEEKLY_RE = /^weekly\\/[^/\\\\]+\\.json$/;\n\nexport function isMigratablePath(rel: string): boolean {\n if (MIGRATE_FILES.includes(rel)) return true;\n if (MIGRATE_ARCHIVE_RE.test(rel)) return true;\n if (MIGRATE_WEEKLY_RE.test(rel)) return true;\n return false;\n}\n\n/** HB-18: budget for a container-supplied payload. Generous next to a real\n * memory (a few MB), small next to what a hostile container would like. */\nexport const MIGRATE_MAX_FILES = 5_000;\nexport const MIGRATE_MAX_BYTES = 64 * 1024 * 1024;\n\nexport interface MigrateEntry {\n path: string; // dataDir-relative\n encrypted: boolean; // was DPAPI-encrypted on the source machine\n content: string;\n}\n\nexport interface MigrateProgress {\n packed: string[];\n missing: string[];\n}\n\nfunction collectWeeklyFiles(guard: PathGuard, paths: WorkspacePaths): string[] {\n const dir = path.join(paths.dataDir, 'weekly');\n try {\n return fs.readdirSync(guard.assert(dir))\n .filter((f) => f.endsWith('.json'))\n .map((f) => path.join('weekly', f).replace(/\\\\/g, '/'));\n } catch {\n return [];\n }\n}\n\n/** Journal archive shards (snapshot rotation output) travel with the memory. */\nfunction collectJournalArchives(guard: PathGuard, paths: WorkspacePaths): string[] {\n try {\n return fs.readdirSync(guard.assert(paths.dataDir))\n .filter((f) => f.startsWith('profile_journal.archive-') && f.endsWith('.jsonl'));\n } catch {\n return [];\n }\n}\n\n/** Read every migration file. A DPAPI file that fails to decrypt aborts the\n * export — a silent half-memory container would be worse than a loud error. */\nexport function collectMigrationEntries(guard: PathGuard, paths: WorkspacePaths): { entries: MigrateEntry[]; progress: MigrateProgress } {\n const entries: MigrateEntry[] = [];\n const packed: string[] = [];\n const missing: string[] = [];\n const rels = [...MIGRATE_FILES, ...collectJournalArchives(guard, paths), ...collectWeeklyFiles(guard, paths)];\n for (const rel of rels) {\n const abs = path.join(paths.dataDir, rel);\n let absCanon: string;\n try {\n absCanon = guard.assert(abs);\n } catch {\n missing.push(rel);\n continue;\n }\n if (!fs.existsSync(absCanon)) {\n missing.push(rel);\n continue;\n }\n const encrypted = isEncrypted(absCanon);\n const content = encrypted\n ? loadEncryptedText(guard, absCanon) ?? (() => { throw new Error(`cannot decrypt ${rel} on this machine`); })()\n : fs.readFileSync(absCanon, 'utf8');\n entries.push({ path: rel.replace(/\\\\/g, '/'), encrypted, content });\n packed.push(rel);\n }\n return { entries, progress: { packed, missing } };\n}\n\n/** Derive the key with the container's OWN cost parameter. `n` must already\n * have passed assertKdfN (export uses the current default). */\nfunction deriveKey(passphrase: string, salt: Buffer, n: number): Buffer {\n return scryptSync(passphrase, salt, KEY_LEN, { N: n, r: 8, p: 1, maxmem: SCRYPT_MAXMEM });\n}\n\n/** Validate the scrypt cost carried by a container. A missing/absurd N is a\n * BROKEN container — reported as such, never as \"wrong passphrase\" (before\n * 2026-10-06 the N in the container was ignored and the two were the same\n * error, so raising the cost would have orphaned every old export). */\nfunction assertKdfN(v: unknown): number {\n const n = Number(v);\n if (!Number.isInteger(n) || n <= 0 || (n & (n - 1)) !== 0) {\n throw new Error('migrate: container has invalid kdf parameters (N must be a power of two)');\n }\n if (n < KDF_N_MIN || n > KDF_N_MAX) {\n throw new Error(`migrate: container kdf N ${n} is outside the supported range [${KDF_N_MIN}, ${KDF_N_MAX}]`);\n }\n return n;\n}\n\n/** HB-18: a container does not get to decide how much work the import does. */\nfunction assertMigrateBudget(files: unknown[]): asserts files is MigrateEntry[] {\n if (files.length > MIGRATE_MAX_FILES) {\n throw new Error(`migrate: container lists ${files.length} files, over the ${MIGRATE_MAX_FILES} limit`);\n }\n let bytes = 0;\n for (const f of files) {\n const entry = f as { path?: unknown; content?: unknown } | null;\n if (!entry || typeof entry.path !== 'string' || typeof entry.content !== 'string') {\n throw new Error('migrate: container file entry is malformed');\n }\n bytes += Buffer.byteLength(entry.content, 'utf8');\n if (bytes > MIGRATE_MAX_BYTES) {\n throw new Error(`migrate: container payload exceeds ${MIGRATE_MAX_BYTES} bytes`);\n }\n }\n}\n\n/** Build the container file content. Everything sensitive lives inside the\n * ciphertext; the outer JSON carries only crypto parameters. */\nexport function encryptContainer(entries: MigrateEntry[], passphrase: string, now = new Date()): string {\n if (!passphrase) throw new Error('migrate: passphrase must not be empty');\n const salt = randomBytes(16);\n const iv = randomBytes(12);\n const key = deriveKey(passphrase, salt, KDF_N);\n const cipher = createCipheriv('aes-256-gcm', key, iv);\n const plain = Buffer.from(JSON.stringify({ version: MIGRATE_VERSION, createdAt: now.toISOString(), files: entries }), 'utf8');\n const data = Buffer.concat([cipher.update(plain), cipher.final()]);\n const tag = cipher.getAuthTag();\n return JSON.stringify({\n magic: MIGRATE_MAGIC,\n kdf: { name: 'scrypt', salt: salt.toString('hex'), N: KDF_N },\n iv: iv.toString('hex'),\n tag: tag.toString('hex'),\n data: data.toString('base64'),\n }, null, 1) + '\\n';\n}\n\n/** Parse + decrypt a container. Throws (loudly) on a wrong passphrase or a\n * corrupted file — never returns partial data. */\nexport function decryptContainer(text: string, passphrase: string): { createdAt: string; files: MigrateEntry[] } {\n let outer: { magic?: string; kdf?: { salt?: string; N?: unknown }; iv?: string; tag?: string; data?: string };\n try {\n outer = JSON.parse(text);\n } catch {\n throw new Error('migrate: not a migration container (bad JSON)');\n }\n if (outer.magic !== MIGRATE_MAGIC) throw new Error('migrate: not a migration container (bad magic)');\n const n = assertKdfN(outer.kdf?.N);\n const salt = Buffer.from(String(outer.kdf?.salt ?? ''), 'hex');\n const iv = Buffer.from(String(outer.iv ?? ''), 'hex');\n const tag = Buffer.from(String(outer.tag ?? ''), 'hex');\n // HB-18: refuse an oversized payload before decoding it. base64 runs ~4/3 of\n // the ciphertext, so this cheap length check bounds the allocation below.\n const dataB64 = String(outer.data ?? '');\n if (dataB64.length > MIGRATE_MAX_BYTES * 2) {\n throw new Error(`migrate: container payload is too large (${dataB64.length} base64 chars)`);\n }\n const data = Buffer.from(dataB64, 'base64');\n const key = deriveKey(passphrase, salt, n);\n const decipher = createDecipheriv('aes-256-gcm', key, iv);\n decipher.setAuthTag(tag);\n let plain: Buffer;\n try {\n plain = Buffer.concat([decipher.update(data), decipher.final()]);\n } catch {\n throw new Error('migrate: wrong passphrase or corrupted container');\n }\n const inner = JSON.parse(plain.toString('utf8')) as { version: number; createdAt: string; files: MigrateEntry[] };\n if (inner.version !== MIGRATE_VERSION) throw new Error(`migrate: unsupported container version ${inner.version}`);\n if (!Array.isArray(inner.files)) throw new Error('migrate: container has no file list');\n assertMigrateBudget(inner.files);\n return { createdAt: inner.createdAt, files: inner.files };\n}\n\nexport interface MigrateImportResult {\n restored: string[];\n backedUp: string[];\n skipped: string[];\n /** H-21: files put back from their backups after a failed commit phase. */\n rolledBack?: string[];\n /** H-21: set when the commit phase failed and the import was rolled back. */\n error?: string;\n}\n\n/**\n * Restore entries into the local dataDir, re-encrypting DPAPI files with the\n * LOCAL machine key.\n *\n * H-21: this used to be a per-file \"back up, then overwrite\" loop with no\n * pre-flight and no rollback — a failure halfway through left a mixed memory\n * (a new `profile.json` next to a stale `profile_journal.jsonl`). Now it runs\n * in two phases: stage every entry next to its target (nothing visible changes\n * yet), then commit each one by rename. A commit failure rolls the\n * already-committed files back from their backups.\n *\n * HB-06 (2026-10-17): the phases are all-or-nothing at BOTH ends. Earlier a\n * staging failure only skipped that entry and the rest were still committed,\n * so one bad path was enough to leave a half-migrated memory. Now any skipped\n * entry aborts the whole import with nothing written; the reason is returned\n * in `error` alongside the offending names.\n */\nexport function applyMigrationEntries(guard: PathGuard, paths: WorkspacePaths, files: MigrateEntry[], now = Date.now()): MigrateImportResult {\n const restored: string[] = [];\n const backedUp: string[] = [];\n const skipped: string[] = [];\n const stamp = new Date(now).toISOString().replace(/[-:T]/g, '').slice(0, 14);\n const staged: Array<{ rel: string; abs: string; incoming: string }> = [];\n for (const f of files) {\n const rel = String(f.path ?? '');\n // String-level rejection BEFORE the path is resolved: the guard's realpath\n // check already refuses escapes, but an import must not depend on another\n // module staying correct. HB-18: and the name must be one an export can\n // produce - a container may not reach settings/, gate.json or vault.key.\n if (!rel || rel.includes('..') || path.isAbsolute(rel) || !isMigratablePath(rel)) {\n skipped.push(rel);\n continue;\n }\n const abs = path.join(paths.dataDir, rel);\n let absCanon: string;\n try {\n absCanon = guard.assert(abs);\n } catch {\n skipped.push(rel); // path refused by the guard — never write it\n continue;\n }\n const incoming = `${absCanon}.incoming-${stamp}`;\n try {\n fs.mkdirSync(path.dirname(absCanon), { recursive: true });\n if (f.encrypted) saveEncryptedText(guard, incoming, f.content);\n else fs.writeFileSync(incoming, f.content, 'utf8');\n staged.push({ rel, abs: absCanon, incoming });\n } catch {\n skipped.push(rel);\n try {\n fs.rmSync(incoming, { force: true });\n } catch {\n /* nothing staged */\n }\n }\n }\n // HB-06: staging is the point of no return. A single entry that could not be\n // staged used to be skipped while the rest were committed, which left a\n // half-migrated memory (a new profile.json next to a stale journal). Any skip\n // now aborts the import with nothing written; the reason travels in `error`.\n if (skipped.length > 0) {\n for (const s of staged) {\n try {\n fs.rmSync(s.incoming, { force: true });\n } catch {\n /* nothing staged */\n }\n }\n return {\n restored: [],\n backedUp: [],\n skipped,\n error: `staging failed for ${skipped.length} file(s): ${skipped.join(', ')}; nothing was imported`,\n };\n }\n const committed: Array<{ rel: string; abs: string; backup: string | null }> = [];\n try {\n for (const s of staged) {\n let backup: string | null = null;\n if (fs.existsSync(s.abs)) {\n backup = `${s.abs}.bak-migrate-${stamp}`;\n fs.copyFileSync(s.abs, backup);\n backedUp.push(s.rel);\n }\n fs.renameSync(s.incoming, s.abs);\n committed.push({ rel: s.rel, abs: s.abs, backup });\n restored.push(s.rel);\n }\n return { restored, backedUp, skipped };\n } catch (e) {\n // Roll back so the dataDir never holds a half-migrated mix; staged files\n // that were never committed are simply dropped.\n const rolledBack: string[] = [];\n for (const c of committed.reverse()) {\n try {\n if (c.backup) fs.renameSync(c.backup, c.abs);\n else fs.rmSync(c.abs, { force: true });\n rolledBack.push(c.rel);\n } catch {\n /* best effort — the backup file itself is still on disk */\n }\n }\n for (const s of staged) {\n if (committed.some((c) => c.abs === s.abs)) continue;\n try {\n fs.rmSync(s.incoming, { force: true });\n } catch {\n /* already gone */\n }\n }\n return { restored: [], backedUp, skipped, rolledBack, error: String(e) };\n }\n}\n"],"mappings":";;;;;;;AAWA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAKA,IAAM,gBAAgB;AACtB,IAAM,kBAAkB;AAI/B,IAAM,QAAQ;AAGd,IAAM,YAAY,KAAK;AACvB,IAAM,YAAY,KAAK;AAGvB,IAAM,gBAAgB,MAAM,OAAO;AACnC,IAAM,UAAU;AAKT,IAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA,EAEA;AAAA,EACA;AACF;AAMA,IAAM,qBAAqB;AAC3B,IAAM,oBAAoB;AAEnB,SAAS,iBAAiB,KAAsB;AACrD,MAAI,cAAc,SAAS,GAAG,EAAG,QAAO;AACxC,MAAI,mBAAmB,KAAK,GAAG,EAAG,QAAO;AACzC,MAAI,kBAAkB,KAAK,GAAG,EAAG,QAAO;AACxC,SAAO;AACT;AAIO,IAAM,oBAAoB;AAC1B,IAAM,oBAAoB,KAAK,OAAO;AAa7C,SAAS,mBAAmB,OAAkB,OAAiC;AAC7E,QAAM,MAAM,KAAK,KAAK,MAAM,SAAS,QAAQ;AAC7C,MAAI;AACF,WAAO,GAAG,YAAY,MAAM,OAAO,GAAG,CAAC,EACpC,OAAO,CAAC,MAAM,EAA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AAAA,YACtC,IAAG,OAAO,EAAE,KAAK,EAAE,OAAO,KAAK,CAAC;AACrC,mBAAW,KAAK,EAAE,GAAG;AAAA,MACvB,QAAQ;AAAA,MAER;AAAA,IACF;AACA,eAAW,KAAK,QAAQ;AACtB,UAAI,UAAU,KAAK,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAG;AAC5C,UAAI;AACF,WAAG,OAAO,EAAE,UAAU,EAAE,OAAO,KAAK,CAAC;AAAA,MACvC,QAAQ;AAAA,MAER;AAAA,IACF;AACA,WAAO,EAAE,UAAU,CAAC,GAAG,UAAU,SAAS,YAAY,OAAO,OAAO,CAAC,EAAE;AAAA,EACzE;AACF;","names":[]}
|
|
@@ -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
|