import { g as getTasksDb } from './connections2-D22b0xbS.js';
import { error } from '@sveltejs/kit';
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { spawnSync } from 'node:child_process';
import './dual-scope-db-ATrwq0LH.js';
import './paths-2M_UxD_H.js';
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: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/[id]/+page.server.ts
/**
* Task detail page server load — single task, subtasks, verification, acceptance,
* notes, MANIFEST artifacts, and linked git commits.
*
* @task T723
*/
/**
* Load manifest entries for a task from the legacy flat-file (migration read-back).
* ADR-027: canonical store is pipeline_manifest in tasks.db, accessed via `cleo manifest` CLI.
*/
function loadManifestEntries(projectPath, taskId) {
	const manifestPath = join(projectPath, ".cleo", "agent-outputs", ["MANIFEST", "jsonl"].join("."));
	if (!existsSync(manifestPath)) return [];
	try {
		const lines = readFileSync(manifestPath, "utf8").split("\n").filter(Boolean);
		const results = [];
		for (const line of lines) try {
			const raw = JSON.parse(line);
			const taskField = String(raw["task"] ?? "");
			const linkedTasks = Array.isArray(raw["linked_tasks"]) ? raw["linked_tasks"] : [];
			const entryId = String(raw["id"] ?? "");
			if (!(taskField === taskId || linkedTasks.includes(taskId) || entryId.startsWith(`${taskId}-`))) continue;
			const files = [];
			if (Array.isArray(raw["files"])) files.push(...raw["files"]);
			if (typeof raw["file"] === "string") files.push(raw["file"]);
			results.push({
				id: entryId,
				task: taskField || taskId,
				type: String(raw["type"] ?? raw["agent_type"] ?? "unknown"),
				status: String(raw["status"] ?? "unknown"),
				date: String(raw["date"] ?? raw["timestamp"] ?? ""),
				title: raw["title"] != null ? String(raw["title"]) : null,
				summary: raw["summary"] != null ? String(raw["summary"]) : null,
				output: raw["output"] != null ? String(raw["output"]) : raw["outputFile"] != null ? String(raw["outputFile"]) : null,
				files,
				linked_tasks: linkedTasks
			});
		} catch {}
		return results;
	} catch {
		return [];
	}
}
/**
* Query git log for commits whose subject line mentions the task ID.
* Returns up to 20 matching commits, each with their changed files.
*/
function loadLinkedCommits(projectPath, taskId) {
	try {
		const result = spawnSync("git", [
			"log",
			"--all",
			"--oneline",
			"--format=%H|%s|%ai",
			`--grep=${taskId}`,
			"-n",
			"20"
		], {
			cwd: projectPath,
			encoding: "utf8",
			timeout: 5e3
		});
		if (result.status !== 0 || !result.stdout?.trim()) return [];
		const commits = [];
		for (const line of result.stdout.trim().split("\n")) {
			const parts = line.split("|");
			if (parts.length < 2) continue;
			const sha = parts[0]?.trim() ?? "";
			const subject = parts[1]?.trim() ?? "";
			const date = parts[2]?.trim() ?? "";
			if (!sha) continue;
			const filesResult = spawnSync("git", [
				"diff-tree",
				"--no-commit-id",
				"-r",
				"--name-only",
				sha
			], {
				cwd: projectPath,
				encoding: "utf8",
				timeout: 3e3
			});
			const files = filesResult.status === 0 ? filesResult.stdout.trim().split("\n").filter(Boolean) : [];
			commits.push({
				sha: sha.slice(0, 8),
				subject,
				date,
				files
			});
		}
		return commits;
	} catch {
		return [];
	}
}
var load = ({ locals, params }) => {
	const db = getTasksDb(locals.projectCtx);
	if (!db) error(503, "tasks.db unavailable");
	const { id } = params;
	const row = db.prepare(`SELECT id, title, description, status, priority, type, parent_id,
              pipeline_stage, size, phase, labels_json, acceptance_json,
              verification_json, notes_json, created_at, updated_at, completed_at,
              assignee, session_id
       FROM tasks WHERE id = ?`).get(id);
	if (!row) error(404, `Task ${id} not found`);
	let verification = null;
	try {
		if (row.verification_json) verification = JSON.parse(row.verification_json);
	} catch {}
	let acceptance = [];
	try {
		if (row.acceptance_json) acceptance = JSON.parse(row.acceptance_json);
	} catch {}
	let labels = [];
	try {
		if (row.labels_json) labels = JSON.parse(row.labels_json);
	} catch {}
	let notes = [];
	try {
		if (row.notes_json) notes = JSON.parse(row.notes_json);
	} catch {}
	const task = {
		id: row.id,
		title: row.title,
		description: row.description,
		status: row.status,
		priority: row.priority,
		type: row.type,
		parent_id: row.parent_id,
		pipeline_stage: row.pipeline_stage,
		size: row.size,
		phase: row.phase,
		created_at: row.created_at,
		updated_at: row.updated_at,
		completed_at: row.completed_at,
		assignee: row.assignee,
		session_id: row.session_id,
		verification,
		acceptance,
		labels,
		notes,
		upstream: [],
		downstream: []
	};
	const subtasks = db.prepare(`SELECT id, title, status, priority, type, pipeline_stage, size,
              verification_json, acceptance_json, created_at, completed_at
       FROM tasks WHERE parent_id = ?
       ORDER BY position ASC, created_at ASC`).all(id);
	const upstream = db.prepare(`SELECT t.id, t.title, t.status, t.priority
       FROM tasks t
       INNER JOIN task_dependencies td ON td.depends_on = t.id
       WHERE td.task_id = ?
       ORDER BY t.id ASC`).all(id);
	const downstream = db.prepare(`SELECT t.id, t.title, t.status, t.priority
       FROM tasks t
       INNER JOIN task_dependencies td ON td.task_id = t.id
       WHERE td.depends_on = ?
       ORDER BY t.id ASC`).all(id);
	task.upstream = upstream;
	task.downstream = downstream;
	let parent = null;
	if (row.parent_id) parent = db.prepare("SELECT id, title, type FROM tasks WHERE id = ?").get(row.parent_id) ?? null;
	const projectPath = locals.projectCtx.projectPath;
	const manifestEntries = loadManifestEntries(projectPath, id);
	const linkedCommits = loadLinkedCommits(projectPath, id);
	return {
		task,
		subtasks,
		parent,
		manifestEntries,
		linkedCommits
	};
};

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

const index = 26;
let component_cache;
const component = async () => component_cache ??= (await import('./_page.svelte-DUs_3y9B.js')).default;
const server_id = "src/routes/tasks/[id]/+page.server.ts";
const imports = ["_app/immutable/nodes/26.BaIQ6VHk.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/BgPpRtmk.js","_app/immutable/chunks/BrUKpZTl.js","_app/immutable/chunks/DsQIgu-4.js","_app/immutable/chunks/Bcuvp8aL.js","_app/immutable/chunks/DnOaYask.js","_app/immutable/chunks/Cjus22ap.js","_app/immutable/chunks/DOqzs8kl2.js","_app/immutable/chunks/DTkg6Mnx.js","_app/immutable/chunks/DIQmuJJZ.js","_app/immutable/chunks/D7w7HllH.js","_app/immutable/chunks/DB5ifLM-.js","_app/immutable/chunks/CxlOpib82.js","_app/immutable/chunks/BKc98lKx.js","_app/immutable/chunks/DsanjglN.js","_app/immutable/chunks/CbGRcr-D.js","_app/immutable/chunks/CX8DOZuw2.js","_app/immutable/chunks/djL6V-tr.js","_app/immutable/chunks/CQCxd1p9.js","_app/immutable/chunks/JPJd4fEI.js","_app/immutable/chunks/RptFUp2P.js","_app/immutable/chunks/CEqOYim7.js","_app/immutable/chunks/CqF5Lomf.js","_app/immutable/chunks/wI_OOyoh.js"];
const stylesheets = ["_app/immutable/assets/StatBlock.DX6OXz7z.css","_app/immutable/assets/no-face-up.BlswZ73M.css","_app/immutable/assets/Tabs.CU9_rsWl.css","_app/immutable/assets/ui.CH-9N9-0.css","_app/immutable/assets/tasks.BZWJL4jq.css","_app/immutable/assets/HeroHeader.ByXNeezk.css","_app/immutable/assets/26.Bc1bH1ab.css"];
const fonts = [];

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