{
  "schema_version": "0.1",
  "artifact_type": "architecture",
  "canonical": true,
  "artifact_id": "ARCH-007",
  "agent_summary": {
    "title": "Unified configuration authority architecture",
    "status": "approved",
    "summary": "The shipped config template supplies defaults, a metadata overlay classifies behavior, prd_config.py is the single operator interface, profiles perform atomic overlays, and one event dispatcher gates existing hook implementations.",
    "last_reviewed_at": "2026-07-14",
    "load_notes": "Canonical JSON; generate Markdown only on explicit human request."
  },
  "context": "The live config has 141 leaf settings while the existing tool registers 45. Persistent JSON, specialized commands, environment overrides, installer flags, and static host wiring are currently understandable only by reading multiple files. Prompt and Stop hooks also fan out into repeated Python startups and optional network/report work.",
  "principles": [
    "One persistent runtime authority, many explicitly classified control planes.",
    "Discover everything; mutate only what has a faithful validated consumer.",
    "Profiles are atomic overlays, not hidden alternate config files.",
    "Disabled means expensive work is skipped; safety gates retain explicit dependencies.",
    "Preserve specialized CRUD where data is structured, but surface its manager in the unified inventory."
  ],
  "components": [
    {"id": "ARCH-COMP-035", "summary": "Derived configuration catalog", "responsibility": "Flatten shipped defaults, apply metadata/validation overrides, classify dynamic and read-only values, and expose current/default/effective state plus latency and ownership metadata.", "requirement_ids": ["PRD-REQ-043", "PRD-REQ-044"], "interface_ids": ["ARCH-IF-028", "ARCH-IF-031"]},
    {"id": "ARCH-COMP-036", "summary": "Unified configuration CLI and profiles", "responsibility": "Provide validated single-key operations, audit, effective explanations, built-in profile overlays, and config-resident custom-profile CRUD with atomic dry-run/apply behavior.", "requirement_ids": ["PRD-REQ-044", "PRD-REQ-045", "PRD-NFR-024"], "interface_ids": ["ARCH-IF-028", "ARCH-IF-029"]},
    {"id": "ARCH-COMP-037", "summary": "Hook event dispatcher", "responsibility": "Read the canonical hook policy once per event, run only enabled existing capabilities in-process, preserve event ordering and block semantics, and expose effective gating reasons.", "requirement_ids": ["PRD-REQ-046", "PRD-NFR-025"], "interface_ids": ["ARCH-IF-030"]},
    {"id": "ARCH-COMP-038", "summary": "Delivery and migration layer", "responsibility": "Install the dispatcher and config additions additively; update host manifests/plugins, commands, templates, documentation, and parity checks without replacing downstream custom settings.", "requirement_ids": ["PRD-REQ-047", "PRD-NFR-026"], "interface_ids": ["ARCH-IF-031"]}
  ],
  "interfaces": [
    {"id": "ARCH-IF-028", "summary": "Configuration catalog entry", "producer": "shipped default template plus metadata overlay", "consumer": "prd_config CLI and external tooling", "contract": "Dotted key, value, default, type, mutable flag, manager, category, latency class, activation scope, dependencies, allowed values/bounds, and source."},
    {"id": "ARCH-IF-029", "summary": "Profile overlay", "producer": "built-in profile registry or configuration.custom_profiles", "consumer": "atomic profile validator/applicator", "contract": "Named description plus operator-mutable dotted-key settings; validated in full before one style-preserving config write."},
    {"id": "ARCH-IF-030", "summary": "Hook event dispatch", "producer": "host SessionStart/UserPromptSubmit/Stop/PreToolUse/PostToolUse wiring", "consumer": "prd_hook_dispatch.py", "contract": "One event and original stdin payload; ordered enabled handlers; original exit/block result propagated where the host supports blocking."},
    {"id": "ARCH-IF-031", "summary": "Control-plane inventory", "producer": "unified config tool", "consumer": "operator, agent, or dashboard", "contract": "Persistent settings plus separately classified specialized CRUD, environment overrides, install-time options, host wiring, and invocation-only flags; no claim that one-shot flags are persistent settings."}
  ],
  "data_state_model": {
    "runtime_authority": ".prd_plugin/config.json",
    "default_schema_source": "templates/config.json in the hub or .prd_plugin/templates/config.json downstream",
    "catalog_metadata": "scripts/prd_config.py metadata overlays; defaults are derived rather than duplicated",
    "custom_profiles": ".prd_plugin/config.json#configuration.custom_profiles",
    "active_profile_marker": ".prd_plugin/config.json#configuration.active_profile",
    "dynamic_managers": "reflection.categories -> prd_reflections/MCP CRUD; version/schema/ID internals -> system-managed",
    "host_runtime": "one prd_hook_dispatch.py invocation per wired event"
  },
  "decisions": [
    {"id": "ARCH-DEC-026", "summary": "Keep .prd_plugin/config.json as the only persistent runtime authority and derive the catalog from shipped defaults.", "rationale": "A second registry of default values would drift; metadata should enrich the existing source rather than clone it.", "source_ids": ["PRD-REQ-043", "PRD-NFR-026"]},
    {"id": "ARCH-DEC-027", "summary": "Expose every setting but make system-owned and structured dynamic fields read-only through the generic setter.", "rationale": "Discoverability and mutability are different; unsafe generic writes must not bypass versioning, ID, or reflection CRUD invariants.", "source_ids": ["PRD-REQ-043", "PRD-REQ-044", "PRD-NFR-024"]},
    {"id": "ARCH-DEC-028", "summary": "Use atomic profile overlays with lean, balanced, and thorough built-ins plus config-resident custom profiles.", "rationale": "Profiles make use-case switching practical while retaining exact visible settings and one runtime authority.", "source_ids": ["PRD-REQ-045"]},
    {"id": "ARCH-DEC-029", "summary": "Consolidate hook fan-out through one dispatcher per host event instead of adding more per-hook wrappers.", "rationale": "This materially reduces process startup cost and provides one place to enforce master/per-capability policy without rewriting existing handler logic.", "source_ids": ["PRD-REQ-046", "PRD-NFR-025"]}
  ],
  "risks": [
    {"id": "ARCH-RISK-022", "summary": "A setting is exposed as mutable although its consumer ignores it.", "mitigation": "Catalog audit requires every mutable key to name a real consumer/manager; otherwise classify it read-only or invocation-only.", "status": "mitigated"},
    {"id": "ARCH-RISK-023", "summary": "A latency profile disables a safety-critical gate or silently enables an external integration.", "mitigation": "Profiles list exact overlays, cannot include system-owned keys, retain mandatory verification fallbacks, and never enable external integrations requiring endpoint/authority configuration.", "status": "mitigated"},
    {"id": "ARCH-RISK-024", "summary": "Dispatcher consolidation changes host blocking or handler order semantics.", "mitigation": "Characterization tests capture current order, stdin, exit codes, and cross-host wiring before replacement; dispatcher integration is a separate verified increment.", "status": "mitigated"}
  ],
  "validation_strategy": [
    "Inventory tests compare every shipped config leaf with catalog output and require zero unclassified settings.",
    "RED/GREEN unit tests cover generic operations, validation, atomic profiles, dry-run, custom profile CRUD, and effective dependency reasons.",
    "Hook characterization and cross-host tests prove one dispatcher process per event and preserve blocking/order behavior.",
    "Installer and template parity tests prove additive downstream migration and all-host delivery.",
    "Focused verification per increment, then one full release verification and CHML audit loop."
  ],
  "traceability": {
    "source_ids": ["REQ-095", "PRD-REQ-043", "PRD-REQ-044", "PRD-REQ-045", "PRD-REQ-046", "PRD-REQ-047"],
    "implementation_task_ids": ["IMP-TASK-053", "IMP-TASK-054", "IMP-TASK-055", "IMP-TASK-056", "IMP-TASK-057"],
    "tracking_ids": ["TRK-097", "TRK-098", "TRK-099", "TRK-100"],
    "health_ids": []
  }
}
