2025-06-25 00:52:09 +00:00
|
|
|
import { Server } from "../../server/server"
|
|
|
|
|
import { cmd } from "./cmd"
|
2025-12-26 20:24:44 +00:00
|
|
|
import { withNetworkOptions, resolveNetworkOptions } from "../network"
|
2026-01-12 20:23:12 +00:00
|
|
|
import { Flag } from "../../flag/flag"
|
2026-02-27 20:36:39 +00:00
|
|
|
import { Workspace } from "../../control-plane/workspace"
|
|
|
|
|
import { Project } from "../../project/project"
|
|
|
|
|
import { Installation } from "../../installation"
|
2026-03-28 17:28:24 +00:00
|
|
|
import { PushRelay } from "../../server/push-relay"
|
2025-06-25 00:52:09 +00:00
|
|
|
|
|
|
|
|
export const ServeCommand = cmd({
|
|
|
|
|
command: "serve",
|
2026-03-28 17:28:24 +00:00
|
|
|
builder: (yargs) =>
|
|
|
|
|
withNetworkOptions(yargs)
|
|
|
|
|
.option("relay-url", {
|
|
|
|
|
type: "string",
|
|
|
|
|
describe: "experimental APN relay URL",
|
|
|
|
|
})
|
|
|
|
|
.option("relay-secret", {
|
|
|
|
|
type: "string",
|
|
|
|
|
describe: "experimental APN relay secret",
|
|
|
|
|
}),
|
2025-06-25 00:52:09 +00:00
|
|
|
describe: "starts a headless opencode server",
|
|
|
|
|
handler: async (args) => {
|
2026-01-12 20:59:17 +00:00
|
|
|
if (!Flag.OPENCODE_SERVER_PASSWORD) {
|
|
|
|
|
console.log("Warning: OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
|
2026-01-12 20:23:12 +00:00
|
|
|
}
|
2025-12-26 20:47:44 +00:00
|
|
|
const opts = await resolveNetworkOptions(args)
|
2025-12-26 20:24:44 +00:00
|
|
|
const server = Server.listen(opts)
|
2025-11-03 21:35:46 +00:00
|
|
|
console.log(`opencode server listening on http://${server.hostname}:${server.port}`)
|
2026-02-27 20:36:39 +00:00
|
|
|
|
2026-03-28 17:28:24 +00:00
|
|
|
const relayURL = (
|
|
|
|
|
args["relay-url"] ??
|
|
|
|
|
process.env.OPENCODE_EXPERIMENTAL_PUSH_RELAY_URL ??
|
|
|
|
|
"https://relay.opencode.ai"
|
|
|
|
|
).trim()
|
|
|
|
|
const relaySecret = (args["relay-secret"] ?? process.env.OPENCODE_EXPERIMENTAL_PUSH_RELAY_SECRET ?? "").trim()
|
|
|
|
|
if (relayURL && relaySecret) {
|
|
|
|
|
const host = server.hostname ?? opts.hostname
|
|
|
|
|
const port = server.port || opts.port || 4096
|
|
|
|
|
const pair = PushRelay.start({
|
|
|
|
|
relayURL,
|
|
|
|
|
relaySecret,
|
|
|
|
|
hostname: host,
|
|
|
|
|
port,
|
|
|
|
|
})
|
|
|
|
|
if (pair) {
|
|
|
|
|
console.log("experimental push relay enabled")
|
|
|
|
|
console.log("qr payload")
|
|
|
|
|
console.log(JSON.stringify(pair, null, 2))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-01 21:15:49 +00:00
|
|
|
await new Promise(() => {})
|
2025-10-31 04:57:58 +00:00
|
|
|
await server.stop()
|
2025-06-25 00:52:09 +00:00
|
|
|
},
|
|
|
|
|
})
|