Files
Kilo-Org_kilocode/packages/opencode/src/cli/cmd/serve.ts
T
2026-05-06 21:32:26 +02:00

36 lines
1.3 KiB
TypeScript

import { Server } from "../../server/server"
import { cmd } from "./cmd"
import { withNetworkOptions, resolveNetworkOptions } from "../network"
import { Flag } from "@opencode-ai/core/flag/flag"
import { InstanceStore } from "../../project/instance-store" // kilocode_change
export const ServeCommand = cmd({
command: "serve",
builder: (yargs) => withNetworkOptions(yargs),
describe: "starts a headless kilo server", // kilocode_change
handler: async (args) => {
if (!Flag.KILO_SERVER_PASSWORD) {
console.log("Warning: KILO_SERVER_PASSWORD is not set; server is unsecured.")
}
const opts = await resolveNetworkOptions(args)
const server = await Server.listen(opts)
console.log(`kilo server listening on http://${server.hostname}:${server.port}`)
// kilocode_change start - graceful signal shutdown
const abort = new AbortController()
const shutdown = async () => {
try {
await InstanceStore.disposeAllInstances()
await server.stop(true)
} finally {
abort.abort()
}
}
process.on("SIGTERM", shutdown)
process.on("SIGINT", shutdown)
process.on("SIGHUP", shutdown)
await new Promise((resolve) => abort.signal.addEventListener("abort", resolve))
// kilocode_change end
},
})