Skip to content
Closed
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
17 changes: 17 additions & 0 deletions src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import { exec, spawn } from "node:child_process";
import { readFileSync } from "node:fs";
import * as http from "node:http";
import * as net from "node:net";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { installHooks, removeHooks } from "./hooks.ts";
import { install, readLockFile, removeLockFile, uninstall, writeLockFile } from "./installer.ts";
import { createServer } from "./server.ts";
import { createStore } from "./state.ts";

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

function readVersion(): string | undefined {
try {
const pkg = JSON.parse(readFileSync(join(__dirname, "..", "package.json"), "utf-8"));
return pkg.version;
} catch {
return undefined;
}
}

const DEFAULT_PORT = 8377;

function parseArgs(argv: string[]): {
Expand Down Expand Up @@ -244,6 +259,7 @@ function main(): void {

function startDashboard(port: number, noHooks: boolean, noOpen: boolean): void {
const store = createStore();
const version = readVersion();

let cleanedUp = false;
function cleanup() {
Expand All @@ -263,6 +279,7 @@ function startDashboard(port: number, noHooks: boolean, noOpen: boolean): void {

const dashboard = createServer({
store,
version,
onShutdown() {
cleanup();
process.exit(0);
Expand Down
10 changes: 10 additions & 0 deletions src/dashboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,14 @@ describe("getDashboardHtml", () => {
it("auto-hides banner after 10 seconds", () => {
assert.ok(html.includes("setTimeout(hideNotifBanner, 10000)"));
});

it("includes version badge when version is provided", () => {
const htmlWithVersion = getDashboardHtml("1.2.3");
assert.ok(htmlWithVersion.includes("1.2.3"));
assert.ok(htmlWithVersion.includes("version-badge"));
});

it("omits version badge element when no version is provided", () => {
assert.ok(!html.includes('<span class="version-badge">'));
});
});
11 changes: 9 additions & 2 deletions src/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function getDashboardHtml(): string {
export function getDashboardHtml(version?: string): string {
return `<!DOCTYPE html>
<html lang="en">
<head>
Expand Down Expand Up @@ -31,6 +31,13 @@ export function getDashboardHtml(): string {
color: #f0f6fc;
}

.version-badge {
font-size: 12px;
font-weight: 400;
color: #6e7681;
margin-left: 8px;
}

.header-right {
display: flex;
align-items: center;
Expand Down Expand Up @@ -399,7 +406,7 @@ export function getDashboardHtml(): string {
</head>
<body>
<header>
<h1>Claude Code Dashboard</h1>
<h1>Claude Code Dashboard${version ? `<span class="version-badge">v${version}</span>` : ""}</h1>
<div class="header-right">
<div class="notification-toggle">
<label class="toggle-switch">
Expand Down
5 changes: 3 additions & 2 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ export interface DashboardServer {

export interface ServerOptions {
store: Store;
version?: string;
idleTimeoutMs?: number;
cleanupIntervalMs?: number;
onShutdown?: () => void;
onRestart?: () => void;
}

export function createServer(options: ServerOptions): DashboardServer {
const { store, onShutdown, onRestart } = options;
const { store, version, onShutdown, onRestart } = options;
const idleTimeoutMs = options.idleTimeoutMs ?? 5 * 60 * 1000;
const cleanupIntervalMs = options.cleanupIntervalMs ?? 60_000;
const sseClients = new Set<http.ServerResponse>();
Expand All @@ -38,7 +39,7 @@ export function createServer(options: ServerOptions): DashboardServer {

if (req.method === "GET" && pathname === "/") {
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
res.end(getDashboardHtml());
res.end(getDashboardHtml(version));
return;
}

Expand Down