import { a as getBrainDb } from './connections2-D22b0xbS.js';
import { p as parseJsonBody, i as isParseError, e as err, r as requireString, o as ok } from './_lafs-C3_fBF_X.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';

//#region src/routes/api/memory/verify/+server.ts
/**
* Memory verify write endpoint (T990 Wave 1D).
*
* @remarks T9616 follow-up: There is no public `verifyMemoryEntry` operation
* in the CORE public API (`packages/core/src/memory/public-api.ts`). The CLI
* `cleo memory verify` command reaches into `memory/brain-retrieval.ts`
* internally. Once a public `verifyMemoryEntry(id, projectRoot)` op is
* promoted, this handler should be migrated. See docs/plans/E-CORE-FIRST-ARCH.md Task 2.
*
* POST /api/memory/verify
*   body: { id: string, agent?: string }
*   → LAFS envelope { success, data: { id, table, verified, promotedAt } }
*
* Flips the `verified` flag on the target memory entry to 1, and
* records the verification timestamp. Routes the update to the correct
* brain_* table via the id prefix:
*   - O- → brain_observations
*   - D- → brain_decisions
*   - P- → brain_patterns
*   - L- → brain_learnings
*
* Ground-truth promotion is owner/cleo-prime only; this endpoint
* inherits the Studio's localhost-only auth posture and does NOT
* emit an audit event yet (T990 Wave 1D is UI-only — the core audit
* trail lives in the CLI `cleo memory verify` op).
*
* @task T990
* @wave 1D
*/
/** Route id-prefix → table. */
function tableFromId(id) {
	if (id.startsWith("O-")) return "brain_observations";
	if (id.startsWith("D-")) return "brain_decisions";
	if (id.startsWith("P-")) return "brain_patterns";
	if (id.startsWith("L-")) return "brain_learnings";
	return null;
}
var POST = async ({ locals, request }) => {
	const body = await parseJsonBody(request);
	if (isParseError(body)) return json(err("E_VALIDATION", body._parseError), { status: 400 });
	const idR = requireString(body, "id", 80);
	if (!idR.ok) return json(err("E_VALIDATION", idR.message), { status: 400 });
	const table = tableFromId(idR.value);
	if (!table) return json(err("E_VALIDATION", "Unknown id prefix — must be O- / D- / P- / L-"), { status: 400 });
	const db = getBrainDb(locals.projectCtx);
	if (!db) return json(err("E_BRAIN_UNAVAILABLE", "brain.db is unavailable for this project"), { status: 503 });
	try {
		if (!db.prepare(`SELECT id FROM ${table} WHERE id = ?`).get(idR.value)) return json(err("E_NOT_FOUND", `No ${table} row with id ${idR.value}`), { status: 404 });
		db.prepare(`UPDATE ${table} SET verified = 1 WHERE id = ?`).run(idR.value);
		const promotedAt = (/* @__PURE__ */ new Date()).toISOString();
		return json(ok({
			id: idR.value,
			table,
			verified: 1,
			promotedAt
		}));
	} catch (e) {
		return json(err("E_BRAIN_WRITE", e instanceof Error ? e.message : "Update failed"), { status: 500 });
	}
};

export { POST };
//# sourceMappingURL=_server.ts-BM9WRI5D.js.map
