import { x as head, a as attr, c as escape_html, b as attr_class, g as derived, s as store_get, e as ensure_array_like, y as bind_props, u as unsubscribe_stores } from './dev-BNpEUZI3.js';
import 'node:module';
import { p as page } from './stores-CdeEEU9O.js';
import { B as Badge } from './Tabs-DzG6Bn9a.js';
import './client-CW9E6S_J.js';
import { S as SvgRenderer, D as DetailDrawer, t as tasksToGraph } from './tasks2-DtLXCqqM.js';
import './tasks-CnwUAUXf.js';
import './internal-DYSVC9SL.js';
import '@sveltejs/kit/internal';
import './index-server-DocJvixA.js';
import './chunk-DDP5xfzh.js';
import '@sveltejs/kit/internal/server';
import './StatBlock-DHJMmOCx.js';
import './ui-DR8zOSpC.js';
import './no-face-up-DcejJLy-.js';
import 'd3';
import './paths-2M_UxD_H.js';
import 'node:fs';
import 'node:path';
import 'node:os';
import 'node:events';
import 'node:diagnostics_channel';
import 'fs';
import 'events';
import 'util';
import 'path';
import 'assert';
import 'worker_threads';
import 'module';
import 'node:url';
import 'url';
import 'buffer';
import 'node:child_process';
import 'node:crypto';
import 'node:process';
import 'node:async_hooks';
import './data-accessor-CVbz8X_7.js';
import './conduit-Ca_OFWR_.js';
import './indexes-aYlULWG3.js';
import './utils-BvHPJOVk.js';
import './unique-constraint-BM-Apx1H.js';
import './sqlite-Dsbe0wec.js';
import './dual-scope-db-ATrwq0LH.js';
import './memory-schema-Bi7cChwo.js';
import './agent-registry-BtE5uhMO.js';
import './nexus-sqlite2-DgTuv9BQ.js';
import './nexus-schema2-BEd-ol6e.js';
import './logger-ChCwlV5k.js';
import 'node:sqlite';
import './lock-BoHF25mx.js';
import './index-IVoIz4D5.js';
import 'constants';
import 'stream';
import 'node:fs/promises';
import 'jsonc-parser';
import '@cleocode/cant';
import 'node:util';
import 'node:buffer';
import 'child_process';
import './branch-lock-qP1EkZ7p.js';
import './src2-DK8DKufK.js';
import 'llmtxt/identity';
import './sessions-j73dkbCI.js';
import './registry2-BSyCTA3q.js';
import './index-Ca4C2M45.js';
import './mvi-helpers-BNsJ8ZpQ.js';
import './session-store-OwQWMSf_.js';
import './session-manifest-ZHrj54LR.js';
import './storage-B9UA3BHR.js';
import './config-B0nEjgSh.js';
import './json-DXl7iDYg.js';
import './data-safety-central-vmfu_Y4J.js';
import './sqlite-data-accessor-C59wZ0zp.js';
import './cross-db-cleanup-C_FLyd-6.js';

//#region src/lib/components/WorkGraphView.svelte
function WorkGraphView($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/** Full task set (from the gateway-backed explorer bundle). */
		/** All dependency edges from the bundle. */
		/**
		* The saga (or any ancestor) id to scope the graph to. Every descendant
		* epic / task / subtask is included via the adapter's ancestor walk.
		* When omitted the full bundle projects (parity with GraphTab).
		*/
		/** Include cancelled epics in the projection. Default false. */
		/** Optional initially-selected node id (drives the drawer on mount). */
		let { tasks, deps, sagaId = null, includeCancelled = false, selectedId = null } = $$props;
		const graph = derived(() => tasksToGraph(tasks, deps, {
			epicScope: sagaId,
			includeCancelled,
			includeArchived: false
		}));
		/** Visible edge kinds — containment + both dependency families. */
		const VISIBLE_EDGE_KINDS = new Set([
			"parent",
			"blocks",
			"depends"
		]);
		const tasksById = derived(() => new Map(tasks.map((t) => [t.id, t])));
		const selectedTask = derived(() => selectedId ? tasksById().get(selectedId) ?? null : null);
		/** Upstream dependency links: tasks the selected node depends on. */
		const upstreamLinks = derived(() => {
			if (!selectedTask()) return [];
			const out = [];
			for (const d of deps) {
				if (d.taskId !== selectedTask().id) continue;
				const blocker = tasksById().get(d.dependsOn);
				if (!blocker) continue;
				out.push({
					id: blocker.id,
					title: blocker.title,
					status: blocker.status,
					priority: blocker.priority
				});
			}
			return out;
		});
		/** Downstream dependency links: tasks that depend on the selected node. */
		const downstreamLinks = derived(() => {
			if (!selectedTask()) return [];
			const out = [];
			for (const d of deps) {
				if (d.dependsOn !== selectedTask().id) continue;
				const dependent = tasksById().get(d.taskId);
				if (!dependent) continue;
				out.push({
					id: dependent.id,
					title: dependent.title,
					status: dependent.status,
					priority: dependent.priority
				});
			}
			return out;
		});
		/** Containment chain: walk `parentId` up to (and including) the saga root. */
		const parentChain = derived(() => {
			if (!selectedTask()) return [];
			const chain = [];
			let current = selectedTask().parentId ? tasksById().get(selectedTask().parentId) : void 0;
			const seen = /* @__PURE__ */ new Set();
			while (current && !seen.has(current.id)) {
				seen.add(current.id);
				chain.unshift({
					id: current.id,
					title: current.title,
					type: current.type
				});
				current = current.parentId ? tasksById().get(current.parentId) : void 0;
			}
			return chain;
		});
		function onNodeClicked(n) {
			selectedId = n.id;
		}
		function onDrawerClose() {
			selectedId = null;
		}
		function onDrawerSelectDep(id) {
			selectedId = id;
		}
		$$renderer.push(`<div class="workgraph-view svelte-1lzd0zi"><div class="workgraph-meta svelte-1lzd0zi"><span class="count svelte-1lzd0zi"><strong class="svelte-1lzd0zi">${escape_html(graph().nodes.length)}</strong> nodes · <strong class="svelte-1lzd0zi">${escape_html(graph().edges.length)}</strong> edges `);
		if (sagaId) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`· scoped to <code class="svelte-1lzd0zi">${escape_html(sagaId)}</code>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--></span> <span class="legend-hint svelte-1lzd0zi">containment · depends · blocks</span></div> <div class="workgraph-body svelte-1lzd0zi"><div class="graph-wrap svelte-1lzd0zi">`);
		if (graph().nodes.length === 0) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<div class="empty-state svelte-1lzd0zi"><p>No tasks in this workgraph `);
			if (sagaId) {
				$$renderer.push("<!--[0-->");
				$$renderer.push(`for <code class="svelte-1lzd0zi">${escape_html(sagaId)}</code>`);
			} else $$renderer.push("<!--[-1-->");
			$$renderer.push(`<!--]-->.</p></div>`);
		} else {
			$$renderer.push("<!--[-1-->");
			SvgRenderer($$renderer, {
				nodes: graph().nodes,
				edges: graph().edges,
				clusters: graph().clusters,
				visibleEdgeKinds: VISIBLE_EDGE_KINDS,
				selectedNodeId: selectedId,
				onNodeClick: onNodeClicked,
				showLabels: "id-only",
				nodeRenderer: "pill",
				showToolbar: true,
				showLegend: true,
				ariaLabel: "Saga workgraph — containment and dependency edges"
			});
		}
		$$renderer.push(`<!--]--></div> `);
		if (selectedTask()) {
			$$renderer.push("<!--[0-->");
			DetailDrawer($$renderer, {
				task: selectedTask(),
				upstream: upstreamLinks(),
				downstream: downstreamLinks(),
				parentChain: parentChain(),
				onClose: onDrawerClose,
				onSelectDep: onDrawerSelectDep
			});
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--></div></div>`);
		bind_props($$props, { selectedId });
	});
}
//#endregion
//#region src/lib/stores/theme.svelte.ts
var STUDIO_THEMES = [
	"hermes",
	"nous",
	"bronze",
	"slate",
	"mono"
];
var STUDIO_THEME_LABELS = {
	hermes: "Hermes",
	nous: "Nous",
	bronze: "Bronze",
	slate: "Slate",
	mono: "Mono"
};
var DEFAULT_STUDIO_THEME = "hermes";
var THEME_KEY = "cleo-studio-theme";
var MODE_KEY = "cleo-studio-theme-mode";
function coerceTheme(value) {
	return STUDIO_THEMES.includes(value ?? "") ? value : DEFAULT_STUDIO_THEME;
}
/**
* The reactive theme store. Construct via {@link createThemeStore}.
*
* Holds the active theme + light-mode flag as `$state`; `apply()` reflects
* them onto `<html>` (`data-theme` + a `.light` class). All DOM access is
* SSR-guarded so the store is safe to instantiate at module scope and
* `apply()` from a client `$effect`.
*/
var ThemeStore = class {
	/** The active operator-console theme. */
	#active = DEFAULT_STUDIO_THEME;
	/** Whether the light operator-console variant is active. */
	#light = false;
	/**
	* @param initial - Optional SSR-provided initial theme (e.g. from a cookie).
	*/
	constructor(initial) {
		if (initial) this.#active = initial;
	}
	/** The active theme id. */
	get active() {
		return this.#active;
	}
	/** Whether the light variant is active. */
	get light() {
		return this.#light;
	}
	/** The ordered theme catalogue (static). */
	get themes() {
		return STUDIO_THEMES;
	}
	/**
	* Hydrate from `localStorage` (client-only) then reflect onto `<html>`.
	* Idempotent + SSR-safe (no-op on the server). A route calls this once
	* from a client `$effect`.
	*/
	hydrate() {
		if (typeof localStorage !== "undefined") {
			this.#active = coerceTheme(localStorage.getItem(THEME_KEY));
			this.#light = localStorage.getItem(MODE_KEY) === "light";
		}
		this.apply();
	}
	/**
	* Switch to a new theme, persist it, and re-apply.
	*
	* @param theme - The theme to activate.
	*/
	set(theme) {
		this.#active = theme;
		if (typeof localStorage !== "undefined") localStorage.setItem(THEME_KEY, theme);
		this.apply();
	}
	/**
	* Toggle the light operator-console variant, persist it, and re-apply.
	*/
	toggleLight() {
		this.#light = !this.#light;
		if (typeof localStorage !== "undefined") localStorage.setItem(MODE_KEY, this.#light ? "light" : "dark");
		this.apply();
	}
	/**
	* Reflect the current `$state` onto the document root. SSR-safe (the
	* `document` guard makes this a no-op on the server).
	*/
	apply() {
		if (typeof document === "undefined") return;
		const root = document.documentElement;
		root.setAttribute("data-theme", this.#active);
		root.classList.toggle("light", this.#light);
	}
};
/**
* Create a {@link ThemeStore}. The ergonomic entry point a route uses.
*
* @param initial - Optional SSR initial theme.
* @returns A fresh reactive theme store.
*
* @example
* ```ts
* const theme = createThemeStore();
* $effect(() => { theme.hydrate(); });
* ```
*/
function createThemeStore(initial) {
	return new ThemeStore(initial);
}
//#endregion
//#region src/lib/components/shell/ThemeSwitcher.svelte
function ThemeSwitcher($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		/** The shared theme rune store (constructed + hydrated by the host route). */
		let { theme } = $$props;
		$$renderer.push(`<div class="theme-switcher svelte-2szurj" role="group" aria-label="Operator console theme"><div class="seg svelte-2szurj" role="radiogroup" aria-label="Theme palette"><!--[-->`);
		const each_array = ensure_array_like(theme.themes);
		for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
			let t = each_array[$$index];
			$$renderer.push(`<button type="button"${attr_class("seg-btn svelte-2szurj", void 0, { "active": theme.active === t })} role="radio"${attr("aria-checked", theme.active === t)}${attr("title", `${STUDIO_THEME_LABELS[t]} theme`)}><span class="swatch svelte-2szurj"${attr("data-theme", t)} aria-hidden="true"></span> ${escape_html(STUDIO_THEME_LABELS[t])}</button>`);
		}
		$$renderer.push(`<!--]--></div> <button type="button" class="mode-btn svelte-2szurj"${attr("aria-pressed", theme.light)} title="Toggle light operator console">${escape_html(theme.light ? "Light" : "Dark")}</button></div>`);
	});
}
//#endregion
//#region src/routes/studio/[projectId]/[sagaId]/+page.svelte
function _page($$renderer, $$props) {
	$$renderer.component(($$renderer) => {
		var $$store_subs;
		let { data } = $$props;
		const theme = createThemeStore();
		const view = derived(() => store_get($$store_subs ??= {}, "$page", page).url.searchParams.get("view") === "kanban" ? "kanban" : "workgraph");
		const sagaTitle = derived(() => data.saga?.title ?? data.sagaId);
		const nodeCount = derived(() => data.explorer?.tasks.length ?? 0);
		head("b7bs0", $$renderer, ($$renderer) => {
			$$renderer.title(($$renderer) => {
				$$renderer.push(`<title>${escape_html(data.sagaId)} · ${escape_html(data.projectName)} — CLEO Studio</title>`);
			});
			$$renderer.push(`<meta name="robots" content="noindex"/>`);
		});
		$$renderer.push(`<section class="saga-shell svelte-b7bs0"${attr("data-view", view())}><header class="command-bar svelte-b7bs0"><nav class="crumbs svelte-b7bs0" aria-label="Breadcrumb"><a class="crumb svelte-b7bs0" href="/projects">${escape_html(data.projectName)}</a> <span class="sep svelte-b7bs0" aria-hidden="true">▸</span> <span class="crumb current svelte-b7bs0"${attr("title", sagaTitle())}><code class="svelte-b7bs0">${escape_html(data.sagaId)}</code> `);
		if (data.saga) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<span class="crumb-title svelte-b7bs0">${escape_html(data.saga.title)}</span>`);
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--></span> `);
		if (data.saga) {
			$$renderer.push("<!--[0-->");
			Badge($$renderer, {
				tone: "info",
				size: "sm",
				children: ($$renderer) => {
					$$renderer.push(`<!---->${escape_html(data.saga.type)}`);
				}});
		} else $$renderer.push("<!--[-1-->");
		$$renderer.push(`<!--]--></nav> <div class="toggle svelte-b7bs0" role="tablist" aria-label="Saga view"><button type="button"${attr_class("toggle-btn svelte-b7bs0", void 0, { "active": view() === "workgraph" })} role="tab"${attr("aria-selected", view() === "workgraph")}>Workgraph</button> <button type="button"${attr_class("toggle-btn svelte-b7bs0", void 0, { "active": view() === "kanban" })} role="tab"${attr("aria-selected", view() === "kanban")}>Kanban</button></div> <div class="bar-right svelte-b7bs0">`);
		ThemeSwitcher($$renderer, { theme });
		$$renderer.push(`<!----></div></header> <div class="canvas svelte-b7bs0">`);
		if (data.error) {
			$$renderer.push("<!--[0-->");
			$$renderer.push(`<div class="shell-error svelte-b7bs0" role="alert"><p>${escape_html(data.error)}</p></div>`);
		} else if (!data.explorer) {
			$$renderer.push("<!--[1-->");
			$$renderer.push(`<div class="shell-error svelte-b7bs0" role="alert"><p>No workgraph bundle available for this saga.</p></div>`);
		} else if (view() === "workgraph") {
			$$renderer.push("<!--[2-->");
			WorkGraphView($$renderer, {
				tasks: data.explorer.tasks,
				deps: data.explorer.deps,
				sagaId: data.sagaId
			});
		} else {
			$$renderer.push("<!--[-1-->");
			$$renderer.push("<!--[-1-->");
			$$renderer.push(`<div class="ssr-placeholder svelte-b7bs0"><p>Loading the live board…</p></div>`);
			$$renderer.push(`<!--]-->`);
		}
		$$renderer.push(`<!--]--></div> <footer class="shell-foot svelte-b7bs0"><span class="hint svelte-b7bs0">${escape_html(nodeCount())} tasks in bundle · containment + depends · operator console</span></footer></section>`);
		if ($$store_subs) unsubscribe_stores($$store_subs);
	});
}

export { _page as default };
//# sourceMappingURL=_page.svelte-DxDS2zHS.js.map
