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
@@ -62,6 +62,7 @@ import { hostScope, openServer } from "../index.js";
62
62
  import { openLog } from "../../log/index.js";
63
63
  import type { LogEvent, ProcessLog } from "../../log/index.js";
64
64
  import { serveStdio } from "../stdio.js";
65
+ import { SidebarStatusWriter, removeSidebarStatus, sidebarInstalled } from "../../sidebar-status.js";
65
66
  import { stoodDownServer } from "../stood-down.js";
66
67
  import { npmWiring } from "../../host-wiring.js";
67
68
  import { PLUGIN_ROOT_ENV, ensureFirstRun, installRoute, mcpGate, pluginOrigin, runningAsPlugin } from "../../plugin.js";
@@ -316,6 +317,13 @@ export function serverConfigChoice(
316
317
  return resolveConfigPath(argv, env as Record<string, string | undefined>);
317
318
  }
318
319
 
320
+ /** The sidebar's status file: first written this long after the server starts… */
321
+ export const SIDEBAR_START_MS = 3000;
322
+ /** …this long after a tool call (one write for a burst of calls)… */
323
+ export const SIDEBAR_AFTER_CALL_MS = 1500;
324
+ /** …and the log's newest seq is looked at this often (one indexed read). */
325
+ export const SIDEBAR_WATCH_MS = 15000;
326
+
319
327
  async function main(): Promise<void> {
320
328
  const { unreadable: stanceNotices, ...opts } = launchOptions(process.argv.slice(2), process.env);
321
329
  // stderr, never stdout (stdout is the JSON-RPC wire), and BEFORE the config
@@ -434,10 +442,14 @@ async function main(): Promise<void> {
434
442
  // THE OWNER'S OWN SESSIONS ARE THE OWNER (owner ruling 2026-10-02): `ownerStance`.
435
443
  const { ownerSaid, ...launch } = opts;
436
444
  const ownerSays = ownerStance({ owner: launch.owner, ownerSaid }, config, startedByClaudeCode);
445
+ // THE SIDEBAR'S STATUS FILE (2026-10-14, `adapters/sidebar-status.ts`):
446
+ // armed below once the store is open; a tool call only schedules a write.
447
+ let sidebar: SidebarStatusWriter | null = null;
437
448
  const server = openServer({
438
449
  ...launch,
439
450
  ...ownerSays,
440
451
  onEvent: toLog,
452
+ afterCall: () => sidebar?.schedule(SIDEBAR_AFTER_CALL_MS),
441
453
  onCounterpartEvent: toLog,
442
454
  // THE COMBINATION, most restrictive wins: a registry that says `observer`
443
455
  // stands the server down even when the configuration did not, and a
@@ -503,6 +515,26 @@ async function main(): Promise<void> {
503
515
  });
504
516
  log = opened;
505
517
  opened.start({ boundSession: server.launchedSession !== null });
518
+ // What the Claude Code sidebar shows, written beside the configuration: a
519
+ // few seconds after this server starts (a session's start, off the
520
+ // SessionStart hook's path), a moment after each tool call, and whenever the
521
+ // log moved under it (a turn's recall, another session, the night). Never
522
+ // for an observer or in a directory set `off`, and never on a call's path.
523
+ // Only where the sidebar is installed (the plugin): elsewhere an old file goes.
524
+ const sidebarWanted = sidebarInstalled(process.env, homedir());
525
+ if (!sidebarWanted) removeSidebarStatus(choice.path);
526
+ if (sidebarWanted && !server.observer && stance !== "off") {
527
+ const store = server.counterpart.store;
528
+ sidebar = new SidebarStatusWriter({
529
+ configPath: choice.path,
530
+ dataDir: store.dir,
531
+ ...(timeZone === undefined ? {} : { timeZone }),
532
+ newestSeq: () => store.eventLog({ order: "desc", limit: 1 })[0]?.seq ?? null,
533
+ onWrite: (w) => toLog({ name: "mcp.sidebar", data: { written: w.written, reason: w.reason, bytes: w.bytes, ms: w.ms } }),
534
+ });
535
+ sidebar.schedule(SIDEBAR_START_MS);
536
+ sidebar.watch(SIDEBAR_WATCH_MS);
537
+ }
506
538
  try {
507
539
  await serveStdio(server, process.stdin, {
508
540
  write: (chunk) => {
@@ -514,6 +546,7 @@ async function main(): Promise<void> {
514
546
  opened.threw(err);
515
547
  throw err;
516
548
  } finally {
549
+ sidebar?.stop();
517
550
  server.forgetLaunch();
518
551
  server.counterpart.close();
519
552
  }
@@ -175,6 +175,7 @@ export function openServer(opts: OpenServerOptions = {}): McpServer {
175
175
  ...(opts.ownerFrom === undefined ? {} : { ownerFrom: opts.ownerFrom }),
176
176
  ...(opts.codeTabOwner === undefined ? {} : { codeTabOwner: opts.codeTabOwner }),
177
177
  ...(opts.onEvent === undefined ? {} : { onEvent: opts.onEvent }),
178
+ ...(opts.afterCall === undefined ? {} : { afterCall: opts.afterCall }),
178
179
  ...(opts.now === undefined ? {} : { now: opts.now }),
179
180
  });
180
181
  }
@@ -168,6 +168,13 @@ export interface McpServerOptions {
168
168
  */
169
169
  launchObserver?: boolean;
170
170
  onEvent?: (e: McpEvent) => void;
171
+ /**
172
+ * Told after every tool call over the wire has its answer, before the answer
173
+ * is written back: the tool's name. It must only SCHEDULE work (the entry
174
+ * point arms the sidebar's status file this way, `adapters/sidebar-status.ts`)
175
+ * — anything it does inline is time the client waits. A throw is swallowed.
176
+ */
177
+ afterCall?: (tool: string) => void;
171
178
  now?: () => number;
172
179
  }
173
180
 
@@ -19,7 +19,7 @@ export const SERVER_NAME = "counterparts";
19
19
  * host decides whether to trust what follows. Read from a constant rather than
20
20
  * from disk so the server opens no file to answer its first message.
21
21
  */
22
- export const SERVER_VERSION = "0.3.21";
22
+ export const SERVER_VERSION = "0.3.23";
23
23
 
24
24
  /**
25
25
  * THE ONE LINE EVERY TOOL ANSWERS WITH when the store on disk is a schema AHEAD
@@ -292,6 +292,7 @@ export class McpServer {
292
292
  private readonly sessionTtlMs: number;
293
293
  private readonly resultCeilingChars: number;
294
294
  private readonly onEvent: ((e: McpEvent) => void) | undefined;
295
+ private readonly afterCall: ((tool: string) => void) | undefined;
295
296
  private readonly nowFn: () => number;
296
297
  private readonly ring: McpEvent[] = [];
297
298
  /**
@@ -378,6 +379,7 @@ export class McpServer {
378
379
  this.codeTabOwner = opts.codeTabOwner === true;
379
380
  this.embedderGiven = opts.embedder ?? null;
380
381
  this.onEvent = opts.onEvent;
382
+ this.afterCall = opts.afterCall;
381
383
  this.nowFn = opts.now ?? ((): number => Date.now());
382
384
  // LAST in the constructor — `emit` needs `nowFn`. A scope nobody chose is
383
385
  // the bug this run measured, so which default won is on the record from the
@@ -622,6 +624,11 @@ export class McpServer {
622
624
  return failure(id, ERROR_CODES.INVALID_PARAMS, "arguments must be an object");
623
625
  }
624
626
  const result = await this.call(name, (args as Record<string, unknown>) ?? {});
627
+ try {
628
+ this.afterCall?.(canonicalToolName(name));
629
+ } catch {
630
+ // a listener's trouble is never the tool's answer
631
+ }
625
632
  return success(id, result as unknown as Record<string, unknown>);
626
633
  }
627
634
 
@@ -173,6 +173,51 @@ export interface ToolSpec {
173
173
  */
174
174
  readonly engine?: readonly Privilege[];
175
175
  readonly inputSchema: Record<string, unknown>;
176
+ /** MCP's tool annotations (`ToolAnnotations`, spec 2025-06-18): hints a host
177
+ * shows or acts on — a short human name, and whether the tool writes,
178
+ * destroys or reaches beyond this machine. Served in `tools/list`. */
179
+ readonly annotations: ToolAnnotations;
180
+ }
181
+
182
+ /**
183
+ * MCP TOOL ANNOTATIONS (2026-10-14, for the Software Directory's policy §5E:
184
+ * "provide all applicable tool annotations, in particular readOnlyHint,
185
+ * destructiveHint, and title"). Hints, not guarantees — a host must not trust
186
+ * them for safety — but they are kept true to the code:
187
+ *
188
+ * - `readOnlyHint` is true only for a tool that never changes the store, a file
189
+ * or a setting. Diagnostic events (the ring, the adapter-event telemetry
190
+ * rows every tool may leave) do not count as a change; anything a later
191
+ * strengthening, fading or wake reads does — so `recall` is NOT read-only:
192
+ * what it delivers is recorded for this session (`Counterpart#noteAsked`, a
193
+ * gate record), and the boundary's credit pass strengthens a memory opened
194
+ * or quoted from it.
195
+ * - `destructiveHint` is true only where a call can take away what was there
196
+ * without keeping it. Every rewrite through the store's one door archives
197
+ * what it replaces (`store#revise`, archive-on-overwrite), a merge keeps its
198
+ * originals and a retired handoff stays readable by id, so the writers are
199
+ * additive. `dream` is destructive: its `undo` phase removes a dream's
200
+ * links and gists.
201
+ * - `idempotentHint` is true only where a repeat call with the same arguments
202
+ * leaves nothing more behind; `openWorldHint` is false for every tool —
203
+ * all of them work on this machine's store and files only.
204
+ */
205
+ export interface ToolAnnotations {
206
+ readonly title: string;
207
+ readonly readOnlyHint: boolean;
208
+ readonly destructiveHint: boolean;
209
+ readonly idempotentHint: boolean;
210
+ readonly openWorldHint: boolean;
211
+ }
212
+
213
+ function annotate(title: string, hints: { readOnly: boolean; destructive?: boolean; idempotent?: boolean }): ToolAnnotations {
214
+ return {
215
+ title,
216
+ readOnlyHint: hints.readOnly,
217
+ destructiveHint: hints.destructive ?? false,
218
+ idempotentHint: hints.idempotent ?? hints.readOnly,
219
+ openWorldHint: false,
220
+ };
176
221
  }
177
222
 
178
223
  /**
@@ -553,6 +598,7 @@ const RELEVANCE_TEXT = "Optional 0-1: how much this bears on them, on you, or on
553
598
  */
554
599
  const REMEMBER: ToolSpec = {
555
600
  name: "remember",
601
+ annotations: annotate("Remember", { readOnly: false }),
556
602
  summary:
557
603
  "Remember something now, while it is in front of you. Memory forms only from what you write here and at the end-of-session ask — nothing reads the transcript afterwards, so what you don't write is not kept. Write what caught your attention: a line you read and why it struck you, something they said about themselves or you, news you passed on, a decision, a work event. One idea per call; keep the exact words when the words matter.",
558
604
  admission:
@@ -704,6 +750,7 @@ const REMEMBER: ToolSpec = {
704
750
 
705
751
  const RECALL: ToolSpec = {
706
752
  name: "recall",
753
+ annotations: annotate("Recall memories", { readOnly: false }),
707
754
  summary:
708
755
  "Deliberate retrieval: a look you take on purpose, beyond the ambient reminding you already get. Three kinds of ask, one per call — a question with a mode (facts or meaning), ids to read memories whole, or a handle (an id or an exact title) to read one.",
709
756
  admission:
@@ -854,6 +901,7 @@ const RECALL: ToolSpec = {
854
901
 
855
902
  const STATUS: ToolSpec = {
856
903
  name: "status",
904
+ annotations: annotate("Memory status", { readOnly: true }),
857
905
  summary:
858
906
  "The census: how much is held, of what kinds, in which bands, how much has left, and how much was removed. Counts and dates only.",
859
907
  admission:
@@ -913,6 +961,7 @@ const DREW_ON_PRIVILEGE = {
913
961
 
914
962
  const SESSION_END: ToolSpec = {
915
963
  name: "session_end",
964
+ annotations: annotate("End session", { readOnly: false }),
916
965
  summary:
917
966
  "The memories half of the end-of-session ask: hand back what caught your attention since you last wrote, one idea per entry, in your own words. With `remember`, this is the only road from conversation to memory — nothing sweeps the transcript. The other half is `chapter`.",
918
967
  admission:
@@ -1126,6 +1175,7 @@ const SESSION_END: ToolSpec = {
1126
1175
  */
1127
1176
  const CHAPTER: ToolSpec = {
1128
1177
  name: "chapter",
1178
+ annotations: annotate("Write a chapter", { readOnly: false }),
1129
1179
  summary:
1130
1180
  "The episode's return channel: write this stretch of the session into your first-person journal — a diary of what happened, in your own voice, at any length. The journal stays open — when something significant happens later, append to it in the moment.",
1131
1181
  admission:
@@ -1218,6 +1268,7 @@ const CHAPTER: ToolSpec = {
1218
1268
  */
1219
1269
  const SCOPE: ToolSpec = {
1220
1270
  name: "scope",
1271
+ annotations: annotate("Directory scope", { readOnly: false }),
1221
1272
  summary:
1222
1273
  "Which directories this memory is for. Read what this one is set to — on, observer (reads only), off, paused, or unset — and set it when the user says. It changes the host's own configuration; it writes no memory and reads none.",
1223
1274
  admission:
@@ -1290,6 +1341,7 @@ const SCOPE: ToolSpec = {
1290
1341
  */
1291
1342
  const SELF_PAGE: ToolSpec = {
1292
1343
  name: "self_page",
1344
+ annotations: annotate("Self page", { readOnly: false }),
1293
1345
  summary: `Your own page — the prose that opens every wake under 'Who I am'. No arguments: read it and when it was last revised. With \`body\`: write the whole page anew — a stable \`## Core\` that has to be earned and a \`## Lately\` for what the last while has been like, by convention; any other \`##\` section is kept too. Aim under ${String(PAGE_ROOM_BYTES)} bytes: a longer page is kept whole, but on a day the wake has no room for it, sessions read a short version instead — so with a longer page send \`short\` too (under ${String(PAGE_ROOM_BYTES)}), or add one later with \`short\` alone.`,
1294
1346
  admission:
1295
1347
  "Call it to READ when you want the page as it stands rather than as the wake abridged it. Call it to WRITE when something you now know about yourself is not on the page and will still be true next month: a way of working that has held up, a correction the user made about you, a standing preference of theirs you keep rediscovering. Date the claims that need dating, say what made you believe them, and phrase what you have learned as practice — what you do now — rather than as praise.",
@@ -1399,6 +1451,7 @@ const SELF_PAGE: ToolSpec = {
1399
1451
  */
1400
1452
  const DREAM: ToolSpec = {
1401
1453
  name: "dream",
1454
+ annotations: annotate("Dream", { readOnly: false, destructive: true }),
1402
1455
  summary:
1403
1456
  "Dreaming, in the nightly run: a few minutes of replay over what was lived since the last dream — merging near-copies, linking what belongs together, replaying what matters, writing a pattern you notice, flagging a contradiction, recording how an old feeling sits now — kept in a dream journal and reversible as a whole — with the page writer before it and a reflection after it, in one background run. Phases: `launch` (the prompt for the background run), `begin` / `propose` / `journal` (the dreamer's), `writer` (the night's page writer: the day to read), `decline` (not today), `setting` (auto, ask or off — 'no dreams' is off).",
1404
1457
  admission:
@@ -1541,6 +1594,7 @@ const DREAM: ToolSpec = {
1541
1594
  */
1542
1595
  const REFLECT: ToolSpec = {
1543
1596
  name: "reflect",
1597
+ annotations: annotate("Reflect", { readOnly: false }),
1544
1598
  summary:
1545
1599
  "Reflection: a few quiet, awake minutes — usually at the end of the nightly run, after the dream — answering two or three questions about yourself, the owner and the two of you, citing the memories your thoughts rest on. It keeps a lived entry, may rewrite your self page from the memories it cites, leaves a short morning share for the owner, can record how a memory feels to you now and what a memory is about. Phases: `launch` (a reflection on its own, for a background agent), `begin` / `part` / `finish` (the reflecting mind's — `part` fetches the rest of a bundle that came in parts), `settle` (two memories it was shown that disagree, when the reason is plain), `told` (the share was told).",
1546
1600
  admission:
@@ -1700,6 +1754,7 @@ const REFLECT: ToolSpec = {
1700
1754
  */
1701
1755
  const MEET: ToolSpec = {
1702
1756
  name: "meet",
1757
+ annotations: annotate("Meet", { readOnly: false }),
1703
1758
  summary: "The first meeting with the person. No step: the script, and where it stands. With step: record that step.",
1704
1759
  admission: "the wake says you haven't met, or they ask to.",
1705
1760
  negativeExamples: ["Do NOT start it unasked mid-task: offer it once."],
@@ -1747,6 +1802,7 @@ export const TOOLS: readonly ToolSpec[] = [
1747
1802
  */
1748
1803
  export const WAKE: ToolSpec = {
1749
1804
  name: "wake",
1805
+ annotations: annotate("Wake", { readOnly: false }),
1750
1806
  summary:
1751
1807
  "Start here in Claude Desktop: wakes this chat's memory. Returns the same briefing a Claude Code session gets when it starts — who I am, what is nearby and arriving, any reminder due today — and a session id for this chat.",
1752
1808
  admission:
@@ -1869,7 +1925,9 @@ export function renderDescription(spec: ToolSpec): string {
1869
1925
  export function toolDefinitions(desktop = false): Record<string, unknown>[] {
1870
1926
  return (desktop ? DESKTOP_TOOLS : TOOLS).map((spec) => ({
1871
1927
  name: spec.name,
1928
+ title: spec.annotations.title,
1872
1929
  description: renderDescription(spec),
1873
1930
  inputSchema: spec.inputSchema,
1931
+ annotations: spec.annotations,
1874
1932
  }));
1875
1933
  }
@@ -282,8 +282,9 @@ export function npmDoctorCommand(wiring: NpmWiring): { readonly exe: string; rea
282
282
  const config = at >= 0 && call.rest[at + 1] !== undefined ? ["--config", call.rest[at + 1] as string] : [];
283
283
  // The single binary is its own install: `<binary> cli doctor`.
284
284
  if (call.runtime === "binary") return { exe: call.exe, args: ["cli", "doctor", ...config] };
285
- // `<root>/src/adapters/claude-code/bin/hook.ts` or `<root>/src/adapters/mcp/bin/serve.ts`.
286
- const cli = join(dirname(call.script), "..", "..", "cli", "bin", "counterparts.ts");
285
+ // `<root>/src/adapters/claude-code/bin/hook.ts` or `<root>/src/adapters/mcp/bin/serve.ts`
286
+ // (`.js`, both, in a transpiled tree: runtime.ts#entryScript).
287
+ const cli = join(dirname(call.script), "..", "..", "cli", "bin", `counterparts${call.script.endsWith(".js") ? ".js" : ".ts"}`);
287
288
  if (!existsSync(cli)) continue;
288
289
  // Whatever the wiring put between the runtime and its script, as written:
289
290
  // Bun's `--no-env-file "--config=…/empty-bunfig.toml" run`, or Node's
@@ -2,7 +2,9 @@
2
2
  * WHICH RUNTIME RUNS A SCRIPT, and the arguments that say so — the one place
3
3
  * that knows the difference between Bun and Node.
4
4
  *
5
- * The sources are TypeScript and there is no build step. Bun runs them as they
5
+ * The sources are TypeScript and there is no build step (one exception: the
6
+ * plugin directory's bundle carries them transpiled to `.js`, `TRANSPILED`
7
+ * below, and its scripts follow `entryScript`). Bun runs them as they
6
8
  * are (`bun run <script.ts>`); Node runs them with `node-hooks.mjs` loaded first
7
9
  * (`node --import <node-hooks.mjs> <script.ts>`), which resolves the sources'
8
10
  * `./x.js` imports to `./x.ts` and strips the types. Every command this package
@@ -88,6 +90,60 @@ export function binaryOf(moduleUrl: string, self: string): Binary | null {
88
90
  /** This process, if it is the compiled binary; null from source. */
89
91
  export const BINARY: Binary | null = binaryOf(import.meta.url, process.execPath);
90
92
 
93
+ // ── the transpiled tree (tools/plugin-bundle/build.ts --flavor directory) ──
94
+ //
95
+ // The plugin directory's bundle carries these sources transpiled one for one,
96
+ // `src/x.ts` → `src/x.js`, types and comments stripped, its entries started by
97
+ // their own shebang (2026-10-14: the directory's validator times out on ~7 MB
98
+ // of commented TypeScript). A tree is all one or all the other, so a script
99
+ // another process runs is named in source by its `.ts` path and takes the
100
+ // extension of the tree it is in from this module's own URL.
101
+
102
+ /** `.js` in the transpiled tree; `.ts` from source and in the single binary
103
+ * (whose entries are found by name, `binaryModeOf`). Pure: a test hands it a
104
+ * URL of either shape. */
105
+ export function moduleExtOf(moduleUrl: string, binary: Binary | null = BINARY): ".ts" | ".js" {
106
+ return binary === null && /\.js$/.test(moduleUrl) ? ".js" : ".ts";
107
+ }
108
+
109
+ /** The extension this package's modules carry where they run now. */
110
+ export const MODULE_EXT: ".ts" | ".js" = moduleExtOf(import.meta.url);
111
+
112
+ /** Is this process running the transpiled tree? It exists only as the plugin
113
+ * directory's bundle, which has no `plugin-run.sh`: Claude Code starts its
114
+ * entries by their shebang. */
115
+ export const TRANSPILED: boolean = MODULE_EXT === ".js";
116
+
117
+ /**
118
+ * Does this build read Claude Code's user configuration, `~/.claude.json`
119
+ * (`$CLAUDE_CONFIG_DIR/.claude.json`)? Yes everywhere but the transpiled tree,
120
+ * the plugin directory's bundle (2026-10-14, owner's decision): there nothing
121
+ * opens that file. What that build gives up, every reader gated on this says:
122
+ * the plugin no longer stands down beside the npm install's wiring (memory
123
+ * wired twice until a marker-based check lands, docs/plugin.md), doctor has
124
+ * no MCP-registration line and no Desktop Code-tab clash, and an uninstall has
125
+ * only `claude mcp remove`'s word that a `-s user` registration is gone (with
126
+ * no `claude`, it says the line to run and does not count it gone). The
127
+ * stand-down check (`host-wiring.ts#npmWiring`) reads nothing at all in this
128
+ * build, the settings files' hooks included; doctor, connect and uninstall
129
+ * still read the settings files, and `plugins/installed_plugins.json` is
130
+ * still read. `transpiled` is a test's seam.
131
+ */
132
+ export function readsHostUserConfig(transpiled: boolean = TRANSPILED): boolean {
133
+ return !transpiled;
134
+ }
135
+
136
+ /**
137
+ * A script this package starts or names, written in source by its `.ts` path
138
+ * as a `new URL` from `import.meta.url` (a literal the bundle's tracer
139
+ * follows), as the file this tree holds: that path from source, its `.js`
140
+ * sibling in the transpiled tree.
141
+ */
142
+ export function entryScript(url: URL, ext: ".ts" | ".js" = MODULE_EXT): string {
143
+ const path = fileURLToPath(url);
144
+ return ext === ".js" ? path.replace(/\.ts$/, ".js") : path;
145
+ }
146
+
91
147
  /** Is this process (or the binary a test names) the compiled binary? */
92
148
  export function isCompiled(binary: Binary | null = BINARY): boolean {
93
149
  return binary !== null;
@@ -134,6 +190,12 @@ export function isBinaryName(exe: string): boolean {
134
190
  return /^counterparts([-.][\w.-]*)?$/i.test(name) && !/^counterparts-(hook|mcp|dashboard)(\.exe)?$/i.test(name);
135
191
  }
136
192
 
193
+ /** An entry script's mode by its file name: the source `.ts` name, or the
194
+ * transpiled tree's `.js` (`BINARY_MODE_OF` keeps the source names). */
195
+ export function binaryModeOf(script: string): BinaryMode | undefined {
196
+ return BINARY_MODE_OF[basename(script).replace(/\.js$/, ".ts")];
197
+ }
198
+
137
199
  function isBinaryMode(word: string | undefined): word is BinaryMode {
138
200
  return (BINARY_MODES as readonly string[]).includes(word ?? "");
139
201
  }
@@ -150,7 +212,22 @@ export const BUN_CONFIG_PREFIX = "--config=";
150
212
  export const NODE_HOOKS = fileURLToPath(new URL("./node-hooks.mjs", import.meta.url));
151
213
 
152
214
  /** The console's own entry, for a command line that must name Node explicitly. */
153
- export const CLI_SCRIPT = fileURLToPath(new URL("./cli/bin/counterparts.ts", import.meta.url));
215
+ export const CLI_SCRIPT = entryScript(new URL("./cli/bin/counterparts.ts", import.meta.url));
216
+
217
+ /**
218
+ * The plugin's console by the plugin's root, as the words typed before its
219
+ * arguments (`doctor`, `scope …`), for a line a person or a Bash call runs:
220
+ * the launcher, `sh <root>/src/adapters/plugin-run.sh cli`, which finds a
221
+ * runtime; or, in the plugin directory's transpiled bundle, which has no
222
+ * launcher, the console's own entry, started by its shebang. Read off the
223
+ * disk; a root holding neither gets the launcher's words.
224
+ */
225
+ export function pluginConsoleWords(root: string): string[] {
226
+ const launcher = join(root, "src", "adapters", "plugin-run.sh");
227
+ const entry = join(root, "src", "adapters", "cli", "bin", "counterparts.js");
228
+ if (!existsSync(launcher) && existsSync(entry)) return [entry];
229
+ return ["sh", launcher, "cli"];
230
+ }
154
231
 
155
232
  /** The oldest Node this has been made to run on: `module.registerHooks`
156
233
  * (22.15 / 23.5), `stripTypeScriptTypes` and unflagged `node:sqlite` (22.13). */
@@ -182,7 +259,7 @@ export function runtimeOf(exe: string): RuntimeKind {
182
259
  * `.env` or `bunfig.toml` (it is built with both off). */
183
260
  export function scriptArgs(script: string, exe: string = process.execPath, binary: Binary | null = BINARY): string[] {
184
261
  // The compiled binary runs ITSELF in another mode: `<binary> runner`.
185
- const mode = binary !== null && exe === binary.self ? BINARY_MODE_OF[basename(script)] : undefined;
262
+ const mode = binary !== null && exe === binary.self ? binaryModeOf(script) : undefined;
186
263
  if (mode !== undefined) return [mode];
187
264
  return runtimeOf(exe) === "node"
188
265
  ? ["--import", NODE_HOOKS, script]
@@ -64,6 +64,7 @@ import { basename, dirname, join, resolve, sep } from "node:path";
64
64
 
65
65
  import { defaultConfigPath } from "./config-path.js";
66
66
  import { isPseudoScope } from "./hosts.js";
67
+ import { pluginConsoleWords } from "./runtime.js";
67
68
 
68
69
  /**
69
70
  * `sessions.ts#canonicalScope`, extended by one step this rule needs and that
@@ -719,7 +720,7 @@ export function scopeCommand(folder: string, flag: string, ctx: ScopeCommandCont
719
720
  const config = ctx.configPath === null ? "" : ` --config ${shellWord(ctx.configPath, ctx.home)}`;
720
721
  return ctx.pluginRoot === null
721
722
  ? `counterparts scope ${target} ${flag}${config}`
722
- : `sh ${shellWord(join(ctx.pluginRoot, "src", "adapters", "plugin-run.sh"), ctx.home)} cli scope ${target} ${flag}${config}`;
723
+ : `${pluginConsoleWords(ctx.pluginRoot).map((w) => shellWord(w, ctx.home)).join(" ")} scope ${target} ${flag}${config}`;
723
724
  }
724
725
 
725
726
  /** `path` with the home directory as `~`, for reading. Both spellings of home