import { WORKSPACE_FILES, init_paths } from "../../config/paths.js";
import { DEFAULT_AGENTS_FILENAME, DEFAULT_HEARTBEAT_FILENAME, DEFAULT_IDENTITY_FILENAME, DEFAULT_MEMORY_FILENAME, DEFAULT_SOUL_FILENAME, DEFAULT_TOOLS_FILENAME, DEFAULT_USER_FILENAME, stripFrontMatter } from "../context/workspace.js";
import { existsSync, readFileSync } from "node:fs";
import { join, resolve } from "node:path";
//#region src/agent/bootstrap/load-bootstrap-files.ts
init_paths();
const BOOTSTRAP_LOAD_ORDER = [
	DEFAULT_AGENTS_FILENAME,
	DEFAULT_SOUL_FILENAME,
	DEFAULT_TOOLS_FILENAME,
	DEFAULT_IDENTITY_FILENAME,
	DEFAULT_USER_FILENAME,
	DEFAULT_HEARTBEAT_FILENAME,
	WORKSPACE_FILES.BOOTSTRAP,
	DEFAULT_MEMORY_FILENAME
];
function readProfileFile(filePath) {
	if (!existsSync(filePath)) return null;
	try {
		return stripFrontMatter(readFileSync(filePath, "utf-8"));
	} catch {
		return null;
	}
}
function isProfileBootstrapPending(profileDir) {
	return existsSync(join(profileDir, WORKSPACE_FILES.BOOTSTRAP));
}
/**
* Load bootstrap profile Markdown from `agents/<id>/profile/`.
* MEMORY.md and BOOTSTRAP.md are omitted when absent; other slots emit missing markers.
*/
function loadProfileBootstrapFiles(profileDir) {
	const resolvedDir = resolve(profileDir);
	const result = [];
	for (const name of BOOTSTRAP_LOAD_ORDER) {
		const filePath = join(resolvedDir, name);
		if (name === "MEMORY.md" || name === WORKSPACE_FILES.BOOTSTRAP) {
			const content = readProfileFile(filePath);
			if (content === null) continue;
			result.push({
				name,
				path: filePath,
				content,
				missing: false
			});
			continue;
		}
		const content = readProfileFile(filePath);
		if (content !== null) result.push({
			name,
			path: filePath,
			content,
			missing: false
		});
		else result.push({
			name,
			path: filePath,
			missing: true
		});
	}
	return result;
}
//#endregion
export { isProfileBootstrapPending, loadProfileBootstrapFiles };

//# sourceMappingURL=load-bootstrap-files.js.map