From 10e00e914214d978ba783105b1a9a4aa95247bc7 Mon Sep 17 00:00:00 2001 From: Joseph Mearman Date: Fri, 18 Sep 2026 16:13:45 +0100 Subject: [PATCH] feat(registry): add ccPeerVersion field, separate from the overloaded version field version means two different things depending on who wrote a registry entry: a real interactive Claude Code session's own app version, or the literal string "cc-peer" for an entry cc-peer's own buildRegistryEntry wrote. Neither case exposes cc-peer's actual package version to a reader. Add ccPeerVersion, populated from package.json and inlined at bundle time via a static JSON import so it needs no filesystem access at runtime. The SEA build ships as a single file with no package.json alongside it. It carries cc-peer's real semver on every entry cc-peer itself writes, and stays absent on entries a real Claude Code session wrote directly. Also replace CC_PEER_VERSION's "0.0.0" placeholder with the same import, since the constant now has a real source of truth to read from. --- schemas/registry-entry.schema.json | 4 ++++ src/cc-peer-class.integration.test.ts | 12 +++++++++++- src/cc-peer.ts | 7 +++++-- src/cc-peer.unit.test.ts | 5 +++-- src/schemas/registry.ts | 2 ++ tsconfig.json | 1 + 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/schemas/registry-entry.schema.json b/schemas/registry-entry.schema.json index 659c3ea..1053fc0 100644 --- a/schemas/registry-entry.schema.json +++ b/schemas/registry-entry.schema.json @@ -27,6 +27,10 @@ "type": "string", "minLength": 1 }, + "ccPeerVersion": { + "type": "string", + "minLength": 1 + }, "peerProtocol": { "type": "integer", "minimum": -9007199254740991, diff --git a/src/cc-peer-class.integration.test.ts b/src/cc-peer-class.integration.test.ts index 15f35a9..4d62716 100644 --- a/src/cc-peer-class.integration.test.ts +++ b/src/cc-peer-class.integration.test.ts @@ -5,7 +5,7 @@ import { join } from "node:path"; import { connect, type Socket } from "node:net"; import { once } from "node:events"; -import { CcPeer } from "./cc-peer.js"; +import { CcPeer, CC_PEER_VERSION } from "./cc-peer.js"; import { UdsTransport, SystemClock } from "./adapters/node/uds-transport.js"; import { FsKeyStore } from "./adapters/node/fs-key-store.js"; import { FsRegistryStore } from "./adapters/node/fs-registry-store.js"; @@ -119,6 +119,16 @@ describe("CcPeer dependency-injected construction", () => { await peer.stop(); }); + test("the registry entry's ccPeerVersion carries cc-peer's own package version, regardless of what the writer's overloaded version field says", async () => { + const home = await tempHome(); + const peer = makePeer(home); + await peer.start(); + const store = new FsRegistryStore({ homeDir: home }); + const entry = await store.read(process.pid); + expect(entry?.ccPeerVersion).toBe(CC_PEER_VERSION); + await peer.stop(); + }); + test("on Windows, start() does not create a socket directory (a named pipe has none of its own)", async () => { const home = await tempHome(); // A fake transport stands in for the real UdsTransport: under a mocked win32 platform, socketPathForPid returns a named-pipe-shaped string, which a real POSIX kernel would just as happily bind as a literal (garbage) relative filename in the working directory — that would prove nothing about mkdir being skipped and would litter the test run with a stray file. Asserting directly on socketPath's shape and on the directory's absence is what this test actually means to check. diff --git a/src/cc-peer.ts b/src/cc-peer.ts index fd9c332..5a2a320 100644 --- a/src/cc-peer.ts +++ b/src/cc-peer.ts @@ -1,6 +1,8 @@ import { EventEmitter } from "node:events"; import { randomBytes } from "node:crypto"; +import packageJson from "../package.json" with { type: "json" }; + import { UdsTransport, SystemClock } from "./adapters/node/uds-transport.js"; import { FsKeyStore } from "./adapters/node/fs-key-store.js"; import { FsRegistryStore } from "./adapters/node/fs-registry-store.js"; @@ -41,8 +43,8 @@ import { UnknownPeerError, } from "./errors.js"; -/** Package version placeholder until semantic-release owns it. */ -export const CC_PEER_VERSION = "0.0.0"; +/** cc-peer's own package version, read from package.json and inlined at bundle time so it needs no filesystem access at runtime (the SEA build ships as a single file with no package.json alongside it). */ +export const CC_PEER_VERSION: string = packageJson.version; /** Default log sink: logs go nowhere unless a logger is provided. */ const sinkLog = (): void => undefined; @@ -165,6 +167,7 @@ export class CcPeer extends EventEmitter { startedAt: now, procStart, version: "cc-peer", + ccPeerVersion: CC_PEER_VERSION, peerProtocol: 1, peerFeatures: ["notify_idle", "reply_across_default_dirs"], kind: "interactive", diff --git a/src/cc-peer.unit.test.ts b/src/cc-peer.unit.test.ts index b4daab9..d736cfc 100644 --- a/src/cc-peer.unit.test.ts +++ b/src/cc-peer.unit.test.ts @@ -1,6 +1,7 @@ import { expect, test } from "vitest"; import { CC_PEER_VERSION } from "./cc-peer.js"; +import packageJson from "../package.json" with { type: "json" }; -test("exports a version constant", () => { - expect(CC_PEER_VERSION).toBe("0.0.0"); +test("exports cc-peer's own real package version, not a placeholder", () => { + expect(CC_PEER_VERSION).toBe(packageJson.version); }); diff --git a/src/schemas/registry.ts b/src/schemas/registry.ts index 82187ca..e0c6f80 100644 --- a/src/schemas/registry.ts +++ b/src/schemas/registry.ts @@ -31,6 +31,8 @@ export const RegistryEntrySchema = defineSchema( startedAt: z.number().int().nonnegative(), procStart: z.string().min(1), version: z.string().min(1), + /** cc-peer's own package version, present on every entry cc-peer itself writes regardless of kind; absent on an entry a real interactive Claude Code session wrote directly, since only cc-peer knows to populate it. Distinct from `version`, which is overloaded between a real Claude Code app version and cc-peer's own sentinel string depending on who wrote the entry. */ + ccPeerVersion: z.string().min(1).optional(), peerProtocol: z.number().int(), peerFeatures: z.array(PeerFeatureSchema), kind: SessionKindSchema, diff --git a/tsconfig.json b/tsconfig.json index c65a6a2..c02c19b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,7 @@ "lib": ["ES2024"], "types": ["node"], "strict": true, + "resolveJsonModule": true, "noUncheckedIndexedAccess": true, "exactOptionalPropertyTypes": true, "noImplicitReturns": true,