import { a as recordAudit } from './audit-log-BXVi9iyE.js';
import { e as executeCliAction } from './cli-action-DQcaqcfn.js';
import 'node:fs';
import 'node:path';
import './spawn-cli-wI1lBJhm.js';
import 'node:child_process';
import '@sveltejs/kit';

//#region src/routes/api/project/doctor/+server.ts
/**
* POST /api/project/doctor
*
* Runs `cleo nexus doctor --json` for the active project context and
* optionally a specific project id (query string `?id=` or body
* `{ projectId }`). Returns the raw diagnostics envelope from the CLI.
*
* The endpoint is read-only from a data perspective (it does not
* mutate rows), but we treat it as a POST because it is a long-running
* shell-out that the operator intentionally triggers. Same-origin guard
* still applies via `hooks.server.ts`.
*
* @task T990
* @wave 1E
*/
var POST = async ({ request, locals }) => {
	let body = {};
	try {
		const raw = await request.json();
		if (raw && typeof raw === "object") body = raw;
	} catch {}
	const args = [
		"nexus",
		"doctor",
		"--json"
	];
	if (typeof body.projectId === "string" && body.projectId.trim()) args.push("--project", body.projectId.trim());
	else if (typeof body.path === "string" && body.path.trim()) args.push("--path", body.path.trim());
	recordAudit(locals.projectCtx.projectPath, {
		actor: "studio-admin",
		action: "project.doctor",
		target: body.projectId ?? body.path ?? locals.projectCtx.projectId ?? null,
		result: "initiated"
	});
	const response = await executeCliAction(args, {
		errorCode: "E_DOCTOR_FAILED",
		meta: {
			projectId: body.projectId,
			path: body.path
		}
	});
	recordAudit(locals.projectCtx.projectPath, {
		actor: "studio-admin",
		action: "project.doctor",
		target: body.projectId ?? body.path ?? locals.projectCtx.projectId ?? null,
		result: response.status === 200 ? "success" : "failure"
	});
	return response;
};

export { POST };
//# sourceMappingURL=_server.ts-Cq60m8Pw.js.map
