import { M as MANIFEST_STATUSES, G as GATE_STATUSES, A as ADR_STATUSES } from './paths-2M_UxD_H.js';
import { A as ATTACHMENT_OWNER_TYPES, j as ATTACHMENT_LIFECYCLE_STATUSES, k as AGENT_INSTANCE_STATUSES, l as AGENT_TYPES, T as TOKEN_USAGE_CONFIDENCE, m as TOKEN_USAGE_METHODS, n as TOKEN_USAGE_TRANSPORTS, W as WARP_CHAIN_INSTANCE_STATUSES } from './conduit-Ca_OFWR_.js';
export { B as BRAIN_RELEASE_LINK_TYPES_CONSOLIDATED, L as LIFECYCLE_VALIDATION_STATUSES, o as TASK_AC_KINDS, p as conduitAttachmentApprovals, q as conduitAttachmentContributors, r as conduitAttachmentVersions, u as conduitAttachments, v as conduitConversations, w as conduitDeadLetters, x as conduitDeliveryJobs, y as conduitMessagePins, z as conduitMessages, C as conduitProjectAgentRefs, D as conduitTopicMessageAcks, E as conduitTopicMessages, F as conduitTopicSubscriptions, G as conduitTopics, H as tasksAcceptanceProjectionDirty, I as tasksAcceptanceProjectionState, J as tasksAgentCredentials, K as tasksBackgroundJobs, M as tasksBrainReleaseLinks, N as tasksCommitFiles, O as tasksCommits, f as tasksEvidenceAcBindings, P as tasksExperiments, Q as tasksExternalTaskLinks, R as tasksLifecycleEvidence, S as tasksLifecycleGateResults, U as tasksLifecyclePipelines, V as tasksLifecycleStages, X as tasksLifecycleTransitions, Y as tasksPrCommits, Z as tasksPrTasks, _ as tasksPullRequests, $ as tasksReleaseArtifacts, a0 as tasksReleaseChanges, a1 as tasksReleaseChangesets, a2 as tasksReleaseCommits, a3 as tasksReleases, a4 as tasksSessionHandoffEntries, t as tasksSessions, h as tasksTaskAcceptanceCriteria, g as tasksTaskAcceptanceCriteriaHistory, a5 as tasksTaskCommits, d as tasksTaskDependencies, e as tasksTaskLabels, i as tasksTaskRelations, a6 as tasksTaskWorkHistory, c as tasksTasks } from './conduit-Ca_OFWR_.js';
import { m as makeSchemaMetaTable } from './memory-schema-Bi7cChwo.js';
export { B as BRAIN_BACKFILL_KINDS, a as BRAIN_DECISION_CONFIRMATION_STATES, b as BRAIN_DECISION_DECIDED_BY, c as BRAIN_EDGE_PLASTICITY_CLASSES, d as BRAIN_PLASTICITY_KINDS, e as BRAIN_STAGING_ACTIONS, f as BRAIN_STAGING_VALIDATION_STATUSES, g as BRAIN_TRANSCRIPT_ROLES, h as brainAttention, i as brainBackfillRuns, j as brainConsolidationEvents, k as brainDecisions, l as brainDeriverQueue, m as brainLearnings, n as brainMemoryColumns, o as brainMemoryLinks, p as brainMemoryTrees, q as brainModulators, r as brainObservations, s as brainObservationsStaging, t as brainPageEdges, u as brainPageNodes, v as brainPatterns, w as brainPlasticityEvents, x as brainPromotionLog, y as brainRetrievalLog, z as brainSchemaMeta, A as brainSessionNarrative, C as brainStickyNotes, D as brainStickyTags, E as brainTranscriptEvents, F as brainUsageLog, G as brainWeightHistory } from './cleo-shared-CG3TSIBu.js';
import { s as sqliteTable, t as text, a as index, i as integer, r as real } from './indexes-aYlULWG3.js';
import { p as primaryKey, u as unique } from './unique-constraint-BM-Apx1H.js';
import { s as sql } from './utils-BvHPJOVk.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 './chunk-DDP5xfzh.js';

//#region ../core/dist/store/schema/cleo-project/audit.js
/**
* Project-scope `cleo.db` — consolidated **audit / governance** domain (6 tables
* + schema_meta).
*
* Part of the consolidated PROJECT-scope `cleo.db` target shape authored for
* SG-DB-SUBSTRATE-V2 (saga T11242, epic T11245/E2, task T11360). Target-shape
* authoring only — physical names carry the `tasks_` domain prefix. The live
* runtime module `schema/audit.ts` keeps its UNPREFIXED names until the exodus
* migration (T11248) swaps the substrate.
*
* Tables: tasks_schema_meta · tasks_audit_log · tasks_token_usage ·
* tasks_architecture_decisions · tasks_adr_task_links · tasks_adr_relations ·
* tasks_status_registry.
*
* ## E10 typing (already conformant — preserved)
*
* - **§4 timestamps:** all canonical TEXT ISO8601 (no epoch non-conformers).
* - **§3 booleans:** `status_registry.is_terminal` already `integer({ mode:
*   'boolean' })` — preserved.
* - **§5 enums:** all already `{ enum }`-narrowed (token_usage method/
*   confidence/transport, ADR status/gate_status, link/relation/entity/
*   namespace types). Inline-literal enums (`gate`, `adr_task_links.link_type`,
*   `adr_relations.relation_type`, `status_registry.entity_type`/`namespace`)
*   are promoted to named const arrays here (§5a — identifier over literal).
* - **§7 idempotency:** `audit_log.idempotency_key` is the CANONICAL model the
*   report cites (§7) — preserved. T11362 promotes its
*   `(project_hash, domain, operation, idempotency_key)` composite to a true
*   UNIQUE constraint (the dedup grain — the same key recurs across distinct
*   domain/operation tuples, so the bare key is NOT unique).
* - **§6a JSON:** `details_json` / `before_json` / `after_json` /
*   `metadata_json` stay serialized TEXT per the JSON-Column Audit.
*
* Cross-table FKs into `tasks_tasks` / `tasks_sessions` / `docs_manifest_entries`
* are carried as plain TEXT id columns (resolved by the exodus prefixer);
* intra-table self-FKs (ADR supersedes/amends) are real `.references()`.
*
* @task T11360 · T11362 (§7 idempotency UNIQUE)
* @epic T11245
* @saga T11242
* @see docs/migration/sqlite-schema-canonical.md §3 · §4 · §5 · §6a · §7
* @see docs/migration/sqlite-schema-columns.json (per-column affinity SSoT)
*/
/** ADR governance-gate kinds — promoted from inline literal (§5a). */
var ADR_GATE_KINDS = ["HITL", "automated"];
/** ADR↔task link types — promoted from inline literal (§5a). */
var ADR_TASK_LINK_TYPES = [
	"related",
	"governed_by",
	"implements"
];
/** ADR↔ADR relation types — promoted from inline literal (§5a). */
var ADR_RELATION_TYPES = [
	"supersedes",
	"amends",
	"related"
];
/** Status-registry entity types — promoted from inline literal (§5a). */
var STATUS_REGISTRY_ENTITY_TYPES = [
	"task",
	"session",
	"lifecycle_pipeline",
	"lifecycle_stage",
	"adr",
	"gate",
	"manifest"
];
/** Status-registry namespaces — promoted from inline literal (§5a). */
var STATUS_REGISTRY_NAMESPACES = [
	"workflow",
	"governance",
	"manifest"
];
/**
* `tasks_schema_meta` — key-value schema-version store.
*
* @task T11360 (target shape)
*/
var tasksSchemaMeta = makeSchemaMetaTable("tasks_schema_meta");
/**
* `tasks_audit_log` — task-change audit log. No FK on task_id (entries outlive
* task deletion). `idempotency_key` is the §7 canonical retry-dedup model.
*
* @task T11360 (target shape) · T4837 (original)
*/
var tasksAuditLog = sqliteTable("tasks_audit_log", {
	id: text("id").primaryKey(),
	timestamp: text("timestamp").notNull().default(sql`(datetime('now'))`),
	action: text("action").notNull(),
	taskId: text("task_id").notNull(),
	actor: text("actor").notNull().default("system"),
	detailsJson: text("details_json").default("{}"),
	beforeJson: text("before_json"),
	afterJson: text("after_json"),
	domain: text("domain"),
	operation: text("operation"),
	sessionId: text("session_id"),
	requestId: text("request_id"),
	idempotencyKey: text("idempotency_key"),
	durationMs: integer("duration_ms"),
	success: integer("success"),
	source: text("source"),
	gateway: text("gateway"),
	errorMessage: text("error_message"),
	projectHash: text("project_hash")
}, (table) => [
	index("idx_tasks_audit_log_task_id").on(table.taskId),
	index("idx_tasks_audit_log_action").on(table.action),
	index("idx_tasks_audit_log_timestamp").on(table.timestamp),
	index("idx_tasks_audit_log_domain").on(table.domain),
	index("idx_tasks_audit_log_request_id").on(table.requestId),
	index("idx_tasks_audit_log_idempotency_key").on(table.idempotencyKey),
	index("idx_tasks_audit_log_project_hash").on(table.projectHash),
	index("idx_tasks_audit_log_actor").on(table.actor),
	index("idx_tasks_audit_log_session_timestamp").on(table.sessionId, table.timestamp),
	index("idx_tasks_audit_log_domain_operation").on(table.domain, table.operation),
	unique("uq_tasks_audit_log_idempotency_lookup").on(table.projectHash, table.domain, table.operation, table.idempotencyKey)
]);
/**
* `tasks_token_usage` — provider-aware token telemetry.
*
* @task T11360 (target shape)
*/
var tasksTokenUsage = sqliteTable("tasks_token_usage", {
	id: text("id").primaryKey(),
	createdAt: text("created_at").notNull().default(sql`(datetime('now'))`),
	provider: text("provider").notNull().default("unknown"),
	model: text("model"),
	transport: text("transport", { enum: TOKEN_USAGE_TRANSPORTS }).notNull().default("unknown"),
	gateway: text("gateway"),
	domain: text("domain"),
	operation: text("operation"),
	sessionId: text("session_id"),
	taskId: text("task_id"),
	requestId: text("request_id"),
	inputChars: integer("input_chars").notNull().default(0),
	outputChars: integer("output_chars").notNull().default(0),
	inputTokens: integer("input_tokens").notNull().default(0),
	outputTokens: integer("output_tokens").notNull().default(0),
	totalTokens: integer("total_tokens").notNull().default(0),
	method: text("method", { enum: TOKEN_USAGE_METHODS }).notNull().default("heuristic"),
	confidence: text("confidence", { enum: TOKEN_USAGE_CONFIDENCE }).notNull().default("coarse"),
	requestHash: text("request_hash"),
	responseHash: text("response_hash"),
	metadataJson: text("metadata_json").notNull().default("{}")
}, (table) => [
	index("idx_tasks_token_usage_created_at").on(table.createdAt),
	index("idx_tasks_token_usage_request_id").on(table.requestId),
	index("idx_tasks_token_usage_session_id").on(table.sessionId),
	index("idx_tasks_token_usage_task_id").on(table.taskId),
	index("idx_tasks_token_usage_provider").on(table.provider),
	index("idx_tasks_token_usage_transport").on(table.transport),
	index("idx_tasks_token_usage_domain_operation").on(table.domain, table.operation),
	index("idx_tasks_token_usage_method").on(table.method),
	index("idx_tasks_token_usage_gateway").on(table.gateway)
]);
/**
* `tasks_architecture_decisions` — DB-backed ADR records.
*
* @task T11360 (target shape)
*/
var tasksArchitectureDecisions = sqliteTable("tasks_architecture_decisions", {
	id: text("id").primaryKey(),
	title: text("title").notNull(),
	status: text("status", { enum: ADR_STATUSES }).notNull().default("proposed"),
	supersedesId: text("supersedes_id").references(() => tasksArchitectureDecisions.id, { onDelete: "set null" }),
	supersededById: text("superseded_by_id").references(() => tasksArchitectureDecisions.id, { onDelete: "set null" }),
	consensusManifestId: text("consensus_manifest_id"),
	content: text("content").notNull(),
	createdAt: text("created_at").notNull().default(sql`(datetime('now'))`),
	updatedAt: text("updated_at"),
	date: text("date").notNull().default(""),
	acceptedAt: text("accepted_at"),
	gate: text("gate", { enum: ADR_GATE_KINDS }),
	gateStatus: text("gate_status", { enum: GATE_STATUSES }),
	amendsId: text("amends_id").references(() => tasksArchitectureDecisions.id, { onDelete: "set null" }),
	filePath: text("file_path").notNull().default(""),
	summary: text("summary"),
	keywords: text("keywords"),
	topics: text("topics")
}, (table) => [index("idx_tasks_architecture_decisions_status").on(table.status), index("idx_tasks_architecture_decisions_amends_id").on(table.amendsId)]);
/**
* `tasks_adr_task_links` — ADR↔task junction.
*
* @task T11360 (target shape)
*/
var tasksAdrTaskLinks = sqliteTable("tasks_adr_task_links", {
	adrId: text("adr_id").notNull().references(() => tasksArchitectureDecisions.id, { onDelete: "cascade" }),
	taskId: text("task_id").notNull(),
	linkType: text("link_type", { enum: ADR_TASK_LINK_TYPES }).notNull().default("related")
}, (table) => [primaryKey({ columns: [table.adrId, table.taskId] }), index("idx_tasks_adr_task_links_task_id").on(table.taskId)]);
/**
* `tasks_adr_relations` — ADR↔ADR cross-reference junction.
*
* @task T11360 (target shape)
*/
var tasksAdrRelations = sqliteTable("tasks_adr_relations", {
	fromAdrId: text("from_adr_id").notNull().references(() => tasksArchitectureDecisions.id, { onDelete: "cascade" }),
	toAdrId: text("to_adr_id").notNull().references(() => tasksArchitectureDecisions.id, { onDelete: "cascade" }),
	relationType: text("relation_type", { enum: ADR_RELATION_TYPES }).notNull()
}, (table) => [primaryKey({ columns: [
	table.fromAdrId,
	table.toAdrId,
	table.relationType
] })]);
/**
* `tasks_status_registry` — canonical status registry (ADR-018).
*
* @task T11360 (target shape)
*/
var tasksStatusRegistry = sqliteTable("tasks_status_registry", {
	name: text("name").notNull(),
	entityType: text("entity_type", { enum: STATUS_REGISTRY_ENTITY_TYPES }).notNull(),
	namespace: text("namespace", { enum: STATUS_REGISTRY_NAMESPACES }).notNull(),
	description: text("description").notNull(),
	isTerminal: integer("is_terminal", { mode: "boolean" }).notNull().default(false)
}, (table) => [
	primaryKey({ columns: [table.name, table.entityType] }),
	index("idx_tasks_status_registry_entity_type").on(table.entityType),
	index("idx_tasks_status_registry_namespace").on(table.namespace)
]);
//#endregion
//#region ../core/dist/store/schema/cleo-project/docs.js
/**
* Project-scope `cleo.db` — consolidated **docs** domain (D11 collapse).
*
* Part of the consolidated PROJECT-scope `cleo.db` target shape authored for
* SG-DB-SUBSTRATE-V2 (saga T11242, epic T11245/E2, task T11360). This module is
* **target-shape authoring only** — it carries the domain-prefixed Pattern-A
* physical table names and the E10 strict typing the exodus migration
* (T11248) will deploy. The live runtime modules under
* `packages/core/src/store/schema/{attachments,manifest}.ts` keep their
* UNPREFIXED physical names until exodus swaps the substrate; do not point
* runtime accessors at this module.
*
* ## D11 — the docs collapse (AC3)
*
* The legacy `attachments` / `attachment_refs` (attachment store) and
* `manifest_entries` / `pipeline_manifest` (RCASD provenance manifest) table
* families collapse into ONE `docs_*` schema. There is no separate
* `attachments_*` or `llmtxt_*` family in the consolidated substrate — every
* document-bearing table lives under the `docs_` prefix:
*
*   - `docs_attachments`        ← `attachments`
*   - `docs_attachment_refs`    ← `attachment_refs`
*   - `docs_manifest_entries`   ← `manifest_entries`
*   - `docs_pipeline_manifest`  ← `pipeline_manifest`
*
* ## E10 typing applied (per docs/migration/sqlite-schema-canonical.md)
*
* - **§3b boolean non-conformer:** `pipeline_manifest.distilled` was already
*   `integer({ mode: 'boolean' })` — preserved.
* - **§4 timestamps:** every timestamp column is the canonical TEXT ISO8601
*   form (`datetime('now')`); none were epoch non-conformers in this domain.
* - **§5 enum-like bare TEXT:** `manifest_entries.status` already carries
*   `{ enum: MANIFEST_STATUSES }` (kept). `attachments.type` and
*   `pipeline_manifest.{type,status}` are §5b non-conformers whose legal value
*   set is **writer-derived / open taxonomy** (attachment `type` is a free
*   doc-kind tag validated at the dispatch layer; pipeline `type` is mapped
*   from phase-directory names and pipeline `status` is written dynamically).
*   Per §8.3 + the `attachments.ts` precedent (dispatch-layer validation so new
*   taxonomy needs no migration) these remain documented bare TEXT — the CHECK
*   list cannot be hand-frozen without rejecting valid writes. Flagged for the
*   exodus writer audit (T11248) rather than guessed here.
* - **§6a JSON-in-TEXT (AC4):** JSON columns use the existing E4 `jsonb<T>()`
*   pattern from `../jsonb.js` for the columns the JSON-Column Audit routes to
*   JSONB, and remain serialized TEXT (with a documented read rule) for the
*   columns that audit keeps as TEXT. No new JSON pattern is invented.
*
* @task T11360
* @epic T11245
* @saga T11242
* @see docs/migration/sqlite-schema-canonical.md §1 (D1″) · §3b · §5 · §6a
* @see docs/migration/sqlite-schema-columns.json (per-column affinity SSoT)
*/
/**
* `docs_attachments` — content-addressed registry of stored documents/blobs.
*
* Domain-prefixed target of the legacy `attachments` table (D11 collapse).
*
* @task T11360 (target shape) · T796 (original)
*/
var docsAttachments = sqliteTable("docs_attachments", {
	id: text("id").primaryKey(),
	sha256: text("sha256").notNull().unique(),
	attachmentJson: text("attachment_json").notNull(),
	createdAt: text("created_at").notNull().default(sql`(datetime('now'))`),
	refCount: integer("ref_count").notNull().default(0),
	slug: text("slug"),
	type: text("type"),
	lifecycleStatus: text("lifecycle_status", { enum: ATTACHMENT_LIFECYCLE_STATUSES }).notNull().default("draft"),
	supersedes: text("supersedes").references(() => docsAttachments.id),
	supersededBy: text("superseded_by").references(() => docsAttachments.id),
	summary: text("summary"),
	keywords: text("keywords"),
	topics: text("topics"),
	relatedTasks: text("related_tasks"),
	ownerVersion: text("owner_version"),
	docVersion: integer("doc_version").notNull().default(1)
}, (table) => [
	index("idx_docs_attachments_sha256").on(table.sha256),
	index("idx_docs_attachments_lifecycle_status").on(table.lifecycleStatus),
	index("idx_docs_attachments_supersedes").on(table.supersedes)
]);
/**
* `docs_attachment_refs` — ref-counted junction linking attachments to owners.
*
* Domain-prefixed target of the legacy `attachment_refs` table (D11 collapse).
*
* @task T11360 (target shape) · T796 (original)
*/
var docsAttachmentRefs = sqliteTable("docs_attachment_refs", {
	attachmentId: text("attachment_id").notNull(),
	ownerType: text("owner_type", { enum: ATTACHMENT_OWNER_TYPES }).notNull(),
	ownerId: text("owner_id").notNull(),
	attachedAt: text("attached_at").notNull(),
	attachedBy: text("attached_by")
}, (table) => [
	primaryKey({ columns: [
		table.attachmentId,
		table.ownerType,
		table.ownerId
	] }),
	index("idx_docs_attachment_refs_attachment_id").on(table.attachmentId),
	index("idx_docs_attachment_refs_owner").on(table.ownerType, table.ownerId)
]);
/**
* `docs_manifest_entries` — RCASD provenance manifest rows.
*
* Domain-prefixed target of the legacy `manifest_entries` table (D11 collapse).
* Cross-domain FKs (`pipeline_id`, `stage_id` → lifecycle tables) are resolved
* by the exodus prefixer against the consolidated single-file schema; this
* target module carries them as plain TEXT id columns (no in-module FK to the
* live lifecycle module, which keeps unprefixed names).
*
* @task T11360 (target shape) · T5100 (original)
*/
var docsManifestEntries = sqliteTable("docs_manifest_entries", {
	id: text("id").primaryKey(),
	pipelineId: text("pipeline_id"),
	stageId: text("stage_id"),
	title: text("title").notNull(),
	date: text("date").notNull(),
	status: text("status", { enum: MANIFEST_STATUSES }).notNull(),
	agentType: text("agent_type"),
	outputFile: text("output_file"),
	topicsJson: text("topics_json").default("[]"),
	findingsJson: text("findings_json").default("[]"),
	linkedTasksJson: text("linked_tasks_json").default("[]"),
	createdBy: text("created_by"),
	createdAt: text("created_at").notNull().default(sql`(datetime('now'))`)
}, (table) => [
	index("idx_docs_manifest_entries_pipeline_id").on(table.pipelineId),
	index("idx_docs_manifest_entries_stage_id").on(table.stageId),
	index("idx_docs_manifest_entries_status").on(table.status)
]);
/**
* `docs_pipeline_manifest` — distilled pipeline manifest (memory ingestion).
*
* Domain-prefixed target of the legacy `pipeline_manifest` table (D11 collapse).
* `session_id` / `task_id` / `epic_id` are cross-domain FKs into the
* `tasks_*` family resolved by the exodus prefixer; carried here as TEXT id
* columns.
*
* @task T11360 (target shape) · T5581 (original)
*/
var docsPipelineManifest = sqliteTable("docs_pipeline_manifest", {
	id: text("id").primaryKey(),
	sessionId: text("session_id"),
	taskId: text("task_id"),
	epicId: text("epic_id"),
	type: text("type").notNull(),
	content: text("content").notNull(),
	contentHash: text("content_hash"),
	status: text("status").notNull().default("active"),
	distilled: integer("distilled", { mode: "boolean" }).notNull().default(false),
	brainObsId: text("brain_obs_id"),
	sourceFile: text("source_file"),
	metadataJson: text("metadata_json"),
	createdAt: text("created_at").notNull().default(sql`(datetime('now'))`),
	archivedAt: text("archived_at")
}, (table) => [
	index("idx_docs_pipeline_manifest_task_id").on(table.taskId),
	index("idx_docs_pipeline_manifest_session_id").on(table.sessionId),
	index("idx_docs_pipeline_manifest_distilled").on(table.distilled),
	index("idx_docs_pipeline_manifest_status").on(table.status),
	index("idx_docs_pipeline_manifest_content_hash").on(table.contentHash)
]);
//#endregion
//#region ../core/dist/store/schema/cleo-project/nexus-graph.js
/**
* Project-scope `cleo.db` — consolidated **nexus code-graph** domain (4 tables).
*
* ## Residency move (ADR-090 · T11538 — residency step 1)
*
* The four per-project code/knowledge-graph tables — `nexus_nodes`,
* `nexus_relations`, `nexus_contracts`, `nexus_code_index` (ADR-090 "Category A")
* — wrongly lived in the GLOBAL-scope `cleo.db` (`../cleo-global/nexus.ts`),
* each carrying a redundant `project_id text NOT NULL` soft FK to
* `nexus_project_registry`. Per ADR-090 §2.1 they MUST reside in the consolidated
* PROJECT-scope `cleo.db` (`<projectRoot>/.cleo/cleo.db`) so that `.cleo/`
* becomes the complete portable living brain (tasks + memory + conduit + docs +
* code-graph).
*
* This module authors that **target shape** for the PROJECT scope. It is
* purely ADDITIVE: it DEFINES the four tables (minus `project_id`) so the
* type-checker and the project-scope schema barrel see them. It does NOT yet
* remove the global copies, move data, or rewire the live accessor — those are:
*   - T11539: remove the four tables from `cleo-global/nexus.ts` + the
*     extract-by-project data move (nexus global table count 10 → 6).
*   - T11545: partition the Hebbian plasticity columns out of `nexus_relations`
*     into the sibling `nexus_relation_weights` table (ADR-090 §5.3). That table
*     also belongs in THIS module and MUST land with the move, not after — until
*     then the plasticity columns (`weight`, `last_accessed_at`,
*     `co_accessed_count`) stay inline on `nexus_relations` as they are in the
*     global source.
*
* ## `project_id` DROPPED (ADR-090 §2.1)
*
* The `project_id` column is REMOVED from all four tables — scope is now
* implicit in which project's `.cleo/cleo.db` is open. Consequently every
* `idx_*_project*` index that LED with `project_id` is dropped or collapsed:
*   - `idx_nexus_nodes_project` → dropped.
*   - `idx_nexus_nodes_project_kind(project_id, kind)` → collapses to the
*     already-present `idx_nexus_nodes_kind(kind)`.
*   - `idx_nexus_nodes_project_file(project_id, file_path)` → collapses to the
*     already-present `idx_nexus_nodes_file(file_path)`.
*   - `idx_nexus_relations_project` → dropped;
*     `idx_nexus_relations_project_type(project_id, type)` → collapses to
*     `idx_nexus_relations_type(type)`.
*   - `idx_nexus_contracts_project` → dropped;
*     `idx_nexus_contracts_project_type(project_id, type)` → collapses to
*     `idx_nexus_contracts_type(type)`.
*   - `idx_nexus_code_index_project` → dropped.
* Every other column, index, and intra-graph soft FK is preserved BYTE-FOR-BYTE
* from the global source.
*
* ## FK reconciliation — intra-scope soft FKs preserved (ADR-090 §2.1)
*
* All graph references are intra-scope (within the same project DB) and stay
* plain `text` soft FKs exactly as in the global source — the graph stores
* unresolved external module specifiers in the same columns, so they were never
* enforced FKs:
*   - `nexus_relations.{source_id,target_id}` → `nexus_nodes.id`.
*   - `nexus_nodes.{parent_id,community_id}` → `nexus_nodes.id`.
*   - `nexus_contracts.{source_symbol_id,route_node_id}` → `nexus_nodes.id`.
* Post-split these tables hold NO machine-specific absolute paths and NO
* cross-scope refs, so they are move-safe (ADR-090 §4 portability).
*
* ## E10 typing — inherited unchanged from the global source
*
* The enum const arrays ({@link NEXUS_NODE_KINDS}, {@link NEXUS_RELATION_TYPES},
* {@link NEXUS_CONTRACT_TYPES}, {@link CODE_INDEX_KINDS}) and typed booleans
* (`is_exported`, `is_external`, `exported` with `{ mode: 'boolean' }`) are
* re-minted here verbatim to keep this scope module self-contained, mirroring
* how `../cleo-global/nexus.ts` mints them in-module (no cross-package
* contracts SSoT exists for these). The two barrels live in DISJOINT Drizzle
* namespaces (`CleoProjectSchemaTypes` vs `CleoGlobalSchemaTypes` in
* `store/dual-scope-db.ts`), so the duplicated identifiers never collide.
*
* @task T11538
* @epic T11535
* @saga T11242
* @see ../cleo-global/nexus.ts (the GLOBAL source these four tables move OUT of)
* @see docs/migration/sqlite-schema-canonical.md §4 · §5b
* @see cleo docs fetch adr-090-nexus-graph-residency-split
*/
/**
* All node kind values — matches `GraphNodeKind` in `@cleocode/contracts`.
* Kept as a const tuple for the Drizzle enum column. Ordering intentional:
* structural → module → callable → type → value-level → language-specific →
* graph-level → legacy.
*
* @task T11538 (project-scope target shape) · T529 (original)
*/
var NEXUS_NODE_KINDS = [
	"file",
	"folder",
	"module",
	"namespace",
	"function",
	"method",
	"constructor",
	"class",
	"interface",
	"struct",
	"trait",
	"impl",
	"type_alias",
	"enum",
	"property",
	"constant",
	"variable",
	"static",
	"record",
	"delegate",
	"macro",
	"union",
	"typedef",
	"annotation",
	"template",
	"community",
	"process",
	"route",
	"tool",
	"section",
	"import",
	"export",
	"type"
];
/**
* All relation type values — matches `GraphRelationType` in `@cleocode/contracts`.
*
* @task T11538 (project-scope target shape) · T529 (original)
*/
var NEXUS_RELATION_TYPES = [
	"contains",
	"defines",
	"imports",
	"accesses",
	"calls",
	"extends",
	"implements",
	"method_overrides",
	"method_implements",
	"has_method",
	"has_property",
	"member_of",
	"step_in_process",
	"handles_route",
	"fetches",
	"handles_tool",
	"entry_point_of",
	"wraps",
	"queries",
	"documents",
	"applies_to",
	"co_changed",
	"co_cited_in_task"
];
/**
* All contract type values for cross-project API extraction.
*
* @task T11538 (project-scope target shape) · T1065 (original)
*/
var NEXUS_CONTRACT_TYPES = [
	"http",
	"grpc",
	"topic"
];
/**
* Legal `nexus_code_index.kind` values — tree-sitter symbol capture kinds.
*
* E10 §5b: `code_index.kind` was bare `text('kind')`. The legal set is the
* symbol-kind taxonomy documented on the source column (the tree-sitter capture
* groups): structural / module / callable / type-hierarchy / value-level
* constructs. Kept as an in-module const so the exodus CHECK derives from this
* identifier rather than a hand-typed literal.
*
* @task T11538 (project-scope target shape) · T11361 (global source)
*/
var CODE_INDEX_KINDS = [
	"function",
	"method",
	"class",
	"interface",
	"type",
	"enum",
	"variable",
	"constant",
	"module",
	"import",
	"export",
	"struct",
	"trait",
	"impl"
];
/**
* `nexus_nodes` — one row per symbol or structural element in the code
* intelligence graph. PROJECT-scope: `project_id` dropped (ADR-090 §2.1) —
* scope is implicit in the owning `.cleo/cleo.db`.
*
* @task T11538 (project-scope target shape) · T11361 (global source) · T529 (original)
*/
var nexusNodes = sqliteTable("nexus_nodes", {
	id: text("id").primaryKey(),
	kind: text("kind", { enum: NEXUS_NODE_KINDS }).notNull(),
	label: text("label").notNull(),
	name: text("name"),
	filePath: text("file_path"),
	startLine: integer("start_line"),
	endLine: integer("end_line"),
	language: text("language"),
	isExported: integer("is_exported", { mode: "boolean" }).notNull().default(false),
	parentId: text("parent_id"),
	parametersJson: text("parameters_json"),
	returnType: text("return_type"),
	docSummary: text("doc_summary"),
	communityId: text("community_id"),
	metaJson: text("meta_json"),
	isExternal: integer("is_external", { mode: "boolean" }).notNull().default(false),
	indexedAt: text("indexed_at").notNull().default(sql`(datetime('now'))`)
}, (table) => [
	index("idx_nexus_nodes_kind").on(table.kind),
	index("idx_nexus_nodes_file").on(table.filePath),
	index("idx_nexus_nodes_name").on(table.name),
	index("idx_nexus_nodes_community").on(table.communityId),
	index("idx_nexus_nodes_parent").on(table.parentId),
	index("idx_nexus_nodes_exported").on(table.isExported),
	index("idx_nexus_nodes_is_external").on(table.isExternal)
]);
/**
* `nexus_relations` — one row per directed graph edge. PROJECT-scope:
* `project_id` dropped (ADR-090 §2.1). The Hebbian plasticity columns
* (`weight`, `last_accessed_at`, `co_accessed_count`) were PARTITIONED out into
* the sibling {@link nexusRelationWeights} table by T11545 (ADR-090 §5.3).
*
* @task T11545 (plasticity partition) · T11538 (project-scope target shape) · T11361 (global source) · T529 (original)
*/
var nexusRelations = sqliteTable("nexus_relations", {
	id: text("id").primaryKey(),
	sourceId: text("source_id").notNull(),
	targetId: text("target_id").notNull(),
	type: text("type", { enum: NEXUS_RELATION_TYPES }).notNull(),
	confidence: real("confidence").notNull(),
	reason: text("reason"),
	step: integer("step"),
	indexedAt: text("indexed_at").notNull().default(sql`(datetime('now'))`)
}, (table) => [
	index("idx_nexus_relations_source").on(table.sourceId),
	index("idx_nexus_relations_target").on(table.targetId),
	index("idx_nexus_relations_type").on(table.type),
	index("idx_nexus_relations_source_type").on(table.sourceId, table.type),
	index("idx_nexus_relations_target_type").on(table.targetId, table.type),
	index("idx_nexus_relations_confidence").on(table.confidence)
]);
/**
* `nexus_relation_weights` — plasticity weights for `nexus_relations` edges
* (Hebbian co-access, T998). PROJECT-scope sibling 1:1 table keyed by
* `relation_id`, partitioned out of `nexus_relations` by T11545 (ADR-090 §5.3)
* to keep the read-mostly structural graph row narrow and isolate the
* write-heavy plasticity hot path.
*
* A relation has at most one weights row; rows are created lazily on the first
* co-access strengthening event (UPSERT in `nexus-plasticity.ts`), so absence
* means "never strengthened" (treat as weight 0.0). `relation_id` is an
* intra-scope soft FK to `nexus_relations.id` (symmetric with the graph's
* soft-FK convention — no DB-level FK). Move-safe (no absolute paths, no
* cross-scope refs) per ADR-090 §4.
*
* @task T11545 (project-scope target shape) · T998 (original plasticity columns)
* @epic T11535
*/
var nexusRelationWeights = sqliteTable("nexus_relation_weights", {
	relationId: text("relation_id").primaryKey(),
	weight: real("weight").notNull().default(0),
	lastAccessedAt: text("last_accessed_at"),
	coAccessedCount: integer("co_accessed_count").notNull().default(0)
}, (table) => [index("idx_nexus_relation_weights_last_accessed").on(table.lastAccessedAt), index("idx_nexus_relation_weights_weight").on(table.weight)]);
/**
* `nexus_contracts` — HTTP/gRPC/topic contract registry extracted from the
* project's code. PROJECT-scope: `project_id` dropped (ADR-090 §2.1).
*
* @task T11538 (project-scope target shape) · T11361 (global source) · T1065 (original)
*/
var nexusContracts = sqliteTable("nexus_contracts", {
	contractId: text("contract_id").primaryKey(),
	type: text("type", { enum: NEXUS_CONTRACT_TYPES }).notNull(),
	path: text("path").notNull(),
	method: text("method"),
	requestSchemaJson: text("request_schema_json").notNull().default("{}"),
	responseSchemaJson: text("response_schema_json").notNull().default("{}"),
	sourceSymbolId: text("source_symbol_id"),
	routeNodeId: text("route_node_id"),
	confidence: real("confidence").notNull().default(1),
	description: text("description"),
	createdAt: text("created_at").notNull().default(sql`(datetime('now'))`),
	updatedAt: text("updated_at").notNull().default(sql`(datetime('now'))`)
}, (table) => [
	index("idx_nexus_contracts_type").on(table.type),
	index("idx_nexus_contracts_path").on(table.path),
	index("idx_nexus_contracts_method").on(table.method),
	index("idx_nexus_contracts_source_symbol").on(table.sourceSymbolId),
	index("idx_nexus_contracts_created").on(table.createdAt)
]);
/**
* `nexus_code_index` — persistent index of code symbols extracted by
* tree-sitter (one row per symbol per file). PROJECT-scope: `project_id`
* dropped (ADR-090 §2.1).
*
* @task T11538 (project-scope target shape) · T11361 (global source)
*/
var nexusCodeIndex = sqliteTable("nexus_code_index", {
	id: text("id").primaryKey(),
	filePath: text("file_path").notNull(),
	symbolName: text("symbol_name").notNull(),
	kind: text("kind", { enum: CODE_INDEX_KINDS }).notNull(),
	startLine: integer("start_line").notNull(),
	endLine: integer("end_line").notNull(),
	language: text("language").notNull(),
	exported: integer("exported", { mode: "boolean" }).default(false),
	parent: text("parent"),
	returnType: text("return_type"),
	docSummary: text("doc_summary"),
	indexedAt: text("indexed_at").notNull()
}, (table) => [
	index("idx_nexus_code_index_file").on(table.filePath),
	index("idx_nexus_code_index_symbol").on(table.symbolName),
	index("idx_nexus_code_index_kind").on(table.kind)
]);
//#endregion
//#region ../core/dist/store/schema/cleo-project/runtime.js
/**
* Project-scope `cleo.db` — consolidated **runtime** domain (chain · agents ·
* playbooks · 6 tables).
*
* Part of the consolidated PROJECT-scope `cleo.db` target shape authored for
* SG-DB-SUBSTRATE-V2 (saga T11242, epic T11245/E2, task T11360). Target-shape
* authoring only — physical names carry the `tasks_` domain prefix. The live
* runtime modules `schema/{chain-schema,agent-schema,playbooks}.ts` keep their
* UNPREFIXED names until the exodus migration (T11248) swaps the substrate.
*
* Tables: tasks_warp_chains · tasks_warp_chain_instances · tasks_agent_instances ·
* tasks_agent_error_log · tasks_playbook_runs · tasks_playbook_approvals.
*
* ## E10 §3b — boolean non-conformer
*
* `playbook_approvals.auto_passed` (untyped INTEGER 0/1) →
* `integer({ mode: 'boolean' })`. (`warp_chains.validated`,
* `agent_error_log.resolved` were already typed boolean — preserved.)
*
* ## E10 §5b — enum-like bare-TEXT → { enum } (from named const arrays, §5a)
*
*   - `warp_chain_instances.status` → { enum: WARP_CHAIN_INSTANCE_STATUSES }
*   - `playbook_runs.status`        → { enum: PLAYBOOK_RUN_STATUSES } (minted here
*     from the `PlaybookRunStatus` contracts union — a CLOSED 5-state set)
*   - `playbook_approvals.status`   → { enum: PLAYBOOK_APPROVAL_STATUSES } (minted
*     here from the `PlaybookApprovalStatus` contracts union — a CLOSED 3-state set)
*   - `agent_error_log.error_type`  → { enum: AGENT_ERROR_TYPES } (promoted from
*     the inline literal, §5a)
*
* The playbook status sets are SAFE to freeze (unlike the conduit §5b cases):
* `@cleocode/contracts` declares them as exhaustive string-literal unions
* (`PlaybookRunStatus`/`PlaybookApprovalStatus`), so the const arrays minted
* here are the complete legal set by construction — verified to match below.
*
* ## E10 §4 / §6a
*
* All timestamps are already canonical TEXT ISO8601 (no epoch non-conformers).
* `warp_chains.definition`, instance `variables`/`stage_to_task`/`gate_results`,
* `agent_instances.metadata_json`, `playbook_runs.{bindings,iteration_counts}`
* stay serialized TEXT per the JSON-Column Audit.
*
* @task T11360
* @epic T11245
* @saga T11242
* @see docs/migration/sqlite-schema-canonical.md §3b · §4 · §5b · §6a
* @see docs/migration/sqlite-schema-columns.json (per-column affinity SSoT)
*/
/**
* Agent-error classification — promoted from the inline literal on
* `agent_error_log.error_type` to a named const array (§5a).
*/
var AGENT_ERROR_TYPES = [
	"retriable",
	"permanent",
	"unknown"
];
/**
* Playbook-run FSM states — minted from the `PlaybookRunStatus` contracts union
* so the §5b CHECK derivation references an identifier (§5a). The
* `satisfies readonly PlaybookRunStatus[]` assertion makes the compiler reject
* this array if it ever drifts from the canonical contracts union.
*/
var PLAYBOOK_RUN_STATUSES = [
	"running",
	"paused",
	"completed",
	"failed",
	"cancelled"
];
/**
* Playbook-approval states — minted from the `PlaybookApprovalStatus` contracts
* union (compiler-checked complete via `satisfies`).
*/
var PLAYBOOK_APPROVAL_STATUSES = [
	"pending",
	"approved",
	"rejected"
];
/**
* `tasks_warp_chains` — stored WarpChain definitions.
*
* @task T11360 (target shape) · T5403 (original)
*/
var tasksWarpChains = sqliteTable("tasks_warp_chains", {
	id: text("id").primaryKey(),
	name: text("name").notNull(),
	version: text("version").notNull(),
	description: text("description"),
	definition: text("definition").notNull(),
	validated: integer("validated", { mode: "boolean" }).default(false),
	createdAt: text("created_at").default(sql`(datetime('now'))`),
	updatedAt: text("updated_at").default(sql`(datetime('now'))`)
}, (table) => [index("idx_tasks_warp_chains_name").on(table.name)]);
/**
* `tasks_warp_chain_instances` — runtime chain instances bound to epics.
*
* @task T11360 (target shape) · T5403 (original)
*/
var tasksWarpChainInstances = sqliteTable("tasks_warp_chain_instances", {
	id: text("id").primaryKey(),
	chainId: text("chain_id").notNull().references(() => tasksWarpChains.id, { onDelete: "cascade" }),
	epicId: text("epic_id").notNull(),
	variables: text("variables"),
	stageToTask: text("stage_to_task"),
	status: text("status", { enum: WARP_CHAIN_INSTANCE_STATUSES }).notNull().default("pending"),
	currentStage: text("current_stage"),
	gateResults: text("gate_results"),
	createdAt: text("created_at").default(sql`(datetime('now'))`),
	updatedAt: text("updated_at").default(sql`(datetime('now'))`)
}, (table) => [
	index("idx_tasks_warp_chain_instances_chain").on(table.chainId),
	index("idx_tasks_warp_chain_instances_epic").on(table.epicId),
	index("idx_tasks_warp_chain_instances_status").on(table.status)
]);
/**
* `tasks_agent_instances` — live agent-process runtime registry.
*
* @task T11360 (target shape)
*/
var tasksAgentInstances = sqliteTable("tasks_agent_instances", {
	id: text("id").primaryKey(),
	agentType: text("agent_type", { enum: AGENT_TYPES }).notNull(),
	status: text("status", { enum: AGENT_INSTANCE_STATUSES }).notNull().default("starting"),
	sessionId: text("session_id"),
	taskId: text("task_id"),
	startedAt: text("started_at").notNull().default(sql`(datetime('now'))`),
	lastHeartbeat: text("last_heartbeat").notNull().default(sql`(datetime('now'))`),
	stoppedAt: text("stopped_at"),
	errorCount: integer("error_count").notNull().default(0),
	totalTasksCompleted: integer("total_tasks_completed").notNull().default(0),
	capacity: text("capacity").notNull().default("1.0"),
	metadataJson: text("metadata_json").default("{}"),
	parentAgentId: text("parent_agent_id")
}, (table) => [
	index("idx_tasks_agent_instances_status").on(table.status),
	index("idx_tasks_agent_instances_agent_type").on(table.agentType),
	index("idx_tasks_agent_instances_session_id").on(table.sessionId),
	index("idx_tasks_agent_instances_task_id").on(table.taskId),
	index("idx_tasks_agent_instances_parent_agent_id").on(table.parentAgentId),
	index("idx_tasks_agent_instances_last_heartbeat").on(table.lastHeartbeat)
]);
/**
* `tasks_agent_error_log` — agent error history.
*
* @task T11360 (target shape)
*/
var tasksAgentErrorLog = sqliteTable("tasks_agent_error_log", {
	id: integer("id").primaryKey({ autoIncrement: true }),
	agentId: text("agent_id").notNull(),
	errorType: text("error_type", { enum: AGENT_ERROR_TYPES }).notNull(),
	message: text("message").notNull(),
	stack: text("stack"),
	occurredAt: text("occurred_at").notNull().default(sql`(datetime('now'))`),
	resolved: integer("resolved", { mode: "boolean" }).notNull().default(false)
}, (table) => [
	index("idx_tasks_agent_error_log_agent_id").on(table.agentId),
	index("idx_tasks_agent_error_log_error_type").on(table.errorType),
	index("idx_tasks_agent_error_log_occurred_at").on(table.occurredAt)
]);
/**
* `tasks_playbook_runs` — playbook run state.
*
* @task T11360 (target shape) · T889 (original)
*/
var tasksPlaybookRuns = sqliteTable("tasks_playbook_runs", {
	runId: text("run_id").primaryKey(),
	playbookName: text("playbook_name").notNull(),
	playbookHash: text("playbook_hash").notNull(),
	currentNode: text("current_node"),
	bindings: text("bindings").notNull().default("{}"),
	errorContext: text("error_context"),
	status: text("status", { enum: PLAYBOOK_RUN_STATUSES }).notNull().default("running"),
	iterationCounts: text("iteration_counts").notNull().default("{}"),
	epicId: text("epic_id"),
	sessionId: text("session_id"),
	startedAt: text("started_at").notNull().default(sql`(datetime('now'))`),
	completedAt: text("completed_at")
});
/**
* `tasks_playbook_approvals` — playbook HITL approval records.
*
* @task T11360 (target shape) · T889 (original)
*/
var tasksPlaybookApprovals = sqliteTable("tasks_playbook_approvals", {
	approvalId: text("approval_id").primaryKey(),
	runId: text("run_id").notNull(),
	nodeId: text("node_id").notNull(),
	token: text("token").notNull().unique(),
	requestedAt: text("requested_at").notNull().default(sql`(datetime('now'))`),
	approvedAt: text("approved_at"),
	approver: text("approver"),
	reason: text("reason"),
	status: text("status", { enum: PLAYBOOK_APPROVAL_STATUSES }).notNull().default("pending"),
	autoPassed: integer("auto_passed", { mode: "boolean" }).notNull().default(false)
});

export { ADR_GATE_KINDS, ADR_RELATION_TYPES, ADR_TASK_LINK_TYPES, AGENT_ERROR_TYPES, CODE_INDEX_KINDS, NEXUS_CONTRACT_TYPES, NEXUS_NODE_KINDS, NEXUS_RELATION_TYPES, PLAYBOOK_APPROVAL_STATUSES, PLAYBOOK_RUN_STATUSES, STATUS_REGISTRY_ENTITY_TYPES, STATUS_REGISTRY_NAMESPACES, docsAttachmentRefs, docsAttachments, docsManifestEntries, docsPipelineManifest, nexusCodeIndex, nexusContracts, nexusNodes, nexusRelationWeights, nexusRelations, tasksAdrRelations, tasksAdrTaskLinks, tasksAgentErrorLog, tasksAgentInstances, tasksArchitectureDecisions, tasksAuditLog, tasksPlaybookApprovals, tasksPlaybookRuns, tasksSchemaMeta, tasksStatusRegistry, tasksTokenUsage, tasksWarpChainInstances, tasksWarpChains };
//# sourceMappingURL=cleo-project-JhUeeQwz.js.map
