Skip to content

Commit b5d1c1a

Browse files
committed
Show git commit hash in sidebar
1 parent 00e2f0a commit b5d1c1a

7 files changed

Lines changed: 24 additions & 4 deletions

File tree

packages/desktop/src/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ interface ImportMeta {
88
}
99

1010
declare const __APP_VERSION__: string
11+
declare const __COMMIT_HASH__: string

packages/desktop/src/pages/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ export default function Layout(props: ParentProps) {
10681068
</Tooltip>
10691069
</div>
10701070
<Show when={layout.sidebar.opened()}>
1071-
<div class="absolute bottom-1 left-2 text-11-regular text-text-weaker">v{__APP_VERSION__}</div>
1071+
<div class="absolute bottom-1 left-2 text-11-regular text-text-weaker">v{__APP_VERSION__} ({__COMMIT_HASH__})</div>
10721072
</Show>
10731073
</div>
10741074
<main class="size-full overflow-x-hidden flex flex-col items-start contain-strict">{props.children}</main>
@@ -1191,7 +1191,7 @@ export default function Layout(props: ParentProps) {
11911191

11921192
{/* Mobile menu footer */}
11931193
<div class="shrink-0 border-t border-border-weak-base p-4">
1194-
<div class="text-11-regular text-text-weaker">v{__APP_VERSION__}</div>
1194+
<div class="text-11-regular text-text-weaker">v{__APP_VERSION__} ({__COMMIT_HASH__})</div>
11951195
</div>
11961196
</div>
11971197
</Show>

packages/desktop/vite.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ import { readFileSync } from "fs"
33
import { VitePWA } from "vite-plugin-pwa"
44
import desktopPlugin from "./vite"
55

6+
import { execSync } from "child_process"
7+
68
const pkg = JSON.parse(readFileSync("./package.json", "utf-8"))
9+
const commitHash = process.env.OPENCODE_COMMIT_HASH || (() => {
10+
try {
11+
return execSync("git rev-parse --short HEAD", { encoding: "utf-8" }).trim()
12+
} catch {
13+
return "unknown"
14+
}
15+
})()
716
const apiPort = process.env.VITE_OPENCODE_SERVER_PORT ?? "4096"
817
const apiTarget = `http://127.0.0.1:${apiPort}`
918

@@ -97,6 +106,7 @@ export default defineConfig({
97106
] as any,
98107
define: {
99108
__APP_VERSION__: JSON.stringify(pkg.version),
109+
__COMMIT_HASH__: JSON.stringify(commitHash),
100110
},
101111
server: {
102112
host: "0.0.0.0",

packages/opencode/script/build.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ for (const item of targets) {
144144
define: {
145145
OPENCODE_VERSION: `'${Script.version}'`,
146146
OPENCODE_BASE_VERSION: `'${Script.baseVersion}'`,
147+
OPENCODE_COMMIT_HASH: `'${Script.commitHash}'`,
147148
OTUI_TREE_SITTER_WORKER_PATH: bunfsRoot + workerRelativePath,
148149
OPENCODE_WORKER_PATH: workerPath,
149150
OPENCODE_CHANNEL: `'${Script.channel}'`,
@@ -175,7 +176,7 @@ for (const item of targets) {
175176
if (staticFlag) {
176177
console.log("building static assets...")
177178
const desktopDir = path.resolve(dir, "../desktop")
178-
await $`bun run build`.cwd(desktopDir)
179+
await $`OPENCODE_COMMIT_HASH=${Script.commitHash} bun run build`.cwd(desktopDir)
179180
await $`cp -r ${desktopDir}/dist ${dir}/static`
180181
console.log("static assets built to ./static")
181182
}

packages/opencode/src/cli/cmd/tui/routes/session/sidebar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ export function Sidebar(props: { sessionID: string }) {
394394
<span style={{ fg: theme.text }}>
395395
<b>code</b>
396396
</span>{" "}
397-
<span>{Installation.VERSION}</span>
397+
<span>{Installation.VERSION}</span>{" "}
398+
<span>({Installation.COMMIT_HASH})</span>
398399
</text>
399400
</box>
400401
</box>

packages/opencode/src/installation/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ declare global {
1313
const OPENCODE_VERSION: string
1414
const OPENCODE_CHANNEL: string
1515
const OPENCODE_BASE_VERSION: string
16+
const OPENCODE_COMMIT_HASH: string
1617
}
1718

1819
export namespace Installation {
@@ -149,6 +150,7 @@ export namespace Installation {
149150
export const VERSION = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "local"
150151
export const CHANNEL = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : "local"
151152
export const BASE_VERSION = typeof OPENCODE_BASE_VERSION === "string" ? OPENCODE_BASE_VERSION : VERSION
153+
export const COMMIT_HASH = typeof OPENCODE_COMMIT_HASH === "string" ? OPENCODE_COMMIT_HASH : "unknown"
152154
export const USER_AGENT = `shuvcode/${CHANNEL}/${VERSION}/${Flag.OPENCODE_CLIENT}`
153155

154156
export function displayVersion() {

packages/script/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ const VERSION = await (async () => {
8888
return BASE_VERSION
8989
})()
9090

91+
const COMMIT_HASH = await $`git rev-parse --short HEAD`.text().then((x) => x.trim()).catch(() => "unknown")
92+
9193
export const Script = {
9294
get channel() {
9395
return CHANNEL
@@ -101,5 +103,8 @@ export const Script = {
101103
get preview() {
102104
return IS_PREVIEW
103105
},
106+
get commitHash() {
107+
return COMMIT_HASH
108+
},
104109
}
105110
console.log(`opencode script`, JSON.stringify(Script, null, 2))

0 commit comments

Comments
 (0)