import { init_agent_scope, resolveAgentProfileDir, resolveAgentWorkspaceDir, resolveDefaultAgentId } from "../../../../agent/agent-scope.js";
import { WORKSPACE_FILES, init_paths } from "../../../../config/paths.js";
import { init_loader, loadConfig } from "../../../../config/loader.js";
import { existsSync } from "node:fs";
import { join } from "node:path";
//#region src/cli/commands/doctor/checks/workspace-status.ts
init_agent_scope();
init_loader();
init_paths();
async function checkWorkspaceStatus(ctx) {
	if (!existsSync(ctx.configPath)) return {
		id: "workspace-status",
		label: "Workspace",
		status: "skip",
		message: "No config file; skipped.",
		hints: []
	};
	let config;
	try {
		config = loadConfig(ctx.configPath);
	} catch {
		return {
			id: "workspace-status",
			label: "Workspace",
			status: "skip",
			message: "Config could not be loaded; skipped.",
			hints: []
		};
	}
	const agentId = resolveDefaultAgentId(config);
	const root = resolveAgentWorkspaceDir(config, agentId);
	const profileRoot = resolveAgentProfileDir(config, agentId);
	const hints = [];
	const hasProfileFile = (name) => existsSync(join(profileRoot, name));
	if (!existsSync(root)) return {
		id: "workspace-status",
		label: "Workspace",
		status: "warn",
		message: "Agent workspace directory is missing.",
		hints: [root, "Run: xopc init or xopc onboard"]
	};
	if (!existsSync(profileRoot)) return {
		id: "workspace-status",
		label: "Workspace",
		status: "warn",
		message: "Agent profile directory is missing.",
		hints: [profileRoot, "Run: xopc init or xopc onboard"]
	};
	const missing = [];
	if (!hasProfileFile(WORKSPACE_FILES.SOUL)) missing.push(WORKSPACE_FILES.SOUL);
	if (!hasProfileFile(WORKSPACE_FILES.IDENTITY)) missing.push(WORKSPACE_FILES.IDENTITY);
	if (missing.length > 0) return {
		id: "workspace-status",
		label: "Workspace",
		status: "warn",
		message: `Essential profile files missing: ${missing.join(", ")}.`,
		hints: [
			profileRoot,
			root,
			"Run: xopc init or xopc onboard"
		]
	};
	if (!hasProfileFile(WORKSPACE_FILES.USER)) hints.push(`${WORKSPACE_FILES.USER} is optional; add a user profile for better context.`);
	if (!hasProfileFile(WORKSPACE_FILES.TOOLS)) hints.push(`${WORKSPACE_FILES.TOOLS} is optional; add tool notes if you use many tools.`);
	if (!existsSync(join(root, ".git"))) hints.push("No .git in workspace; version control is recommended for backup and history.");
	if (hints.length > 0) return {
		id: "workspace-status",
		label: "Workspace",
		status: "pass",
		message: "Markdown workspace and essential profile files are present.",
		hints
	};
	return {
		id: "workspace-status",
		label: "Workspace",
		status: "pass",
		message: "Markdown workspace and essential profile files look good.",
		hints: [profileRoot, root]
	};
}
//#endregion
export { checkWorkspaceStatus };

//# sourceMappingURL=workspace-status.js.map