# udayanirogi/agent-hygiene architecture

> Architecture diagram of the GitHub repository udayanirogi/agent-hygiene, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/udayanirogi/agent-hygiene
- Repository: https://github.com/udayanirogi/agent-hygiene
- Video tour (about a minute): https://gitdiagram.com/udayanirogi/agent-hygiene/video

## Overview

agent-hygiene is a local macOS/Linux CLI for inventorying coding-agent files, auto-starts, and processes, then previewing safe cleanup with reversible backups. Its main workflow runs from CLI commands through scan and inventory presentation or cleanup planning, application, and undo; separate commands supervise agent runs and check team policy. The graph follows documented CLI behavior and sampled imports/calls. Some command implementations and subsystems are unsampled, so their internal links are limited to README-documented behavior.

Main entry points: [`agent_hygiene/scan/__init__.py`](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/scan/__init__.py) (Inventory orchestrator), [`agent_hygiene/cli.py`](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/cli.py) (Command router), [`agent_hygiene/runner.py`](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/runner.py) (Agent supervisor), [`agent_hygiene/scan/processes.py`](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/scan/processes.py) (Process and ports)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI workflow"]
  node_cli["Command router<br/>[cli.py]"]
  node_render["Inventory output<br/>[output.py]"]
end

subgraph group_inventory["Agent inventory"]
  node_agent_specs["Agent registry<br/>[agents.py]"]
  node_scan["Inventory orchestrator<br/>[__init__.py]"]
  node_footprint["Disk footprints<br/>[footprint.py]"]
  node_autostart["Auto-start scan<br/>[autostart.py]"]
  node_processes["Process and ports<br/>[processes.py]"]
  node_inventory_data["Inventory model<br/>[model.py]"]
end

subgraph group_changes["Cleanup and undo"]
  node_clean["Cleanup planner<br/>[clean.py]"]
  node_policy["Team policy<br/>[policy.py]"]
  node_journal[("Backup journal<br/>[journal.py]")]
  node_restore["Restore and purge<br/>[restore.py]"]
end

subgraph group_supervision["Run supervision"]
  node_runner["Agent supervisor<br/>[runner.py]"]
end

subgraph group_shared["Shared services"]
  node_platform["Platform utilities<br/>[platform.py]"]
end

node_user(("Operator"))
node_agent_cli(("Coding-agent CLI"))
node_host_os["Local OS"]
node_home_state[("Home and backup files")]
node_system_tools["OS process tools"]

node_user -->|"runs command"| node_cli
node_cli -->|"requests inventory"| node_scan
node_scan -->|"iterates agents"| node_agent_specs
node_scan -->|"scans disk"| node_footprint
node_scan -->|"scans entries"| node_autostart
node_scan -->|"scans processes"| node_processes
node_scan -->|"builds inventory"| node_inventory_data
node_footprint -->|"reads agent paths"| node_agent_specs
node_autostart -->|"matches entries"| node_agent_specs
node_processes -->|"matches commands"| node_agent_specs
node_cli -->|"renders results"| node_render
node_render -->|"formats inventory"| node_inventory_data
node_cli -->|"checks policy"| node_policy
node_cli -->|"builds and applies plan"| node_clean
node_clean -->|"gets inventory"| node_scan
node_clean -->|"records changes"| node_journal
node_clean -->|"modifies agent files"| node_home_state
node_journal -->|"stores backups"| node_home_state
node_cli -->|"dispatches undo"| node_restore
node_restore -->|"loads records"| node_journal
node_restore -->|"restores or purges"| node_home_state
node_cli -->|"starts supervisor"| node_runner
node_runner -->|"launches and tracks"| node_agent_cli
node_runner -->|"identifies children"| node_processes
node_runner -->|"writes run reports"| node_home_state
node_scan -->|"reads host details"| node_host_os
node_footprint -->|"uses path helpers"| node_platform
node_autostart -->|"uses OS helpers"| node_platform
node_processes -->|"runs system commands"| node_platform
node_journal -->|"uses private storage"| node_platform
node_runner -->|"uses OS helpers"| node_platform
node_autostart -.->|"queries startup state"| node_system_tools
node_processes -.->|"reads process sockets"| node_system_tools

click node_cli "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/cli.py"
click node_agent_specs "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/agents.py"
click node_scan "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/scan/__init__.py"
click node_footprint "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/scan/footprint.py"
click node_autostart "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/scan/autostart.py"
click node_processes "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/scan/processes.py"
click node_inventory_data "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/model.py"
click node_render "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/output.py"
click node_clean "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/clean.py"
click node_policy "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/policy.py"
click node_journal "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/journal.py"
click node_restore "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/restore.py"
click node_runner "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/runner.py"
click node_platform "https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/platform.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_render toneBlue
class node_agent_specs,node_scan,node_footprint,node_autostart,node_processes,node_inventory_data,node_home_state toneAmber
class node_clean,node_policy,node_journal,node_restore toneMint
class node_runner toneRose
class node_platform,node_user,node_agent_cli,node_host_os,node_system_tools toneIndigo
```

## Components

### CLI workflow

- [Command router](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/cli.py): `agent_hygiene/cli.py`
- [Inventory output](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/output.py): `agent_hygiene/output.py`

### Agent inventory

- [Agent registry](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/agents.py): `agent_hygiene/agents.py`
- [Inventory orchestrator](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/scan/__init__.py): `agent_hygiene/scan/__init__.py`
- [Disk footprints](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/scan/footprint.py): `agent_hygiene/scan/footprint.py`
- [Auto-start scan](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/scan/autostart.py): `agent_hygiene/scan/autostart.py`
- [Process and ports](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/scan/processes.py): `agent_hygiene/scan/processes.py`
- [Inventory model](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/model.py): `agent_hygiene/model.py`

### Cleanup and undo

- [Cleanup planner](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/clean.py): `agent_hygiene/clean.py`
- [Team policy](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/policy.py): `agent_hygiene/policy.py`
- [Backup journal](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/journal.py): `agent_hygiene/journal.py`
- [Restore and purge](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/restore.py): `agent_hygiene/restore.py`

### Run supervision

- [Agent supervisor](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/runner.py): `agent_hygiene/runner.py`

### Shared services

- [Platform utilities](https://github.com/udayanirogi/agent-hygiene/blob/main/agent_hygiene/platform.py): `agent_hygiene/platform.py`

### Other components

- **Operator**
- **Coding-agent CLI**
- **Local OS**
- **Home and backup files**
- **OS process tools**

## Connections

- Operator → Command router: runs command (evidence: `README.md`)
- Command router → Inventory orchestrator: requests inventory (evidence: `agent_hygiene/cli.py`)
- Inventory orchestrator → Agent registry: iterates agents (evidence: `agent_hygiene/scan/__init__.py`)
- Inventory orchestrator → Disk footprints: scans disk (evidence: `agent_hygiene/scan/__init__.py`)
- Inventory orchestrator → Auto-start scan: scans entries (evidence: `agent_hygiene/scan/__init__.py`)
- Inventory orchestrator → Process and ports: scans processes (evidence: `agent_hygiene/scan/__init__.py`)
- Inventory orchestrator → Inventory model: builds inventory (evidence: `agent_hygiene/scan/__init__.py`)
- Disk footprints → Agent registry: reads agent paths (evidence: `agent_hygiene/scan/footprint.py`)
- Auto-start scan → Agent registry: matches entries (evidence: `agent_hygiene/scan/autostart.py`)
- Process and ports → Agent registry: matches commands (evidence: `agent_hygiene/scan/processes.py`)
- Command router → Inventory output: renders results (evidence: `agent_hygiene/cli.py`)
- Inventory output → Inventory model: formats inventory (evidence: `agent_hygiene/output.py`)
- Command router → Team policy: checks policy (evidence: `agent_hygiene/cli.py`)
- Command router → Cleanup planner: builds and applies plan (evidence: `agent_hygiene/cli.py`)
- Cleanup planner → Inventory orchestrator: gets inventory (evidence: `agent_hygiene/cli.py`)
- Cleanup planner → Backup journal: records changes (evidence: `agent_hygiene/clean.py`)
- Cleanup planner → Home and backup files: modifies agent files (evidence: `README.md`)
- Backup journal → Home and backup files: stores backups (evidence: `agent_hygiene/journal.py`)
- Command router → Restore and purge: dispatches undo (evidence: `agent_hygiene/cli.py`)
- Restore and purge → Backup journal: loads records (evidence: `agent_hygiene/restore.py`)
- Restore and purge → Home and backup files: restores or purges (evidence: `README.md`)
- Command router → Agent supervisor: starts supervisor (evidence: `agent_hygiene/cli.py`)
- Agent supervisor → Coding-agent CLI: launches and tracks (evidence: `README.md`)
- Agent supervisor → Process and ports: identifies children (evidence: `agent_hygiene/runner.py`)
- Agent supervisor → Home and backup files: writes run reports (evidence: `README.md`)
- Inventory orchestrator → Local OS: reads host details (evidence: `agent_hygiene/scan/__init__.py`)
- Disk footprints → Platform utilities: uses path helpers (evidence: `agent_hygiene/scan/footprint.py`)
- Auto-start scan → Platform utilities: uses OS helpers (evidence: `agent_hygiene/scan/autostart.py`)
- Process and ports → Platform utilities: runs system commands (evidence: `agent_hygiene/scan/processes.py`)
- Backup journal → Platform utilities: uses private storage (evidence: `agent_hygiene/journal.py`)
- Agent supervisor → Platform utilities: uses OS helpers (evidence: `agent_hygiene/runner.py`)
- Auto-start scan → OS process tools: queries startup state (evidence: `README.md`)
- Process and ports → OS process tools: reads process sockets (evidence: `README.md`)
