import { init_agent_scope, resolveAgentHomeDir, resolveAgentIdForWorkspacePath } from "../agent-scope.js";
import { join } from "node:path";
//#region src/agent/memory/memory-config.ts
init_agent_scope();
/** When false, curated `memories/` (under agent home) + external memory providers are off. */
function isMemorySubsystemEnabled(config) {
	return config?.agents?.defaults?.memory?.enabled !== false;
}
/** Curated memory tool + agent-home `memories/` store (not injected into system prompt). */
function isCuratedMemoryInPrompt(config) {
	const m = config?.agents?.defaults?.memory;
	if (m?.enabled === false) return false;
	if (m?.useEnhancedSystem === false) return false;
	return true;
}
function resolveBuiltinMemoryStoreConfig(workspaceDir, config) {
	const m = config?.agents?.defaults?.memory;
	return {
		workspaceDir,
		memoriesDir: config != null ? join(resolveAgentHomeDir(config, resolveAgentIdForWorkspacePath(config, workspaceDir)), "memories") : join(workspaceDir, "memories"),
		memoryCharLimit: m?.memoryCharLimit ?? 2200,
		userCharLimit: m?.userCharLimit ?? 1375,
		userProfileEnabled: m?.userProfileEnabled !== false
	};
}
/**
* Whether to prefix the user message with prefetched external memory this turn.
* `first-turn` only injects on turn 1. `contextCadence` N injects on turns 1, N+1, 2N+1, …
*/
function shouldInjectMemoryPrefetchThisTurn(config, turnNumber) {
	const m = config?.agents?.defaults?.memory;
	if ((m?.injectionFrequency ?? "every-turn") === "first-turn") return turnNumber === 1;
	const cadence = m?.contextCadence ?? 1;
	if (cadence <= 1) return true;
	return (turnNumber - 1) % cadence === 0;
}
function shouldRegisterCuratedMemoryTool(config) {
	return isCuratedMemoryInPrompt(config);
}
//#endregion
export { isCuratedMemoryInPrompt, isMemorySubsystemEnabled, resolveBuiltinMemoryStoreConfig, shouldInjectMemoryPrefetchThisTurn, shouldRegisterCuratedMemoryTool };

//# sourceMappingURL=memory-config.js.map