import { b as getNexusDb } from './connections2-D22b0xbS.js';
import { g as getActiveProjectId, l as listRegisteredProjects } from './project-context-D0JIm5Ed.js';
import { json } from '@sveltejs/kit';
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';
import './open-cleo-db-Ba2LY1h4.js';

//#region src/routes/api/search/+server.ts
/**
* Cross-project symbol search API endpoint.
*
* GET /api/search?q=<term>&scope=all|current
*
* Searches nexus_nodes across all registered projects (scope=all) or
* just the current/active project (scope=current).
*
* Query params:
*   q      - search term (required, min 2 chars)
*   scope  - "all" (default) or "current"
*   limit  - max results per project (default 20, max 100)
*
* Returns a LAFS-compliant JSON envelope.
*
* @task T622
*/
var GET = ({ url, cookies }) => {
	const startTime = Date.now();
	const q = url.searchParams.get("q") ?? "";
	const scope = url.searchParams.get("scope") ?? "all";
	const limitParam = parseInt(url.searchParams.get("limit") ?? "20", 10);
	const limit = Math.min(Math.max(1, limitParam), 100);
	if (q.length < 2) return json({
		success: false,
		error: {
			code: "E_INVALID_INPUT",
			message: "q must be at least 2 characters"
		},
		meta: {
			operation: "api.search",
			duration_ms: Date.now() - startTime,
			timestamp: (/* @__PURE__ */ new Date()).toISOString()
		}
	}, { status: 400 });
	try {
		const db = getNexusDb();
		if (!db) return json({
			success: true,
			data: {
				query: q,
				scope,
				results: [],
				totalHits: 0
			},
			meta: {
				operation: "api.search",
				duration_ms: Date.now() - startTime,
				timestamp: (/* @__PURE__ */ new Date()).toISOString()
			}
		});
		let projectFilter = null;
		if (scope === "current") {
			const activeId = getActiveProjectId(cookies);
			if (activeId) projectFilter = [activeId];
		}
		const allProjects = listRegisteredProjects();
		const projectNameById = new Map(allProjects.map((p) => [p.projectId, p.name]));
		const hits = [];
		const term = `%${q.toLowerCase()}%`;
		if (projectFilter) for (const projectId of projectFilter) {
			const rows = db.prepare(`SELECT id, project_id, name, kind, file_path, start_line, language, doc_summary, is_exported
             FROM nexus_nodes
             WHERE project_id = ?
               AND lower(name) LIKE ?
               AND kind NOT IN ('community', 'process', 'file', 'folder')
             ORDER BY
               CASE kind
                 WHEN 'function' THEN 0 WHEN 'method' THEN 1 WHEN 'class' THEN 2
                 WHEN 'interface' THEN 3 WHEN 'type_alias' THEN 4 ELSE 5
               END, name
             LIMIT ?`).all(projectId, term, limit);
			for (const row of rows) {
				if (!row.name) continue;
				hits.push({
					projectId: row.project_id,
					projectName: projectNameById.get(row.project_id) ?? row.project_id,
					nodeId: row.id,
					name: row.name,
					kind: row.kind,
					filePath: row.file_path ?? null,
					startLine: row.start_line ?? null,
					language: row.language ?? null,
					docSummary: row.doc_summary ?? null,
					isExported: row.is_exported === 1
				});
			}
		}
		else {
			const rows = db.prepare(`SELECT id, project_id, name, kind, file_path, start_line, language, doc_summary, is_exported
           FROM nexus_nodes
           WHERE lower(name) LIKE ?
             AND kind NOT IN ('community', 'process', 'file', 'folder')
           ORDER BY
             CASE kind
               WHEN 'function' THEN 0 WHEN 'method' THEN 1 WHEN 'class' THEN 2
               WHEN 'interface' THEN 3 WHEN 'type_alias' THEN 4 ELSE 5
             END, name
           LIMIT ?`).all(term, limit * Math.max(allProjects.length, 1));
			for (const row of rows) {
				if (!row.name) continue;
				hits.push({
					projectId: row.project_id,
					projectName: projectNameById.get(row.project_id) ?? row.project_id,
					nodeId: row.id,
					name: row.name,
					kind: row.kind,
					filePath: row.file_path ?? null,
					startLine: row.start_line ?? null,
					language: row.language ?? null,
					docSummary: row.doc_summary ?? null,
					isExported: row.is_exported === 1
				});
			}
		}
		return json({
			success: true,
			data: {
				query: q,
				scope,
				results: hits,
				totalHits: hits.length
			},
			meta: {
				operation: "api.search",
				duration_ms: Date.now() - startTime,
				timestamp: (/* @__PURE__ */ new Date()).toISOString()
			}
		});
	} catch (err) {
		return json({
			success: false,
			error: {
				code: "E_SEARCH_FAILED",
				message: err instanceof Error ? err.message : String(err)
			},
			meta: {
				operation: "api.search",
				duration_ms: Date.now() - startTime,
				timestamp: (/* @__PURE__ */ new Date()).toISOString()
			}
		}, { status: 500 });
	}
};

export { GET };
//# sourceMappingURL=_server.ts-BFgW3iuZ.js.map
