counterparts 0.3.13 → 0.3.14

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 (84) hide show
  1. package/CHANGELOG.md +160 -0
  2. package/package.json +1 -1
  3. package/src/adapters/claude-code/bin/hook.mjs +4 -2
  4. package/src/adapters/claude-code/bin/hook.ts +11 -4
  5. package/src/adapters/claude-code/bin/nightly.ts +5 -1
  6. package/src/adapters/claude-code/bin/runner.ts +11 -3
  7. package/src/adapters/claude-code/doctor.ts +69 -5
  8. package/src/adapters/claude-code/embed-client.ts +3 -0
  9. package/src/adapters/cli/bin/counterparts.mjs +4 -2
  10. package/src/adapters/cli/bin/counterparts.ts +11 -3
  11. package/src/adapters/cli/commands.ts +65 -23
  12. package/src/adapters/cli/index.ts +1 -0
  13. package/src/adapters/cli/install.ts +22 -9
  14. package/src/adapters/cli/settle.ts +39 -2
  15. package/src/adapters/cli/wire.ts +4 -0
  16. package/src/adapters/config.ts +29 -1
  17. package/src/adapters/dashboard/NOTES.md +33 -0
  18. package/src/adapters/dashboard/bin/dashboard.mjs +4 -2
  19. package/src/adapters/dashboard/bin/dashboard.ts +11 -3
  20. package/src/adapters/dashboard/index.ts +14 -0
  21. package/src/adapters/dashboard/source.ts +0 -8
  22. package/src/adapters/dashboard/web/fired.ts +8 -0
  23. package/src/adapters/dashboard/web/pages/flow/sections/fired.js +1 -1
  24. package/src/adapters/dashboard/web/pages/health/sections/cycle.js +7 -10
  25. package/src/adapters/dashboard/web/pages/memories/memories.css +3 -0
  26. package/src/adapters/dashboard/web/pages/memories/row.js +5 -2
  27. package/src/adapters/dashboard/web/pages/memories/sections/hold.js +2 -1
  28. package/src/adapters/dashboard/web/pages/memories/sections/search.js +19 -3
  29. package/src/adapters/dashboard/web/server.ts +16 -4
  30. package/src/adapters/dashboard/web/shared/dates.js +6 -16
  31. package/src/adapters/dashboard/web/shared/memory-modal.js +21 -8
  32. package/src/adapters/dashboard/web/views/health.ts +11 -0
  33. package/src/adapters/dashboard/web/views/mechanism-panel.ts +8 -5
  34. package/src/adapters/dashboard/web/views/memories.ts +26 -7
  35. package/src/adapters/dashboard/web/views/memory-words.ts +16 -0
  36. package/src/adapters/dashboard/web/views/memory.ts +51 -2
  37. package/src/adapters/dashboard/web/views/mind.ts +31 -6
  38. package/src/adapters/empty-bunfig.toml +5 -0
  39. package/src/adapters/fired.ts +6 -2
  40. package/src/adapters/host-wiring.ts +4 -3
  41. package/src/adapters/log/index.ts +2 -2
  42. package/src/adapters/mcp/CONTRACT.md +16 -2
  43. package/src/adapters/mcp/INTERFACE-GAPS.md +15 -1
  44. package/src/adapters/mcp/NOTES.md +243 -0
  45. package/src/adapters/mcp/bin/serve.mjs +4 -2
  46. package/src/adapters/mcp/bin/serve.ts +11 -4
  47. package/src/adapters/mcp/facts.ts +72 -4
  48. package/src/adapters/mcp/meaning.ts +218 -15
  49. package/src/adapters/mcp/server.ts +1 -1
  50. package/src/adapters/mcp/tools.ts +81 -57
  51. package/src/adapters/plugin-run.sh +405 -33
  52. package/src/adapters/plugin.ts +14 -2
  53. package/src/adapters/runtime.ts +192 -17
  54. package/src/adapters/sessions.ts +2 -2
  55. package/src/core/associate/NOTES.md +10 -0
  56. package/src/core/bridge.ts +1 -1
  57. package/src/core/briefing.ts +20 -3
  58. package/src/core/contradictions.ts +56 -20
  59. package/src/core/counterpart.ts +39 -17
  60. package/src/core/dream/CONTRACT.md +4 -12
  61. package/src/core/dream/INTERFACE-GAPS.md +3 -2
  62. package/src/core/dream/NOTES.md +10 -0
  63. package/src/core/dream/index.ts +10 -52
  64. package/src/core/embed/static.ts +5 -1
  65. package/src/core/encode/INTERFACE-GAPS.md +2 -1
  66. package/src/core/encode/NOTES.md +12 -0
  67. package/src/core/encode/chunk.ts +6 -30
  68. package/src/core/encode/index.ts +0 -1
  69. package/src/core/encode/types.ts +1 -13
  70. package/src/core/handoff/last-here.ts +18 -2
  71. package/src/core/physics/CONTRACT.md +6 -0
  72. package/src/core/physics/NOTES.md +33 -2
  73. package/src/core/physics/index.ts +22 -7
  74. package/src/core/prospective/CONTRACT.md +3 -1
  75. package/src/core/prospective/NOTES.md +15 -0
  76. package/src/core/recall/time-ask.ts +154 -19
  77. package/src/core/self/CONTRACT.md +23 -3
  78. package/src/core/self/NOTES.md +64 -0
  79. package/src/core/self/behind.ts +6 -3
  80. package/src/core/self/briefing.ts +272 -11
  81. package/src/core/self/index.ts +50 -4
  82. package/src/core/sleep/NOTES.md +32 -0
  83. package/src/core/store/NOTES.md +16 -0
  84. package/src/core/time.ts +15 -0
@@ -31,7 +31,6 @@ import { isDay, localDate, localTime, resolveZone, todayIn } from "../../core/ti
31
31
  import { homedir, tmpdir } from "node:os";
32
32
  import { basename, delimiter, dirname, isAbsolute, join, resolve } from "node:path";
33
33
  import { spawn } from "node:child_process";
34
- import { fileURLToPath } from "node:url";
35
34
  import { parseArgs } from "node:util";
36
35
 
37
36
  import {
@@ -155,7 +154,7 @@ import {
155
154
  SPAWN_START_COUNT_KEY,
156
155
  SPAWN_START_DATE_KEY,
157
156
  } from "../claude-code/hooks.js";
158
- import { loadConfig, withEmbedderDefault } from "../config.js";
157
+ import { loadConfig, withEmbedderDefault, zoneBeside } from "../config.js";
159
158
  // The one answer to "is there an embedder", shared with the hook, the worker and
160
159
  // the MCP server's entry point — `ask` embeds its question with it.
161
160
  import { openEmbedder } from "../claude-code/embed-client.js";
@@ -239,7 +238,8 @@ import type { ParkStep, StartFreshPlan, UndoPlan } from "./start-fresh.js";
239
238
  // but the `Io` type, so this direction is one-way.
240
239
  import { realProcessLister, realSpawner, sessionsNote, tilde, unwire, wire } from "./wire.js";
241
240
  import { connectDesktop, desktopUnavailable, readDesktop } from "./desktop.js";
242
- import { runtimeLabel } from "../runtime.js";
241
+ import { BINARY, bundledModelDir, packagePath, runtimeLabel } from "../runtime.js";
242
+ import type { Binary } from "../runtime.js";
243
243
  import { DESKTOP_ALWAYS_ALLOW, DESKTOP_HOST, upgradeWords } from "../hosts.js";
244
244
  import { hostsSeen, installedVersion } from "../sessions.js";
245
245
  import type {
@@ -504,8 +504,29 @@ export interface RunOptions {
504
504
  * falls back to.)
505
505
  */
506
506
  scope?: string;
507
+ /**
508
+ * THE SINGLE BINARY (`runtime.ts#Binary`), when this console is it — the
509
+ * program the Claude Code plugin downloads when a machine has no Bun or Node.
510
+ * Real runs never pass it and get `BINARY`; tests pass one to drive the
511
+ * binary's refusals from source.
512
+ */
513
+ binary?: Binary | null;
507
514
  }
508
515
 
516
+ /**
517
+ * WHAT THE SINGLE BINARY WILL NOT DO TO A HOST. The binary lives in the
518
+ * plugin's data directory, which Claude Code deletes with the plugin, and the
519
+ * plugin already runs the hooks and the memory server — so a hooks block, an
520
+ * MCP registration or a Claude Desktop entry naming it would be a second
521
+ * install that dies silently on uninstall. Wiring a host by hand is the npm
522
+ * install's job.
523
+ */
524
+ export const BINARY_CONNECT_REFUSAL =
525
+ "This is Counterparts' single program, the one the Claude Code plugin downloads when a computer has no Bun or Node.js. " +
526
+ "It doesn't connect hosts itself: the plugin already runs the hooks and the memory server, and anything wired to this file " +
527
+ "would stop working when the plugin is uninstalled. To wire Claude Code or Claude Desktop by hand, install Counterparts with " +
528
+ "npm (`npm i -g counterparts`) and run `counterparts connect` from that install.";
529
+
509
530
  /**
510
531
  * THE CONSOLE'S MAP — about forty lines, grouped, one line per command.
511
532
  *
@@ -544,7 +565,7 @@ let readVersion: string | null = null;
544
565
  export function packageVersion(): string {
545
566
  if (readVersion !== null) return readVersion;
546
567
  try {
547
- const raw = readFileSync(fileURLToPath(new URL("../../../package.json", import.meta.url)), "utf8");
568
+ const raw = readFileSync(packagePath("package.json"), "utf8");
548
569
  const said = (JSON.parse(raw) as Record<string, unknown>)["version"];
549
570
  readVersion = typeof said === "string" && said.length > 0 ? said : VERSION_UNKNOWN;
550
571
  } catch {
@@ -817,7 +838,7 @@ export const COMMAND_BLURB: Record<Command, string> = {
817
838
  core:
818
839
  "The core — the memories about me, about us and about the owner that do not fade. With no flags (or --list), what it holds and which lane carried each one there, what dreams have nominated, and what you sent back; --demote <id> --reason \"...\" sends one back to ordinary fading from today, records why, and keeps the lanes from promoting it again; --reflected-feeling on|off opens or closes the core to reflection alone. On (the default): a feeling a reflection records later and a reflection citing a memory both count toward the fast lane, and a reflection may re-label what a memory is about either way — each re-label is recorded with its reason, and one into me, us or the owner is told in the next morning share. Off: nothing reaches the core on a reflection alone — the fast lane needs a feeling felt at the time (not one a reflection recorded later) and an ordinary use after a gap (not a reflection citing it), and a reflection may only move what a memory is about toward work or world. Reading works under observer; the two changes refuse there.",
819
840
  settle:
820
- "Two memories that disagree. With no flags (or --list), the pairs nobody has settled — a dream flags them — and the ones settled lately: how, which holds, who settled it and why. --pair <id> --holds <memory id> --how changed|corrected|open --why \"...\" settles one as you (or --holds <id> --against <id> for two memories no dream flagged): changed — both were true at their time, the older fades once and is shown as earlier; corrected — the older was wrong, it leaves recall and stays readable by its id; open — a real disagreement, both kept and shown together. No memory is rewritten. --undo <pair> reverses a settle: the strength comes back, a corrected memory comes back into recall, and the pair is unsettled again. Reading works under observer; the two changes refuse there.",
841
+ "Two memories that disagree. With no flags (or --list), the pairs nobody has settled — a dream flags them — and the ones settled lately: how, which holds, who settled it and why; and the corrections held in the last 7 lived days (a memory said it changes or corrects one that didn't look related, so nothing was settled) that nobody has settled since, each with the command that settles it. --pair <id> --holds <memory id> --how changed|corrected|open --why \"...\" settles one as you (or --holds <id> --against <id> for two memories no dream flagged): changed — both were true at their time, the older fades once and is shown as earlier; corrected — the older was wrong, it leaves recall and stays readable by its id; open — a real disagreement, both kept and shown together. No memory is rewritten. --undo <pair> reverses a settle: the strength comes back, a corrected memory comes back into recall, and the pair is unsettled again. Reading works under observer; the two changes refuse there.",
821
842
  coverage:
822
843
  "What is written up, and what is not yet, for one date (default today): each session that captured something that day, how much of it is written up, and what is not yet written up — how many pieces, over how long, since when — and whether that is owed (the next session in its project is asked to write it up), lapsed (nobody did in two days of use; nothing is deleted), under the floor, or still at work. Read-only.",
823
844
  dashboard:
@@ -1634,6 +1655,29 @@ export async function run(argv: readonly string[], opts: RunOptions): Promise<nu
1634
1655
  io.err(implicit);
1635
1656
  return EXIT.refused;
1636
1657
  }
1658
+ // THE SINGLE BINARY makes the store and the configuration — the plugin's
1659
+ // first run is exactly `install --no-connect` — and wires nothing: no
1660
+ // conversation that ends in `connect`, no Desktop entry, no printed hooks
1661
+ // block naming a file the plugin's uninstall will delete.
1662
+ const binary = opts.binary === undefined ? BINARY : opts.binary;
1663
+ if (binary !== null) {
1664
+ const hostAsked = parsed.flags["host"];
1665
+ if (hostAsked !== undefined && hostAsked !== "claude-code") {
1666
+ io.err(BINARY_CONNECT_REFUSAL);
1667
+ return EXIT.refused;
1668
+ }
1669
+ try {
1670
+ const code = installCommand(parsed, io, env, opts.home, named, { hostSteps: false });
1671
+ if (code === EXIT.ok) {
1672
+ io.out("");
1673
+ io.out("Claude Code runs this memory through the Counterparts plugin, so there is nothing to connect.");
1674
+ }
1675
+ return code;
1676
+ } catch (err) {
1677
+ io.err(`install failed: ${describeDirRefusal(err)}`);
1678
+ return EXIT.failed;
1679
+ }
1680
+ }
1637
1681
  // `--host claude-desktop` (2026-09-30): the store and the configuration as
1638
1682
  // any install makes them, then Claude Desktop's config entry instead of
1639
1683
  // Claude Code's hooks. No `--host`, or `--host claude-code`, is the install
@@ -1676,6 +1720,10 @@ export async function run(argv: readonly string[], opts: RunOptions): Promise<nu
1676
1720
  // The explicit-dir guard applies by hand, exactly as it does to `install`:
1677
1721
  // the default configuration names the live store and the live base, and
1678
1722
  // `uninstall --park` renames the directory that file sits in.
1723
+ if (command === "connect" && (opts.binary === undefined ? BINARY : opts.binary) !== null) {
1724
+ io.err(BINARY_CONNECT_REFUSAL);
1725
+ return EXIT.refused;
1726
+ }
1679
1727
  if (command === "connect" || command === "disconnect" || command === "uninstall") {
1680
1728
  const implicit = named === undefined ? null : implicitConfigRefusal(named, env);
1681
1729
  if (implicit !== null) {
@@ -3848,7 +3896,8 @@ async function installConversation(
3848
3896
  // Looked for the way the hooks will look (`resolveStaticWeights`: the
3849
3897
  // environment variable, then the installed package), and then for the table
3850
3898
  // FILE in what that found — a variable naming an empty folder is not a table.
3851
- const table = resolveStaticWeights({ env });
3899
+ const bundled = bundledModelDir();
3900
+ const table = resolveStaticWeights({ env, ...(bundled === undefined ? {} : { packageDir: bundled }) });
3852
3901
  const tableOn = config.embedder?.enabled === true;
3853
3902
  const tableMissing = tableOn && (table === null || !existsSync(join(table.dir, MODEL_FILE)));
3854
3903
  if (tableOn && !tableMissing) {
@@ -8736,27 +8785,14 @@ export function openCounterpart(
8736
8785
  });
8737
8786
  }
8738
8787
 
8739
- /**
8740
- * `snapshots.dir` from the host configuration beside the store
8741
- * (`<base>/claude-code.json`, the file `install` writes), so a migration the
8742
- * console runs puts its copy where the worker's rotation and doctor look.
8743
- * Absent, unreadable or unset: undefined, and the store's default applies.
8744
- */
8745
8788
  /**
8746
8789
  * `timeZone` from the host configuration beside the store — the same file
8747
8790
  * `snapshotsDirBeside` reads — so a console command names the person's day in
8748
- * the zone the hooks use (docs/time.md, 2026-09-25). Absent or unreadable:
8749
- * undefined, and the store follows the machine's zone.
8791
+ * the zone the hooks use (docs/time.md, 2026-09-25). It lives in `config.ts`
8792
+ * since 2026-10-09, where the dashboard reads it too; re-exported here for the
8793
+ * console's callers.
8750
8794
  */
8751
- export function zoneBeside(dir: string): string | undefined {
8752
- const beside = join(dir, "..", "claude-code.json");
8753
- if (!existsSync(beside)) return undefined;
8754
- try {
8755
- return loadConfig(JSON.parse(readFileSync(beside, "utf8"))).config.timeZone;
8756
- } catch {
8757
- return undefined;
8758
- }
8759
- }
8795
+ export { zoneBeside };
8760
8796
 
8761
8797
  /** `Store.open` for the console: the config's zone beside the store rides along. */
8762
8798
  function openStoreAt(opts: { dir: string; observer?: boolean }): Store {
@@ -8764,6 +8800,12 @@ function openStoreAt(opts: { dir: string; observer?: boolean }): Store {
8764
8800
  return Store.open({ ...opts, ...(timeZone === undefined ? {} : { timeZone }) });
8765
8801
  }
8766
8802
 
8803
+ /**
8804
+ * `snapshots.dir` from the host configuration beside the store
8805
+ * (`<base>/claude-code.json`, the file `install` writes), so a migration the
8806
+ * console runs puts its copy where the worker's rotation and doctor look.
8807
+ * Absent, unreadable or unset: undefined, and the store's default applies.
8808
+ */
8767
8809
  export function snapshotsDirBeside(dir: string): string | undefined {
8768
8810
  const beside = join(dir, "..", "claude-code.json");
8769
8811
  if (!existsSync(beside)) return undefined;
@@ -8,6 +8,7 @@
8
8
  * caller imports. The console reaches it directly; nobody else may.
9
9
  */
10
10
  export {
11
+ BINARY_CONNECT_REFUSAL,
11
12
  COMMANDS,
12
13
  COMMAND_BLURB,
13
14
  COMMAND_FLAGS,
@@ -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)));
@@ -585,10 +587,15 @@ export interface HostRead {
585
587
  /** One runtime a host's configuration launches us with. */
586
588
  export interface HostRuntime {
587
589
  readonly exe: string;
588
- readonly kind: RuntimeKind;
590
+ /** `binary`: the single compiled binary, its own runtime. */
591
+ readonly kind: RuntimeKind | "binary";
589
592
  readonly present: boolean;
590
593
  /** `hooks`, `mcp`, or both. */
591
594
  readonly used: readonly ("hooks" | "mcp")[];
595
+ /** Of `used`, the ones whose command lets Bun read the project's `.env` or
596
+ * `bunfig.toml` — wired before `--no-env-file` and an empty `--config=`
597
+ * (`runtime.ts#BUN_NO_ENV_FILE`, `#EMPTY_BUNFIG`). */
598
+ readonly projectEnv: readonly ("hooks" | "mcp")[];
592
599
  }
593
600
 
594
601
  /**
@@ -599,10 +606,11 @@ export interface HostRuntime {
599
606
  * version matched any command merely *mentioning* the name, so `echo
600
607
  * counterparts-hook` read as an installed hook. It still cannot resolve an
601
608
  * arbitrary shell command — that is out of scope, and deliberately so — but it
602
- * no longer matches prose.
609
+ * no longer matches prose. The third shape is the single binary's own
610
+ * (`"<…>/counterparts" hook`, `runtime.ts#parseScriptInvocation`).
603
611
  */
604
612
  export const HOOK_COMMAND_MARK =
605
- /(^|[\s"'=/\\])counterparts-hook(\s|$|")|claude-code[/\\]bin[/\\]hook\.ts/;
613
+ /(^|[\s"'=/\\])counterparts-hook(\s|$|")|claude-code[/\\]bin[/\\]hook\.ts|[/\\]counterparts(\.exe)?"?\s+hook(\s|$)/;
606
614
 
607
615
  /**
608
616
  * The absolute path a hook command runs, when it names one — the first token
@@ -613,6 +621,9 @@ export const HOOK_COMMAND_MARK =
613
621
  * anything else rather than guessing. A null is never reported as stale.
614
622
  */
615
623
  export function hookTargetPath(command: string): string | null {
624
+ // The single binary is its own script: `"<binary>" hook` needs the binary.
625
+ const run = parseScriptInvocation(shellTokens(command));
626
+ if (run?.runtime === "binary") return run.exe;
616
627
  const tokens = command.trim().split(/\s+/);
617
628
  for (const raw of tokens) {
618
629
  const token = raw.replace(/^["']|["']$/g, "");
@@ -718,12 +729,13 @@ export function readHost(
718
729
  const settingsUnreadable: string[] = [];
719
730
  // WHICH RUNTIME the host launches us with — read off the same commands, never
720
731
  // spawned: `bun run <script>` or `node --import <node-hooks.mjs> <script>`.
721
- const runtimes = new Map<string, { kind: RuntimeKind; used: Set<"hooks" | "mcp"> }>();
732
+ const runtimes = new Map<string, { kind: RuntimeKind | "binary"; used: Set<"hooks" | "mcp">; projectEnv: Set<"hooks" | "mcp"> }>();
722
733
  const noteRuntime = (tokens: readonly string[], used: "hooks" | "mcp"): void => {
723
734
  const run = parseScriptInvocation(tokens);
724
735
  if (run === null) return;
725
- const row = runtimes.get(run.exe) ?? { kind: run.runtime, used: new Set<"hooks" | "mcp">() };
736
+ const row = runtimes.get(run.exe) ?? { kind: run.runtime, used: new Set<"hooks" | "mcp">(), projectEnv: new Set<"hooks" | "mcp">() };
726
737
  row.used.add(used);
738
+ if (run.projectEnv === "read") row.projectEnv.add(used);
727
739
  runtimes.set(run.exe, row);
728
740
  };
729
741
  for (const path of hostSettingsFiles(hostSettingsDir(home, env), cwd)) {
@@ -792,6 +804,7 @@ export function readHost(
792
804
  kind: row.kind,
793
805
  present: runtimePresent(exe, env),
794
806
  used: [...row.used].sort(),
807
+ projectEnv: [...row.projectEnv].sort(),
795
808
  })),
796
809
  plugin: pluginInstall({ home, env, cwd }),
797
810
  };
@@ -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 \"...\"",
@@ -1016,6 +1016,10 @@ const PROCESS_MARKS: readonly { readonly re: RegExp; readonly what: string }[] =
1016
1016
  { re: /claude-code[/\\]bin[/\\]runner\.ts/, what: "the worker" },
1017
1017
  { re: /dashboard[/\\]bin[/\\]dashboard\.(ts|mjs)/, what: "a dashboard" },
1018
1018
  { re: /(^|[\s"'/\\])counterparts-dashboard(\s|$|")/, what: "a dashboard" },
1019
+ // The single binary (`runtime.ts#BINARY_MODES`): `…/counterparts mcp`.
1020
+ { re: /(^|[/\\])counterparts(\.exe)?"?\s+mcp(\s|$)/, what: "an MCP server" },
1021
+ { re: /(^|[/\\])counterparts(\.exe)?"?\s+runner(\s|$)/, what: "the worker" },
1022
+ { re: /(^|[/\\])counterparts(\.exe)?"?\s+dashboard(\s|$)/, what: "a dashboard" },
1019
1023
  ];
1020
1024
 
1021
1025
  /** Which of ours, if any, this command line is. Exported for the test, which
@@ -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
  });
@@ -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
  }
@@ -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. ") +
@@ -1,19 +1,16 @@
1
1
  /* The last sleep cycle, as one line with a dot per step. */
2
- import { dateWords, localIso } from "../../../shared/dates.js";
2
+ import { dateWords } from "../../../shared/dates.js";
3
3
  import { $, esc } from "../../../shared/dom.js";
4
4
 
5
5
  export const markup = `
6
6
  <div class="card pad hcy" id="h-cycle"></div>`;
7
7
 
8
- function sameLocalDay(ms) {
9
- const a = new Date(ms);
10
- const b = new Date();
11
- return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
12
- }
13
-
14
- function when(c) {
15
- if (c.at !== null && sameLocalDay(c.at)) return "today";
16
- if (c.at !== null) return "on " + dateWords(localIso(c.at)) + " (lived day " + c.day + ")";
8
+ /* The day comes dated from the server, in the person's zone (`views/health.ts`,
9
+ `cycle.on` and `cycle.today`), so it agrees with every other date on the
10
+ page; it read the browser's calendar until 2026-10-09. */
11
+ export function when(c) {
12
+ if (c.today) return "today";
13
+ if (c.on) return "on " + (dateWords(c.on) || c.on) + " (lived day " + c.day + ")";
17
14
  return "on lived day " + c.day;
18
15
  }
19
16
 
@@ -46,6 +46,8 @@
46
46
  /* An answer's quieter notes, on their own line under its head (what it is
47
47
  about, a time it named, what it left out and why). */
48
48
  .find-note{display:block;color:var(--faint);font-size:12px;margin-top:2px}
49
+ /* A name asked about with no card, said before the head (2026-10-09). */
50
+ .find-lead{display:block;color:var(--text);margin-bottom:2px}
49
51
 
50
52
  /* ── the two small pictures: how well I remember, how it feels ── */
51
53
  .glance2{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,24rem),1fr));gap:0 20px;align-items:stretch}
@@ -155,6 +157,7 @@
155
157
  .mdate{color:var(--faint);font-size:12px;white-space:nowrap}
156
158
  .mkind{display:inline-flex;align-items:center;gap:5px;color:var(--faint);font-size:12px;white-space:nowrap}
157
159
  .mfading{color:var(--amber);font-size:12px;white-space:nowrap}
160
+ .mrepeats{color:var(--dim);font-size:12px;white-space:nowrap}
158
161
  /* The close matches' heading, under the exact ones (M4). */
159
162
  .mclose-h{padding:9px 15px 7px;border-bottom:1px solid var(--border);color:var(--ink);font-size:12.5px;font-weight:600;background:rgba(255,255,255,.02)}
160
163
  .mclose-h span{color:var(--dim);font-weight:400}
@@ -2,7 +2,8 @@
2
2
  Title on its own line with the words dimmer beneath (two lines, clipped); the
3
3
  date, the kind and the marks on the right. Every row is drawn at the same
4
4
  brightness (round 4, 2026-09-28): how well it is remembered shows only when
5
- it is not the usual — the one word "fading". A plain fact carries no kind
5
+ it is not the usual — the one word "fading", or for a date that still
6
+ repeats, how often ("repeats every May 14"). A plain fact carries no kind
6
7
  tag (the quiet default); a journal chapter is titled by its day. An id
7
8
  written inside the words is a small link to that memory (2026-10-09). */
8
9
  import { esc } from "../../shared/dom.js";
@@ -108,7 +109,9 @@ export function memRow(r, opts = {}) {
108
109
  // A plain fact is the quiet default: no tag. A journal chapter says so in its title.
109
110
  const kindTag = !r.kind || (r.kind === "fact" && !r.schemaRole) || r.journal ? ""
110
111
  : '<span class="mkind" title="' + esc(kindWords) + '">' + kindMark(r.kind, false) + '<span class="klabel">' + esc(kindWords) + "</span></span>";
111
- const held = r.hold === "fading" ? '<span class="mfading" title="unless it is used, I may put it away within my next two weeks of use">fading</span>' : "";
112
+ // A date that still repeats is kept for its next time, however faint (2026-10-09): it is never "fading", and says how often instead.
113
+ const held = r.hold === "fading" ? '<span class="mfading" title="unless it is used, I may put it away within my next two weeks of use">fading</span>'
114
+ : r.repeats ? '<span class="mrepeats" title="' + esc("it comes round " + r.repeats + ", so I'll keep it while it does") + '">repeats ' + esc(r.repeats) + "</span>" : "";
112
115
  const date = r.date && !r.journal
113
116
  ? '<span class="mdate" title="' + esc(DATE_WORDS[r.dateFrom] || "") + '">' + esc(dateOr(r.date)) + "</span>" : "";
114
117
  const put = r.archived