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
@@ -54,6 +54,19 @@
54
54
  * host's own door. We READ the file to decide whether to call it — reading
55
55
  * is what `doctor` already does — and we shell out to change it.
56
56
  *
57
+ * ONE KEY BESIDE `hooks` (2026-10-27, R1): one entry in `deniedMcpServers`,
58
+ * `{ "serverUrl": install.ts#HOSTED_DENY_URL }`, so a person's claude.ai
59
+ * connector to Counterparts Online is not loaded into Claude Code as a second
60
+ * memory. Every rule above holds for it: one plan with the hooks
61
+ * (`planSettings`), so one backup and one atomic write; every other entry in
62
+ * that list keeps its place and keys; already there is no change; a list
63
+ * that is not a list is a refusal on `connect` (and left alone by
64
+ * `disconnect`); and `disconnect` takes out exactly that entry and nothing
65
+ * else (`mergeDeny`). OURS IS RECOGNISED BY CONTENT: an entry that is exactly
66
+ * that one object is taken out whoever typed it. A person leaving this
67
+ * install for Online wants it gone anyway, and `disconnect` says which entry
68
+ * it took out.
69
+ *
57
70
  * The one thing this file cannot do anything about is said out loud instead:
58
71
  * a Claude Code session that is already open. Measured 2026-09-21 — after
59
72
  * `settings.json` changes, an open session's hooks fire on its NEXT TURN, and
@@ -88,13 +101,17 @@ import { expandHome, hookCommandLive, isOurHookCommand, npmWiring, readOurHook }
88
101
  import { noteNpmLive, removeNpmLive } from "../npm-live.js";
89
102
  import { PACKAGE_ROOT, PLUGIN_DATA_ENV, PLUGIN_ROOT_ENV } from "../plugin.js";
90
103
  import { claudeCodeEnvMarker } from "../hosts.js";
104
+ import { withHostUmask } from "../private-umask.js";
105
+ import { tightenInstallBase } from "../private-base.js";
91
106
  import { parseScriptInvocation, readsHostUserConfig, scriptArgs, shellTokens } from "../runtime.js";
92
107
  import { installedBuild, installedVersion, readServerRecords, sameBuild, serverBelieved } from "../sessions.js";
93
108
  import type { BuildStamp, ServerRecordRead } from "../sessions.js";
94
109
  import type { Io } from "./commands.js";
95
110
  import {
96
111
  BIN,
112
+ DENY_KEY,
97
113
  HOOK_COMMAND_MARK,
114
+ HOSTED_DENY_URL,
98
115
  HOST_EVENTS,
99
116
  MCP_SCRIPT,
100
117
  MCP_SERVER_NAME,
@@ -362,7 +379,9 @@ function isRecord(value: unknown): value is Record<string, unknown> {
362
379
  * Six refusals, and each one is a shape whose meaning we would be guessing at:
363
380
  * a symlink out of the home, something that is not a regular file, bytes that
364
381
  * are not JSON, a top-level value that is not an object, a `hooks` key that is
365
- * not an object, and one of our five events whose value is not an array.
382
+ * not an object, and one of our five events whose value is not an array. (A
383
+ * `deniedMcpServers` that is not a list is `connect`'s seventh, `denyRefusal`:
384
+ * `disconnect` has nothing to take out of it.)
366
385
  * Guessing about any of them means rewriting somebody's configuration into a
367
386
  * shape they did not choose.
368
387
  */
@@ -784,6 +803,128 @@ export function mergeHooks(
784
803
  return { value: next, events, changed, foreignKept, wrapped, spared };
785
804
  }
786
805
 
806
+ // ── the deny entry (2026-10-27, R1) ─────────────────────────────────────────
807
+
808
+ export interface DenyResult {
809
+ readonly value: Record<string, unknown>;
810
+ /** `added`/`kept` on a wire, `removed`/`none` on an unwire. */
811
+ readonly change: "added" | "kept" | "removed" | "none";
812
+ readonly changed: boolean;
813
+ /** Entries belonging to anybody else, carried through untouched. */
814
+ readonly foreignKept: number;
815
+ }
816
+
817
+ /** Is this deny-list entry exactly ours — `{ "serverUrl": HOSTED_DENY_URL }`
818
+ * and no other key? An entry that names our URL beside keys of its own is
819
+ * somebody's: it counts as "already kept out" and is never removed. */
820
+ function isOurDeny(entry: unknown): boolean {
821
+ return isRecord(entry) && entry["serverUrl"] === HOSTED_DENY_URL && Object.keys(entry).length === 1;
822
+ }
823
+
824
+ /** Does this entry keep our URL out, whoever wrote it? */
825
+ function deniesOurs(entry: unknown): boolean {
826
+ return isRecord(entry) && entry["serverUrl"] === HOSTED_DENY_URL;
827
+ }
828
+
829
+ /**
830
+ * Add (or remove) Counterparts Online's one entry in `deniedMcpServers`, PURE
831
+ * over the settings object, under `mergeHooks`' rules: every other entry keeps
832
+ * its place and its keys, a second copy of ours is dropped, and a list that
833
+ * already keeps our URL out is left as it is. On an unwire the KEY goes when
834
+ * ours was the last thing in it (our litter, as an emptied hook event is), so
835
+ * a list that was already `[]` before a wire does not come back.
836
+ *
837
+ * A `deniedMcpServers` that is not a list never gets here (`sightSettings`
838
+ * refuses it); handed one anyway, this changes nothing.
839
+ *
840
+ * WHAT THIS CANNOT PROVE (said in the PR, and a RUNBOOK §7 step): that a
841
+ * `serverUrl` entry alone keeps a claude.ai connector out of Claude Code. The
842
+ * documented match is on the server's URL, and `/mcp` at deploy is the check.
843
+ */
844
+ export function mergeDeny(settings: Record<string, unknown>, direction: "wire" | "unwire"): DenyResult {
845
+ const raw = settings[DENY_KEY];
846
+ if (raw !== undefined && !Array.isArray(raw)) {
847
+ return { value: settings, change: direction === "wire" ? "kept" : "none", changed: false, foreignKept: 0 };
848
+ }
849
+ const list: unknown[] = Array.isArray(raw) ? raw : [];
850
+ const foreignKept = list.filter((e) => !isOurDeny(e)).length;
851
+ const ours = list.filter(isOurDeny).length;
852
+ if (direction === "wire") {
853
+ if (ours === 0 && list.some(deniesOurs)) {
854
+ // Somebody's own entry for our URL already does the work.
855
+ return { value: settings, change: "kept", changed: false, foreignKept };
856
+ }
857
+ if (ours === 1) return { value: settings, change: "kept", changed: false, foreignKept };
858
+ const next = structuredClone(settings) as Record<string, unknown>;
859
+ if (ours > 1) {
860
+ // A copy pasted twice: the first stays where it is, the rest go.
861
+ let seen = false;
862
+ next[DENY_KEY] = list.filter((e) => {
863
+ if (!isOurDeny(e)) return true;
864
+ if (seen) return false;
865
+ seen = true;
866
+ return true;
867
+ });
868
+ return { value: next, change: "kept", changed: true, foreignKept };
869
+ }
870
+ next[DENY_KEY] = [...structuredClone(list), { serverUrl: HOSTED_DENY_URL }];
871
+ return { value: next, change: "added", changed: true, foreignKept };
872
+ }
873
+ if (ours === 0) return { value: settings, change: "none", changed: false, foreignKept };
874
+ const next = structuredClone(settings) as Record<string, unknown>;
875
+ const kept = (next[DENY_KEY] as unknown[]).filter((e) => !isOurDeny(e));
876
+ if (kept.length === 0) delete next[DENY_KEY];
877
+ else next[DENY_KEY] = kept;
878
+ return { value: next, change: "removed", changed: true, foreignKept };
879
+ }
880
+
881
+ /**
882
+ * THE DENY LIST IS A LIST OR NOTHING, for `connect` (2026-10-27, R1): any other
883
+ * shape is one whose meaning we would be guessing at, so a wire refuses it like
884
+ * a bad `hooks` key. An unwire does not ask: it has nothing of ours to take out
885
+ * of a value that is not a list, and leaves it as it is (review of #657).
886
+ */
887
+ export function denyRefusal(sight: SettingsSight): string | null {
888
+ const denied = sight.value[DENY_KEY];
889
+ if (denied === undefined || Array.isArray(denied)) return null;
890
+ const what = denied === null ? "null" : isRecord(denied) ? "an object" : `a ${typeof denied}`;
891
+ return (
892
+ `refused: the "${DENY_KEY}" key in ${sight.target} is ${what}, not a list. The host reads it ` +
893
+ "as a list of servers to keep out, and this command will not overwrite a value whose meaning it cannot tell."
894
+ );
895
+ }
896
+
897
+ /** Does this settings object keep our URL out (any entry naming it)? */
898
+ export function denyPresent(settings: Record<string, unknown>): boolean {
899
+ const raw = settings[DENY_KEY];
900
+ return Array.isArray(raw) && raw.some(deniesOurs);
901
+ }
902
+
903
+ /**
904
+ * The hooks and the deny entry, as ONE plan over one object, so there is one
905
+ * backup and one write whichever of the two changed.
906
+ */
907
+ export interface SettingsPlan {
908
+ readonly hooks: MergeResult;
909
+ readonly deny: DenyResult;
910
+ readonly value: Record<string, unknown>;
911
+ readonly changed: boolean;
912
+ }
913
+
914
+ export function planSettings(
915
+ settings: Record<string, unknown>,
916
+ command: string,
917
+ direction: "wire" | "unwire",
918
+ spare?: (command: string) => boolean,
919
+ keepDeny = false,
920
+ ): SettingsPlan {
921
+ const hooks = mergeHooks(settings, command, direction, spare);
922
+ const deny = keepDeny
923
+ ? { value: hooks.value, change: "none" as const, changed: false, foreignKept: 0 }
924
+ : mergeDeny(hooks.value, direction);
925
+ return { hooks, deny, value: deny.value, changed: hooks.changed || deny.changed };
926
+ }
927
+
787
928
  // ── writing it ──────────────────────────────────────────────────────────────
788
929
 
789
930
  /**
@@ -829,7 +970,8 @@ export function writeSettings(
829
970
  let backup: string | null = null;
830
971
  let temp: string | null = null;
831
972
  try {
832
- mkdirSync(dir, { recursive: true });
973
+ // Not our directory (`~/.claude`, Desktop's folder): made under the host's umask.
974
+ withHostUmask(() => mkdirSync(dir, { recursive: true }));
833
975
  if (sight.exists) {
834
976
  backup = copyToFreeBackup(target, now);
835
977
  // A backup of a 0600 file must not be world-readable because `copyFile`
@@ -878,7 +1020,9 @@ export function realSpawner(env: Record<string, string | undefined>): Spawner {
878
1020
  // ARGUMENTS, NEVER A SHELL STRING. The store path and the config path come
879
1021
  // from a file on disk and can hold anything at all; a shell would interpret
880
1022
  // it. `spawnSync` with an array passes each one through whole.
881
- const res = spawnSync(CLAUDE_BIN, [...args], {
1023
+ // Under the umask this process was started with: `claude` writes its own
1024
+ // files, and they keep the modes they always had (`private-umask.ts`).
1025
+ const res = withHostUmask(() => spawnSync(CLAUDE_BIN, [...args], {
882
1026
  encoding: "utf8",
883
1027
  timeout: CLAUDE_TIMEOUT_MS,
884
1028
  windowsHide: true,
@@ -886,7 +1030,7 @@ export function realSpawner(env: Record<string, string | undefined>): Spawner {
886
1030
  // a `spawnSync` with no `env` resolves the binary against the REAL
887
1031
  // environment, so a caller's PATH would be ignored.
888
1032
  env: env as NodeJS.ProcessEnv,
889
- });
1033
+ }));
890
1034
  if (res.error !== undefined && res.error !== null) {
891
1035
  const code = (res.error as NodeJS.ErrnoException).code ?? "";
892
1036
  return {
@@ -1188,6 +1332,9 @@ export interface WireResult {
1188
1332
  * was (`mcp` is then "skipped"). A caller that removes it later needs to
1189
1333
  * know whether that removal will need `claude` (`uninstall.ts#offerDelete`). */
1190
1334
  readonly mcpLeft?: LeftWhy;
1335
+ /** What happened to the `deniedMcpServers` entry (2026-10-27, R1); absent
1336
+ * on the arms that returned before the settings were planned. */
1337
+ readonly deny?: DenyResult["change"];
1191
1338
  }
1192
1339
 
1193
1340
  /**
@@ -1239,15 +1386,17 @@ export async function wire(input: WireInput): Promise<WireResult> {
1239
1386
  u.heading("Connecting Claude Code…");
1240
1387
  }
1241
1388
 
1242
- if (sight.refusal !== null) {
1243
- io.err(sight.refusal);
1389
+ const refusal = sight.refusal ?? denyRefusal(sight);
1390
+ if (refusal !== null) {
1391
+ io.err(refusal);
1244
1392
  io.err("");
1245
- io.err("Nothing was changed. The block to merge by hand, under a top-level \"hooks\" key:");
1393
+ io.err("Nothing was changed. The block to merge by hand, its two keys at the top level:");
1246
1394
  for (const line of settingsBlock(command).split("\n")) io.err(` ${line}`);
1247
1395
  return { outcome: "refused", hooks: "refused", mcp: "skipped", backup: null, mcpConfirmed: false };
1248
1396
  }
1249
1397
 
1250
- const merged = mergeHooks(sight.value, command, "wire");
1398
+ const plan = planSettings(sight.value, command, "wire");
1399
+ const merged = plan.hooks;
1251
1400
  const mcp = readMcp(home, env, input.store, input.custom, input.exe);
1252
1401
  // WHEN OUR READ OF THE HOST'S FILE FAILS, ASK THE HOST (review m8).
1253
1402
  //
@@ -1259,7 +1408,7 @@ export async function wire(input: WireInput): Promise<WireResult> {
1259
1408
  const mcpNeeded = !registered;
1260
1409
 
1261
1410
  // ── nothing to do ─────────────────────────────────────────────────────────
1262
- if (!merged.changed && !mcpNeeded) {
1411
+ if (!plan.changed && !mcpNeeded) {
1263
1412
  u.ok(
1264
1413
  `already connected — all ${String(HOST_EVENTS.length)} hooks and the memory tools are in place.`,
1265
1414
  );
@@ -1267,7 +1416,7 @@ export async function wire(input: WireInput): Promise<WireResult> {
1267
1416
  u.hint(`tools: ${tilde(mcp.file, home)} (registered as "${MCP_SERVER_NAME}")`);
1268
1417
  u.hint("Nothing was changed and no backup was taken.");
1269
1418
  if (!input.dryRun) noteWired(input);
1270
- return { outcome: "ok", hooks: "already", mcp: "already", backup: null, mcpConfirmed: false };
1419
+ return { outcome: "ok", hooks: "already", mcp: "already", backup: null, mcpConfirmed: false, deny: "kept" };
1271
1420
  }
1272
1421
 
1273
1422
  // ── say what would change ─────────────────────────────────────────────────
@@ -1288,13 +1437,14 @@ export async function wire(input: WireInput): Promise<WireResult> {
1288
1437
  u,
1289
1438
  sight,
1290
1439
  home,
1291
- hooksClause(merged.changed, sight.exists),
1440
+ hooksClause(plan.changed, sight.exists),
1292
1441
  mcp.present
1293
1442
  ? mcp.matches
1294
1443
  ? "already registered"
1295
1444
  : "re-registered via `claude mcp add`"
1296
1445
  : "via `claude mcp add`",
1297
1446
  );
1447
+ if (plan.deny.change === "added") u.hint(`1 entry -> ${DENY_KEY} in the same file (keeps Counterparts Online out of Claude Code)`);
1298
1448
  }
1299
1449
  for (const e of replacing) {
1300
1450
  u.hint(`${e.event}: replacing a Counterparts hook that names ${e.was ?? "another path"}`);
@@ -1346,18 +1496,22 @@ export async function wire(input: WireInput): Promise<WireResult> {
1346
1496
  /** Where the hooks ended up — the re-read file's target when there was a
1347
1497
  * write, and the one already sighted when there was not. */
1348
1498
  let landedIn = sight.target;
1349
- if (merged.changed) {
1499
+ /** What happened to the deny entry: `kept` until a write says otherwise. */
1500
+ let deny: DenyResult["change"] = "kept";
1501
+ if (plan.changed) {
1350
1502
  // RE-READ BEFORE WRITING (commands.ts rule 2): between the preview and the
1351
1503
  // answer the file may have changed — another tool's installer, an editor
1352
1504
  // saving. The plan is re-made against what is there NOW, and a file that
1353
1505
  // has become unreadable in the meantime refuses rather than gets rewritten.
1354
1506
  const fresh = sightSettings(named, home);
1355
- if (fresh.refusal !== null) {
1356
- io.err(`refused after re-reading the file: ${fresh.refusal}`);
1507
+ const freshRefusal = fresh.refusal ?? denyRefusal(fresh);
1508
+ if (freshRefusal !== null) {
1509
+ io.err(`refused after re-reading the file: ${freshRefusal}`);
1357
1510
  return { outcome: "refused", hooks: "refused", mcp: "skipped", backup: null, mcpConfirmed: false };
1358
1511
  }
1359
- const again = mergeHooks(fresh.value, command, "wire");
1512
+ const again = planSettings(fresh.value, command, "wire");
1360
1513
  landedIn = fresh.target;
1514
+ deny = again.deny.change;
1361
1515
  if (!again.changed) {
1362
1516
  // THE WORK WAS DONE WHILE WE ASKED (review n3). The re-read found the
1363
1517
  // hooks already right — another `connect`, another terminal, the person
@@ -1365,6 +1519,7 @@ export async function wire(input: WireInput): Promise<WireResult> {
1365
1519
  // it took a backup and rewrote identical bytes; now nothing is written
1366
1520
  // and nothing is backed up, and the line below says "already in".
1367
1521
  u.hint("The hooks were already in place when the file was read again, so nothing was written.");
1522
+ deny = "kept";
1368
1523
  } else {
1369
1524
  const wrote = writeSettings(fresh, again.value, now);
1370
1525
  backup = wrote.backup;
@@ -1377,7 +1532,11 @@ export async function wire(input: WireInput): Promise<WireResult> {
1377
1532
  );
1378
1533
  return { outcome: "failed", hooks: "refused", mcp: "skipped", backup, mcpConfirmed: false };
1379
1534
  }
1380
- hooksWord = again.events.some((e) => e.change === "replaced") ? "repaired" : "wired";
1535
+ hooksWord = !again.hooks.changed
1536
+ ? "already"
1537
+ : again.hooks.events.some((e) => e.change === "replaced")
1538
+ ? "repaired"
1539
+ : "wired";
1381
1540
  }
1382
1541
  }
1383
1542
 
@@ -1408,10 +1567,16 @@ export async function wire(input: WireInput): Promise<WireResult> {
1408
1567
  : "memory tools registered";
1409
1568
  const hooksSaid = `${String(HOST_EVENTS.length)} hooks ${verb} ${where}${kept}`;
1410
1569
  u.ok(tools === null ? hooksSaid : `connected — ${hooksSaid}, ${tools}`);
1570
+ if (deny === "added") u.hint(DENY_ADDED_LINE);
1411
1571
  noteWired(input);
1412
- return { outcome: "ok", hooks: hooksWord, mcp: mcpWord, backup, mcpConfirmed: false };
1572
+ return { outcome: "ok", hooks: hooksWord, mcp: mcpWord, backup, mcpConfirmed: false, deny };
1413
1573
  }
1414
1574
 
1575
+ /** `connect`'s one line when the deny entry went in — said once, on the run
1576
+ * that added it, and never on a run that found it there. */
1577
+ export const DENY_ADDED_LINE =
1578
+ `Counterparts Online's connector is kept out of Claude Code (${DENY_KEY} in the same file), so a claude.ai connection never becomes a second memory here.`;
1579
+
1415
1580
  /**
1416
1581
  * THE MARKER A DIRECTORY-FLAVOR PLUGIN STANDS DOWN BY (`npm-live.ts`), written
1417
1582
  * now rather than at the next hook, so a plugin beside this install stands
@@ -1423,6 +1588,9 @@ export async function wire(input: WireInput): Promise<WireResult> {
1423
1588
  * copy then runs beside the settings wiring — a rare path, left as it is.
1424
1589
  */
1425
1590
  function noteWired(input: WireInput): void {
1591
+ // The install's base directory, private (R1, `private-base.ts`): `connect` is
1592
+ // the upgrade path an older install runs.
1593
+ tightenInstallBase(input.configPath, input.store, { home: input.home });
1426
1594
  if ((input.env[PLUGIN_ROOT_ENV] ?? "").trim().length > 0) return;
1427
1595
  noteNpmLive({
1428
1596
  configPath: input.configPath,
@@ -1467,7 +1635,7 @@ function registerMcp(input: WireInput, u: Ui, mcp: McpReading): WireResult["mcp"
1467
1635
  if (res.missing) {
1468
1636
  u.warn("`claude` is not on this PATH, so the MCP server was not registered.");
1469
1637
  u.hint("The hooks are in. Run this one line yourself, then restart Claude Code:");
1470
- u.hint(` ${line}`);
1638
+ u.command(line);
1471
1639
  return "printed";
1472
1640
  }
1473
1641
  let word: WireResult["mcp"] = "added";
@@ -1489,7 +1657,7 @@ function registerMcp(input: WireInput, u: Ui, mcp: McpReading): WireResult["mcp"
1489
1657
  const detail = `${res.err}${res.out}`.trim();
1490
1658
  if (detail.length > 0) for (const l of detail.split("\n").slice(0, 4)) u.hint(l);
1491
1659
  u.hint("Run this yourself, then restart Claude Code:");
1492
- u.hint(` ${line}`);
1660
+ u.command(line);
1493
1661
  return "printed";
1494
1662
  }
1495
1663
  return word;
@@ -1847,7 +2015,7 @@ export async function unwire(input: WireInput): Promise<WireResult> {
1847
2015
  // THE PLUGIN'S RULE (`onlyDead`): a hook that still runs stays.
1848
2016
  const dirs = input.onlyDead === true ? pluginDirs(env, home) : [];
1849
2017
  const spare = input.onlyDead === true ? (command: string): boolean => hookStillRuns(command, env, dirs) : undefined;
1850
- const merged = mergeHooks(sight.value, "", "unwire", spare);
2018
+ const hooksPlan = mergeHooks(sight.value, "", "unwire", spare);
1851
2019
  const mcp = readMcp(home, env, input.store, input.custom, input.exe, MCP_SCRIPT, input.readsUserConfig);
1852
2020
 
1853
2021
  // `mcp.unreadable` is NOT "nothing there": that file is the host's own and a
@@ -1856,9 +2024,16 @@ export async function unwire(input: WireInput): Promise<WireResult> {
1856
2024
  // A file this build never opens (`notRead`) is no evidence either: the
1857
2025
  // removal below asks `claude`. A registration left alone (`onlyDead`, and
1858
2026
  // it still runs or cannot be told) is not ours to disconnect.
1859
- const why = input.onlyDead === true ? leftWhy(input, mcp, merged.spared > 0, dirs) : null;
2027
+ const why = input.onlyDead === true ? leftWhy(input, mcp, hooksPlan.spared > 0, dirs) : null;
1860
2028
  const leave = why !== null;
1861
- if (!merged.changed && (leave || (!mcp.present && !mcp.unreadable && mcp.notRead !== true))) {
2029
+ // THE DENY ENTRY GOES WITH THE LOCAL MEMORY, NOT BEFORE IT (R1). Under the
2030
+ // plugin's rule, a hook or a registration that still runs is a live npm
2031
+ // install's, and the entry is what keeps a hosted connector from becoming
2032
+ // its second memory: it stays while anything of ours is left running.
2033
+ const keepDeny = input.onlyDead === true && (hooksPlan.spared > 0 || (why !== null && why !== "absent"));
2034
+ const plan = planSettings(sight.value, "", "unwire", spare, keepDeny);
2035
+ const merged = plan.hooks;
2036
+ if (!plan.changed && (leave || (!mcp.present && !mcp.unreadable && mcp.notRead !== true))) {
1862
2037
  u.ok(
1863
2038
  `nothing to disconnect: no Counterparts hooks${merged.spared > 0 ? " whose program is gone" : ""}` +
1864
2039
  `${leave ? "" : " and no memory server"} were found.`,
@@ -1883,6 +2058,7 @@ export async function unwire(input: WireInput): Promise<WireResult> {
1883
2058
  u.hint("dry run — nothing below has been written.");
1884
2059
  for (const e of merged.events) u.hint(`${e.event}: would remove ${e.was ?? "our hook"}`);
1885
2060
  if (merged.spared > 0) u.hint(`${String(merged.spared)} Counterparts hook(s) that still run would stay.`);
2061
+ if (plan.deny.change === "removed") u.hint(`${DENY_KEY}: would remove Counterparts Online's entry`);
1886
2062
  if (!leave) u.hint(`would run: claude mcp remove ${MCP_SERVER_NAME} -s user`);
1887
2063
  if (merged.foreignKept > 0) {
1888
2064
  u.hint(
@@ -1906,7 +2082,7 @@ export async function unwire(input: WireInput): Promise<WireResult> {
1906
2082
  u,
1907
2083
  sight,
1908
2084
  home,
1909
- merged.changed ? "(backup first)" : "(none of ours are there)",
2085
+ plan.changed ? "(backup first)" : "(none of ours are there)",
1910
2086
  leave ? "left as it is" : "removed via `claude mcp remove`",
1911
2087
  );
1912
2088
  const go = await confirm(io, leave ? "Remove the Counterparts hooks?" : "Remove the Counterparts hooks and the MCP server?", {
@@ -1920,25 +2096,28 @@ export async function unwire(input: WireInput): Promise<WireResult> {
1920
2096
 
1921
2097
  let backup: string | null = null;
1922
2098
  let hooksWord: WireResult["hooks"] = "none";
1923
- if (merged.changed) {
2099
+ let deny: DenyResult["change"] = keepDeny ? "kept" : "none";
2100
+ if (plan.changed) {
1924
2101
  const fresh = sightSettings(named, home);
1925
2102
  if (fresh.refusal !== null) {
1926
2103
  io.err(`refused after re-reading the file: ${fresh.refusal}`);
1927
2104
  return { outcome: "refused", hooks: "refused", mcp: "skipped", backup: null, mcpConfirmed: false };
1928
2105
  }
1929
- const again = mergeHooks(fresh.value, "", "unwire", spare);
2106
+ const replan = planSettings(fresh.value, "", "unwire", spare, keepDeny);
2107
+ const again = replan.hooks;
1930
2108
  // THE SAME RACE, THE OTHER WAY ROUND (review n3): the hooks went while the
1931
2109
  // question was up. Nothing to write, no backup, and the line says so.
1932
- if (!again.changed) {
2110
+ if (!replan.changed) {
1933
2111
  u.ok(`no Counterparts hooks were left in ${tilde(fresh.target, home)} when it was read again.`);
1934
2112
  }
1935
- const wrote = again.changed ? writeSettings(fresh, again.value, now) : { backup: null, error: null };
2113
+ const wrote = replan.changed ? writeSettings(fresh, replan.value, now) : { backup: null, error: null };
1936
2114
  backup = wrote.backup;
1937
2115
  if (wrote.error !== null) {
1938
2116
  io.err(`failed to write ${fresh.target}: ${wrote.error}`);
1939
2117
  io.err(backup === null ? "Nothing was changed." : `The backup taken first is at ${backup}.`);
1940
2118
  return { outcome: "failed", hooks: "refused", mcp: "skipped", backup, mcpConfirmed: false };
1941
2119
  }
2120
+ const backupSaid = backup === null ? "" : ` (backup: ${basename(backup)})`;
1942
2121
  if (again.changed) {
1943
2122
  hooksWord = "removed";
1944
2123
  // THE BACKUP IS NAMED HERE, IN FULL, and not on `connect`'s line — the
@@ -1948,7 +2127,16 @@ export async function unwire(input: WireInput): Promise<WireResult> {
1948
2127
  // copy.
1949
2128
  u.ok(
1950
2129
  `${String(again.events.length)} hook${again.events.length === 1 ? "" : "s"} removed from ` +
1951
- `${tilde(fresh.target, home)}${backup === null ? "" : ` (backup: ${basename(backup)})`}`,
2130
+ `${tilde(fresh.target, home)}${backupSaid}`,
2131
+ );
2132
+ }
2133
+ if (replan.deny.changed) {
2134
+ deny = replan.deny.change;
2135
+ // Only the deny entry was there (the hooks taken out by hand): the
2136
+ // backup is named on this line instead.
2137
+ u.hint(
2138
+ `Counterparts Online's entry, { "serverUrl": "${HOSTED_DENY_URL}" }, was taken out of ${DENY_KEY}` +
2139
+ `${again.changed ? "" : ` in ${tilde(fresh.target, home)}${backupSaid}`}.`,
1952
2140
  );
1953
2141
  }
1954
2142
  if (again.foreignKept > 0) {
@@ -1970,7 +2158,7 @@ export async function unwire(input: WireInput): Promise<WireResult> {
1970
2158
  if (why !== null) {
1971
2159
  leftMcpNote(u, mcp, why, home);
1972
2160
  u.hint("An open Claude Code session keeps working until you close it.");
1973
- return { outcome: "ok", hooks: hooksWord, mcp: "skipped", backup, mcpConfirmed: false, mcpLeft: why };
2161
+ return { outcome: "ok", hooks: hooksWord, mcp: "skipped", backup, mcpConfirmed: false, mcpLeft: why, deny };
1974
2162
  }
1975
2163
 
1976
2164
  // THE REMOVE IS ATTEMPTED WHETHER OR NOT OUR READ SAW A REGISTRATION.
@@ -2019,7 +2207,9 @@ export async function unwire(input: WireInput): Promise<WireResult> {
2019
2207
  u.warn(
2020
2208
  "`claude` is not on this PATH and this version does not read Claude Code's own configuration, so whether a memory server is still registered (an npm install's, if there is one) could not be checked.",
2021
2209
  );
2022
- u.hint(`Remove one if it is there: claude mcp remove ${MCP_SERVER_NAME} -s user — and run this again where \`claude\` is on PATH to have it checked.`);
2210
+ u.hint("Remove one if it is there:");
2211
+ u.command(`claude mcp remove ${MCP_SERVER_NAME} -s user`);
2212
+ u.hint("Then run this again where `claude` is on PATH to have it checked.");
2023
2213
  mcpWord = "printed";
2024
2214
  } else if (res.missing) {
2025
2215
  mcpConfirmed = !stillThere();
@@ -2028,7 +2218,8 @@ export async function unwire(input: WireInput): Promise<WireResult> {
2028
2218
  mcpWord = "absent";
2029
2219
  } else {
2030
2220
  u.warn("`claude` is not on this PATH, so the MCP server was not deregistered.");
2031
- u.hint(`Run it yourself: claude mcp remove ${MCP_SERVER_NAME} -s user`);
2221
+ u.hint("Run it yourself:");
2222
+ u.command(`claude mcp remove ${MCP_SERVER_NAME} -s user`);
2032
2223
  mcpWord = "printed";
2033
2224
  }
2034
2225
  } else if (res.code === 0) {
@@ -2045,11 +2236,14 @@ export async function unwire(input: WireInput): Promise<WireResult> {
2045
2236
  } else {
2046
2237
  mcpConfirmed = !stillThere();
2047
2238
  u.warn(`\`claude mcp remove\` exited ${String(res.code ?? -1)}.`);
2048
- if (!mcpConfirmed) u.hint(`Run it yourself: claude mcp remove ${MCP_SERVER_NAME} -s user`);
2239
+ if (!mcpConfirmed) {
2240
+ u.hint("Run it yourself:");
2241
+ u.command(`claude mcp remove ${MCP_SERVER_NAME} -s user`);
2242
+ }
2049
2243
  mcpWord = mcpConfirmed ? "absent" : "printed";
2050
2244
  }
2051
2245
 
2052
2246
  u.hint("An open Claude Code session keeps working until you close it.");
2053
- return { outcome: "ok", hooks: hooksWord, mcp: mcpWord, backup, mcpConfirmed };
2247
+ return { outcome: "ok", hooks: hooksWord, mcp: mcpWord, backup, mcpConfirmed, deny };
2054
2248
  }
2055
2249
 
@@ -390,6 +390,17 @@ export interface AdapterConfig {
390
390
  * an old setting.
391
391
  */
392
392
  readonly debug?: { readonly nightTranscripts?: boolean };
393
+ /**
394
+ * THE DAILY UPDATE CHECK (U1b, 2026-10-28): `"updateCheck": false` turns it
395
+ * off — no request to registry.npmjs.org, and no update line in any wake
396
+ * (`adapters/update-check.ts`). The durable switch /privacy names first,
397
+ * because it reaches every process that reads this file (the worker under
398
+ * Claude Code, Desktop's server, doctor in a terminal), where an environment
399
+ * variable does not. Read leniently: only `false` means off; any other value
400
+ * is ignored, never a reason to stand the configuration down.
401
+ * ("off", "no", "0" and 0 are read as false too.)
402
+ */
403
+ readonly updateCheck?: false;
393
404
  /**
394
405
  * SETTINGS THIS BUILD NO LONGER READS, phrased for a person — e.g.
395
406
  * `"credentialsFile" is no longer used …`. Present only when the file named
@@ -456,6 +467,7 @@ export function loadConfig(raw: unknown): LoadedConfig {
456
467
  dreaming?: { model?: string; timeoutMs?: number; maxTurns?: number; ignored?: string[] };
457
468
  retention?: { afterWriteUpDays?: number; maxDays?: number; ignored?: string[] };
458
469
  debug?: { nightTranscripts?: boolean };
470
+ updateCheck?: false;
459
471
  retired?: string[];
460
472
  timeZone?: string;
461
473
  timeZoneUnknown?: string;
@@ -639,6 +651,17 @@ export function loadConfig(raw: unknown): LoadedConfig {
639
651
  if (typeof debug === "object" && debug !== null && !Array.isArray(debug)) {
640
652
  out.debug = (debug as Record<string, unknown>)["nightTranscripts"] === true ? { nightTranscripts: true } : {};
641
653
  }
654
+ // THE UPDATE CHECK'S SWITCH (U1b): lenient. `false`, `0`, and the words
655
+ // `COUNTERPARTS_UPDATE_CHECK` takes ("off", "false", "0", "no", "disable",
656
+ // "disabled") all mean off; anything else is ignored, never refused.
657
+ const updateCheck = rec["updateCheck"];
658
+ if (
659
+ updateCheck === false ||
660
+ updateCheck === 0 ||
661
+ (typeof updateCheck === "string" && ["off", "false", "0", "no", "disable", "disabled"].includes(updateCheck.trim().toLowerCase()))
662
+ ) {
663
+ out.updateCheck = false;
664
+ }
642
665
  const identity = rec["identity"];
643
666
  if (identity !== undefined) {
644
667
  const i = identity as Record<string, unknown>;
@@ -23,6 +23,7 @@ import { terminalWantsColour } from "../ansi.js";
23
23
  import { DATA_DIR_ENV, dataDir, describeGuardRefusal, isStoreError } from "../../../core/store/index.js";
24
24
  import { upgradePending, upgradePendingSentence } from "../upgrade.js";
25
25
  import { BINARY } from "../../runtime.js";
26
+ import { usePrivateUmask } from "../../private-umask.js";
26
27
  import type { Binary } from "../../runtime.js";
27
28
  import type { StoreError } from "../../../core/store/index.js";
28
29
  import type { Band, Kind } from "../../../core/types.js";
@@ -479,6 +480,7 @@ export function isEntryPoint(argv1: string | undefined, url: string, binary: Bin
479
480
  /** Print a view, or `serve` the web page — what this file does as a script,
480
481
  * and what the single binary's `dashboard` mode calls. */
481
482
  export async function start(): Promise<void> {
483
+ usePrivateUmask();
482
484
  const argv = process.argv.slice(2);
483
485
  // Help first, and before `serve` too: `serve --help` would otherwise bind a
484
486
  // socket against the default store.
@@ -336,7 +336,7 @@ export const DURABLE_EVENTS = {
336
336
  "handoff.refused": "a handoff was turned away (past the hard limit, stopped by the gate battery, carrying the wake's own markers, written where no project was named, sent as something other than text, sent from a Claude Desktop call that named no session, retiring an id that is not a handoff here, or — with `no-room` — composed before the wake had room reserved for its pointer)",
337
337
  // Durable since 2026-10-01: it was a ring event, gone with the hook, and
338
338
  // the wake bar could not say a session start went without it.
339
- "handoff.lasthere.noroom": "a session start had no room for the \"Last here\" line naming the chapter last written in that project (the bundle's bytes, the ceiling, and whether a handoff was carried in its place)",
339
+ "handoff.lasthere.noroom": "a session start had no room for the \"Last here\" line naming the chapter last written in that project, or the later session that wrote none (the bundle's bytes, the ceiling, and whether a handoff was carried in its place)",
340
340
  // Durable since 2026-10-02: "Work here" had more lines than the wake carried.
341
341
  "self.work.overflow": "a session start had more \"Work here\" lines for its project than it carried — more than the wake shows, so they rotate, or fewer fitted the room (how many, how many shown)",
342
342
  "recall.credit": "a boundary decided which memories the replies actually used, and credited them",
@@ -35,6 +35,7 @@ import * as reconsolidationPanel from "./reconsolidation/panel.js";
35
35
  import * as interferencePanel from "./interference/panel.js";
36
36
  import * as retrievalPanel from "./retrieval/panel.js";
37
37
  import * as saliencePanel from "./salience/panel.js";
38
+ import * as schemaPanel from "./schema/panel.js";
38
39
 
39
40
  export const MECHANISMS = [salience, emotional, decay, interference, retrieval, association, prospective, consolidation, dreaming, reconsolidation, episodic_semantic, schema];
40
41
 
@@ -60,6 +61,7 @@ export const PANELS = {
60
61
  reconsolidation: reconsolidationPanel,
61
62
  interference: interferencePanel,
62
63
  "episodic-semantic": gistPanel,
64
+ schema: schemaPanel,
63
65
  };
64
66
 
65
67
  /**
@@ -1,6 +1,6 @@
1
1
  /* Schema & assimilation. `explainer` is what Counterparts actually does, checked against
2
- docs/research/mechanism-audit-2026-09-24.md; `built` / `inDevelopment` are the
3
- audit plus #215/#218/#220, in plain words; `tagline` is the
2
+ docs/research/mechanism-audit-2026-09-24.md and wave 2's beliefs (lane C, 0.3.31);
3
+ `built` / `inDevelopment` are in plain words; `tagline` is the
4
4
  site's (regions.ts). Its light comes from `/api/mechanisms`. */
5
5
  export default {
6
6
  id: "schema",
@@ -8,8 +8,11 @@ export default {
8
8
  name: "Schema & assimilation",
9
9
  short: "Schemas",
10
10
  tagline: "New facts don’t land on blank ground. They’re folded into what you already believe.",
11
- does: "Would fold new facts into what I already believe about people and projects. Not built yet.",
12
- explainer: "Not built yet. It keeps cards for the people and projects it knows, but does not form beliefs about them from many memories.",
13
- built: ["Cards for the people, projects and places it knows, which fade and come back with use."],
14
- inDevelopment: ["Beliefs about them, weighed against new evidence, have no live producer yet."],
11
+ does: "Forms beliefs about me, you, and the people and projects we know, and weighs new memories for or against them.",
12
+ explainer: "Built. At night the reflection forms beliefs about me, us, and the people and projects the day’s memories name, or adopts one a dream suggested; each starts weak, grows only as lived memories are filed for it, and is pressed to change by one filed against it.",
13
+ built: [
14
+ "Cards for the people, projects and places it knows, which fade and come back with use.",
15
+ "Beliefs born weak, earned by the memories filed for them, pressed by the ones against.",
16
+ ],
17
+ inDevelopment: ["Awake, a session forms beliefs only about me or us; the rest wait for the night."],
15
18
  };
@@ -0,0 +1,14 @@
1
+ /* Schemas, pictured (2026-10-26): the newest beliefs formed here, each with
2
+ how many lived memories back it and go against it. */
3
+ import { esc } from "../../shared/dom.js";
4
+ import { memLink, nothingYet } from "../picture.js";
5
+
6
+ const HOW = { reflection: "formed at night", session: "formed in a session", dream: "adopted from a dream", correction: "formed from a correction" };
7
+
8
+ export function picture(p) {
9
+ if (!p || p.beliefs.length === 0) return nothingYet("No belief has formed here yet. The night's reflection forms one when lived memories back it.");
10
+ return '<ul class="pic-list pic-rows">' + p.beliefs.map((b) =>
11
+ "<li>" + memLink(b, 90) + '<span class="pic-meta">' + esc(HOW[b.route] || "formed") + " on day " + esc(String(b.day)) +
12
+ " · " + esc(String(b.support)) + " for, " + esc(String(b.against)) + " against</span></li>"
13
+ ).join("") + "</ul>";
14
+ }