feat(tui): show current branch in location labels

This commit is contained in:
Aiden Cline 2026-08-03 13:45:33 +00:00
commit 4b58478b6f
16 changed files with 176 additions and 14 deletions

View file

@ -1330,11 +1330,16 @@ export function Prompt(props: PromptProps) {
if (!props.sessionID) {
// No session yet: show where the next session will be created.
const directory = currentLocation.ref?.directory ?? data.location.default().directory
return abbreviateHome(directory, paths.home)
const branch = data.location.vcs.get(currentLocation.ref)?.branch
const label = abbreviateHome(directory, paths.home)
return branch ? label + ":" + branch : label
}
if (status() !== "idle") return
const directory = data.session.get(props.sessionID)?.location.directory
return directory ? abbreviateHome(directory, paths.home) : undefined
const ref = data.session.get(props.sessionID)?.location
if (!ref) return
const label = abbreviateHome(ref.directory, paths.home)
const branch = data.location.vcs.get(ref)?.branch
return branch ? label + ":" + branch : label
})
const spinnerDef = createMemo(() => {

View file

@ -28,6 +28,7 @@ import type {
ShellInfo,
SkillInfo,
OpenCodeEvent,
VcsInfo,
WebSearchProvider,
} from "@opencode-ai/client"
import type { Plugin } from "@opencode-ai/plugin/tui"
@ -49,6 +50,7 @@ type ShellWithLocation = ShellInfo & { readonly location: LocationRef }
type LocationData = {
info?: LocationGetOutput
vcs?: VcsInfo
agent?: AgentInfo[]
command?: CommandInfo[]
integration?: IntegrationInfo[]
@ -905,6 +907,15 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
result.location.mcp.resource.invalidate(event.location)
void result.location.mcp.resource.sync(event.location)
break
case "vcs.branch.updated": {
const ref = event.location ?? defaultLocation()
const key = locationKey(ref)
setStore("location", key, {
...store.location[key],
vcs: { branch: event.data.branch },
})
break
}
}
}
@ -1139,6 +1150,26 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
default() {
return defaultLocation()
},
vcs: {
get(ref?: LocationRef) {
return store.location[locationKey(ref ?? defaultLocation())]?.vcs
},
sync(ref?: LocationRef) {
const location = ref ?? defaultLocation()
const id = locationKey(location)
return sync.run(`location.vcs:${id}`, async () => {
const response = await client.api.vcs.get({ location: locationQuery(location) })
const key = locationKey(response.location)
setStore("location", key, {
...store.location[key],
vcs: response.data,
})
})
},
invalidate(ref?: LocationRef) {
sync.invalidate(`location.vcs:${locationKey(ref ?? defaultLocation())}`)
},
},
async sync(ref?: LocationRef) {
const current = ref ?? defaultLocation()
await sync.run(`location:${locationKey(current)}`, async () => {
@ -1161,6 +1192,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
result.location.provider.sync(location),
result.location.reference.sync(location),
result.location.skill.sync(location),
result.location.vcs.sync(location),
result.shell.sync(location),
result.session.form.sync("global", location),
])
@ -1177,6 +1209,7 @@ export const { use: useData, provider: DataProvider } = createSimpleContext({
result.location.provider.invalidate(location)
result.location.reference.invalidate(location)
result.location.skill.invalidate(location)
result.location.vcs.invalidate(location)
result.shell.invalidate(location)
result.session.form.invalidate("global", location)
},

View file

@ -6,8 +6,14 @@ function View(props: { context: Plugin.Context }) {
const directory = createMemo(() =>
props.context.location ? props.context.ui.format.path(props.context.location.directory) : undefined,
)
const value = createMemo(() => {
const path = directory()
if (!path) return
const branch = props.context.data.location.vcs.get(props.context.location)?.branch
return branch ? path + ":" + branch : path
})
return (
<Show when={directory()}>
<Show when={value()}>
{(value) => <FilePath value={value()} maxWidth={38} fg={props.context.theme.text.subdued} />}
</Show>
)

View file

@ -127,6 +127,11 @@ export function createFetch(override?: FetchHandler, events?: ReturnType<typeof
})
if (url.pathname === "/api/reference")
return json({ location: { directory, project: { id: "proj_test", directory, canonical: directory } }, data: [] })
if (url.pathname === "/api/vcs")
return json({
location: { directory, project: { id: "proj_test", directory: worktree, canonical: worktree } },
data: { branch: "main" },
})
if (url.pathname === "/api/websearch/provider") {
return json({ location: { directory, project: { id: "proj_test", directory, canonical: directory } }, data: [] })
}