import { __esmMin } from "../../_virtual/_rolldown/runtime.js";
import { ENV_VARS, init_paths_state, resolveHomeDir, resolveStateDir } from "./paths-state.js";
import { init_workspace_defaults, resolveDefaultAgentWorkspaceDir } from "./workspace-defaults.js";
import { init_agent_scope, resolveAgentDir as resolveAgentDir$1, resolveAgentHomeDir as resolveAgentHomeDir$1, resolveAgentProfileDir as resolveAgentProfileDir$1, resolveAgentProfileMarkdownPath as resolveAgentProfileMarkdownPath$1, resolveAgentWorkspaceDir, resolveSessionsDir as resolveSessionsDir$1 } from "../agent/agent-scope.js";
import { init_transcript_paths, resolveSessionFilePath, resolveSessionTranscriptPathInDir } from "../session/parity/transcript-paths.js";
import { dirname, join } from "path";
import { existsSync } from "fs";
import { fileURLToPath } from "url";
//#region src/config/paths.ts
/**
* Resolve the main config file path
*/
function resolveConfigPath() {
	return process.env[ENV_VARS.CONFIG_PATH] ?? join(resolveStateDir(), FILENAMES.CONFIG);
}
/**
* Resolve the credentials directory
*/
function resolveCredentialsDir() {
	return process.env[ENV_VARS.CREDENTIALS_DIR] ?? join(resolveStateDir(), "credentials");
}
/**
* Resolve the global auth-profiles.json path
*/
function resolveAuthProfilesPath() {
	return join(resolveCredentialsDir(), FILENAMES.CREDENTIALS_PROFILES);
}
/**
* Resolve OAuth token file path for a provider
*/
function resolveOAuthPath(provider) {
	return join(resolveCredentialsDir(), "oauth", `${provider}.json`);
}
/**
* Internal agent state dir: `stateDir/agents/<id>/agent/`
* (credentials, inbox IPC, pid, agent.json — not the Markdown workspace).
*/
function resolveAgentDir(config, agentId) {
	return resolveAgentDir$1(config, agentId);
}
/**
* Per-agent home: `stateDir/agents/<id>/` (sessions + `agent/`).
*/
function resolveAgentHomeDir(config, agentId) {
	return resolveAgentHomeDir$1(config, agentId);
}
/** Agent profile Markdown root: `stateDir/agents/<id>/profile/`. */
function resolveAgentProfileDir(config, agentId) {
	return resolveAgentProfileDir$1(config, agentId);
}
/** Single file under {@link resolveAgentProfileDir} (basename only). */
function resolveAgentProfileMarkdownPath(config, agentId, filename) {
	return resolveAgentProfileMarkdownPath$1(config, agentId, filename);
}
/**
* Resolve a profile system Markdown path (SOUL.md, …) under the agent `profile/` directory.
*/
function resolveWorkspaceFile(config, filename, agentId) {
	return join(resolveAgentProfileDir$1(config, agentId), filename);
}
/**
* OpenClaw-aligned: per-agent auth-profiles.json directly under agent dir (no credentials subdirectory).
*/
function resolveAgentAuthProfilesPath(config, agentId) {
	return join(resolveAgentDir(config, agentId), FILENAMES.CREDENTIALS_PROFILES);
}
/**
* Agent session store root: `stateDir/agents/<id>/sessions/` (flat `sessions.json` + `*.jsonl`).
*/
function resolveSessionsDir(config, agentId) {
	return resolveSessionsDir$1(config, agentId);
}
/**
* Resolve the OpenClaw-aligned `sessions.json` path for an agent.
*/
function resolveSessionsMapPath(config, agentId) {
	return join(resolveSessionsDir(config, agentId), FILENAMES.SESSIONS_MAP);
}
/**
* Resolve the sessions archive directory (optional secondary storage).
*/
function resolveSessionsArchiveDir(config, agentId) {
	return join(resolveSessionsDir(config, agentId), "archive");
}
/**
* Resolve a session transcript JSONL path (OpenClaw naming: `{sessionId}.jsonl` or topic variant).
*/
function resolveSessionTranscriptPath(config, sessionId, agentId, topicId) {
	return resolveSessionTranscriptPathInDir(sessionId, resolveSessionsDir(config, agentId), topicId);
}
/**
* Resolve the inbox directory for an agent
*/
function resolveInboxDir(config, agentId) {
	return join(resolveAgentDir(config, agentId), "inbox");
}
/**
* Resolve the pending inbox directory
*/
function resolveInboxPendingDir(config, agentId) {
	return join(resolveInboxDir(config, agentId), "pending");
}
/**
* Resolve the processed inbox directory
*/
function resolveInboxProcessedDir(config, agentId) {
	return join(resolveInboxDir(config, agentId), "processed");
}
/**
* Resolve a specific inbox message path
*/
function resolveInboxMessagePath(config, messageId, pending, agentId) {
	return join(pending ? resolveInboxPendingDir(config, agentId) : resolveInboxProcessedDir(config, agentId), `${messageId}.json`);
}
/**
* Resolve the pid file path
*/
function resolvePidPath(config, agentId) {
	return join(resolveAgentDir(config, agentId), FILENAMES.PID);
}
/**
* Resolve the status.json path
*/
function resolveStatusPath(config, agentId) {
	return join(resolveAgentDir(config, agentId), FILENAMES.STATUS);
}
/**
* Resolve the Unix socket path
*/
function resolveSocketPath(config, agentId) {
	return join(resolveAgentDir(config, agentId), FILENAMES.SOCKET);
}
/**
* Resolve the extensions directory (global)
*/
function resolveExtensionsDir() {
	return join(resolveStateDir(), "extensions");
}
/**
* Resolve the extensions lockfile path
*/
function resolveExtensionsLockPath() {
	return join(resolveExtensionsDir(), FILENAMES.EXTENSIONS_LOCK);
}
/**
* Per-agent extensions directory (`…/agents/<id>/agent/extensions/`) — used for discovery of
* legacy or manually placed copies. CLI, web store, and `extensions dev` symlink installs use
* {@link resolveExtensionsDir} (`~/.xopc/extensions`) only.
*/
function resolveWorkspaceExtensionsDir(config, agentId) {
	return join(resolveAgentDir(config, agentId), "extensions");
}
/**
* Resolve the skills directory (global)
*/
function resolveSkillsDir() {
	return join(resolveStateDir(), "skills");
}
/**
* Resolve a specific skill path
*/
function resolveSkillPath(skillId) {
	return join(resolveSkillsDir(), skillId, "SKILL.md");
}
/**
* Skills hub lock file (~/.xopc/skills-lock.json): install source + content hash per managed skill id.
*/
function resolveSkillsLockPath() {
	return join(resolveStateDir(), FILENAMES.SKILLS_LOCK);
}
/**
* Resolve the cron directory
*/
function resolveCronDir() {
	return join(resolveStateDir(), "cron");
}
/**
* Resolve the cron jobs file path
*/
function resolveCronJobsPath() {
	return join(resolveCronDir(), FILENAMES.CRON_JOBS);
}
/**
* Resolve the cron logs directory
*/
function resolveCronLogsDir() {
	return join(resolveCronDir(), "logs");
}
/**
* Directory for persisted cron run history (one JSONL file per job id).
*/
function resolveCronRunsDir() {
	return join(resolveCronDir(), "runs");
}
/**
* Resolve a specific cron log file path
*/
function resolveCronLogPath(date) {
	return join(resolveCronLogsDir(), `${date}.jsonl`);
}
/**
* Resolve the logs directory
*/
function resolveLogsDir() {
	return process.env[ENV_VARS.LOG_DIR] ?? join(resolveStateDir(), "logs");
}
/**
* Resolve a specific log file path
*/
function resolveLogPath(date) {
	return join(resolveLogsDir(), `xopc-${date}.log`);
}
/**
* Resolve the bin directory
*/
function resolveBinDir() {
	return join(resolveStateDir(), "bin");
}
/**
* Resolve the xopc CLI path
*/
function resolveXopcBinPath() {
	return join(resolveBinDir(), "xopc");
}
/**
* Resolve the tools directory
*/
function resolveToolsDir() {
	return join(resolveStateDir(), "tools");
}
/**
* Resolve the Node.js tools directory
*/
function resolveNodeToolsDir() {
	return join(resolveToolsDir(), "node");
}
/**
* Resolve the current Node.js bin directory
*/
function resolveNodeBinDir() {
	return join(resolveNodeToolsDir(), "current", "bin");
}
/**
* Resolve the node binary path
*/
function resolveNodeBinPath() {
	return join(resolveNodeBinDir(), "node");
}
/**
* Resolve the npm binary path
*/
function resolveNpmBinPath() {
	return join(resolveNodeBinDir(), "npm");
}
/**
* Resolve the models.json path
*/
function resolveModelsJsonPath() {
	return join(resolveStateDir(), FILENAMES.MODELS_JSON);
}
/**
* Resolve the agent metadata file path
*/
function resolveAgentMetadataPath(config, agentId) {
	return join(resolveAgentDir(config, agentId), FILENAMES.AGENT_JSON);
}
/**
* OpenClaw-aligned: workspace setup state directory (`<workspace>/.xopc/`).
*/
function resolveWorkspaceStateDir(config, agentId) {
	return join(resolveAgentWorkspaceDir(config, agentId), ".xopc");
}
/**
* OpenClaw-aligned: workspace setup state file (`<workspace>/.xopc/workspace-state.json`).
*/
function resolveWorkspaceStatePath(config, agentId) {
	return join(resolveWorkspaceStateDir(config, agentId), FILENAMES.WORKSPACE_STATE);
}
/**
* Resolve the skills cache file path (internal agent state, under agent dir).
*/
function resolveSkillsCachePath(config, agentId) {
	return join(resolveAgentDir(config, agentId), "state", FILENAMES.SKILLS_CACHE);
}
/**
* Resolve the memory directory
*/
function resolveMemoryDir(config, agentId) {
	return join(resolveAgentWorkspaceDir(config, agentId), "memory");
}
/**
* Resolve a specific memory file path
*/
function resolveMemoryPath(config, date, agentId) {
	return join(resolveMemoryDir(config, agentId), `${date}.md`);
}
/**
* Resolve the bundled extensions directory (shipped with xopc).
*
* Layout-dependent candidates (first existing wins):
* - `dist/src/config` → `dist/extensions` (npm / gateway)
* - `src/config` → `extensions/` (dev, tsx)
* - `out/server` → `dist/extensions` (Electron esbuild bundle)
*/
function resolveBundledExtensionsDir() {
	try {
		const srcDir = dirname(fileURLToPath(import.meta.url));
		const candidates = [
			join(srcDir, "..", "..", "extensions"),
			join(srcDir, "..", "..", "dist", "extensions"),
			join(srcDir, "..", "..", "..", "extensions")
		];
		for (const dir of candidates) if (existsSync(dir)) return dir;
		return null;
	} catch {
		return null;
	}
}
/**
* Resolve the bundled skills directory (shipped with xopc)
*/
function resolveBundledSkillsDir() {
	try {
		const srcDir = dirname(fileURLToPath(import.meta.url));
		const skillsDir = join(join(srcDir, "..", ".."), "skills");
		if (existsSync(skillsDir)) return skillsDir;
		const devSkillsDir = join(join(srcDir, "..", "..", ".."), "skills");
		if (existsSync(devSkillsDir)) return devSkillsDir;
		return null;
	} catch {
		return null;
	}
}
/**
* Path to extension-sdk entry (for jiti / extension loader aliases).
*/
function resolveExtensionSdkPath() {
	try {
		const srcDir = dirname(fileURLToPath(import.meta.url));
		const adjacent = join(srcDir, "..", "extensions", "sdk", "index.ts");
		if (existsSync(adjacent)) return adjacent;
		const fromPackageRoot = join(srcDir, "..", "..", "src", "extensions", "sdk", "index.ts");
		if (existsSync(fromPackageRoot)) return fromPackageRoot;
		const cwd = join(process.cwd(), "src", "extensions", "sdk", "index.ts");
		if (existsSync(cwd)) return cwd;
		return adjacent;
	} catch {
		return join(process.cwd(), "src", "extensions", "sdk", "index.ts");
	}
}
var FILENAMES, WORKSPACE_FILES;
var init_paths = __esmMin((() => {
	init_agent_scope();
	init_paths_state();
	init_workspace_defaults();
	init_transcript_paths();
	FILENAMES = {
		CONFIG: "xopc.json",
		MODELS_JSON: "models.json",
		AGENT_JSON: "agent.json",
		/** OpenClaw-aligned session key → entry map (flat `sessions/` dir). */
		SESSIONS_MAP: "sessions.json",
		EXTENSIONS_LOCK: "extensions-lock.json",
		CREDENTIALS_PROFILES: "auth-profiles.json",
		CRON_JOBS: "jobs.json",
		WORKSPACE_STATE: "workspace.json",
		SKILLS_CACHE: "skills-cache.json",
		/** Hub / CLI install provenance for ~/.xopc/skills/<id>. */
		SKILLS_LOCK: "skills-lock.json",
		PID: "pid",
		STATUS: "status.json",
		SOCKET: "agent.sock"
	};
	WORKSPACE_FILES = {
		SOUL: "SOUL.md",
		IDENTITY: "IDENTITY.md",
		USER: "USER.md",
		AGENTS: "AGENTS.md",
		TOOLS: "TOOLS.md",
		HEARTBEAT: "HEARTBEAT.md",
		MEMORY: "MEMORY.md",
		BOOTSTRAP: "BOOTSTRAP.md"
	};
}));
//#endregion
init_paths();
export { ENV_VARS, FILENAMES, WORKSPACE_FILES, existsSync, init_paths, resolveAgentAuthProfilesPath, resolveAgentDir, resolveAgentDir$1 as resolveAgentDirFromConfig, resolveAgentHomeDir, resolveAgentHomeDir$1 as resolveAgentHomeDirFromConfig, resolveAgentMetadataPath, resolveAgentProfileDir, resolveAgentProfileMarkdownPath, resolveAgentWorkspaceDir, resolveAuthProfilesPath, resolveBinDir, resolveBundledExtensionsDir, resolveBundledSkillsDir, resolveConfigPath, resolveCredentialsDir, resolveCronDir, resolveCronJobsPath, resolveCronLogPath, resolveCronLogsDir, resolveCronRunsDir, resolveDefaultAgentWorkspaceDir, resolveExtensionSdkPath, resolveExtensionsDir, resolveExtensionsLockPath, resolveHomeDir, resolveInboxDir, resolveInboxMessagePath, resolveInboxPendingDir, resolveInboxProcessedDir, resolveLogPath, resolveLogsDir, resolveMemoryDir, resolveMemoryPath, resolveModelsJsonPath, resolveNodeBinDir, resolveNodeBinPath, resolveNodeToolsDir, resolveNpmBinPath, resolveOAuthPath, resolvePidPath, resolveSessionFilePath, resolveSessionTranscriptPath, resolveSessionTranscriptPathInDir, resolveSessionsArchiveDir, resolveSessionsDir, resolveSessionsDir$1 as resolveSessionsDirFromConfig, resolveSessionsMapPath, resolveSkillPath, resolveSkillsCachePath, resolveSkillsDir, resolveSkillsLockPath, resolveSocketPath, resolveStateDir, resolveStatusPath, resolveToolsDir, resolveWorkspaceExtensionsDir, resolveWorkspaceFile, resolveWorkspaceStateDir, resolveWorkspaceStatePath, resolveXopcBinPath };

//# sourceMappingURL=paths.js.map