2026-05-03 01:44:06 +00:00
|
|
|
import { Effect } from "effect"
|
2025-06-25 00:52:09 +00:00
|
|
|
import { Server } from "../../server/server"
|
2026-05-03 01:44:06 +00:00
|
|
|
import { effectCmd } from "../effect-cmd"
|
2025-12-26 20:24:44 +00:00
|
|
|
import { withNetworkOptions, resolveNetworkOptions } from "../network"
|
2026-04-25 17:29:52 +00:00
|
|
|
import { Flag } from "@opencode-ai/core/flag/flag"
|
2025-06-25 00:52:09 +00:00
|
|
|
|
2026-05-03 01:44:06 +00:00
|
|
|
export const ServeCommand = effectCmd({
|
2025-06-25 00:52:09 +00:00
|
|
|
command: "serve",
|
2025-12-26 20:24:44 +00:00
|
|
|
builder: (yargs) => withNetworkOptions(yargs),
|
2025-06-25 00:52:09 +00:00
|
|
|
describe: "starts a headless opencode server",
|
2026-05-03 01:44:06 +00:00
|
|
|
// Server loads instances per-request via x-opencode-directory header — no
|
|
|
|
|
// need for an ambient project InstanceContext at startup.
|
|
|
|
|
instance: false,
|
|
|
|
|
handler: Effect.fn("Cli.serve")(function* (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
|
|
|
}
|
2026-05-06 15:02:08 +00:00
|
|
|
const opts = yield* resolveNetworkOptions(args)
|
2026-05-03 01:44:06 +00:00
|
|
|
const server = yield* Effect.promise(() => 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-05-03 01:44:06 +00:00
|
|
|
yield* Effect.never
|
|
|
|
|
}),
|
2025-06-25 00:52:09 +00:00
|
|
|
})
|