counterparts 0.3.21 → 0.3.23

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 (41) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/docs/module-map.md +1 -0
  3. package/package.json +1 -1
  4. package/src/adapters/claude-code/bin/hook.ts +3 -3
  5. package/src/adapters/claude-code/bin/runner.ts +27 -1
  6. package/src/adapters/claude-code/doctor-host.ts +28 -9
  7. package/src/adapters/claude-code/night-run.ts +2 -3
  8. package/src/adapters/claude-code/transcript.ts +1 -1
  9. package/src/adapters/cli/bin/counterparts.ts +9 -2
  10. package/src/adapters/cli/commands-dashboard.ts +31 -2
  11. package/src/adapters/cli/commands-start-fresh.ts +11 -2
  12. package/src/adapters/cli/desktop.ts +10 -5
  13. package/src/adapters/cli/help.ts +4 -3
  14. package/src/adapters/cli/install.ts +16 -8
  15. package/src/adapters/cli/removal.ts +7 -0
  16. package/src/adapters/cli/uninstall.ts +12 -4
  17. package/src/adapters/cli/wire.ts +41 -12
  18. package/src/adapters/dashboard/web/README.md +1 -1
  19. package/src/adapters/dashboard/web/actions.ts +6 -4
  20. package/src/adapters/dashboard/web/app.html +3 -0
  21. package/src/adapters/dashboard/web/favicon.svg +1 -0
  22. package/src/adapters/dashboard/web/pages/home/home.css +3 -0
  23. package/src/adapters/dashboard/web/pages/home/sections/brain.js +37 -9
  24. package/src/adapters/dashboard/web/probe.ts +33 -0
  25. package/src/adapters/dashboard/web/server.ts +49 -27
  26. package/src/adapters/dashboard/web/views/mechanism-panel.ts +13 -3
  27. package/src/adapters/host-wiring.ts +44 -6
  28. package/src/adapters/mcp/bin/serve.ts +33 -0
  29. package/src/adapters/mcp/index.ts +1 -0
  30. package/src/adapters/mcp/server-options.ts +7 -0
  31. package/src/adapters/mcp/server-words.ts +1 -1
  32. package/src/adapters/mcp/server.ts +7 -0
  33. package/src/adapters/mcp/tools.ts +58 -0
  34. package/src/adapters/plugin.ts +3 -2
  35. package/src/adapters/runtime.ts +80 -3
  36. package/src/adapters/scopes.ts +2 -1
  37. package/src/adapters/sidebar-status.ts +505 -0
  38. package/src/adapters/spawn.ts +2 -2
  39. package/src/core/dream/index.ts +1 -1
  40. package/src/core/dream/reflect.ts +6 -5
  41. package/src/core/onboarding.ts +5 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,71 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.23 — 2026-10-14
4
+
5
+ The plugin's sidebar now shows your memory and does nothing else: it has no buttons and no links, runs no command, calls no tool and makes no network request. Its footer says how to do the rest yourself (`/counterparts:meet`, `/counterparts:dashboard`, say "pause memory here", `/counterparts quiet`). What it shows comes from a small file Counterparts writes for it, `~/.counterparts/sidebar.json`, only while the plugin is installed, so the dashboard no longer has to be running for the sidebar to show anything. The sidebar's brain is gone and the fox stays. The plugin directory's build of the plugin no longer reads Claude Code's user configuration file and leaves out the dashboard's 3D brain; beside an npm install it does not stand down, so keep one or the other. No store-format change (store v13, cache v6) and no wiring change: nothing to run after upgrading from 0.3.22, and `counterparts connect` is not needed.
6
+
7
+ - **The sidebar shows memory and no longer acts.** It has no buttons: the "Start the
8
+ 5-minute intro" row, the desktop's dashboard buttons, the folder switch (on, paused, off)
9
+ and its confirm, and the view and avatar switches are gone. Its footer says how instead:
10
+ `/counterparts:meet` for the intro, `/counterparts:dashboard` for the dashboard, say
11
+ "pause memory here" to Claude to pause a folder, `/counterparts quiet` to hide it. A
12
+ paused folder still says so, with how to resume; `/counterparts resume` now says how
13
+ rather than resuming. COUNTERPARTS and a long memory's `more` are plain words, not links.
14
+ - **The sidebar makes no network request.** It used to ask the dashboard on 127.0.0.1;
15
+ now Counterparts' own background processes (the one after each reply, and the memory
16
+ server) write `~/.counterparts/sidebar.json` (mode 0600, beside `claude-code.json`) and
17
+ the sidebar reads it every 15 to 30 seconds while it is open. The file holds the day and
18
+ the count, today's counts, the last dream, recent activity and the memories it names
19
+ (title and the first 800 characters; a confidential memory's text is withheld). It is
20
+ written only while the plugin is installed; an npm-only install never writes it, and
21
+ once the plugin is gone the next Counterparts process deletes it. A surfaced memory's
22
+ title can take up to about 30 seconds to appear. `COUNTERPARTS_DASHBOARD_PORT` no longer
23
+ matters to the sidebar.
24
+ - **The sidebar's brain is gone; the fox stays.** `/counterparts avatar` takes `animal` or
25
+ `off`; a brain chosen before shows the fox. `/counterparts fps` is gone with it.
26
+ - **The directory build never reads `~/.claude.json`.** The plugin as built for
27
+ Anthropic's directory does not open Claude Code's user configuration file. The cost: it
28
+ can't see an npm install's memory server there, so beside a wired npm install it doesn't
29
+ stand down; both run on the same memory and Claude is offered the memory tools twice.
30
+ Keep one: `counterparts disconnect` and a restart keep only the plugin, uninstalling the
31
+ plugin keeps only the npm install. The npm install's doctor tells the two plugin builds
32
+ apart and says this. The marketplace's plugin (the full build) is unchanged and still
33
+ stands down.
34
+ - **The directory build leaves out the dashboard's 3D brain** (and three.js); its home
35
+ page draws without the picture. No file in that build is over 256 KiB.
36
+ - **Uninstalling the directory build with no `claude` on PATH keeps your memory.** It
37
+ can't confirm the memory server registration is gone, so it stops before deleting or
38
+ moving the store, and prints the `claude mcp remove` line to run.
39
+ - The dashboard's icon is now a file of its own (same address, same picture).
40
+
41
+ ## 0.3.22 — 2026-10-14
42
+
43
+ The sidebar is ready for Anthropic's plugin directory, and the plugin now installs from a repository of its own. In the sidebar the search box is gone, COUNTERPARTS and a memory's `more` are links to the dashboard in a terminal and buttons in the desktop app, and the sidebar no longer runs a command to open a browser; `counterparts dashboard` opens the dashboard already running for your memory instead of failing on its port. The plugin's marketplace entry now names `counterparts-ai/counterparts-plugin`, a generated folder that holds only the plugin, so an install clones a few hundred files instead of the whole development repository; if you added the marketplace before, run `/plugin marketplace update counterparts` first, and your memory and the plugin's data folder stay where they are. Also: the memory tools tell a host which of them only read and which can take something away, and the context a session starts with offers the first meeting and its other steps instead of ordering them. No store-format change (store v13, cache v6) and no wiring change: nothing to run after upgrading from 0.3.21, and `counterparts connect` is not needed.
44
+
45
+ - **The plugin installs from its own repository.** The marketplace entry now names
46
+ `https://github.com/counterparts-ai/counterparts-plugin.git` at the release tag: the
47
+ plugin alone, generated from this repository at each release, without its tests, docs
48
+ and development tools. The marketplace keeps its name, so the plugin's data folder and
49
+ your memory are unchanged. If you added the marketplace before, run
50
+ `/plugin marketplace update counterparts` first.
51
+ - **The memory tools now say what they do to a host.** Each one carries MCP's tool annotations: a
52
+ short title, and whether it only reads (`status`), writes, or can take something away (`dream`,
53
+ whose undo removes a dream's links and gists). A host can show these beside a tool or ask before
54
+ a call.
55
+ - **Session context offers rather than orders.** The first-meeting line now offers the
56
+ meeting to the person and describes the `meet` tool as where the script lives; the
57
+ morning share and the contradiction note describe the `told` and `settle` steps instead
58
+ of ordering a tool call nobody asked for.
59
+ - **The sidebar is ready for Anthropic's plugin directory.** The search box (hidden since
60
+ 0.3.20) is gone. In a terminal, COUNTERPARTS and a memory's `more` are now ordinary links
61
+ to the dashboard, opened by your terminal (on some terminals with a ⌘- or Ctrl-click); in
62
+ the desktop app they are buttons that run `/counterparts:dashboard`. The sidebar no
63
+ longer runs a command to open a browser. The fox's pictures load from the plugin's own
64
+ image files.
65
+ - **`counterparts dashboard` opens the dashboard that is already running** for your memory,
66
+ instead of failing because its port is taken. A dashboard for another memory on that
67
+ port still fails, and says so.
68
+
3
69
  ## 0.3.21 — 2026-10-13
4
70
 
5
71
  Your conversation text is kept for less time, and never in a backup. The text of a conversation is now deleted 3 days after it has been written up and the session has ended (it was 7), and it is never kept more than 14 days after the session's last activity, written up or not; both numbers can be changed with `"retention": {"afterWriteUpDays": 3, "maxDays": 14}` in `claude-code.json`. The first time the new version runs on an existing memory, everything older than those limits is deleted in one go, so if you want to keep more, add the `retention` setting before your first session on 0.3.21. Daily backups stop copying conversation text; backups made before this update still hold it until they rotate out, or until you run `counterparts delete backups`. New `counterparts delete conversation-text`, `delete backups` and `delete activity-log` (and "Delete data…" on the dashboard's Memories page) each delete one kind of data after showing what they would delete. The few words recall carries from your last message are cleared once a session has been quiet past the same 14-day limit. Also: the plugin installs over HTTPS without a GitHub SSH key (run `/plugin marketplace update counterparts` first if you added the marketplace before), "installed twice" is said once, the first meeting says where the sidebar appears, and the sidebar's fox and its look in the Claude Desktop app are polished (the Desktop shows the fox, not the brain, this version). No store-format change (store v13, cache v6) and no wiring change: nothing to run after upgrading from 0.3.20, and `counterparts connect` is not needed.
@@ -55,6 +55,7 @@ input — does `encode` shrink to gates-and-tagging inside `remember`'s pipeline
55
55
  | `spawn.ts` | The detached worker's plan and start (`planSpawn`, `spawnDetached`): watchdog checked against the staleness window, environment pinned last. Moved out of `claude-code/` on **2026-09-30** so any host's adapter can start the same worker. |
56
56
  | `fired.ts` | Which mechanisms have fired and which have gone quiet, read only from the store's rows — `counterparts mechanisms`, the dashboard's panel. Each entry names the module that does the work. |
57
57
  | `snapshots.ts` | The daily rotating snapshot and its rotation — the one place this package deletes a copy of the memory, and only what it can prove is a snapshot. |
58
+ | `sidebar-status.ts` | The Claude Code sidebar's status file (`sidebar.json` beside the configuration): what the sidebar shows, built by the dashboard's view functions over an observer handle and written whole, by the worker after each boundary and by the memory server off its tool calls' path, so the sidebar makes no network request. |
58
59
  | `stance-env.ts` | `COUNTERPARTS_OBSERVER` / `COUNTERPARTS_OWNER`, read the way the explicit-dir guard is, each failing toward less power. Unset, the configuration's `owner: true` decides for a server Claude Code starts (`mcp/bin/serve.ts#ownerStance`, 2026-10-02). |
59
60
  | `log/` | A shared leaf with its own CONTRACT: the process log — one line per allowlisted event (failures, stand-downs, turn ends, write-ups, the night, the wake) from the hook, the worker, the nightly run and the MCP server, to `<dataDir>/sessions/log/<date>.log`, ids and codes only, kept 7 days. Read by `counterparts log` and one doctor line. **Added 2026-09-30**: none of the four processes wired its `onEvent`, so ~270 event names died with their process. |
60
61
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "counterparts",
3
- "version": "0.3.21",
3
+ "version": "0.3.23",
4
4
  "license": "MIT",
5
5
  "description": "Memory that turns AI tools into counterparts - a local-first, human-memory-modeled memory layer for AI.",
6
6
  "repository": {
@@ -61,7 +61,7 @@ import {
61
61
  } from "../standdown.js";
62
62
  import type { SaysSoHook, StandDownFault } from "../standdown.js";
63
63
  import { readTranscript } from "../transcript.js";
64
- import { BINARY, scriptArgs } from "../../runtime.js";
64
+ import { BINARY, entryScript, scriptArgs } from "../../runtime.js";
65
65
  import type { Binary } from "../../runtime.js";
66
66
  import { npmWiring } from "../../host-wiring.js";
67
67
  import {
@@ -168,9 +168,9 @@ export const CONFIG_PATH = defaultConfigPath();
168
168
 
169
169
  /** The worker script this hook's spawn runs. Resolved from THIS file's location,
170
170
  * never from a working directory the host chose. */
171
- export const RUNNER_PATH = fileURLToPath(new URL("./runner.ts", import.meta.url));
171
+ export const RUNNER_PATH = entryScript(new URL("./runner.ts", import.meta.url));
172
172
  /** The headless nightly run's own process (2026-09-29, `night-run.ts`). */
173
- export const NIGHTLY_PATH = fileURLToPath(new URL("./nightly.ts", import.meta.url));
173
+ export const NIGHTLY_PATH = entryScript(new URL("./nightly.ts", import.meta.url));
174
174
 
175
175
  async function readStdin(): Promise<string> {
176
176
  const chunks: Buffer[] = [];
@@ -66,6 +66,7 @@
66
66
  * It exits 0 on every path. Nothing about a failed run may reach the host.
67
67
  */
68
68
  import { readFileSync } from "node:fs";
69
+ import { homedir } from "node:os";
69
70
  import { resolve } from "node:path";
70
71
  import { fileURLToPath } from "node:url";
71
72
 
@@ -102,6 +103,8 @@ import type { LiveEmbedder } from "../embed-client.js";
102
103
  import { DATA_DIR_ENV, SCOPE_ENV, SESSION_ENV, WATCHDOG_ENV } from "../../spawn.js";
103
104
  import { backfillVectors, laggedSemantic } from "../vectors.js";
104
105
  import type { BackfillReport, LagReport } from "../vectors.js";
106
+ import { removeSidebarStatus, sidebarInstalled, writeSidebarStatus } from "../../sidebar-status.js";
107
+ import type { SidebarWrite } from "../../sidebar-status.js";
105
108
  import { runSnapshot } from "../../snapshots.js";
106
109
  import type { SnapshotRunReport } from "../../snapshots.js";
107
110
 
@@ -142,6 +145,9 @@ export interface RunReport {
142
145
  /** The day's retention pass, or why it did not run. Null when the run refused
143
146
  * before it opened a store at all. */
144
147
  readonly retention: RetentionJobReport | null;
148
+ /** The sidebar's status file (`adapters/sidebar-status.ts`), written after the
149
+ * store closed; absent when the run was not asked to (no configuration path). */
150
+ readonly sidebar?: SidebarWrite;
145
151
  }
146
152
 
147
153
  /** What the retention step came to on one worker run. */
@@ -310,6 +316,9 @@ export async function runOnce(input: {
310
316
  /** The package version this run is, for the wake's build stamp. Absent: the
311
317
  * installed manifest's (`installedVersion`). Injected so a test can be an upgrade. */
312
318
  build?: string | null;
319
+ /** The configuration this run read: the sidebar's status file is written
320
+ * beside it once the run is done (`adapters/sidebar-status.ts`). Absent: none. */
321
+ sidebarConfigPath?: string;
313
322
  onEvent?: (name: string, data: Record<string, string | number | boolean | null>) => void;
314
323
  }): Promise<RunReport> {
315
324
  const { config } = input;
@@ -503,7 +512,20 @@ export async function runOnce(input: {
503
512
  }
504
513
  counterpart.close();
505
514
  }
506
- return { ...result, snapshot: snapshotReport, retention: retentionReport };
515
+ // 5. THE SIDEBAR'S STATUS FILE (2026-10-14), last: what the Claude Code
516
+ // sidebar shows, from what every step above left, through a handle of its
517
+ // own (observer) opened after this run's closed. Detached, so no hook waits
518
+ // on it; it never throws.
519
+ let sidebar: SidebarWrite | undefined;
520
+ if (input.sidebarConfigPath !== undefined && input.sidebarConfigPath.length > 0) {
521
+ sidebar = writeSidebarStatus({
522
+ configPath: input.sidebarConfigPath,
523
+ dataDir: config.dataDir,
524
+ ...(config.timeZone === undefined ? {} : { timeZone: config.timeZone }),
525
+ });
526
+ emit("runner.sidebar", { written: sidebar.written, reason: sidebar.reason, bytes: sidebar.bytes, ms: sidebar.ms });
527
+ }
528
+ return { ...result, snapshot: snapshotReport, retention: retentionReport, ...(sidebar === undefined ? {} : { sidebar }) };
507
529
  }
508
530
 
509
531
  /**
@@ -653,12 +675,16 @@ async function main(): Promise<void> {
653
675
  observer: config.observer === true,
654
676
  });
655
677
  log.start();
678
+ const sidebarWanted = sidebarInstalled(process.env, homedir());
679
+ if (!sidebarWanted && removeSidebarStatus(choice.path)) log.event({ name: "runner.sidebar", data: { removed: true } });
656
680
  try {
657
681
  const report = await runOnce({
658
682
  config,
659
683
  signal: controller.signal,
660
684
  ...(pinnedSession() === null ? {} : { session: pinnedSession() as string }),
661
685
  ...(pinnedScope() === null ? {} : { scope: pinnedScope() as string }),
686
+ // Only where the sidebar is installed (the plugin); otherwise an old file goes.
687
+ ...(sidebarWanted ? { sidebarConfigPath: choice.path } : {}),
662
688
  onEvent: (name, data) => log.event({ name, data }),
663
689
  });
664
690
  log.end(report.reason, { swept: report.swept, minted: report.minted, code: report.code });
@@ -51,6 +51,10 @@ export interface HostReading {
51
51
  readonly mcpFile: string;
52
52
  /** The MCP file exists but could not be read or parsed. */
53
53
  readonly mcpUnreadable: boolean;
54
+ /** False: this build does not open the MCP file at all (the plugin
55
+ * directory's, `runtime.ts#readsHostUserConfig`), so there is no MCP clause,
56
+ * and its plugin does not stand down beside the npm install. Absent: read. */
57
+ readonly mcpRead?: boolean;
54
58
  /**
55
59
  * Whether a `claude` executable is on the PATH the caller would run
56
60
  * `counterparts connect` with (the go-public Phase C walk, 2026-09-23).
@@ -281,15 +285,17 @@ export function hostFindings(reading: HostReading): Finding[] {
281
285
  stale: stale.map((s) => `${s.event}→${s.path}`).join(","),
282
286
  settingsRead: reading.settingsRead.join(","),
283
287
  settingsUnreadable: reading.settingsUnreadable.join(","),
284
- mcp: reading.mcp,
285
- mcpFile: reading.mcpFile,
288
+ // Null when this build never opened the MCP file (`mcpRead`).
289
+ mcp: reading.mcpRead === false ? null : reading.mcp,
290
+ mcpFile: reading.mcpRead === false ? null : reading.mcpFile,
286
291
  };
287
292
  // THE PLUGIN (prototype, 2026-10-09). A plugin install wires nothing in
288
293
  // these files — Claude Code loads its hooks and server from the plugin — so
289
294
  // without this the line told a plugin user "no hook of ours is connected,
290
295
  // run counterparts connect", which would wire the host twice. Enabled and
291
- // alone: connected. Enabled beside live npm wiring: the plugin stands down
292
- // (`adapters/plugin.ts`), which works, and is said, with both ways out.
296
+ // alone: connected. Enabled beside live npm wiring: the launcher flavor
297
+ // stands down (`adapters/plugin.ts`), the directory flavor runs beside it
298
+ // (below); either is said, with both ways out.
293
299
  const plugin = reading.plugin !== undefined && reading.plugin !== null && reading.plugin.enabled ? reading.plugin : null;
294
300
  data["plugin"] = plugin === null ? null : plugin.id;
295
301
  const npmAny = reading.events.length > 0 || reading.mcp;
@@ -305,13 +311,26 @@ export function hostFindings(reading: HostReading): Finding[] {
305
311
  ),
306
312
  ];
307
313
  }
314
+ // THE PLUGIN DIRECTORY'S BUILD DOES NOT STAND DOWN (2026-10-14): it never
315
+ // reads `~/.claude.json`, so it cannot tell this wiring is there, and both
316
+ // run, on the same memory, until a marker-based check lands (docs/plugin.md).
317
+ // Known two ways: this doctor IS that build (`mcpRead` false), or the
318
+ // installed plugin is (`standsDown` false, read from its `installPath`, the
319
+ // case of an npm doctor beside it). Unknown (null) keeps the launcher's word.
320
+ const bothRun = plugin !== null && (reading.mcpRead === false || plugin.standsDown === false);
308
321
  const twiceClause =
309
- plugin === null ? "" : `ALSO installed as the Claude Code plugin (${plugin.id}), which stands down while this wiring is live`;
322
+ plugin === null
323
+ ? ""
324
+ : bothRun
325
+ ? `ALSO installed as the Claude Code plugin (${plugin.id}), whose build does not check for the other install, so both are running, on the same memory: every hook and memory tool is wired twice until a later version checks`
326
+ : `ALSO installed as the Claude Code plugin (${plugin.id}), which stands down while this wiring is live`;
310
327
  const twiceFix =
311
328
  plugin === null
312
329
  ? ""
313
- : `Installed twice: to keep only the plugin, run \`counterparts disconnect\` and restart Claude Code; to keep only this install, run \`claude plugin uninstall ${plugin.id}\`. Same memory either way.`;
314
- const mcpClause = reading.mcp
330
+ : `Installed twice${bothRun ? "; remove one" : ""}: to keep only the plugin, run \`counterparts disconnect\` and restart Claude Code; to keep only this install, run \`claude plugin uninstall ${plugin.id}\`. Same memory either way.`;
331
+ const mcpClause = reading.mcpRead === false
332
+ ? ""
333
+ : reading.mcp
315
334
  ? `the MCP server is registered in ${reading.mcpFile}`
316
335
  : reading.mcpUnreadable
317
336
  ? `${reading.mcpFile} could not be read, so the MCP registration could not be checked`
@@ -362,8 +381,8 @@ export function hostFindings(reading: HostReading): Finding[] {
362
381
  // that one case the fix is the line `connect` itself prints: run it wherever
363
382
  // `claude` works. The hooks half, if it is owed, is still `connect`'s.
364
383
  const cannotRegister =
365
- !reading.mcp && !reading.mcpUnreadable && reading.claudeOnPath === false && reading.mcpAddLine !== undefined;
366
- if (!reading.mcp && !reading.mcpUnreadable && !cannotRegister) does.push("registers the memory tools");
384
+ reading.mcpRead !== false && !reading.mcp && !reading.mcpUnreadable && reading.claudeOnPath === false && reading.mcpAddLine !== undefined;
385
+ if (reading.mcpRead !== false && !reading.mcp && !reading.mcpUnreadable && !cannotRegister) does.push("registers the memory tools");
367
386
  const byHand = cannotRegister
368
387
  ? `\`claude\` is not on this PATH, so \`counterparts connect\` cannot register the memory tools: run this where \`claude\` works — ${reading.mcpAddLine ?? ""} — then restart Claude Code.`
369
388
  : "";
@@ -75,14 +75,13 @@
75
75
  * written in the PR, not claimed here.
76
76
  */
77
77
  import { randomUUID } from "node:crypto";
78
- import { fileURLToPath } from "node:url";
79
78
 
80
79
  import { Counterpart, MCP_SPILLED_EVENT } from "../../core/counterpart.js";
81
80
  import type { CounterpartEvent } from "../../core/counterpart.js";
82
81
  import { CATCH_UP_ONLY_REASONS } from "../../core/dream/index.js";
83
82
  import type { CatchUpOnlyReason, NightChildRun, NightPart, NightRun } from "../../core/dream/index.js";
84
83
  import { CONFIG_ENV as CONFIG_PATH_ENV } from "../config-path.js";
85
- import { scriptArgs } from "../runtime.js";
84
+ import { entryScript, scriptArgs } from "../runtime.js";
86
85
  import { TOOL_RESULT_CEILING } from "../../core/fit/index.js";
87
86
  import { installedVersion } from "../sessions.js";
88
87
  import { OBSERVER_ENV, OWNER_ENV } from "../stance-env.js";
@@ -173,7 +172,7 @@ export const DREAM_CHILD_DENIED = ["mcp__counterparts__reflect"] as const;
173
172
  export const NIGHT_MCP_SERVER = "counterparts";
174
173
 
175
174
  /** The MCP entry point beside this adapter — what the install registers (`cli/install.ts#MCP_SCRIPT`). */
176
- export const NIGHT_MCP_SCRIPT = fileURLToPath(new URL("../mcp/bin/serve.ts", import.meta.url));
175
+ export const NIGHT_MCP_SCRIPT = entryScript(new URL("../mcp/bin/serve.ts", import.meta.url));
177
176
 
178
177
  /**
179
178
  * THE ONE MCP SERVER THE CHILD LOADS (owner decision B): counterparts, as the
@@ -713,7 +713,7 @@ export const WAKE_HEAD_MAX_LINES = 40;
713
713
  * and the cost of missing it is a session that reads `not-found`, which is
714
714
  * INTERFACE-GAPS §11's residual.
715
715
  */
716
- export const COUNTERPARTS_HOOK_COMMAND = /claude-code[/\\]bin[/\\]hook\.ts|counterparts-hook/;
716
+ export const COUNTERPARTS_HOOK_COMMAND = /(adapters[/\\]claude-code[/\\]bin[/\\]hook\.js|claude-code[/\\]bin[/\\]hook\.ts)(?=$|["'\s])|counterparts-hook/;
717
717
 
718
718
  /**
719
719
  * The wake's two sentinels, recognised INSIDE a larger string rather than as a
@@ -29,14 +29,15 @@
29
29
  * rather than resolving as an answer nobody gave.
30
30
  */
31
31
  import { spawnSync } from "node:child_process";
32
+ import { realpathSync } from "node:fs";
32
33
  import { homedir } from "node:os";
33
34
  import { resolve } from "node:path";
34
35
  import { fileURLToPath } from "node:url";
35
36
 
36
- import { BINARY } from "../../runtime.js";
37
+ import { BINARY, TRANSPILED } from "../../runtime.js";
37
38
  import type { Binary } from "../../runtime.js";
38
39
  import { npmWiring } from "../../host-wiring.js";
39
- import { npmDoctorCommand, pluginDoctorLine, pluginOrigin, runningAsPlugin } from "../../plugin.js";
40
+ import { PACKAGE_ROOT, PLUGIN_ROOT_ENV, npmDoctorCommand, pluginDoctorLine, pluginOrigin, runningAsPlugin } from "../../plugin.js";
40
41
 
41
42
  import { run } from "../commands.js";
42
43
  import { echoPrompt, hiddenPrompt } from "../ui.js";
@@ -151,6 +152,12 @@ export function isEntryPoint(argv1: string | undefined, url: string, binary: Bin
151
152
  /** Run one console command and exit — what this file does as a script, and
152
153
  * what the single binary's `cli` mode calls. */
153
154
  export function start(): void {
155
+ // THE PLUGIN DIRECTORY'S BUNDLE (transpiled, no `plugin-run.sh`): this entry
156
+ // is what its commands run, from a Bash call that carries no
157
+ // CLAUDE_PLUGIN_ROOT, so it says what `plugin-run.sh cli` says for the full
158
+ // bundle: this console is the plugin's copy (`plugin.ts#runningAsPlugin`).
159
+ // The transpiled tree exists only as that bundle (`runtime.ts#TRANSPILED`).
160
+ if (TRANSPILED) process.env[PLUGIN_ROOT_ENV] = realpathSync(PACKAGE_ROOT);
154
161
  void main().then(
155
162
  (code) => process.exit(code),
156
163
  (err: unknown) => {
@@ -15,6 +15,7 @@ import { tilde } from "./wire.js";
15
15
  import { upgradeWords } from "../hosts.js";
16
16
  import { hostsSeen } from "../sessions.js";
17
17
  import { EXIT, hostConfigFor } from "./commands-shared.js";
18
+ import { storeId } from "../store-id.js";
18
19
  import type { Parsed, Io, RunOptions } from "./commands-shared.js";
19
20
 
20
21
  // ── dashboard ───────────────────────────────────────────────────────────────
@@ -70,6 +71,12 @@ export interface DashboardSeam {
70
71
  open?(url: string): void;
71
72
  /** Resolves when the person stops it. Ctrl-C, in a real run. */
72
73
  until?(): Promise<void>;
74
+ /**
75
+ * Which store the dashboard already holding `port` serves (its `/api/whoami`, on
76
+ * 127.0.0.1), or null: nothing answered, or not with a store id. Asked only when
77
+ * the port is taken.
78
+ */
79
+ storeAt?(port: number): Promise<string | null>;
73
80
  }
74
81
 
75
82
  /** The default port, restated rather than imported: naming it here costs one
@@ -157,9 +164,26 @@ export async function dashboardCommand(
157
164
  });
158
165
  } catch (err) {
159
166
  if ((err as { code?: string }).code === "EADDRINUSE") {
167
+ // THE PORT IS TAKEN. When what holds it is this store's own dashboard (the
168
+ // sidebar's button runs this command whether or not one is up), open the
169
+ // browser on it and succeed; anything else fails as before, said plainly.
170
+ const errPort = (err as { port?: unknown }).port;
171
+ const taken = typeof errPort === "number" && errPort > 0 ? errPort : (port ?? DASHBOARD_DEFAULT_PORT);
172
+ const serving = (await seam.storeAt?.(taken)) ?? null;
173
+ const ours = storeId(dir);
174
+ if (serving !== null && ours !== null && serving === ours) {
175
+ const url = `http://127.0.0.1:${String(taken)}`;
176
+ io.out(`Dashboard: ${url} (already running for this store; this command started nothing)`);
177
+ io.out(`reading ${tilde(dir, home_)}`);
178
+ if (parsed.flags["no-open"] !== true) seam.open?.(url);
179
+ return EXIT.ok;
180
+ }
160
181
  io.err(
161
- `Port ${String(port ?? DASHBOARD_DEFAULT_PORT)} is already in use — a dashboard may ` +
162
- "already be running. Pass --port <n> to use another one.",
182
+ serving !== null
183
+ ? `Port ${String(taken)} is already in use by a dashboard serving another store. ` +
184
+ "Pass --port <n> to use another one."
185
+ : `Port ${String(taken)} is already in use — a dashboard may ` +
186
+ "already be running. Pass --port <n> to use another one.",
163
187
  );
164
188
  return EXIT.failed;
165
189
  }
@@ -207,6 +231,11 @@ function realDashboard(env: Record<string, string | undefined>): DashboardSeam {
207
231
  openInBrowser(url, env);
208
232
  },
209
233
  until: untilInterrupted,
234
+ async storeAt(port: number): Promise<string | null> {
235
+ // LAZY for the same reason as the server: only a taken port pulls it in.
236
+ const { dashboardStoreAt } = await import("../dashboard/web/probe.js");
237
+ return dashboardStoreAt(port);
238
+ },
210
239
  };
211
240
  }
212
241
 
@@ -1,5 +1,6 @@
1
1
  /** `start-fresh`, its `--undo`, and `rollback` (moved out of `commands.ts`, 2026-10-11). */
2
2
  import { existsSync, renameSync } from "node:fs";
3
+ import { sidebarStatusPath, writeSidebarStatus } from "../sidebar-status.js";
3
4
  import { homedir } from "node:os";
4
5
  import { basename, dirname, isAbsolute, join, resolve } from "node:path";
5
6
  import {
@@ -57,6 +58,7 @@ import { installedVersion } from "../sessions.js";
57
58
  import { EXIT, hostConfigFor, openStoreAt, snapshotsDirBeside } from "./commands-shared.js";
58
59
  import type { Parsed, Io, RunOptions } from "./commands-shared.js";
59
60
  import { installCommand } from "./commands-install.js";
61
+ import { MODULE_EXT } from "../runtime.js";
60
62
 
61
63
  // ── start-fresh ─────────────────────────────────────────────────────────────
62
64
 
@@ -309,8 +311,8 @@ export async function startFreshCommand(
309
311
  io.out("");
310
312
  io.out(" What you CAN check, in another terminal:");
311
313
  io.out(" pgrep -fl counterparts");
312
- io.out(" Look for lines running one of OURS — serve.ts (an MCP server), dashboard.ts,");
313
- io.out(" hook.ts, runner.ts (the worker). Every one of those is holding the store open.");
314
+ io.out(` Look for lines running one of OURS — serve${MODULE_EXT} (an MCP server), dashboard${MODULE_EXT},`);
315
+ io.out(` hook${MODULE_EXT}, runner${MODULE_EXT} (the worker). Every one of those is holding the store open.`);
314
316
  io.out(" IGNORE anything that merely has the word in a path: `pgrep -f` matches the");
315
317
  io.out(" whole command line, so an editor, a `tail`, a dev server in a directory with");
316
318
  io.out(" this name in it will all show up and none of them matters. This command will");
@@ -524,6 +526,13 @@ export async function startFreshCommand(
524
526
 
525
527
  const created = parking ? final.storeDir : installTarget;
526
528
 
529
+ // THE SIDEBAR'S STATUS FILE (2026-10-14) showed the store just set aside, a
530
+ // few of its memories' words included: written again, now, for the new one
531
+ // (which is nothing yet). Only where there is one: the sidebar is installed.
532
+ if (existsSync(sidebarStatusPath(configPath))) {
533
+ writeSidebarStatus({ configPath, dataDir: created, ...(host.config.timeZone === undefined ? {} : { timeZone: host.config.timeZone }) });
534
+ }
535
+
527
536
  // ── the record the new store keeps of its own beginning ───────────────────
528
537
  //
529
538
  // Box 2's meta table, which is this store's general-purpose key space. NOT a
@@ -39,7 +39,7 @@ import { existsSync, readFileSync } from "node:fs";
39
39
  import { dirname } from "node:path";
40
40
 
41
41
  import { CONFIG_ENV } from "../config-path.js";
42
- import { scriptArgs } from "../runtime.js";
42
+ import { readsHostUserConfig, scriptArgs } from "../runtime.js";
43
43
  import { BIN, desktopConfigPath, hostConfigBase, hostMcpFile, isOurDesktopEntry, MCP_SCRIPT, MCP_SERVER_NAME } from "./install.js";
44
44
  import { sightSettings, tilde, unparsedSettingsWhy, writeSettings } from "./wire.js";
45
45
 
@@ -288,15 +288,20 @@ function dataDirOf(entry: unknown): string | null {
288
288
 
289
289
  /**
290
290
  * READ DESKTOP'S CONFIG FOR DOCTOR — two small file reads, never a write:
291
- * Desktop's own file, and Claude Code's `~/.claude.json` for the name clash.
291
+ * Desktop's own file, and Claude Code's `~/.claude.json` for the name clash —
292
+ * not opened by the plugin directory's build (`runtime.ts#readsHostUserConfig`),
293
+ * which then reports no clash.
292
294
  */
293
- export function readDesktop(home: string, env: Record<string, string | undefined> = {}): DesktopConfigReading {
295
+ export function readDesktop(
296
+ home: string,
297
+ env: Record<string, string | undefined> = {},
298
+ readsUserConfig: boolean = readsHostUserConfig(),
299
+ ): DesktopConfigReading {
294
300
  const path = desktopConfigPath(home);
295
301
  const read = readObject(path);
296
302
  const servers = read.value["mcpServers"];
297
303
  const ours = isRecord(servers) ? servers[MCP_SERVER_NAME] : undefined;
298
- const code = readObject(hostMcpFile(hostConfigBase(home, env)));
299
- const codeServers = code.value["mcpServers"];
304
+ const codeServers = readsUserConfig ? readObject(hostMcpFile(hostConfigBase(home, env))).value["mcpServers"] : undefined;
300
305
  const codeOurs = isRecord(codeServers) ? codeServers[MCP_SERVER_NAME] : undefined;
301
306
  return {
302
307
  path,
@@ -470,9 +470,10 @@ export const COMMAND_DETAIL: Record<string, readonly string[]> = {
470
470
  "A settings file it cannot parse is a refusal: it changes nothing and",
471
471
  "prints the block for you to merge by hand.",
472
472
  "",
473
- "The MCP server is registered by running `claude mcp add`; it never writes",
474
- "~/.claude.json itself, because Claude Code owns that file. If `claude` is",
475
- "not on your PATH the hooks still go in and the line is printed for you.",
473
+ "The MCP server is registered by running `claude mcp add`; it never edits",
474
+ "Claude Code's user configuration file itself, because Claude Code owns it.",
475
+ "If `claude` is not on your PATH the hooks still go in and the line is",
476
+ "printed for you.",
476
477
  "",
477
478
  "Claude Code is the one host it knows today, so `counterparts connect` and",
478
479
  "`counterparts connect claude-code` are the same thing and any other name",
@@ -52,7 +52,6 @@ import {
52
52
  import { isDay } from "../../core/time.js";
53
53
  import { homedir, tmpdir } from "node:os";
54
54
  import { basename, dirname, join, resolve } from "node:path";
55
- import { fileURLToPath } from "node:url";
56
55
 
57
56
  /** The store directory under the base. Named, because three files agree on it. */
58
57
  export const DEFAULT_STORE_DIR = "store";
@@ -60,7 +59,7 @@ export const DEFAULT_STORE_DIR = "store";
60
59
  import { EMBEDDER_KINDS } from "../config.js";
61
60
  import type { EmbedderKind } from "../config.js";
62
61
  import { CONFIG_ENV, CONFIG_FLAG, defaultConfigPath } from "../config-path.js";
63
- import { parseScriptInvocation, runtimeOf, runtimePresent, scriptArgs, shellTokens } from "../runtime.js";
62
+ import { entryScript, parseScriptInvocation, readsHostUserConfig, runtimeOf, runtimePresent, scriptArgs, shellTokens } from "../runtime.js";
64
63
  import type { RuntimeKind } from "../runtime.js";
65
64
  import { pluginInstall, readOurHook } from "../host-wiring.js";
66
65
  import type { PluginInstallRead } from "../host-wiring.js";
@@ -112,8 +111,8 @@ export const MCP_SERVER_NAME = "counterparts";
112
111
  * RUNNER_PATH]`). The short names stay on PATH for a human at a terminal; they
113
112
  * are not what goes into a host's configuration.
114
113
  */
115
- export const HOOK_SCRIPT = fileURLToPath(new URL("../claude-code/bin/hook.ts", import.meta.url));
116
- export const MCP_SCRIPT = fileURLToPath(new URL("../mcp/bin/serve.ts", import.meta.url));
114
+ export const HOOK_SCRIPT = entryScript(new URL("../claude-code/bin/hook.ts", import.meta.url));
115
+ export const MCP_SCRIPT = entryScript(new URL("../mcp/bin/serve.ts", import.meta.url));
117
116
 
118
117
  /** Double-quote a path so a shell keeps it whole. Paths with `"` are refused
119
118
  * by being escaped rather than silently mangled. */
@@ -578,6 +577,10 @@ export interface HostRead {
578
577
  readonly mcpName: string;
579
578
  readonly mcpFile: string;
580
579
  readonly mcpUnreadable: boolean;
580
+ /** False when this build does not open the MCP file at all
581
+ * (`runtime.ts#readsHostUserConfig`, the plugin directory's bundle): `mcp`
582
+ * is then "not looked", never "not registered". */
583
+ readonly mcpRead: boolean;
581
584
  /** The runtimes our hook commands and our MCP registration name, one row
582
585
  * per distinct executable (`adapters/runtime.ts`), and whether each is there. */
583
586
  readonly runtimes: readonly HostRuntime[];
@@ -620,7 +623,7 @@ export function isOurDesktopEntry(entry: unknown): entry is { command: string; a
620
623
  if (typeof command !== "string" || !Array.isArray(args) || !args.every((a) => typeof a === "string")) return false;
621
624
  const run = parseScriptInvocation([command, ...(args as string[])]);
622
625
  if (run === null || run.rest.length > 0) return false;
623
- return run.mode === "mcp" || (run.mode === undefined && /mcp[/\\]bin[/\\]serve\.ts$/.test(run.script));
626
+ return run.mode === "mcp" || (run.mode === undefined && /((^|[/\\])adapters[/\\]mcp[/\\]bin[/\\]serve\.js|mcp[/\\]bin[/\\]serve\.ts)$/.test(run.script));
624
627
  }
625
628
 
626
629
  /** One runtime a host's configuration launches us with. */
@@ -649,10 +652,12 @@ export interface HostRuntime {
649
652
  * (`"<…>/counterparts" hook`, `runtime.ts#parseScriptInvocation`). It matches
650
653
  * the entry's `.mjs` shim as well as `hook.ts` (2026-10-09, with
651
654
  * `host-wiring.ts#readOurHook`): a line that runs our hook is ours to report,
652
- * whatever flags or entry file a later version writes.
655
+ * whatever flags or entry file a later version writes. The entry ends at its
656
+ * extension, and the transpiled tree's `.js` is read only under `adapters/`
657
+ * (review of #475): a bare `claude-code/bin/hook.js` is another tool's.
653
658
  */
654
659
  export const HOOK_COMMAND_MARK =
655
- /(^|[\s"'=/\\])counterparts-hook(\s|$|")|claude-code[/\\]bin[/\\]hook\.(ts|mjs)|[/\\]counterparts(\.exe)?"?\s+hook(\s|$)/;
660
+ /(^|[\s"'=/\\])counterparts-hook(\s|$|")|(adapters[/\\]claude-code[/\\]bin[/\\]hook\.js|claude-code[/\\]bin[/\\]hook\.(ts|mjs))(?=$|["'\s])|[/\\]counterparts(\.exe)?"?\s+hook(\s|$)/;
656
661
 
657
662
  /**
658
663
  * The absolute path a hook command runs, when it names one — the first token
@@ -762,6 +767,7 @@ export function readHost(
762
767
  home: string,
763
768
  cwd: string,
764
769
  env: Record<string, string | undefined> = process.env,
770
+ readsUserConfig: boolean = readsHostUserConfig(),
765
771
  ): HostRead {
766
772
  const base = hostConfigBase(home, env);
767
773
  const events = new Set<string>();
@@ -828,7 +834,8 @@ export function readHost(
828
834
  }
829
835
  }
830
836
  const mcpFile = hostMcpFile(base);
831
- const mcpRead = readJsonFile(mcpFile);
837
+ // Not opened by the plugin directory's build (`runtime.ts#readsHostUserConfig`).
838
+ const mcpRead: ReturnType<typeof readJsonFile> = readsUserConfig ? readJsonFile(mcpFile) : { state: "absent", value: {} };
832
839
  const servers = mcpRead.value["mcpServers"];
833
840
  const mcp =
834
841
  servers !== null &&
@@ -868,6 +875,7 @@ export function readHost(
868
875
  mcpName: MCP_SERVER_NAME,
869
876
  mcpFile,
870
877
  mcpUnreadable: mcpRead.state === "unreadable",
878
+ mcpRead: readsUserConfig,
871
879
  runtimes: [...runtimes.entries()].map(([exe, row]) => ({
872
880
  exe,
873
881
  kind: row.kind,
@@ -79,6 +79,7 @@ import type {
79
79
  // destruction path. It is reachable by importing the seam on purpose, never by
80
80
  // holding a `Store` (INTERFACE-GAPS §1, closed 2026-08-25).
81
81
  import { chaseRemoved } from "../../core/store/owner-op-seam.js";
82
+ import { chaseSidebarStatus } from "../sidebar-status.js";
82
83
  // The page has its own door out (`self-page --clear`), and removal is not it.
83
84
  import { isSelfPageRow } from "../../core/self/page.js";
84
85
 
@@ -1061,6 +1062,12 @@ export function ownerRemoval(
1061
1062
  // have already gone.
1062
1063
  chaseWriteAheadLog(store.dir, chased, unchased);
1063
1064
 
1065
+ // THE SIDEBAR'S STATUS FILE (2026-10-14) holds a few memories' words for the
1066
+ // Claude Code sidebar, beside the configuration: deleted when it names this
1067
+ // one, and written again without it (`adapters/sidebar-status.ts`).
1068
+ const sidebar = chaseSidebarStatus(store.dir, request.targetId);
1069
+ if (sidebar !== null) (sidebar.chased ? chased : unchased).push(sidebar.line);
1070
+
1064
1071
  // THE DURABLE RECORD MUST NOT CLAIM MORE THAN THE CONSOLE (third review's
1065
1072
  // open question). The record's stages carry no surface list, so `complete`
1066
1073
  // has always meant "the ceremony finished", not "everything was reached" —