Skip to content

Morpheus drain · detailed

flowchart TD
  subgraph TRIG["Trigger · endless_dreaming.py (runs in API)"]
    direction TB
    DAEMON["EndlessDreamingDaemon.run_forever<br/>run_cycle · ~5s loop · flock singleton"]
    STDG["engineering-standards gate"]
    BUDG["budget eval · 5h + weekly token windows"]
    NEXT["_next_task → drain_pending_todos"]
    DAEMON --> STDG --> BUDG --> NEXT
  end
  subgraph SM["Drain V2 state machine · morpheus_drain_phases.py"]
    direction TB
    P0["pending"]
    P1["planning · build_planning_prompt"]
    P2["coding · build_coding_prompt"]
    P3["critic · opt · morpheus_drain_critic"]
    P4["smoke · configured cmd · ≤3 retries"]
    P5["browser · Playwright screenshot"]
    P6["pre-PR gate · HR11"]
    P7["pr-open"]
    P8["done"]
    PB["blocked"]
    P0 --> P1 --> P2 --> P3 --> P4 --> P5 --> P6 --> P7 --> P8
    P2 -.blocker.-> PB
    PB -.operator reply.-> P2
  end
  subgraph CX["Codex agent · morpheus_drain_codex.py"]
    direction TB
    CXCMD["codex exec --json · gpt-5.5 · xhigh"]
    CXWR["write / edit / shell"]
    CXCMD --> CXWR
  end
  subgraph GATE["Operator-Authority gate · HR11"]
    direction TB
    GW["per-write gate · operator_authority/gate.py"]
    PRG["pre-PR gate · morpheus_pre_pr_gate<br/>runs repo CI · fail-closed"]
  end
  subgraph STATE["State + persistence · run/morpheus-drain-state"]
    direction TB
    DS["DrainState T#.json<br/>phase · branch · plan_text · codex_stream · pr_url · iteration ≤50"]
    TOK["token-usage.jsonl ledger"]
    MEMS["morpheus_memory_store · SQLite · decay sweep"]
    PATCH["todo-timestamp.patch"]
    DS ~~~ TOK ~~~ MEMS ~~~ PATCH
  end
  subgraph WS["Workspace · stm-morpheus-workspace-sync"]
    direction TB
    SYNC["git fetch --prune loop · ~300s"]
    VOL["morpheus_workspace volume · shared"]
    SYNC --> VOL
  end
  TODOS[("world.todos · #morpheus")]
  GH["GitHub · git push + gh pr create · build_pr_body"]
  OP["Operator · review / merge"]
  DASHV["Dashboard · DrainEventEmitter<br/>self-code / morpheus tab"]
  TGQ["Telegram · question router · blocked-resume"]
  NEXT --> P0
  TODOS -.read #morpheus.-> P0
  P1 --> CXCMD
  P2 --> CXCMD
  CXWR --> GW
  GW -.allow / deny.-> CXWR
  P6 --> PRG
  P7 --> GH
  GH --> OP
  VOL -.repo clone.-> CXCMD
  P2 -.state.-> DS
  CXCMD -.tokens.-> TOK
  P5 -.events.-> DASHV
  PB -.question.-> TGQ
  TGQ -.reply.-> OP
  style TRIG fill:#f5f4f2,stroke:#78716c,stroke-width:2px,color:#78716c
  style SM fill:#fdf2f8,stroke:#be185d,stroke-width:2px,color:#be185d
  style CX fill:#f5f4f2,stroke:#78716c,stroke-width:2px,color:#78716c
  style GATE fill:#eef0ff,stroke:#4338ca,stroke-width:2px,color:#4338ca
  style STATE fill:#f4f1ff,stroke:#7c5cff,stroke-width:2px,color:#7c5cff
  style WS fill:#f5f4f2,stroke:#78716c,stroke-width:2px,color:#78716c
  classDef mN fill:#ffffff,stroke:#be185d,color:#27272a,stroke-width:1px
  classDef supN fill:#ffffff,stroke:#78716c,color:#27272a,stroke-width:1px
  classDef aaN fill:#ffffff,stroke:#4338ca,color:#27272a,stroke-width:1px
  classDef stN fill:#ffffff,stroke:#7c5cff,color:#27272a,stroke-width:1px
  classDef exN fill:#ffffff,stroke:#475569,color:#27272a,stroke-width:1px
  class P0,P1,P2,P3,P4,P5,P6,P7,P8,PB mN
  class DAEMON,STDG,BUDG,NEXT,CXCMD,CXWR,SYNC,VOL supN
  class GW,PRG aaN
  class DS,TOK,MEMS,PATCH,TODOS stN
  class GH,OP,DASHV,TGQ exN