Files
crosscode-platform/apps/agent/src/command.ts
T
joshuaandClaude Opus 5.5 2e8e4c04ca agent 1.7.0 + contracts 1.23.0: a demo scenario seeds whatever the church has installed
- contracts 1.23.0: the seed-scenario job (church, scenario, optional adminEmail; 45 minutes),
  SEED_SCENARIO_JOB_MIN_AGENT 1.7.0.
- agent 1.7.0: seed-scenario -> `crosscode demo <church> --scenario <s>`; seed-demo for
  accounts and app, and --scenario passed on to every product.
- crosscode script: `crosscode demo <church> --scenario <s>` loads the scenario on every product
  the church has here (Accounts, Events, the Website, the App), skipping the rest; every
  installed release checked first; the first failure stops the rest and names what's out of
  step (loaded / skipped in the report). `crosscode demo <church> app` says the App's demo comes
  with App 1.0.0.
- Docs: HANDOVER, APP-1.0-PLAN, VERSIONS, CHANGELOG, agent What's New.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 16:25:31 +02:00

93 lines
4.8 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, frp-read, frp-write, probe-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;
const product = a.products[0];
if (a.products.length !== 1 || (product !== "events" && product !== "accounts")) throw new Error("This agent installs one product at a time: Events or Accounts.");
const domain = a.domains[product];
const ports = a.ports[product];
if (!domain || !ports) throw new Error(`An install of ${product} needs its domain and ports.`);
// The church's address: the product's domain without "<product>." (crosscode keeps it in
// church.env ADDRESS for the products added later; the domain itself goes in --<product>-domain).
const address = domain.startsWith(`${product}.`) ? domain.slice(product.length + 1) : domain;
const out = ["install", a.church, "--products", product, "--domain", address, `--${product}-domain`, domain,
"--api-port", String(ports.api), "--web-port", String(ports.web), "--frp"];
const v = a.versions?.[product];
if (v) out.push("--version", v);
return out;
}
case "add-product": {
// A product next to the church's others (phase 3: Accounts next to Events), behind frp.
const a = job.args;
const out = ["add", a.church, a.product, "--domain", a.domain, "--api-port", String(a.ports.api), "--web-port", String(a.ports.web), "--frp"];
if (a.version) out.push("--version", a.version);
return out;
}
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 "env-read":
return ["env", job.args.church, job.args.product];
case "env-set": {
// Each value is its own argument (no shell), so spaces and quotes in values are safe.
const out = ["env", job.args.church, job.args.product, "--file", job.args.file];
for (const [name, value] of Object.entries(job.args.set)) out.push("--set", `${name}=${value}`);
for (const name of job.args.unset) out.push("--unset", name);
if (job.args.restart) out.push("--restart");
return out;
}
case "seed-demo": {
// 1.6.0: the Website's demo names the product; Events' (no product) keeps its old form.
// 1.7.0: the App's and Accounts' too, and a demo scenario passed on (`--scenario`), so each
// product can tell a scenario load from a single one.
const a = job.args;
const product = a.product && a.product !== "events" ? [a.product] : [];
return ["demo", a.church, ...product, "--profile", a.profile,
...(a.scenario ? ["--scenario", a.scenario] : []),
...(a.adminEmail ? ["--admin-email", a.adminEmail] : [])];
}
case "seed-scenario":
// 1.7.0: a whole demo scenario. No product named: the script loads every product the church
// has on this server, Accounts first, and skips the others.
return ["demo", job.args.church, "--scenario", job.args.scenario, ...(job.args.adminEmail ? ["--admin-email", job.args.adminEmail] : [])];
case "export":
if (!opts.exportFile) throw new Error("export needs a file to write");
return ["export", job.args.church, ...(job.args.products ?? []), "--out", opts.exportFile];
case "uninstall":
// 1.5.0: only the products named go (the church keeps its others); none named: the church.
return ["uninstall", job.args.church, ...(job.args.products ?? []), "--confirm", job.args.church];
case "purge":
return ["purge", job.args.church, ...(job.args.products ?? []), "--confirm", job.args.church];
case "status":
return ["status", ...(job.args.church ? [job.args.church] : []), "--no-fetch"];
case "update-agent":
case "check-ports":
case "frp-read":
case "frp-write":
case "probe-ports":
return null;
}
}