apps/agent (docs/AGENT-1.0-PLAN.md §3-4, §10): listens on nothing; checks every job (pinned Hub key, server, time window, replays for 90 days, type per mode, strict arguments) before running crosscode with an argument array; opens the sealed config into a root-only file only for the job; redacts log lines; keeps unsent reports in an outbox; encrypts exports before upload; check-ports on the central server (read-only); self-update with automatic revert. One bundled dist/cli.js, a systemd unit and the install script that joins a server with a one-time token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.7 KiB
TypeScript
59 lines
2.7 KiB
TypeScript
import type { agent } from "@crosscode/contracts";
|
|
|
|
/**
|
|
* The `crosscode` arguments for a job (AGENT-1.0-PLAN §4): built from the checked arguments only,
|
|
* as an array passed straight to the process (never through a shell). Jobs the agent handles
|
|
* itself (update-agent, check-ports) have none.
|
|
*
|
|
* `--config <file>` is added by the runner when the job brings config; `--json` always.
|
|
*/
|
|
export function crosscodeArgs(job: agent.AgentJob, opts: { exportFile?: string } = {}): string[] | null {
|
|
switch (job.type) {
|
|
case "install": {
|
|
const a = job.args;
|
|
if (a.products.length !== 1 || a.products[0] !== "events") throw new Error("This agent can only install Events so far.");
|
|
const domain = a.domains.events;
|
|
const ports = a.ports.events;
|
|
if (!domain || !ports) throw new Error("An Events install needs its domain and ports.");
|
|
// The church's address: the Events domain without "events." (crosscode uses it for the
|
|
// church.env ADDRESS; the domain itself goes in --events-domain).
|
|
const address = domain.startsWith("events.") ? domain.slice("events.".length) : domain;
|
|
const out = ["install", a.church, "--products", "events", "--domain", address, "--events-domain", domain,
|
|
"--api-port", String(ports.api), "--web-port", String(ports.web), "--frp"];
|
|
const v = a.versions?.events;
|
|
if (v) out.push("--version", v);
|
|
return out;
|
|
}
|
|
case "add-product":
|
|
return ["add", job.args.church, job.args.product];
|
|
case "deploy": {
|
|
const out = ["deploy", job.args.church, ...job.args.products];
|
|
for (const v of job.args.versions ?? []) out.push("--version", v);
|
|
if (job.args.check) out.push("--check");
|
|
return out;
|
|
}
|
|
case "adopt": {
|
|
const out = ["adopt", job.args.church, "--events-dir", job.args.eventsDir];
|
|
if (job.args.version) out.push("--version", job.args.version);
|
|
if (job.args.address) out.push("--address", job.args.address);
|
|
return out;
|
|
}
|
|
case "adopt-undo":
|
|
return ["adopt", job.args.church, "--undo"];
|
|
case "restart":
|
|
return ["restart", job.args.church, ...(job.args.product ? [job.args.product] : [])];
|
|
case "export":
|
|
if (!opts.exportFile) throw new Error("export needs a file to write");
|
|
return ["export", job.args.church, "--out", opts.exportFile];
|
|
case "uninstall":
|
|
return ["uninstall", job.args.church, "--confirm", job.args.church];
|
|
case "purge":
|
|
return ["purge", job.args.church, "--confirm", job.args.church];
|
|
case "status":
|
|
return ["status", ...(job.args.church ? [job.args.church] : []), "--no-fetch"];
|
|
case "update-agent":
|
|
case "check-ports":
|
|
return null;
|
|
}
|
|
}
|