counterparts 0.3.38 → 0.3.39

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.
@@ -83,7 +83,7 @@ import { createHash, randomBytes } from "node:crypto";
83
83
  import { appendFileSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
84
84
  import { join } from "node:path";
85
85
 
86
- import { SESSIONS_DIR, canonicalScope } from "./sessions.js";
86
+ import { EXPANSIONS_SALT_FILE, SESSIONS_DIR, canonicalScope } from "./sessions.js";
87
87
 
88
88
  /** One file, inside the registry's directory — see the header on placement. */
89
89
  export const EXPANSIONS_FILE = "expansions.jsonl";
@@ -147,8 +147,9 @@ export function expansionsPath(dataDir: string): string {
147
147
  return join(dataDir, SESSIONS_DIR, EXPANSIONS_FILE);
148
148
  }
149
149
 
150
- /** The salt file, beside the log — see `expansionSalt`. */
151
- export const EXPANSIONS_SALT_FILE = "expansions.salt";
150
+ /** The salt file, beside the log — see `expansionSalt`. Spelled in
151
+ * `sessions.ts`, whose prune keeps it by name (`KEPT_BY_NAME`). */
152
+ export { EXPANSIONS_SALT_FILE };
152
153
 
153
154
  /** 16 random bytes, hex. Long enough that guessing it is not the cheap attack. */
154
155
  const SALT_BYTES = 16;
@@ -1905,6 +1905,8 @@ its own small PR, after a look at its live use.
1905
1905
  - **Open check (review of #666, item 3; Q11):** "Update now" vs "Update marketplace". Whether Installed → counterparts
1906
1906
  → Update now refreshes the marketplace listing first, or answers "already at the latest" with auto-update off, needs
1907
1907
  a throwaway-home run in interactive Claude Code. Until then `PLUGIN_UPDATE` stays "Update now".
1908
+ (U1b, 2026-10-28: changed to Update marketplace as the design note says, Mike's Q11 "yes"; the throwaway-home
1909
+ run is still not done, so it stays unverified.)
1908
1910
 
1909
1911
  ## 2026-10-27 — the hook and doctor weigh the writer too (F1, after #666)
1910
1912
 
@@ -54,6 +54,7 @@ import { openEmbedder } from "../../claude-code/embed-client.js";
54
54
  import type { LiveEmbedder } from "../../claude-code/embed-client.js";
55
55
  import { SESSION_NOTICE_BUDGET_MS, doctorFindings, noticeMessage, wakeMeaningLine } from "../../claude-code/doctor.js";
56
56
  import { staleWindowsLine } from "../../claude-code/stale-windows.js";
57
+ import { updateLineInputHere, updateNoticeLine, urgentUpdateLine } from "../../update-check.js";
57
58
  import { SPAWN_REFUSAL_PREFIX, SPAWN_START_COUNT_KEY, SPAWN_START_DATE_KEY } from "../../lifecycle.js";
58
59
  import { WORKER_RUNNER_PATH } from "../../spawn.js";
59
60
  import { claudeCodeEnvMarker } from "../../hosts.js";
@@ -66,7 +67,7 @@ import { serveStdio } from "../stdio.js";
66
67
  import { SidebarStatusWriter, keepPluginPresence, removeSidebarStatus, sidebarInstalled } from "../../sidebar-status.js";
67
68
  import { stoodDownServer } from "../stood-down.js";
68
69
  import { noteNpmLive, npmWiringForGate } from "../../npm-live.js";
69
- import { installedVersion } from "../../sessions.js";
70
+ import { installedVersion, manifestVersionOnDisk } from "../../sessions.js";
70
71
  import { PLUGIN_ROOT_ENV, ensureFirstRun, installRoute, mcpGate, pluginOrigin, runningAsPlugin } from "../../plugin.js";
71
72
  import { DATA_DIR_ENV, describeGuardRefusal } from "../../../core/store/index.js";
72
73
  import { BINARY, scriptArgs } from "../../runtime.js";
@@ -264,9 +265,15 @@ export function desktopWakeNotice(input: {
264
265
  env?: Record<string, string | undefined>;
265
266
  /** This server's pid, whose own record is not an older window; absent, this process's. */
266
267
  selfPid?: number;
268
+ /** The home Claude Code's records are read under; absent, this process's. */
269
+ home?: string;
270
+ /** The package version on disk now; absent, `sessions.ts#manifestVersionOnDisk`. */
271
+ onDisk?: () => string | null;
267
272
  }): string | null {
268
273
  let meaning: string | null = null;
269
274
  let stale: string | null = null;
275
+ let urgent: string | null = null;
276
+ let update: string | null = null;
270
277
  try {
271
278
  const env = input.env ?? process.env;
272
279
  meaning =
@@ -282,10 +289,32 @@ export function desktopWakeNotice(input: {
282
289
  input.night === true
283
290
  ? null
284
291
  : (staleWindowsLine({ store: input.store, fallback: { route: "either", codeTab: false }, now: Date.now(), selfPid: input.selfPid ?? process.pid })?.line ?? null);
292
+ // UPDATES (U1b, `adapters/update-check.ts`): the same lines a Claude Code
293
+ // start carries, in the same order and under the same cap of three
294
+ // maintenance lines — never on a night's own wake.
295
+ // DESKTOP'S SERVER LIVES AS LONG AS THE APP (review of #672): the version
296
+ // it loaded is not necessarily the one installed now. When the package on
297
+ // disk differs from this process's, its own "was updated" line
298
+ // (`wakeUpdateLine`) is the one to say, and an update line would tell the
299
+ // person to install what they already have: none is said.
300
+ const onDisk = (input.onDisk ?? manifestVersionOnDisk)();
301
+ if (input.night !== true && onDisk === installedVersion()) {
302
+ const lineInput = updateLineInputHere({
303
+ store: input.store,
304
+ configPath: input.configPath,
305
+ config: input.config,
306
+ route: installRoute(env),
307
+ today: input.today,
308
+ env,
309
+ home: input.home ?? homedir(),
310
+ });
311
+ urgent = urgentUpdateLine(lineInput);
312
+ if ([stale, urgent, meaning].filter((l) => l !== null).length < 3) update = updateNoticeLine({ ...lineInput, urgentSaid: urgent !== null });
313
+ }
285
314
  } catch {
286
315
  meaning = null;
287
316
  }
288
- const lines = [desktopDoctorNotice(input), stale, meaning].filter((l): l is string => l !== null);
317
+ const lines = [desktopDoctorNotice(input), stale, urgent, meaning, update].filter((l): l is string => l !== null);
289
318
  return lines.length === 0 ? null : lines.join("\n");
290
319
  }
291
320
 
@@ -21,7 +21,7 @@ export const SERVER_NAME = "counterparts";
21
21
  * host decides whether to trust what follows. Read from a constant rather than
22
22
  * from disk so the server opens no file to answer its first message.
23
23
  */
24
- export const SERVER_VERSION = "0.3.38";
24
+ export const SERVER_VERSION = "0.3.39";
25
25
 
26
26
  /**
27
27
  * THE ONE LINE EVERY TOOL ANSWERS WITH when the store on disk is a schema AHEAD
@@ -87,6 +87,8 @@ import type { ScopeCommandContext, ScopeMode, ScopeRegistry, ScopeVerdict } from
87
87
  import { randomUUID } from "node:crypto";
88
88
  import { homedir } from "node:os";
89
89
 
90
+ import { NONESSENTIAL_TRAFFIC_ENV, UPDATE_CHECK_ENV, UPDATE_OFF_KEY, askedOff, updateSwitch } from "../update-check.js";
91
+ import type { UpdateSwitch } from "../update-check.js";
90
92
  import { CLAUDE_AI_HOST, CODE_TAB_ENTRYPOINT, DEFAULT_HOST, DESKTOP_HOST, DESKTOP_SCOPE, chatScopeOf, claudeCodeEnvMarker, hostOfClient, isChatHost, isPseudoScope, wordingFor } from "../hosts.js";
91
93
  import { PLUGIN_ROOT_ENV, recordedForThisCopy } from "../plugin.js";
92
94
  import type { InstallRoute } from "../plugin.js";
@@ -1353,6 +1355,60 @@ export class McpServer {
1353
1355
  };
1354
1356
  }
1355
1357
 
1358
+ /** The update check's switch as this server sees it: the config it read, the store, its environment. */
1359
+ private updateCheckSwitch(): UpdateSwitch {
1360
+ return updateSwitch({ config: this.lifecycleOpts.config ?? {}, asked: askedOff(this.counterpart.store), env: process.env });
1361
+ }
1362
+
1363
+ /**
1364
+ * `scope` with `updates` (U1b, 2026-10-28) — the person telling their Claude
1365
+ * to stop (or start) Counterparts' daily update check. Mike's must-have
1366
+ * (Q4): saying so to the AI is enough. Recorded as one store setting
1367
+ * (`update-check.ts#UPDATE_OFF_KEY`), which the worker reads before it asks
1368
+ * npm and every wake and doctor read before they say anything, wherever
1369
+ * they run. Passed alone; refused under observer like any write; not on
1370
+ * claude.ai, whose memory is always current and makes no check.
1371
+ */
1372
+ private updatesTool(args: Record<string, unknown>): ToolResult {
1373
+ const value = args["updates"];
1374
+ if (this.host === CLAUDE_AI_HOST) {
1375
+ return this.refuse("scope", "updates-not-here", {
1376
+ detail: "Counterparts Online is always current and checks for nothing, so there is no update check to switch here.",
1377
+ });
1378
+ }
1379
+ if (args["mode"] !== undefined || args["note"] !== undefined) {
1380
+ return this.refuse("scope", "updates-alone", { detail: "Pass `updates` on its own — not with `mode` or `note`." });
1381
+ }
1382
+ if (value !== "off" && value !== "on") {
1383
+ return this.refuse("scope", "updates-unusable", { detail: "`updates` takes off or on." });
1384
+ }
1385
+ if (this.desktop && this.callAs === null ? this.storeObserver : this.observer) return this.standDown("scope");
1386
+ const store = this.counterpart.store;
1387
+ if (value === "off") store.setMeta(UPDATE_OFF_KEY, "off");
1388
+ else store.updateMeta(UPDATE_OFF_KEY, (current) => (current === undefined ? undefined : null));
1389
+ const sw = this.updateCheckSwitch();
1390
+ this.emit("mcp.scope.updates", undefined, { updates: value, switch: sw });
1391
+ const still =
1392
+ value === "on" && sw === "config"
1393
+ ? ` It is still off in the configuration: "updateCheck": false in ${this.lifecycleOpts.configPath ?? "claude-code.json"} — the person can remove that line.`
1394
+ : value === "on" && sw === "env"
1395
+ ? ` It is still off where Counterparts runs: ${UPDATE_CHECK_ENV}=off is set.`
1396
+ : value === "on" && sw === "nonessential"
1397
+ ? ` Claude Code's ${NONESSENTIAL_TRAFFIC_ENV} is set, so it still makes no request.`
1398
+ : "";
1399
+ return this.result(
1400
+ {
1401
+ updates: sw === "none" ? "on" : "off",
1402
+ ...(sw === "none" || sw === "asked" ? {} : { offBy: sw }),
1403
+ detail:
1404
+ value === "off"
1405
+ ? "Done: Counterparts no longer asks npm for the newest version, and no session will mention updates. Tell the person it's off, and that they can ask you to turn it back on."
1406
+ : `Done: the daily check for a newer version is back on.${still}`,
1407
+ },
1408
+ false,
1409
+ );
1410
+ }
1411
+
1356
1412
  /**
1357
1413
  * `scope` — read, or set, what this directory is for (owner asks G41–G43).
1358
1414
  *
@@ -1363,6 +1419,7 @@ export class McpServer {
1363
1419
  * under observer exactly as every other write does.
1364
1420
  */
1365
1421
  private scopeTool(args: Record<string, unknown>): ToolResult {
1422
+ if (args["updates"] !== undefined) return this.updatesTool(args);
1366
1423
  const mode = args["mode"];
1367
1424
  const file = this.scopesFile;
1368
1425
  const verdict = this.scopeVerdict();
@@ -1380,6 +1437,8 @@ export class McpServer {
1380
1437
  ...(verdict.entry?.note === undefined ? {} : { note: verdict.entry.note }),
1381
1438
  ...(verdict.mode === "paused" ? { resumesTo: resumeTarget(verdict.entry) } : {}),
1382
1439
  ...(file === null ? {} : { registry: file }),
1440
+ // Counterparts' daily update check (U1b), on or off, for "are you checking?".
1441
+ ...(this.host === CLAUDE_AI_HOST ? {} : { updates: this.updateCheckSwitch() === "none" ? "on" : "off" }),
1383
1442
  // A registry in trouble is never silent, on any surface that has a
1384
1443
  // reader (#92 review, F2): entries nobody can honour read as unset,
1385
1444
  // which is ON, and this is the one place a model can see that.
@@ -1345,16 +1345,32 @@ const CHAPTER: ToolSpec = {
1345
1345
  },
1346
1346
  };
1347
1347
 
1348
+ /**
1349
+ * `scope`'s `updates` (U1b, 2026-10-28; Mike's must-have, Q4): "stop reminding
1350
+ * me about updates" said to the AI must be enough. Not a tool of its own — a
1351
+ * field on the door that already changes the host's settings — and passed
1352
+ * alone. Stripped from claude.ai's list (`withoutUpdates`): the hosted memory
1353
+ * is always current and makes no check.
1354
+ */
1355
+ const UPDATES_PROPERTY = {
1356
+ type: "string",
1357
+ enum: ["off", "on"],
1358
+ description:
1359
+ "Pass alone. `off` when the person says to stop reminding them about updates or stop checking for them: Counterparts stops asking npm once a day for the newest version, and no wake mentions updates again. `on` turns that back on.",
1360
+ } as const;
1361
+
1348
1362
  /**
1349
1363
  * `scope`'s privileges. Every one of them is about what this tool does NOT
1350
1364
  * touch: it is the only door here that writes no memory, and the only one that
1351
1365
  * answers at all in a directory that has been switched off.
1352
1366
  */
1367
+ const SCOPE_SUMMARY_BASE =
1368
+ "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.";
1369
+
1353
1370
  const SCOPE: ToolSpec = {
1354
1371
  name: "scope",
1355
1372
  annotations: annotate("Directory scope", { readOnly: false }),
1356
- summary:
1357
- "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.",
1373
+ summary: `${SCOPE_SUMMARY_BASE} \`updates\` alone: off when they say stop reminding them about updates.`,
1358
1374
  admission:
1359
1375
  "Call it to READ when a session starts in a directory nothing is set for and the wake asks you to; call it to SET the moment the user answers 'remember here', 'just read', 'not here' or 'pause this'.",
1360
1376
  negativeExamples: [
@@ -1388,6 +1404,11 @@ const SCOPE: ToolSpec = {
1388
1404
  "A registry it cannot parse is never overwritten: it says what it could not read and changes nothing.",
1389
1405
  mechanizedBy: "src/adapters/scopes.ts#readScopes -> src/adapters/mcp/server.ts#scopeTool",
1390
1406
  },
1407
+ {
1408
+ claim:
1409
+ "`updates: \"off\"` (the person saying stop): no daily request to npm and no update line in any wake or in doctor, until `updates: \"on\"`. One store setting, not about this directory; no memory. Not on claude.ai.",
1410
+ mechanizedBy: "src/adapters/mcp/server.ts#updatesTool -> src/adapters/update-check.ts#askedOff (runUpdateCheck, updateNoticeLine, urgentUpdateLine)",
1411
+ },
1391
1412
  ],
1392
1413
  inputSchema: {
1393
1414
  type: "object",
@@ -1403,6 +1424,7 @@ const SCOPE: ToolSpec = {
1403
1424
  description:
1404
1425
  "Optional: the user's own reason, recorded beside the setting. Omit it and the note already there is kept; pass an empty string to clear it — the same rule the console's --note follows.",
1405
1426
  },
1427
+ updates: UPDATES_PROPERTY,
1406
1428
  },
1407
1429
  required: [],
1408
1430
  additionalProperties: false,
@@ -2238,6 +2260,8 @@ export const CLAUDE_AI_WORDS: Readonly<
2238
2260
  summary:
2239
2261
  "Search your long-term memory on purpose: what you remember about the person, past conversations, a project, a plan — beyond what the wake brought. 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.",
2240
2262
  },
2263
+ // The every-host summary without its `updates` sentence: claude.ai's scope has no update check (`withoutUpdates`).
2264
+ scope: { summary: SCOPE_SUMMARY_BASE },
2241
2265
  status: {
2242
2266
  summary:
2243
2267
  "Memory status: the census of long-term memory — how much is held, of what kinds, in which bands, how much has left, and how much was removed. Counts and dates only.",
@@ -2273,6 +2297,14 @@ export const CLAUDE_AI_WORDS: Readonly<
2273
2297
  },
2274
2298
  };
2275
2299
 
2300
+ /** claude.ai's `scope` has no `updates` (U1b): the hosted memory is always current. Its privilege stays, as every host's do (it says it is not offered there). */
2301
+ function withoutUpdates(spec: ToolSpec): ToolSpec {
2302
+ if (spec.name !== "scope") return spec;
2303
+ const schema = spec.inputSchema as { properties?: Record<string, unknown> };
2304
+ const { updates: _updates, ...properties } = schema.properties ?? {};
2305
+ return { ...spec, inputSchema: { ...spec.inputSchema, properties } };
2306
+ }
2307
+
2276
2308
  function withClaudeAiWords(spec: ToolSpec): ToolSpec {
2277
2309
  const words = CLAUDE_AI_WORDS[spec.name as ToolName];
2278
2310
  return words === undefined ? spec : { ...spec, ...words };
@@ -2280,7 +2312,7 @@ function withClaudeAiWords(spec: ToolSpec): ToolSpec {
2280
2312
 
2281
2313
  /** The tools a claude.ai server offers: `wake` first, then every host's, each
2282
2314
  * able to name its session, in the chat's words where those differ. */
2283
- export const CLAUDE_AI_TOOLS: readonly ToolSpec[] = [CLAUDE_AI_WAKE, ...TOOLS.map((t) => withClaudeAiWords(withClaudeAiSession(t)))];
2315
+ export const CLAUDE_AI_TOOLS: readonly ToolSpec[] = [CLAUDE_AI_WAKE, ...TOOLS.map((t) => withoutUpdates(withClaudeAiWords(withClaudeAiSession(t))))];
2284
2316
 
2285
2317
  /**
2286
2318
  * WHICH LIST A SERVER OFFERS: a boolean is the old question (is this Desktop?),
@@ -121,6 +121,31 @@ export const SESSION_TTL_MS = 4 * 60 * 60 * 1000;
121
121
  */
122
122
  export const SESSION_PRUNE_MS = 7 * 24 * 60 * 60 * 1000;
123
123
 
124
+ /**
125
+ * The store's handle salt (`expansions.ts#expansionSalt`), spelled here so the
126
+ * prune below can name it without importing the module that imports this one.
127
+ */
128
+ export const EXPANSIONS_SALT_FILE = "expansions.salt";
129
+
130
+ /**
131
+ * Plain files in `sessions/` that `pruneSessions` keeps whatever their age,
132
+ * because they are WRITTEN ONCE and only read after that, so their mtime says
133
+ * when they were made, not whether they are still in use (2026-10-28).
134
+ *
135
+ * - `expansions.salt`: minted at a store's first wake and never rewritten.
136
+ * Pruned, the next wake mints another, which changes the store id
137
+ * (`store-id.ts`, compared by the sidebar) and orphans every key in the
138
+ * handle log.
139
+ *
140
+ * Everything else directly in `sessions/` is rewritten while it matters: session
141
+ * records at every boundary, stand-down markers per session, the handle log
142
+ * (`expansions.jsonl`, whose lines expire after a day anyway) at every
143
+ * resolution, the sidebar's pointer at every status write (`sidebar-status.ts
144
+ * #notePointer`). Server records go by liveness instead, and directories are
145
+ * never pruned here.
146
+ */
147
+ export const KEPT_BY_NAME: ReadonlySet<string> = new Set([EXPANSIONS_SALT_FILE]);
148
+
124
149
  export type SessionPhase = "start" | "boundary" | "end";
125
150
 
126
151
  export interface SessionRecord {
@@ -959,6 +984,9 @@ export function pruneSessions(
959
984
  // throws on a directory, which is not a rule anybody wrote down.
960
985
  const st = statSync(full);
961
986
  if (st.isDirectory()) continue;
987
+ // A WRITTEN-ONCE FILE is kept by name (`KEPT_BY_NAME`): its age is
988
+ // its birthday, not a sign it was abandoned.
989
+ if (KEPT_BY_NAME.has(name)) continue;
962
990
  // A SERVER RECORD is kept for exactly as long as its server is
963
991
  // believed alive — its pid running AND its heartbeat fresh
964
992
  // (`serverBelieved`) — whatever its age: a session left open for a week