import { _ as __exportAll } from './chunk-DDP5xfzh.js';
import { s as sqliteTable, t as text, i as integer, a as index, r as real } from './indexes-aYlULWG3.js';
import { s as sql } from './utils-BvHPJOVk.js';

//#region ../core/dist/store/schema/nexus-schema.js
/**
* Drizzle ORM runtime schema for the CLEO nexus domain inside the consolidated
* GLOBAL `cleo.db` (SQLite via node:sqlite).
*
* Tables (post-cutover PREFIXED physical names — T11578 · AC3):
*   nexus_project_registry, nexus_audit_log, nexus_schema_meta, nexus_nodes,
*   nexus_relations, nexus_relation_weights, nexus_contracts,
*   nexus_user_profile, nexus_sigils, nexus_project_id_aliases.
* Stores cross-project registry and audit infrastructure for the Nexus domain,
* plus the code intelligence graph layer (nodes + directed edges), plus the
* global user identity / preference profile (PSYCHE Wave 1 — T1077), plus the
* peer-card sigil identity layer (PSYCHE Wave 8 — T1148).
*
* ## COMPLETE-CUTOVER to prefixed `nexus_*` tables (T11578 · AC3)
*
* The nexus runtime READ + WRITE path now targets the PREFIXED consolidated
* tables the consolidated cleo-global migration
* (`drizzle-cleo-global/…t11363-consolidation-cleo-global`) creates — NOT the
* legacy BARE tables (`project_registry`, `user_profile`, `sigils`,
* `project_id_aliases`). Only the four registry/identity table NAMES change
* (bare → `nexus_*`); the five already-prefixed tables (`nexus_audit_log`,
* `nexus_schema_meta`, `nexus_nodes`, `nexus_relations`, `nexus_contracts`)
* keep identity. The TypeScript EXPORT symbol names are intentionally
* UNCHANGED (`projectRegistry`, `userProfile`, `sigils`, `projectIdAliases`,
* …) so every accessor that imports them needs ZERO source change — only the
* physical table they map to moves to the prefixed shape.
*
* ## Shape parity with the consolidated migration (T11578 · AC3)
*
* The consolidated migration (T11363) injects enum/format `CHECK` constraints
* and canonical TEXT ISO-8601 timestamp affinity. To keep the runtime drizzle
* mapping aligned with the physical tables it now queries:
*   - `nexus_user_profile.{firstObservedAt,lastReinforcedAt}` and
*     `nexus_sigils.{createdAt,updatedAt}` are canonical TEXT ISO-8601 (were
*     `integer({ mode:'timestamp' })`). The writers pass `.toISOString()` so
*     the `GLOB 'YYYY-MM-DD*'` CHECK is satisfied.
*   - The Hebbian plasticity columns (`weight`, `last_accessed_at`,
*     `co_accessed_count`) are PARTITIONED out of `nexus_relations` into the
*     sibling `nexus_relation_weights` table (T11545 · ADR-090 §5.3). The
*     `nexus-sqlite.ts` open path drops the inline columns from the consolidated
*     `nexus_relations` (which still carries them in the T11363 shape) and
*     ensures the sibling table.
*
* ## ADR-090 residency split — graph tables PROJECT-scoped (T11648)
*
* The four code-graph tables (`nexus_nodes`, `nexus_relations`,
* `nexus_contracts`, `nexus_code_index`) + the `nexus_relation_weights`
* plasticity sibling no longer carry `project_id` (ADR-090 §2.1): they live in
* the PROJECT `cleo.db` and `nexus-sqlite.ts` opens the project scope as `main`,
* so scope is implicit. The graph accessors therefore DROP the former
* `WHERE project_id = ?` predicate (single project per DB). The
* registry/identity tables (`nexus_project_registry`, `nexus_user_profile`,
* `nexus_sigils`, `nexus_project_id_aliases`, `nexus_audit_log`,
* `nexus_schema_meta`) stay GLOBAL and are reached through the
* `nexus_global` ATTACH (see `nexus-sqlite.ts`); their mappings are unchanged.
*
* @task T5365
* @task T529
* @task T1077
* @task T1148
* @task T11578
* @task T11648
*/
var nexus_schema_exports = /* @__PURE__ */ __exportAll({
	NEXUS_CONTRACT_TYPES: () => NEXUS_CONTRACT_TYPES,
	NEXUS_NODE_KINDS: () => NEXUS_NODE_KINDS,
	NEXUS_RELATION_TYPES: () => NEXUS_RELATION_TYPES,
	SIGIL_ROLES: () => SIGIL_ROLES,
	nexusAuditLog: () => nexusAuditLog,
	nexusContracts: () => nexusContracts,
	nexusNodes: () => nexusNodes,
	nexusRelationWeights: () => nexusRelationWeights,
	nexusRelations: () => nexusRelations,
	nexusSchemaMeta: () => nexusSchemaMeta,
	projectIdAliases: () => projectIdAliases,
	projectRegistry: () => projectRegistry,
	sigils: () => sigils,
	userProfile: () => userProfile
});
/** Central registry of all CLEO projects known to the Nexus. */
var projectRegistry = sqliteTable("nexus_project_registry", {
	projectId: text("project_id").primaryKey(),
	projectHash: text("project_hash").notNull().unique(),
	projectPath: text("project_path").notNull().unique(),
	name: text("name").notNull(),
	registeredAt: text("registered_at").notNull().default(sql`(datetime('now'))`),
	lastSeen: text("last_seen").notNull().default(sql`(datetime('now'))`),
	healthStatus: text("health_status").notNull().default("unknown"),
	healthLastCheck: text("health_last_check"),
	permissions: text("permissions").notNull().default("read"),
	lastSync: text("last_sync").notNull().default(sql`(datetime('now'))`),
	taskCount: integer("task_count").notNull().default(0),
	labelsJson: text("labels_json").notNull().default("[]"),
	brainDbPath: text("brain_db_path"),
	tasksDbPath: text("tasks_db_path"),
	lastIndexed: text("last_indexed"),
	statsJson: text("stats_json").notNull().default("{}")
}, (table) => [
	index("idx_nexus_project_registry_hash").on(table.projectHash),
	index("idx_nexus_project_registry_health").on(table.healthStatus),
	index("idx_nexus_project_registry_name").on(table.name),
	index("idx_nexus_project_registry_last_indexed").on(table.lastIndexed)
]);
/**
* Maps legacy base64url(path) project IDs to their canonical IDs.
*
* Populated during W5 identity migration. Allows the dispatch layer to
* resolve old IDs transparently without breaking existing integrations.
*
* @task T9149
*/
var projectIdAliases = sqliteTable("nexus_project_id_aliases", {
	legacyId: text("legacy_id").primaryKey(),
	canonicalId: text("canonical_id").notNull(),
	createdAt: text("created_at").notNull().default(sql`(datetime('now'))`)
}, (table) => [index("idx_nexus_project_id_aliases_canonical").on(table.canonicalId)]);
/** Append-only audit log for all Nexus operations across projects. */
var nexusAuditLog = sqliteTable("nexus_audit_log", {
	id: text("id").primaryKey(),
	timestamp: text("timestamp").notNull().default(sql`(datetime('now'))`),
	action: text("action").notNull(),
	projectHash: text("project_hash"),
	projectId: text("project_id"),
	domain: text("domain"),
	operation: text("operation"),
	sessionId: text("session_id"),
	requestId: text("request_id"),
	source: text("source"),
	gateway: text("gateway"),
	success: integer("success"),
	durationMs: integer("duration_ms"),
	detailsJson: text("details_json").default("{}"),
	errorMessage: text("error_message")
}, (table) => [
	index("idx_nexus_audit_timestamp").on(table.timestamp),
	index("idx_nexus_audit_action").on(table.action),
	index("idx_nexus_audit_project_hash").on(table.projectHash),
	index("idx_nexus_audit_project_id").on(table.projectId),
	index("idx_nexus_audit_session").on(table.sessionId)
]);
/** Key-value store for nexus.db schema versioning and metadata. */
var nexusSchemaMeta = sqliteTable("nexus_schema_meta", {
	key: text("key").primaryKey(),
	value: text("value").notNull()
});
/**
* All node kind values — matches GraphNodeKind in @cleocode/contracts.
*
* Kept as a const tuple for use in Drizzle enum column definitions.
* The ordering is intentional: structural → module → callable → type →
* value-level → language-specific → graph-level → legacy.
*/
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"
];
/**
* Graph nodes table — one row per symbol or structural element.
*
* Stores all code intelligence graph nodes indexed per project.
* Synthetic nodes (community, process) share this table with
* source-derived nodes (function, class, file).
*
* Both this table and `code_index` are populated from the same parse pass.
* They serve complementary roles — do NOT merge them.
*
* @task T529
*/
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)
]);
/**
* All relation type values — matches GraphRelationType in @cleocode/contracts.
*
* Kept as a const tuple for use in Drizzle enum column definitions.
*/
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"
];
/**
* Graph relations table — one row per directed edge.
*
* All graph traversal (impact, context, process detection) reads from
* this table after ingestion completes.
*
* Source and target reference nexus_nodes.id. They are soft FKs —
* unresolved targets (e.g., external packages) are stored as raw specifiers.
*
* @task T529
*/
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)
]);
/**
* Plasticity weights for `nexus_relations` edges — Hebbian co-access (T998).
*
* Partitioned out of `nexus_relations` by T11545 (ADR-090 §5.3): the
* write-heavy plasticity columns (`weight`, `last_accessed_at`,
* `co_accessed_count`) live in this sibling 1:1 table keyed by `relation_id`,
* keeping the read-mostly structural graph row narrow. 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` (no DB-level
* FK — symmetric with the rest of the graph's soft-FK convention).
*
* @task T11545
* @task T998
* @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)]);
/**
* All contract type values for extraction.
*
* Kept as a const tuple for use in Drizzle enum column definitions.
*
* @task T1065
*/
var NEXUS_CONTRACT_TYPES = [
	"http",
	"grpc",
	"topic"
];
/**
* Cross-project code contract registry for HTTP/gRPC/topic APIs.
*
* Stores extracted contracts keyed by type, path/method, and project.
* Used to detect integration points and compatibility across projects.
*
* @task T1065
*/
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)
]);
/**
* Global user identity / preference profile for CLEO.
*
* Each row records a single trait about the user: a preference, a behaviour
* pattern, or any other stable attribute derived from interaction history via
* the PSYCHE Dialectic Evaluator (Wave 3).  The table lives in nexus.db so
* that it is global (user-scoped) rather than per-project.
*
* Design decisions:
* - `traitKey` is the PK — traits are upserted by key, not duplicated.
* - `confidence` (0.0–1.0) follows a Bayesian decay/reinforce model: each
*   observation that re-confirms the trait increments reinforcementCount and
*   may push confidence toward 1.0; contradicting observations trigger a new
*   upsert with lower confidence.
* - `supersededBy` links deprecated traits to their replacement so downstream
*   code can follow the supersession chain (T1139).
* - `derivedFromMessageId` is a soft FK to a future session_messages table
*   (Wave 5 — T1145).  It is nullable until that table exists.
*
* PSYCHE reference: `upstream psyche-lineage · models.py` (User + metadata).
*
* @task T1077
* @epic T1076
*/
var userProfile = sqliteTable("nexus_user_profile", {
	traitKey: text("trait_key").primaryKey(),
	traitValue: text("trait_value").notNull(),
	confidence: real("confidence").notNull(),
	source: text("source").notNull(),
	derivedFromMessageId: text("derived_from_message_id"),
	firstObservedAt: text("first_observed_at").notNull(),
	lastReinforcedAt: text("last_reinforced_at").notNull(),
	reinforcementCount: integer("reinforcement_count").notNull().default(1),
	supersededBy: text("superseded_by")
}, (table) => [
	index("idx_nexus_user_profile_confidence").on(table.confidence),
	index("idx_nexus_user_profile_source").on(table.source),
	index("idx_nexus_user_profile_last_reinforced").on(table.lastReinforcedAt),
	index("idx_nexus_user_profile_superseded").on(table.supersededBy)
]);
/**
* Legal `nexus_sigils.role` values — the canonical CANT agent role taxonomy.
*
* Mirrors `SIGIL_ROLES` in the consolidated `cleo-global/nexus.ts` target
* module (T11578 · AC3) so the runtime drizzle mapping matches the physical
* `CHECK (role IN (…))` the consolidated migration injects. `''` is the column
* default (a sigil before a `.cant` role is associated). The writer
* (`nexus/sigil.ts`) normalizes any out-of-set free-form `.cant` role onto this
* enum so the CHECK is always satisfied.
*
* @task T1148
* @task T11578
*/
var SIGIL_ROLES = [
	"",
	"orchestrator",
	"lead",
	"worker",
	"subagent",
	"specialist",
	"validator"
];
/**
* Peer-card sigil identity layer for CANT agents.
*
* Each row represents a CANT agent's structured identity as seen by BRAIN —
* the "sigil" encodes display name, role, CANT file path, behavioral
* constraints (system-prompt fragment), and capability flags.
*
* Sigils are keyed by `peerId` (the canonical peer identifier that appears on
* all brain tables via the `peer_id` column introduced in Wave 2).  A single
* peer may have at most one sigil record; use `upsertSigil` to update.
*
* PSYCHE reference: `upstream psyche-lineage · crud/peer_card.py`
*
* @task T1148
* @epic T1075
*/
var sigils = sqliteTable("nexus_sigils", {
	peerId: text("peer_id").primaryKey(),
	cantFile: text("cant_file"),
	displayName: text("display_name").notNull().default(""),
	role: text("role", { enum: SIGIL_ROLES }).notNull().default(""),
	systemPromptFragment: text("system_prompt_fragment"),
	capabilityFlags: text("capability_flags"),
	createdAt: text("created_at").notNull().$defaultFn(() => (/* @__PURE__ */ new Date()).toISOString()),
	updatedAt: text("updated_at").notNull().$defaultFn(() => (/* @__PURE__ */ new Date()).toISOString())
}, (table) => [index("idx_nexus_sigils_display_name").on(table.displayName), index("idx_nexus_sigils_role").on(table.role)]);

export { NEXUS_CONTRACT_TYPES as N, SIGIL_ROLES as S, projectIdAliases as a, NEXUS_NODE_KINDS as b, NEXUS_RELATION_TYPES as c, nexusAuditLog as d, nexusContracts as e, nexusNodes as f, nexusRelationWeights as g, nexusRelations as h, nexusSchemaMeta as i, nexus_schema_exports as n, projectRegistry as p, sigils as s, userProfile as u };
//# sourceMappingURL=nexus-schema2-BEd-ol6e.js.map
