web command

This commit is contained in:
Dax Raad
2025-11-03 16:10:13 -05:00
parent 55d07a139c
commit 902763b47d
4 changed files with 53 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import { Server } from "../../server/server"
import { UI } from "../ui"
import { cmd } from "./cmd"
export const ServeCommand = cmd({
@@ -24,7 +25,12 @@ export const ServeCommand = cmd({
port,
hostname,
})
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
UI.println(
UI.Style.TEXT_NORMAL_BOLD,
"Web interface: ",
UI.Style.TEXT_NORMAL,
`https://desktop.dev.opencode.ai?url=${server.url}`,
)
await new Promise(() => {})
await server.stop()
},

View File

@@ -178,12 +178,16 @@ function App() {
useKeyboard(async (evt) => {
if (evt.meta && evt.name === "t") {
renderer.toggleDebugOverlay()
if (process.env.DEBUG) {
renderer.toggleDebugOverlay()
}
return
}
if (evt.meta && evt.name === "d") {
renderer.console.toggle()
if (process.env.DEBUG) {
renderer.console.toggle()
}
return
}
})

View File

@@ -0,0 +1,38 @@
import { Server } from "../../server/server"
import { UI } from "../ui"
import { cmd } from "./cmd"
import open from "open"
export const WebCommand = cmd({
command: "web",
builder: (yargs) =>
yargs
.option("port", {
alias: ["p"],
type: "number",
describe: "port to listen on",
default: 0,
})
.option("hostname", {
type: "string",
describe: "hostname to listen on",
default: "127.0.0.1",
}),
describe: "starts a headless opencode server",
handler: async (args) => {
const hostname = args.hostname
const port = args.port
const server = Server.listen({
port,
hostname,
})
const url = `https://desktop.dev.opencode.ai?url=${server.url}`
UI.empty()
UI.println(UI.logo(" "))
UI.empty()
UI.println(UI.Style.TEXT_INFO_BOLD + " Web interface: ", UI.Style.TEXT_NORMAL, url)
open(url).catch(() => {})
await new Promise(() => {})
await server.stop()
},
})

View File

@@ -22,6 +22,7 @@ import { TuiThreadCommand } from "./cli/cmd/tui/thread"
import { TuiSpawnCommand } from "./cli/cmd/tui/spawn"
import { AcpCommand } from "./cli/cmd/acp"
import { EOL } from "os"
import { WebCommand } from "./cli/cmd/web"
process.on("unhandledRejection", (e) => {
Log.Default.error("rejection", {
@@ -81,6 +82,7 @@ const cli = yargs(hideBin(process.argv))
.command(AgentCommand)
.command(UpgradeCommand)
.command(ServeCommand)
.command(WebCommand)
.command(ModelsCommand)
.command(StatsCommand)
.command(ExportCommand)