"""Call site metadata — descriptions, categories, cost policy, wiring status.

Sourced from docs/architecture/genesis-v3-model-routing-registry.md and
verified against live code traces (2026-04-05 audit; revised 2026-05-10).

Fields:
  description:    What this does + when it runs (1-2 sentences)
  category:       Subsystem grouping for neural monitor ring/color
  frequency:      How often this fires
  cost_policy:    Auto-derived for most; manual for CC-dispatched sites
  dispatch:       "cc" (CC background only), "dual" (API-first, CC fallback)
  cc_model:       Which CC model (Haiku/Sonnet/Opus) for dispatch=cc/dual
  wired:          False if config exists but no code invokes this call site
  model_tier:     What class of model this needs (embedding/slm/mid/frontier/cc)
  status_reason:  Machine-readable status (WIRED, WIRED_DIFFERENT_MECHANISM,
                  PARTIALLY_WIRED, V4_PLACEHOLDER, DEPRECATED_REMOVED,
                  SUPERSEDED, TEMP_DISABLED, REPLACED_BY_AWARENESS_LOOP,
                  NO_API_KEYS [runtime overlay, install-specific]).
                  Renders as a colored badge in the neural monitor.
                  NO_API_KEYS is set at snapshot time by call_sites.py
                  when every provider in a site's chain has has_api_key=False;
                  intrinsic statuses defined in _CALL_SITE_META take
                  precedence (setdefault).
  see_also:       Sibling call-site IDs to cross-reference. Populated for
                  confusable-vocabulary families. Rendered as clickable
                  links in the neural monitor detail panel.

# ─────────────────────────────────────────────────────────────────────────
# CONFUSABLE-VOCABULARY MASTER CROSS-REFERENCE
# ─────────────────────────────────────────────────────────────────────────
# Multiple call sites share or shared overloaded words ("triage",
# "task_retrospective", "fresh_eyes_review", "ego_compaction"). The
# original numbering scheme implied uniqueness — it didn't.
#
# 2026-05-10 rename pass disambiguated the worst offenders:
#   17_fresh_eyes_review  → 17_executor_review
#   23_fresh_eyes_review  → 23_outreach_review
#   email_triage          → outreach_email_triage
#
# Below is the authoritative map. When editing or grepping for these
# IDs, check here FIRST.
#
# ── "triage" family (4 sites — only 3 wired) ────────────────────────────
#
# 2_triage [REMOVED FROM YAML 2026-05-10]
#   Was: original threshold-based triage of every awareness-tick signal,
#        deciding which reflection depth to fire. Never wired in code.
#   Superseded by: deterministic threshold math in
#                  awareness/loop.py:classify_depth() (no LLM call).
#
# 29_retrospective_triage [LIVE — THE triage classifier]
#   Per outcome: classifies a completed InteractionSummary into a
#   TriageDepth (0=SKIP / 1=QUICK_NOTE / 2=WORTH_THINKING / 3=FULL_ANALYSIS
#   / 4=FULL_PLUS_WORKAROUND). Output drives how deeply the learning
#   pipeline analyzes the interaction. Reads few-shot examples from
#   src/genesis/identity/TRIAGE_CALIBRATION.md (regenerated by site 30).
#   Live callers: learning/triage/classifier.py:47, learning/pipeline.py:256
#
# 30_triage_calibration [LIVE — calibrates the classifier above]
#   Daily: reviews recent site-29 outputs (under/over-classification),
#   regenerates few-shot calibration examples + rules, writes a new
#   TRIAGE_CALIBRATION.md. Does NOT classify interactions itself; it
#   tunes the classifier. (Previous meta entry referenced a "15_triage_calibration"
#   predecessor — that ID is a ghost; no such entry exists in this file
#   or in the live YAML.)
#   Live caller: learning/triage/calibration.py:97
#
# outreach_email_triage [LIVE — separate domain]
#   Weekly: light filter for the email batch, classifying by relevance and
#   urgency to decide which deserve outreach attention. Different domain
#   entirely (outreach, not learning); operates on emails, not interaction
#   summaries. Gemini-primary free-only chain.
#   Renamed from `email_triage` 2026-05-10 to disambiguate the triage
#   namespace and lead with the outreach domain.
#
# ── "task_retrospective" family (2 sites — only 1 wired) ────────────────
#
# 7_task_retrospective [REMOVED FROM YAML 2026-05-10]
#   Was meant to: root-cause classify completed executor tasks. The
#   executor went live with 43_task_retrospective instead and this entry
#   was forgotten (user-confirmed 2026-05-10: "duplicate that got
#   forgotten when 43_* was wired"). Meta entry retained for historical
#   reference; routing chain definition removed.
#
# 43_task_retrospective [LIVE — the actual executor retrospective]
#   Per executor task completion: classifies the task trace, produces
#   structured retrospective data feeding learning + ego context.
#   Live caller: autonomy/executor/trace.py:24 (_CALL_SITE constant) and :202
#
# ── executor/outreach review pair (2 sites — both live, different domains) ─
#
# Renamed 2026-05-10 from the `fresh_eyes_review` family (where both sites
# shared the same descriptor). The ID now leads with the domain.
#
# 17_executor_review [LIVE — executor Gate 2, cross-vendor PAID]
#   Per executor task verification: cross-vendor second-opinion review of
#   task deliverables. Part of a 3-gate pipeline: (1) programmatic checks,
#   (2) this site, (3) 20_adversarial_counterargument. Cross-vendor by
#   design (different model family than the task author). PAID chain
#   (DeepSeek V4 Pro + Qwen 3.6+ via OpenRouter).
#   Live caller: autonomy/executor/review.py:37
#                (_CALL_SITE_EXECUTOR_REVIEW constant)
#   Renamed from: 17_fresh_eyes_review (2026-05-10)
#
# 23_outreach_review [LIVE — outreach pre-send check, FREE]
#   Per outreach message draft: scores 1-5 ("would user appreciate this?").
#   If score >= min_score (default 3.0), approved for send. Different
#   question, different cost profile from 17_executor_review.
#   Live caller: outreach/fresh_eyes.py:40
#   Renamed from: 23_fresh_eyes_review (2026-05-10)
#
# ── "ego_compaction" namespace (1 routing site + 2 observability labels) ─
#
# 8_ego_compaction [LIVE routing site — ego subsystem-gated]
#   Rolling-summary compaction of ego session context. When an ego
#   session's context grows too large, this compacts it via Mistral Large
#   into a summary. Live caller: ego/compaction.py:54 (default
#   call_site_id param on EgoCompactor).
#
# 8_user_ego_compaction [NOT a routing ID — observability label only]
#   Cost-tracking / event-bus tag identifying that a compaction came from
#   the USER ego (CEO/Opus). Passed to cost_events or deferred_work, NOT
#   to route_call(). Reference: runtime/init/ego.py:86.
#
# 8_genesis_ego_compaction [NOT a routing ID — observability label only]
#   Same as above but for the GENESIS ego (COO/Sonnet).
#   Reference: runtime/init/ego.py:157.
#
# ─────────────────────────────────────────────────────────────────────────
"""

from __future__ import annotations

_CALL_SITE_META: dict[str, dict] = {
    # ── WIRED: actively executing, have last_run records ──────────────
    "3_micro_reflection": {
        "description": "Fast pattern check on the latest signals. Runs every awareness tick using free models.",
        "category": "reflection",
        "frequency": "Every 5 min",
        "cost_policy": "Free primary",
        "model_tier": "slm",
    },
    "4_light_reflection": {
        "description": "Assesses flagged signals when urgency is elevated. Free API chain with CC/Haiku fallback.",
        "category": "reflection",
        "frequency": "On elevated urgency",
        "cost_policy": "Free only (never pays)",
        "dispatch": "dual",
        "cc_model": "Haiku",
        "model_tier": "slm",
    },
    "5_deep_reflection": {
        "description": "Journal-quality analysis of patterns, trends, and user context. Dispatched via CC background session (Sonnet).",
        "category": "reflection",
        "frequency": "Weekly + high urgency",
        "cost_policy": "CC background (Sonnet)",
        "dispatch": "cc",
        "cc_model": "Sonnet",
        "model_tier": "cc",
    },
    "6_strategic_reflection": {
        "description": "Quarterly-depth strategic analysis and long-term planning. Dispatched via CC background session (Opus).",
        "category": "reflection",
        "frequency": "4-8/month",
        "cost_policy": "CC background (Opus)",
        "dispatch": "cc",
        "cc_model": "Opus",
        "model_tier": "cc",
    },
    "8_ego_compaction": {
        "description": "Ego-internal rolling summary compactor. Folds old ego_cycles outputs into a single compacted_summary in ego_state so long-running ego memory stays bounded. NOT Genesis-wide memory consolidation — that is the dream cycle (call site: dream_cycle_synthesis, weekly Sunday 3am). Only caller: ego/compaction.py:54. Note: 8_user_ego_compaction and 8_genesis_ego_compaction are observability labels (NOT routing IDs) — see runtime/init/ego.py:86,157.",
        "category": "processing",
        "frequency": "Daily",
        "model_tier": "slm",
        "status_reason": "WIRED",
    },
    "9_fact_extraction": {
        "description": "Extracts structured facts (entities, dates, relationships) from unstructured input during ingestion.",
        "category": "processing",
        "frequency": "Per ingestion",
        "model_tier": "slm",
    },
    "11_user_model_synthesis": {
        "description": "LLM-narrative user knowledge synthesis. Every 48h the user_model_evolver job in runtime/init/learning.py calls router.route_call('11_user_model_synthesis', ...) with the current model dict + recent delta evidence, and writes the narrative to USER_KNOWLEDGE.md. Falls back to rules-based dict rendering when all free providers are exhausted.",
        "category": "reasoning",
        "frequency": "Every 48h (via user_model_evolution job)",
        "model_tier": "slm",
    },
    "12_surplus_brainstorm": {
        "description": "Brainstorm sessions during idle compute. Uses reflection pipeline (Depth.LIGHT) with free APIs. Tracks separately from light reflections.",
        "category": "content",
        "frequency": "Opportunistic",
        "cost_policy": "Free only (never pays)",
        "model_tier": "slm",
    },
    "13_morning_report": {
        "description": "Compiles overnight system health, observations, and pending items into a daily morning report.",
        "category": "content",
        "frequency": "Daily",
        "model_tier": "slm",
    },
    "14_weekly_self_assessment": {
        "description": "Honest self-evaluation of Genesis's recent performance. Dispatched via CC background session (Sonnet).",
        "category": "reasoning",
        "frequency": "Weekly",
        "cost_policy": "CC background (Sonnet)",
        "dispatch": "cc",
        "cc_model": "Sonnet",
        "model_tier": "cc",
    },
    "16_quality_calibration": {
        "description": "Audits recent LLM outputs for quality regression and consistency. Dispatched via CC background session (Sonnet).",
        "category": "calibration",
        "frequency": "Weekly",
        "cost_policy": "CC background (Sonnet)",
        "dispatch": "cc",
        "cc_model": "Sonnet",
        "model_tier": "cc",
    },
    "21_embeddings": {
        "description": "Write-path: embeds text via local Ollama before storing to Qdrant. Uses qwen3-embedding (0.6B).",
        "category": "embedding",
        "frequency": "On memory store",
        "cost_policy": "Free (local)",
        "model_tier": "embedding",
    },
    "21b_query_embedding": {
        "description": "Read-path: embeds search queries via cloud provider for Qdrant recall. DeepInfra-primary, DashScope/Ollama fallback.",
        "category": "embedding",
        "frequency": "On memory recall",
        "cost_policy": "Cloud embedding API",
        "model_tier": "embedding",
    },
    "23_outreach_review": {
        "description": "Cross-vendor review of outreach messages before sending. Free chain (Gemini/Groq/Mistral). Scores 1-5; approves if >= min_score. Distinct from 17_executor_review which is the executor's Gate 2 (paid chain). Renamed from 23_fresh_eyes_review 2026-05-10.",
        "category": "assessment",
        "frequency": "Per outreach message",
        "model_tier": "slm",
        "status_reason": "WIRED",
        "see_also": ["17_executor_review"],
    },
    "29_retrospective_triage": {
        "description": "THE LIVE triage classifier. Per interaction outcome, classifies an InteractionSummary into TriageDepth (0=SKIP through 4=FULL_PLUS_WORKAROUND). Output drives the learning pipeline depth. NOT to be confused with 2_triage (removed), 30_triage_calibration (calibration), or outreach_email_triage (outreach domain).",
        "category": "classification",
        "frequency": "Per outcome",
        "model_tier": "slm",
        "status_reason": "WIRED",
        "see_also": ["2_triage", "30_triage_calibration", "outreach_email_triage"],
    },
    "30_triage_calibration": {
        "description": "Daily calibration of the 29_retrospective_triage classifier — reviews recent outputs for under/over-classification, regenerates TRIAGE_CALIBRATION.md few-shot examples and rules. Does NOT classify interactions itself; it tunes the classifier.",
        "category": "calibration",
        "frequency": "Weekly",
        "model_tier": "mid",
        "status_reason": "WIRED",
        "see_also": ["2_triage", "29_retrospective_triage", "outreach_email_triage"],
    },
    "31_outcome_classification": {
        "description": "Classifies task outcomes (success/partial/failure) for the learning and retrospective pipeline.",
        "category": "processing",
        "frequency": "Per outcome",
        "model_tier": "mid",
    },
    "32_delta_assessment": {
        "description": "Assesses changes between cognitive state snapshots to detect drift and track evolution.",
        "category": "processing",
        "frequency": "Daily",
        "model_tier": "mid",
    },
    "34_research_synthesis": {
        "description": "Synthesizes multi-source research results into concise summaries. Called by research orchestrator.",
        "category": "content",
        "frequency": "On demand",
        "model_tier": "slm",
    },
    "35_content_draft": {
        "description": "Drafts content for Telegram, email, and other platforms via ContentDrafter. Free models.",
        "category": "content",
        "frequency": "On demand",
        "model_tier": "slm",
    },
    "36_code_auditor": {
        "description": "Surplus task: reviews codebase for bugs, quality issues, and improvement opportunities during idle time.",
        "category": "surplus",
        "frequency": "Opportunistic (idle time)",
        "model_tier": "mid",
    },
    "cc_update_analysis": {
        "description": "Analyzes Claude Code version changelogs for impact on Genesis integrations and hooks.",
        "category": "processing",
        "frequency": "On CC update detection",
        "model_tier": "slm",
    },
    "outreach_email_triage": {
        "description": "Gemini-primary light filter for weekly email batch. Classifies emails by relevance and urgency. Outreach domain — distinct from the learning-pipeline triage sites (29_retrospective_triage, 30_triage_calibration). Renamed from email_triage 2026-05-10 (disambiguates the triage namespace).",
        "category": "classification",
        "frequency": "Per email batch",
        "cost_policy": "Free only (never pays)",
        "model_tier": "slm",
        "status_reason": "WIRED",
        "see_also": ["2_triage", "29_retrospective_triage", "30_triage_calibration"],
    },
    "bookmark_enrichment": {
        "description": "Generates rich summaries of shelved sessions for bookmarks. Routes through 33_skill_refiner chain (free APIs). Runs during surplus idle time.",
        "category": "content",
        "frequency": "On bookmark enrichment",
        "model_tier": "slm",
    },
    "embedding_recovery": {
        "description": "Drains pending FTS5-only memories to Qdrant when embedding provider recovers. Background recovery worker.",
        "category": "embedding",
        "frequency": "On provider recovery",
        "model_tier": "embedding",
    },
    "contribution_gate": {
        "description": "Evaluates whether a community code fix is already upstream before creating a PR. Part of the contribution pipeline.",
        "category": "assessment",
        "frequency": "Per landed fix commit (contribution pipeline)",
        "cost_policy": "Free primary, paid fallback",
        "model_tier": "slm",
        "status_reason": "WIRED",
    },
    # ── PARTIALLY WIRED: code exists, conditions haven't triggered yet ─
    "27_pre_execution_assessment": {
        "description": "Sanity-checks proposed task execution plans before committing resources. Opus via CC invoker, route_call fallback.",
        "category": "reasoning",
        "frequency": "Per task",
        "model_tier": "cc",
        "dispatch": "cli",
        "cc_model": "Opus",
        "wired": True,
    },
    "33_skill_refiner": {
        "description": "Proposes improvements to Genesis's learned skills based on recent outcomes. Part of the learning pipeline.",
        "category": "content",
        "frequency": "Periodic",
        "model_tier": "slm",
    },
    "38_procedure_extraction": {
        "description": "Extracts reusable procedures from interaction outcomes (success path + failures). Part of the learning pipeline.",
        "category": "content",
        "frequency": "On demand",
        "model_tier": "mid",
    },
    "contingency_foreground": {
        "description": "API-based foreground conversation fallback when CC is rate-limited or unavailable.",
        "category": "reasoning",
        "frequency": "On CC rate limit",
        "model_tier": "frontier",
    },
    "contingency_micro": {
        "description": "Free API-based Micro reflection fallback when CC is rate-limited or unavailable. Used only for cheap periodic awareness-loop ticks where free SLMs are acceptable.",
        "category": "processing",
        "frequency": "On CC rate limit",
        "cost_policy": "Free only (never pays)",
        "model_tier": "slm",
    },
    # ── GROUNDWORK: config exists, no code invokes them yet ───────────
    "2_triage": {
        "description": "REMOVED FROM YAML 2026-05-10. Was: original threshold-based triage of awareness-tick signals. Never wired in code; superseded by deterministic threshold math in awareness/loop.py:classify_depth(). Meta entry retained for historical reference; routing chain definition removed from config/model_routing.yaml.",
        "category": "classification",
        "frequency": "Was: every 5 min",
        "model_tier": "slm",
        "wired": False,
        "status_reason": "DEPRECATED_REMOVED",
        "see_also": ["29_retrospective_triage", "30_triage_calibration", "outreach_email_triage"],
    },
    "7_ego_cycle": {
        "description": "Persistent ego session — CLI-only dispatch with --resume continuity and MCP tool access.",
        "category": "reasoning",
        "frequency": "Per ego cycle",
        "cost_policy": "CC background (Opus)",
        "dispatch": "cli",
        "cc_model": "Opus",
        "model_tier": "cc",
        "wired": True,
    },
    "7_task_retrospective": {
        "description": "REMOVED FROM YAML 2026-05-10. Was: root-cause classification of completed executor tasks. DUPLICATE — the executor went live with 43_task_retrospective (autonomy/executor/trace.py:24) and this entry was forgotten. Meta entry retained for historical reference; routing chain definition removed.",
        "category": "processing",
        "frequency": "Was: per task",
        "model_tier": "slm",
        "wired": False,
        "status_reason": "DEPRECATED_REMOVED",
        "see_also": ["43_task_retrospective"],
    },
    "10_cognitive_state": {
        "description": "V4 placeholder. Cognitive state IS actively maintained today via direct DB writes (awareness/loop.py, cc/reflection_bridge*.py) — NOT this call site. The YAML entry reserves a routing chain for a future LLM-summary regeneration feature; no current consumers route through it.",
        "category": "reasoning",
        "frequency": "Daily (via direct DB writes, not this call site)",
        "model_tier": "frontier",
        "wired": False,
        "status_reason": "WIRED_DIFFERENT_MECHANISM",
    },
    "17_executor_review": {
        "description": "Cross-vendor quality review of executor deliverables (Gate 2 of the 3-gate executor verification pipeline). PAID chain: DeepSeek V4 Pro primary, Qwen 3.6+ fallback via OpenRouter. Distinct from 23_outreach_review which is the outreach pre-send check (free chain). Renamed from 17_fresh_eyes_review 2026-05-10.",
        "category": "assessment",
        "frequency": "Per task verification",
        "model_tier": "frontier",
        "wired": True,
        "status_reason": "WIRED",
        "see_also": ["23_outreach_review"],
    },
    "18_meta_prompting": {
        "description": "V4 placeholder. Pre-reflection prompt engineering. Never wired; reserved for future adaptive-prompting work. Remove from YAML if V4 design drops the feature.",
        "category": "calibration",
        "frequency": "Per reflection",
        "model_tier": "slm",
        "wired": False,
        "status_reason": "V4_PLACEHOLDER",
    },
    "20_adversarial_counterargument": {
        "description": "Devil's advocate review of executor deliverables (Gate 3). GPT 5.5 primary, DeepSeek V4 Pro + Qwen 3.6+ fallback via OpenRouter.",
        "category": "assessment",
        "frequency": "Per task verification",
        "model_tier": "frontier",
        "wired": True,
    },
    "22_tagging": {
        "description": "V4 placeholder. Entity extraction and metadata tagging for the knowledge graph. No live consumers today; chain is prep for the future memory-consolidation pipeline (potential SLM bundle target — see plan).",
        "category": "classification",
        "frequency": "Per input",
        "model_tier": "slm",
        "wired": False,
        "status_reason": "V4_PLACEHOLDER",
    },
    "dream_cycle_synthesis": {
        "description": "Dream cycle cluster-merge synthesis. Consolidates near-duplicate episodic memories into canonical records. Weekly Sunday 3am via CronTrigger.",
        "category": "consolidation",
        "frequency": "Weekly batch (Sunday 3am, max 100 clusters/run)",
        "model_tier": "slm",
        "wired": True,
    },
    "28_observation_sweep": {
        "description": "Functionally replaced by awareness loop's signal collection (awareness/loop.py:perform_tick). Kept as historical reference; no live consumers route through this call site.",
        "category": "processing",
        "frequency": "Per awareness tick (replaced)",
        "model_tier": "frontier",
        "wired": False,
        "status_reason": "REPLACED_BY_AWARENESS_LOOP",
    },
    "37_infrastructure_monitor": {
        "description": "Temporarily disabled in commit ff2198c (2026-05-03). Sentinel infrastructure (src/genesis/sentinel/monitor.py) remains in place. Disable reason: output quality from free-model providers was too low for surplus dispatch. Rework pending: requires higher-tier providers and tighter prompting before re-enable.",
        "category": "surplus",
        "frequency": "Disabled (was: opportunistic via deep reflection)",
        "model_tier": "slm",
        "wired": False,
        "status_reason": "TEMP_DISABLED",
    },
    "outreach_fallback": {
        "description": "Deferred outreach delivery retry. Enqueue path active (pipeline.py:335), but consumer NOT BUILT — deferred messages silently marked completed without retry. CRITICAL BUG: needs consumer implementation.",
        "category": "content",
        "frequency": "On outreach failure",
        "model_tier": "slm",
    },
    "40_knowledge_distillation": {
        "description": "Distills ingested knowledge sources into atomic units. Parallelized across provider chain via chain_offset.",
        "category": "processing",
        "frequency": "Per ingestion",
        "model_tier": "slm",
        "parallelized": True,
    },
    "43_task_retrospective": {
        "description": "Executor's post-execution retrospective. Per completed executor task, classifies the task trace and produces structured retrospective data that feeds the learning pipeline and ego context. Live caller: autonomy/executor/trace.py:24 (_CALL_SITE constant) and :202. Distinct from 7_task_retrospective which was a duplicate (removed from YAML 2026-05-10).",
        "category": "processing",
        "frequency": "Per executor task completion",
        "model_tier": "frontier",
        "wired": True,
        "status_reason": "WIRED",
        "see_also": ["7_task_retrospective"],
    },
    "autonomous_executor_reasoning": {
        "description": "Non-tooling reasoning for autonomous executor steps (research/analysis/synthesis). API-first via AutonomousDispatchRouter.",
        "category": "reasoning",
        "frequency": "Per executor step",
        "model_tier": "frontier",
        "wired": True,
    },
}
