import { dirname, join } from "path";
import { existsSync, readFileSync } from "fs";
import { fileURLToPath } from "url";
//#region src/cli/templates.ts
/**
* Workspace template files for onboarding.
* Templates are stored in docs/reference/templates/ and loaded at runtime.
*/
const __dirname = dirname(fileURLToPath(import.meta.url));
/** All template file names (for loading / caching). */
const TEMPLATE_FILES = [
	"SOUL.md",
	"IDENTITY.md",
	"USER.md",
	"TOOLS.md",
	"AGENTS.md",
	"HEARTBEAT.md",
	"MEMORY.md",
	"BOOTSTRAP.md"
];
/**
* Profile Markdown templates (system-prompt stack, excluding BOOTSTRAP.md).
* Seeded by seedAgentProfileMarkdownFiles / seedMainAgentProfileMarkdown.
*/
const PROFILE_MARKDOWN_TEMPLATE_FILES = [
	"SOUL.md",
	"IDENTITY.md",
	"USER.md",
	"TOOLS.md",
	"AGENTS.md",
	"HEARTBEAT.md",
	"MEMORY.md"
];
/**
* Onboarding guide template (seeded into the Markdown workspace root as `BOOTSTRAP.md`).
*/
const WORKSPACE_TEMPLATE_FILES = ["BOOTSTRAP.md"];
/** Template content cache */
const templateCache = /* @__PURE__ */ new Map();
/**
* Get the path to template files.
* Uses environment or looks in project root.
*/
function getTemplatePath() {
	const envPath = process.env.XOPC_TEMPLATE_PATH;
	if (envPath && existsSync(envPath)) return envPath;
	const defaultPath = join(join(__dirname, "../../.."), "docs/reference/templates");
	if (existsSync(defaultPath)) return defaultPath;
	return defaultPath;
}
/**
* Load a template file. Caches results for repeated access.
*/
function loadTemplate(name) {
	if (templateCache.has(name)) return templateCache.get(name);
	const templatePath = join(getTemplatePath(), name);
	try {
		if (existsSync(templatePath)) {
			const content = readFileSync(templatePath, "utf-8");
			templateCache.set(name, content);
			return content;
		}
	} catch {}
	console.warn(`Warning: Template ${name} not found, using fallback`);
	return getFallbackTemplate(name);
}
/**
* Load all templates as a record.
*/
function loadAllTemplates() {
	const result = {};
	for (const name of TEMPLATE_FILES) result[name] = loadTemplate(name);
	return result;
}
/**
* Clear the template cache (useful for testing).
*/
function clearTemplateCache() {
	templateCache.clear();
}
/** Minimal fallback templates in case files are missing */
function getFallbackTemplate(name) {
	return {
		"BOOTSTRAP.md": `# BOOTSTRAP.md - Hello, World

_You just woke up. Time to figure out who you are._

Start with something like:

> "Hey. I just came online. Who am I? Who are you?"

Then figure out together your name, nature, vibe, and emoji.

Delete this file when done.
`,
		"AGENTS.md": `# AGENTS.md - Your Workspace

This folder is home. Treat it that way.

## Session Startup

Use runtime-provided startup context first. Bootstrap files (SOUL, USER, MEMORY, etc.) are injected by xopc on /new and /reset.

Do not manually reread startup files unless the user asks or the provided context is incomplete.

## Red Lines

- Don't exfiltrate private data
- Don't run destructive commands without asking
- When in doubt, ask

## Memory

- **Daily notes:** \`memory/YYYY-MM-DD.md\`
- **Long-term:** profile \`MEMORY.md\`

Write what matters. Text > Brain.
`,
		"SOUL.md": `# SOUL.md - Who You Are

_You're not a chatbot. You're becoming someone._

## Core Truths

- Be genuinely helpful, not performatively helpful
- Have opinions
- Be resourceful before asking
- Earn trust through competence
- Remember you're a guest

## Boundaries

- Private things stay private
- When in doubt, ask before acting externally
- Never send half-baked replies

This file is yours to evolve.
`,
		"IDENTITY.md": `# IDENTITY.md - Who Am I?

_Fill this in during your first conversation._

- **Name:**
- **Creature:**
- **Vibe:**
- **Emoji:**
`,
		"USER.md": `# USER.md - About Your Human

_Learn about the person you're helping._

- **Name:**
- **What to call them:**
- **Timezone:**
- **Notes:**
`,
		"TOOLS.md": `# TOOLS.md - Local Notes

Environment-specific notes:

- SSH hosts
- API endpoints
- Device nicknames
`,
		"HEARTBEAT.md": `# HEARTBEAT.md - Periodic Checks

Edit this file to define what you check during heartbeat polls.

## Example Checklist

- [ ] Check email for urgent messages
- [ ] Check calendar for upcoming events

**Remember:** If nothing needs attention, reply \`HEARTBEAT_OK\`.
`,
		"MEMORY.md": `# MEMORY.md - Long-Term Memory

_Your curated memories._

## People

## Projects

## Preferences

## Learned Lessons

**Only load in main sessions.**
`
	}[name] || `# ${name}\n\n(Template content missing)\n`;
}
//#endregion
export { PROFILE_MARKDOWN_TEMPLATE_FILES, TEMPLATE_FILES, WORKSPACE_TEMPLATE_FILES, clearTemplateCache, getFallbackTemplate, loadAllTemplates, loadTemplate };

//# sourceMappingURL=templates.js.map