@kanadego/dsh-heartbeat 2.3.0 → 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.
Files changed (40) hide show
  1. package/README.md +70 -81
  2. package/USAGE-GUIDE.md +357 -0
  3. package/dist/{chunk-43Q42HWH.js → chunk-AJ5JAQVB.js} +13 -2
  4. package/dist/chunk-AJ5JAQVB.js.map +1 -0
  5. package/dist/chunk-CRRN6UD3.js +389 -0
  6. package/dist/chunk-CRRN6UD3.js.map +1 -0
  7. package/dist/{chunk-K47VV6IQ.js → chunk-ERRPMYKB.js} +163 -153
  8. package/dist/chunk-ERRPMYKB.js.map +1 -0
  9. package/dist/chunk-L54R23O2.js +262 -0
  10. package/dist/chunk-L54R23O2.js.map +1 -0
  11. package/dist/{chunk-HSTGRQLP.js → chunk-MHRAPKES.js} +406 -66
  12. package/dist/chunk-MHRAPKES.js.map +1 -0
  13. package/dist/{chunk-ABFO4QII.js → chunk-RPWQZYNW.js} +603 -157
  14. package/dist/chunk-RPWQZYNW.js.map +1 -0
  15. package/dist/cli/index.js +160 -23
  16. package/dist/cli/index.js.map +1 -1
  17. package/dist/index.d.ts +6 -0
  18. package/dist/index.js +98 -22
  19. package/dist/index.js.map +1 -1
  20. package/dist/{migrate-6HH2ZARV.js → migrate-25F53XIC.js} +4 -2
  21. package/dist/{orchestrator-OJJM5QSV.js → orchestrator-4PJD7QYO.js} +11 -6
  22. package/dist/snapshot-J6LKNY57.js +27 -0
  23. package/dist/store-HM6ZMFKS.js +45 -0
  24. package/package.json +6 -3
  25. package/dist/chunk-43Q42HWH.js.map +0 -1
  26. package/dist/chunk-ABFO4QII.js.map +0 -1
  27. package/dist/chunk-HSTGRQLP.js.map +0 -1
  28. package/dist/chunk-JIRQ36F7.js +0 -87
  29. package/dist/chunk-JIRQ36F7.js.map +0 -1
  30. package/dist/chunk-K47VV6IQ.js.map +0 -1
  31. package/dist/chunk-KGOC6EX4.js +0 -413
  32. package/dist/chunk-KGOC6EX4.js.map +0 -1
  33. package/dist/chunk-QOLKUYQ3.js +0 -393
  34. package/dist/chunk-QOLKUYQ3.js.map +0 -1
  35. package/dist/pool-QTY2MI56.js +0 -49
  36. package/dist/snapshot-6DFNGXTR.js +0 -16
  37. /package/dist/{migrate-6HH2ZARV.js.map → migrate-25F53XIC.js.map} +0 -0
  38. /package/dist/{orchestrator-OJJM5QSV.js.map → orchestrator-4PJD7QYO.js.map} +0 -0
  39. /package/dist/{pool-QTY2MI56.js.map → snapshot-J6LKNY57.js.map} +0 -0
  40. /package/dist/{snapshot-6DFNGXTR.js.map → store-HM6ZMFKS.js.map} +0 -0
package/dist/cli/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  collectMigrationEntries,
4
4
  decryptContainer,
5
5
  encryptContainer
6
- } from "../chunk-43Q42HWH.js";
6
+ } from "../chunk-AJ5JAQVB.js";
7
7
  import {
8
8
  BUNDLED_PRESET_ID,
9
9
  EXCERPT_HEADER,
@@ -13,57 +13,58 @@ import {
13
13
  describeInstall,
14
14
  excerptFilePath,
15
15
  installBundledPreset,
16
- loadPolicy,
17
16
  presetStatus,
18
17
  readExcerpts,
19
18
  removeExcerpt
20
- } from "../chunk-KGOC6EX4.js";
19
+ } from "../chunk-L54R23O2.js";
21
20
  import {
22
21
  CORRECTIONS_DONE_HEADER,
23
22
  CORRECTIONS_HEADER,
24
23
  LEDGER_DONE_HEADER,
24
+ activeSeeds,
25
+ addSeed,
25
26
  adviseWander,
26
27
  appendEntry,
28
+ archiveSeedById,
29
+ archivedSeeds,
27
30
  browseStatus,
28
31
  completeWander,
29
32
  correctionsDoneFilePath,
30
33
  correctionsFilePath,
31
34
  ensureRegistered,
35
+ gcPool,
32
36
  ledgerDoneFilePath,
33
37
  ledgerFilePath,
34
38
  listWeeklyReports,
35
39
  loadInterests,
36
- localDayKey,
40
+ loadPool,
37
41
  markDone,
38
42
  readLedger,
39
43
  readWeeklyReport,
40
44
  scanPending,
41
45
  seedBookFile,
46
+ seedsFilePath,
42
47
  sendNewMessageHint,
48
+ surfaceSeed,
43
49
  weeklyDirPath
44
- } from "../chunk-HSTGRQLP.js";
50
+ } from "../chunk-MHRAPKES.js";
45
51
  import {
46
52
  openPath
47
53
  } from "../chunk-OCBE2AKW.js";
48
- import {
49
- activeSeeds,
50
- addSeed,
51
- archiveSeedById,
52
- archivedSeeds,
53
- gcPool,
54
- loadPool,
55
- seedsFilePath,
56
- surfaceSeed
57
- } from "../chunk-QOLKUYQ3.js";
58
54
  import {
59
55
  appendAuditLine,
56
+ loadPolicy,
57
+ localDayKey,
58
+ pruneAuditFile
59
+ } from "../chunk-CRRN6UD3.js";
60
+ import {
61
+ SNAPSHOT_ARCHIVE_NAME_RE,
60
62
  loadProfile,
61
63
  profileFilePath,
62
- pruneAuditFile,
63
64
  rebuildProfile,
64
65
  verifyProfile,
65
66
  wipeProfile
66
- } from "../chunk-K47VV6IQ.js";
67
+ } from "../chunk-ERRPMYKB.js";
67
68
  import {
68
69
  containerKind,
69
70
  dshHomeDir,
@@ -121,6 +122,15 @@ var BURN_LIST = [
121
122
  // above — the persona report log records WHAT SHE SAID (spoken / seed_ids /
122
123
  // profile_ids / reason), so a burn that skips it is a burn that lies.
123
124
  { file: "profile_snapshot.json", note: "\u753B\u50CF\u5FEB\u7167\uFF08journal \u8F6E\u8F6C\u57FA\u7EBF\uFF09" },
125
+ // v2.4.0: dated snapshot archives (profile restore 的还原点) each hold one
126
+ // fold's full doc — same memory as the canonical file above, so a burn that
127
+ // skipped them would leave the profile restorable. The regex (not a prefix)
128
+ // so the canonical `profile_snapshot.json` is only matched by its own row.
129
+ { match: SNAPSHOT_ARCHIVE_NAME_RE, note: "\u753B\u50CF\u5FEB\u7167\u5F52\u6863\uFF08\u6BCF\u65E5\u8FD8\u539F\u70B9\uFF0Cprofile_snapshot.<ts>.json\uFF09" },
130
+ // v2.4.0: `profile restore` backs the current view up before overwriting
131
+ // (profile.json.before-restore-<ts>) — a full copy of the pre-restore
132
+ // memory, so it burns with the rest (same reasoning as .bak-migrate above).
133
+ { match: /^profile\.json\.before-restore-\d{14}(-\d+)?$/, note: "\u753B\u50CF\u6062\u590D\u524D\u5907\u4EFD\uFF08profile restore \u4EA7\u7269\uFF09" },
124
134
  { file: "cursors.json", note: "\u89C2\u5BDF\u6E38\u6807\uFF08\u4F1A\u8BDD\u4E8B\u4EF6\u4F4D\u70B9\uFF09" },
125
135
  { file: "seed_report.jsonl", note: "\u6295\u9012\u62A5\u8D26\u65E5\u5FD7\uFF08\u52A0\u5BC6\uFF09" },
126
136
  { file: "preference.json", note: "\u8BDD\u9898\u504F\u597D\u7EDF\u8BA1" },
@@ -281,6 +291,9 @@ function usage() {
281
291
  " profile verify journal replay vs disk (report only)",
282
292
  " profile rebuild [--check] rebuild materialized view from journal",
283
293
  " profile snapshot [--force] fold the journal into a snapshot + archive shard",
294
+ " profile snapshots [--days n] list restore points (snapshot archives)",
295
+ " profile restore --at <ISO> restore the profile view to a past instant [--dry-run]",
296
+ " profile log --id <entryId> print the journal history of one entry",
284
297
  " profile wipe wipe profile data (asks --yes)",
285
298
  " weekly list list generated weekly reports",
286
299
  " weekly show [file] print a report (default: newest)",
@@ -652,7 +665,7 @@ async function verbNotify(c) {
652
665
  }
653
666
  }
654
667
  async function verbProfile(c) {
655
- const { guard, paths, sub, rest } = c;
668
+ const { guard, paths, policy, sub, rest } = c;
656
669
  const doc = loadProfile(guard, profileFilePath(paths.dataDir));
657
670
  const all = rest.includes("--all");
658
671
  switch (sub) {
@@ -703,7 +716,7 @@ async function verbProfile(c) {
703
716
  return 0;
704
717
  }
705
718
  case "snapshot": {
706
- const { snapshotDue, snapshotProfile, SNAPSHOT_THRESHOLD } = await import("../snapshot-6DFNGXTR.js");
719
+ const { snapshotDue, snapshotProfile, SNAPSHOT_THRESHOLD } = await import("../snapshot-J6LKNY57.js");
707
720
  const { needed, lines } = snapshotDue(guard, paths.dataDir);
708
721
  console.log(`journal ${lines} \u6761\uFF08\u9608\u503C ${SNAPSHOT_THRESHOLD}\uFF09`);
709
722
  if (!needed && !rest.includes("--force")) {
@@ -719,6 +732,130 @@ async function verbProfile(c) {
719
732
  console.log("verify/rebuild \u81EA\u52A8\u4ECE\u5FEB\u7167\u57FA\u70B9\u91CD\u653E\uFF0C\u65E0\u9700\u989D\u5916\u64CD\u4F5C\u3002");
720
733
  return 0;
721
734
  }
735
+ case "snapshots": {
736
+ const { listSnapshots, readSnapshotFile } = await import("../store-HM6ZMFKS.js");
737
+ const { resolveRetentionDays } = await import("../snapshot-J6LKNY57.js");
738
+ const days = Number(flag(rest, "--days")) || resolveRetentionDays(guard, paths.dataDir);
739
+ if (!(days > 0)) {
740
+ console.error("--days must be a positive number");
741
+ return 1;
742
+ }
743
+ const cutoff = Date.now() - days * 864e5;
744
+ const refs = listSnapshots(guard, paths.dataDir).filter((r) => r.baselineTs >= cutoff);
745
+ if (refs.length === 0) {
746
+ console.log(`(${days} \u5929\u5185\u6CA1\u6709\u8FD8\u539F\u70B9\uFF1B\u6298\u53E0\u4E00\u6B21\u753B\u50CF\u5FEB\u7167\u5373\u53EF\u751F\u6210\uFF0C\u89C1 profile snapshot\uFF09`);
747
+ return 0;
748
+ }
749
+ for (const ref of refs) {
750
+ const snap = readSnapshotFile(guard, ref.path);
751
+ const entries = snap ? Object.values(snap.doc.partitions).reduce((n, b) => n + b.entries.length, 0) : null;
752
+ const at = new Date(ref.baselineTs);
753
+ console.log(`${at.toISOString()} \u6761\u76EE ${entries ?? "?"} ${ref.path}`);
754
+ }
755
+ return 0;
756
+ }
757
+ case "restore": {
758
+ const { restoreAt } = await import("../store-HM6ZMFKS.js");
759
+ const at = flag(rest, "--at");
760
+ if (!at) {
761
+ console.error("usage: profile restore --at <ISO> [--dry-run]");
762
+ return 1;
763
+ }
764
+ if (!Number.isFinite(Date.parse(at))) {
765
+ console.error(`invalid --at timestamp: ${at}`);
766
+ return 1;
767
+ }
768
+ const dry = rest.includes("--dry-run");
769
+ let r;
770
+ try {
771
+ r = restoreAt(guard, paths.dataDir, at, { dryRun: dry });
772
+ } catch (e) {
773
+ console.error(String(e instanceof Error ? e.message : e));
774
+ return 1;
775
+ }
776
+ const atIso = r.restoredTo > 0 ? new Date(r.restoredTo).toISOString() : String(r.restoredTo);
777
+ console.log(JSON.stringify({
778
+ mode: dry ? "dry-run" : "restore",
779
+ restoredTo: atIso,
780
+ backupPath: r.backupPath || "(none)",
781
+ wrote: r.wrote,
782
+ diff: r.diff
783
+ }, null, 2));
784
+ if (!r.wrote && dry) {
785
+ console.log("\uFF08dry-run\uFF1A\u672A\u5199\u76D8\u3002\u786E\u8BA4\u5DEE\u5F02\u540E\u53BB\u6389 --dry-run \u771F\u8DD1\u3002\uFF09");
786
+ } else if (!r.wrote) {
787
+ console.log("\u76EE\u6807\u4E3A\u6700\u65B0\u8BB0\u5F55\u4E14\u753B\u50CF\u5DF2\u4E0E\u4E4B\u4E00\u81F4\u2014\u2014\u5DF2\u662F\u5F53\u524D\u72B6\u6001\uFF0C\u672A\u5199\u76D8\u3002");
788
+ } else if (r.toNow) {
789
+ console.log(`\u5DF2\u6062\u590D\u5230\u6700\u65B0\u8BB0\u5F55\uFF08${atIso}\uFF09\uFF1B\u78C1\u76D8\u89C6\u56FE\u6B64\u524D\u843D\u540E\u4E8E journal\uFF0C\u5DF2\u6309\u6700\u65B0\u72B6\u6001\u5199\u56DE${r.backupPath ? `\uFF0C\u6062\u590D\u524D\u89C6\u56FE\u5907\u4EFD\u5728 ${r.backupPath}` : ""}\u3002`);
790
+ console.log("\u6CE8\u610F\uFF1Ajournal \u4ECD\u662F\u5B8C\u6574\u5386\u53F2\uFF0C\u73B0\u5728 verify \u5E94\u5F53\u4E00\u81F4\uFF1B\u5982\u4ECD\u5F02\u5E38\u53EF\u8DD1 rebuild\u3002");
791
+ } else if (r.backupPath) {
792
+ console.log(`\u5DF2\u6062\u590D\u81F3 ${atIso}\uFF1B\u6062\u590D\u524D\u7684\u753B\u50CF\u5907\u4EFD\u5728 ${r.backupPath}`);
793
+ console.log("\u6CE8\u610F\uFF1Ajournal \u4ECD\u4FDD\u5B58\u5B8C\u6574\u5386\u53F2\uFF0Cverify \u4F1A\u62A5\u544A\u4E0E\u5F53\u524D\u89C6\u56FE\u7684\u5DEE\u5F02\uFF08\u8FD9\u662F\u56DE\u6EDA\u7684\u9884\u671F\u884C\u4E3A\uFF09\uFF1Brebuild \u53EF\u56DE\u5230\u6700\u65B0\u3002");
794
+ } else {
795
+ console.log(`\u5DF2\u6062\u590D\u81F3 ${atIso}\uFF08\u6B64\u524D\u6CA1\u6709 profile.json\uFF0C\u672A\u751F\u6210\u6062\u590D\u524D\u5907\u4EFD\uFF09\u3002`);
796
+ console.log("\u6CE8\u610F\uFF1Ajournal \u4ECD\u4FDD\u5B58\u5B8C\u6574\u5386\u53F2\uFF0Cverify \u4F1A\u62A5\u544A\u4E0E\u5F53\u524D\u89C6\u56FE\u7684\u5DEE\u5F02\uFF08\u8FD9\u662F\u56DE\u6EDA\u7684\u9884\u671F\u884C\u4E3A\uFF09\uFF1Brebuild \u53EF\u56DE\u5230\u6700\u65B0\u3002");
797
+ }
798
+ return 0;
799
+ }
800
+ case "log": {
801
+ const id = flag(rest, "--id");
802
+ if (!id) {
803
+ console.error("usage: profile log --id <entryId>");
804
+ return 1;
805
+ }
806
+ const { readJournalTexts } = await import("../store-HM6ZMFKS.js");
807
+ const touches = [];
808
+ let prevContent = null;
809
+ let prevValidTo = void 0;
810
+ for (const text of readJournalTexts(guard, paths.dataDir)) {
811
+ for (const line of text.split("\n")) {
812
+ const s = line.trim();
813
+ if (!s) continue;
814
+ let rec;
815
+ try {
816
+ rec = JSON.parse(s);
817
+ } catch {
818
+ continue;
819
+ }
820
+ const ts = String(rec.ts ?? "");
821
+ if (rec.v === 2 && Array.isArray(rec.entries)) {
822
+ for (const e of rec.entries) {
823
+ if (e?.id !== id) continue;
824
+ const entry = e;
825
+ const content = typeof entry.content === "string" ? entry.content : null;
826
+ const op = prevValidTo === void 0 ? "ADD" : prevValidTo === null && entry.validTo != null ? "INVALIDATE" : "UPDATE";
827
+ touches.push({ ts, op, contentChanged: prevContent !== null && content !== prevContent, content });
828
+ prevContent = content;
829
+ prevValidTo = entry.validTo ?? null;
830
+ }
831
+ } else if (Array.isArray(rec.applied)) {
832
+ for (const op of rec.applied) {
833
+ const matches = op?.op === "ADD" ? op.assignedId === id : op?.id === id;
834
+ if (!matches) continue;
835
+ const content = op?.op === "ADD" && typeof op.content === "string" ? op.content : op?.op === "UPDATE" && typeof op.changes?.content === "string" ? op.changes.content : prevContent;
836
+ touches.push({
837
+ ts,
838
+ op: String(op?.op ?? "?"),
839
+ contentChanged: op?.op === "UPDATE" && op.changes?.content !== void 0 && content !== prevContent,
840
+ content
841
+ });
842
+ if (content != null) prevContent = content;
843
+ if (op?.op === "INVALIDATE") prevValidTo = ts;
844
+ }
845
+ }
846
+ }
847
+ }
848
+ if (touches.length === 0) {
849
+ console.log(`(no history for ${id})`);
850
+ return 0;
851
+ }
852
+ for (const t of touches) {
853
+ const body = t.content != null ? ` ${t.content.slice(0, 60)}` : "";
854
+ console.log(`${t.ts} ${t.op.padEnd(10)} content ${t.contentChanged ? "changed" : "same"}${body}`);
855
+ }
856
+ console.log(`\u5171 ${touches.length} \u6B21\u53D8\u66F4\uFF08\u65F6\u95F4\u5347\u5E8F\uFF1B\u6B63\u6587\u6309 profile list \u7684 60 \u5B57\u622A\u65AD\u53E3\u5F84\u5C55\u793A\uFF09\u3002`);
857
+ return 0;
858
+ }
722
859
  default:
723
860
  console.error(`unknown profile subcommand: ${sub}`);
724
861
  return 1;
@@ -808,7 +945,7 @@ async function verbSessions(c) {
808
945
  const root = path2.join(dshHomeDir(), "sessions");
809
946
  let found = 0;
810
947
  if (fs2.existsSync(root)) {
811
- const { homeSessionId } = await import("../orchestrator-OJJM5QSV.js");
948
+ const { homeSessionId } = await import("../orchestrator-4PJD7QYO.js");
812
949
  const own = homeSessionId(guard, paths);
813
950
  for (const slug of fs2.readdirSync(root)) {
814
951
  for (const id of fs2.readdirSync(path2.join(root, slug))) {
@@ -827,7 +964,7 @@ async function verbBind(c) {
827
964
  switch (sub) {
828
965
  case "list": {
829
966
  const data = loadBindings(guard, paths.settingsDir);
830
- const { homeSessionId } = await import("../orchestrator-OJJM5QSV.js");
967
+ const { homeSessionId } = await import("../orchestrator-4PJD7QYO.js");
831
968
  const own = homeSessionId(guard, paths);
832
969
  if (own) console.log(`\u5FC3\u8DF3\u6B63\u8EAB: ${own}\uFF08\u51B3\u7B56\u8F6E\u6B21\u53D1\u751F\u5730\uFF1Bbind remove \u5B83 = \u91CD\u7F6E\u6B63\u8EAB\uFF09`);
833
970
  for (const b of data.bindings) {
@@ -855,7 +992,7 @@ async function verbBind(c) {
855
992
  return 1;
856
993
  }
857
994
  console.log(removeBinding(guard, paths.settingsDir, id) ? `UNBOUND ${id}` : "NOT_FOUND");
858
- const { resetHomeSession } = await import("../orchestrator-OJJM5QSV.js");
995
+ const { resetHomeSession } = await import("../orchestrator-4PJD7QYO.js");
859
996
  if (resetHomeSession(guard, paths, id)) {
860
997
  console.log("\u6CE8\u610F\uFF1A\u8FD9\u662F\u5FC3\u8DF3\u6B63\u8EAB\u4F1A\u8BDD\u3002\u5DF2\u91CD\u7F6E\u2014\u2014\u4E0B\u6B21\u5FC3\u8DF3\u5C06\u521B\u5EFA\u65B0\u7684\u6B63\u8EAB\u4F1A\u8BDD\uFF08\u65E7\u4F1A\u8BDD\u4E0D\u518D\u6709\u5FC3\u8DF3\uFF09");
861
998
  }
@@ -929,7 +1066,7 @@ async function verbVault(c) {
929
1066
  async function verbFocus(c) {
930
1067
  const { sub, rest, decisionLog } = c;
931
1068
  const { readFocusState, writeFocusState, clearFocusState } = await import("../focus-store-XGTPIVF6.js");
932
- const { formatFocusClock } = await import("../orchestrator-OJJM5QSV.js");
1069
+ const { formatFocusClock } = await import("../orchestrator-4PJD7QYO.js");
933
1070
  const audit = (entry) => {
934
1071
  try {
935
1072
  appendAuditLine(decisionLog, entry);