6.5 KiB
6.5 KiB
1. ARCHITECTURE_CONSTITUTION.md
1.1 Назначение
Этот документ — краткий набор законов репозитория и production-архитектуры. Он выше обычных task packets, примеров и локальных README. Codex не является архитектурным authority: он реализует только то, на что выдана task authority.
1.2 Иерархия архитектурной власти
- Architecture Constitution.
- Accepted ADR / Foundation Decision.
- Machine-readable Architecture Registry.
- Versioned semantic contracts and state machines.
- Module architecture specification.
- Codex Task Packet.
- Implementation and examples.
Если нижний уровень противоречит верхнему, нижний считается ошибочным. Существующий код является evidence of implementation, но не authority to redefine architecture.
1.3 Неприкосновенные инварианты V1
- LLM/model/provider не является Assistant.
- Capability не означает Authority.
- Observation, Claim, Belief, Prediction, Action и Outcome — разные семантические классы.
- Model output никогда напрямую не мутирует canonical semantic state и не выполняет external mutation.
- Любая реальная мутация проходит Proposal → semantic owner validation → Authority/Integrity checks → Commit → Executor → Outcome/Verification.
- Любая executable activity имеет live justification path к действующей Goal, Commitment, Responsibility или Policy.
- Отмена/суперсессия justification должна распространяться до зависимых работ перед следующим commit.
- Canonical owner — один на конкретный mutable semantic state в конкретной semantic generation.
- Другие модули не пишут canonical storage владельца напрямую.
- Cross-owner SQL writes, cross-owner FK и скрытая cross-owner trigger logic запрещены по умолчанию.
- Derived projections/caches/indexes не являются source of truth и должны быть rebuildable либо явно classified otherwise.
- Temporal/NATS/Redis/vector index/model memory не являются единственным местом хранения commitments, authority, semantic history или future obligations.
- Durable future obligations живут в canonical prospective state независимо от workflow/scheduler engine.
- External side effect должен быть idempotent/reconcilable; timeout не равен failure; UNKNOWN_OUTCOME — first-class state.
- No correctness property may depend on a shared in-process lock across bounded modules.
- Semantic topology, process topology, storage topology и model topology независимы и меняются отдельно.
- Co-location — deployment optimization, не архитектурная привилегия.
- Major bounded contracts должны быть serializable и не зависеть от Go pointers, shared memory, global variables или ambient process state.
- Core/domain не импортирует PostgreSQL/NATS/Temporal/MCP/model-provider packages.
- Никакого giant
common/shareddomain package; technical shared mechanisms допускаются только вplatformи не владеют domain semantics. - Semantic duplication предпочтительнее ложной абстракции.
- Event-driven взаимодействие используется ради temporal decoupling/history, а не потому, что два модуля разные.
- Public query не должен скрыто изменять canonical state.
- Durable background responsibility не реализуется unmanaged goroutine/timer.
context.Contextне переносит скрытый user/scope/authority/task state; это явные typed fields.- Unknown/Conflict/NotApplicable/NotObserved не схлопываются в nil/false/default.
- Type system, package visibility, DB ACL и CI должны делать критические ошибки невозможными там, где это возможно.
- Architecture guardrails themselves are protected and cannot validate their own weakening alone.
- Codex ordinary feature task не меняет Constitution, Architecture Registry, public semantic topology, guardrails или canonical ownership без отдельного approved change.
- Codex может завершить задачу typed gap (
BLOCKED_BY_SPEC_GAP,BLOCKED_BY_ARCHITECTURE_GAP) вместо архитектурного обхода. - Every persistent thing has lifecycle, owner/justification, stop/retirement path and recovery semantics appropriate to criticality.
- Historical meaning is not rewritten by current interpretation; corrections/supersessions are appended/versioned.
- Newer/stronger model never automatically receives broader authority.
- More intelligence, more code, more services or more automations are not goals themselves.
- KEEP/WAIT/DO_NOTHING are valid decisions.
- The system must remain recoverable, exportable and replaceable.
1.4 Codex-specific hard prohibitions
- No direct cross-module DB access “temporarily”.
- No cross-schema JOIN as application dependency between canonical owners.
- No direct provider/model call outside Cognitive Gateway/adapters.
- No external mutation outside Commit/Executor path.
- No generic
SaveEntity(any),Invoke(any), global Service Locator or God Context. - No semantic side effects in Go package
init(). - No semantic durable timers using
time.After/sleep in request process. - No production semantic behavior hidden only in middleware, SQL trigger or YAML DSL.
- No silent retry of ambiguous external mutation.
- No weakening of architecture/security tests inside unrelated feature task.
- No new third-party dependency, canonical table, integration contract or privileged secret access without declared change classification.
1.5 Core change rule
Change the lowest layer that eliminates the causal class of the problem. Escalate only when necessary:
data/config → local implementation → skill/strategy → module contract → ownership/schema → architecture → constitutional invariant.