Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions schemas/registry-entry.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"type": "string",
"minLength": 1
},
"ccPeerVersion": {
"type": "string",
"minLength": 1
},
"peerProtocol": {
"type": "integer",
"minimum": -9007199254740991,
Expand Down
12 changes: 11 additions & 1 deletion src/cc-peer-class.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions src/cc-peer.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/cc-peer.unit.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
2 changes: 2 additions & 0 deletions src/schemas/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"lib": ["ES2024"],
"types": ["node"],
"strict": true,
"resolveJsonModule": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"noImplicitReturns": true,
Expand Down
Loading