mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-11-03 06:32:38 +08:00
89 lines
3.0 KiB
TypeScript
89 lines
3.0 KiB
TypeScript
import type { Argv, InferredOptionTypes } from "yargs"
|
|
import { ConfigV1 } from "@opencode-ai/core/v1/config/config"
|
|
import type { Config } from "@/config/config"
|
|
import { Effect } from "effect"
|
|
|
|
const options = {
|
|
port: {
|
|
type: "number" as const,
|
|
describe: "port to listen on",
|
|
default: 0,
|
|
},
|
|
hostname: {
|
|
type: "string" as const,
|
|
describe: "hostname to listen on",
|
|
default: "127.0.0.1",
|
|
},
|
|
mdns: {
|
|
type: "boolean" as const,
|
|
describe: "enable mDNS service discovery (defaults hostname to 0.0.0.0)",
|
|
default: false,
|
|
},
|
|
"mdns-domain": {
|
|
type: "string" as const,
|
|
describe: "custom domain name for mDNS service (default: kilo.local)", // kilocode_change
|
|
default: "kilo.local", // kilocode_change
|
|
},
|
|
cors: {
|
|
type: "string" as const,
|
|
array: true,
|
|
describe: "additional domains to allow for CORS",
|
|
default: [] as string[],
|
|
},
|
|
}
|
|
|
|
export type NetworkOptions = InferredOptionTypes<typeof options>
|
|
|
|
// kilocode_change start
|
|
const flags = [
|
|
["port", "--port"],
|
|
["hostname", "--hostname"],
|
|
["mdns", "--mdns"],
|
|
["mdnsDomain", "--mdns-domain"],
|
|
["cors", "--cors"],
|
|
] as const
|
|
export type NetworkOption = (typeof flags)[number][0]
|
|
|
|
export function explicitNetworkOptions(argv = process.argv) {
|
|
const index = argv.indexOf("--")
|
|
const args = index === -1 ? argv : argv.slice(0, index)
|
|
return flags.flatMap(([name, flag]) =>
|
|
args.some((arg) => arg === flag || arg.startsWith(`${flag}=`) || (name === "mdns" && arg === "--no-mdns"))
|
|
? [name]
|
|
: [],
|
|
)
|
|
}
|
|
// kilocode_change end
|
|
|
|
export function withNetworkOptions<T>(yargs: Argv<T>) {
|
|
return yargs.options(options)
|
|
}
|
|
export const resolveNetworkOptions = Effect.fn("Cli.resolveNetworkOptions")(function* (args: NetworkOptions) {
|
|
const { Config } = yield* Effect.promise(() => import("@/config/config"))
|
|
const config = yield* Config.Service.use((cfg) => cfg.getGlobal())
|
|
return resolveNetworkOptionsNoConfig(args, config)
|
|
})
|
|
|
|
export function resolveNetworkOptionsNoConfig(args: NetworkOptions, config?: ConfigV1.Info) {
|
|
// kilocode_change start
|
|
const explicit = explicitNetworkOptions()
|
|
const portExplicitlySet = explicit.includes("port")
|
|
const hostnameExplicitlySet = explicit.includes("hostname")
|
|
const mdnsExplicitlySet = explicit.includes("mdns")
|
|
const mdnsDomainExplicitlySet = explicit.includes("mdnsDomain")
|
|
// kilocode_change end
|
|
const mdns = mdnsExplicitlySet ? args.mdns : (config?.server?.mdns ?? args.mdns)
|
|
const mdnsDomain = mdnsDomainExplicitlySet ? args["mdns-domain"] : (config?.server?.mdnsDomain ?? args["mdns-domain"])
|
|
const port = portExplicitlySet ? args.port : (config?.server?.port ?? args.port)
|
|
const hostname = hostnameExplicitlySet
|
|
? args.hostname
|
|
: mdns && !config?.server?.hostname
|
|
? "0.0.0.0"
|
|
: (config?.server?.hostname ?? args.hostname)
|
|
const configCors = config?.server?.cors ?? []
|
|
const argsCors = Array.isArray(args.cors) ? args.cors : args.cors ? [args.cors] : []
|
|
const cors = [...configCors, ...argsCors]
|
|
|
|
return { hostname, port, mdns, mdnsDomain, cors }
|
|
}
|