counterparts 0.3.37 → 0.3.39

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 (129) hide show
  1. package/CHANGELOG.md +188 -0
  2. package/README.md +2 -1
  3. package/docs/QUICKSTART.md +14 -8
  4. package/docs/module-map.md +4 -2
  5. package/package.json +9 -1
  6. package/src/adapters/claude-code/CONTRACT.md +26 -4
  7. package/src/adapters/claude-code/NOTES.md +116 -0
  8. package/src/adapters/claude-code/bin/hook.ts +70 -6
  9. package/src/adapters/claude-code/bin/nightly.ts +2 -0
  10. package/src/adapters/claude-code/bin/runner.ts +64 -2
  11. package/src/adapters/claude-code/child-error.ts +211 -0
  12. package/src/adapters/claude-code/child.ts +29 -10
  13. package/src/adapters/claude-code/doctor-checkout.ts +4 -2
  14. package/src/adapters/claude-code/doctor-host.ts +31 -0
  15. package/src/adapters/claude-code/doctor-meaning.ts +200 -0
  16. package/src/adapters/claude-code/doctor-modes.ts +115 -0
  17. package/src/adapters/claude-code/doctor-open.ts +12 -2
  18. package/src/adapters/claude-code/doctor-self-page.ts +2 -0
  19. package/src/adapters/claude-code/doctor-write-ups.ts +84 -19
  20. package/src/adapters/claude-code/doctor.ts +199 -23
  21. package/src/adapters/claude-code/hooks.ts +162 -11
  22. package/src/adapters/claude-code/index.ts +15 -0
  23. package/src/adapters/claude-code/night-catch-up.ts +25 -5
  24. package/src/adapters/claude-code/night-run.ts +86 -11
  25. package/src/adapters/claude-code/stale-windows.ts +160 -0
  26. package/src/adapters/claude-code/standdown.ts +70 -3
  27. package/src/adapters/cli/INTERFACE-GAPS.md +14 -0
  28. package/src/adapters/cli/NOTES.md +25 -0
  29. package/src/adapters/cli/bin/counterparts.ts +4 -2
  30. package/src/adapters/cli/commands-dashboard.ts +8 -5
  31. package/src/adapters/cli/commands-install.ts +12 -14
  32. package/src/adapters/cli/commands.ts +5 -2
  33. package/src/adapters/cli/coverage.ts +28 -6
  34. package/src/adapters/cli/help.ts +6 -1
  35. package/src/adapters/cli/index.ts +2 -0
  36. package/src/adapters/cli/install.ts +24 -1
  37. package/src/adapters/cli/mechanisms.ts +31 -8
  38. package/src/adapters/cli/rollback.ts +3 -3
  39. package/src/adapters/cli/snapshot.ts +4 -4
  40. package/src/adapters/cli/ui.ts +10 -0
  41. package/src/adapters/cli/uninstall.ts +16 -74
  42. package/src/adapters/cli/wire.ts +227 -33
  43. package/src/adapters/config.ts +23 -0
  44. package/src/adapters/dashboard/bin/dashboard.ts +2 -0
  45. package/src/adapters/dashboard/registries.ts +1 -1
  46. package/src/adapters/dashboard/web/mechanisms/index.js +2 -0
  47. package/src/adapters/dashboard/web/mechanisms/schema/index.js +9 -6
  48. package/src/adapters/dashboard/web/mechanisms/schema/panel.js +14 -0
  49. package/src/adapters/dashboard/web/narrate.ts +10 -3
  50. package/src/adapters/dashboard/web/views/mechanism-panel.ts +44 -0
  51. package/src/adapters/dashboard/web/views/mechanisms.ts +13 -1
  52. package/src/adapters/expansions.ts +4 -3
  53. package/src/adapters/fired.ts +29 -0
  54. package/src/adapters/host-wiring.ts +56 -1
  55. package/src/adapters/hosts.ts +51 -0
  56. package/src/adapters/lifecycle.ts +4 -2
  57. package/src/adapters/mcp/CONTRACT.md +26 -3
  58. package/src/adapters/mcp/INTERFACE-GAPS.md +11 -0
  59. package/src/adapters/mcp/NOTES.md +149 -0
  60. package/src/adapters/mcp/bin/serve.ts +83 -4
  61. package/src/adapters/mcp/chat-wake.ts +111 -0
  62. package/src/adapters/mcp/deliberate.ts +5 -2
  63. package/src/adapters/mcp/index.ts +3 -1
  64. package/src/adapters/mcp/nights.ts +434 -9
  65. package/src/adapters/mcp/protocol.ts +11 -2
  66. package/src/adapters/mcp/server-args.ts +6 -0
  67. package/src/adapters/mcp/server-options.ts +19 -2
  68. package/src/adapters/mcp/server-self-tools.ts +23 -8
  69. package/src/adapters/mcp/server-session-end.ts +5 -3
  70. package/src/adapters/mcp/server-words.ts +218 -4
  71. package/src/adapters/mcp/server.ts +524 -56
  72. package/src/adapters/mcp/tools.ts +266 -12
  73. package/src/adapters/mechanism-evidence.ts +90 -15
  74. package/src/adapters/owned-names.ts +105 -0
  75. package/src/adapters/plugin.ts +34 -7
  76. package/src/adapters/private-base.ts +175 -0
  77. package/src/adapters/private-umask.ts +71 -0
  78. package/src/adapters/remote/CONTRACT.md +75 -0
  79. package/src/adapters/remote/INTERFACE-GAPS.md +20 -0
  80. package/src/adapters/remote/NOTES.md +80 -0
  81. package/src/adapters/remote/bin/serve-http.ts +258 -0
  82. package/src/adapters/remote/call-log.ts +206 -0
  83. package/src/adapters/remote/http.ts +500 -0
  84. package/src/adapters/sessions.ts +121 -7
  85. package/src/adapters/snapshots.ts +3 -3
  86. package/src/adapters/spawn.ts +13 -6
  87. package/src/adapters/update-check.ts +870 -0
  88. package/src/adapters/update-words.ts +230 -0
  89. package/src/core/counterpart-deposit.ts +35 -2
  90. package/src/core/counterpart-sweep.ts +7 -1
  91. package/src/core/counterpart-types.ts +7 -0
  92. package/src/core/counterpart.ts +185 -23
  93. package/src/core/coverage/CONTRACT.md +12 -5
  94. package/src/core/coverage/NOTES.md +40 -1
  95. package/src/core/coverage/index.ts +73 -14
  96. package/src/core/coverage/tunables.ts +15 -1
  97. package/src/core/dream/CONTRACT.md +47 -9
  98. package/src/core/dream/NOTES.md +115 -0
  99. package/src/core/dream/index.ts +51 -6
  100. package/src/core/dream/recalled.ts +90 -0
  101. package/src/core/dream/reflect.ts +156 -25
  102. package/src/core/dream/tunables.ts +61 -0
  103. package/src/core/handoff/CONTRACT.md +8 -1
  104. package/src/core/handoff/NOTES.md +52 -0
  105. package/src/core/handoff/last-here.ts +52 -0
  106. package/src/core/mint.ts +8 -1
  107. package/src/core/onboarding.ts +35 -8
  108. package/src/core/recall/CONTRACT.md +11 -0
  109. package/src/core/reconsolidation.ts +2 -1
  110. package/src/core/remember/CONTRACT.md +2 -1
  111. package/src/core/remember/owes.ts +7 -1
  112. package/src/core/remember/proposals.ts +41 -1
  113. package/src/core/schemas/CONTRACT.md +4 -2
  114. package/src/core/self/INTERFACE-GAPS.md +20 -0
  115. package/src/core/self/briefing.ts +37 -1
  116. package/src/core/self/identity.ts +54 -4
  117. package/src/core/self/index.ts +69 -4
  118. package/src/core/self/work.ts +20 -0
  119. package/src/core/self/writer.ts +15 -1
  120. package/src/core/store/CONTRACT.md +28 -2
  121. package/src/core/store/NOTES.md +97 -2
  122. package/src/core/store/db.ts +24 -1
  123. package/src/core/store/index.ts +28 -2
  124. package/src/core/store/operational.ts +37 -1
  125. package/src/core/store/pre-migration.ts +6 -2
  126. package/src/core/store/private.ts +319 -0
  127. package/src/core/store/shapes.ts +6 -0
  128. package/src/core/types.ts +28 -0
  129. package/tools/install-loop/run.sh +3 -0
@@ -2092,3 +2092,28 @@ door the plugin's `/counterparts:uninstall` drives.
2092
2092
  deprecated, for the same release; the `store.export` row no longer carries them.
2093
2093
  - The `remove` list and `dream` / `night` / `core --list` lost their `[confidential]`
2094
2094
  markers; `[journal]` and the body fallback stay.
2095
+
2096
+ ## 2026-10-27 — `connect` writes Counterparts Online's deny entry (R1)
2097
+
2098
+ - One entry, `{ "serverUrl": install.ts#HOSTED_DENY_URL }`, in `deniedMcpServers`, planned
2099
+ with the hooks (`wire.ts#planSettings`) so a run that changes either takes one backup and
2100
+ makes one write. Ours is recognised only as exactly that object; an entry somebody wrote
2101
+ for the same URL with keys of its own counts as present and is never removed. A
2102
+ `deniedMcpServers` that is not a list is a refusal, like a bad `hooks` key.
2103
+ - The URL, not a `serverName`: the name is whatever each person typed for the connector.
2104
+ - The plugin's keep-the-memory uninstall (`onlyDead`) leaves the entry while a hook or
2105
+ registration of ours still runs: it is a live npm install's protection.
2106
+ - An install from before this build has its hooks and server already, so nothing re-adds
2107
+ the entry until `connect` runs again; `doctor`'s Online line is amber with that fix.
2108
+ - `doctor`'s Online line shows only beside npm wiring: with nothing connected the Claude
2109
+ Code line already says to run `connect`, and a plugin-only install has no `connect` to run.
2110
+ - Our own processes run under umask 077 (`adapters/private-umask.ts`), so `connect` spawns
2111
+ `claude` under the umask it was given (`withHostUmask`): rule 6, `~/.claude.json` is not
2112
+ ours, extends to its mode.
2113
+ - Review of #657: ours is matched by content, so an entry a person typed byte for byte the
2114
+ same is taken out by `disconnect` too, and the line names it (someone leaving for Online
2115
+ wants it gone anyway). A `deniedMcpServers` that is not a list refuses only `connect`;
2116
+ `disconnect` leaves it alone. `~/.claude` (and Desktop's folder) are made under the host's
2117
+ umask, and so are our own children (`spawn.ts`, the plugin's first run, the plugin
2118
+ console's hand-off), which set 077 themselves: before, the night's `claude -p` inherited
2119
+ 077 from a hook and wrote Claude Code's own files 0600.
@@ -35,6 +35,7 @@ import { resolve } from "node:path";
35
35
  import { fileURLToPath } from "node:url";
36
36
 
37
37
  import { BINARY, TRANSPILED } from "../../runtime.js";
38
+ import { usePrivateUmask, withHostUmask } from "../../private-umask.js";
38
39
  import type { Binary } from "../../runtime.js";
39
40
  import { npmWiring } from "../../host-wiring.js";
40
41
  import { PACKAGE_ROOT, PLUGIN_ROOT_ENV, npmDoctorCommand, pluginDoctorLine, pluginOrigin, runningAsPlugin } from "../../plugin.js";
@@ -86,8 +87,8 @@ function doctorFromStoodDownPlugin(): number | null {
86
87
  const wired = npmDoctorCommand(wiring);
87
88
  const r =
88
89
  wired !== null
89
- ? spawnSync(wired.exe, [...wired.args], { stdio: "inherit", env })
90
- : spawnSync("counterparts", process.argv.slice(2), { stdio: "inherit", env });
90
+ ? withHostUmask(() => spawnSync(wired.exe, [...wired.args], { stdio: "inherit", env }))
91
+ : withHostUmask(() => spawnSync("counterparts", process.argv.slice(2), { stdio: "inherit", env }));
91
92
  if (r.error !== undefined) {
92
93
  process.stdout.write("The npm install's `counterparts` is not on this PATH. Run `counterparts doctor` in a terminal.\n");
93
94
  return 0;
@@ -152,6 +153,7 @@ export function isEntryPoint(argv1: string | undefined, url: string, binary: Bin
152
153
  /** Run one console command and exit — what this file does as a script, and
153
154
  * what the single binary's `cli` mode calls. */
154
155
  export function start(): void {
156
+ usePrivateUmask();
155
157
  // THE PLUGIN DIRECTORY'S BUNDLE (transpiled, no `plugin-run.sh`): this entry
156
158
  // is what its commands run, from a Bash call that carries no
157
159
  // CLAUDE_PLUGIN_ROOT, so it says what `plugin-run.sh cli` says for the full
@@ -17,6 +17,7 @@ import { hostsSeen } from "../sessions.js";
17
17
  import { EXIT, hostConfigFor } from "./commands-shared.js";
18
18
  import { storeId } from "../store-id.js";
19
19
  import type { Parsed, Io, RunOptions } from "./commands-shared.js";
20
+ import { withHostUmask } from "../private-umask.js";
20
21
 
21
22
  // ── dashboard ───────────────────────────────────────────────────────────────
22
23
 
@@ -253,11 +254,13 @@ function openInBrowser(url: string, env: Record<string, string | undefined>): vo
253
254
  process.platform === "darwin" ? "open" : process.platform === "linux" ? "xdg-open" : null;
254
255
  if (opener === null) return;
255
256
  try {
256
- const child = spawn(opener, [url], {
257
- detached: true,
258
- stdio: "ignore",
259
- env: env as NodeJS.ProcessEnv,
260
- });
257
+ const child = withHostUmask(() =>
258
+ spawn(opener, [url], {
259
+ detached: true,
260
+ stdio: "ignore",
261
+ env: env as NodeJS.ProcessEnv,
262
+ }),
263
+ );
261
264
  // An ENOENT arrives as an EVENT, not as a throw, and an unhandled 'error'
262
265
  // on a child process takes the whole console down with it.
263
266
  child.on("error", () => {
@@ -11,12 +11,11 @@ import { CONFIG_ENV, CONFIG_FLAG, defaultConfigPath } from "../config-path.js";
11
11
  import type { ConfigChoice } from "../config-path.js";
12
12
  // The local table's locator, for install's one check that the weights the new
13
13
  // configuration asks for are where the hooks will look.
14
- import {
15
- MODEL_FILE,
16
- STATIC_WEIGHTS_ENV,
17
- STATIC_WEIGHTS_PACKAGE,
18
- resolveStaticWeights,
19
- } from "../../core/embed/static.js";
14
+ import { STATIC_WEIGHTS_ENV } from "../../core/embed/static.js";
15
+ // The same look and the same route's step as doctor's Recall by meaning line
16
+ // and the wake's (2026-10-27, review of #664).
17
+ import { PLUGIN_TABLE_UPDATE, byRoute, npmTableCommand, tableOnDisk } from "../claude-code/doctor-meaning.js";
18
+ import { installRoute } from "../plugin.js";
20
19
  import {
21
20
  installLayout,
22
21
  layoutRefusal,
@@ -46,7 +45,6 @@ import { tilde, realSpawner, realProcessLister, wire, unwire, sessionsNote, look
46
45
  import type { WireResult, Spawner, WireInput, ProcessLister } from "./wire.js";
47
46
  import { desktopUnavailable, connectDesktop, repairDesktop } from "./desktop.js";
48
47
  import type { DesktopRepair } from "./desktop.js";
49
- import { bundledModelDir } from "../runtime.js";
50
48
  import { DESKTOP_ALWAYS_ALLOW } from "../hosts.js";
51
49
  // `humanBytes` comes from `uninstall.ts` rather than from the private one
52
50
  // below: the two spell a size differently ("7.6 MB" against "7.6 MiB"), and
@@ -449,7 +447,8 @@ function printHostSteps(io: Io, resolved: string, custom: string | undefined, ho
449
447
  io.out("Two steps left, and they are the HOST'S files, so they are printed, not applied.");
450
448
  io.out("Nothing below has been written and no host configuration was read.");
451
449
  io.out("");
452
- io.out(" 1. Merge this into ~/.claude/settings.json (one script, five events):");
450
+ io.out(" 1. Merge this into ~/.claude/settings.json (one script on five events, and one");
451
+ io.out(" deniedMcpServers entry that keeps Counterparts Online out of Claude Code):");
453
452
  io.out("");
454
453
  for (const line of settingsBlock(hookCommand(custom)).split("\n")) io.out(` ${line}`);
455
454
  io.out("");
@@ -834,12 +833,11 @@ async function installConversation(
834
833
  // M1 named.
835
834
  //
836
835
  // Looked for the way the hooks will look (`resolveStaticWeights`: the
837
- // environment variable, then the installed package), and then for the table
838
- // FILE in what that found — a variable naming an empty folder is not a table.
839
- const bundled = bundledModelDir();
840
- const table = resolveStaticWeights({ env, ...(bundled === undefined ? {} : { packageDir: bundled }) });
836
+ // environment variable, then the installed package), and then for the
837
+ // table's two FILES in what that found — a variable naming an empty folder
838
+ // is not a table (`doctor-meaning.ts#tableOnDisk`, doctor's look too).
841
839
  const tableOn = config.embedder?.enabled === true;
842
- const tableMissing = tableOn && (table === null || !existsSync(join(table.dir, MODEL_FILE)));
840
+ const tableMissing = tableOn && !tableOnDisk({ env }).complete;
843
841
  if (tableOn && !tableMissing) {
844
842
  io.out("Recall by meaning: on. A small model runs on your machine; nothing is sent anywhere.");
845
843
  u.blank();
@@ -853,7 +851,7 @@ async function installConversation(
853
851
  }
854
852
  if (tableMissing) {
855
853
  u.warn("recall by meaning is on, but its table was not found — recall will match on words only.");
856
- u.hint(`Install it: bun add -g ${STATIC_WEIGHTS_PACKAGE} — or set ${STATIC_WEIGHTS_ENV} to a folder holding it.`);
854
+ u.hint(`Install it: ${byRoute(installRoute(env), npmTableCommand(), PLUGIN_TABLE_UPDATE)} — or set ${STATIC_WEIGHTS_ENV} to a folder holding it.`);
857
855
  u.blank();
858
856
  }
859
857
 
@@ -144,6 +144,9 @@ export type { Io, RunOptions } from "./commands-shared.js";
144
144
  export { logEntryLine, firedLines, DOCTOR_RED_EXIT } from "./commands-readings.js";
145
145
  // The settled-things measure, public for a host's own reading (the harness's compare column).
146
146
  export { settledReading, settledLines } from "./mechanisms.js";
147
+ // The coverage ledger as rows (2026-10-26): what `counterparts coverage` reads, for the harness's scripted week.
148
+ export { coverageReading } from "./coverage.js";
149
+ export type { CoverageRow } from "./coverage.js";
147
150
  export type { SettledReading } from "./mechanisms.js";
148
151
  export { carryForward, KNOWN_HOSTS } from "./commands-install.js";
149
152
  export { DASHBOARD_DEFAULT_PORT, dashboardLine } from "./commands-dashboard.js";
@@ -345,7 +348,7 @@ export const BINARY_CONNECT_REFUSAL =
345
348
  "This is Counterparts' single program, the one the Claude Code plugin downloads when a computer has no Bun or Node.js. " +
346
349
  "It doesn't connect hosts itself: the plugin already runs the hooks and the memory server, and anything wired to this file " +
347
350
  "would stop working when the plugin is uninstalled. To wire Claude Code or Claude Desktop by hand, install Counterparts with " +
348
- "npm (`npm i -g counterparts`) and run `counterparts connect` from that install.";
351
+ "npm (`npm i -g counterparts@latest`) and run `counterparts connect` from that install.";
349
352
 
350
353
  /**
351
354
  * THE CONSOLE'S MAP — about forty lines, grouped, one line per command.
@@ -622,7 +625,7 @@ export const COMMAND_BLURB: Record<Command, string> = {
622
625
  status: "What is held, what left, what was removed. Read-only.",
623
626
  install:
624
627
  "Cold start: create the store and write claude-code.json under ~/.counterparts/ (the path the hooks read unless --config names another). At a terminal it asks your name, turns on recall by meaning (a local table — nothing leaves this machine), connects Claude Code (counterparts disconnect undoes that), and offers back any memory a parked uninstall set aside. Anywhere else — a pipe, a script, a CI job — and with --no-connect it prints the host's hooks block and MCP line and changes nothing of the host's.",
625
- connect: "Connect an AI to your memory: put the five hooks in the host's settings file and register the memory tools. It backs the settings file up first and says the path, keeps every other tool's hooks exactly where they are, repairs an entry of ours that names a path that is gone, and refuses a settings file it cannot parse. Claude Code is the one host it knows today.",
628
+ connect: "Connect an AI to your memory: put the five hooks in the host's settings file and register the memory tools, and keep Counterparts Online's claude.ai connector out of Claude Code with one deniedMcpServers entry. It backs the settings file up first and says the path, keeps every other tool's hooks exactly where they are, repairs an entry of ours that names a path that is gone, and refuses a settings file it cannot parse. Claude Code is the one host it knows today.",
626
629
  disconnect:
627
630
  "Disconnect an AI: take the Counterparts hooks back out of the host's settings file and deregister the memory server. It removes only what it recognises as ours; another tool's hooks are never candidates. Your memory is not touched.",
628
631
  uninstall:
@@ -51,7 +51,7 @@ function standing(e: LedgerEntry, zone: string, auto: boolean, person: boolean):
51
51
  if (e.lapsed) {
52
52
  return `${what} — let go after ${plural(e.daysOfUseSince, "day", "days")} of use unwritten: lost to memory, no longer owed, nothing deleted`;
53
53
  }
54
- if (e.owed && !person) return `${what} — left to lapse (small; not known as a person's session): nothing asks for its write-up`;
54
+ if (e.owed && !person) return `${what} — left to lapse (short, and headless or with no session record): nothing asks for its write-up`;
55
55
  if (e.owed) {
56
56
  const why = e.state === "ended" ? "it ended" : "it has been quiet since the date changed";
57
57
  // WHO CATCHES IT UP (2026-10-11): under dreaming `auto` the nightly run
@@ -67,15 +67,37 @@ function standing(e: LedgerEntry, zone: string, auto: boolean, person: boolean):
67
67
  );
68
68
  }
69
69
 
70
+ /** The ledger as this command reads it: every session holding a captured piece, judged now. Read-only. */
71
+ function ledgerNow(store: Store): LedgerEntry[] {
72
+ const now = store.now();
73
+ // READ-ONLY by construction: an observer buffer writes nothing.
74
+ const spans = new SpanBuffer({ dir: store.dir, observer: true, now: () => now });
75
+ const host = hostSessionEvidence(store);
76
+ return ledger(spans, { now, zone: store.zone(), host: (s) => ({ endedAt: host(s).endedAt }) });
77
+ }
78
+
79
+ /** One session as the ledger judges it, with the catch-up's filter beside it. Counts and times, no text. */
80
+ export type CoverageRow = LedgerEntry & {
81
+ /** A write-up is ever asked for it (`sessions.ts#pointable`). */
82
+ readonly person: boolean;
83
+ };
84
+
85
+ /**
86
+ * THE LEDGER, STRUCTURED (2026-10-26, harness tier 0): what this command
87
+ * prints, as rows, for a host or an instrument that measures it (the
88
+ * harness's scripted week). The same reading and the same filter as
89
+ * `coverageLines`. Read-only.
90
+ */
91
+ export function coverageReading(store: Store): CoverageRow[] {
92
+ return ledgerNow(store).map((e) => ({ ...e, person: pointable(e, store.dir) }));
93
+ }
94
+
70
95
  /** The lines `counterparts coverage` prints for `date`. */
71
96
  export function coverageLines(input: { store: Store; date: string; today: string }): string[] {
72
97
  const { store, date } = input;
73
98
  const zone = store.zone();
74
99
  const now = store.now();
75
- // READ-ONLY by construction: an observer buffer writes nothing.
76
- const spans = new SpanBuffer({ dir: store.dir, observer: true, now: () => now });
77
- const host = hostSessionEvidence(store);
78
- const entries = ledger(spans, { now, zone, host: (s) => ({ endedAt: host(s).endedAt }) });
100
+ const entries = ledgerNow(store);
79
101
  // ONE FILTER for "is a write-up ever asked for it" (2026-10-11): the one
80
102
  // the catch-up and doctor read, so this command never lists as owed what
81
103
  // they rightly let lapse.
@@ -139,7 +161,7 @@ export function coverageLines(input: { store: Store; date: string; today: string
139
161
  );
140
162
  if (lapsing.length > 0) {
141
163
  out.push(
142
- `Left to lapse (small; not known as a person's session): ${plural(lapsing.length, "session", "sessions")} — ${lapsing
164
+ `Left to lapse (short, and headless or with no session record): ${plural(lapsing.length, "session", "sessions")} — ${lapsing
143
165
  .map((e) => `${e.session} (${plural(e.stretch?.pieces ?? 0, "piece", "pieces")})`)
144
166
  .join(", ")}.`,
145
167
  );
@@ -491,6 +491,10 @@ export const COMMAND_DETAIL: Record<string, readonly string[]> = {
491
491
  "If `claude` is not on your PATH the hooks still go in and the line is",
492
492
  "printed for you.",
493
493
  "",
494
+ "It also adds one entry to deniedMcpServers in the same file, so a",
495
+ "claude.ai connector to Counterparts Online is not loaded into Claude Code",
496
+ "as a second memory; every other entry there stays as it is.",
497
+ "",
494
498
  "Claude Code is the one host it knows today, so `counterparts connect` and",
495
499
  "`counterparts connect claude-code` are the same thing and any other name",
496
500
  "is refused. It does not ask first: naming the verb is the yes.",
@@ -505,7 +509,8 @@ export const COMMAND_DETAIL: Record<string, readonly string[]> = {
505
509
  ],
506
510
  disconnect: [
507
511
  "It removes only the entries it recognises as its own — another tool's hooks",
508
- "are never candidates — and runs `claude mcp remove`. It backs the settings",
512
+ "are never candidates — and runs `claude mcp remove`. It takes its one",
513
+ "deniedMcpServers entry back out, and only that one. It backs the settings",
509
514
  "file up first, exactly as `connect` does. Your memory is not touched, and",
510
515
  "this one works even if the configuration is already gone.",
511
516
  ],
@@ -77,6 +77,8 @@ export {
77
77
  CONFIG_FILE,
78
78
  HOOK_SCRIPT,
79
79
  HOST_EVENTS,
80
+ HOSTED_DENY_URL,
81
+ DENY_KEY,
80
82
  MCP_SCRIPT,
81
83
  MCP_SERVER_NAME,
82
84
  budgetRefusal,
@@ -93,6 +93,22 @@ export const BIN = {
93
93
  /** The name the MCP server is registered under, and the one `status` reports. */
94
94
  export const MCP_SERVER_NAME = "counterparts";
95
95
 
96
+ /**
97
+ * COUNTERPARTS ONLINE, KEPT OUT OF CLAUDE CODE (2026-10-27, R1). Claude Code
98
+ * loads a person's claude.ai connectors into every session, so somebody with
99
+ * this install AND the hosted connector would get two memory servers over two
100
+ * stores. `connect` puts this one entry in `deniedMcpServers`
101
+ * (`wire.ts#mergeDeny`); `disconnect` takes exactly it out; `doctor` reads it.
102
+ *
103
+ * The URL, never a `serverName`: the name is whatever each person typed for
104
+ * the connector. The domain is the hosted DESIGN's lean (`app.counterparts.ai`),
105
+ * not a final word: this constant is the one place to change it.
106
+ */
107
+ export const HOSTED_DENY_URL = "https://app.counterparts.ai/*";
108
+
109
+ /** The settings key Claude Code reads its MCP deny list from. */
110
+ export const DENY_KEY = "deniedMcpServers";
111
+
96
112
  /**
97
113
  * THE TWO ENTRY SCRIPTS, ABSOLUTE, resolved from THIS file's location — never
98
114
  * from a working directory and never from a name on a PATH.
@@ -443,7 +459,7 @@ export function settingsBlock(hookCommand = runCommand(HOOK_SCRIPT)): string {
443
459
  for (const event of HOST_EVENTS) {
444
460
  hooks[event] = [{ hooks: [{ type: "command", command: hookCommand }] }];
445
461
  }
446
- return JSON.stringify({ hooks }, null, 2);
462
+ return JSON.stringify({ hooks, [DENY_KEY]: [{ serverUrl: HOSTED_DENY_URL }] }, null, 2);
447
463
  }
448
464
 
449
465
  /**
@@ -588,6 +604,9 @@ export interface HostRead {
588
604
  readonly plugin: PluginInstallRead | null;
589
605
  /** A recorded `counterparts-sidebar@…` install (`host-wiring.ts#sidebarPluginRecorded`). */
590
606
  readonly sidebarPlugin: boolean;
607
+ /** Some settings file read carries `{ "serverUrl": HOSTED_DENY_URL }` in
608
+ * `deniedMcpServers` (R1, 2026-10-27). */
609
+ readonly deny: boolean;
591
610
  }
592
611
 
593
612
  /** Which of our host entries a runtime row came from: Claude Code's hooks, its
@@ -776,6 +795,8 @@ export function readHost(
776
795
  const stale = new Map<string, string>();
777
796
  const settingsRead: string[] = [];
778
797
  const settingsUnreadable: string[] = [];
798
+ // Counterparts Online kept out (R1): our URL in any settings file read.
799
+ let deny = false;
779
800
  // WHICH RUNTIME the host launches us with — read off the same commands, never
780
801
  // spawned: `bun run <script>` or `node --import <node-hooks.mjs> <script>`.
781
802
  const runtimes = new Map<string, { kind: RuntimeKind | "binary"; used: Set<HostUse>; projectEnv: Set<HostUse> }>();
@@ -809,6 +830,7 @@ export function readHost(
809
830
  if (read.state === "unreadable") settingsUnreadable.push(path);
810
831
  if (read.state !== "read") continue;
811
832
  settingsRead.push(path);
833
+ if (Array.isArray(read.value[DENY_KEY]) && (read.value[DENY_KEY] as unknown[]).some((e) => e !== null && typeof e === "object" && (e as Record<string, unknown>)["serverUrl"] === HOSTED_DENY_URL)) deny = true;
812
834
  const hooks = read.value["hooks"];
813
835
  if (hooks === null || typeof hooks !== "object" || Array.isArray(hooks)) continue;
814
836
  for (const [event, entries] of Object.entries(hooks as Record<string, unknown>)) {
@@ -886,6 +908,7 @@ export function readHost(
886
908
  })),
887
909
  plugin: pluginInstall({ home, env, cwd }),
888
910
  sidebarPlugin: sidebarPluginRecorded({ home, env, cwd }),
911
+ deny,
889
912
  };
890
913
  }
891
914
 
@@ -68,15 +68,14 @@ function plural(n: number, one: string, many = `${one}s`): string {
68
68
  return `${String(n)} ${n === 1 ? one : many}`;
69
69
  }
70
70
 
71
- const NOT_BUILT = (why: string) => (): { light: Light; says: string } => ({
72
- light: LIGHT.notBuilt,
73
- says: `not built yet: ${why}`,
74
- });
75
-
76
71
  /**
77
72
  * THE CONSOLE'S WINDOW: seven CALENDAR days, today included, in the store's
78
73
  * zone — the same window the `fired` report counts over. The lived-day bound
79
74
  * only keeps the read cheap (a lived day is never longer than a calendar day).
75
+ * A census has no row to date and counts from its bound alone, so it is given
76
+ * the dashboard's: seven lived days, today included (2026-10-26, review of
77
+ * #629 — at `- 7` a belief born eight lived days back lit the console's
78
+ * Schemas row while the dashboard and `fired` called it quiet).
80
79
  */
81
80
  export function calendarWindow(store: ReadOnlyStore, today: string): EvidenceWindow {
82
81
  let livedDay = 0;
@@ -89,6 +88,7 @@ export function calendarWindow(store: ReadOnlyStore, today: string): EvidenceWin
89
88
  const zone = store.zone();
90
89
  return {
91
90
  sinceDay: Math.max(0, livedDay - FIRED_DAYS),
91
+ censusSinceDay: Math.max(0, livedDay - (FIRED_DAYS - 1)),
92
92
  today: livedDay,
93
93
  contains: (row: EventRow) => {
94
94
  const date = rowDate(row, payloadOf(row), zone);
@@ -367,9 +367,32 @@ export const MEMORY_MECHANISMS: readonly MemoryMechanism[] = [
367
367
  name: "Schemas",
368
368
  group: "Transformation",
369
369
  id: "schema",
370
- // Entity cards are built; beliefs about them have no live producer.
371
- evidence: ["entity-birth"],
372
- read: NOT_BUILT("nothing forms beliefs about people and projects yet"),
370
+ // Built since wave 2 (0.3.31): the night's reflection forms beliefs about
371
+ // me, us and the people and projects in play, adopts a dream's
372
+ // candidates, and files the memories that back or go against them; a
373
+ // session may form one about me awake. Read off the rows (the census).
374
+ evidence: ["entity-birth", "belief-birth", "belief-support"],
375
+ read: (v) => {
376
+ const born = part(v, "born");
377
+ const adopted = part(v, "adopted");
378
+ const support = part(v, "support");
379
+ const contrary = part(v, "contrary");
380
+ const held = v.held === null ? "" : `; ${plural(v.held, "belief")} held`;
381
+ if (v.fired) {
382
+ const parts: string[] = [];
383
+ if (born > 0) parts.push(`${plural(born, "belief")} formed`);
384
+ if (adopted > 0) parts.push(`${plural(adopted, "belief")} adopted from a dream`);
385
+ parts.push(`${plural(support, "memory", "memories")} filed as support (${String(contrary)} against)`);
386
+ return { light: LIGHT.working, says: `${parts.join(", ")}${held}` };
387
+ }
388
+ return {
389
+ light: LIGHT.idle,
390
+ says:
391
+ (v.held ?? 0) > 0
392
+ ? `built, not firing this week: no belief formed and no memory filed for or against one${held}`
393
+ : "built, not firing yet: no beliefs yet (the night's reflection forms one when lived memories back it)",
394
+ };
395
+ },
373
396
  },
374
397
  {
375
398
  name: "Gist",
@@ -79,6 +79,7 @@ import { listSessions, readServerRecords, serverBelieved } from "../sessions.js"
79
79
  import { pathGuard, readLiveness, realpathDeep, sameFilesystemRefusal } from "./start-fresh.js";
80
80
  import { look } from "./wire.js";
81
81
  import type { ProcessLister } from "./wire.js";
82
+ import { ASIDE_NAME_RE, ASIDE_PREFIX } from "../owned-names.js";
82
83
 
83
84
  /** Take the hold away, and its directory when that leaves it empty. Here and
84
85
  * not in the store, whose files call no filesystem removal. */
@@ -91,9 +92,8 @@ export function clearRollbackHold(storeDir: string): void {
91
92
  removeIfEmpty(join(storeDir, ROLLBACK_HOLD_DIR));
92
93
  }
93
94
 
94
- /** `<base>/rollback-aside-v13-2026-10-11T07-25-00-000Z`. */
95
- export const ASIDE_PREFIX = "rollback-aside-v";
96
- const ASIDE_NAME_RE = /^rollback-aside-v[0-9A-Za-z]+-\d{4}-\d{2}-\d{2}T\d{2}-\d{2}-\d{2}-\d{3}Z$/;
95
+ /** `<base>/rollback-aside-v13-2026-10-11T07-25-00-000Z`: spelled in `owned-names.ts`, the list uninstall and privacy share. */
96
+ export { ASIDE_PREFIX } from "../owned-names.js";
97
97
 
98
98
  /** `counterparts.sqlite.rollback-<pid>`: the copy, before it is renamed into place. */
99
99
  const TMP_INFIX = ".rollback-";
@@ -27,7 +27,6 @@ import {
27
27
  copyFileSync,
28
28
  existsSync,
29
29
  lstatSync,
30
- mkdirSync,
31
30
  readdirSync,
32
31
  realpathSync,
33
32
  statSync,
@@ -43,6 +42,7 @@ import {
43
42
  isWithin,
44
43
  paths,
45
44
  } from "../../core/store/index.js";
45
+ import { mkdirPrivate } from "../../core/store/index.js";
46
46
  import type { Store } from "../../core/store/index.js";
47
47
 
48
48
  export type CopyMethod = "vacuum-into" | "file-tree" | "skipped";
@@ -158,11 +158,11 @@ function copyTree(from: string, to: string): number {
158
158
  if (!existsSync(from)) return 0;
159
159
  const stat = statSync(from);
160
160
  if (!stat.isDirectory()) {
161
- mkdirSync(join(to, ".."), { recursive: true });
161
+ mkdirPrivate(join(to, ".."));
162
162
  copyFileSync(from, to);
163
163
  return 1;
164
164
  }
165
- mkdirSync(to, { recursive: true });
165
+ mkdirPrivate(to);
166
166
  let files = 0;
167
167
  for (const name of readdirSync(from)) {
168
168
  files += copyTree(join(from, name), join(to, name));
@@ -189,7 +189,7 @@ export function snapshot(store: Store, target: string): SnapshotReport {
189
189
  // The layout is re-asserted here, not assumed from open: a directory that
190
190
  // appeared since the store opened must be classified before it is skipped.
191
191
  store.assertLayout();
192
- mkdirSync(resolvedTarget, { recursive: true });
192
+ mkdirPrivate(resolvedTarget);
193
193
  } catch (err) {
194
194
  return {
195
195
  ok: false,
@@ -816,6 +816,12 @@ export interface Ui {
816
816
  warning(text: string, ...more: readonly string[]): void;
817
817
  /** An aside under the line above it: dim, and indented into the gutter. */
818
818
  hint(text: string): void;
819
+ /**
820
+ * A paste-ready command, alone on its line and NEVER folded (W3, 10-28): a
821
+ * command broken across lines breaks when pasted. Indented under the hints
822
+ * around it; the prose around it may wrap, this may not.
823
+ */
824
+ command(text: string): void;
819
825
  /** A doctor-shaped line: the grade in colour, the label in its column, a
820
826
  * SHORT message, and the fix on its own indented dim line. */
821
827
  statusLine(grade: Grade, label: string, message: string, fix?: string): void;
@@ -897,6 +903,10 @@ export function ui(io: Io, env: UiEnv, opts: InteractiveOptions = {}): Ui {
897
903
  for (const line of emit(cell, text, MARK_COLUMN)) io.out(p.dim(line));
898
904
  },
899
905
 
906
+ command(text: string): void {
907
+ io.out(`${" ".repeat(MARK_COLUMN + 2)}${text}`);
908
+ },
909
+
900
910
  statusLine(grade: Grade, label: string, message: string, fix?: string): void {
901
911
  const gradeCell = grade.padEnd(GRADE_COLUMN);
902
912
  const prefix = `${gradeCell}${labelCell(label)}`;
@@ -98,6 +98,8 @@ import { Store, assertSafeDataDir, dateOf, isWithin, storeExists } from "../../c
98
98
  import { isJournal } from "../../core/sleep/index.js";
99
99
  import { SCOPES_FILE_NAME, shellWord } from "../scopes.js";
100
100
  import { NPM_LIVE_NAME } from "../npm-live.js";
101
+ import { ownedKind, ownedNames } from "../owned-names.js";
102
+ import type { OwnedKind, OwnedNames } from "../owned-names.js";
101
103
  import { PLUGIN_PRESENCE_NAME, SIDEBAR_FILE_NAME } from "../sidebar-status.js";
102
104
  import { PLUGIN_ROOT_ENV, installRoute } from "../plugin.js";
103
105
  import { pluginInstall } from "../host-wiring.js";
@@ -256,80 +258,11 @@ export function forbiddenBaseRefusal(base: string): string | null {
256
258
  }
257
259
 
258
260
  // ── what we own, by name ────────────────────────────────────────────────────
259
-
260
- export type OwnedKind = "config" | "scopes" | "snapshots" | "store" | "sidecar";
261
-
262
- /** The basenames this package writes inside a configuration directory. Built
263
- * from the configuration rather than assumed, because three of the five are
264
- * things the file itself can move. */
265
- export interface OwnedNames {
266
- readonly config: string;
267
- readonly scopes: string;
268
- /** Null when `snapshots.dir` points at a directory the OWNER chose, which
269
- * this command leaves alone exactly as `start-fresh` does. */
270
- readonly snapshots: string | null;
271
- /** Null when `dataDir` is not directly inside the configuration directory. */
272
- readonly store: string | null;
273
- }
274
-
275
- export function ownedNames(
276
- configPath: string,
277
- config: AdapterConfig,
278
- storeDir: string | null,
279
- ): OwnedNames {
280
- const dir = resolve(dirname(configPath));
281
- const snaps =
282
- storeDir === null
283
- ? null
284
- : resolveSnapshotsDir(storeDir, config.snapshots?.dir).dir;
285
- return {
286
- config: basename(resolve(configPath)),
287
- scopes: SCOPES_FILE_NAME,
288
- snapshots:
289
- snaps !== null && resolve(dirname(snaps)) === dir ? basename(snaps) : null,
290
- store: storeDir !== null && resolve(dirname(storeDir)) === dir ? basename(storeDir) : null,
291
- };
292
- }
293
-
294
- /**
295
- * Is this entry name one this package writes, and which kind?
296
- *
297
- * The sidecars matter as much as the files: `scopes.ts` writes `<path>.<pid>.tmp`
298
- * siblings (and the removed `keys.ts` wrote them too, and a bare `<path>.tmp`
299
- * before review n4, which a leftover may still be), `start-fresh` leaves `store.parked-<date>`,
300
- * `store.blank-<date>` and `store.new-<pid>` behind, and `wire` leaves
301
- * `<file>.counterparts-backup-<stamp>`. A directory holding only those is still
302
- * a directory holding only ours.
303
- */
304
- export function ownedKind(name: string, owned: OwnedNames, configDir?: string): OwnedKind | null {
305
- if (name === owned.config) return "config";
306
- if (name === owned.scopes) return "scopes";
307
- if (owned.snapshots !== null && name === owned.snapshots) return "snapshots";
308
- if (owned.store !== null && name === owned.store) return "store";
309
- if (name === SIDEBAR_FILE_NAME || name === PLUGIN_PRESENCE_NAME || /^sidebar\.json\.\d+\.tmp$/.test(name)) return "sidecar";
310
- if (NPM_LIVE_NAME.test(name)) return "sidecar";
311
- // A developer's night transcripts (2026-10-23, `debug.nightTranscripts`),
312
- // beside a store this package laid out (`config.ts#nightDebugDir`) — ours
313
- // only while it holds nothing else: a `debug` folder with anything of the
314
- // owner's in it is the owner's, never deleted whole (review of C1).
315
- if (name === NIGHT_DEBUG_DIR) {
316
- return owned.store === DEFAULT_STORE_SUBDIR && configDir !== undefined && onlyNightTranscripts(join(configDir, name)) ? "sidecar" : null;
317
- }
318
- const bases = [owned.config, owned.scopes, owned.snapshots, owned.store];
319
- for (const base of bases) {
320
- if (base === null || !name.startsWith(`${base}.`)) continue;
321
- const suffix = name.slice(base.length + 1);
322
- if (
323
- /^\d+\.tmp$/.test(suffix) ||
324
- suffix === "tmp" ||
325
- /^counterparts-backup-/.test(suffix) ||
326
- /^(parked|blank|new)-/.test(suffix)
327
- ) {
328
- return "sidecar";
329
- }
330
- }
331
- return null;
332
- }
261
+ //
262
+ // `owned-names.ts`, shared with `private-base.ts` (re-check of #657), so what a
263
+ // delete may take and what is made private cannot drift apart.
264
+ export { ownedKind, ownedNames } from "../owned-names.js";
265
+ export type { OwnedKind, OwnedNames } from "../owned-names.js";
333
266
 
334
267
  // ── how much is about to go ─────────────────────────────────────────────────
335
268
 
@@ -757,6 +690,7 @@ const WHAT: Record<OwnedKind, string> = {
757
690
  scopes: "which directories memory is on for",
758
691
  snapshots: "the snapshots",
759
692
  store: "your memory",
693
+ aside: "memories too: a whole store `rollback` set aside",
760
694
  sidecar: "a file this package left",
761
695
  };
762
696
 
@@ -767,6 +701,7 @@ const SHORT_WHAT: Record<OwnedKind, string> = {
767
701
  scopes: "scopes",
768
702
  snapshots: "snapshots",
769
703
  store: "your memory",
704
+ aside: "memory stores rollback set aside",
770
705
  sidecar: "files it left behind",
771
706
  };
772
707
 
@@ -990,6 +925,13 @@ export function planLines(
990
925
  for (const line of log ?? []) out.push(`${" ".repeat(2 + pathWidth + 2 + sizeWidth + 3)}${line}`);
991
926
  }
992
927
  if (plan.entries.length === 0) out.push(" (nothing — there is none of ours left here)");
928
+ // A SET-ASIDE STORE IS MEMORY (round 4 of #657): said and counted as such,
929
+ // so "your memory" on one line is not read as the only memory going.
930
+ const asides = plan.entries.filter((e) => e.kind === "aside").length;
931
+ if (asides > 0) {
932
+ const stores = `${String(asides)} whole memory store${asides === 1 ? "" : "s"} \`rollback\` set aside`;
933
+ out.push(plan.storeActed ? ` That is ${String(asides + 1)} memory stores: yours, and ${stores}.` : ` That includes ${stores}.`);
934
+ }
993
935
  if (plan.wholeDirectory) {
994
936
  out.push(` and the ${short(plan.configDir)} folder itself.`);
995
937
  }