counterparts 0.3.11 → 0.3.13

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 (150) hide show
  1. package/CHANGELOG.md +326 -0
  2. package/docs/QUICKSTART.md +5 -0
  3. package/docs/README.md +2 -2
  4. package/docs/module-map.md +3 -3
  5. package/package.json +1 -1
  6. package/src/adapters/claude-code/CONTRACT.md +36 -10
  7. package/src/adapters/claude-code/INTERFACE-GAPS.md +116 -16
  8. package/src/adapters/claude-code/NOTES.md +182 -0
  9. package/src/adapters/claude-code/bin/hook.ts +46 -12
  10. package/src/adapters/claude-code/bin/runner.ts +7 -1
  11. package/src/adapters/claude-code/doctor.ts +632 -18
  12. package/src/adapters/claude-code/hooks.ts +61 -16
  13. package/src/adapters/claude-code/index.ts +11 -0
  14. package/src/adapters/claude-code/night-run.ts +150 -14
  15. package/src/adapters/claude-code/transcript.ts +268 -1
  16. package/src/adapters/cli/CONTRACT.md +5 -0
  17. package/src/adapters/cli/INTERFACE-GAPS.md +8 -4
  18. package/src/adapters/cli/NOTES.md +111 -0
  19. package/src/adapters/cli/commands.ts +134 -92
  20. package/src/adapters/cli/dream-core.ts +57 -42
  21. package/src/adapters/cli/export.ts +320 -21
  22. package/src/adapters/cli/help.ts +2 -1
  23. package/src/adapters/cli/index.ts +1 -0
  24. package/src/adapters/cli/install.ts +39 -7
  25. package/src/adapters/cli/mechanisms.ts +7 -1
  26. package/src/adapters/cli/uninstall.ts +13 -5
  27. package/src/adapters/cli/wire.ts +189 -63
  28. package/src/adapters/config.ts +2 -0
  29. package/src/adapters/dashboard/INTERFACE-GAPS.md +10 -1
  30. package/src/adapters/dashboard/NOTES.md +79 -0
  31. package/src/adapters/dashboard/registries.ts +34 -2
  32. package/src/adapters/dashboard/web/README.md +19 -14
  33. package/src/adapters/dashboard/web/actions.ts +23 -1
  34. package/src/adapters/dashboard/web/flow.ts +14 -0
  35. package/src/adapters/dashboard/web/lanes.ts +10 -0
  36. package/src/adapters/dashboard/web/narrate.ts +88 -2
  37. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -0
  38. package/src/adapters/dashboard/web/pages/health/sections/checks.js +2 -0
  39. package/src/adapters/dashboard/web/pages/health/sections/wake.js +3 -1
  40. package/src/adapters/dashboard/web/pages/memories/memories.css +17 -4
  41. package/src/adapters/dashboard/web/pages/memories/row.js +37 -21
  42. package/src/adapters/dashboard/web/pages/memories/sections/search.js +279 -60
  43. package/src/adapters/dashboard/web/pages/memories/state.js +2 -1
  44. package/src/adapters/dashboard/web/server.ts +0 -5
  45. package/src/adapters/dashboard/web/shared/memory-marks.css +7 -0
  46. package/src/adapters/dashboard/web/shared/memory-marks.js +33 -0
  47. package/src/adapters/dashboard/web/shared/memory-modal.js +5 -3
  48. package/src/adapters/dashboard/web/views/health.ts +21 -3
  49. package/src/adapters/dashboard/web/views/search.ts +4 -45
  50. package/src/adapters/dashboard/web/views.ts +2 -2
  51. package/src/adapters/fired.ts +430 -28
  52. package/src/adapters/host-wiring.ts +300 -0
  53. package/src/adapters/hosts.ts +11 -0
  54. package/src/adapters/lifecycle.ts +42 -2
  55. package/src/adapters/log/index.ts +9 -0
  56. package/src/adapters/mcp/CONTRACT.md +151 -11
  57. package/src/adapters/mcp/INTERFACE-GAPS.md +24 -2
  58. package/src/adapters/mcp/NOTES.md +313 -1
  59. package/src/adapters/mcp/bin/serve.ts +74 -1
  60. package/src/adapters/mcp/deliberate.ts +169 -651
  61. package/src/adapters/mcp/facts.ts +1094 -0
  62. package/src/adapters/mcp/index.ts +25 -7
  63. package/src/adapters/mcp/meaning.ts +1610 -0
  64. package/src/adapters/mcp/server.ts +835 -150
  65. package/src/adapters/mcp/stdio.ts +3 -1
  66. package/src/adapters/mcp/stood-down.ts +51 -0
  67. package/src/adapters/mcp/tools.ts +167 -41
  68. package/src/adapters/plugin-run.sh +133 -0
  69. package/src/adapters/plugin.ts +329 -0
  70. package/src/adapters/sessions.ts +18 -4
  71. package/src/core/associate/CONTRACT.md +2 -1
  72. package/src/core/associate/INTERFACE-GAPS.md +6 -1
  73. package/src/core/associate/NOTES.md +45 -0
  74. package/src/core/briefing.ts +12 -3
  75. package/src/core/contradictions.ts +184 -0
  76. package/src/core/counterpart.ts +797 -51
  77. package/src/core/dream/CONTRACT.md +36 -4
  78. package/src/core/dream/INTERFACE-GAPS.md +29 -6
  79. package/src/core/dream/NOTES.md +107 -0
  80. package/src/core/dream/feeling-weeks.ts +198 -0
  81. package/src/core/dream/index.ts +109 -18
  82. package/src/core/dream/reflect.ts +346 -87
  83. package/src/core/dream/tunables.ts +24 -4
  84. package/src/core/encode/INTERFACE-GAPS.md +3 -1
  85. package/src/core/encode/NOTES.md +7 -0
  86. package/src/core/encode/words.ts +45 -0
  87. package/src/core/fit/INTERFACE-GAPS.md +8 -2
  88. package/src/core/fit/NOTES.md +39 -1
  89. package/src/core/fit/index.ts +40 -0
  90. package/src/core/handoff/CONTRACT.md +37 -2
  91. package/src/core/handoff/INTERFACE-GAPS.md +10 -0
  92. package/src/core/handoff/NOTES.md +72 -0
  93. package/src/core/handoff/index.ts +214 -12
  94. package/src/core/handoff/last-here.ts +6 -4
  95. package/src/core/mint.ts +12 -2
  96. package/src/core/physics/CONTRACT.md +14 -2
  97. package/src/core/physics/NOTES.md +33 -1
  98. package/src/core/physics/index.ts +28 -5
  99. package/src/core/prospective/CONTRACT.md +45 -6
  100. package/src/core/prospective/INTERFACE-GAPS.md +4 -0
  101. package/src/core/prospective/NOTES.md +138 -0
  102. package/src/core/prospective/derive.ts +33 -5
  103. package/src/core/prospective/index.ts +90 -5
  104. package/src/core/prospective/windows.ts +72 -1
  105. package/src/core/recall/CONTRACT.md +31 -12
  106. package/src/core/recall/INTERFACE-GAPS.md +28 -4
  107. package/src/core/recall/NOTES.md +70 -1
  108. package/src/core/recall/feeling-ask.ts +10 -1
  109. package/src/core/recall/index.ts +3 -1
  110. package/src/core/recall/probe.ts +58 -0
  111. package/src/core/recall/session.ts +46 -2
  112. package/src/core/recall/time-ask.ts +487 -0
  113. package/src/core/remember/CONTRACT.md +4 -1
  114. package/src/core/remember/INTERFACE-GAPS.md +9 -1
  115. package/src/core/remember/NOTES.md +8 -0
  116. package/src/core/remember/proposals.ts +47 -5
  117. package/src/core/revision.ts +18 -1
  118. package/src/core/schemas/CONTRACT.md +21 -1
  119. package/src/core/schemas/INTERFACE-GAPS.md +20 -2
  120. package/src/core/schemas/NOTES.md +144 -0
  121. package/src/core/schemas/aliases.ts +55 -5
  122. package/src/core/schemas/index.ts +93 -1
  123. package/src/core/schemas/types.ts +2 -0
  124. package/src/core/self/CONTRACT.md +32 -5
  125. package/src/core/self/INTERFACE-GAPS.md +7 -2
  126. package/src/core/self/NOTES.md +102 -1
  127. package/src/core/self/behind.ts +43 -3
  128. package/src/core/self/briefing.ts +12 -2
  129. package/src/core/self/chapter-address.ts +254 -0
  130. package/src/core/self/episodes.ts +27 -0
  131. package/src/core/self/index.ts +83 -8
  132. package/src/core/self/page.ts +88 -0
  133. package/src/core/self/tunables.ts +5 -0
  134. package/src/core/self/work.ts +35 -2
  135. package/src/core/self/writer.ts +30 -0
  136. package/src/core/sleep/INTERFACE-GAPS.md +22 -3
  137. package/src/core/sleep/NOTES.md +20 -1
  138. package/src/core/sleep/consolidate.ts +59 -7
  139. package/src/core/sleep/index.ts +3 -0
  140. package/src/core/sleep/prune.ts +6 -2
  141. package/src/core/sleep/types.ts +7 -0
  142. package/src/core/store/CONTRACT.md +16 -0
  143. package/src/core/store/NOTES.md +66 -0
  144. package/src/core/store/feelings.ts +14 -1
  145. package/src/core/store/index.ts +483 -16
  146. package/src/core/store/operational.ts +95 -2
  147. package/src/core/store/owner-op-seam.ts +23 -0
  148. package/src/core/time.ts +152 -0
  149. package/tools/install-loop/run.sh +48 -12
  150. package/src/adapters/dashboard/web/pages/memories/fold.js +0 -53
@@ -77,7 +77,7 @@ import { SCOPES_FILE_NAME } from "../scopes.js";
77
77
  import { SNAPSHOTS_DIR_NAME, resolveSnapshotsDir } from "../snapshots.js";
78
78
  import type { AdapterConfig } from "../config.js";
79
79
  import type { Io } from "./commands.js";
80
- import { BIN, CONFIG_FILE, LEGACY_CREDENTIALS_FILE, MCP_SERVER_NAME } from "./install.js";
80
+ import { BIN, CONFIG_FILE, LEGACY_CREDENTIALS_FILE, MCP_SERVER_NAME, hostSettingsDir } from "./install.js";
81
81
  import {
82
82
  PARKED_INFIX,
83
83
  pairedSuffix,
@@ -479,6 +479,9 @@ export interface PlanInput {
479
479
  readonly home: string;
480
480
  /** "park" or "delete", for the refusals' wording. */
481
481
  readonly verb: string;
482
+ /** The process environment, for where the host keeps its own directory
483
+ * (`CLAUDE_CONFIG_DIR`, review of #337). Absent: `~/.claude` only. */
484
+ readonly env?: Record<string, string | undefined>;
482
485
  }
483
486
 
484
487
  /**
@@ -515,7 +518,7 @@ export function planUninstall(input: PlanInput): UninstallPlan {
515
518
  refusal: null,
516
519
  };
517
520
 
518
- const dirRefusal = configDirRefusal(configDir, configPath, input.home, input.verb);
521
+ const dirRefusal = configDirRefusal(configDir, configPath, input.home, input.verb, input.env);
519
522
  if (dirRefusal !== null) return { ...empty, refusal: dirRefusal };
520
523
 
521
524
  if (written !== undefined && written.trim().length > 0 && storeDir === null) {
@@ -649,13 +652,15 @@ function isDirectory(path: string): boolean {
649
652
  *
650
653
  * `start-fresh`'s ring, plus the four the blocker added: the host's own
651
654
  * `~/.claude`, the home directory, any PARENT of the home directory, and
652
- * anything holding a `.git`.
655
+ * anything holding a `.git`. The host's own directory is also wherever
656
+ * `CLAUDE_CONFIG_DIR` puts it, when `env` says so (review of #337).
653
657
  */
654
658
  export function configDirRefusal(
655
659
  configDir: string,
656
660
  configPath: string,
657
661
  home: string,
658
662
  verb: string,
663
+ env: Record<string, string | undefined> = {},
659
664
  ): string | null {
660
665
  // THE RAW SPELLING DECIDES THIS ONE. `resolve()` is relative to the process
661
666
  // working directory and always hands back an absolute path, so a test on the
@@ -700,7 +705,10 @@ export function configDirRefusal(
700
705
  // is a command somebody can type, and the first version of this file renamed
701
706
  // Claude Code's settings, project transcripts and todos away under a heading
702
707
  // that said "Your memory, parked".
703
- if (real === realpathDeep(join(home, ".claude"))) {
708
+ // `CLAUDE_CONFIG_DIR` MOVES IT (review of #337): the host keeps the same
709
+ // settings, transcripts and todos there instead, so a configuration inside
710
+ // `~/.claude-work` is the same mistake as one inside `~/.claude`.
711
+ if (real === realpathDeep(join(home, ".claude")) || real === realpathDeep(resolve(hostSettingsDir(home, env)))) {
704
712
  return (
705
713
  `refused: ${written} is Claude Code's own configuration directory. Whatever this ` +
706
714
  "install put there, the settings, the project transcripts and the todos beside it are " +
@@ -968,7 +976,7 @@ export async function uninstall(input: UninstallInput): Promise<Outcome> {
968
976
 
969
977
  let plan: UninstallPlan | null = null;
970
978
  if (moving) {
971
- plan = planUninstall({ configPath: input.configPath, config: input.config, home, verb });
979
+ plan = planUninstall({ configPath: input.configPath, config: input.config, home, verb, env });
972
980
  if (plan.refusal !== null) {
973
981
  io.err(plan.refusal);
974
982
  io.err("Nothing has changed.");
@@ -58,7 +58,8 @@
58
58
  * a Claude Code session that is already open. Measured 2026-09-21 — after
59
59
  * `settings.json` changes, an open session's hooks fire on its NEXT TURN, and
60
60
  * its MCP tools appear only after Claude Code is restarted. `sessionsNote` says
61
- * exactly that, and counts the memory servers still running when it cheaply can;
61
+ * exactly that, and counts the memory servers still running when it cheaply can
62
+ * — by the build each one's own record names, since 2026-10-09 (`serverCensus`);
62
63
  * since 2026-09-22 the CALLER prints it, because `install` ends with its own
63
64
  * "restart Claude Code, then run doctor" line and two of them on one screen is
64
65
  * the finding this round is about.
@@ -82,7 +83,11 @@ import { basename, dirname, isAbsolute, join, resolve } from "node:path";
82
83
 
83
84
  import { DATA_DIR_ENV, isWithin } from "../../core/store/index.js";
84
85
  import { CONFIG_ENV, CONFIG_FLAG } from "../config-path.js";
86
+ import { isOurHookCommand } from "../host-wiring.js";
87
+ import { claudeCodeEnvMarker } from "../hosts.js";
85
88
  import { parseScriptInvocation, scriptArgs, shellTokens } from "../runtime.js";
89
+ import { installedBuild, readServerRecords, sameBuild, serverBelieved } from "../sessions.js";
90
+ import type { BuildStamp, ServerRecordRead } from "../sessions.js";
86
91
  import type { Io } from "./commands.js";
87
92
  import {
88
93
  BIN,
@@ -93,6 +98,7 @@ import {
93
98
  hookCommand,
94
99
  hostConfigBase,
95
100
  hostMcpFile,
101
+ hostSettingsDir,
96
102
  mcpCommand,
97
103
  settingsBlock,
98
104
  } from "./install.js";
@@ -104,9 +110,11 @@ import type { Ui, UiEnv } from "./ui.js";
104
110
 
105
111
  /** The user-scope settings file: the ONE this command writes. Project files
106
112
  * (`.claude/settings.json` in a working directory) are read by `doctor` and
107
- * never written here — wiring one project is not what anybody asked for. */
113
+ * never written here — wiring one project is not what anybody asked for.
114
+ * `$CLAUDE_CONFIG_DIR/settings.json` when that is set (`hostSettingsDir`,
115
+ * 2026-10-09), never `$CLAUDE_CONFIG_DIR/.claude/settings.json`. */
108
116
  export function userSettingsPath(home: string, env: UiEnv): string {
109
- return join(hostConfigBase(home, env), ".claude", "settings.json");
117
+ return join(hostSettingsDir(home, env), "settings.json");
110
118
  }
111
119
 
112
120
  /** The infix a backup wears. Named, because the test and the output share it. */
@@ -588,51 +596,13 @@ export interface MergeResult {
588
596
  }
589
597
 
590
598
  /**
591
- * IS THIS COMMAND OURS TO REWRITE — which is a stricter question than "does it
592
- * mention us" (review m1).
593
- *
594
- * `HOOK_COMMAND_MARK` answers the reporting question `doctor` asks: is a hook
595
- * of ours installed on this event? It matches a COMPOSITE command, and it
596
- * should — a wrapper that ends in `counterparts-hook` really does run our hook,
597
- * and a doctor that said otherwise would be wrong.
598
- *
599
- * It is the wrong question for a WRITE. The review wrapped our hook two ways —
600
- * `~/bin/log-start.sh && counterparts-hook`, and `/opt/mytool/bin/wrap --then
601
- * counterparts-hook` — and `wire` overwrote the first with ours alone while
602
- * `unwire` deleted the second outright. Both are somebody's own line, and this
603
- * file's own promise is that nothing belonging to another tool is a candidate.
604
- *
605
- * So a command is ours to rewrite only when it IS our invocation and nothing
606
- * else: our runtime and our hook script, or the installed shim, optionally
607
- * followed by `--config <path>`. Anything with a shell operator in it is
608
- * refused outright, whatever else it looks like — a command this cannot parse
609
- * is a command this does not edit.
610
- *
611
- * `test/wire.test.ts` holds the two to each other in the direction that
612
- * matters: everything `wire` WRITES is matched by both, so a hook we installed
613
- * can never read as missing on the surface a person checks.
599
+ * IS THIS COMMAND OURS TO REWRITE — `host-wiring.ts#isOurHookCommand`, which
600
+ * is where the rule and its history now live (moved 2026-10-09 so the plugin's
601
+ * hook and MCP server can recognise the npm wiring without importing the
602
+ * console). Re-exported unchanged: this file and `doctor` still ask exactly the
603
+ * same question of exactly the same function.
614
604
  */
615
- export function isOurHookCommand(command: string): boolean {
616
- // A shell operator means the line does something besides run our hook.
617
- if (/&&|\|\||;|\||>|<|`|\$\(/.test(command)) return false;
618
- const tokens = shellTokens(command);
619
- if (tokens.length === 0) return false;
620
- const tail = (from: number): boolean => {
621
- const rest = tokens.slice(from);
622
- if (rest.length === 0) return true;
623
- return rest.length === 2 && rest[0] === CONFIG_FLAG && (rest[1] ?? "").length > 0;
624
- };
625
- const first = tokens[0] ?? "";
626
- // The installed shim, by itself.
627
- if (/(^|[/\\])counterparts-hook$/.test(first)) return tail(1);
628
- // `<runtime> run <our hook script>`, or Node's
629
- // `<runtime> --import <node-hooks.mjs> <our hook script>` (`runtime.ts`).
630
- const run = parseScriptInvocation(tokens);
631
- if (run !== null && /claude-code[/\\]bin[/\\]hook\.ts$/.test(run.script)) {
632
- return tail(tokens.length - run.rest.length);
633
- }
634
- return false;
635
- }
605
+ export { isOurHookCommand };
636
606
 
637
607
  /** Is this inner entry one this command may rewrite or remove? */
638
608
  function isOurs(entry: unknown): entry is Record<string, unknown> {
@@ -1004,6 +974,9 @@ export interface RunningProcess {
1004
974
  /** In the words the output uses: "an MCP server", "the worker", "a dashboard". */
1005
975
  readonly what: string;
1006
976
  readonly command: string;
977
+ /** Its parent, when the look saw it. For an MCP server that is the host
978
+ * process that started it — Claude Code, for one of its sessions. */
979
+ readonly ppid?: number;
1007
980
  }
1008
981
 
1009
982
  /**
@@ -1017,6 +990,13 @@ export interface RunningProcess {
1017
990
  export interface ProcessSighting {
1018
991
  readonly looked: boolean;
1019
992
  readonly processes: readonly RunningProcess[];
993
+ /**
994
+ * EVERY process's parent (pid → ppid), not only ours — the chain from this
995
+ * process up to the host it runs under is what tells `connect` which
996
+ * running server is the session it was typed into (`serverCensus`).
997
+ * Absent when the look could not say, and from a lister that does not.
998
+ */
999
+ readonly parents?: ReadonlyMap<number, number>;
1020
1000
  }
1021
1001
 
1022
1002
  export type ProcessLister = () => ProcessSighting;
@@ -1048,7 +1028,13 @@ export function processMark(command: string): string | null {
1048
1028
  }
1049
1029
 
1050
1030
  /**
1051
- * `ps -axo pid=,command=`, filtered here rather than by `pgrep -f`.
1031
+ * `ps -axwwo pid=,ppid=,command=`, filtered here rather than by `pgrep -f`. The
1032
+ * parent column (2026-10-09) is kept for every line, ours or not, so a caller
1033
+ * can walk from this process up to its host (`ProcessSighting.parents`).
1034
+ *
1035
+ * `ww` (review of #331): procps on Linux cuts `command` at `$COLUMNS` when that
1036
+ * is set, even into a pipe, and the cut can fall before the path segment
1037
+ * `processMark` needs. Unlimited width on both procps and macOS.
1052
1038
  *
1053
1039
  * **It never throws and it never fails the caller.** A machine with no `ps`, a
1054
1040
  * `ps` that times out, a sandbox that refuses process listing — every one of
@@ -1058,7 +1044,7 @@ export function processMark(command: string): string | null {
1058
1044
  export function realProcessLister(env: Record<string, string | undefined>): ProcessLister {
1059
1045
  return () => {
1060
1046
  try {
1061
- const res = spawnSync("ps", ["-axo", "pid=,command="], {
1047
+ const res = spawnSync("ps", ["-axwwo", "pid=,ppid=,command="], {
1062
1048
  encoding: "utf8",
1063
1049
  timeout: 4000,
1064
1050
  windowsHide: true,
@@ -1070,17 +1056,20 @@ export function realProcessLister(env: Record<string, string | undefined>): Proc
1070
1056
  if (res.error !== undefined && res.error !== null) return NO_LOOK;
1071
1057
  if (res.status !== 0) return NO_LOOK;
1072
1058
  const out: RunningProcess[] = [];
1059
+ const parents = new Map<number, number>();
1073
1060
  for (const line of String(res.stdout ?? "").split("\n")) {
1074
- const m = /^\s*(\d+)\s+(.*)$/.exec(line);
1061
+ const m = /^\s*(\d+)\s+(\d+)\s+(.*)$/.exec(line);
1075
1062
  if (m === null) continue;
1076
1063
  const pid = Number(m[1]);
1077
- const command = m[2] ?? "";
1064
+ const ppid = Number(m[2]);
1065
+ const command = m[3] ?? "";
1066
+ parents.set(pid, ppid);
1078
1067
  if (pid === process.pid) continue;
1079
1068
  const what = processMark(command);
1080
1069
  if (what === null) continue;
1081
- out.push({ pid, what, command });
1070
+ out.push({ pid, what, command, ppid });
1082
1071
  }
1083
- return { looked: true, processes: out };
1072
+ return { looked: true, processes: out, parents };
1084
1073
  } catch {
1085
1074
  return NO_LOOK;
1086
1075
  }
@@ -1100,11 +1089,6 @@ export function look(lister: ProcessLister): ProcessSighting {
1100
1089
  }
1101
1090
  }
1102
1091
 
1103
- /** Only the MCP servers, which is what "restart your sessions" is about. This
1104
- * one FAILS OPEN on purpose: it is a courtesy line, not a guard. */
1105
- export function runningServers(lister: ProcessLister): readonly RunningProcess[] {
1106
- return look(lister).processes.filter((p) => p.what === "an MCP server");
1107
- }
1108
1092
 
1109
1093
  // ── the command ─────────────────────────────────────────────────────────────
1110
1094
 
@@ -1461,17 +1445,159 @@ export function wrappedNote(
1461
1445
  * until Claude Code is restarted (a server keeps the code and the registration
1462
1446
  * it was launched with). Both halves are said, because a person who reads only
1463
1447
  * the first will wonder why `note` is missing.
1448
+ *
1449
+ * THE COUNT SAYS WHAT IT KNOWS (2026-10-09). It used to be every memory server
1450
+ * in the process table, called "the previous version's" — which nothing had
1451
+ * checked. The 0.3.12 release run printed "11 sessions are running the
1452
+ * previous version's memory server" over the owner's own open sessions, the
1453
+ * one it was typed into among them. Each server now goes where this store's
1454
+ * own records put it (`serverCensus`): another build than this install,
1455
+ * this build, or no record here at all — and the session the command was run
1456
+ * from is named in whichever it is in, when the process table can say which.
1464
1457
  */
1465
- export function sessionsNote(u: Ui, lister: ProcessLister): void {
1458
+ export function sessionsNote(
1459
+ u: Ui,
1460
+ lister: ProcessLister,
1461
+ opts: {
1462
+ /** The store the connected server is told to open — where servers leave their records. */
1463
+ readonly dataDir: string;
1464
+ readonly env?: Readonly<Record<string, string | undefined>>;
1465
+ readonly installed?: BuildStamp;
1466
+ readonly selfPid?: number;
1467
+ readonly now?: number;
1468
+ },
1469
+ ): void {
1466
1470
  u.hint("Hooks start with your next turn in any open Claude Code session.");
1467
1471
  u.hint("The memory tools appear after you restart Claude Code.");
1468
- const running = runningServers(lister);
1469
- if (running.length > 0) {
1472
+ // Only the MCP servers, which is what "restart your sessions" is about. This
1473
+ // FAILS OPEN on purpose: a look that did not happen says nothing, because
1474
+ // this is a courtesy line, not a guard.
1475
+ const sight = look(lister);
1476
+ const running = sight.processes.filter((p) => p.what === "an MCP server");
1477
+ if (running.length === 0) return;
1478
+ const installed = opts.installed ?? installedBuild();
1479
+ const census = serverCensus(running, {
1480
+ dataDir: opts.dataDir,
1481
+ installed,
1482
+ ...(sight.parents === undefined ? {} : { parents: sight.parents }),
1483
+ ...(opts.selfPid === undefined ? {} : { selfPid: opts.selfPid }),
1484
+ ...(opts.now === undefined ? {} : { now: opts.now }),
1485
+ });
1486
+ const here = "the session you ran this from";
1487
+ if (census.other > 0) {
1488
+ const n = census.other;
1489
+ u.hint(
1490
+ `(${String(n)} open session${n === 1 ? "" : "s"} still run${n === 1 ? "s" : ""} memory server ${census.otherVersions.join(" or ")}, ` +
1491
+ `not this install's ${installed.version ?? "build"}${census.mine === "other" ? ` — ${here} ${n === 1 ? "is that one" : "is one of them"}` : ""}: ` +
1492
+ `restart ${n === 1 ? "it, or run /mcp and Reconnect in it" : "them, or run /mcp and Reconnect in each"}.)`,
1493
+ );
1494
+ }
1495
+ if (census.current > 0) {
1496
+ const n = census.current;
1470
1497
  u.hint(
1471
- `(${String(running.length)} session${running.length === 1 ? " is" : "s are"} running the ` +
1472
- "previous version's memory server — restart them.)",
1498
+ `(${String(n)} open session${n === 1 ? "" : "s"} already run${n === 1 ? "s" : ""} this version` +
1499
+ `${census.mine === "current" ? `, ${here} included` : ""}.)`,
1473
1500
  );
1474
1501
  }
1502
+ if (census.unplaced > 0) {
1503
+ const n = census.unplaced;
1504
+ const more = census.other + census.current > 0 ? " more" : "";
1505
+ u.hint(
1506
+ `(${String(n)}${more} memory server${n === 1 ? " is" : "s are"} running that this store holds no current record of — ` +
1507
+ "another store's, one in a directory where memory is off, or a build from before servers recorded themselves — " +
1508
+ `so which version ${n === 1 ? "it runs" : "they run"} is not known here${census.mine === "unplaced" ? `; ${here} is ${n === 1 ? "that one" : "one of them"}` : ""}.)`,
1509
+ );
1510
+ }
1511
+ // HONEST WHEN IT CANNOT TELL. Run from inside Claude Code, that session's
1512
+ // own server is one of the ones counted; without the parent column the
1513
+ // count cannot say which, so it says that rather than guess.
1514
+ if (!census.knowsMine && claudeCodeEnvMarker(opts.env ?? {}) !== null) {
1515
+ u.hint("(This was run from inside a Claude Code session, so that session's own server is counted above; which one it is could not be told from here.)");
1516
+ }
1517
+ }
1518
+
1519
+ /** Where the running memory servers stand, by this store's own records. */
1520
+ export interface ServerCensus {
1521
+ /** Servers whose record here names another build than this install's. */
1522
+ readonly other: number;
1523
+ /** Those builds' versions, distinct, in the order first seen. */
1524
+ readonly otherVersions: readonly string[];
1525
+ /** Servers whose record here names this install's build. */
1526
+ readonly current: number;
1527
+ /** Running servers this store holds no believed record of. */
1528
+ readonly unplaced: number;
1529
+ /** Which of the three the server of the session this command runs in is in,
1530
+ * or null when none of them could be named as its. */
1531
+ readonly mine: "other" | "current" | "unplaced" | null;
1532
+ /** Whether the look gave parents, so `mine` is an answer and not a blank. */
1533
+ readonly knowsMine: boolean;
1534
+ }
1535
+
1536
+ /**
1537
+ * SORT THE RUNNING MEMORY SERVERS BY WHAT THIS STORE KNOWS OF THEM.
1538
+ *
1539
+ * Every server leaves `sessions/mcp-server@<pid>.json` in the store it opened
1540
+ * (`sessions.ts#recordServerLaunch`): its build, and its parent — the host
1541
+ * process that started it. A record is believed when its pid is one the
1542
+ * process table just listed AND its heartbeat is fresh (`serverBelieved`,
1543
+ * with the table as the liveness answer), so a pid the OS handed on is not
1544
+ * read as the server that left the file.
1545
+ *
1546
+ * THE SESSION THIS COMMAND RUNS IN is the one whose server's parent is one of
1547
+ * this process's own ancestors — run from Claude Code's shell, the chain goes
1548
+ * up through the shell to the very `claude` process that started that server.
1549
+ * Pid 1 is never an ancestor for this: an orphaned server is reparented to it,
1550
+ * and every process descends from it. Pure over its inputs; never throws.
1551
+ */
1552
+ export function serverCensus(
1553
+ running: readonly RunningProcess[],
1554
+ input: {
1555
+ readonly dataDir: string;
1556
+ readonly installed: BuildStamp;
1557
+ readonly parents?: ReadonlyMap<number, number>;
1558
+ readonly selfPid?: number;
1559
+ readonly now?: number;
1560
+ },
1561
+ ): ServerCensus {
1562
+ const listed = new Set(running.map((p) => p.pid));
1563
+ const now = input.now ?? Date.now();
1564
+ const records = new Map<number, ServerRecordRead>();
1565
+ for (const r of readServerRecords(input.dataDir)) {
1566
+ if (serverBelieved(r.pid, r.refreshedAt, now, (pid) => listed.has(pid))) records.set(r.pid, r);
1567
+ }
1568
+ const ancestors = new Set<number>();
1569
+ if (input.parents !== undefined) {
1570
+ let at = input.parents.get(input.selfPid ?? process.pid);
1571
+ while (at !== undefined && at > 1 && !ancestors.has(at)) {
1572
+ ancestors.add(at);
1573
+ at = input.parents.get(at);
1574
+ }
1575
+ }
1576
+ let other = 0;
1577
+ let current = 0;
1578
+ let unplaced = 0;
1579
+ const otherVersions: string[] = [];
1580
+ let mine: ServerCensus["mine"] = null;
1581
+ for (const p of running) {
1582
+ const r = records.get(p.pid);
1583
+ const bucket: NonNullable<ServerCensus["mine"]> =
1584
+ r === undefined ? "unplaced" : sameBuild(r.build, input.installed) ? "current" : "other";
1585
+ if (bucket === "unplaced") unplaced += 1;
1586
+ else if (bucket === "current") current += 1;
1587
+ else {
1588
+ other += 1;
1589
+ const v =
1590
+ r === undefined || r.build.version === null
1591
+ ? "of an unknown version"
1592
+ : r.build.version === input.installed.version
1593
+ ? `${r.build.version} (another build of it)`
1594
+ : r.build.version;
1595
+ if (!otherVersions.includes(v)) otherVersions.push(v);
1596
+ }
1597
+ const ppid = p.ppid ?? input.parents?.get(p.pid);
1598
+ if (mine === null && ((ppid !== undefined && ancestors.has(ppid)) || (r !== undefined && ancestors.has(r.hostPid)))) mine = bucket;
1599
+ }
1600
+ return { other, otherVersions, current, unplaced, mine, knowsMine: input.parents !== undefined };
1475
1601
  }
1476
1602
 
1477
1603
  /**
@@ -150,6 +150,8 @@ export const TUNABLES = {
150
150
  * a tool result that this package has measured; this is the size the
151
151
  * write-up door already hands over in one part (`WRITE_UP_PART_BYTES`, ~24
152
152
  * KB), so a wake plus a pointer is never the first thing to find the real one.
153
+ * (2026-10-02: the real one is measured now — `fit/TOOL_RESULT_CEILING`,
154
+ * 40,000 under Claude Code's 50,000 — and this sits under it by choice.)
153
155
  */
154
156
  TOOL_RESULT_CHARS: 24_000,
155
157
  /**
@@ -67,6 +67,10 @@ reachable through `eventLog({ sinceDay })`. That is the likely fix and it is a v
67
67
  decision, not a core one — but events are bounded-retention telemetry and the meta
68
68
  records are not, so the two are not interchangeable for an old cycle.
69
69
 
70
+ *(Noted 2026-10-09: the store has a prefix read now, `Store#metaWithPrefix(prefix)`
71
+ (#95, 2026-09-14). Nothing in the dashboard calls it yet, and `status` still reports
72
+ since birth, so the view's half is open.)*
73
+
70
74
  **Owner:** `store/` (the surface), `sleep/` (the records).
71
75
 
72
76
  ---
@@ -155,7 +159,12 @@ small by construction. Negligible today; wrong at a hundred names.
155
159
  **Owner:** `store/`.
156
160
 
157
161
 
158
- ## §6 — Returns are kept by moment, the lights' window by lived day (2026-09-26)
162
+ ## §6 — Returns are kept by moment, the lights' window by lived day (2026-09-26) — CLOSED 2026-09-26 (noted 2026-10-09)
163
+
164
+ **Closed in the same PR, #251** (`197e1ca`): `Store#returnCounts` takes
165
+ `{ sinceAt?, sinceDay? }`, and the mechanism lights ask it by lived day
166
+ (`web/views/mechanisms.ts`, `mechanism-panel.ts`, `adapters/mechanism-evidence.ts`). The
167
+ text below is the gap as filed.
159
168
 
160
169
  **Have:** `store.returnCounts(sinceAt)` counts the `returns` table from a UTC
161
170
  moment; the mechanism window is seven LIVED days. A light that wants "returns in
@@ -547,3 +547,82 @@ From Fable's review of Health (2026-09-28) and the open follow-ups of #277:
547
547
  - **Counts** (329 vs 322 vs 296) were already labelled by 09-28/09-30 work:
548
548
  Health's line says it leaves out the people and project cards, and the
549
549
  memories grid says its journal chapters aren't scored.
550
+
551
+ ## 2026-10-09 — Ask reads the answers 0.3.12 gives
552
+
553
+ 0.3.12 gave recall a required mode (#323) and the console's `ask --json` started
554
+ printing a `FactsResult`. The Memories page's Ask kept reading the answer it was
555
+ built for: a confidence `tier` (gone with the tiers), a `from` chapter link (folded
556
+ into the answer by facts mode itself, so `/api/chapters` answered `{}`), a date
557
+ written at the front of the body (facts carries `occurredOn` / `learned`), and
558
+ `journal: false` written in by the page. So the match words, the links and most
559
+ dates vanished without an error, and "by meaning" was answered in facts mode — the
560
+ console had no other. Every test of it passed: they fed the page answers written by
561
+ hand, in the old shape.
562
+
563
+ - **Three ways to find.** The switch is "by word | facts | by meaning". By word is
564
+ unchanged; facts and by meaning ask on Enter with `act("ask", {json, mode, page})`,
565
+ which is `counterparts ask --json --mode meaning` for meaning — a flag the console
566
+ did not have (`--mode`, facts by default, as the MCP tool's `mode`). A third
567
+ position, rather than turning "by meaning" into facts or Enter-in-by-word into an
568
+ ask, because the 09-30 switch was the owner's (M3) and adding to it reverses
569
+ nothing; whether three is right is his to say.
570
+ - **Facts, as the answer says it.** The head counts every match (`matched`), the
571
+ pager pages it (`page`, `pages`, ten a page), and the notes say what it was about,
572
+ the time it named, words only, and what was left out. A row's date is when it
573
+ happened, else when it was learned (the hover says which); under the words, only
574
+ what the answer carries: who said it, its status, when it was learned, which
575
+ chapter, "earlier: …" with a link to the earlier memory, corrected ones counted,
576
+ "disagrees with" as a link. A journal answer's heading is taken off the front of
577
+ its words, display only.
578
+ - **Meaning, as an arc.** The head names the subject and counts its chapters and
579
+ moments; each chapter is a row titled by its day that opens its journal, with its
580
+ line, its marks (start, latest, a turn), whose feelings side by side, and its
581
+ moments as links; a session's moments with no chapter are a row that opens
582
+ nothing. Then faded moments, earlier readings, what is still open, what recurs.
583
+ `--voiced` finally decides something: the dashboard asks in my voice, so "mine"
584
+ in a meaning answer is mine.
585
+ - **Dropped, not invented:** the match-strength word, `fold.js`, and `/api/chapters`
586
+ with `views/search.ts#chapterLinks` — their only reader was the fold.
587
+ - **The drawing is pure and fed real answers.** `factsHead`, `factsRows`,
588
+ `meaningHead`, `meaningRows` and `askPager` in `sections/search.js` take the
589
+ parsed answer; `test/dashboard-ask-answers.test.ts` gets every answer it draws
590
+ through `runAction("ask", …)` on a seeded temp store and reads each field it
591
+ checks off the typed `FactsResult` / `MeaningResult`, so a renamed field breaks
592
+ the build there before it can vanish from the page again.
593
+ - **An id in a memory's words is a link** (`memory-marks.js#idMark`): "(mem_…)"
594
+ shows as "memory ↗" and opens it, "epi_…#2" as "journal chapter 2 ↗", the id on
595
+ hover. Inside something already clickable (a moment's title) it is drawn the same
596
+ but not linked. The memory card's own body still prints ids as written.
597
+ - **Review of #333: in meaning mode the owner's "I" becomes "you", not his name.**
598
+ The voice rewrite turned "what has Ilya been to me" into "… to Rosalind", and
599
+ meaning takes the card with the most memories as its subject: the owner's own
600
+ card, usually the biggest, won, and the person asked about went under "also
601
+ named". The answer tests ran the action with no owner name, as the server never
602
+ does. Facts still gets his name, where words are what match.
603
+ (2026-10-09: meaning now takes the card the question is about, and in my voice
604
+ "you" asked about is the owner's card, so "what have I been like" finds his card
605
+ again with no change here; see mcp NOTES of that day.)
606
+
607
+ ## 2026-10-09 — the card's "Written" day is local
608
+
609
+ The memory card's "Written …" line took the UTC date of `createdAt`
610
+ (`shared/memory-modal.js#writtenOn`), so in Denver a memory written in the
611
+ evening said the next day, beside a "recorded" chip that said the right one.
612
+ It now reads `shared/dates.js#localIso`, the browser's calendar, as the Health
613
+ cycle line already did. The "written" row under the card's details still prints
614
+ its UTC minute and says "UTC", so it was left alone.
615
+
616
+ The browser's zone is the dashboard's zone for now (review of #335):
617
+ `Dashboard.open` passes no `timeZone`, so the server views (`mind.ts`,
618
+ `traits.ts`, `activity.ts`) also read the machine's zone, which is the browser's
619
+ on a local dashboard. The hooks do read the config's `timeZone`, so with one set
620
+ that differs from the machine's, `learnedOn` ("recorded") follows the config while
621
+ everything the dashboard dates itself follows the machine. If the dashboard learns
622
+ the config's zone (`cli/commands.ts#zoneBeside`), this day and the Health cycle
623
+ line should come from the server too.
624
+
625
+ How it got through: `test/time.test.ts` scans `src/` for hand-built dates, but
626
+ only `.ts` files, so the browser modules here are not scanned at all. Widening
627
+ the scan to `.js` would also catch `dates.js` and `cycle.js`, which build dates
628
+ on purpose, so it needs its own allow-list decisions; left as a follow-up.
@@ -52,6 +52,13 @@ import {
52
52
  SNAPSHOT_ROTATED_EVENT,
53
53
  SNAPSHOT_TAKEN_EVENT,
54
54
  MCP_RECALL_EVENT,
55
+ MCP_PART_EVENT,
56
+ MCP_OVERSIZE_EVENT,
57
+ MCP_SPILLED_EVENT,
58
+ ENVELOPE_GAVE_WAY_EVENT,
59
+ ENVELOPE_OVERCAP_EVENT,
60
+ INJECTION_OVERBUDGET_EVENT,
61
+ NOTICE_DROPPED_EVENT,
55
62
  SPAWN_FAILED_EVENT,
56
63
  SPAWN_REFUSED_EVENT,
57
64
  SPAWN_STARTED_EVENT,
@@ -80,6 +87,7 @@ import {
80
87
  SELF_PAGE_REFUSED_EVENT,
81
88
  SELF_PAGE_REVISED_EVENT,
82
89
  SELF_PAGE_WRITER_EVENT,
90
+ WORK_OVERFLOW_EVENT,
83
91
  } from "../../core/self/index.js";
84
92
  // The per-directory handoff's four, from `handoff/` itself (2026-09-20, E1):
85
93
  // working context for a place is not a memory, so its rows are its own.
@@ -107,9 +115,11 @@ import {
107
115
  DREAM_UNDONE_EVENT,
108
116
  } from "../../core/dream/index.js";
109
117
  import { V8_CENSUS_EVENT } from "../../core/sleep/index.js";
110
- // Contradictions (2026-09-29, `core/contradictions.ts`): a flag, a settle, an undo.
118
+ // Contradictions (2026-09-29, `core/contradictions.ts`): a flag, a settle, an
119
+ // undo — and a write's `updates` held as unrelated (2026-10-09).
111
120
  import {
112
121
  CONTRADICTION_FLAGGED_EVENT,
122
+ CONTRADICTION_HELD_EVENT,
113
123
  CONTRADICTION_SETTLED_EVENT,
114
124
  CONTRADICTION_UNDONE_EVENT,
115
125
  } from "../../core/contradictions.js";
@@ -197,6 +207,14 @@ export type DurableEventName =
197
207
  | typeof WRITE_UP_FAILED_EVENT
198
208
  | typeof CAPTURE_FAILED_EVENT
199
209
  | typeof MCP_RECALL_EVENT
210
+ | typeof MCP_PART_EVENT
211
+ | typeof MCP_OVERSIZE_EVENT
212
+ | typeof MCP_SPILLED_EVENT
213
+ | typeof ENVELOPE_OVERCAP_EVENT
214
+ | typeof NOTICE_DROPPED_EVENT
215
+ | typeof ENVELOPE_GAVE_WAY_EVENT
216
+ | typeof INJECTION_OVERBUDGET_EVENT
217
+ | typeof WORK_OVERFLOW_EVENT
200
218
  | typeof CHECKOUT_EVENT
201
219
  | typeof SNAPSHOT_TAKEN_EVENT
202
220
  | typeof SNAPSHOT_FAILED_EVENT
@@ -221,6 +239,7 @@ export type DurableEventName =
221
239
  | typeof CONTRADICTION_FLAGGED_EVENT
222
240
  | typeof CONTRADICTION_SETTLED_EVENT
223
241
  | typeof CONTRADICTION_UNDONE_EVENT
242
+ | typeof CONTRADICTION_HELD_EVENT
224
243
  | typeof COVERAGE_OWED_EVENT
225
244
  | typeof COVERAGE_WRITTEN_EVENT
226
245
  | typeof COVERAGE_LAPSED_EVENT;
@@ -250,6 +269,15 @@ export const DURABLE_EVENTS = {
250
269
  // surface wrote nothing, so a session that asked and got nothing and a session
251
270
  // that never asked were the same silence.
252
271
  "mcp.recall": "the session went looking for a memory on purpose (what kind of ask, how much came back, and every verdict that kept something out)",
272
+ "mcp.part": "a later part of a dream's or a reflection's bundle was handed over (which part of how many, and its size)",
273
+ "mcp.result.oversize": "a tool result came to more than the host shows in one answer, and was cut to fit with a note saying so",
274
+ "mcp.result.spilled": "the host showed one of the nightly run's tool results only as a short preview, so the run read part of it (found in the run's own transcript)",
275
+ // What a delivery could not carry (durable since 2026-10-02; ring-only
276
+ // before, so a dropped notice or a hook past the host's cap left nothing).
277
+ "adapter.envelope.overcap": "a hook's output was past the host's 10,000-character cap even in plain form, so the host showed only a preview of it",
278
+ "adapter.notice.dropped": "the owner's notice was dropped from a session start so the rest of the envelope stayed under the host's cap",
279
+ "adapter.envelope.gave-way": "a part of a delivery waited for want of room — the write-up pointer, the scope question, the turn's recall, a reminder, the dream offer or the update notice (which hook, which part)",
280
+ "adapter.injection.overbudget": "a session start sent more than the ceiling the host reported (what it sent, and the ceiling)",
253
281
  // Which CODE was live at a session start (2026-09-14): the hooks run whatever
254
282
  // the install tree has checked out, so a peer session's unmerged branch in
255
283
  // that tree is the memory layer the owner is using.
@@ -258,7 +286,7 @@ export const DURABLE_EVENTS = {
258
286
  "adapter.primacy.deliver": "a hook delivered while the parallel run was on",
259
287
  "adapter.primacy.standdown": "a hook withheld delivery so the other system could speak",
260
288
  "adapter.recall": "a turn's recall was composed for injection (counts and bytes)",
261
- "adapter.wake.delivered": "the previous wake's arrival was checked on the next turn",
289
+ "adapter.wake.delivered": "the wake's arrival was checked, at the first prompt or the first Stop",
262
290
  "adapter.wake.injected": "a wake bundle was handed to the host (bytes, never text)",
263
291
  "band.promoted": "a memory crossed into the identity band",
264
292
  "band.transition": "a memory changed bands (the symmetry counter's food)",
@@ -299,6 +327,8 @@ export const DURABLE_EVENTS = {
299
327
  // Durable since 2026-10-01: it was a ring event, gone with the hook, and
300
328
  // the wake bar could not say a session start went without it.
301
329
  "handoff.lasthere.noroom": "a session start had no room for the \"Last here\" line naming the chapter last written in that directory (the bundle's bytes, the ceiling, and whether a handoff was carried in its place)",
330
+ // Durable since 2026-10-02: "Work here" had more lines than the wake carried.
331
+ "self.work.overflow": "a session start had more \"Work here\" lines for its directory than it carried — more than the wake shows, so they rotate, or fewer fitted the room (how many, how many shown)",
302
332
  "recall.credit": "a boundary decided which memories the replies actually used, and credited them",
303
333
  // Learned association had no line in the log at all: an edge is its own
304
334
  // record, so a flush that never happened read exactly like a credit pass with
@@ -342,6 +372,8 @@ export const DURABLE_EVENTS = {
342
372
  "contradiction.flagged": "two memories that disagree were flagged as a pair, unsettled (by a dream, today)",
343
373
  "contradiction.settled": "a pair of memories that disagree was settled — changed, corrected or open — and by whom (a session, a dream, a reflection, the page writer or the owner)",
344
374
  "contradiction.undone": "a settle was undone: strength put back, a corrected memory back in recall, the pair unsettled again",
375
+ // The update guard (2026-10-09). Ids, the reading and its numbers; no text.
376
+ "contradiction.held": "a new memory said it changed or corrected one that looked unrelated to it, so the old one was left as it was and the two were not linked (the writer was shown it and asked to settle it if it meant to)",
345
377
  // What is not written up (2026-09-30). Ids and counts only; one row per stretch per state.
346
378
  "coverage.owed": "a session left a stretch that is not written up — three pieces or more over a quarter of an hour — and is no longer at work, so it owes a write-up (how many pieces, over how long)",
347
379
  "coverage.written": "a stretch of a session was written up (how many pieces, and by whom: the session itself, a \"nothing new\", a chapter, or the next session)",