import { g as getTasksDb } 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/tasks/sessions/+page.server.ts
/**
* Sessions page server load — session history with task completions timeline.
*/
var load = ({ locals }) => {
	const db = getTasksDb(locals.projectCtx);
	if (!db) return { sessions: [] };
	try {
		const rows = db.prepare(`SELECT id, name, status, agent, started_at, ended_at,
                current_task, tasks_completed_json, tasks_created_json
         FROM sessions
         ORDER BY started_at DESC
         LIMIT 100`).all();
		const sessionIds = rows.map((r) => r.id);
		const workHistoryRows = sessionIds.length > 0 ? db.prepare(`SELECT twh.session_id, twh.task_id, twh.set_at, twh.cleared_at,
                      t.title, t.status
               FROM task_work_history twh
               JOIN tasks t ON t.id = twh.task_id
               WHERE twh.session_id IN (${sessionIds.map(() => "?").join(",")})
               ORDER BY twh.set_at ASC`).all(...sessionIds) : [];
		const workHistoryBySession = /* @__PURE__ */ new Map();
		for (const row of workHistoryRows) {
			const existing = workHistoryBySession.get(row.session_id) ?? [];
			existing.push({
				id: row.task_id,
				title: row.title,
				status: row.status,
				setAt: row.set_at,
				clearedAt: row.cleared_at
			});
			workHistoryBySession.set(row.session_id, existing);
		}
		return { sessions: rows.map((s) => {
			let completedIds = [];
			try {
				completedIds = s.tasks_completed_json ? JSON.parse(s.tasks_completed_json) : [];
			} catch {
				completedIds = [];
			}
			let createdCount = 0;
			try {
				const created = s.tasks_created_json ? JSON.parse(s.tasks_created_json) : [];
				createdCount = Array.isArray(created) ? created.length : 0;
			} catch {
				createdCount = 0;
			}
			const completedTasks = [];
			for (const tid of completedIds.slice(0, 20)) {
				const t = db.prepare("SELECT id, title, status FROM tasks WHERE id = ?").get(tid);
				if (t) completedTasks.push(t);
			}
			let currentTask = null;
			if (s.current_task) {
				const ct = db.prepare("SELECT id, title, status FROM tasks WHERE id = ?").get(s.current_task);
				if (ct) currentTask = ct;
			}
			const workedTasks = workHistoryBySession.get(s.id) ?? [];
			const durationMs = s.started_at && s.ended_at ? new Date(s.ended_at).getTime() - new Date(s.started_at).getTime() : null;
			return {
				id: s.id,
				name: s.name,
				status: s.status,
				agent: s.agent,
				startedAt: s.started_at,
				endedAt: s.ended_at,
				durationMs,
				completedCount: completedIds.length,
				createdCount,
				completedTasks,
				currentTask,
				workedTasks
			};
		}) };
	} catch {
		return { sessions: [] };
	}
};

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

const index = 30;
let component_cache;
const component = async () => component_cache ??= (await import('./_page.svelte-B_pq-Z98.js')).default;
const server_id = "src/routes/tasks/sessions/+page.server.ts";
const imports = ["_app/immutable/nodes/30.DXj0Wm2A.js","_app/immutable/chunks/DyGQ_VXC.js","_app/immutable/chunks/DrKWWDpL.js","_app/immutable/chunks/CQCxd1p9.js","_app/immutable/chunks/wI_OOyoh.js","_app/immutable/chunks/B9psmq5-.js","_app/immutable/chunks/JPJd4fEI.js","_app/immutable/chunks/CEqOYim7.js","_app/immutable/chunks/CqF5Lomf.js"];
const stylesheets = ["_app/immutable/assets/HeroHeader.ByXNeezk.css","_app/immutable/assets/Sparkline.DVOptay1.css","_app/immutable/assets/StatBlock.DX6OXz7z.css","_app/immutable/assets/Tabs.CU9_rsWl.css","_app/immutable/assets/ui.CH-9N9-0.css","_app/immutable/assets/30.hXrXZpmS.css"];
const fonts = [];

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