counterparts 0.3.45 → 0.3.47

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 (125) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/CONSTITUTION.md +6 -4
  3. package/README.md +17 -4
  4. package/docs/QUICKSTART.md +25 -7
  5. package/docs/manual.md +134 -0
  6. package/docs/module-map.md +2 -1
  7. package/package.json +9 -2
  8. package/src/adapters/claude-code/NOTES.md +2 -1
  9. package/src/adapters/claude-code/bin/runner.ts +23 -0
  10. package/src/adapters/claude-code/doctor.ts +110 -8
  11. package/src/adapters/claude-code/hooks.ts +18 -1
  12. package/src/adapters/claude-code/index.ts +2 -0
  13. package/src/adapters/claude-code/night-catch-up.ts +2 -0
  14. package/src/adapters/claude-code/night-run.ts +2 -0
  15. package/src/adapters/claude-code/transcript.ts +60 -6
  16. package/src/adapters/cli/CONTRACT.md +18 -3
  17. package/src/adapters/cli/commands-install.ts +30 -5
  18. package/src/adapters/cli/commands-note.ts +11 -0
  19. package/src/adapters/cli/commands-readings.ts +10 -2
  20. package/src/adapters/cli/commands-remove.ts +10 -1
  21. package/src/adapters/cli/commands-shared.ts +3 -0
  22. package/src/adapters/cli/commands.ts +3 -2
  23. package/src/adapters/cli/export.ts +2 -0
  24. package/src/adapters/cli/help.ts +15 -4
  25. package/src/adapters/cli/removal.ts +144 -54
  26. package/src/adapters/cli/uninstall.ts +194 -12
  27. package/src/adapters/dashboard/registries.ts +1 -1
  28. package/src/adapters/dashboard/resolve.ts +35 -4
  29. package/src/adapters/dashboard/web/pages/memories/index.js +4 -2
  30. package/src/adapters/dashboard/web/views/health.ts +7 -1
  31. package/src/adapters/dashboard/web/views/memories.ts +11 -2
  32. package/src/adapters/dashboard/web/views/overview.ts +14 -3
  33. package/src/adapters/dashboard/web/views/search.ts +7 -3
  34. package/src/adapters/dashboard/web/views/shared.ts +6 -0
  35. package/src/adapters/dashboard/web/views/subjects.ts +6 -2
  36. package/src/adapters/dashboard/web/views/today.ts +10 -2
  37. package/src/adapters/hosts.ts +26 -4
  38. package/src/adapters/lifecycle.ts +12 -4
  39. package/src/adapters/mcp/CONTRACT.md +5 -1
  40. package/src/adapters/mcp/INTERFACE-GAPS.md +10 -0
  41. package/src/adapters/mcp/NOTES.md +82 -0
  42. package/src/adapters/mcp/bin/serve.ts +3 -0
  43. package/src/adapters/mcp/chat-wake.ts +9 -3
  44. package/src/adapters/mcp/deliberate.ts +5 -0
  45. package/src/adapters/mcp/facts.ts +23 -6
  46. package/src/adapters/mcp/index.ts +10 -0
  47. package/src/adapters/mcp/manual.ts +145 -0
  48. package/src/adapters/mcp/meaning.ts +7 -2
  49. package/src/adapters/mcp/server-args.ts +22 -1
  50. package/src/adapters/mcp/server-options.ts +15 -0
  51. package/src/adapters/mcp/server-self-tools.ts +21 -6
  52. package/src/adapters/mcp/server-session-end.ts +2 -0
  53. package/src/adapters/mcp/server-words.ts +98 -13
  54. package/src/adapters/mcp/server.ts +375 -26
  55. package/src/adapters/mcp/tools.ts +150 -26
  56. package/src/adapters/mcp/write-up.ts +3 -1
  57. package/src/adapters/plugin-run.sh +32 -8
  58. package/src/adapters/remote/NOTES.md +11 -1
  59. package/src/adapters/remote/http.ts +6 -1
  60. package/src/adapters/sessions.ts +25 -1
  61. package/src/adapters/update-check.ts +1 -1
  62. package/src/core/counterpart-deposit.ts +76 -8
  63. package/src/core/counterpart-types.ts +26 -0
  64. package/src/core/counterpart-wake-news.ts +230 -0
  65. package/src/core/counterpart-wake-shape.ts +131 -29
  66. package/src/core/counterpart.ts +59 -11
  67. package/src/core/coverage/CONTRACT.md +7 -2
  68. package/src/core/coverage/NOTES.md +45 -0
  69. package/src/core/coverage/index.ts +71 -6
  70. package/src/core/coverage/tunables.ts +4 -1
  71. package/src/core/dream/CONTRACT.md +14 -1
  72. package/src/core/dream/INTERFACE-GAPS.md +7 -0
  73. package/src/core/dream/NOTES.md +56 -0
  74. package/src/core/dream/index.ts +22 -6
  75. package/src/core/dream/project-ask.ts +5 -5
  76. package/src/core/dream/reflect.ts +48 -11
  77. package/src/core/dream/slices.ts +87 -6
  78. package/src/core/encode/secrets.ts +67 -5
  79. package/src/core/handoff/CONTRACT.md +9 -0
  80. package/src/core/handoff/last-here.ts +34 -12
  81. package/src/core/mint.ts +8 -0
  82. package/src/core/onboarding.ts +48 -16
  83. package/src/core/prospective/CONTRACT.md +6 -1
  84. package/src/core/prospective/NOTES.md +25 -0
  85. package/src/core/prospective/index.ts +11 -3
  86. package/src/core/recall/CONTRACT.md +1 -1
  87. package/src/core/recall/INTERFACE-GAPS.md +1 -1
  88. package/src/core/recall/NOTES.md +110 -0
  89. package/src/core/recall/activate.ts +28 -5
  90. package/src/core/recall/gate.ts +63 -12
  91. package/src/core/recall/habituation.ts +15 -2
  92. package/src/core/recall/index.ts +18 -3
  93. package/src/core/recall/session.ts +9 -3
  94. package/src/core/recall/tunables.ts +8 -2
  95. package/src/core/remember/CONTRACT.md +14 -0
  96. package/src/core/remember/NOTES.md +54 -0
  97. package/src/core/remember/index.ts +5 -0
  98. package/src/core/remember/own-plumbing.ts +135 -0
  99. package/src/core/remember/spans.ts +12 -1
  100. package/src/core/removal-hold.ts +246 -0
  101. package/src/core/schemas/index.ts +2 -2
  102. package/src/core/self/CONTRACT.md +1 -1
  103. package/src/core/self/NOTES.md +54 -0
  104. package/src/core/self/briefing-delivery.ts +16 -4
  105. package/src/core/self/identity.ts +4 -0
  106. package/src/core/self/index.ts +4 -1
  107. package/src/core/self/journal-file.ts +2 -1
  108. package/src/core/self/tunables.ts +34 -2
  109. package/src/core/self/work.ts +29 -10
  110. package/src/core/self/writer.ts +9 -2
  111. package/src/core/sleep/CONTRACT.md +4 -2
  112. package/src/core/sleep/consolidate.ts +8 -0
  113. package/src/core/sleep/cycle.ts +20 -0
  114. package/src/core/sleep/types.ts +7 -0
  115. package/src/core/store/CONTRACT.md +21 -3
  116. package/src/core/store/NOTES.md +33 -1
  117. package/src/core/store/cache.ts +5 -0
  118. package/src/core/store/index.ts +303 -12
  119. package/src/core/store/owner-op-seam.ts +5 -3
  120. package/src/core/store/reads-memories.ts +59 -1
  121. package/src/core/store/shapes.ts +20 -1
  122. package/src/core/store/tag-reads.ts +3 -0
  123. package/src/core/told.ts +443 -0
  124. package/src/core/types.ts +5 -0
  125. package/tools/install-loop/run.sh +21 -7
@@ -83,6 +83,9 @@ import type { HostSessionEvidence, RetentionReport } from "../../../core/remembe
83
83
  // `remember/index.ts` does not re-export it, and `test/cli.test.ts` pins every
84
84
  // importer — nothing that holds a `Counterpart` can reach it.
85
85
  import { pruneRetention } from "../../../core/remember/retention.js";
86
+ // THE ERASE AFTER A CHAT'S HOLD (HD1): the one import of the console's removal
87
+ // outside `adapters/cli/` on local, pinned by `test/cli.test.ts`.
88
+ import { sweepHeldRemovals } from "../../cli/removal.js";
86
89
  import { dataDir, describeGuardRefusal } from "../../../core/store/index.js";
87
90
  import type { Store } from "../../../core/store/index.js";
88
91
  import { hostSessionEvidence, installedVersion, rewindWriteUps, writeUpSources } from "../../sessions.js";
@@ -401,6 +404,9 @@ export async function runOnce(input: {
401
404
  };
402
405
  /** How long this process took to reach `main()`, for the `runner.steps` row. */
403
406
  bootMs?: number;
407
+ /** The wall clock the hold sweep reads (HD1). Absent: the store's. Injected
408
+ * so a test can step past the 24-hour window without waiting a day. */
409
+ now?: () => number;
404
410
  onEvent?: (name: string, data: Record<string, string | number | boolean | null>) => void;
405
411
  }): Promise<RunReport> {
406
412
  const { config } = input;
@@ -646,6 +652,23 @@ export async function runOnce(input: {
646
652
  emit("carries.threw", { code: err instanceof Error ? err.name : "UNKNOWN" });
647
653
  }
648
654
  steps.lap("carries");
655
+ // 3e. A CHAT'S DELETES, ERASED AFTER THEIR HOLD (HD1, 2026-11-04): every
656
+ // memory `remember`'s `remove` put on the 24-hour hold whose window has
657
+ // passed is removed by the console's own removal (`adapters/cli/`). This
658
+ // file is the one importer outside `adapters/cli/` on local — the
659
+ // caller-universality test pins it — so the model's call only hides, and
660
+ // this owner-side clock erases. Before the day's copy below, so the copy
661
+ // made after an erase does not hold it. Its own try, like the steps above.
662
+ try {
663
+ const swept = sweepHeldRemovals(counterpart.store, {
664
+ ...(input.now === undefined ? {} : { now: input.now() }),
665
+ onEvent: emit,
666
+ });
667
+ if (swept.due > 0) emit("runner.holds", { due: swept.due, erased: swept.erased.length, failed: swept.failed.length });
668
+ } catch (err) {
669
+ emit("holds.threw", { code: err instanceof Error ? err.name : "UNKNOWN" });
670
+ }
671
+ steps.lap("removals");
649
672
  // 4. THE DAY'S COPY OF THE STORE — after everything above has written, on
650
673
  // the failed path as well as the good one, and before the store is closed.
651
674
  // It never throws by construction (`adapters/snapshots.ts`); the try is
@@ -68,6 +68,7 @@ import {
68
68
  } from "../../core/counterpart.js";
69
69
  import { Counterpart } from "../../core/counterpart.js";
70
70
  import {
71
+ INDEX_REBUILT_AT_OPEN_EVENT,
71
72
  STORE_CREATED_KEY,
72
73
  Store,
73
74
  isSelfRelevantFeeling,
@@ -137,6 +138,7 @@ import {
137
138
  } from "../update-check.js";
138
139
  import type { UpdateSwitch } from "../update-check.js";
139
140
  import type { Finding } from "./doctor-finding.js";
141
+ import { overdueHolds } from "../../core/removal-hold.js";
140
142
  import { checkoutFindings } from "./doctor-checkout.js";
141
143
  import type { CheckoutReading } from "./doctor-checkout.js";
142
144
  import { openFindings, journalFindings, journalCopyFindings, chapterSummaryFindings, openItemsFindings } from "./doctor-open.js";
@@ -168,6 +170,7 @@ import { owedFolders, readOwed, crashWriteUpFindings, nightHeldFindings, overdue
168
170
  import type { OwedSource, OwedReading } from "./doctor-write-ups.js";
169
171
  import { worstFirst } from "./doctor-report.js";
170
172
  import { feedbackLoopFindings } from "./doctor-feedback.js";
173
+ import { starterNotes } from "../../core/told.js";
171
174
 
172
175
  // What moved to the doctor-*.ts parts, re-exported so every import of this file still resolves.
173
176
  export { SEVERITIES } from "./doctor-finding.js";
@@ -502,7 +505,8 @@ function configFindings(input: DoctorInput): Finding[] {
502
505
  : finding("store", "green", MEMORY_TITLE, memoryDetail(input, held), "", {
503
506
  dir: input.dir,
504
507
  exists: true,
505
- memories: held,
508
+ memories: held === null ? null : held.lived,
509
+ starterNotes: held === null ? null : held.told,
506
510
  }),
507
511
  );
508
512
  return out;
@@ -595,7 +599,8 @@ function configFindings(input: DoctorInput): Finding[] {
595
599
  finding("store", "green", MEMORY_TITLE, memoryDetail(input, held), "", {
596
600
  dir: input.dir,
597
601
  exists: true,
598
- memories: held,
602
+ memories: held === null ? null : held.lived,
603
+ starterNotes: held === null ? null : held.told,
599
604
  }),
600
605
  );
601
606
  }
@@ -628,9 +633,11 @@ const MEMORY_TITLE = "Memory";
628
633
  * row: this line is built on the hook's hot path too, and a census that opened
629
634
  * every row would put the whole store between a session and its first word.
630
635
  */
631
- function memoryCount(store: Store): number | null {
636
+ /** Live memory rows, the starter memories counted apart (S1): `{ lived, told }`. */
637
+ function memoryCount(store: Store): { lived: number; told: number } | null {
632
638
  try {
633
- return store.countMemories({ type: "memory", archived: false });
639
+ const told = store.liveToldCount();
640
+ return { lived: store.countMemories({ type: "memory", archived: false }) - told, told };
634
641
  } catch {
635
642
  // A store that will not answer still has a path worth printing, and the
636
643
  // `Store open` line is where an unreadable store is graded.
@@ -647,8 +654,12 @@ function memoryCount(store: Store): number | null {
647
654
  * `--json` still carry it, and a store that will NOT open prints its own line
648
655
  * with the code and the repair.
649
656
  */
650
- function memoryDetail(input: DoctorInput, n: number | null): string {
651
- const held = n === null ? "" : ` — ${String(n)} ${n === 1 ? "memory" : "memories"}`;
657
+ function memoryDetail(input: DoctorInput, n: { lived: number; told: number } | null): string {
658
+ // The lived memories are the number; the starter notes are said apart (ROADMAP, 11-03).
659
+ const held =
660
+ n === null
661
+ ? ""
662
+ : ` — ${String(n.lived)} ${n.lived === 1 ? "memory" : "memories"}${n.told === 0 ? "" : ` · ${starterNotes(n.told)}`}`;
652
663
  const opens = input.open?.ok === true ? ", opens fine" : "";
653
664
  return `${tilde(input.dir)}${held}${opens}`;
654
665
  }
@@ -1955,6 +1966,45 @@ function halfwayMemoryFinding(dir: string): Finding {
1955
1966
  });
1956
1967
  }
1957
1968
 
1969
+ /**
1970
+ * THE WORD INDEX, when it was ever found empty (EX1, 2026-11-04). A store file
1971
+ * moved in without its cache — a hosted "Download my memory" file opened
1972
+ * locally — finds nothing by question until the index is rebuilt. Every
1973
+ * writable open rebuilds it now (`Store#reindexIfEmpty`), so this reads two
1974
+ * things: AMBER while it is empty (only observer opens have seen the file
1975
+ * yet), and a green line for a week after an open rebuilt it, so the repair is
1976
+ * seen. Silent otherwise. Two COUNTs and one bounded event read.
1977
+ */
1978
+ function wordIndexFindings(store: Store): Finding[] {
1979
+ if (store.wordIndexEmpty()) {
1980
+ return [
1981
+ finding(
1982
+ "word-index",
1983
+ "amber",
1984
+ "Word index",
1985
+ "empty, though the store has memories: recall by question finds nothing until it is rebuilt",
1986
+ "The next session rebuilds it as it opens the store; or run: counterparts verify --rebuild",
1987
+ { empty: true },
1988
+ ),
1989
+ ];
1990
+ }
1991
+ const day = store.livedDay();
1992
+ const newest = newestRows(store, INDEX_REBUILT_AT_OPEN_EVENT, 1, day).rows.at(-1);
1993
+ if (newest === undefined || day - newest.day > 7) return [];
1994
+ const indexed = payloadOf(newest)["indexed"];
1995
+ const n = typeof indexed === "number" ? indexed : 0;
1996
+ return [
1997
+ finding(
1998
+ "word-index",
1999
+ "green",
2000
+ "Word index",
2001
+ `was empty when the store was opened on ${localDate(newest.at, store.zone())}, and that open rebuilt it (${String(n)} ${n === 1 ? "row" : "rows"})`,
2002
+ "",
2003
+ { empty: false, rebuiltDay: newest.day, indexed: n },
2004
+ ),
2005
+ ];
2006
+ }
2007
+
1958
2008
  function vectorFindings(input: DoctorInput, store: Store): Finding[] {
1959
2009
  // NOTHING TO EMBED, NOTHING TO SAY (finding #24). With the embedder off every
1960
2010
  // live memory has no vector, so this line reported the whole store as a
@@ -2009,7 +2059,12 @@ function vectorFindings(input: DoctorInput, store: Store): Finding[] {
2009
2059
  // session. A store that has lived one and still has a shortfall keeps the
2010
2060
  // amber below.
2011
2061
  if (unembedded > 0 && !livedABoundary(store)) {
2012
- const memories = unembedded === 1 ? "1 memory" : `${unembedded} memories`;
2062
+ // The starter notes said apart (S1): a new store's 11 are not memories anybody made.
2063
+ const toldIds = new Set(store.toldIds());
2064
+ const toldWaiting = toldIds.size === 0 ? 0 : store.missingVectors(unembedded).filter((id) => toldIds.has(id)).length;
2065
+ const lived = unembedded - toldWaiting;
2066
+ const livedSaid = lived === 1 ? "1 memory" : `${lived} memories`;
2067
+ const memories = toldWaiting === 0 ? livedSaid : lived === 0 ? starterNotes(toldWaiting) : `${livedSaid} · ${starterNotes(toldWaiting)}`;
2013
2068
  return [finding("vectors", "green", "Vectors", `${memories} not searchable by meaning yet — this builds after your first session`, "", data)];
2014
2069
  }
2015
2070
  if (unembedded > 0) {
@@ -2044,6 +2099,36 @@ export function logFindings(input: DoctorInput): Finding[] {
2044
2099
  /** The meta row the v12 upgrade writes (`store/operational.ts#V12_UPGRADE_KEY`). */
2045
2100
  const V12_UPGRADE_META = "recall.v12.upgrade";
2046
2101
 
2102
+ /**
2103
+ * DELETIONS OVERDUE (HD1, ROADMAP 11:55), amber, silent at none: memories a
2104
+ * chat deleted that are still on their hold more than 48 hours after their
2105
+ * erase was due — the worker hasn't run since (no session) — or that the sweep
2106
+ * claimed and didn't finish (its erase failed and is backing off; R1-a). They stay hidden; nothing about them is lost or
2107
+ * shown. The fix is the console's own removal, which finishes a held memory at
2108
+ * once. Ids only, never a word of the memory.
2109
+ */
2110
+ export function overdueDeletionFindings(store: Store, now: number = store.now()): Finding[] {
2111
+ let late: ReturnType<typeof overdueHolds>;
2112
+ try {
2113
+ late = overdueHolds(store, now);
2114
+ } catch {
2115
+ return [];
2116
+ }
2117
+ if (late.length === 0) return [];
2118
+ const one = late.length === 1;
2119
+ const tried = late.filter((h) => h.claims > 0).length;
2120
+ return [
2121
+ finding(
2122
+ "deletions-overdue",
2123
+ "amber",
2124
+ "Deletions",
2125
+ `${String(late.length)} ${one ? "deletion" : "deletions"} overdue: ${one ? "a memory" : "memories"} deleted in chat ${one ? "is" : "are"} still not erased${tried > 0 ? ` (${String(tried)} tried and failed; tried again later)` : ", more than 48 hours after the erase was due (no session has run it since)"}. ${one ? "It stays" : "They stay"} hidden, and can no longer be undone from chat once tried.`,
2126
+ `Erase ${one ? "it" : "them"} now: ${late.map((h) => `counterparts remove ${h.id} --confirm`).join(" · ")}. \`counterparts log\` shows why an erase failed (cli.removal.sweep, holds.threw).`,
2127
+ { overdue: late.length, tried },
2128
+ ),
2129
+ ];
2130
+ }
2131
+
2047
2132
  /**
2048
2133
  * WRITE FIELDS (v12, 2026-10-03), informational, never amber or red: of the
2049
2134
  * memories written since the v12 upgrade by a door that takes the writer's
@@ -2389,8 +2474,18 @@ export function reflectionFindings(input: DoctorInput, store: Store): Finding[]
2389
2474
  // A SHARE STUCK AT `carried` (2026-10-02): `told` was never called, so the
2390
2475
  // line said "carried to a later session" forever. Now it says since when:
2391
2476
  // the day it was carried (`share_at`), else the reflection's own date.
2477
+ // A SHARE TOLD ON DELIVERY (2026-11-04, TC1): the host marks a carried
2478
+ // share told as it hands it over (`detail.toldVia: "carry"`), so whether it
2479
+ // was ever said isn't recorded. The line keeps that readable: when it was
2480
+ // handed over, and that told means delivered.
2481
+ let viaCarry = false;
2482
+ try {
2483
+ viaCarry = last?.share_state === "told" && (JSON.parse(last.detail ?? "{}") as Record<string, unknown>)["toldVia"] === "carry";
2484
+ } catch {
2485
+ viaCarry = false;
2486
+ }
2392
2487
  const carriedOn =
2393
- last?.share_state !== "carried"
2488
+ last === undefined || (last.share_state !== "carried" && !viaCarry)
2394
2489
  ? null
2395
2490
  : typeof last.share_at === "number"
2396
2491
  ? localDate(last.share_at, readingZone)
@@ -2400,6 +2495,10 @@ export function reflectionFindings(input: DoctorInput, store: Store): Finding[]
2400
2495
  if (carriedDays !== null && carriedDays > 0) {
2401
2496
  share["carried"] = `its morning share carried to a later session ${String(carriedDays)} ${carriedDays === 1 ? "day" : "days"} ago and never told`;
2402
2497
  }
2498
+ if (viaCarry) {
2499
+ const ago = carriedDays === null ? "" : carriedDays === 0 ? " today" : ` ${String(carriedDays)} ${carriedDays === 1 ? "day" : "days"} ago`;
2500
+ share["told"] = `its morning share handed to a later session${ago} (marked told on delivery)`;
2501
+ }
2403
2502
  const what =
2404
2503
  last === undefined
2405
2504
  ? "has not reflected yet"
@@ -3493,6 +3592,7 @@ export function doctorFindings(input: DoctorInput): Finding[] {
3493
3592
  ["rows", () => rowFindings(input, store)],
3494
3593
  ["authorship", () => authorshipFindings(input, store, owedReading)],
3495
3594
  ["journal", () => journalFindings(store)],
3595
+ ["word-index", () => wordIndexFindings(store)],
3496
3596
  ["vectors", () => vectorFindings(input, store)],
3497
3597
  // The snapshot policy lives in the configuration, so with none read this
3498
3598
  // line would grade a default nobody chose.
@@ -3521,6 +3621,8 @@ export function doctorFindings(input: DoctorInput): Finding[] {
3521
3621
  // The process log (2026-09-30): one directory listing and today's file.
3522
3622
  // Not in the session-start reading: it is never red, and it reads a file.
3523
3623
  ...(input.budgetMs !== undefined ? [] : [["log", (): Finding[] => logFindings(input)] as const]),
3624
+ // HD1 (ROADMAP 11:55): a chat's delete more than 48 h past its erase. One grouped read; silent at none.
3625
+ ["deletions-overdue", () => overdueDeletionFindings(store)],
3524
3626
  // B3's week: one bounded read of the newest `remember.prune` row. Folds into
3525
3627
  // `Background` while green.
3526
3628
  ["retention", () => retentionFindings(input, store)],
@@ -82,6 +82,7 @@ import { SESSION_NOTICE_BUDGET_MS, checkoutIsGraded, doctorFindings, noticeMessa
82
82
  import type { CheckoutReading } from "./doctor.js";
83
83
  import { staleWindowsLine as staleWindowsSaid } from "./stale-windows.js";
84
84
  import { upperFirst, windowStep } from "../update-words.js";
85
+ import { heldWakeLine } from "../../core/removal-hold.js";
85
86
  import { UPDATE_ROOM_MARGIN, updateLineInputHere, updateNoticeLine, urgentUpdateLine } from "../update-check.js";
86
87
  import { nightRowTimeoutMs, planNightRunner } from "./night-run.js";
87
88
  import { NOTHING_OWED_BEFORE_KEY, catchUpOf, catchUpWords, owedBefore } from "./night-catch-up.js";
@@ -800,7 +801,14 @@ export class ClaudeCodeAdapter extends Lifecycle {
800
801
  resumed || !watched || maintenance >= 3 || (meaning !== null && this.install === "plugin")
801
802
  ? null
802
803
  : this.updateLine(input, "notice", { fits: fitsUnder([stale, urgent, meaning]), urgentSaid: urgent !== null });
803
- const leadLines = [codeTab, stale, urgent, meaning, update].filter((l): l is string => l !== null);
804
+ // A CHAT'S DELETES STILL HELD (HD1, 2026-11-04): one count line, never
805
+ // titles, while any memory deleted in chat waits for its erase — the
806
+ // window turns a forged delete the person sees into one they can undo.
807
+ // Only where a person reads it — and on a RESUMED session too (R5,
808
+ // ROADMAP 10:33): a delete the person didn't ask for must be in front
809
+ // of them while its day runs, and a long chat resumed is where it hides.
810
+ const held = !watched ? null : this.heldLine();
811
+ const leadLines = [codeTab, stale, urgent, meaning, update, held].filter((l): l is string => l !== null);
804
812
  // THE FIRST MEETING'S MARKER (2026-10-11), on every session-start wake:
805
813
  // the state word only, for the mod, which cannot reach the dashboard
806
814
  // before somebody starts it. The store marker beside it (2026-10-12)
@@ -1979,6 +1987,15 @@ export class ClaudeCodeAdapter extends Lifecycle {
1979
1987
  * hears nothing. Reads the worker's small `updates.json` and two meta keys;
1980
1988
  * makes no request (a hook never does). Never throws.
1981
1989
  */
1990
+ /** The count of a chat's deletes still on their hold (HD1), or null. Never throws. */
1991
+ heldLine(): string | null {
1992
+ try {
1993
+ return heldWakeLine(this.counterpart.store.pendingHolds().length);
1994
+ } catch {
1995
+ return null;
1996
+ }
1997
+ }
1998
+
1982
1999
  updateLine(
1983
2000
  input: HookInput,
1984
2001
  which: "urgent" | "notice",
@@ -218,6 +218,8 @@ export function openAdapter(
218
218
  ...(config.identity === undefined
219
219
  ? {}
220
220
  : { identity: { name: config.identity.name, aliases: [...(config.identity.aliases ?? [])] } }),
221
+ // Claude Code's hooks run on the person's computer (EX1).
222
+ toldSurface: "local",
221
223
  ...(onCounterpartEvent === undefined ? {} : { onEvent: onCounterpartEvent }),
222
224
  });
223
225
  return new ClaudeCodeAdapter({ counterpart, config, ...adapterOpts });
@@ -69,6 +69,7 @@ import {
69
69
  NIGHT_RUNNER_PREFIX,
70
70
  WRITE_UP_CLAIM_MS,
71
71
  WRITE_UP_PART_BYTES,
72
+ WRITE_UP_PLUMBING_RULE,
72
73
  claimedByOther,
73
74
  firstUnwrittenPart,
74
75
  grantWriteUps,
@@ -460,6 +461,7 @@ export function catchUpPrompt(plan: CatchUpPlan): string {
460
461
  "1. Call session_end with writeUp: <its id> and no memories. It returns one part of that conversation.",
461
462
  "2. Call session_end with writeUp: <its id>, part: <that part>, memories: [...] — what caught your attention in it, one idea each, in your own words. Do not write again what is marked as already written up. If nothing that is not marked so is worth keeping, send memories: [] with nothing: \"<one line: why>\"; an empty answer without that line is refused while the part holds words not yet written up.",
462
463
  "3. Fetch again for its next part, until the answer is \"written-up\" or the door says this run's allowance for it is spent. Then the next session.",
464
+ WRITE_UP_PLUMBING_RULE,
463
465
  "",
464
466
  "Sessions:",
465
467
  ...plan.subjects.map(
@@ -1661,6 +1661,8 @@ export function openNightCounterpart(config: AdapterConfig, onEvent?: (e: Counte
1661
1661
  ...(config.pageWriter?.mode === undefined ? {} : { pageWriterMode: config.pageWriter.mode }),
1662
1662
  ...(config.identity === undefined ? {} : { identity: { name: config.identity.name, aliases: [...(config.identity.aliases ?? [])] } }),
1663
1663
  build: installedVersion(),
1664
+ // The headless night runs on the person's computer (EX1).
1665
+ toldSurface: "local",
1664
1666
  ...(onEvent === undefined ? {} : { onEvent }),
1665
1667
  });
1666
1668
  }
@@ -58,6 +58,14 @@
58
58
  * visible. A `Stop hook feedback:` block carrying a v1 marker is still
59
59
  * `foreign` — foreign is checked first, so the canary's agreement holds.
60
60
  *
61
+ * **PLUMBING NEVER ENTERS** (2026-11-03, WP1). The host's own line after a
62
+ * declined permission prompt (`[Request interrupted by user for tool use]`)
63
+ * and a hook's output written as user text are the machinery, not anything
64
+ * the person or the counterpart said; kept as `injected`, the first reached
65
+ * the night's write-up beside the person's words. They are tagged `plumbing`
66
+ * (`PLUMBING_FRAMES`) and `enters()` refuses them, counted. What either of
67
+ * them SAID about a prompt or a refusal stays conversation.
68
+ *
61
69
  * **B1 — pacing counts what the PERSON typed, decided from the entry's own
62
70
  * metadata first** (2026-09-23; since 2026-09-24 the assistant's replies add
63
71
  * bytes but never turns — `hooks.ts#substanceOf`). A subagent's hand-back
@@ -126,11 +134,14 @@ const INJECTED =
126
134
  * - `Another Claude session sent a message:` — how 2.1.28x delivers a
127
135
  * subagent's hand-back (the `<agent-message …>` wrapper follows it);
128
136
  * - `[Subagent hand-back]` — the same hand-back's own opening line;
129
- * - `[Request interrupted by user…]` — the host's marker for an interrupt;
137
+ * - `[Request interrupted by user…]` — the host's marker for an interrupt
138
+ * (but not the one after a declined permission prompt: `PLUMBING_FRAMES`);
130
139
  * - `<Event> hook success:` / `… hook additional context:` / `… hook system
131
- * message:` — how the host RENDERS hook output to the model. In the file
132
- * these are `attachment` entries, which carry no role and never reach this
133
- * reader; the anchor is here in case a build ever writes one as user text.
140
+ * message:` written BARE — how the host renders hook output, should a build
141
+ * write it as user text. Kept as `injected`, not `plumbing`: one bare line
142
+ * cannot be told from a person on an older build (no metadata) asking about
143
+ * their hook ("Stop hook success: why does this keep showing?"), and losing
144
+ * their words is worse than keeping the machinery (review of #731).
134
145
  * `hook error` is deliberately NOT here: it is what a person types when
135
146
  * their own hook breaks.
136
147
  *
@@ -145,6 +156,38 @@ const HOST_FRAMES: readonly RegExp[] = [
145
156
  /^[A-Z][A-Za-z]+ hook (?:success|additional context|system message):/,
146
157
  ];
147
158
 
159
+ /**
160
+ * PLUMBING FRAMES (2026-11-03, WP1): host frames that carry the machinery, not
161
+ * the conversation, and so enter nothing (`plumbing`, refused and counted).
162
+ * Same anchoring and the same reach as `HOST_FRAMES` (user-role, never the
163
+ * person's own typed entry), checked first:
164
+ *
165
+ * - `[Request interrupted by user for tool use]`, the WHOLE block — what the
166
+ * host writes, as its own user-role entry with no metadata, after the
167
+ * person declines a permission prompt (measured 11-03 on the owner's
168
+ * transcripts: the rejected `tool_result` comes first and is already a
169
+ * blind spot). Kept as `injected` until then, it reached the night's
170
+ * write-up as part of what the person said. A plain interrupt is still a
171
+ * host frame: the person stopping a reply is something they did;
172
+ * - a system reminder holding ONLY a hook's output (`<Event> hook success:`
173
+ * / `… additional context:` / `… system message:`), the WHOLE block, one
174
+ * reminder and nothing after it — how the host hands hook output to the
175
+ * model (`OWN_ASK`'s shapes). In the file these are `attachment` entries,
176
+ * which carry no role and never reach this reader; the anchor is here in
177
+ * case a build ever writes one as user text. Some OTHER hook's output was
178
+ * `injected`, kept, until then. Anything the person wrote after the
179
+ * reminder keeps the block out of here (review of #731), and the bare
180
+ * form stays a `HOST_FRAMES` entry, kept.
181
+ *
182
+ * What the person or the counterpart SAYS about a refusal or a prompt ("why
183
+ * do you keep asking me to allow that?") is conversation; that is the
184
+ * write-up's prompt to weigh (`sessions.ts#WRITE_UP_PLUMBING_RULE`), not this file's.
185
+ */
186
+ const PLUMBING_FRAMES: readonly RegExp[] = [
187
+ /^\[Request interrupted by user for tool use\]\s*$/,
188
+ /^<system-reminder>\s*[A-Z][A-Za-z]+ hook (?:success|additional context|system message):(?:(?!<\/system-reminder>)[\s\S])*<\/system-reminder>\s*$/,
189
+ ];
190
+
148
191
  /**
149
192
  * The host's blocking-Stop channel, which returns a hook's own stderr to the
150
193
  * model as user-role text. Anchored: a block that merely MENTIONS the phrase
@@ -265,7 +308,13 @@ export function classifyBlock(text: string): TurnSource {
265
308
  /** True when a user-role block with no metadata opens with a host frame. */
266
309
  function hostFramed(text: string): boolean {
267
310
  const probe = text.trimStart();
268
- return HOST_FRAMES.some((frame) => frame.test(probe));
311
+ return plumbingFramed(text) || HOST_FRAMES.some((frame) => frame.test(probe));
312
+ }
313
+
314
+ /** True when a user-role block opens with a plumbing frame (`PLUMBING_FRAMES`). */
315
+ function plumbingFramed(text: string): boolean {
316
+ const probe = text.trimStart();
317
+ return PLUMBING_FRAMES.some((frame) => frame.test(probe));
269
318
  }
270
319
 
271
320
  /**
@@ -539,7 +588,10 @@ export function parseTranscript(raw: string): TranscriptRead {
539
588
  // The host's own lines keep only what is refused (and so counted); their
540
589
  // text enters no turn (`hostRecord`).
541
590
  const all = blocksOf(content, role, author);
542
- const pieces = role === "user" && hostRecord(entry) ? all.filter((p) => p.source !== "injected") : all;
591
+ // Plumbing on such a line enters no turn either (2026-11-03): it was
592
+ // `injected` and dropped here before, and the turn list a live session's
593
+ // cursor indexes must not grow across an upgrade.
594
+ const pieces = role === "user" && hostRecord(entry) ? all.filter((p) => p.source !== "injected" && p.source !== "plumbing") : all;
543
595
  // A twin, if the host ever writes one, is the person's NEXT sent entry: the
544
596
  // same words, marked queued. Anything else the person sends closes the
545
597
  // window. Assistant lines do not: the turn goes on after the attachment.
@@ -634,6 +686,7 @@ function pieceOf(text: string, role: "user" | "assistant", author: EntryAuthor):
634
686
  if (role !== "user") return { text, source: author === "host" ? "injected" : source };
635
687
  if (author === "host") {
636
688
  if (OWN_ASK.test(text.trimStart())) return { text, source: "ritual" };
689
+ if (plumbingFramed(text)) return { text, source: "plumbing" };
637
690
  // Kept in capture — a hand-back or a notification is real experience — and
638
691
  // out of pacing, because nobody in this session typed it. The peer rewrite
639
692
  // still applies, so a wrapper is labelled rather than read as the owner.
@@ -654,6 +707,7 @@ function pieceOf(text: string, role: "user" | "assistant", author: EntryAuthor):
654
707
  // a bare opener may be the person quoting it), then master's rule, plus the
655
708
  // anchored host frames.
656
709
  if (OWN_ASK_FRAMED.test(text.trimStart())) return { text, source: "ritual" };
710
+ if (plumbingFramed(text)) return { text, source: "plumbing" };
657
711
  if (source === "conversation" && hostFramed(text)) return { text, source: "injected" };
658
712
  const attributed = attributePeers(text);
659
713
  if (attributed.peers === 0) return { text, source };
@@ -5,7 +5,9 @@
5
5
  ## 1. Purpose
6
6
 
7
7
  The `counterparts` command: status, install, and the owner-only operations — removal,
8
- export, backup and restore — that no model-reachable path may perform.
8
+ export, backup and restore. No model-reachable path may perform them. A model may hold one
9
+ memory for removal on the person's word; the erase runs only in the console or in a sweep
10
+ after 24 hours of wall-clock time (HD1, 2026-11-04).
9
11
 
10
12
  ## 2. Brain analog
11
13
 
@@ -19,7 +21,12 @@ owner owns the data.
19
21
 
20
22
  - **Destruction lives in exactly one place, and a caller-universality test pins who may
21
23
  reach it.** [v1] behavioral-spec §16 G1–G2, earned-mechanism #14 — *no model-reachable
22
- path may import it, and that test failing is the point.*
24
+ path may import it, and that test failing is the point.* Since 2026-11-04 (HD1) the test
25
+ names two more callers, both owner-side clocks no model calls: the background worker on
26
+ local and hosted's ten-minute timer, each importing only `sweepHeldRemovals`, which erases
27
+ a memory a chat put on its 24-hour hold. The model's door (`remember`'s `remove`,
28
+ `core/removal-hold.ts`) writes the hold and nothing else, so it hides and never destroys:
29
+ the purpose of v1's rule, kept with its wording changed.
23
30
  - **Removal is recorded, and the record is canonical, append-only, and carries no body and
24
31
  no content hash.** [v1] §16 G7–G9, scar §2.20 — a hash of low-entropy content is
25
32
  brute-forceable, which would make the record of removal a leak of the thing removed.
@@ -72,7 +79,7 @@ owner owns the data.
72
79
  - **The staged quarantine → cooling-off → chase-every-copy erase ceremony is released**
73
80
  (owner rescope 3, settled): 871 lines, never production-fired, no designated target since
74
81
  2026-07-29. What replaces it is **plain owner-initiated removal plus a record** — loud,
75
- recorded, unreachable from any model path. Every guarantee in §3 survives the release;
82
+ recorded, unreachable from any model path (a chat's delete only holds, HD1). Every guarantee in §3 survives the release;
76
83
  the staging does not.
77
84
  - **Forever-archive becomes bounded versioning** (owner rescope 3, settled). Superseded
78
85
  rows retain ~90 lived days.
@@ -310,6 +317,14 @@ The standalone verb does not ask either: typing it is the yes.*
310
317
  question, not by the plan made before it. When another process did the same work
311
318
  while the question was up, nothing is written and no backup is taken, and the screen
312
319
  says the hooks were already in place (or already gone) when the file was read again.*
320
+ *Amended 2026-11-04 (LD1): `connect` and `disconnect` keep their backups, but
321
+ `uninstall`, when its unwire read a healthy settings file, took our hooks out and
322
+ wrote it back, removes every backup of ours beside the file (the whole
323
+ `<file>.counterparts-backup-<stamp>` name, regular files only, never a link or a
324
+ directory), the one it just took included, and says how many went. The backups are
325
+ the only recovery if something else damaged the file, so only an unwire that read and
326
+ rewrote a healthy file removes them: a missing, empty or hook-free file, or a failed
327
+ unwire, keeps every one, and uninstall says where they are.*
313
328
  22. **[M] Every other key and every other tool's hooks survive, and the merge works on
314
329
  the INNER hook entry.** Another tool's entry keeps its position, its `matcher`, its
315
330
  `timeout` and every key this package has never heard of; an event we do not use is not
@@ -16,6 +16,19 @@ import { STATIC_WEIGHTS_ENV } from "../../core/embed/static.js";
16
16
  // and the wake's (2026-10-27, review of #664).
17
17
  import { PLUGIN_TABLE_UPDATE, byRoute, npmTableCommand, tableOnDisk } from "../claude-code/doctor-meaning.js";
18
18
  import { installRoute } from "../plugin.js";
19
+ import { updateSwitch } from "../update-check.js";
20
+
21
+ /** What setup says when recall by meaning is on. */
22
+ export const RECALL_ON_LINE = "Recall by meaning: on. A small model runs on your machine and sends nothing anywhere.";
23
+ /** What a new install says about the daily update check (`update-check.ts`): the
24
+ * durable switch, since an environment variable only reaches the worker when
25
+ * Claude Code itself was started with it. */
26
+ export function updateCheckLine(config: string): string {
27
+ return (
28
+ "Updates: once a day Counterparts asks registry.npmjs.org for the newest version number; it sends " +
29
+ `nothing about you or your memory. To turn that off, set "updateCheck": false in ${config}.`
30
+ );
31
+ }
19
32
  import {
20
33
  installLayout,
21
34
  layoutRefusal,
@@ -35,6 +48,7 @@ import {
35
48
  } from "./install.js";
36
49
  import type { InstallLayout, ParkedSighting } from "./install.js";
37
50
  import { NEW_INSTALL_DREAMING_LINE, beginNewInstall } from "../../core/onboarding.js";
51
+ import { plantTold } from "../../core/told.js";
38
52
  // The console's shared manners (2026-09-21): is there a person here, ask them,
39
53
  // and say one marked line back.
40
54
  import { isPromptAborted, ui, ask } from "./ui.js";
@@ -253,6 +267,10 @@ export function installCommand(
253
267
  if (!existed) {
254
268
  try {
255
269
  beginNewInstall(store, { dreaming: opts.newInstall !== "start-fresh" });
270
+ // THE STARTER MEMORIES (S1, `core/told.ts`): told, not lived, planted
271
+ // only here, in a store this call created — `start-fresh`'s blank store
272
+ // included, since it is a new store with a new counterpart in it.
273
+ plantTold(store, "local");
256
274
  } catch (err) {
257
275
  store.close();
258
276
  io.err(prefixedRefusal(describeDirRefusal(err, layout.store)));
@@ -266,7 +284,7 @@ export function installCommand(
266
284
  // `Counterpart.open`, so the core appeared only when a session first fired.
267
285
  // Two things were wrong with that. §3 says "It seeds the identity core" of a
268
286
  // command that had not yet; and `init --name` DID seed it immediately, so the
269
- // two commands the same page calls interchangeable produced different stores
287
+ // two commands (then called interchangeable) produced different cores
270
288
  // (found 2026-09-04, when a captured recall reproduced one row higher than
271
289
  // the page said). Same door as `init`: `Counterpart.open`'s own option, which
272
290
  // is an ENSURE, so the hook's later call finds it and mints nothing.
@@ -346,9 +364,9 @@ export function installCommand(
346
364
  } else {
347
365
  say(` ${config.what} ${config.path}`);
348
366
  }
349
- // The SAME sentence `init` prints, because the two commands did the same
350
- // thing: a page that calls them interchangeable and then has them say it
351
- // differently has made the reader do the comparison.
367
+ // The SAME sentence `init` prints, because the two seed the core the same
368
+ // way. They are not interchangeable since S1 (ROADMAP, 11-03): "init makes a
369
+ // bare store, with no starter notes; install sets up yours."
352
370
  // The conversation (`installInteractive`) has already said this, one step up, in
353
371
  // the person's own answer; saying it twice is the wall of text the owner named.
354
372
  if (seeded && opts.nameAlreadySaid !== true) {
@@ -839,7 +857,14 @@ async function installConversation(
839
857
  const tableOn = config.embedder?.enabled === true;
840
858
  const tableMissing = tableOn && !tableOnDisk({ env }).complete;
841
859
  if (tableOn && !tableMissing) {
842
- io.out("Recall by meaning: on. A small model runs on your machine; nothing is sent anywhere.");
860
+ io.out(RECALL_ON_LINE);
861
+ u.blank();
862
+ }
863
+ // THE ONE REQUEST OUTSIDE CLAUDE CODE, said where the person installs (LD1,
864
+ // 2026-11-04): only on a new install with no switch already off, so it is
865
+ // never said of a check that will not run.
866
+ if (!already && updateSwitch({ config, asked: false, env }) === "none") {
867
+ io.out(updateCheckLine(tilde(layout.config, home_)));
843
868
  u.blank();
844
869
  }
845
870
  // DREAMING IS ON FOR A NEW INSTALL (2026-10-11), and a person is told so
@@ -362,6 +362,7 @@ export async function recallCommand(
362
362
  {
363
363
  learnedOn: (id) => facts.memories.find((m) => m.id === id)?.learned ?? null,
364
364
  dim: paint(io, env).dim,
365
+ emptyIndex: facts.memories.length === 0 && counterpart.store.wordIndexEmpty(),
365
366
  },
366
367
  );
367
368
  return EXIT.ok;
@@ -457,11 +458,21 @@ export function printAskList(
457
458
  readonly learnedOn?: (id: string) => string | null;
458
459
  /** How the metadata line is quietened. Absent: plain. */
459
460
  readonly dim?: (s: string) => string;
461
+ /** The store's word index is empty beside live rows (EX1): a store file
462
+ * moved in, a hosted download, that no writable open has seen yet. */
463
+ readonly emptyIndex?: boolean;
460
464
  } = {},
461
465
  ): void {
462
466
  const found = Math.max(result.matched ?? 0, result.memories.length);
463
467
  if (found === 0) {
464
468
  io.out(`Nothing found (${how}).`);
469
+ if (opts.emptyIndex === true) {
470
+ // `ask` only looks (observer), so it cannot rebuild the index itself:
471
+ // say why nothing came, and what does (EX1).
472
+ io.out(" This memory's word index is empty: the file was moved in and nothing has opened it to write yet.");
473
+ io.out(` The next Claude Code or Claude Desktop session that uses this memory rebuilds it as it opens it (not in a folder where memory is off or observer only); or run: ${BIN.cli} verify --rebuild`);
474
+ return;
475
+ }
465
476
  // A faded match is counted in `matched` and listed with the rest (2026-10-10).
466
477
  io.out(
467
478
  result.considered === 0