feat(setup)!: expand agent integrations and verify updates (#577)
* feat(setup)!: expand agent integrations and simplify onboarding Add native configuration formats for OpenCode, Antigravity, GitHub Copilot CLI, VS Code, and Devin. Preserve JSONC comments and unrelated settings while making setup and uninstall ownership-aware and idempotent. Select agent targets before planning, separate discovery from intent, and keep agent-only setup independent of optional provider prerequisites. Cover configuration boundaries and interactive behavior in packaged checks. BREAKING CHANGE: unscoped setup refreshes only existing REA-owned registrations. Use --all-detected to configure every detected client. Setup JSON contains a compact doctor summary; use rea doctor for full diagnostics. Cancellation and successful dry runs now exit successfully. * feat(cli)!: replace upgrade with verified updates Resolve an exact release through npm's configured registry, update only the identified installation, and verify its new executable before reporting success. Return a read-only maintenance plan for existing enabled REA integrations. BREAKING CHANGE: replace rea upgrade with rea update; no alias is retained. Successful update JSON uses status "updated", reports the verified installed version, and returns an unapplied maintenance plan instead of opening setup.
This commit is contained in:
@@ -2,7 +2,7 @@ import { json, run, runWithStatus } from "./lib/verify-package-core.mjs";
|
||||
|
||||
const REQUIRED_HELP_COMMANDS = [
|
||||
"setup",
|
||||
"upgrade",
|
||||
"update",
|
||||
"inspect-artifact",
|
||||
"extract-artifact",
|
||||
"import-reference-source",
|
||||
@@ -39,6 +39,9 @@ export async function verifyPackageDiscovery({ cli, environment }) {
|
||||
const doctor = json(doctorExecution.stdout);
|
||||
const supportedSetupHost =
|
||||
doctor.checks?.find(({ name }) => name === "host")?.ok === true;
|
||||
const hopperSetupSupported =
|
||||
supportedSetupHost && process.platform !== "win32";
|
||||
const hopperReady = doctor.checks?.find(({ name }) => name === "hopper")?.ok;
|
||||
const expectedDoctorHealth = doctor.checks?.every(({ ok }) => ok) === true;
|
||||
const missingHelp = REQUIRED_HELP_COMMANDS.filter(
|
||||
(command) => !help.includes(command),
|
||||
@@ -51,10 +54,10 @@ export async function verifyPackageDiscovery({ cli, environment }) {
|
||||
missingLlms.length !== 0 ||
|
||||
doctor.healthy !== expectedDoctorHealth ||
|
||||
doctorExecution.status !== (expectedDoctorHealth ? 0 : 1) ||
|
||||
doctor.checks?.find(({ name }) => name === "hopper")?.ok !== true
|
||||
(hopperSetupSupported && hopperReady !== true)
|
||||
)
|
||||
throw new Error(
|
||||
`packaged CLI discovery or doctor failed: ${JSON.stringify({ helpSetup: help.includes("setup"), llmsDecompile: llms.includes("decompile"), doctor })}`,
|
||||
);
|
||||
return { supportedSetupHost };
|
||||
return { supportedSetupHost, hopperSetupSupported };
|
||||
}
|
||||
|
||||
@@ -18,6 +18,16 @@ import {
|
||||
run,
|
||||
runWithStatus,
|
||||
} from "./lib/verify-package-core.mjs";
|
||||
import { parse as parseJsonc } from "jsonc-parser";
|
||||
|
||||
const OPENCODE_ORIGINAL = `{
|
||||
// OpenCode preferences must survive setup.
|
||||
"model": "provider/model",
|
||||
"mcp": {
|
||||
// Keep this independently managed server.
|
||||
"other": { "type": "local", "command": ["node", "other.js"] },
|
||||
},
|
||||
}\n`;
|
||||
|
||||
const verifyMcpAdd = async ({ cli, environment, npxLog }) => {
|
||||
await run(cli, ["mcp", "add"], environment);
|
||||
@@ -27,12 +37,48 @@ const verifyMcpAdd = async ({ cli, environment, npxLog }) => {
|
||||
throw new Error("Incur mcp add did not register the pinned npx command");
|
||||
};
|
||||
|
||||
const verifyInteractiveSetup = async ({ command, environment, root }) =>
|
||||
const snapshotFiles = async (paths) =>
|
||||
Promise.all(
|
||||
paths.map(async (path) => {
|
||||
const exists = await pathExists(path);
|
||||
return {
|
||||
path,
|
||||
exists,
|
||||
content: exists ? await readFile(path, "utf8") : null,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
const assertFilesUnchanged = async (snapshot, label) => {
|
||||
for (const entry of snapshot) {
|
||||
const exists = await pathExists(entry.path);
|
||||
const content = exists ? await readFile(entry.path, "utf8") : null;
|
||||
if (exists !== entry.exists || content !== entry.content)
|
||||
throw new Error(`${label} changed ${entry.path}`);
|
||||
}
|
||||
};
|
||||
|
||||
const verifyInteractiveSetup = async ({
|
||||
command,
|
||||
environment,
|
||||
root,
|
||||
unchangedPaths,
|
||||
}) =>
|
||||
new Promise((resolvePromise, reject) => {
|
||||
let output = "";
|
||||
let cancelled = false;
|
||||
let settled = false;
|
||||
const terminal = spawn(command, ["setup"], {
|
||||
const unchanged = snapshotFiles(unchangedPaths);
|
||||
const wrapper = `
|
||||
const { spawnSync } = require("node:child_process");
|
||||
const child = spawnSync(process.argv[1], ["setup"], { stdio: "inherit", env: process.env, shell: process.platform === "win32" });
|
||||
const terminal = process.platform === "win32"
|
||||
? spawnSync("cmd.exe", ["/c", "mode", "CON"], { encoding: "utf8", stdio: ["inherit", "pipe", "inherit"] })
|
||||
: spawnSync("stty", ["-a"], { encoding: "utf8", stdio: ["inherit", "pipe", "inherit"] });
|
||||
process.stdout.write("\\n__REA_SETUP_EXIT__" + JSON.stringify({ status: child.status, termios: terminal.stdout, error: child.error?.message }));
|
||||
process.exit(child.status ?? 1);
|
||||
`;
|
||||
const terminal = spawn(process.execPath, ["-e", wrapper, command], {
|
||||
cwd: root,
|
||||
env: { ...environment, NO_COLOR: "1", TERM: "xterm-256color" },
|
||||
name: "xterm-256color",
|
||||
@@ -55,21 +101,120 @@ const verifyInteractiveSetup = async ({ command, environment, root }) =>
|
||||
|
||||
terminal.onData((data) => {
|
||||
output += data;
|
||||
if (!cancelled && output.includes("What should REA set up?")) {
|
||||
if (!cancelled && output.includes("Which agents should use REA?")) {
|
||||
cancelled = true;
|
||||
terminal.write("\u0003");
|
||||
}
|
||||
});
|
||||
terminal.onExit(() => {
|
||||
if (!cancelled || !output.includes("No changes were made.")) {
|
||||
terminal.onExit(async ({ exitCode }) => {
|
||||
const marker = output.lastIndexOf("__REA_SETUP_EXIT__");
|
||||
const result = marker < 0 ? undefined : output.slice(marker + 18).trim();
|
||||
let childResult;
|
||||
try {
|
||||
childResult = result === undefined ? undefined : JSON.parse(result);
|
||||
} catch {
|
||||
childResult = undefined;
|
||||
}
|
||||
if (
|
||||
!cancelled ||
|
||||
exitCode !== 0 ||
|
||||
childResult?.status !== 0 ||
|
||||
!output.includes("\u001b[?25h") ||
|
||||
(process.platform !== "win32" &&
|
||||
(!childResult.termios?.includes("icanon") ||
|
||||
!childResult.termios?.includes("echo"))) ||
|
||||
!output.includes("No changes were made.")
|
||||
) {
|
||||
finish(
|
||||
new Error(
|
||||
`packaged rea-agents setup did not open and cancel the wizard: ${output}`,
|
||||
`packaged rea-agents setup did not cancel with a restored terminal and exit 0: ${output}`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
finish();
|
||||
try {
|
||||
await assertFilesUnchanged(await unchanged, "Interactive cancellation");
|
||||
finish();
|
||||
} catch (error) {
|
||||
finish(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const verifyRedirectedStdoutSetup = async ({
|
||||
command,
|
||||
environment,
|
||||
root,
|
||||
unchangedPaths,
|
||||
}) =>
|
||||
new Promise((resolvePromise, reject) => {
|
||||
let output = "";
|
||||
let settled = false;
|
||||
const unchanged = snapshotFiles(unchangedPaths);
|
||||
const wrapper = `
|
||||
const { spawnSync } = require("node:child_process");
|
||||
const child = spawnSync(process.argv[1], ["setup"], { encoding: "utf8", env: process.env, stdio: ["inherit", "pipe", "inherit"], shell: process.platform === "win32" });
|
||||
process.stdout.write("\\n__REA_REDIRECTED_SETUP__" + JSON.stringify({ status: child.status, stdout: child.stdout, error: child.error?.message, stdinTTY: process.stdin.isTTY, stderrTTY: process.stderr.isTTY, stdoutRedirected: true }));
|
||||
process.exit(child.status ?? 1);
|
||||
`;
|
||||
const terminal = spawn(process.execPath, ["-e", wrapper, command], {
|
||||
cwd: root,
|
||||
env: { ...environment, NO_COLOR: "1", TERM: "xterm-256color" },
|
||||
name: "xterm-256color",
|
||||
cols: 120,
|
||||
rows: 40,
|
||||
});
|
||||
const finish = (error) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
clearTimeout(timeout);
|
||||
if (error === undefined) resolvePromise();
|
||||
else reject(error);
|
||||
};
|
||||
const timeout = setTimeout(() => {
|
||||
terminal.kill();
|
||||
finish(
|
||||
new Error(
|
||||
`packaged setup started an interactive prompt with redirected stdout: ${output}`,
|
||||
),
|
||||
);
|
||||
}, 15_000);
|
||||
terminal.onData((data) => {
|
||||
output += data;
|
||||
});
|
||||
terminal.onExit(async ({ exitCode }) => {
|
||||
const marker = output.lastIndexOf("__REA_REDIRECTED_SETUP__");
|
||||
let childResult;
|
||||
try {
|
||||
childResult =
|
||||
marker < 0 ? undefined : JSON.parse(output.slice(marker + 24).trim());
|
||||
} catch {
|
||||
childResult = undefined;
|
||||
}
|
||||
const allOutput = `${output}\n${childResult?.stdout ?? ""}`;
|
||||
if (
|
||||
(exitCode !== 0 && exitCode !== 1) ||
|
||||
childResult?.status !== exitCode ||
|
||||
childResult.stdinTTY !== true ||
|
||||
childResult.stderrTTY !== true ||
|
||||
childResult.stdoutRedirected !== true ||
|
||||
childResult.stdout?.includes("Which agents should use REA?") ||
|
||||
allOutput.includes("Which agents should use REA?") ||
|
||||
/\u001b\[[0-9;?]*[ -/]*[@-~]/u.test(allOutput)
|
||||
) {
|
||||
finish(
|
||||
new Error(
|
||||
`packaged setup did not remain plain and non-interactive with redirected stdout: ${output}`,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await assertFilesUnchanged(await unchanged, "Redirected-stdout setup");
|
||||
finish();
|
||||
} catch (error) {
|
||||
finish(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -79,11 +224,13 @@ const verifySetupPlan = async ({
|
||||
claudeConfig,
|
||||
cursorConfig,
|
||||
codexTarget,
|
||||
opencodeConfig,
|
||||
opencodeOriginal,
|
||||
supportedSetupHost,
|
||||
}) => {
|
||||
const plannedExecution = await runWithStatus(
|
||||
cli,
|
||||
["setup", "--json"],
|
||||
["setup", "--all-detected", "--dry-run", "--json"],
|
||||
environment,
|
||||
);
|
||||
const planned = json(plannedExecution.stdout);
|
||||
@@ -91,15 +238,17 @@ const verifySetupPlan = async ({
|
||||
const plannedClaudeConfig = await readFile(claudeConfig, "utf8");
|
||||
const plannedCodexConfig = await readFile(codexTarget, "utf8");
|
||||
const plannedCursorConfig = await readFile(cursorConfig, "utf8");
|
||||
const plannedOpenCodeConfig = await readFile(opencodeConfig, "utf8");
|
||||
if (
|
||||
planned.status !== "needs_confirmation" ||
|
||||
plannedExecution.status !== 1 ||
|
||||
planned.status !== "planned" ||
|
||||
plannedExecution.status !== 0 ||
|
||||
planned.appliedActions.length !== 0 ||
|
||||
!planned.plannedActions.some(({ kind }) => kind === "configure_client") ||
|
||||
!planned.plannedActions.some(({ kind }) => kind === "install_skill") ||
|
||||
plannedClaudeConfig !== '{"existing":true}\n' ||
|
||||
plannedCodexConfig !== 'model = "gpt-5"\n' ||
|
||||
plannedCursorConfig !== '{"existing":true}\n'
|
||||
plannedCursorConfig !== '{"existing":true}\n' ||
|
||||
plannedOpenCodeConfig !== opencodeOriginal
|
||||
)
|
||||
throw new Error(
|
||||
`packaged setup plan was not read-only: ${JSON.stringify({ status: planned.status, exitCode: plannedExecution.status, plannedKinds: planned.plannedActions.map(({ kind }) => kind), appliedKinds: planned.appliedActions.map(({ kind }) => kind), claudeConfig: plannedClaudeConfig, codexConfig: plannedCodexConfig, cursorConfig: plannedCursorConfig })}`,
|
||||
@@ -108,11 +257,101 @@ const verifySetupPlan = async ({
|
||||
return { planned };
|
||||
};
|
||||
|
||||
const verifySetupApply = async ({ cli, environment, supportedSetupHost }) => {
|
||||
const status = process.platform === "linux" ? "needs_human" : "ready";
|
||||
const verifyAbsentOpenCodeSetup = async ({ cli, environment, home }) => {
|
||||
const xdgConfigHome = join(home, ".xdg-opencode-absent");
|
||||
const configPath = join(xdgConfigHome, "opencode", "opencode.json");
|
||||
if (await pathExists(configPath))
|
||||
throw new Error("packaged OpenCode first-run fixture was not absent");
|
||||
const execution = await runWithStatus(
|
||||
cli,
|
||||
["setup", "--yes", "--client", "opencode", "--skill=false", "--json"],
|
||||
{ ...environment, XDG_CONFIG_HOME: xdgConfigHome },
|
||||
);
|
||||
const result = json(execution.stdout);
|
||||
const config = JSON.parse(await readFile(configPath, "utf8"));
|
||||
if (
|
||||
execution.status !== 0 ||
|
||||
result.status !== "ready" ||
|
||||
!result.appliedActions.includes("configured_opencode") ||
|
||||
config.mcp?.rea?.type !== "local" ||
|
||||
config.mcp.rea.enabled !== true ||
|
||||
JSON.stringify(config.mcp.rea.command) !== JSON.stringify([cli, "mcp"])
|
||||
)
|
||||
throw new Error(
|
||||
`packaged setup did not configure explicitly selected OpenCode without a config file: ${JSON.stringify(result)}`,
|
||||
);
|
||||
await rm(xdgConfigHome, { recursive: true, force: true });
|
||||
};
|
||||
|
||||
const verifyAbsentClaudeCodeSetup = async ({ cli, environment, home }) => {
|
||||
const freshHome = join(home, ".claude-code-absent-home");
|
||||
const configPath = join(freshHome, ".claude.json");
|
||||
const markerPath = join(freshHome, ".claude");
|
||||
await rm(freshHome, { recursive: true, force: true });
|
||||
await mkdir(freshHome, { recursive: true });
|
||||
const childEnvironment = {
|
||||
...environment,
|
||||
HOME: freshHome,
|
||||
USERPROFILE: freshHome,
|
||||
XDG_CONFIG_HOME: join(freshHome, ".config"),
|
||||
};
|
||||
delete childEnvironment.CLAUDE_CONFIG_DIR;
|
||||
if ((await pathExists(configPath)) || (await pathExists(markerPath)))
|
||||
throw new Error("packaged Claude Code first-run fixture was not absent");
|
||||
const args = [
|
||||
"setup",
|
||||
"--yes",
|
||||
"--client",
|
||||
"claude_code",
|
||||
"--skill=false",
|
||||
"--json",
|
||||
];
|
||||
const firstExecution = await runWithStatus(cli, args, childEnvironment);
|
||||
const first = json(firstExecution.stdout);
|
||||
const config = json(await readFile(configPath, "utf8"));
|
||||
const registration = first.doctor.identity?.registrations?.find(
|
||||
({ client }) => client === "claude_code",
|
||||
);
|
||||
if (
|
||||
firstExecution.status !== 0 ||
|
||||
first.status !== "ready" ||
|
||||
!first.appliedActions.includes("configured_claude_code") ||
|
||||
config.mcpServers?.rea?.command !== cli ||
|
||||
JSON.stringify(config.mcpServers?.rea?.args) !== JSON.stringify(["mcp"]) ||
|
||||
(await pathExists(markerPath)) ||
|
||||
registration?.state !== "aligned" ||
|
||||
registration.config_path !== configPath
|
||||
)
|
||||
throw new Error(
|
||||
`packaged setup did not configure an explicitly selected Claude Code with no marker directory: ${JSON.stringify(first)}`,
|
||||
);
|
||||
const repeatExecution = await runWithStatus(cli, args, childEnvironment);
|
||||
const repeat = json(repeatExecution.stdout);
|
||||
if (
|
||||
repeatExecution.status !== 0 ||
|
||||
repeat.status !== "ready" ||
|
||||
repeat.appliedActions.length !== 0 ||
|
||||
repeat.plannedActions.length !== 0
|
||||
)
|
||||
throw new Error(
|
||||
`packaged setup was not idempotent for Claude Code without a marker directory: ${JSON.stringify(repeat)}`,
|
||||
);
|
||||
await rm(freshHome, { recursive: true, force: true });
|
||||
};
|
||||
|
||||
const verifySetupApply = async ({
|
||||
cli,
|
||||
environment,
|
||||
supportedSetupHost,
|
||||
hopperSetupSupported,
|
||||
}) => {
|
||||
const status = "ready";
|
||||
const hopperStatus = hopperSetupSupported
|
||||
? "needs_confirmation"
|
||||
: "needs_human";
|
||||
const firstExecution = await runWithStatus(
|
||||
cli,
|
||||
["setup", "--yes", "--json"],
|
||||
["setup", "--yes", "--all-detected", "--json"],
|
||||
environment,
|
||||
);
|
||||
const first = json(firstExecution.stdout);
|
||||
@@ -124,14 +363,24 @@ const verifySetupApply = async ({ cli, environment, supportedSetupHost }) => {
|
||||
const aligned = json(alignedExecution.stdout);
|
||||
const secondExecution = await runWithStatus(
|
||||
cli,
|
||||
["setup", "--install-hopper", "--json"],
|
||||
[
|
||||
"setup",
|
||||
"--client",
|
||||
"claude_desktop",
|
||||
"--client",
|
||||
"codex",
|
||||
"--client",
|
||||
"cursor",
|
||||
"--install-hopper",
|
||||
"--json",
|
||||
],
|
||||
environment,
|
||||
);
|
||||
const second = json(secondExecution.stdout);
|
||||
if (supportedSetupHost) {
|
||||
if (
|
||||
first.status !== status ||
|
||||
second.status !== "needs_confirmation" ||
|
||||
second.status !== hopperStatus ||
|
||||
firstExecution.status !== (status === "ready" ? 0 : 1) ||
|
||||
secondExecution.status !== 1 ||
|
||||
aligned.status !== status ||
|
||||
@@ -170,6 +419,31 @@ const assertClientConfig = async (cli, configPath) => {
|
||||
throw new Error("packaged client backup failed");
|
||||
};
|
||||
|
||||
const assertOpenCodeConfig = async ({
|
||||
cli,
|
||||
configPath,
|
||||
expectedRegistration,
|
||||
}) => {
|
||||
const contents = await readFile(configPath, "utf8");
|
||||
const errors = [];
|
||||
const parsed = parseJsonc(contents, errors, { allowTrailingComma: true });
|
||||
const config = parsed;
|
||||
const mcp = config?.mcp;
|
||||
if (
|
||||
errors.length !== 0 ||
|
||||
!contents.includes("// OpenCode preferences must survive setup.") ||
|
||||
!contents.includes("// Keep this independently managed server.") ||
|
||||
config?.model !== "provider/model" ||
|
||||
mcp?.other?.command?.[0] !== "node" ||
|
||||
(expectedRegistration &&
|
||||
(mcp?.rea?.type !== "local" ||
|
||||
mcp.rea.enabled !== true ||
|
||||
JSON.stringify(mcp.rea.command) !== JSON.stringify([cli, "mcp"]))) ||
|
||||
(!expectedRegistration && mcp?.rea !== undefined)
|
||||
)
|
||||
throw new Error("packaged OpenCode JSONC registration readback failed");
|
||||
};
|
||||
|
||||
const assertCodexSymlink = async ({
|
||||
cli,
|
||||
codexConfig,
|
||||
@@ -245,6 +519,8 @@ const verifyConfigReadback = async ({
|
||||
root,
|
||||
skillPath,
|
||||
siblingSkillPath,
|
||||
opencodeConfig,
|
||||
opencodeOriginal,
|
||||
}) => {
|
||||
await assertClientConfig(cli, claudeConfig);
|
||||
await assertClientConfig(cli, cursorConfig);
|
||||
@@ -255,6 +531,18 @@ const verifyConfigReadback = async ({
|
||||
codexTarget,
|
||||
});
|
||||
await assertSkill({ skillPath, siblingSkillPath, root });
|
||||
await assertOpenCodeConfig({
|
||||
cli,
|
||||
configPath: opencodeConfig,
|
||||
expectedRegistration: true,
|
||||
});
|
||||
if (
|
||||
(await readFile(`${opencodeConfig}.rea.backup`, "utf8")) !==
|
||||
opencodeOriginal
|
||||
)
|
||||
throw new Error(
|
||||
"packaged OpenCode backup did not preserve the original JSONC",
|
||||
);
|
||||
await assertAlignedDoctor(cli, environment);
|
||||
};
|
||||
|
||||
@@ -269,7 +557,7 @@ const verifySetupFailureRecovery = async ({
|
||||
await writeFile(cursorConfig, '{"existing":true}\n');
|
||||
const failedExecution = await runWithStatus(
|
||||
cli,
|
||||
["setup", "--yes", "--json"],
|
||||
["setup", "--yes", "--all-detected", "--json"],
|
||||
environment,
|
||||
);
|
||||
const failed = json(failedExecution.stdout);
|
||||
@@ -289,7 +577,7 @@ const verifySetupFailureRecovery = async ({
|
||||
await writeFile(claudeConfig, "{}\n");
|
||||
const recoveredExecution = await runWithStatus(
|
||||
cli,
|
||||
["setup", "--yes", "--json"],
|
||||
["setup", "--yes", "--all-detected", "--json"],
|
||||
environment,
|
||||
);
|
||||
const recovered = json(recoveredExecution.stdout);
|
||||
@@ -308,7 +596,7 @@ const verifyDanglingSymlink = async ({ cli, environment, home }) => {
|
||||
await symlink(join(home, "missing-gemini.json"), geminiConfig);
|
||||
const danglingExecution = await runWithStatus(
|
||||
cli,
|
||||
["setup", "--yes", "--json"],
|
||||
["setup", "--yes", "--client", "gemini_cli", "--json"],
|
||||
environment,
|
||||
);
|
||||
const dangling = json(danglingExecution.stdout);
|
||||
@@ -335,7 +623,9 @@ const verifyUninstall = async ({
|
||||
codexConfig,
|
||||
cursorTarget,
|
||||
codexTarget,
|
||||
opencodeConfig,
|
||||
}) => {
|
||||
const openCodeBeforeUninstall = await readFile(opencodeConfig, "utf8");
|
||||
const uninstallExecution = await runWithStatus(
|
||||
cli,
|
||||
["uninstall", "--json"],
|
||||
@@ -344,6 +634,12 @@ const verifyUninstall = async ({
|
||||
const uninstall = json(uninstallExecution.stdout);
|
||||
const cursorAfterUninstall = json(await readFile(cursorTarget, "utf8"));
|
||||
const codexAfterUninstall = await readFile(codexTarget, "utf8");
|
||||
const openCodeErrors = [];
|
||||
const openCodeAfterUninstall = parseJsonc(
|
||||
await readFile(opencodeConfig, "utf8"),
|
||||
openCodeErrors,
|
||||
{ allowTrailingComma: true },
|
||||
);
|
||||
if (
|
||||
uninstall.status !== "complete" ||
|
||||
uninstallExecution.status !== 0 ||
|
||||
@@ -357,6 +653,18 @@ const verifyUninstall = async ({
|
||||
cursorAfterUninstall.mcpServers?.rea !== undefined ||
|
||||
!codexAfterUninstall.includes('model = "gpt-5"') ||
|
||||
codexAfterUninstall.includes("mcp_servers.rea") ||
|
||||
openCodeErrors.length !== 0 ||
|
||||
openCodeAfterUninstall?.model !== "provider/model" ||
|
||||
openCodeAfterUninstall?.mcp?.rea !== undefined ||
|
||||
openCodeAfterUninstall?.mcp?.other?.command?.[0] !== "node" ||
|
||||
!(await readFile(`${opencodeConfig}.rea.backup`, "utf8")).includes(
|
||||
"OpenCode preferences must survive setup",
|
||||
) ||
|
||||
!(await readFile(`${opencodeConfig}.rea.backup`, "utf8")).includes(
|
||||
"Keep this independently managed server",
|
||||
) ||
|
||||
(await readFile(`${opencodeConfig}.rea.backup`, "utf8")) !==
|
||||
openCodeBeforeUninstall ||
|
||||
!(await readFile(`${cursorConfig}.rea.backup`, "utf8")).includes('"rea"') ||
|
||||
!(await readFile(`${codexConfig}.rea.backup`, "utf8")).includes(
|
||||
"[mcp_servers.rea]",
|
||||
@@ -380,13 +688,9 @@ export async function verifyPackageSetup({
|
||||
codexTarget,
|
||||
cursorTarget,
|
||||
supportedSetupHost,
|
||||
hopperSetupSupported,
|
||||
root,
|
||||
}) {
|
||||
await verifyInteractiveSetup({
|
||||
command: packageRunnerCli,
|
||||
environment,
|
||||
root,
|
||||
});
|
||||
await verifyMcpAdd({ cli, environment, npxLog });
|
||||
const skillPath = join(
|
||||
home,
|
||||
@@ -397,20 +701,53 @@ export async function verifyPackageSetup({
|
||||
await mkdir(join(home, ".agents/skills/unrelated"), { recursive: true });
|
||||
await writeFile(siblingSkillPath, "unrelated skill\n");
|
||||
}
|
||||
const opencodeConfig = join(
|
||||
environment.XDG_CONFIG_HOME ?? join(home, ".config"),
|
||||
"opencode",
|
||||
"opencode.json",
|
||||
);
|
||||
if (supportedSetupHost) {
|
||||
await mkdir(join(opencodeConfig, ".."), { recursive: true });
|
||||
await writeFile(opencodeConfig, OPENCODE_ORIGINAL);
|
||||
}
|
||||
const unchangedPaths = [
|
||||
claudeConfig,
|
||||
cursorConfig,
|
||||
codexTarget,
|
||||
opencodeConfig,
|
||||
skillPath,
|
||||
];
|
||||
await verifyInteractiveSetup({
|
||||
command: packageRunnerCli,
|
||||
environment,
|
||||
root,
|
||||
unchangedPaths,
|
||||
});
|
||||
await verifyRedirectedStdoutSetup({
|
||||
command: packageRunnerCli,
|
||||
environment,
|
||||
root,
|
||||
unchangedPaths,
|
||||
});
|
||||
await verifySetupPlan({
|
||||
cli,
|
||||
environment,
|
||||
claudeConfig,
|
||||
cursorConfig,
|
||||
codexTarget,
|
||||
opencodeConfig,
|
||||
opencodeOriginal: OPENCODE_ORIGINAL,
|
||||
supportedSetupHost,
|
||||
});
|
||||
const apply = await verifySetupApply({
|
||||
cli,
|
||||
environment,
|
||||
supportedSetupHost,
|
||||
hopperSetupSupported,
|
||||
});
|
||||
if (supportedSetupHost) {
|
||||
await verifyAbsentOpenCodeSetup({ cli, environment, home });
|
||||
await verifyAbsentClaudeCodeSetup({ cli, environment, home });
|
||||
await verifyConfigReadback({
|
||||
cli,
|
||||
environment,
|
||||
@@ -421,6 +758,8 @@ export async function verifyPackageSetup({
|
||||
root,
|
||||
skillPath,
|
||||
siblingSkillPath,
|
||||
opencodeConfig,
|
||||
opencodeOriginal: OPENCODE_ORIGINAL,
|
||||
});
|
||||
await verifySetupFailureRecovery({
|
||||
cli,
|
||||
@@ -437,6 +776,7 @@ export async function verifyPackageSetup({
|
||||
codexConfig,
|
||||
cursorTarget,
|
||||
codexTarget,
|
||||
opencodeConfig,
|
||||
});
|
||||
} else if (
|
||||
apply.first.status !== "needs_human" ||
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { createServer } from "node:http";
|
||||
import { readFile, writeFile, mkdir } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
import { exec, json } from "./lib/verify-package-core.mjs";
|
||||
|
||||
/** Exercise the packaged updater with real npm and a local release registry fixture. */
|
||||
export async function verifyPackageUpdate({
|
||||
prefix,
|
||||
packageRoot,
|
||||
tarball,
|
||||
workspace,
|
||||
environment,
|
||||
}) {
|
||||
const metadataPath = join(packageRoot, "package.json");
|
||||
const metadata = json(await readFile(metadataPath, "utf8"));
|
||||
const archive = await readFile(tarball);
|
||||
const entry = join(packageRoot, "scripts", "rea.mjs");
|
||||
const home = join(workspace, "update-home");
|
||||
const codexPath = join(home, ".codex", "config.toml");
|
||||
const originalConfig =
|
||||
'[mcp_servers.rea]\ncommand = "npx"\nargs = ["-y", "rea-agents@0.0.0", "mcp"]\n';
|
||||
await mkdir(dirname(codexPath), { recursive: true });
|
||||
await writeFile(codexPath, originalConfig);
|
||||
const server = createServer((request, response) => {
|
||||
void serveRegistry(request, response).catch((error) => {
|
||||
response.writeHead(500);
|
||||
response.end(String(error));
|
||||
});
|
||||
});
|
||||
let registry;
|
||||
async function serveRegistry(request, response) {
|
||||
const pathname = new URL(request.url, registry).pathname;
|
||||
if (pathname === "/rea-agents") {
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
response.end(
|
||||
JSON.stringify({
|
||||
name: metadata.name,
|
||||
"dist-tags": { latest: metadata.version },
|
||||
versions: {
|
||||
[metadata.version]: {
|
||||
...metadata,
|
||||
dist: {
|
||||
tarball: `${registry}/release.tgz`,
|
||||
integrity: `sha512-${createHash("sha512").update(archive).digest("base64")}`,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
} else if (pathname === "/release.tgz") {
|
||||
response.end(archive);
|
||||
} else if (request.method === "POST") {
|
||||
response.setHeader("Content-Type", "application/json");
|
||||
response.end("{}");
|
||||
} else {
|
||||
const upstream = await fetch(`https://registry.npmjs.org${request.url}`);
|
||||
response.writeHead(upstream.status, {
|
||||
"Content-Type":
|
||||
upstream.headers.get("content-type") ?? "application/octet-stream",
|
||||
});
|
||||
response.end(Buffer.from(await upstream.arrayBuffer()));
|
||||
}
|
||||
}
|
||||
await new Promise((resolveListen, reject) => {
|
||||
server.once("error", reject);
|
||||
server.listen(0, "127.0.0.1", resolveListen);
|
||||
});
|
||||
try {
|
||||
const address = server.address();
|
||||
if (typeof address !== "object" || address === null)
|
||||
throw new Error("Registry fixture did not bind");
|
||||
registry = `http://127.0.0.1:${address.port}`;
|
||||
// Model an older installed release's identity while retaining the new updater
|
||||
// under test. The registry supplies the unmodified packed target artifact.
|
||||
const generatedPath = join(
|
||||
packageRoot,
|
||||
"dist",
|
||||
"generatedPackageMetadata.js",
|
||||
);
|
||||
const generated = await readFile(generatedPath, "utf8");
|
||||
const previousVersion = "0.0.0";
|
||||
const previousGenerated = generated.replace(
|
||||
`version: "${metadata.version}"`,
|
||||
`version: "${previousVersion}"`,
|
||||
);
|
||||
if (previousGenerated === generated)
|
||||
throw new Error("Could not create previous-release identity fixture");
|
||||
await writeFile(generatedPath, previousGenerated);
|
||||
await writeFile(
|
||||
metadataPath,
|
||||
JSON.stringify({ ...metadata, version: previousVersion }),
|
||||
);
|
||||
const runtimeEnvironment = {
|
||||
...environment,
|
||||
HOME: home,
|
||||
USERPROFILE: home,
|
||||
APPDATA: join(home, "AppData", "Roaming"),
|
||||
CLAUDE_CONFIG_DIR: home,
|
||||
CODEX_HOME: join(home, ".codex"),
|
||||
COPILOT_HOME: join(home, ".copilot"),
|
||||
XDG_CONFIG_HOME: join(home, ".config"),
|
||||
OPENCODE_CONFIG: join(home, ".config", "opencode", "opencode.json"),
|
||||
npm_config_prefix: prefix,
|
||||
npm_config_registry: registry,
|
||||
};
|
||||
const previous = (
|
||||
await exec(process.execPath, [entry, "--version"], {
|
||||
env: runtimeEnvironment,
|
||||
})
|
||||
).stdout.trim();
|
||||
if (previous !== previousVersion)
|
||||
throw new Error(`Previous-release fixture reported ${previous}`);
|
||||
const harness = join(workspace, "verify-update.mjs");
|
||||
await writeFile(
|
||||
harness,
|
||||
`
|
||||
import { runUpdate } from ${JSON.stringify(pathToFileURL(join(packageRoot, "dist/application/Update.js")).href)};
|
||||
import { systemUpdateHost } from ${JSON.stringify(pathToFileURL(join(packageRoot, "dist/application/UpdateRuntime.js")).href)};
|
||||
const host = systemUpdateHost(${JSON.stringify(packageRoot)}, ${JSON.stringify(home)});
|
||||
const result = await runUpdate(${JSON.stringify(previousVersion)}, host, "structured");
|
||||
process.stdout.write(JSON.stringify(result));
|
||||
if (result.status === "failed") process.exitCode = 1;
|
||||
`,
|
||||
);
|
||||
const result = json(
|
||||
(
|
||||
await exec(process.execPath, [harness], {
|
||||
env: runtimeEnvironment,
|
||||
maxBuffer: 16 * 1024 * 1024,
|
||||
})
|
||||
).stdout,
|
||||
);
|
||||
if (
|
||||
result.status !== "updated" ||
|
||||
result.installedVersion !== metadata.version ||
|
||||
result.command.at(-1) !== `${metadata.name}@${metadata.version}` ||
|
||||
result.maintenance.status !== "planned" ||
|
||||
result.maintenance.scope.clients.join(",") !== "codex" ||
|
||||
result.maintenance.scope.skill !== false
|
||||
)
|
||||
throw new Error(
|
||||
`Packaged updater failed its exact-release contract: ${JSON.stringify(result)}`,
|
||||
);
|
||||
if ((await readFile(codexPath, "utf8")) !== originalConfig)
|
||||
throw new Error(
|
||||
"Update applied integration maintenance without approval",
|
||||
);
|
||||
const current = (
|
||||
await exec(process.execPath, [entry, "--version"], {
|
||||
env: runtimeEnvironment,
|
||||
})
|
||||
).stdout.trim();
|
||||
if (current !== metadata.version)
|
||||
throw new Error(`Updated executable reported ${current}`);
|
||||
const help = (
|
||||
await exec(process.execPath, [entry, "--help"], {
|
||||
env: runtimeEnvironment,
|
||||
})
|
||||
).stdout;
|
||||
if (!/^\s{2}update\s/mu.test(help) || /^\s{2}upgrade\s/mu.test(help))
|
||||
throw new Error(
|
||||
"Updated CLI did not expose update as its sole maintenance command",
|
||||
);
|
||||
return {
|
||||
installed_version: result.installedVersion,
|
||||
exact_release: true,
|
||||
maintenance_read_only: true,
|
||||
};
|
||||
} finally {
|
||||
server.closeAllConnections();
|
||||
await new Promise((resolveClose, reject) =>
|
||||
server.close((error) =>
|
||||
error === undefined ? resolveClose() : reject(error),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import { verifyPackageDiscovery } from "./verify-package-discovery.mjs";
|
||||
import { verifyPackageEnvironment } from "./verify-package-environment.mjs";
|
||||
import { verifyPackageEvidence } from "./verify-package-evidence.mjs";
|
||||
import { verifyPackageInstall } from "./verify-package-install.mjs";
|
||||
import { verifyPackageUpdate } from "./verify-package-update.mjs";
|
||||
import { verifyPackageMcp } from "./verify-package-mcp.mjs";
|
||||
import { verifyPackagePack } from "./verify-package-pack.mjs";
|
||||
import { verifyPackagePlatform } from "./verify-package-platform.mjs";
|
||||
@@ -32,6 +33,7 @@ const referenceRoot = join(workspace, "reference-source");
|
||||
let tarball;
|
||||
let mcpStartup;
|
||||
let mcpModuleLoading;
|
||||
let update;
|
||||
|
||||
try {
|
||||
({ tarball } = await verifyPackagePack({ root, workspace }));
|
||||
@@ -48,6 +50,18 @@ try {
|
||||
workspace,
|
||||
environment: environmentData.environment,
|
||||
});
|
||||
update = await verifyPackageUpdate({
|
||||
prefix: environmentData.prefix,
|
||||
packageRoot: join(
|
||||
environmentData.prefix,
|
||||
"lib",
|
||||
"node_modules",
|
||||
PRODUCT_IDENTITY.packageName,
|
||||
),
|
||||
tarball: join(root, tarball),
|
||||
workspace,
|
||||
environment: environmentData.environment,
|
||||
});
|
||||
mcpStartup = await measureMcpStartup({
|
||||
command: cli,
|
||||
args: ["mcp"],
|
||||
@@ -65,10 +79,11 @@ try {
|
||||
policy: MCP_STARTUP_POLICY,
|
||||
packageName: PRODUCT_IDENTITY.packageName,
|
||||
});
|
||||
const { supportedSetupHost } = await verifyPackageDiscovery({
|
||||
cli,
|
||||
environment: environmentData.environment,
|
||||
});
|
||||
const { supportedSetupHost, hopperSetupSupported } =
|
||||
await verifyPackageDiscovery({
|
||||
cli,
|
||||
environment: environmentData.environment,
|
||||
});
|
||||
await verifyPackageArtifactAndElectron({
|
||||
cli,
|
||||
workspace,
|
||||
@@ -109,6 +124,7 @@ try {
|
||||
codexTarget: environmentData.codexTarget,
|
||||
cursorTarget: environmentData.cursorTarget,
|
||||
supportedSetupHost,
|
||||
hopperSetupSupported,
|
||||
root,
|
||||
});
|
||||
await verifyPackageMcp({
|
||||
@@ -117,7 +133,7 @@ try {
|
||||
evidenceRoot,
|
||||
});
|
||||
process.stdout.write(
|
||||
`${JSON.stringify({ verifier_run: await completeVerifierRun(verifierRun), cli: true, analysisCli: true, artifactCli: true, managedCli: true, managedReconstructionCli: true, managedNativeVerificationCli: true, managedApplicationGraphCli: true, evidenceCli: true, incurMcpCommand: PRODUCT_IDENTITY.mcpCommand, lifecycleScriptsRequired: false, doctor: "platform-appropriate", setup: supportedSetupHost ? "planned-then-idempotent" : "unsupported-host-rejected", setupPlanReadOnly: supportedSetupHost, existingHopperPreserved: supportedSetupHost, clients: supportedSetupHost ? 3 : 0, backupReadback: supportedSetupHost, failureRecovery: supportedSetupHost, configSymlinkLifecycle: supportedSetupHost, skill: supportedSetupHost, skillReferences: supportedSetupHost, mcpTools: TOOL_CONTRACTS.length, mcpPrompts: prompts.names.length, promptCompletion: true, promptCompletionLifecycle: true, evidenceMcp: true, targetFree: true, targetLifecycle: true, boundedRegexBridge: true, mcpStartup, mcpModuleLoading })}\n`,
|
||||
`${JSON.stringify({ verifier_run: await completeVerifierRun(verifierRun), cli: true, analysisCli: true, artifactCli: true, managedCli: true, managedReconstructionCli: true, managedNativeVerificationCli: true, managedApplicationGraphCli: true, evidenceCli: true, incurMcpCommand: PRODUCT_IDENTITY.mcpCommand, lifecycleScriptsRequired: false, doctor: "platform-appropriate", setup: supportedSetupHost ? "planned-then-idempotent" : "unsupported-host-rejected", setupPlanReadOnly: supportedSetupHost, existingHopperPreserved: supportedSetupHost, clients: supportedSetupHost ? 4 : 0, backupReadback: supportedSetupHost, failureRecovery: supportedSetupHost, configSymlinkLifecycle: supportedSetupHost, skill: supportedSetupHost, skillReferences: supportedSetupHost, mcpTools: TOOL_CONTRACTS.length, mcpPrompts: prompts.names.length, promptCompletion: true, promptCompletionLifecycle: true, evidenceMcp: true, targetFree: true, targetLifecycle: true, boundedRegexBridge: true, update, mcpStartup, mcpModuleLoading })}\n`,
|
||||
);
|
||||
} finally {
|
||||
if (tarball) await rm(join(root, tarball), { force: true });
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
||||
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { delimiter, join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { pathToFileURL } from "node:url";
|
||||
|
||||
import { lt, rcompare } from "semver";
|
||||
|
||||
@@ -44,7 +45,7 @@ transport.stderr?.on("data", (chunk) => {
|
||||
});
|
||||
|
||||
let publishedToolCount = 0;
|
||||
let upgrade;
|
||||
let update;
|
||||
|
||||
try {
|
||||
await client.connect(transport);
|
||||
@@ -71,7 +72,7 @@ try {
|
||||
});
|
||||
if (status.isError === true)
|
||||
throw new Error("Published target-free MCP session check failed");
|
||||
upgrade = await verifyPublishedUpgrade({ version, canaryRoot });
|
||||
update = await verifyPublishedUpdate({ version, canaryRoot });
|
||||
} catch (cause) {
|
||||
throw new Error(`Published package verification failed: ${stderr}`, {
|
||||
cause,
|
||||
@@ -86,17 +87,17 @@ try {
|
||||
}
|
||||
|
||||
process.stdout.write(
|
||||
`${JSON.stringify({ verifier_run: await completeVerifierRun(verifierRun), package: "rea-agents", version, mcpTools: publishedToolCount, canonicalMcpTools: CATALOG_IDENTITY.counts.mcp_tools, upgrade })}\n`,
|
||||
`${JSON.stringify({ verifier_run: await completeVerifierRun(verifierRun), package: "rea-agents", version, mcpTools: publishedToolCount, canonicalMcpTools: CATALOG_IDENTITY.counts.mcp_tools, update })}\n`,
|
||||
);
|
||||
|
||||
async function verifyPublishedUpgrade({ version: targetVersion, canaryRoot }) {
|
||||
async function verifyPublishedUpdate({ version: targetVersion, canaryRoot }) {
|
||||
const previousVersion = await findPreviousPublishedVersion(targetVersion);
|
||||
const prefix = join(canaryRoot, "upgrade-prefix");
|
||||
const home = join(canaryRoot, "upgrade-home");
|
||||
const prefix = join(canaryRoot, "update-prefix");
|
||||
const home = join(canaryRoot, "update-home");
|
||||
const environment = {
|
||||
...process.env,
|
||||
HOME: home,
|
||||
npm_config_cache: join(canaryRoot, "upgrade-cache"),
|
||||
npm_config_cache: join(canaryRoot, "update-cache"),
|
||||
npm_config_prefix: prefix,
|
||||
PATH: `${join(prefix, "bin")}${delimiter}${process.env.PATH ?? ""}`,
|
||||
};
|
||||
@@ -114,33 +115,63 @@ async function verifyPublishedUpgrade({ version: targetVersion, canaryRoot }) {
|
||||
{ cwd: canaryRoot, env: environment, maxBuffer: 16 * 1024 * 1024 },
|
||||
);
|
||||
|
||||
const { stdout } = await execFileAsync(
|
||||
"npx",
|
||||
["rea-agents", "upgrade", "--json"],
|
||||
{ cwd: canaryRoot, env: environment, maxBuffer: 16 * 1024 * 1024 },
|
||||
);
|
||||
const result = JSON.parse(stdout);
|
||||
if (
|
||||
result.status !== "upgraded" ||
|
||||
result.previousVersion !== previousVersion ||
|
||||
result.latestVersion !== targetVersion
|
||||
)
|
||||
throw new Error(
|
||||
`npx rea-agents upgrade did not upgrade ${previousVersion} to ${targetVersion}: ${stdout}`,
|
||||
);
|
||||
|
||||
const npmRoot = (
|
||||
await execFileAsync("npm", ["root", "--global"], {
|
||||
cwd: canaryRoot,
|
||||
env: environment,
|
||||
})
|
||||
).stdout.trim();
|
||||
// Older releases may predate the update command. Exercise the new published
|
||||
// updater's production workflow against that real previous installation.
|
||||
const updaterPrefix = join(canaryRoot, "updater");
|
||||
await execFileAsync(
|
||||
"npm",
|
||||
[
|
||||
"install",
|
||||
"--ignore-scripts",
|
||||
"--no-save",
|
||||
"--no-package-lock",
|
||||
"--prefix",
|
||||
updaterPrefix,
|
||||
`rea-agents@${targetVersion}`,
|
||||
],
|
||||
{ cwd: canaryRoot, env: environment, maxBuffer: 16 * 1024 * 1024 },
|
||||
);
|
||||
const updaterRoot = join(updaterPrefix, "node_modules", "rea-agents");
|
||||
const harness = join(canaryRoot, "update.mjs");
|
||||
await writeFile(
|
||||
harness,
|
||||
`
|
||||
import { runUpdate } from ${JSON.stringify(pathToFileURL(join(updaterRoot, "dist/application/Update.js")).href)};
|
||||
import { systemUpdateHost } from ${JSON.stringify(pathToFileURL(join(updaterRoot, "dist/application/UpdateRuntime.js")).href)};
|
||||
const result = await runUpdate(${JSON.stringify(previousVersion)}, systemUpdateHost(${JSON.stringify(join(npmRoot, "rea-agents"))}, ${JSON.stringify(home)}), "structured");
|
||||
process.stdout.write(JSON.stringify(result));
|
||||
if (result.status === "failed") process.exitCode = 1;
|
||||
`,
|
||||
);
|
||||
const { stdout } = await execFileAsync(process.execPath, [harness], {
|
||||
cwd: canaryRoot,
|
||||
env: environment,
|
||||
maxBuffer: 16 * 1024 * 1024,
|
||||
});
|
||||
const result = JSON.parse(stdout);
|
||||
if (
|
||||
result.status !== "updated" ||
|
||||
result.previousVersion !== previousVersion ||
|
||||
result.latestVersion !== targetVersion ||
|
||||
result.installedVersion !== targetVersion ||
|
||||
result.command.at(-1) !== `rea-agents@${targetVersion}`
|
||||
)
|
||||
throw new Error(
|
||||
`Published REA updater did not update ${previousVersion} to ${targetVersion}: ${stdout}`,
|
||||
);
|
||||
|
||||
const installed = JSON.parse(
|
||||
await readFile(join(npmRoot, "rea-agents", "package.json"), "utf8"),
|
||||
);
|
||||
if (installed.version !== targetVersion)
|
||||
throw new Error(
|
||||
`npx rea-agents upgrade installed ${installed.version}, expected ${targetVersion}`,
|
||||
`REA update installed ${installed.version}, expected ${targetVersion}`,
|
||||
);
|
||||
|
||||
const help = (
|
||||
@@ -149,8 +180,10 @@ async function verifyPublishedUpgrade({ version: targetVersion, canaryRoot }) {
|
||||
env: environment,
|
||||
})
|
||||
).stdout;
|
||||
if (!help.includes("setup"))
|
||||
throw new Error("the upgraded rea-agents executable did not start");
|
||||
if (!/^\s{2}update\s/mu.test(help) || /^\s{2}upgrade\s/mu.test(help))
|
||||
throw new Error(
|
||||
"the updated executable did not expose only the update command",
|
||||
);
|
||||
|
||||
return {
|
||||
status: result.status,
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { execFile } from "node:child_process";
|
||||
import { access, mkdtemp, rm } from "node:fs/promises";
|
||||
import {
|
||||
access,
|
||||
mkdir,
|
||||
mkdtemp,
|
||||
readFile,
|
||||
rm,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { parse as parseJsonc } from "jsonc-parser";
|
||||
import { supportedClients } from "../dist/application/SupportedClients.js";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
|
||||
import { verifyCompleteToolCatalog } from "./lib/verify-package-core.mjs";
|
||||
import { verifyPackageUpdate } from "./verify-package-update.mjs";
|
||||
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
|
||||
|
||||
const exec = promisify(execFile);
|
||||
@@ -89,6 +99,117 @@ try {
|
||||
await client.close();
|
||||
}
|
||||
|
||||
const home = join(workspace, "home");
|
||||
const setupEnvironment = {
|
||||
...environment,
|
||||
HOME: home,
|
||||
USERPROFILE: home,
|
||||
APPDATA: join(home, "AppData", "Roaming"),
|
||||
XDG_CONFIG_HOME: join(home, ".config"),
|
||||
OPENCODE_CONFIG: join(home, ".config", "opencode", "opencode.jsonc"),
|
||||
COPILOT_HOME: join(home, ".copilot"),
|
||||
};
|
||||
await mkdir(join(home, ".config", "opencode"), { recursive: true });
|
||||
await writeFile(
|
||||
setupEnvironment.OPENCODE_CONFIG,
|
||||
'{\n // preserve user settings\n "theme": "dark",\n}\n',
|
||||
);
|
||||
const setupArgs = [
|
||||
"setup",
|
||||
"--yes",
|
||||
"--client",
|
||||
"opencode",
|
||||
"--client",
|
||||
"vscode",
|
||||
"--client",
|
||||
"copilot_cli",
|
||||
"--skill=false",
|
||||
"--json",
|
||||
];
|
||||
const setup = JSON.parse(
|
||||
(
|
||||
await exec(process.execPath, [entry, ...setupArgs], {
|
||||
env: setupEnvironment,
|
||||
windowsHide: true,
|
||||
})
|
||||
).stdout,
|
||||
);
|
||||
if (setup.status !== "ready" || setup.appliedActions.length !== 3)
|
||||
throw new Error(
|
||||
`Packaged agent-only setup failed: ${JSON.stringify(setup)}`,
|
||||
);
|
||||
const expectedCommand =
|
||||
process.platform === "win32"
|
||||
? [process.execPath, entry, "mcp"]
|
||||
: [entry, "mcp"];
|
||||
const clients = supportedClients(home, process.platform, setupEnvironment);
|
||||
for (const id of ["opencode", "vscode", "copilot_cli"]) {
|
||||
const clientLocation = clients.find(({ name }) => name === id);
|
||||
if (clientLocation === undefined)
|
||||
throw new Error(`Missing packaged client ${id}`);
|
||||
const text = await readFile(clientLocation.configPath, "utf8");
|
||||
const config = parseJsonc(text);
|
||||
const registration =
|
||||
id === "opencode"
|
||||
? config.mcp?.rea
|
||||
: id === "vscode"
|
||||
? config.servers?.rea
|
||||
: config.mcpServers?.rea;
|
||||
const actualCommand =
|
||||
id === "opencode"
|
||||
? registration?.command
|
||||
: [registration?.command, ...(registration?.args ?? [])];
|
||||
if (JSON.stringify(actualCommand) !== JSON.stringify(expectedCommand))
|
||||
throw new Error(
|
||||
`Packaged ${id} has an unusable launcher: ${JSON.stringify(actualCommand)}`,
|
||||
);
|
||||
if (id === "opencode" && !text.includes("// preserve user settings"))
|
||||
throw new Error("Packaged setup discarded OpenCode JSONC comments");
|
||||
}
|
||||
const repeated = JSON.parse(
|
||||
(
|
||||
await exec(process.execPath, [entry, ...setupArgs], {
|
||||
env: setupEnvironment,
|
||||
windowsHide: true,
|
||||
})
|
||||
).stdout,
|
||||
);
|
||||
if (
|
||||
repeated.status !== "ready" ||
|
||||
repeated.plannedActions.length !== 0 ||
|
||||
repeated.appliedActions.length !== 0
|
||||
)
|
||||
throw new Error("Packaged agent setup is not idempotent");
|
||||
const uninstalled = JSON.parse(
|
||||
(
|
||||
await exec(process.execPath, [entry, "uninstall", "--json"], {
|
||||
env: setupEnvironment,
|
||||
windowsHide: true,
|
||||
})
|
||||
).stdout,
|
||||
);
|
||||
for (const id of ["opencode", "vscode", "copilot_cli"])
|
||||
if (
|
||||
uninstalled.items?.find(({ name }) => name === id)?.status !== "removed"
|
||||
)
|
||||
throw new Error(`Packaged uninstall did not remove ${id}`);
|
||||
|
||||
if (process.platform !== "win32")
|
||||
await npm(
|
||||
["install", "--global", "--ignore-scripts", "--prefix", prefix, tarball],
|
||||
workspace,
|
||||
);
|
||||
const update = await verifyPackageUpdate({
|
||||
prefix,
|
||||
packageRoot:
|
||||
process.platform === "win32"
|
||||
? join(prefix, "node_modules", "rea-agents")
|
||||
: join(prefix, "lib", "node_modules", "rea-agents"),
|
||||
tarball,
|
||||
workspace,
|
||||
environment,
|
||||
});
|
||||
|
||||
process.stdout.write(
|
||||
`${JSON.stringify({
|
||||
verifier_run: await completeVerifierRun(verifierRun),
|
||||
@@ -97,6 +218,10 @@ try {
|
||||
package: packageResult.filename,
|
||||
tools: toolCount,
|
||||
ghidra_bridge: "present",
|
||||
agent_setup: ["opencode", "vscode", "copilot_cli"],
|
||||
setup_idempotent: true,
|
||||
uninstall: true,
|
||||
update,
|
||||
})}\n`,
|
||||
);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user