@kanadego/dsh-heartbeat 2.0.1 → 2.1.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.
Files changed (50) hide show
  1. package/README.md +77 -23
  2. package/client.js +498 -125
  3. package/config/interests.json +1 -1
  4. package/config/policy.json +3 -2
  5. package/dist/{chunk-TVX4HV4Y.js → chunk-63E5OYSI.js} +56 -5
  6. package/dist/chunk-63E5OYSI.js.map +1 -0
  7. package/dist/{chunk-NCPKOWS7.js → chunk-AT32XCCI.js} +2 -2
  8. package/dist/{chunk-DC5HMCJC.js → chunk-DLOYERAK.js} +3 -3
  9. package/dist/{chunk-544QOJN5.js → chunk-ECXYNTEV.js} +2 -2
  10. package/dist/{chunk-IFRMKVIC.js → chunk-HE6IF6OU.js} +5 -2
  11. package/dist/chunk-HE6IF6OU.js.map +1 -0
  12. package/dist/{chunk-DZ7YCFGX.js → chunk-KZLVR4J7.js} +2 -2
  13. package/dist/{chunk-6XM6KY7M.js → chunk-LPPRI53J.js} +39 -37
  14. package/dist/chunk-LPPRI53J.js.map +1 -0
  15. package/dist/chunk-LQKOYTRL.js +59 -0
  16. package/dist/chunk-LQKOYTRL.js.map +1 -0
  17. package/dist/{chunk-AKIJ4LS2.js → chunk-M72T5MZU.js} +44 -1
  18. package/dist/chunk-M72T5MZU.js.map +1 -0
  19. package/dist/{chunk-6MVKWICX.js → chunk-XCMGPIUQ.js} +99 -23
  20. package/dist/chunk-XCMGPIUQ.js.map +1 -0
  21. package/dist/cli/index.js +51 -11
  22. package/dist/cli/index.js.map +1 -1
  23. package/dist/focus-store-RNHBAFYS.js +20 -0
  24. package/dist/{inbox-OWBK6PE2.js → inbox-ZLX2MH7A.js} +3 -3
  25. package/dist/index.d.ts +16 -3
  26. package/dist/index.js +119 -69
  27. package/dist/index.js.map +1 -1
  28. package/dist/{migrate-TQ5PB2DI.js → migrate-XFZU5EBE.js} +3 -3
  29. package/dist/{orchestrator-P7AEWVYR.js → orchestrator-MNFCPH43.js} +27 -8
  30. package/dist/{pool-2T6TVS2L.js → pool-MAABBHC4.js} +9 -3
  31. package/dist/{snapshot-F5B2DD56.js → snapshot-SU2VGM4C.js} +4 -4
  32. package/dist/snapshot-SU2VGM4C.js.map +1 -0
  33. package/icon.svg +11 -0
  34. package/locale/en.json +6 -0
  35. package/locale/zh.json +6 -0
  36. package/package.json +11 -6
  37. package/dist/chunk-6MVKWICX.js.map +0 -1
  38. package/dist/chunk-6XM6KY7M.js.map +0 -1
  39. package/dist/chunk-AKIJ4LS2.js.map +0 -1
  40. package/dist/chunk-IFRMKVIC.js.map +0 -1
  41. package/dist/chunk-TVX4HV4Y.js.map +0 -1
  42. /package/dist/{chunk-NCPKOWS7.js.map → chunk-AT32XCCI.js.map} +0 -0
  43. /package/dist/{chunk-DC5HMCJC.js.map → chunk-DLOYERAK.js.map} +0 -0
  44. /package/dist/{chunk-544QOJN5.js.map → chunk-ECXYNTEV.js.map} +0 -0
  45. /package/dist/{chunk-DZ7YCFGX.js.map → chunk-KZLVR4J7.js.map} +0 -0
  46. /package/dist/{inbox-OWBK6PE2.js.map → focus-store-RNHBAFYS.js.map} +0 -0
  47. /package/dist/{migrate-TQ5PB2DI.js.map → inbox-ZLX2MH7A.js.map} +0 -0
  48. /package/dist/{orchestrator-P7AEWVYR.js.map → migrate-XFZU5EBE.js.map} +0 -0
  49. /package/dist/{pool-2T6TVS2L.js.map → orchestrator-MNFCPH43.js.map} +0 -0
  50. /package/dist/{snapshot-F5B2DD56.js.map → pool-MAABBHC4.js.map} +0 -0
package/dist/index.js CHANGED
@@ -1,53 +1,53 @@
1
- import {
2
- EXCERPT_HEADER,
3
- appendExcerpt,
4
- createPathGuard,
5
- deepMerge,
6
- describeInstall,
7
- excerptFilePath,
8
- installBundledPreset,
9
- loadPolicy,
10
- readExcerpts,
11
- recentExcerpts,
12
- removeExcerpt,
13
- updateUserPolicy,
14
- userPresetRoot
15
- } from "./chunk-IFRMKVIC.js";
16
- import {
17
- addBinding,
18
- loadBindings,
19
- removeBinding
20
- } from "./chunk-3DNGY4DS.js";
21
1
  import {
22
2
  StatusReader,
23
3
  applyHeartbeatInterval,
24
4
  buildDigest,
25
5
  buildSeedReportTool,
26
6
  clearNote,
7
+ formatFocusClock,
8
+ getFocusUntil,
27
9
  getLastBeat,
28
10
  homeSessionId,
29
11
  inQuietHours,
30
12
  notepadFilePath,
31
13
  notepadView,
14
+ pauseFocus,
32
15
  readNotepad,
33
16
  readSentState,
34
17
  readStatus,
35
18
  reportFilePath,
36
19
  resetHomeSession,
20
+ resumeFocus,
37
21
  sessionEventCount,
38
22
  sessionEvents,
39
23
  startOrchestrator,
40
24
  writeNote
41
- } from "./chunk-6MVKWICX.js";
25
+ } from "./chunk-XCMGPIUQ.js";
26
+ import {
27
+ EXCERPT_HEADER,
28
+ appendExcerpt,
29
+ createPathGuard,
30
+ deepMerge,
31
+ describeInstall,
32
+ excerptFilePath,
33
+ installBundledPreset,
34
+ loadPolicy,
35
+ readExcerpts,
36
+ recentExcerpts,
37
+ removeExcerpt,
38
+ updateUserPolicy,
39
+ userPresetRoot
40
+ } from "./chunk-HE6IF6OU.js";
42
41
  import {
43
42
  appendEntry,
44
43
  ledgerFilePath,
45
44
  listWeeklyReports,
45
+ localDayKey,
46
46
  markDone,
47
47
  readLedger,
48
48
  readWeeklyReport,
49
49
  scanPending
50
- } from "./chunk-6XM6KY7M.js";
50
+ } from "./chunk-LPPRI53J.js";
51
51
  import {
52
52
  getRuntime,
53
53
  setRuntime
@@ -60,19 +60,29 @@ import {
60
60
  loadPool,
61
61
  restoreSeed,
62
62
  seedsFilePath
63
- } from "./chunk-TVX4HV4Y.js";
64
- import "./chunk-DZ7YCFGX.js";
65
- import "./chunk-DC5HMCJC.js";
63
+ } from "./chunk-63E5OYSI.js";
64
+ import {
65
+ clearFocusState,
66
+ readFocusState,
67
+ writeFocusState
68
+ } from "./chunk-LQKOYTRL.js";
69
+ import "./chunk-KZLVR4J7.js";
70
+ import "./chunk-DLOYERAK.js";
66
71
  import {
67
72
  appendAuditLine,
68
73
  loadProfile,
69
74
  profileFilePath
70
- } from "./chunk-544QOJN5.js";
75
+ } from "./chunk-ECXYNTEV.js";
71
76
  import {
72
77
  dshHomeDir,
73
78
  initWorkspace,
74
79
  writeText
75
- } from "./chunk-AKIJ4LS2.js";
80
+ } from "./chunk-M72T5MZU.js";
81
+ import {
82
+ addBinding,
83
+ loadBindings,
84
+ removeBinding
85
+ } from "./chunk-3DNGY4DS.js";
76
86
  import {
77
87
  atomicWriteFileSync,
78
88
  atomicWriteJsonSync
@@ -249,6 +259,13 @@ function turnOriginIsInboxSplice(session) {
249
259
  if (splicedIdx < 0) return false;
250
260
  return splicedIdx > turnEndIdx;
251
261
  }
262
+ function isSubagentSession(session) {
263
+ if (!session) return false;
264
+ const header = session.header;
265
+ if (header?.origin === "subagent") return true;
266
+ if (typeof header?.delegationDepth === "number" && header.delegationDepth > 0) return true;
267
+ return sessionEvents(session).slice(0, 8).some((e) => e?.type === "subagent/descriptor");
268
+ }
252
269
  function formatElapsed(ms) {
253
270
  const minutes = Math.max(1, Math.round(ms / 6e4));
254
271
  if (minutes < 60) return `${minutes} \u5206\u949F`;
@@ -321,6 +338,14 @@ function registerTimeInjection(ctx, guard, dataDir, opts) {
321
338
  now,
322
339
  intervalMs
323
340
  })) return decision;
341
+ if (isSubagentSession(payload.agent.session)) {
342
+ appendAuditLine(opts.paths.logsDir + "/heartbeat.jsonl", {
343
+ event: "time_inject_skipped",
344
+ sessionId,
345
+ reason: "subagent"
346
+ });
347
+ return decision;
348
+ }
324
349
  try {
325
350
  const { createUserMessage } = await import("@deepseek-ai/dsh-llm");
326
351
  let text = renderTimeText({
@@ -519,6 +544,42 @@ function buildEndpoints(deps, isLive) {
519
544
  return ok({ sessions: out });
520
545
  },
521
546
  "bindings.get": () => ok(loadBindings(guard, paths.settingsDir)),
547
+ // Focus mode (v2.1.0 ①). The card and the CLI are two clients of the same
548
+ // pause: module state gives the host an immediate answer, data/focus.json
549
+ // carries it across processes (and survives a restart). `status` merges
550
+ // both so the card shows a pause the CLI set and vice versa.
551
+ "focus.status"() {
552
+ const now = Date.now();
553
+ const file = readFocusState(guard, paths, now);
554
+ const mem = getFocusUntil();
555
+ const until = Math.max(mem > now ? mem : 0, file?.until ?? 0);
556
+ return ok({
557
+ paused: until > now,
558
+ until: until > now ? new Date(until).toISOString() : null,
559
+ clock: until > now ? formatFocusClock(until) : null,
560
+ minutes: file?.minutes ?? null,
561
+ via: file?.via ?? (mem > now ? "rpc" : null)
562
+ });
563
+ },
564
+ "focus.pause"(p) {
565
+ const raw = Number(p.minutes ?? 30);
566
+ if (!Number.isFinite(raw) || raw <= 0) return err("bad-request", "minutes must be a positive number (1-1440)");
567
+ const now = Date.now();
568
+ const mem = pauseFocus(raw);
569
+ const file = writeFocusState(guard, paths, raw, now, "settings-card");
570
+ const until = Math.max(mem, file.until);
571
+ return ok({
572
+ paused: true,
573
+ until: new Date(until).toISOString(),
574
+ clock: formatFocusClock(until),
575
+ minutes: file.minutes
576
+ });
577
+ },
578
+ "focus.resume"() {
579
+ resumeFocus();
580
+ const removed = clearFocusState(guard, paths);
581
+ return ok({ paused: false, removed });
582
+ },
522
583
  "bindings.add"(p) {
523
584
  const id = String(p.sessionId ?? "");
524
585
  if (!id.startsWith("session-")) return err("bad-request", "sessionId must look like session-...");
@@ -662,10 +723,10 @@ function buildEndpoints(deps, isLive) {
662
723
  async "migrate.export"(p) {
663
724
  const passphrase = String(p.passphrase ?? "");
664
725
  if (!passphrase) return err("bad-request", "\u9700\u8981\u8BBE\u7F6E\u53E3\u4EE4");
665
- const { collectMigrationEntries, encryptContainer } = await import("./migrate-TQ5PB2DI.js");
726
+ const { collectMigrationEntries, encryptContainer } = await import("./migrate-XFZU5EBE.js");
666
727
  const { entries } = collectMigrationEntries(guard, paths);
667
728
  if (entries.length === 0) return err("bad-request", "\u6CA1\u6709\u53EF\u6253\u5305\u7684\u8BB0\u5FC6\u6587\u4EF6\uFF08data/ \u662F\u7A7A\u7684\uFF09");
668
- const out = path4.join(paths.exportsDir, `heartbeat-memory-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.hbmig`);
729
+ const out = path4.join(paths.exportsDir, `heartbeat-memory-${localDayKey()}.hbmig`);
669
730
  writeText(guard, out, encryptContainer(entries, passphrase));
670
731
  appendAuditLine(guard.assert(paths.logsDir + "/heartbeat.jsonl"), { event: "migrate_export", files: entries.length });
671
732
  return ok({ path: out, count: entries.length });
@@ -674,7 +735,7 @@ function buildEndpoints(deps, isLive) {
674
735
  const passphrase = String(p.passphrase ?? "");
675
736
  const file = String(p.file ?? "");
676
737
  if (!passphrase || !file) return err("bad-request", "\u9700\u8981\u5BB9\u5668\u8DEF\u5F84\u4E0E\u53E3\u4EE4");
677
- const { decryptContainer, applyMigrationEntries } = await import("./migrate-TQ5PB2DI.js");
738
+ const { decryptContainer, applyMigrationEntries } = await import("./migrate-XFZU5EBE.js");
678
739
  let text;
679
740
  try {
680
741
  text = fs4.readFileSync(file, "utf8");
@@ -887,17 +948,31 @@ function heartbeatPresetDefinition(id = "heartbeat") {
887
948
  ]
888
949
  };
889
950
  }
951
+ var DUPLICATE_RE = /Duplicate agent preset/i;
952
+ var DUPLICATE_RETRY_MS = [80, 160, 320];
953
+ function delay(ms) {
954
+ return new Promise((resolve) => {
955
+ setTimeout(resolve, ms);
956
+ });
957
+ }
890
958
  async function registerHeartbeatPreset(service, id = "heartbeat", enabled = true) {
891
959
  if (!enabled) return { action: "skipped-disabled", id };
892
960
  const registrar = service;
893
961
  if (registrar === void 0 || registrar === null || typeof registrar.register !== "function") {
894
962
  return { action: "skipped-no-api", id };
895
963
  }
896
- try {
897
- const disposer = await registrar.register(heartbeatPresetDefinition(id));
898
- return typeof disposer === "function" ? { action: "registered", id, disposer } : { action: "registered", id };
899
- } catch (e) {
900
- return { action: "error", id, detail: String(e).slice(0, 200) };
964
+ let detail = "";
965
+ for (let attempt = 0; ; attempt += 1) {
966
+ try {
967
+ const disposer = await registrar.register(heartbeatPresetDefinition(id));
968
+ return typeof disposer === "function" ? { action: "registered", id, disposer } : { action: "registered", id };
969
+ } catch (e) {
970
+ detail = String(e).slice(0, 200);
971
+ if (!DUPLICATE_RE.test(detail)) return { action: "error", id, detail };
972
+ const wait = DUPLICATE_RETRY_MS[attempt];
973
+ if (wait === void 0) return { action: "already-registered", id, detail };
974
+ await delay(wait);
975
+ }
901
976
  }
902
977
  }
903
978
 
@@ -1125,7 +1200,7 @@ ${items.join("\n")}` };
1125
1200
 
1126
1201
  // src/index.ts
1127
1202
  var name = "heartbeat";
1128
- var inject = ["agents", "settings"];
1203
+ var inject = ["agents"];
1129
1204
  var Config = z.object({
1130
1205
  /** Override the runtime data dir (workspace guard boundary). Empty = default (<packageRoot>/data). */
1131
1206
  dataDir: z.string().default(""),
@@ -1236,6 +1311,8 @@ function apply(ctx, config = {}) {
1236
1311
  ctx.logger.warn("heartbeat: preset register failed (%s) \u2014 the engine room runs without it", result2.detail ?? "");
1237
1312
  } else if (result2.action === "registered") {
1238
1313
  ctx.logger.info("heartbeat: preset %s registered at runtime", result2.id);
1314
+ } else if (result2.action === "already-registered") {
1315
+ ctx.logger.info("heartbeat: preset %s already registered \u2014 reusing it", result2.id);
1239
1316
  } else {
1240
1317
  ctx.logger.info("heartbeat: preset registration skipped (%s)", result2.action);
1241
1318
  }
@@ -1281,47 +1358,20 @@ function apply(ctx, config = {}) {
1281
1358
  ctx.logger.warn("heartbeat: settings override failed (%s)", String(e).slice(0, 120));
1282
1359
  }
1283
1360
  };
1284
- void (async () => {
1361
+ ctx.inject(["settings"], (settingsCtx) => {
1285
1362
  try {
1286
- const settingsService = ctx.get("settings");
1287
- if (settingsService && typeof settingsService.installSection === "function") {
1288
- settingsService.installSection(ctx, "heartbeat", Config, config, {
1289
- setSource: (current) => {
1290
- sectionSource = current;
1291
- },
1292
- onChange: () => {
1293
- applySettingsOverrides();
1294
- }
1295
- });
1296
- applySettingsOverrides();
1297
- ctx.logger.info("heartbeat: settings section registered (0.1.5 settings service)");
1298
- return;
1299
- }
1363
+ const settingsService = settingsCtx.get("settings");
1300
1364
  if (settingsService && typeof settingsService.describe === "function") {
1301
1365
  sectionSource = () => config;
1302
1366
  applySettingsOverrides();
1303
- ctx.logger.info("heartbeat: config served by the 0.1.7 profile form (edits reload the plugin)");
1304
- return;
1305
- }
1306
- const legacy = await import("@deepseek-ai/dsh-settings");
1307
- if (typeof legacy.installSettingsSection === "function" && typeof legacy.settingsNamespace === "function") {
1308
- legacy.installSettingsSection(ctx, legacy.settingsNamespace("heartbeat"), Config, config, {
1309
- setSource: (current) => {
1310
- sectionSource = current;
1311
- },
1312
- onChange: () => {
1313
- applySettingsOverrides();
1314
- }
1315
- });
1316
- applySettingsOverrides();
1317
- ctx.logger.info("heartbeat: settings section registered (legacy 0.1.1 settings)");
1367
+ ctx.logger.info("heartbeat: config served by the profile settings form (edits reload the plugin)");
1318
1368
  return;
1319
1369
  }
1320
- ctx.logger.warn("heartbeat: no settings integration found; policy file values only");
1370
+ ctx.logger.warn("heartbeat: settings service present but not a SettingsForms instance; policy file values only");
1321
1371
  } catch (e) {
1322
- ctx.logger.warn("heartbeat: settings section unavailable (%s)", String(e).slice(0, 120));
1372
+ ctx.logger.warn("heartbeat: settings form unavailable (%s)", String(e).slice(0, 120));
1323
1373
  }
1324
- })();
1374
+ });
1325
1375
  appendAuditLine(
1326
1376
  guard.assert(paths.logsDir + "/heartbeat.jsonl"),
1327
1377
  { event: "plugin_init", dataDir: paths.dataDir }