@startuml
title SmartTools Workflow

actor Developer as Dev
participant CLI
participant "API Server" as API
participant Gitea
database "Local FS" as FS
actor Maintainer

box "A. Publishing a Tool"
    Dev -> CLI: publish ./tool/
    CLI -> CLI: validate locally
    CLI -> API: POST /tools
    API -> Gitea: Create branch
    API -> Gitea: Create PR
    Gitea --> API: {"pr_url": "..."}
    API --> CLI
    CLI --> Dev: "PR created, pending review"
end box

box "B. Installing a Tool"
    Dev -> CLI: install summarize
    CLI -> API: GET /tools/summarize
    API --> CLI: {config: "yaml..."}
    CLI -> FS: write config.yaml
    CLI -> FS: generate wrapper script
    CLI --> Dev: "Installed summarize v1.2.0"
end box

box "C. Sync on Merge (keeping API in sync with repo)"
    Maintainer -> Gitea: Merge PR
    Gitea -> API: POST /webhook/gitea
    API -> Gitea: git pull
    Gitea --> API: (repo contents)
    API -> API: parse tools/
    API -> Database: UPDATE tools
    API -> Database: rebuild search idx
end box

@enduml