fix(cli): auto-inject VERSION from package.json at build time
alpha.28-30 binaries all reported 'v1.0.0-alpha.27' from a hardcoded constant in src/constants/urls.ts — my bump sed only matched package.json's 'version' key, not the TypeScript literal. build.ts now reads package.json version and injects it via Bun's `define` (source-text replacement, equivalent to esbuild --define). urls.ts reads the injected symbol with a runtime fallback for `bun src/...` dev mode. Version drift can't recur. + peers + status migrated to the render.ts unified renderer. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,11 @@ import { gzipSync } from "node:zlib";
|
|||||||
|
|
||||||
const MAX_GZIPPED_BYTES = 1.2 * 1024 * 1024; // 1.2 MB
|
const MAX_GZIPPED_BYTES = 1.2 * 1024 * 1024; // 1.2 MB
|
||||||
|
|
||||||
|
// Inject the version from package.json at build time so VERSION can never
|
||||||
|
// drift from what's published. Bun's `define` is a source-text replacement,
|
||||||
|
// equivalent to `--define` in esbuild / a webpack DefinePlugin.
|
||||||
|
const pkgVersion = ((await Bun.file("package.json").json()) as { version: string }).version;
|
||||||
|
|
||||||
const result = await Bun.build({
|
const result = await Bun.build({
|
||||||
entrypoints: [
|
entrypoints: [
|
||||||
"src/entrypoints/cli.ts",
|
"src/entrypoints/cli.ts",
|
||||||
@@ -13,6 +18,9 @@ const result = await Bun.build({
|
|||||||
format: "esm",
|
format: "esm",
|
||||||
splitting: false,
|
splitting: false,
|
||||||
sourcemap: "external",
|
sourcemap: "external",
|
||||||
|
define: {
|
||||||
|
__CLAUDEMESH_VERSION__: JSON.stringify(pkgVersion),
|
||||||
|
},
|
||||||
external: [
|
external: [
|
||||||
"libsodium-wrappers",
|
"libsodium-wrappers",
|
||||||
"ws",
|
"ws",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "claudemesh-cli-v2",
|
"name": "claudemesh-cli-v2",
|
||||||
"version": "1.0.0-alpha.30",
|
"version": "1.0.0-alpha.31",
|
||||||
"description": "Peer mesh for Claude Code sessions — CLI + MCP server.",
|
"description": "Peer mesh for Claude Code sessions — CLI + MCP server.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"claude-code",
|
"claude-code",
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
import { withMesh } from "./connect.js";
|
import { withMesh } from "./connect.js";
|
||||||
import { readConfig } from "~/services/config/facade.js";
|
import { readConfig } from "~/services/config/facade.js";
|
||||||
|
import { render } from "~/ui/render.js";
|
||||||
|
import { bold, dim, green, yellow } from "~/ui/styles.js";
|
||||||
|
|
||||||
export interface PeersFlags {
|
export interface PeersFlags {
|
||||||
mesh?: string;
|
mesh?: string;
|
||||||
@@ -13,22 +15,12 @@ export interface PeersFlags {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function runPeers(flags: PeersFlags): Promise<void> {
|
export async function runPeers(flags: PeersFlags): Promise<void> {
|
||||||
const useColor =
|
|
||||||
!process.env.NO_COLOR && process.env.TERM !== "dumb" && process.stdout.isTTY;
|
|
||||||
const dim = (s: string) => (useColor ? `\x1b[2m${s}\x1b[22m` : s);
|
|
||||||
const bold = (s: string) => (useColor ? `\x1b[1m${s}\x1b[22m` : s);
|
|
||||||
const green = (s: string) => (useColor ? `\x1b[32m${s}\x1b[39m` : s);
|
|
||||||
const yellow = (s: string) => (useColor ? `\x1b[33m${s}\x1b[39m` : s);
|
|
||||||
|
|
||||||
const config = readConfig();
|
const config = readConfig();
|
||||||
|
const slugs = flags.mesh ? [flags.mesh] : config.meshes.map((m) => m.slug);
|
||||||
// If --mesh specified, show only that one. Otherwise show all.
|
|
||||||
const slugs = flags.mesh
|
|
||||||
? [flags.mesh]
|
|
||||||
: config.meshes.map(m => m.slug);
|
|
||||||
|
|
||||||
if (slugs.length === 0) {
|
if (slugs.length === 0) {
|
||||||
console.error("No meshes joined. Run `claudemesh join <url>` first.");
|
render.err("No meshes joined.");
|
||||||
|
render.hint("claudemesh <invite-url> # join + launch");
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,39 +36,39 @@ export async function runPeers(flags: PeersFlags): Promise<void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(bold(`Peers on ${mesh.slug}`) + dim(` (${peers.length})`));
|
render.section(`peers on ${mesh.slug} (${peers.length})`);
|
||||||
console.log("");
|
|
||||||
|
|
||||||
if (peers.length === 0) {
|
if (peers.length === 0) {
|
||||||
console.log(dim(" No peers connected."));
|
render.info(dim(" (no peers connected)"));
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (const p of peers) {
|
for (const p of peers) {
|
||||||
const groups = p.groups.length
|
const groups = p.groups.length
|
||||||
? " [" + p.groups.map((g: { name: string; role?: string }) =>
|
? " [" +
|
||||||
`@${g.name}${g.role ? `:${g.role}` : ""}`).join(", ") + "]"
|
p.groups
|
||||||
|
.map((g: { name: string; role?: string }) => `@${g.name}${g.role ? `:${g.role}` : ""}`)
|
||||||
|
.join(", ") +
|
||||||
|
"]"
|
||||||
: "";
|
: "";
|
||||||
const statusIcon = p.status === "working" ? yellow("●") : green("●");
|
const statusDot = p.status === "working" ? yellow("●") : green("●");
|
||||||
const name = bold(p.displayName);
|
const name = bold(p.displayName);
|
||||||
const meta: string[] = [];
|
const meta: string[] = [];
|
||||||
if (p.peerType) meta.push(p.peerType);
|
if (p.peerType) meta.push(p.peerType);
|
||||||
if (p.channel) meta.push(p.channel);
|
if (p.channel) meta.push(p.channel);
|
||||||
if (p.model) meta.push(p.model);
|
if (p.model) meta.push(p.model);
|
||||||
const metaStr = meta.length ? dim(` (${meta.join(", ")})`) : "";
|
const metaStr = meta.length ? dim(` (${meta.join(", ")})`) : "";
|
||||||
const cwdStr = p.cwd ? dim(` cwd: ${p.cwd}`) : "";
|
const summary = p.summary ? dim(` — ${p.summary}`) : "";
|
||||||
const summary = p.summary ? dim(` ${p.summary}`) : "";
|
render.info(`${statusDot} ${name}${groups}${metaStr}${summary}`);
|
||||||
console.log(` ${statusIcon} ${name}${groups}${metaStr}${summary}`);
|
if (p.cwd) render.info(dim(` cwd: ${p.cwd}`));
|
||||||
if (cwdStr) console.log(` ${cwdStr}`);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
console.log("");
|
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(dim(` Could not connect to ${slug}: ${e instanceof Error ? e.message : String(e)}`));
|
render.err(`${slug}: ${e instanceof Error ? e.message : String(e)}`);
|
||||||
console.log("");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags.json) {
|
if (flags.json) {
|
||||||
console.log(JSON.stringify(slugs.length === 1 ? allJson[0]?.peers : allJson, null, 2));
|
process.stdout.write(JSON.stringify(slugs.length === 1 ? allJson[0]?.peers : allJson, null, 2) + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { statSync, existsSync } from "node:fs";
|
|||||||
import WebSocket from "ws";
|
import WebSocket from "ws";
|
||||||
import { readConfig, getConfigPath } from "~/services/config/facade.js";
|
import { readConfig, getConfigPath } from "~/services/config/facade.js";
|
||||||
import { VERSION } from "~/constants/urls.js";
|
import { VERSION } from "~/constants/urls.js";
|
||||||
|
import { render } from "~/ui/render.js";
|
||||||
|
|
||||||
interface MeshStatus {
|
interface MeshStatus {
|
||||||
slug: string;
|
slug: string;
|
||||||
@@ -17,10 +18,12 @@ interface MeshStatus {
|
|||||||
pubkey: string;
|
pubkey: string;
|
||||||
reachable: boolean;
|
reachable: boolean;
|
||||||
error?: string;
|
error?: string;
|
||||||
|
latencyMs?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function probeBroker(url: string, timeoutMs = 4000): Promise<{ ok: boolean; error?: string }> {
|
async function probeBroker(url: string, timeoutMs = 4000): Promise<{ ok: boolean; error?: string; latencyMs?: number }> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
const started = Date.now();
|
||||||
const ws = new WebSocket(url);
|
const ws = new WebSocket(url);
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
try { ws.terminate(); } catch { /* noop */ }
|
try { ws.terminate(); } catch { /* noop */ }
|
||||||
@@ -28,8 +31,9 @@ async function probeBroker(url: string, timeoutMs = 4000): Promise<{ ok: boolean
|
|||||||
}, timeoutMs);
|
}, timeoutMs);
|
||||||
ws.on("open", () => {
|
ws.on("open", () => {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
|
const latency = Date.now() - started;
|
||||||
try { ws.close(); } catch { /* noop */ }
|
try { ws.close(); } catch { /* noop */ }
|
||||||
resolve({ ok: true });
|
resolve({ ok: true, latencyMs: latency });
|
||||||
});
|
});
|
||||||
ws.on("error", (err) => {
|
ws.on("error", (err) => {
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
@@ -39,65 +43,59 @@ async function probeBroker(url: string, timeoutMs = 4000): Promise<{ ok: boolean
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function runStatus(): Promise<void> {
|
export async function runStatus(): Promise<void> {
|
||||||
const useColor =
|
render.section(`status (v${VERSION})`);
|
||||||
!process.env.NO_COLOR && process.env.TERM !== "dumb" && process.stdout.isTTY;
|
|
||||||
const dim = (s: string): string => (useColor ? `\x1b[2m${s}\x1b[22m` : s);
|
|
||||||
const green = (s: string): string => (useColor ? `\x1b[32m${s}\x1b[39m` : s);
|
|
||||||
const red = (s: string): string => (useColor ? `\x1b[31m${s}\x1b[39m` : s);
|
|
||||||
|
|
||||||
console.log(`claudemesh status (v${VERSION})`);
|
|
||||||
console.log("─".repeat(60));
|
|
||||||
|
|
||||||
const configPath = getConfigPath();
|
const configPath = getConfigPath();
|
||||||
let configPerms = "missing";
|
let configPermsNote = "missing";
|
||||||
if (existsSync(configPath)) {
|
if (existsSync(configPath)) {
|
||||||
const st = statSync(configPath);
|
const mode = (statSync(configPath).mode & 0o777).toString(8).padStart(4, "0");
|
||||||
const mode = (st.mode & 0o777).toString(8).padStart(4, "0");
|
configPermsNote = mode === "0600" ? `${mode}` : `${mode} — expected 0600`;
|
||||||
configPerms = mode === "0600" ? `${mode} ✓` : `${mode} ⚠ (expected 0600)`;
|
|
||||||
}
|
}
|
||||||
console.log(`Config: ${configPath} (${configPerms})`);
|
render.kv([["config", configPath], ["perms", configPermsNote]]);
|
||||||
|
|
||||||
const config = readConfig();
|
const config = readConfig();
|
||||||
if (config.meshes.length === 0) {
|
if (config.meshes.length === 0) {
|
||||||
console.log("");
|
render.blank();
|
||||||
console.log(dim("No meshes joined. Run `claudemesh join <invite-url>` to get started."));
|
render.info("No meshes joined.");
|
||||||
|
render.hint("claudemesh <invite-url> # join + launch");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("");
|
render.blank();
|
||||||
console.log(`Meshes (${config.meshes.length}):`);
|
render.heading(`meshes (${config.meshes.length})`);
|
||||||
|
|
||||||
const results: MeshStatus[] = [];
|
const results: MeshStatus[] = [];
|
||||||
for (const m of config.meshes) {
|
for (const m of config.meshes) {
|
||||||
process.stdout.write(` ${m.slug.padEnd(20)} probing ${m.brokerUrl}… `);
|
|
||||||
const probe = await probeBroker(m.brokerUrl);
|
const probe = await probeBroker(m.brokerUrl);
|
||||||
results.push({
|
const entry: MeshStatus = {
|
||||||
slug: m.slug,
|
slug: m.slug,
|
||||||
brokerUrl: m.brokerUrl,
|
brokerUrl: m.brokerUrl,
|
||||||
pubkey: m.pubkey,
|
pubkey: m.pubkey,
|
||||||
reachable: probe.ok,
|
reachable: probe.ok,
|
||||||
error: probe.error,
|
error: probe.error,
|
||||||
});
|
latencyMs: probe.latencyMs,
|
||||||
|
};
|
||||||
|
results.push(entry);
|
||||||
if (probe.ok) {
|
if (probe.ok) {
|
||||||
console.log(green("reachable"));
|
render.ok(`${m.slug}`, `${probe.latencyMs}ms → ${m.brokerUrl}`);
|
||||||
} else {
|
} else {
|
||||||
console.log(red(`unreachable (${probe.error})`));
|
render.err(`${m.slug}`, `unreachable (${probe.error})`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("");
|
render.blank();
|
||||||
for (const r of results) {
|
for (const r of results) {
|
||||||
console.log(dim(` ${r.slug}: pubkey ${r.pubkey.slice(0, 16)}…`));
|
render.kv([[r.slug, `${r.pubkey.slice(0, 16)}…`]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const allOk = results.every((r) => r.reachable);
|
const allOk = results.every((r) => r.reachable);
|
||||||
console.log("");
|
render.blank();
|
||||||
if (allOk) {
|
if (allOk) {
|
||||||
console.log(green("All meshes reachable."));
|
render.ok("all meshes reachable");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
} else {
|
} else {
|
||||||
const broken = results.filter((r) => !r.reachable).length;
|
const broken = results.filter((r) => !r.reachable).length;
|
||||||
console.log(red(`${broken} of ${results.length} mesh(es) unreachable.`));
|
render.err(`${broken} of ${results.length} mesh(es) unreachable`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,11 @@ export const URLS = {
|
|||||||
NPM_REGISTRY: "https://registry.npmjs.org/claudemesh-cli",
|
NPM_REGISTRY: "https://registry.npmjs.org/claudemesh-cli",
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const VERSION = "1.0.0-alpha.27";
|
// Injected at build time from package.json#version via `bun build --define`
|
||||||
|
// (see build.ts). Falls back to a dev sentinel when running from source.
|
||||||
|
declare const __CLAUDEMESH_VERSION__: string;
|
||||||
|
export const VERSION: string =
|
||||||
|
typeof __CLAUDEMESH_VERSION__ !== "undefined" ? __CLAUDEMESH_VERSION__ : "0.0.0-dev";
|
||||||
|
|
||||||
export const env = {
|
export const env = {
|
||||||
CLAUDEMESH_BROKER_URL: URLS.BROKER,
|
CLAUDEMESH_BROKER_URL: URLS.BROKER,
|
||||||
|
|||||||
Reference in New Issue
Block a user