Dax Raad hace 3 meses
padre
commit
902763b47d

+ 7 - 1
packages/opencode/src/cli/cmd/serve.ts

@@ -1,4 +1,5 @@
 import { Server } from "../../server/server"
 import { Server } from "../../server/server"
+import { UI } from "../ui"
 import { cmd } from "./cmd"
 import { cmd } from "./cmd"
 
 
 export const ServeCommand = cmd({
 export const ServeCommand = cmd({
@@ -24,7 +25,12 @@ export const ServeCommand = cmd({
       port,
       port,
       hostname,
       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 new Promise(() => {})
     await server.stop()
     await server.stop()
   },
   },

+ 6 - 2
packages/opencode/src/cli/cmd/tui/app.tsx

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

+ 38 - 0
packages/opencode/src/cli/cmd/web.ts

@@ -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()
+  },
+})

+ 2 - 0
packages/opencode/src/index.ts

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