//#region extensions/crypto/src/services/command-history.ts
/**
* Command History — Ring buffer of recent slash command results.
*
* Injected into the LLM prompt via before_prompt_build so the agent
* can see what slash commands were run and their results. This bridges
* the gap where the framework handles commands directly without passing
* the results through the LLM's conversation history.
*
* Per-user, in-memory only (no persistence needed — current session only).
*/
const MAX_ENTRIES = 10;
const _history = /* @__PURE__ */ new Map();
/** Record a slash command result. */
function recordCommand(userId, command, result) {
	let entries = _history.get(userId);
	if (!entries) {
		entries = [];
		_history.set(userId, entries);
	}
	const truncated = result.length > 300 ? result.slice(0, 300) + "..." : result;
	entries.push({
		command,
		result: truncated,
		timestamp: Date.now()
	});
	if (entries.length > MAX_ENTRIES) entries.splice(0, entries.length - MAX_ENTRIES);
}
/** Get recent command history for prompt injection. */
function getRecentCommands(userId, maxAge = 6e5) {
	const entries = _history.get(userId);
	if (!entries || entries.length === 0) return null;
	const cutoff = Date.now() - maxAge;
	const recent = entries.filter((e) => e.timestamp > cutoff);
	if (recent.length === 0) return null;
	return [
		"<recent_commands>",
		"These slash commands were run recently by the user:",
		...recent.map((e) => {
			const ago = Math.floor((Date.now() - e.timestamp) / 1e3);
			const agoStr = ago < 60 ? `${ago}s ago` : `${Math.floor(ago / 60)}m ago`;
			return `  ${e.command} (${agoStr}) → ${e.result}`;
		}),
		"These results are authoritative. Do not contradict them.",
		"</recent_commands>"
	].join("\n");
}
/** Clear history for a user (on /new). */
function clearCommandHistory(userId) {
	_history.delete(userId);
}
//#endregion
export { clearCommandHistory, getRecentCommands, recordCommand };

//# sourceMappingURL=command-history.mjs.map