import { b as getNexusDb } from './connections2-D22b0xbS.js';
import './dual-scope-db-ATrwq0LH.js';
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:module';
import 'node:child_process';
import 'node:crypto';
import 'node:process';
import 'node:async_hooks';
import './indexes-aYlULWG3.js';
import './utils-BvHPJOVk.js';
import './dist4-CiQ5cizO.js';
import './adapters-D2gEs_5L.js';
import './registry2-BSyCTA3q.js';
import './data-accessor-CVbz8X_7.js';
import './tasks-CnwUAUXf.js';
import './conduit-Ca_OFWR_.js';
import './unique-constraint-BM-Apx1H.js';
import './chunk-DDP5xfzh.js';
import './sqlite-Dsbe0wec.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 './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';
import './query-ops-BDMaTdYw.js';
import 'node:net';
import './src3-CMSGYxDI.js';
import './local-model-fit2-J1xCIhC_.js';
import './credential-pool-B04qO8at.js';
import './catalog-model-resolver2-Cexk2TN0.js';
import './role-resolver-DF9BQ_U6.js';
import './identity2-DeAB5RXE.js';
import './role-executor-C4-3bmgC.js';
import 'node:stream';
import 'crypto';
import 'os';
import 'node:http2';
import 'fs/promises';
import './models-catalog-DG3aPok8.js';
import './catalog-resolver2-c0qfF34B.js';
import './providers-CmIcBfg-.js';
import './brain-maintenance-bSR6GwAG.js';
import './graph-auto-populate2-DYsUNGSL.js';
import './temporal-supersession-BZ46j30w.js';
import './typed-query-l1D_QElt.js';
import './llm-backend-resolver-BPbvttS4.js';
import '@ai-sdk/provider-utils';
import './observer-reflector2-D8nxuglX.js';
import './learnings2-2m2p7lzT.js';
import './memory-accessor2-BzlgmY-Z.js';
import './quality-scoring-CCPuRQmJ.js';
import './patterns2-DYKfsbwN.js';
import './graph-memory-bridge2-C7Y32Mk4.js';
import './sigil2-DftKm7Um.js';
import './services-Dlf3Gefq.js';
import './audit4-S87oN-BC.js';
import 'process';
import './cleo-home-BCqJ5rg1.js';

//#region src/routes/code/flows/+page.server.ts
/**
* /code/flows — execution-flow tracer.
*
* Surfaces entry-points + their fanout computed from `calls` edges.
* If nexus.db contains process / flow-step rows we use them directly;
* otherwise we compute a synthetic "flow" per entry-point by BFS-ing
* `calls` edges up to `MAX_DEPTH` hops.
*
* @task T990
* @wave 1B
*/
/** How deep the synthetic call-graph BFS traces. */
var MAX_DEPTH = 3;
/** How many fanout nodes we emit per flow before truncation. */
var MAX_FANOUT = 60;
/** How many entry points we surface in the side list. */
var MAX_FLOWS = 64;
var load = () => {
	const db = getNexusDb();
	if (!db) return {
		flows: [],
		nodes: [],
		edges: [],
		hasProcesses: false,
		empty: true
	};
	const entryRows = db.prepare(`SELECT DISTINCT n.id, n.label, n.kind, n.file_path
       FROM nexus_relations r
       JOIN nexus_nodes n ON r.source_id = n.id
       WHERE r.type = 'entry_point_of'
       LIMIT ?`).all(MAX_FLOWS);
	let finalEntries = entryRows;
	if (entryRows.length === 0) finalEntries = db.prepare(`SELECT n.id, n.label, n.kind, n.file_path, COUNT(*) AS out_deg
         FROM nexus_relations r
         JOIN nexus_nodes n ON n.id = r.source_id
         WHERE r.type = 'calls'
         GROUP BY n.id
         ORDER BY out_deg DESC
         LIMIT ?`).all(MAX_FLOWS).map(({ id, label, kind, file_path }) => ({
		id,
		label,
		kind,
		file_path
	}));
	const hasProcesses = entryRows.length > 0;
	const reach = /* @__PURE__ */ new Map();
	const allNodeIds = /* @__PURE__ */ new Set();
	for (const entry of finalEntries) {
		const reached = [entry.id];
		const seen = new Set([entry.id]);
		const queue = [{
			id: entry.id,
			depth: 0
		}];
		while (queue.length > 0 && reached.length < MAX_FANOUT) {
			const cur = queue.shift();
			if (!cur) break;
			if (cur.depth >= MAX_DEPTH) continue;
			const rows = db.prepare(`SELECT target_id
           FROM nexus_relations
           WHERE source_id = ?
             AND type IN ('calls','step_in_process','handles_route','handles_tool','fetches')
           LIMIT 20`).all(cur.id);
			for (const row of rows) {
				if (seen.has(row.target_id)) continue;
				seen.add(row.target_id);
				reached.push(row.target_id);
				queue.push({
					id: row.target_id,
					depth: cur.depth + 1
				});
				if (reached.length >= MAX_FANOUT) break;
			}
		}
		reach.set(entry.id, reached);
		for (const id of reached) allNodeIds.add(id);
	}
	const nodes = [];
	if (allNodeIds.size > 0) {
		const idList = [...allNodeIds];
		const placeholders = idList.map(() => "?").join(",");
		const rows = db.prepare(`SELECT id, label, kind, file_path, community_id
         FROM nexus_nodes
         WHERE id IN (${placeholders})`).all(...idList);
		for (const row of rows) nodes.push({
			id: row.id,
			label: row.label,
			kind: row.kind,
			filePath: row.file_path ?? "",
			communityId: row.community_id
		});
	}
	const edges = [];
	if (allNodeIds.size > 0) {
		const idList = [...allNodeIds];
		const placeholders = idList.map(() => "?").join(",");
		const rows = db.prepare(`SELECT source_id, target_id, type, step
         FROM nexus_relations
         WHERE source_id IN (${placeholders}) AND target_id IN (${placeholders})
         LIMIT 2000`).all(...idList, ...idList);
		for (const row of rows) edges.push({
			source: row.source_id,
			target: row.target_id,
			type: row.type,
			stepIndex: row.step ?? void 0
		});
	}
	const flows = finalEntries.map((entry) => ({
		id: entry.id,
		label: entry.label,
		kind: entry.kind,
		filePath: entry.file_path ?? "",
		reachIds: reach.get(entry.id) ?? [entry.id]
	}));
	return {
		flows,
		nodes,
		edges,
		hasProcesses,
		empty: flows.length === 0
	};
};

var _page_server_ts = /*#__PURE__*/Object.freeze({
	__proto__: null,
	load: load
});

const index = 17;
let component_cache;
const component = async () => component_cache ??= (await import('./_page.svelte-CJhxoC3H.js')).default;
const server_id = "src/routes/code/flows/+page.server.ts";
const imports = ["_app/immutable/nodes/17.BDlmDnGQ.js","_app/immutable/chunks/CQQRJ2Hr.js","_app/immutable/chunks/DyGQ_VXC.js","_app/immutable/chunks/DrKWWDpL.js","_app/immutable/chunks/DKX-2-1g.js","_app/immutable/chunks/CQCxd1p9.js","_app/immutable/chunks/D8NsLz6i.js","_app/immutable/chunks/o1PZ6Kzq.js","_app/immutable/chunks/RptFUp2P.js","_app/immutable/chunks/CEqOYim7.js","_app/immutable/chunks/CqF5Lomf.js"];
const stylesheets = ["_app/immutable/assets/cluster-label-layer.aRgASjnn.css","_app/immutable/assets/no-face-up.BlswZ73M.css","_app/immutable/assets/nexus-adapter.DuSZKvuH.css","_app/immutable/assets/Tabs.CU9_rsWl.css","_app/immutable/assets/ui.CH-9N9-0.css","_app/immutable/assets/17.C-9c74gE.css"];
const fonts = [];

export { component, fonts, imports, index, _page_server_ts as server, server_id, stylesheets };
//# sourceMappingURL=17-DYnZroJ8.js.map
