//#region src/agent/workflow/last-run-memory.ts
/**
* Per-session memory of the most recent workflow script that ran successfully.
*
* Purpose: enable `/workflow save <name>` — the user sees a workflow run,
* likes it, types `/workflow save audit_repo_strict`, and the model-generated
* script lands in `~/.xopc/workflows/`.
*
* Scope decision (KISS):
* - In-memory only, keyed by sessionKey. Cleared on process restart. OPC is
*   long-lived per session, so the practical window is "from when the user
*   ran the workflow until they save it" — minutes, not days. Persisting
*   across restarts would require either session-store coupling or a separate
*   sidecar file, both bigger than the value.
* - Records on EVERY successful workflow tool execution, including runs by
*   name (so users can re-save a slightly modified built-in too).
* - Bounded by a small LRU so a runaway never grows the heap.
*/
const DEFAULT_MAX_ENTRIES = 64;
var LastWorkflowMemoryImpl = class {
	entries = /* @__PURE__ */ new Map();
	constructor(maxEntries = DEFAULT_MAX_ENTRIES) {
		this.maxEntries = maxEntries;
	}
	record(sessionKey, entry) {
		if (!sessionKey) return;
		if (this.entries.has(sessionKey)) this.entries.delete(sessionKey);
		this.entries.set(sessionKey, entry);
		while (this.entries.size > this.maxEntries) {
			const oldestKey = this.entries.keys().next().value;
			if (oldestKey === void 0) break;
			this.entries.delete(oldestKey);
		}
	}
	get(sessionKey) {
		if (!sessionKey) return void 0;
		return this.entries.get(sessionKey);
	}
	clear(sessionKey) {
		if (sessionKey === void 0) this.entries.clear();
		else this.entries.delete(sessionKey);
	}
	/** Visible for tests; do not consume from production code. */
	_size() {
		return this.entries.size;
	}
};
let singleton = null;
function getLastWorkflowMemory() {
	if (!singleton) singleton = new LastWorkflowMemoryImpl();
	return singleton;
}
/** Reset the singleton (tests only). */
function _resetLastWorkflowMemoryForTests() {
	singleton = null;
}
//#endregion
export { _resetLastWorkflowMemoryForTests, getLastWorkflowMemory };

//# sourceMappingURL=last-run-memory.js.map