import { parseArgs } from "node:util" import { loadAgentPaaSConfig, requestJSON } from "../.opencode/lib/agentpaas" import { startSoftwareReviewPanel } from "../.opencode/lib/software-review-panel" const args = parseArgs({ options: { review: { type: "string" }, port: { type: "string" } } }).values if (!args.review || !/^[a-f0-9]{32}$/.test(args.review)) throw new Error("使用 --review <真实审阅编号>;凭证通过现有 AGENTPAAS 配置读取") const base = await loadAgentPaaSConfig() const url = process.env.AGENTPAAS_SOFTWARE_REVIEW_URL?.replace(/\/+$/, "") || base.url const target = new URL(url) const origin = new URL(base.url) if (target.hostname !== origin.hostname || target.protocol !== origin.protocol || target.username || target.password || target.search || target.hash || target.pathname !== "/") throw new Error("审阅 API 必须与 PaaS 使用相同主机与协议") const port = args.port ? Number(args.port) : 0 if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error("无效端口") const config = { ...base, url } await requestJSON(config, `/software-reviews/${args.review}`, new AbortController().signal) const panel = startSoftwareReviewPanel(config, args.review, port, "dashboard") console.log(JSON.stringify({ url: panel.url, review_id: args.review, read_only: true })) process.on("SIGTERM", () => { panel.server.stop(true); process.exit(0) }) process.on("SIGINT", () => { panel.server.stop(true); process.exit(0) })