Skip to content

Commit 27d361e

Browse files
committed
feat(opencode): add desktop command for opening desktop app
Add to launch the desktop app via deep link and normalize worktree paths when opening projects so trailing slash variants do not create duplicate project entries.
1 parent c3ddc85 commit 27d361e

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

packages/app/src/context/server.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ function isLocalHost(url: string) {
3333
if (host === "localhost" || host === "127.0.0.1") return "local"
3434
}
3535

36+
export function normalizeWorktree(input: string) {
37+
return input.trim().replace(/[\/\\]+$/, "")
38+
}
39+
3640
export namespace ServerConnection {
3741
type Base = { displayName?: string }
3842

@@ -241,7 +245,8 @@ export const { use: useServer, provider: ServerProvider } = createSimpleContext(
241245
const key = origin()
242246
if (!key) return
243247
const current = store.projects[key] ?? []
244-
if (current.find((x) => x.worktree === directory)) return
248+
const target = normalizeWorktree(directory)
249+
if (current.find((x) => normalizeWorktree(x.worktree) === target)) return
245250
setStore("projects", key, [{ worktree: directory, expanded: true }, ...current])
246251
},
247252
close(directory: string) {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { UI } from "../ui"
2+
import { cmd } from "./cmd"
3+
import open from "open"
4+
import path from "path"
5+
import { Filesystem } from "../../util/filesystem"
6+
7+
export const DesktopCommand = cmd({
8+
command: "desktop [path]",
9+
describe: "open path in opencode desktop app",
10+
builder: (yargs) => {
11+
return yargs.positional("path", {
12+
describe: "path to open",
13+
type: "string",
14+
default: ".",
15+
})
16+
},
17+
handler: async (args) => {
18+
const targetPath = path.resolve(process.cwd(), args.path)
19+
if (!(await Filesystem.exists(targetPath))) {
20+
UI.error(`Path not found: ${targetPath}`)
21+
process.exit(1)
22+
}
23+
24+
const url = `opencode://open-project?directory=${encodeURIComponent(targetPath)}`
25+
await open(url)
26+
},
27+
})

packages/opencode/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { TuiThreadCommand } from "./cli/cmd/tui/thread"
2727
import { AcpCommand } from "./cli/cmd/acp"
2828
import { EOL } from "os"
2929
import { WebCommand } from "./cli/cmd/web"
30+
import { DesktopCommand } from "./cli/cmd/open"
3031
import { PrCommand } from "./cli/cmd/pr"
3132
import { SessionCommand } from "./cli/cmd/session"
3233
import { DbCommand } from "./cli/cmd/db"
@@ -137,6 +138,7 @@ let cli = yargs(hideBin(process.argv))
137138
.command(UninstallCommand)
138139
.command(ServeCommand)
139140
.command(WebCommand)
141+
.command(DesktopCommand)
140142
.command(ModelsCommand)
141143
.command(StatsCommand)
142144
.command(ExportCommand)

0 commit comments

Comments
 (0)