import { g as getTaskAccessor } from './data-accessor-CVbz8X_7.js';
import { l as listTasks } from './list-DfOyEStk.js';
import { c as computeTaskRollups } from './rollup-DNaP6j6l.js';
import { json } from '@sveltejs/kit';
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 './storage-B9UA3BHR.js';
import './mvi-helpers-BNsJ8ZpQ.js';
import './sqlite-Dsbe0wec.js';
import './chunk-DDP5xfzh.js';
import './dual-scope-db-ATrwq0LH.js';
import './indexes-aYlULWG3.js';
import './utils-BvHPJOVk.js';
import './conduit-Ca_OFWR_.js';
import './unique-constraint-BM-Apx1H.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';

//#region src/routes/api/tasks/pipeline/+server.ts
/**
* Ordered canonical pipeline column IDs. Mirrors the RCASD-IVTR+C chain
* from `@cleocode/core` with terminal display buckets appended.
*
* Kept in string form (no import from core) so the Studio server runtime
* stays free of CLI-only imports — the facade boundary is respected.
*/
var PIPELINE_STAGES = [
	"research",
	"consensus",
	"architecture_decision",
	"specification",
	"decomposition",
	"implementation",
	"validation",
	"testing",
	"release",
	"contribution"
];
/** Project a core `Task` row into the pre-T948 snake_case shape. */
function _toPipelineRow(task) {
	return {
		id: task.id,
		title: task.title,
		status: task.status,
		priority: task.priority,
		type: task.type ?? "task",
		parent_id: task.parentId ?? null,
		pipeline_stage: task.pipelineStage ?? null,
		size: task.size ?? null,
		verification_json: task.verification !== void 0 && task.verification !== null ? JSON.stringify(task.verification) : null,
		acceptance_json: task.acceptance !== void 0 && task.acceptance.length > 0 ? JSON.stringify(task.acceptance) : null,
		created_at: task.createdAt,
		updated_at: task.updatedAt ?? task.createdAt,
		completed_at: task.completedAt ?? null
	};
}
/**
* Decide which stage bucket a task belongs in. Uses the canonical rollup
* `pipelineStage` as the authoritative signal. `null` → 'unassigned', any
* unknown value also falls back to 'unassigned' so new stages introduced by
* core don't crash the Studio UI before the whitelist is updated.
*/
function _resolveStage(rollup) {
	const stage = rollup.pipelineStage;
	if (stage === null) return "unassigned";
	return PIPELINE_STAGES.includes(stage) ? stage : "unassigned";
}
/** Capitalise the first letter of a stage id for a human label. */
function _labelFor(stage) {
	if (stage === "unassigned") return "Unassigned";
	return stage.charAt(0).toUpperCase() + stage.slice(1);
}
var GET = async ({ locals }) => {
	const ctx = locals.projectCtx;
	if (!ctx.tasksDbExists) return json({ error: "tasks.db unavailable" }, { status: 503 });
	try {
		const accessor = await getTaskAccessor(ctx.projectPath);
		const tasks = (await listTasks({
			excludeArchived: true,
			sortByPriority: true,
			limit: 1e3
		}, ctx.projectPath, accessor)).tasks;
		const rollups = await computeTaskRollups(tasks.map((t) => t.id), accessor);
		const rollupById = /* @__PURE__ */ new Map();
		for (const r of rollups) rollupById.set(r.id, r);
		const stageMap = /* @__PURE__ */ new Map();
		for (const s of [...PIPELINE_STAGES, "unassigned"]) stageMap.set(s, {
			tasks: [],
			rollups: []
		});
		for (const task of tasks) {
			const rollup = rollupById.get(task.id);
			if (rollup === void 0) continue;
			const stage = _resolveStage(rollup);
			const bucket = stageMap.get(stage);
			if (bucket === void 0) continue;
			bucket.tasks.push(_toPipelineRow(task));
			bucket.rollups.push(rollup);
		}
		const stages = PIPELINE_STAGES.map((s) => {
			const bucket = stageMap.get(s) ?? {
				tasks: [],
				rollups: []
			};
			return {
				id: s,
				label: _labelFor(s),
				count: bucket.tasks.length,
				tasks: bucket.tasks,
				rollups: bucket.rollups
			};
		});
		const unassigned = stageMap.get("unassigned");
		if (unassigned !== void 0 && unassigned.tasks.length > 0) stages.push({
			id: "unassigned",
			label: "Unassigned",
			count: unassigned.tasks.length,
			tasks: unassigned.tasks,
			rollups: unassigned.rollups
		});
		return json({ stages });
	} catch (err) {
		return json({ error: String(err) }, { status: 500 });
	}
};

export { GET, _labelFor, _resolveStage, _toPipelineRow };
//# sourceMappingURL=_server.ts-EvvZs0u5.js.map
