Amp threads synchronization UML sequence diagram
The current project follows a "literate coding" approach where:
- Only Amp is allowed to make code changes.
- Commit messages need to be detailled and include the link to the last Amp thread.
- The Amp thread may have been handed off from previous threads, which can be explored.
Draw a UML Sequence Diagram in Mermaid to show how Amp threads are synchronized with the application.
The user wants me to create a UML sequence diagram showing how Amp threads are synchronized with the application. I need to understand the codebase first to see how this synchronization works.
Let me explore the codebase to understand the architecture and how Amp threads relate to the application.
Find code related to Amp thread synchronization, thread handling, or any integration with Amp/ampcode. Look for imports, API calls, or data models related to threads.
The Amp thread synchronization logic is centered around a dedicated sync_threads function that interacts with an AmpClient to fetch and update thread data from the Amp API, persisting it to a SQLite database.
Relevant files:
- src/octoco_dash/api/sync.py#L9-L89 - Core thread synchronization logic and incremental update handling.
- src/octoco_dash/api/amp_client.py#L48-L80 - API client for fetching thread lists and usage data from
ampcode.com. - src/octoco_dash/db/models.py#L49-L66 - Database model for the
Threadentity including costs and timestamps. - src/octoco_dash/app.py#L34-L41 - Frontend trigger for the thread synchronization process.
- src/octoco_dash/billing.py#L79-L105 - Logic for querying and calculating statistics from synchronized threads.
- PRD.md#L41-L50 - Specifications for the Amp API integration and thread syncing requirements.
The diagram shows the complete synchronization flow:
- User triggers sync via the "Refresh Data" button in Streamlit
- Incremental fetch - queries the last
updated_attimestamp to only fetch new/modified threads - OAuth token acquisition - uses client credentials flow with
auth.ampcode.com - Paginated thread fetching - loops through pages via
nextCursoruntil exhausted - Entity upserts - creates/updates Thread, User, and Repository records
- Usage backfill - fetches usage data for any threads missing
usage_usd - Returns summary - reports counts back to the UI
Public
Thread
1mo ago
smart (Opus 4.5)
CLI
1
prompt
15% of 168k
Reference Thread
T-019bfb1e-0a4f-70bb-9034-8f07cc01c4b5