flowchart LR
  subgraph repo["Repo / Forgejo / Git workflow"]
    A["Forgejo / Git remotes<br/>code + legacy file-KB PR flow"]
    B["deploy/auto-deploy.sh<br/>fetch main, syntax-check, rsync runtime dirs"]
    C["VPS runtime dirs<br/>/opt/teleo-eval, /home/teleo profile"]
    A --> B --> C
  end

  subgraph pg["Docker Postgres on VPS 77.42.65.182"]
    D["teleo-pg container<br/>database teleo"]
    E["canonical public.*<br/>claims, sources, claim_evidence, claim_edges<br/>strategies, strategy_nodes, anchors"]
    F["staging kb_stage.*<br/>kb_proposals, pending proposals,<br/>staged/import tables"]
    D --> E
    D --> F
  end

  subgraph load["KB loading and apply"]
    G["Leo / user / operator request"]
    H["teleo-kb bridge or proposal generator"]
    I["kb_stage.kb_proposals<br/>pending_review"]
    J["reviewer/operator approval<br/>approved"]
    K["strict apply_payload or reviewed packet"]
    L["guarded apply<br/>kb_apply/operator"]
    M["ledger stamped applied<br/>canonical readback"]
    G --> H --> I --> J --> K --> L --> E --> M
    I -. "not canonical yet" .-> F
  end

  subgraph self["Agent self-update loop"]
    N["Leo reads canonical context<br/>Postgres first, not runtime memory"]
    O["Leo proposes self/strategy change<br/>revise_strategy"]
    P["apply updates strategies/nodes"]
    Q["renderer/context refresh<br/>Leo reads new self"]
    E --> N --> O --> I
    L --> P --> Q --> N
  end

  C --> H
  C --> D
  A -. "confirmed code/file workflow provenance<br/>direct live DB bootstrap unknown" .-> D
