36 lines
1.3 KiB
TypeScript
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
|
|
},
|
|
})
|