fix(web): remove payload REST API route + cli backup guards
Some checks failed
CI / Lint (push) Has been cancelled
CI / Typecheck (push) Has been cancelled
CI / Broker tests (Postgres) (push) Has been cancelled
CI / Docker build (linux/amd64) (push) Has been cancelled

Remove Payload's /api/[...slug] route that conflicts with existing
/api/[...route]. Blog/changelog pages use Payload's local API.

Includes cli install.ts backup + assertNoMcpLoss guards (from
worktree agent).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alejandro Gutiérrez
2026-04-06 01:11:09 +01:00
parent 57a6af5013
commit 8bd8d1ff76
2 changed files with 38 additions and 11 deletions

View File

@@ -19,6 +19,7 @@
import {
chmodSync,
copyFileSync,
existsSync,
mkdirSync,
readFileSync,
@@ -65,7 +66,44 @@ function readClaudeConfig(): Record<string, unknown> {
}
}
/**
* Create a timestamped backup of ~/.claude.json before any write.
* Keeps the last 3 backups to avoid clutter.
*/
function backupClaudeConfig(): void {
if (!existsSync(CLAUDE_CONFIG)) return;
const backupDir = join(dirname(CLAUDE_CONFIG), ".claude", "backups");
mkdirSync(backupDir, { recursive: true });
const ts = Date.now();
const dest = join(backupDir, `.claude.json.pre-claudemesh.${ts}`);
copyFileSync(CLAUDE_CONFIG, dest);
}
/**
* Sanity-check: abort if we're about to lose MCP servers that existed
* on disk but are missing from the object we're about to write.
*/
function assertNoMcpLoss(next: Record<string, unknown>): void {
if (!existsSync(CLAUDE_CONFIG)) return;
const prev = readClaudeConfig();
const prevServers = Object.keys(
(prev.mcpServers as Record<string, unknown>) ?? {},
);
const nextServers = Object.keys(
(next.mcpServers as Record<string, unknown>) ?? {},
);
const lost = prevServers.filter((k) => !nextServers.includes(k));
if (lost.length > 0) {
throw new Error(
`Aborting write: would lose ${lost.length} existing MCP server(s): ${lost.join(", ")}. ` +
`This is a bug — please report it. A backup was saved in ~/.claude/backups/`,
);
}
}
function writeClaudeConfig(obj: Record<string, unknown>): void {
backupClaudeConfig();
assertNoMcpLoss(obj);
mkdirSync(dirname(CLAUDE_CONFIG), { recursive: true });
writeFileSync(
CLAUDE_CONFIG,