Skip to content
Open
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: 2 additions & 2 deletions packages/opencode/src/cli/cmd/tui/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async function getTerminalBackgroundColor(): Promise<"dark" | "light"> {
})
}

export function tui(input: { url: string; args: Args; onExit?: () => Promise<void> }) {
export function tui(input: { url: string; args: Args; attached?: boolean; onExit?: () => Promise<void> }) {
// promise to prevent immediate exit
return new Promise<void>(async (resolve) => {
const mode = await getTerminalBackgroundColor()
Expand All @@ -116,7 +116,7 @@ export function tui(input: { url: string; args: Args; onExit?: () => Promise<voi
<KVProvider>
<ToastProvider>
<RouteProvider>
<SDKProvider url={input.url}>
<SDKProvider url={input.url} attached={input.attached}>
<SyncProvider>
<ThemeProvider mode={mode}>
<LocalProvider>
Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/cli/cmd/tui/attach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const AttachCommand = cmd({
await tui({
url: args.url,
args: { sessionID: args.session },
attached: true,
})
},
})
10 changes: 7 additions & 3 deletions packages/opencode/src/cli/cmd/tui/context/directory.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { createMemo } from "solid-js"
import { useSync } from "./sync"
import { useSDK } from "./sdk"
import { Global } from "@/global"

export function useDirectory() {
const sync = useSync()
const sdk = useSDK()
return createMemo(() => {
const remote = sdk.remoteHost
const directory = sync.data.path.directory || process.cwd()
const result = directory.replace(Global.Path.home, "~")
if (sync.data.vcs?.branch) return result + ":" + sync.data.vcs.branch
return result
const cwd = remote ? sync.data.path.directory || "..." : directory.replace(Global.Path.home, "~")
const prefix = remote ? `${remote} ` : ""
if (sync.data.vcs?.branch) return prefix + cwd + ":" + sync.data.vcs.branch
return prefix + cwd
})
}
12 changes: 10 additions & 2 deletions packages/opencode/src/cli/cmd/tui/context/sdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import { createSimpleContext } from "./helper"
import { createGlobalEmitter } from "@solid-primitives/event-bus"
import { batch, onCleanup, onMount } from "solid-js"

function parseRemoteHost(url: string): string {
const parsed = new URL(url)
const host = parsed.hostname
const port = parsed.port
return port ? `${host}:${port}` : host
}

export const { use: useSDK, provider: SDKProvider } = createSimpleContext({
name: "SDK",
init: (props: { url: string }) => {
init: (props: { url: string; attached?: boolean }) => {
const abort = new AbortController()
const sdk = createOpencodeClient({
baseUrl: props.url,
signal: abort.signal,
})
const remoteHost = props.attached ? parseRemoteHost(props.url) : undefined

const emitter = createGlobalEmitter<{
[key in Event["type"]]: Extract<Event, { type: key }>
Expand Down Expand Up @@ -69,6 +77,6 @@ export const { use: useSDK, provider: SDKProvider } = createSimpleContext({
abort.abort()
})

return { client: sdk, event: emitter, url: props.url }
return { client: sdk, event: emitter, url: props.url, remoteHost }
},
})