counterparts 0.3.13 → 0.3.15

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 (106) hide show
  1. package/CHANGELOG.md +264 -0
  2. package/docs/QUICKSTART.md +22 -0
  3. package/docs/README.md +1 -0
  4. package/package.json +1 -1
  5. package/src/adapters/claude-code/CONTRACT.md +48 -0
  6. package/src/adapters/claude-code/NOTES.md +148 -0
  7. package/src/adapters/claude-code/bin/hook.mjs +4 -2
  8. package/src/adapters/claude-code/bin/hook.ts +61 -7
  9. package/src/adapters/claude-code/bin/nightly.ts +5 -1
  10. package/src/adapters/claude-code/bin/runner.ts +11 -3
  11. package/src/adapters/claude-code/claim.ts +319 -0
  12. package/src/adapters/claude-code/doctor.ts +170 -16
  13. package/src/adapters/claude-code/embed-client.ts +3 -0
  14. package/src/adapters/cli/CONTRACT.md +5 -0
  15. package/src/adapters/cli/NOTES.md +25 -0
  16. package/src/adapters/cli/bin/counterparts.mjs +4 -2
  17. package/src/adapters/cli/bin/counterparts.ts +49 -3
  18. package/src/adapters/cli/commands.ts +169 -32
  19. package/src/adapters/cli/desktop.ts +112 -7
  20. package/src/adapters/cli/help.ts +10 -0
  21. package/src/adapters/cli/index.ts +1 -0
  22. package/src/adapters/cli/install.ts +94 -14
  23. package/src/adapters/cli/self-page.ts +5 -8
  24. package/src/adapters/cli/settle.ts +39 -2
  25. package/src/adapters/cli/wire.ts +18 -1
  26. package/src/adapters/config.ts +29 -1
  27. package/src/adapters/dashboard/NOTES.md +33 -0
  28. package/src/adapters/dashboard/bin/dashboard.mjs +4 -2
  29. package/src/adapters/dashboard/bin/dashboard.ts +11 -3
  30. package/src/adapters/dashboard/index.ts +14 -0
  31. package/src/adapters/dashboard/registries.ts +3 -0
  32. package/src/adapters/dashboard/source.ts +0 -8
  33. package/src/adapters/dashboard/web/fired.ts +8 -0
  34. package/src/adapters/dashboard/web/flow.ts +1 -0
  35. package/src/adapters/dashboard/web/lanes.ts +1 -0
  36. package/src/adapters/dashboard/web/narrate.ts +11 -0
  37. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -1
  38. package/src/adapters/dashboard/web/pages/health/sections/cycle.js +7 -10
  39. package/src/adapters/dashboard/web/pages/memories/memories.css +3 -0
  40. package/src/adapters/dashboard/web/pages/memories/row.js +5 -2
  41. package/src/adapters/dashboard/web/pages/memories/sections/hold.js +2 -1
  42. package/src/adapters/dashboard/web/pages/memories/sections/search.js +19 -3
  43. package/src/adapters/dashboard/web/server.ts +16 -4
  44. package/src/adapters/dashboard/web/shared/dates.js +6 -16
  45. package/src/adapters/dashboard/web/shared/memory-modal.js +21 -8
  46. package/src/adapters/dashboard/web/views/health.ts +19 -5
  47. package/src/adapters/dashboard/web/views/mechanism-panel.ts +8 -5
  48. package/src/adapters/dashboard/web/views/memories.ts +26 -7
  49. package/src/adapters/dashboard/web/views/memory-words.ts +16 -0
  50. package/src/adapters/dashboard/web/views/memory.ts +51 -2
  51. package/src/adapters/dashboard/web/views/mind.ts +38 -6
  52. package/src/adapters/empty-bunfig.toml +5 -0
  53. package/src/adapters/fired.ts +16 -2
  54. package/src/adapters/host-wiring.ts +112 -17
  55. package/src/adapters/log/index.ts +2 -2
  56. package/src/adapters/mcp/CONTRACT.md +17 -2
  57. package/src/adapters/mcp/INTERFACE-GAPS.md +15 -1
  58. package/src/adapters/mcp/NOTES.md +269 -0
  59. package/src/adapters/mcp/bin/serve.mjs +4 -2
  60. package/src/adapters/mcp/bin/serve.ts +17 -6
  61. package/src/adapters/mcp/facts.ts +72 -4
  62. package/src/adapters/mcp/meaning.ts +218 -15
  63. package/src/adapters/mcp/server.ts +21 -6
  64. package/src/adapters/mcp/tools.ts +86 -61
  65. package/src/adapters/plugin-run.sh +413 -34
  66. package/src/adapters/plugin.ts +141 -17
  67. package/src/adapters/runtime.ts +192 -17
  68. package/src/adapters/sessions.ts +2 -2
  69. package/src/core/associate/NOTES.md +10 -0
  70. package/src/core/bridge.ts +1 -1
  71. package/src/core/briefing.ts +20 -3
  72. package/src/core/contradictions.ts +56 -20
  73. package/src/core/counterpart.ts +72 -23
  74. package/src/core/dream/CONTRACT.md +6 -14
  75. package/src/core/dream/INTERFACE-GAPS.md +3 -2
  76. package/src/core/dream/NOTES.md +10 -0
  77. package/src/core/dream/index.ts +11 -53
  78. package/src/core/dream/reflect.ts +11 -2
  79. package/src/core/embed/static.ts +5 -1
  80. package/src/core/encode/INTERFACE-GAPS.md +2 -1
  81. package/src/core/encode/NOTES.md +12 -0
  82. package/src/core/encode/chunk.ts +6 -30
  83. package/src/core/encode/index.ts +0 -1
  84. package/src/core/encode/types.ts +1 -13
  85. package/src/core/handoff/INTERFACE-GAPS.md +1 -1
  86. package/src/core/handoff/index.ts +2 -1
  87. package/src/core/handoff/last-here.ts +18 -2
  88. package/src/core/physics/CONTRACT.md +6 -0
  89. package/src/core/physics/NOTES.md +33 -2
  90. package/src/core/physics/index.ts +22 -7
  91. package/src/core/prospective/CONTRACT.md +3 -1
  92. package/src/core/prospective/NOTES.md +15 -0
  93. package/src/core/recall/activate.ts +1 -1
  94. package/src/core/recall/time-ask.ts +173 -19
  95. package/src/core/self/CONTRACT.md +56 -19
  96. package/src/core/self/NOTES.md +172 -0
  97. package/src/core/self/behind.ts +6 -3
  98. package/src/core/self/briefing.ts +384 -28
  99. package/src/core/self/index.ts +105 -44
  100. package/src/core/self/page.ts +12 -85
  101. package/src/core/self/tunables.ts +16 -19
  102. package/src/core/self/writer.ts +31 -4
  103. package/src/core/sleep/NOTES.md +32 -0
  104. package/src/core/store/NOTES.md +21 -2
  105. package/src/core/store/index.ts +2 -1
  106. package/src/core/time.ts +15 -0
@@ -58,9 +58,9 @@ export const DEFAULT_STORE_DIR = "store";
58
58
  import { EMBEDDER_KINDS } from "../config.js";
59
59
  import type { EmbedderKind } from "../config.js";
60
60
  import { CONFIG_ENV, CONFIG_FLAG, defaultConfigPath } from "../config-path.js";
61
- import { parseScriptInvocation, runtimePresent, scriptArgs, shellTokens } from "../runtime.js";
61
+ import { parseScriptInvocation, runtimeOf, runtimePresent, scriptArgs, shellTokens } from "../runtime.js";
62
62
  import type { RuntimeKind } from "../runtime.js";
63
- import { pluginInstall } from "../host-wiring.js";
63
+ import { pluginInstall, readOurHook } from "../host-wiring.js";
64
64
  import type { PluginInstallRead } from "../host-wiring.js";
65
65
  // `preRowsMarkersIn` reads FILENAMES and opens nothing, which is the only
66
66
  // reason a module that promises never to open a parked store may call it —
@@ -120,10 +120,12 @@ export function shellQuote(path: string): string {
120
120
  }
121
121
 
122
122
  /**
123
- * `<runtime> run <script>` under Bun, `<runtime> --import <node-hooks.mjs>
124
- * <script>` under Node (`adapters/runtime.ts`) — the shape both printed host
125
- * commands take. A path is quoted and a bare flag is not, so the Bun shape is
126
- * exactly the one written since 2026-09-03.
123
+ * `<runtime> --no-env-file "--config=<empty-bunfig.toml>" run <script>` under
124
+ * Bun, `<runtime> --import <node-hooks.mjs> <script>` under Node
125
+ * (`adapters/runtime.ts`) — the shape both printed host commands take. A path
126
+ * (or a flag carrying one) is quoted and a bare flag is not. Until 2026-10-09
127
+ * the Bun shape was `<runtime> run <script>`; those commands still read as
128
+ * ours, so `connect` repairs them in place.
127
129
  */
128
130
  export function runCommand(script: string, exe: string = process.execPath): string {
129
131
  const words = scriptArgs(script, exe).map((a) => (/^[A-Za-z-]+$/.test(a) ? a : shellQuote(a)));
@@ -582,13 +584,55 @@ export interface HostRead {
582
584
  readonly plugin: PluginInstallRead | null;
583
585
  }
584
586
 
587
+ /** Which of our host entries a runtime row came from: Claude Code's hooks, its
588
+ * MCP registration, or Claude Desktop's `counterparts` server entry. */
589
+ export type HostUse = "hooks" | "mcp" | "desktop";
590
+
591
+ /**
592
+ * Where Claude Desktop keeps its MCP servers, under a home directory (macOS).
593
+ * Here rather than in `desktop.ts` (which re-exports it) because `readHost`
594
+ * reads Desktop's entry too, and `desktop.ts` imports this file.
595
+ */
596
+ export function desktopConfigPath(home: string): string {
597
+ return join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json");
598
+ }
599
+
600
+ /**
601
+ * Is a `counterparts` entry in Desktop's file one this package wrote? Its
602
+ * command must read back as ours (`runtime.ts#parseScriptInvocation`) and run
603
+ * the memory server — a hand-made entry under the same name is somebody's
604
+ * own, and `connect` leaves it alone (`desktop.ts#repairDesktop`), so doctor's
605
+ * Runtime line does not grade it either (`readHost`): an amber whose fix,
606
+ * `connect`, never touches the entry would never clear.
607
+ *
608
+ * NOTHING AFTER THE SCRIPT (review of #354). `desktop.ts#desktopEntry` never
609
+ * writes a tail — the configuration travels in `env` — so an entry with
610
+ * arguments after `serve.ts` (or after the binary's `mcp`) is somebody's edit
611
+ * of ours, and the rewrite, which replaces `args` whole, would drop them
612
+ * without a word. The line `host-wiring.ts#isOurHookCommand` holds for hooks.
613
+ */
614
+ export function isOurDesktopEntry(entry: unknown): entry is { command: string; args: string[] } & Record<string, unknown> {
615
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return false;
616
+ const command = (entry as Record<string, unknown>)["command"];
617
+ const args = (entry as Record<string, unknown>)["args"];
618
+ if (typeof command !== "string" || !Array.isArray(args) || !args.every((a) => typeof a === "string")) return false;
619
+ const run = parseScriptInvocation([command, ...(args as string[])]);
620
+ if (run === null || run.rest.length > 0) return false;
621
+ return run.mode === "mcp" || (run.mode === undefined && /mcp[/\\]bin[/\\]serve\.ts$/.test(run.script));
622
+ }
623
+
585
624
  /** One runtime a host's configuration launches us with. */
586
625
  export interface HostRuntime {
587
626
  readonly exe: string;
588
- readonly kind: RuntimeKind;
627
+ /** `binary`: the single compiled binary, its own runtime. */
628
+ readonly kind: RuntimeKind | "binary";
589
629
  readonly present: boolean;
590
630
  /** `hooks`, `mcp`, or both. */
591
- readonly used: readonly ("hooks" | "mcp")[];
631
+ readonly used: readonly HostUse[];
632
+ /** Of `used`, the ones whose command lets Bun read the project's `.env` or
633
+ * `bunfig.toml` — wired before `--no-env-file` and an empty `--config=`
634
+ * (`runtime.ts#BUN_NO_ENV_FILE`, `#EMPTY_BUNFIG`). */
635
+ readonly projectEnv: readonly HostUse[];
592
636
  }
593
637
 
594
638
  /**
@@ -599,10 +643,14 @@ export interface HostRuntime {
599
643
  * version matched any command merely *mentioning* the name, so `echo
600
644
  * counterparts-hook` read as an installed hook. It still cannot resolve an
601
645
  * arbitrary shell command — that is out of scope, and deliberately so — but it
602
- * no longer matches prose.
646
+ * no longer matches prose. The third shape is the single binary's own
647
+ * (`"<…>/counterparts" hook`, `runtime.ts#parseScriptInvocation`). It matches
648
+ * the entry's `.mjs` shim as well as `hook.ts` (2026-10-09, with
649
+ * `host-wiring.ts#readOurHook`): a line that runs our hook is ours to report,
650
+ * whatever flags or entry file a later version writes.
603
651
  */
604
652
  export const HOOK_COMMAND_MARK =
605
- /(^|[\s"'=/\\])counterparts-hook(\s|$|")|claude-code[/\\]bin[/\\]hook\.ts/;
653
+ /(^|[\s"'=/\\])counterparts-hook(\s|$|")|claude-code[/\\]bin[/\\]hook\.(ts|mjs)|[/\\]counterparts(\.exe)?"?\s+hook(\s|$)/;
606
654
 
607
655
  /**
608
656
  * The absolute path a hook command runs, when it names one — the first token
@@ -613,6 +661,9 @@ export const HOOK_COMMAND_MARK =
613
661
  * anything else rather than guessing. A null is never reported as stale.
614
662
  */
615
663
  export function hookTargetPath(command: string): string | null {
664
+ // The single binary is its own script: `"<binary>" hook` needs the binary.
665
+ const run = parseScriptInvocation(shellTokens(command));
666
+ if (run?.runtime === "binary") return run.exe;
616
667
  const tokens = command.trim().split(/\s+/);
617
668
  for (const raw of tokens) {
618
669
  const token = raw.replace(/^["']|["']$/g, "");
@@ -718,14 +769,32 @@ export function readHost(
718
769
  const settingsUnreadable: string[] = [];
719
770
  // WHICH RUNTIME the host launches us with — read off the same commands, never
720
771
  // spawned: `bun run <script>` or `node --import <node-hooks.mjs> <script>`.
721
- const runtimes = new Map<string, { kind: RuntimeKind; used: Set<"hooks" | "mcp"> }>();
722
- const noteRuntime = (tokens: readonly string[], used: "hooks" | "mcp"): void => {
772
+ const runtimes = new Map<string, { kind: RuntimeKind | "binary"; used: Set<HostUse>; projectEnv: Set<HostUse> }>();
773
+ const noteRuntime = (tokens: readonly string[], used: HostUse): void => {
723
774
  const run = parseScriptInvocation(tokens);
724
775
  if (run === null) return;
725
- const row = runtimes.get(run.exe) ?? { kind: run.runtime, used: new Set<"hooks" | "mcp">() };
776
+ const row = runtimes.get(run.exe) ?? { kind: run.runtime, used: new Set<HostUse>(), projectEnv: new Set<HostUse>() };
726
777
  row.used.add(used);
778
+ if (run.projectEnv === "read") row.projectEnv.add(used);
727
779
  runtimes.set(run.exe, row);
728
780
  };
781
+ // A HOOK LINE IS READ BY ITS SCRIPT when the strict parser does not know its
782
+ // flags (`host-wiring.ts#readOurHook`): a line a later `connect` wrote keeps
783
+ // its Runtime row instead of vanishing from it. The shim names no runtime.
784
+ const noteHookRuntime = (command: string): void => {
785
+ const tokens = shellTokens(command);
786
+ if (parseScriptInvocation(tokens) !== null) return noteRuntime(tokens, "hooks");
787
+ const ours = readOurHook(command);
788
+ if (ours === null || ours.shape === "shim") return;
789
+ const row = runtimes.get(ours.exe) ?? {
790
+ kind: ours.shape === "binary" ? "binary" : runtimeOf(ours.exe),
791
+ used: new Set<HostUse>(),
792
+ projectEnv: new Set<HostUse>(),
793
+ };
794
+ row.used.add("hooks");
795
+ if (ours.projectEnv === "read") row.projectEnv.add("hooks");
796
+ runtimes.set(ours.exe, row);
797
+ };
729
798
  for (const path of hostSettingsFiles(hostSettingsDir(home, env), cwd)) {
730
799
  const read = readJsonFile(path);
731
800
  if (read.state === "unreadable") settingsUnreadable.push(path);
@@ -744,7 +813,7 @@ export function readHost(
744
813
  const command = (h as Record<string, unknown>)["command"];
745
814
  if (typeof command !== "string" || !HOOK_COMMAND_MARK.test(command)) continue;
746
815
  events.add(event);
747
- noteRuntime(shellTokens(command), "hooks");
816
+ noteHookRuntime(command);
748
817
  // A BLOCK THAT NAMES A PATH THAT IS NOT THERE fails at every session
749
818
  // start, silently. One event can carry several entries, so a live one
750
819
  // anywhere wins and a stale one is only reported when nothing on that
@@ -774,6 +843,16 @@ export function readHost(
774
843
  }
775
844
  }
776
845
  }
846
+ // CLAUDE DESKTOP'S ENTRY (`install --host claude-desktop`, 2026-10-10): the
847
+ // third command we write into a host's configuration, read the same way, so
848
+ // the Runtime line says when Desktop's server still lets Bun read a
849
+ // project's `.env` (`connect` rewrites it too, while Desktop is closed).
850
+ // Only an entry `connect` would rewrite (`isOurDesktopEntry`, review of #354).
851
+ const desktopServers = readJsonFile(desktopConfigPath(home)).value["mcpServers"];
852
+ if (desktopServers !== null && typeof desktopServers === "object" && !Array.isArray(desktopServers)) {
853
+ const entry = (desktopServers as Record<string, unknown>)[MCP_SERVER_NAME];
854
+ if (isOurDesktopEntry(entry)) noteRuntime([entry.command, ...entry.args], "desktop");
855
+ }
777
856
  return {
778
857
  expected: [...HOST_EVENTS],
779
858
  events: [...events].sort(),
@@ -792,6 +871,7 @@ export function readHost(
792
871
  kind: row.kind,
793
872
  present: runtimePresent(exe, env),
794
873
  used: [...row.used].sort(),
874
+ projectEnv: [...row.projectEnv].sort(),
795
875
  })),
796
876
  plugin: pluginInstall({ home, env, cwd }),
797
877
  };
@@ -131,10 +131,12 @@ export interface WrittenLines {
131
131
  readonly ok: boolean;
132
132
  }
133
133
 
134
- /** What the console says about a write, accepted or not. */
134
+ /** What the console says about a write, accepted or not. `limit` is the
135
+ * page's write limit in bytes (`PAGE_MAX_BYTES`), named in a refusal so the
136
+ * owner knows how much shorter to make it. */
135
137
  export function writeLines(
136
138
  written: ReturnType<Counterpart["revisePage"]>,
137
- wakeCap: number,
139
+ limit: number,
138
140
  ): WrittenLines {
139
141
  if (!written.written) {
140
142
  switch (written.reason) {
@@ -146,7 +148,7 @@ export function writeLines(
146
148
  case "too-large":
147
149
  return {
148
150
  lines: [
149
- `refused: the page is ${written.bytes} bytes, past the hard limit. Refused rather than cut — what gets cut at write time is the only copy.`,
151
+ `refused: the page is ${written.bytes} bytes, past the ${limit}-byte limit — the most the wake prints whole. Refused rather than cut — what gets cut at write time is the only copy. Say it in ${written.bytes - limit} fewer bytes and write it again.`,
150
152
  ],
151
153
  ok: false,
152
154
  };
@@ -217,11 +219,6 @@ export function writeLines(
217
219
  : [
218
220
  `NOTE: the gate redacted the page before storing it (${written.redacted.gate}) — ${written.redacted.bytesBefore} bytes in, ${written.bytes} out. Read it back before you rely on it: counterparts self-page.`,
219
221
  ]),
220
- ...(written.warning === null
221
- ? []
222
- : [
223
- `warning: past the wake's ${wakeCap}-byte cap, so the wake will show a cut of it with a marker. The page itself is kept whole.`,
224
- ]),
225
222
  // The write marks the wake behind (2026-09-30, `self/behind.ts`), and
226
223
  // the worker the next turn's end starts re-renders it. With no session
227
224
  // running, `rebrief` is the lever.
@@ -1,14 +1,18 @@
1
1
  /**
2
2
  * `counterparts settle` — the owner's door to contradictions (2026-09-29).
3
3
  *
4
- * With no flags it lists what is unsettled and what was settled lately (who,
5
- * how, why); with `--pair`/`--holds`/`--over`/`--how` it settles one, as the
4
+ * With no flags it lists what is unsettled, what was settled lately (who,
5
+ * how, why), and the week's held corrections nobody has settled since
6
+ * (2026-10-09); with `--pair`/`--holds`/`--over`/`--how` it settles one, as the
6
7
  * owner; `--undo <pair>` reverses a settle. Every decision is
7
8
  * `core/contradictions.ts`'s — this file only reads and prints. Reading works
8
9
  * under observer; the two changes refuse there.
9
10
  */
11
+ import { heldPairs } from "../../core/contradictions.js";
12
+ import type { HeldPair } from "../../core/contradictions.js";
10
13
  import type { Counterpart } from "../../core/counterpart.js";
11
14
  import type { ContradictionRow, SettleRow } from "../../core/store/index.js";
15
+ import { CONTRADICTION_WINDOW_DAYS } from "../claude-code/doctor.js";
12
16
  import { memoryWords } from "./dream-core.js";
13
17
 
14
18
  /** How many settled pairs the list shows. */
@@ -32,6 +36,38 @@ export function settleLine(counterpart: Counterpart, pair: ContradictionRow): st
32
36
  return `${pair.id} ${pair.how ?? "settled"}: ${pair.holds ?? "?"} holds over ${pair.over ?? "?"}${by}`;
33
37
  }
34
38
 
39
+ /**
40
+ * HELD CORRECTIONS (2026-10-09): the writes of the last
41
+ * `CONTRADICTION_WINDOW_DAYS` lived days — doctor's Contradictions line
42
+ * counts the same ones — that said they changed or corrected a memory that
43
+ * looked unrelated, so nothing was settled, and that nobody has settled by
44
+ * hand since. No pair was written for them, so each is settled by its two ids.
45
+ * Empty when there are none.
46
+ */
47
+ export function heldListLines(counterpart: Counterpart): string[] {
48
+ const store = counterpart.store;
49
+ let held: HeldPair[];
50
+ try {
51
+ held = heldPairs(store, { sinceDay: store.livedDay() - CONTRADICTION_WINDOW_DAYS + 1 }).filter((h) => !h.settledAfter);
52
+ } catch {
53
+ return [];
54
+ }
55
+ if (held.length === 0) return [];
56
+ const out = [
57
+ "",
58
+ `Held (${String(held.length)}, last ${String(CONTRADICTION_WINDOW_DAYS)} lived days): ${held.length === 1 ? "a correction" : "corrections"} that named a memory that didn't look related, so nothing was settled. Most are a wrong pointer and need nothing; settle one that was meant.`,
59
+ ];
60
+ for (const h of held.slice(0, SETTLE_LIST_RECENT)) {
61
+ const how = h.how === "changed" || h.how === "corrected" ? h.how : "corrected";
62
+ out.push(` ${h.holds} said it ${how === "changed" ? "changes" : "corrects"} ${h.over} (lived day ${String(h.day)})`);
63
+ out.push(` newer: "${memoryWords(counterpart, h.holds)}"`);
64
+ out.push(` older: "${memoryWords(counterpart, h.over)}"`);
65
+ out.push(` if meant: counterparts settle --holds ${h.holds} --against ${h.over} --how ${how} --why "..."`);
66
+ }
67
+ if (held.length > SETTLE_LIST_RECENT) out.push(` (+${String(held.length - SETTLE_LIST_RECENT)} older)`);
68
+ return out;
69
+ }
70
+
35
71
  /** What `counterparts settle` prints with no flags. */
36
72
  export function settleListLines(counterpart: Counterpart): string[] {
37
73
  const store = counterpart.store;
@@ -54,6 +90,7 @@ export function settleListLines(counterpart: Counterpart): string[] {
54
90
  out.push("", `Settled lately (${String(settled.length)}):`);
55
91
  for (const p of settled) out.push(` ${settleLine(counterpart, p)}`);
56
92
  }
93
+ out.push(...heldListLines(counterpart));
57
94
  out.push(
58
95
  "",
59
96
  "Settle one: counterparts settle --pair <id> --holds <memory id> --how changed|corrected|open --why \"...\"",
@@ -997,8 +997,19 @@ export interface ProcessSighting {
997
997
  * Absent when the look could not say, and from a lister that does not.
998
998
  */
999
999
  readonly parents?: ReadonlyMap<number, number>;
1000
+ /**
1001
+ * Whether Claude Desktop itself is running (its app's main process, not a
1002
+ * server of ours) — `connect` will not rewrite Desktop's config file under
1003
+ * it, because Desktop rewrites that file while it runs. Absent when the
1004
+ * look could not say, and from a lister that does not.
1005
+ */
1006
+ readonly desktopRunning?: boolean;
1000
1007
  }
1001
1008
 
1009
+ /** Claude Desktop's main process on macOS: the app's own executable, not its
1010
+ * "Claude Helper" processes and not a path that merely mentions the app. */
1011
+ export const DESKTOP_APP_PROCESS = /(^|\/)Claude\.app\/Contents\/MacOS\/Claude(\s|$)/;
1012
+
1002
1013
  export type ProcessLister = () => ProcessSighting;
1003
1014
 
1004
1015
  /**
@@ -1016,6 +1027,10 @@ const PROCESS_MARKS: readonly { readonly re: RegExp; readonly what: string }[] =
1016
1027
  { re: /claude-code[/\\]bin[/\\]runner\.ts/, what: "the worker" },
1017
1028
  { re: /dashboard[/\\]bin[/\\]dashboard\.(ts|mjs)/, what: "a dashboard" },
1018
1029
  { re: /(^|[\s"'/\\])counterparts-dashboard(\s|$|")/, what: "a dashboard" },
1030
+ // The single binary (`runtime.ts#BINARY_MODES`): `…/counterparts mcp`.
1031
+ { re: /(^|[/\\])counterparts(\.exe)?"?\s+mcp(\s|$)/, what: "an MCP server" },
1032
+ { re: /(^|[/\\])counterparts(\.exe)?"?\s+runner(\s|$)/, what: "the worker" },
1033
+ { re: /(^|[/\\])counterparts(\.exe)?"?\s+dashboard(\s|$)/, what: "a dashboard" },
1019
1034
  ];
1020
1035
 
1021
1036
  /** Which of ours, if any, this command line is. Exported for the test, which
@@ -1057,6 +1072,7 @@ export function realProcessLister(env: Record<string, string | undefined>): Proc
1057
1072
  if (res.status !== 0) return NO_LOOK;
1058
1073
  const out: RunningProcess[] = [];
1059
1074
  const parents = new Map<number, number>();
1075
+ let desktopRunning = false;
1060
1076
  for (const line of String(res.stdout ?? "").split("\n")) {
1061
1077
  const m = /^\s*(\d+)\s+(\d+)\s+(.*)$/.exec(line);
1062
1078
  if (m === null) continue;
@@ -1064,12 +1080,13 @@ export function realProcessLister(env: Record<string, string | undefined>): Proc
1064
1080
  const ppid = Number(m[2]);
1065
1081
  const command = m[3] ?? "";
1066
1082
  parents.set(pid, ppid);
1083
+ if (DESKTOP_APP_PROCESS.test(command)) desktopRunning = true;
1067
1084
  if (pid === process.pid) continue;
1068
1085
  const what = processMark(command);
1069
1086
  if (what === null) continue;
1070
1087
  out.push({ pid, what, command, ppid });
1071
1088
  }
1072
- return { looked: true, processes: out, parents };
1089
+ return { looked: true, processes: out, parents, desktopRunning };
1073
1090
  } catch {
1074
1091
  return NO_LOOK;
1075
1092
  }
@@ -23,7 +23,8 @@
23
23
  * And one from observer-mode G5: an unreadable configuration resolves to
24
24
  * OBSERVER, never to "encode anyway". `loadConfig` never throws.
25
25
  */
26
- import { isAbsolute } from "node:path";
26
+ import { existsSync, readFileSync } from "node:fs";
27
+ import { isAbsolute, join } from "node:path";
27
28
 
28
29
  import { isZone } from "../core/time.js";
29
30
 
@@ -847,3 +848,30 @@ export function withEmbedderDefault(config: AdapterConfig): AdapterConfig {
847
848
  const { block, source } = resolveEmbedder(config);
848
849
  return source === "explicit" || block === undefined ? config : { ...config, embedder: block };
849
850
  }
851
+
852
+ /**
853
+ * `timeZone` from the host configuration at `path` (docs/time.md, 2026-09-25):
854
+ * the zone the hooks and the MCP server date the person's days in. Absent,
855
+ * unreadable or unset: undefined, and the caller follows the machine's zone.
856
+ * Never throws — a reader that cannot find the zone shows the machine's day,
857
+ * which is what doctor's line names when they differ.
858
+ */
859
+ export function zoneOfConfig(path: string): string | undefined {
860
+ if (!existsSync(path)) return undefined;
861
+ try {
862
+ return loadConfig(JSON.parse(readFileSync(path, "utf8"))).config.timeZone;
863
+ } catch {
864
+ return undefined;
865
+ }
866
+ }
867
+
868
+ /**
869
+ * `timeZone` from the host configuration BESIDE a store (`<dir>/../claude-code.json`,
870
+ * the file `install` writes), for a reader handed only the store's directory —
871
+ * the console's commands and the dashboard (moved here from `cli/commands.ts`
872
+ * on 2026-10-09, so the dashboard reads the zone the hooks use without
873
+ * importing the console).
874
+ */
875
+ export function zoneBeside(dir: string): string | undefined {
876
+ return zoneOfConfig(join(dir, "..", "claude-code.json"));
877
+ }
@@ -626,3 +626,36 @@ How it got through: `test/time.test.ts` scans `src/` for hand-built dates, but
626
626
  only `.ts` files, so the browser modules here are not scanned at all. Widening
627
627
  the scan to `.js` would also catch `dates.js` and `cycle.js`, which build dates
628
628
  on purpose, so it needs its own allow-list decisions; left as a follow-up.
629
+
630
+ ## 2026-10-09 (later) — the dashboard reads the configured zone
631
+
632
+ Done, the same day. `Dashboard.open` takes a `timeZone`, and with none given it
633
+ reads the configuration beside a named `dir` (`config.ts#zoneBeside`, moved there
634
+ from `cli/commands.ts` so the dashboard need not import the console);
635
+ `startDashboard` reads the named configuration's first (`zoneOfConfig`). The store
636
+ then opens in that zone, so every server view that dates through `store.zone()`
637
+ follows it with no change of its own.
638
+
639
+ The browser no longer turns a moment into a day. `/api/memory` carries `writtenOn`
640
+ and `writtenClock` (`views/memory.ts#writtenWhen`; the clock is `core/time.ts#localClockZone`,
641
+ "11:47 MDT"), `/api/health`'s cycle carries `on` and `today`, `/api/fired` carries
642
+ its `zone` for the footer (which still said "(UTC)" after the reading went local).
643
+ `dates.js` lost `localIso` and `stampWords`. What the browser still reads off its
644
+ own clock: `dateWords` leaving out "this year" (wrong only in the hours a New Year
645
+ falls on one side of the zones and not the other), and the Health checklist's
646
+ "checked 14:05", the moment the browser ran doctor. Both are left as they are.
647
+ One edge left too: the page's `ask` runs the console, which dates in the zone beside the
648
+ store (`cli/commands.ts#openCounterpart`), not a named configuration kept somewhere else.
649
+ On an install the configuration is beside the store, and the two agree.
650
+ Test: `test/dashboard-zone.test.ts`, on a store configured to a zone 20 hours or
651
+ more from the machine's.
652
+
653
+ ## 2026-10-09 (later) — Ask names corrected versions
654
+
655
+ A facts answer now names its corrected versions (`FactItem.correctedShown`; the mcp
656
+ NOTES of this day), and `search.js#factLines` draws them under the words as it draws an
657
+ earlier one: `corrected (was wrong): “…”`, when it was learned and when corrected, and
658
+ its id as a link that opens it; `+N more corrected (was wrong)` for the rest. "N
659
+ corrected versions hidden" stays only for an answer that names none (one a non-owner
660
+ may not be told of). "Ask reads the answers 0.3.12 gives" above says "corrected ones
661
+ counted": that was the answer then. Test: `test/dashboard-ask-answers.test.ts`.
@@ -1,7 +1,9 @@
1
1
  #!/bin/sh
2
- ':' //; if command -v bun >/dev/null 2>&1; then exec bun "$0" "$@"; elif command -v node >/dev/null 2>&1; then exec node "$0" "$@"; else echo "counterparts: needs Bun 1.3+ or Node 22.15+ on PATH" >&2; exit 127; fi
2
+ ':' //; s="$0"; n=0; while [ -h "$s" ] && [ $n -lt 32 ]; do n=$((n+1)); l="$(readlink "$s")"; case "$l" in /*) s="$l" ;; *) s="${s%/*}/$l" ;; esac; done; c="${s%/*}/../../empty-bunfig.toml"; [ -f "$c" ] || c=/dev/null; if command -v bun >/dev/null 2>&1; then exec bun --no-env-file "--config=$c" "$0" "$@"; elif command -v node >/dev/null 2>&1; then exec node "$0" "$@"; else echo "counterparts: needs Bun 1.3+ or Node 22.15+ on PATH" >&2; exit 127; fi
3
3
  // A shell script and an ES module at once: the line above is a no-op string to
4
- // JavaScript and, to sh, the runtime choice (Bun if it is on PATH, else Node).
4
+ // JavaScript and, to sh, the runtime choice (Bun if it is on PATH, else Node;
5
+ // Bun with --no-env-file and --config=<empty-bunfig.toml>, found through any
6
+ // bin symlink, so a project's .env and bunfig.toml stay out: adapters/runtime.ts).
5
7
  // See `adapters/launch.mjs`.
6
8
  import { launch } from "../../launch.mjs";
7
9
 
@@ -22,6 +22,8 @@ import type { ViewArgs, ViewName } from "../index.js";
22
22
  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
+ import { BINARY } from "../../runtime.js";
26
+ import type { Binary } from "../../runtime.js";
25
27
  import type { StoreError } from "../../../core/store/index.js";
26
28
  import type { Band, Kind } from "../../../core/types.js";
27
29
 
@@ -467,12 +469,16 @@ export function run(argv: readonly string[]): string {
467
469
  /** True only when this file is the process entry point — so a test may import
468
470
  * `run` and `parseArgv` without the script printing itself (the same guard
469
471
  * `adapters/claude-code/bin/` uses). */
470
- export function isEntryPoint(argv1: string | undefined, url: string): boolean {
471
- if (argv1 === undefined) return false;
472
+ export function isEntryPoint(argv1: string | undefined, url: string, binary: Binary | null = BINARY): boolean {
473
+ // Never in the single binary, where every module shares one URL: its
474
+ // dispatcher (tools/single-binary/main.ts) calls `start()` itself.
475
+ if (argv1 === undefined || binary !== null) return false;
472
476
  return resolve(argv1) === fileURLToPath(new URL(url));
473
477
  }
474
478
 
475
- if (isEntryPoint(process.argv[1], import.meta.url)) {
479
+ /** Print a view, or `serve` the web page — what this file does as a script,
480
+ * and what the single binary's `dashboard` mode calls. */
481
+ export async function start(): Promise<void> {
476
482
  const argv = process.argv.slice(2);
477
483
  // Help first, and before `serve` too: `serve --help` would otherwise bind a
478
484
  // socket against the default store.
@@ -498,3 +504,5 @@ if (isEntryPoint(process.argv[1], import.meta.url)) {
498
504
  process.exit(0);
499
505
  }
500
506
  }
507
+
508
+ if (isEntryPoint(process.argv[1], import.meta.url)) await start();
@@ -42,6 +42,7 @@
42
42
  * functions knows it: they return strings.
43
43
  */
44
44
  import { Counterpart } from "../../core/counterpart.js";
45
+ import { zoneBeside } from "../config.js";
45
46
  import { PLAIN, style as makeStyle } from "./ansi.js";
46
47
  import type { Style } from "./ansi.js";
47
48
  import { DEFAULT_WIDTH } from "./layout.js";
@@ -104,6 +105,15 @@ export interface DashboardOptions {
104
105
  /** Escapes off unless asked. Views are byte-stable without one. */
105
106
  readonly colour?: boolean;
106
107
  readonly width?: number;
108
+ /**
109
+ * The person's zone, an IANA name: the host configuration's `timeZone`, the
110
+ * one the hooks and the MCP server date days in (docs/time.md). Left out,
111
+ * the configuration beside `dir` is read for it (`config.ts#zoneBeside`);
112
+ * none there, the machine's zone. Every date a view prints is read in it
113
+ * (`store.zone()`), so one page never shows two days for one moment
114
+ * (review of #335, 2026-10-09).
115
+ */
116
+ readonly timeZone?: string;
107
117
  }
108
118
 
109
119
  export class Dashboard {
@@ -113,8 +123,12 @@ export class Dashboard {
113
123
  readonly width: number;
114
124
 
115
125
  private constructor(opts: DashboardOptions) {
126
+ // Read beside a NAMED dir only: resolving the default here would be a
127
+ // second place that can refuse before the store's own refusal says why.
128
+ const timeZone = opts.timeZone ?? (opts.dir === undefined ? undefined : zoneBeside(opts.dir));
116
129
  this.counterpart = Counterpart.open({
117
130
  ...(opts.dir === undefined ? {} : { dir: opts.dir }),
131
+ ...(timeZone === undefined ? {} : { timeZone }),
118
132
  // NOT spread from the caller, and NOT defaulted: set here, unconditionally.
119
133
  observer: true,
120
134
  });
@@ -45,6 +45,7 @@ import {
45
45
  RECALL_DECISION_EVENT,
46
46
  RECALL_DELIVERED_EVENT,
47
47
  RUNNER_FAILED_EVENT,
48
+ HOOK_CLAIM_LOST_EVENT,
48
49
  SELF_BRIEFING_EVENT,
49
50
  SEMANTIC_LAG_EVENT,
50
51
  SLEEP_CYCLE_EVENT,
@@ -204,6 +205,7 @@ export type DurableEventName =
204
205
  | typeof SPAWN_FAILED_EVENT
205
206
  | typeof SPAWN_STARTED_EVENT
206
207
  | typeof RUNNER_FAILED_EVENT
208
+ | typeof HOOK_CLAIM_LOST_EVENT
207
209
  | typeof WRITE_UP_FAILED_EVENT
208
210
  | typeof CAPTURE_FAILED_EVENT
209
211
  | typeof MCP_RECALL_EVENT
@@ -258,6 +260,7 @@ export const DURABLE_EVENTS = {
258
260
  // worker was refused at every boundary and the only record was a ring that
259
261
  // died with the hook process. One row per reason per date.
260
262
  "adapter.runner.failed": "the detached worker failed after opening the store (which step, and the code)",
263
+ "adapter.hook.claim.lost": "two Counterparts wirings ran one event and this hook found it already claimed, so it delivered nothing (which hook, which side gave way)",
261
264
  "adapter.writeup.failed": "a session start could not compose the pointer to an earlier session's write-up (the code) — that session was not offered its write-up this time",
262
265
  "remember.capture.failed": "a turn's words could not be kept for its write-up (which step of the capture, and the code) — the next boundary reads the same turns again",
263
266
  "adapter.spawn.failed": "the detached worker could not be started at all (the OS said why)",
@@ -22,7 +22,6 @@
22
22
  * scan stays — it is what covers them, and a cast.
23
23
  */
24
24
  import type { Counterpart } from "../../core/counterpart.js";
25
- import type { Dreams } from "../../core/dream/index.js";
26
25
  import type { Schemas } from "../../core/schemas/index.js";
27
26
  import type { Self } from "../../core/self/index.js";
28
27
  import type { ReadOnlyStore } from "../../core/store/index.js";
@@ -31,12 +30,6 @@ export interface DashboardSource {
31
30
  readonly store: ReadOnlyStore;
32
31
  readonly schemas: Schemas;
33
32
  readonly self: Self;
34
- /**
35
- * The dream gate's read-only preview (`Dreams.previewAsk`, #262): would the
36
- * day's ask be raised now, and why. Optional so a hand-built source still
37
- * type-checks; a view without it says only how much is new.
38
- */
39
- readonly dreams?: Pick<Dreams, "previewAsk">;
40
33
  /** Always true. A false one never gets built. */
41
34
  readonly observer: boolean;
42
35
  }
@@ -56,7 +49,6 @@ export function sourceOf(counterpart: Counterpart): DashboardSource {
56
49
  store: counterpart.store,
57
50
  schemas: counterpart.schemas,
58
51
  self: counterpart.self,
59
- dreams: counterpart.dreams,
60
52
  observer: true,
61
53
  };
62
54
  }
@@ -21,11 +21,19 @@ export interface FiredPanel extends FiredReport {
21
21
  /** The state vocabulary, in the order the panel draws its groups, with the
22
22
  * one line each one means. On the payload so the page never restates it. */
23
23
  readonly vocabulary: { state: string; meaning: string }[];
24
+ /**
25
+ * The zone the window's days are read in (`store.zone()`: the
26
+ * configuration's `timeZone`, else the machine's), so the footer names the
27
+ * calendar it counts by. It said "(UTC)" until 2026-10-09, after the
28
+ * reading itself had moved to the local day.
29
+ */
30
+ readonly zone: string;
24
31
  }
25
32
 
26
33
  export function firedPanel(src: DashboardSource, today: string): FiredPanel {
27
34
  return {
28
35
  ...firedReport(src.store, today),
29
36
  vocabulary: STATE_ORDER.map((state) => ({ state, meaning: STATE_MEANING[state] })),
37
+ zone: src.store.zone(),
30
38
  };
31
39
  }
@@ -420,6 +420,7 @@ export const EVENT_NODE = {
420
420
  // the flush and the cycle; when it cannot start or cannot finish, the node
421
421
  // that did not happen is the sweep's.
422
422
  "adapter.spawn.refused": "sweep",
423
+ "adapter.hook.claim.lost": "session",
423
424
  "adapter.spawn.failed": "sweep",
424
425
  "adapter.runner.failed": "sweep",
425
426
  // The two failures the process log promoted to rows (2026-09-30): a turn the
@@ -110,6 +110,7 @@ export const LANES = {
110
110
  "adapter.semantic.lag": "flow",
111
111
  "adapter.spawn.failed": "flow",
112
112
  "adapter.spawn.refused": "flow",
113
+ "adapter.hook.claim.lost": "flow",
113
114
  "adapter.spawn.started": "flow",
114
115
  "adapter.wake.delivered": "flow",
115
116
  "adapter.wake.injected": "flow",
@@ -35,6 +35,7 @@ import {
35
35
  NOISY_IF_CHRONIC_SWEEP_REASONS,
36
36
  NOISY_NOW_SWEEP_REASONS,
37
37
  } from "../../../core/remember/index.js";
38
+ import { readPageTooLargeDetail } from "../../../core/self/index.js";
38
39
  import { BAND_TRANSITION_FIELDS } from "../../../core/sleep/index.js";
39
40
  import type { EventRow, ReadOnlyStore } from "../../../core/store/index.js";
40
41
  import { num } from "../layout.js";
@@ -356,6 +357,10 @@ export const NARRATORS = {
356
357
  amber(
357
358
  `My background worker opened the store and then failed at ${String(t.p["step"] ?? "an unnamed step")} (${String(t.p["code"] ?? "no code")}).`,
358
359
  ),
360
+ "adapter.hook.claim.lost": (t) =>
361
+ amber(
362
+ `Two Counterparts installs ran the same ${String(t.p["hook"] ?? "hook")} at once; the ${String(t.p["lost"] ?? "second")} one found it already taken and said nothing, so nothing reached the session twice. Keeping one install stops the doubling.`,
363
+ ),
359
364
  "adapter.writeup.failed": (t) =>
360
365
  amber(
361
366
  `A session started and I could not hand it the pointer to an earlier session's write-up (${String(t.p["code"] ?? "no code")}). The next session start tries again.`,
@@ -660,6 +665,11 @@ export const NARRATORS = {
660
665
  case "refused":
661
666
  return calm(`A revision of my page from ${about} was turned away (${s(t, "detail") ?? "refused"}). The page is unchanged.`);
662
667
  case "failed":
668
+ // A page refused for length and not sent again (review of #358): it
669
+ // ran, and wrote too much.
670
+ if (readPageTooLargeDetail(s(t, "detail") ?? "") !== null) {
671
+ return calm(`The nightly writer's page from ${about} was too long and was not sent again shorter (${s(t, "detail") ?? ""}). The page is unchanged.`);
672
+ }
663
673
  return calm(`The nightly writer could not run for ${about} (${s(t, "detail") ?? "failed"}). The page is unchanged.`);
664
674
  default:
665
675
  return calm(`The nightly writer stood down for ${about} (${s(t, "detail") ?? "skipped"}), in ${mode} mode.`);
@@ -1164,6 +1174,7 @@ export const REF_KIND = {
1164
1174
  "adapter.recall": "none",
1165
1175
  "adapter.runner.failed": "none",
1166
1176
  "adapter.writeup.failed": "none",
1177
+ "adapter.hook.claim.lost": "none",
1167
1178
  "remember.capture.failed": "none",
1168
1179
  "adapter.semantic.lag": "none",
1169
1180
  "adapter.spawn.failed": "none",
@@ -33,7 +33,7 @@ export async function render() {
33
33
  "<table><thead><tr><th>what it does</th><th class='num'>last fired</th><th class='num'>7 days</th></tr></thead><tbody>" +
34
34
  rows.join("") + "</tbody></table>";
35
35
  $("h-fired-foot").textContent =
36
- d.from + "→" + d.today + " (UTC), against " + d.previousFrom + "→" + d.previousTo + ". " +
36
+ d.from + "→" + d.today + (d.zone ? " (" + d.zone + ")" : "") + ", against " + d.previousFrom + "→" + d.previousTo + ". " +
37
37
  (d.missedOccasion && d.missedOccasion.length ? "Its occasion came this week and it did not fire: " + d.missedOccasion.join("; ") + ". " : "") +
38
38
  (d.wentQuiet.length ? "Fired last week and not once this week: " + d.wentQuiet.join("; ") + ". "
39
39
  : "Nothing that fired last week has fallen silent this week. ") +