import { join } from "path";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
//#region src/cli/utils/workspace.ts
/**
* Workspace utilities - shared between setup and onboard commands
*/
/**
* Check if workspace directory exists (markdown root + memory/ are created by setupWorkspace).
*/
function isWorkspaceSetup(workspacePath) {
	return existsSync(workspacePath);
}
/**
* Check if config file exists
*/
function isConfigSetup(configPath) {
	return existsSync(configPath);
}
/**
* Get current workspace status
*/
function getWorkspaceStatus(configPath, workspacePath) {
	return {
		configExists: isConfigSetup(configPath),
		workspaceExists: existsSync(workspacePath),
		workspaceSetup: isWorkspaceSetup(workspacePath),
		configPath,
		workspacePath
	};
}
/**
* Create markdown workspace root and memory/ only.
* Persona Markdown is seeded into `agents/<id>/profile/` via seedMainAgentProfileMarkdown.
*/
function setupWorkspace(workspacePath) {
	if (!existsSync(workspacePath)) {
		mkdirSync(workspacePath, { recursive: true });
		console.log("✅ Created workspace:", workspacePath);
	} else console.log("ℹ️  Workspace already exists:", workspacePath);
	const memoryDir = join(workspacePath, "memory");
	if (!existsSync(memoryDir)) {
		mkdirSync(memoryDir, { recursive: true });
		console.log("✅ Created memory/ directory");
	}
}
/**
* Create empty config file
*/
function setupConfig(configPath) {
	const configDir = join(configPath, "..");
	if (!existsSync(configDir)) mkdirSync(configDir, { recursive: true });
	if (!existsSync(configPath)) {
		writeFileSync(configPath, "{}\n", "utf-8");
		console.log("✅ Created config:", configPath);
	} else console.log("ℹ️  Config already exists:", configPath);
}
/**
* Load raw config without schema parsing
*/
function loadRawConfig(configPath) {
	if (!existsSync(configPath)) return null;
	try {
		const content = readFileSync(configPath, "utf-8");
		return JSON.parse(content);
	} catch {
		return null;
	}
}
//#endregion
export { getWorkspaceStatus, isConfigSetup, isWorkspaceSetup, loadRawConfig, setupConfig, setupWorkspace };

//# sourceMappingURL=workspace.js.map