--- id: t10324 tasks: [T10324] kind: feat summary: "schema: @cross-db JSDoc tag + lint gate + ADR-068 charter rule (Saga T10281 / Epic T10285 E4-DB-CROSS-LINKS)" --- Formalises the cross-database soft-FK contract that SQLite cannot enforce at the file level. Every Drizzle column whose value points at a row in a DIFFERENT `.db` file now carries an `@cross-db ..` JSDoc tag immediately above the declaration, with prose identifying which accessor or validator enforces the soft FK at runtime. ### Annotations added (33 cross-DB columns) - `packages/core/src/store/memory-schema.ts` — `brain.db` → `tasks.db`: `brain_decisions.context_epic_id`, `brain_decisions.context_task_id`, `brain_observations.source_session_id`, `brain_memory_links.task_id`, `brain_retrieval_log.session_id`, `brain_plasticity_events.session_id`, `brain_modulators.session_id`, `brain_consolidation_events.session_id`, `brain_transcript_events.session_id`, `session_narrative.session_id`. - `packages/core/src/store/conduit-schema.ts` — `conduit.db` → `signaldock.db`: `messages.from_agent_id`, `messages.to_agent_id`, `attachments.from_agent_id`, `attachment_versions.author_agent_id`, `attachment_approvals.reviewer_agent_id`, `attachment_contributors.agent_id`, `project_agent_refs.agent_id`, `topics.created_by`, `topic_subscriptions.agent_id`, `topic_messages.from_agent_id`, `topic_message_acks.subscriber_agent_id`. Also `topics.epic_id` (conduit→tasks). - `packages/core/src/store/nexus-schema.ts` — `nexus.db` → filesystem / project-context.json: `project_registry.project_id`, `project_registry.project_path`, `project_registry.brain_db_path`, `project_registry.tasks_db_path`, `nexus_audit_log.session_id`, `user_profile.derived_from_message_id`. - `packages/core/src/store/skills-schema.ts` — `skills.db` → `tasks.db`: `skill_usage.task_id`. - `packages/core/src/agents/agent-schema.ts` — `tasks.db` → `signaldock.db`: `agent_instances.id`, `agent_instances.parent_agent_id`, `agent_error_log.agent_id`. ### New CI gate — `Cross-DB Annotation Lint (T10324)` - `scripts/lint-cross-db-annotations.mjs` walks every Drizzle schema file under `packages/core/src/store/` and `packages/core/src/agents/`, identifies cross-DB columns by snake-case name pattern (`task_id`, `session_id`, `epic_id`, `agent_id`, `*_agent_id`, `brain_anchor`, `project_path`, `*_db_path`, etc.), and fails the PR when ANY such column is missing a `@cross-db` tag. - Intra-DB FKs (columns that chain `.references(() => …)` or live in the tasks-DB schema files) are auto-exempt. Per-line opt-out via `// cross-db-annotation-ok: ` for cases the heuristic mis-classifies (currently `agent_instances.session_id`/`task_id`). - Three modes: `--strict` (zero tolerance), `--baseline` (capture current state), `--check` (CI default — fails only on net-add vs baseline). - Baseline file `scripts/.lint-cross-db-annotations-baseline.json` seeded at 0 — the initial pass landed under T10324 annotated every cross-DB column simultaneously. - 10 poison tests under `scripts/__tests__/lint-cross-db-annotations.test.mjs` cover every classification branch (annotated, un-annotated, intra-DB FK, opt-out, intra-DB file allowlist, baseline + check). ### ADR-068 amendment New subsection "Cross-DB Reference Columns" between the `openCleoDb` chokepoint and the CI Gate section. Defines the tag grammar (`@cross-db .
. — `), enumerates which column-name patterns count as cross-DB, lists the intra-DB exemption rules, and documents the new CI gate. Amendment history entry added; status remains `accepted`.