# oxbshw/watch-skill architecture

> Architecture diagram of the GitHub repository oxbshw/watch-skill, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/oxbshw/watch-skill
- Repository: https://github.com/oxbshw/watch-skill

## Overview

#### Purpose and Entry Points
Watch Skill is a Python 3.11+ video-memory and agent-verification engine. It converts media, streams, meetings, and screen recordings into a persistent timestamped evidence index, then supports retrieval, answering, extraction, and self-verification loops.

Primary surfaces share the core: CLI (`src/watch_skill/surfaces/cli/main.py`), stdio MCP server (`src/watch_skill/surfaces/mcp/server.py`), REST application (`src/watch_skill/surfaces/api/app.py`), and framework adapters (`src/watch_skill/integrations/_core.py`).

#### 1. Orchestration and Shared Contracts
The top-level watch workflow coordinates acquisition, perception, transcription, indexing, and reporting. Batch and background-style work are represented separately.
- `src/watch_skill/watch.py`
- `src/watch_skill/jobs.py`
- `src/watch_skill/batch.py`

Configuration and explicit domain errors form cross-cutting boundaries for storage, privacy, providers, budgets, and user-facing repair paths.
- `src/watch_skill/config.py`
- `src/watch_skill/errors.py`

#### 2. Media Acquisition Boundary
Acquisition normalizes heterogeneous inputs—local/direct media, supported hosted sources, and streams—into common media/source types. Resolver logic selects download mechanisms; cache prevents unnecessary reacquisition.
- `src/watch_skill/acquire/resolver.py`
- `src/watch_skill/acquire/sources.py`
- `src/watch_skill/acquire/cache.py`

External runtime dependencies include download tooling such as yt-dlp and Cobalt-compatible acquisition, represented by `src/watch_skill/acquire/ytdlp.py` and `src/watch_skill/acquire/cobalt.py`.

#### 3. Perception and Transcription Pipeline
Media is processed into scene-aware frames, OCR evidence, and timestamped transcript segments. Perception uses budget controls and scene/deduplication logic before costly visual interpretation.
- `src/watch_skill/perceive/engine.py`
- `src/watch_skill/perceive/scenes.py`
- `src/watch_skill/perceive/ocr_backends.py`

Transcription follows a provider ladder: captions/VTT and local audio processing first, with optional cloud speech services and diarization.
- `src/watch_skill/transcribe/ladder.py`
- `src/watch_skill/transcribe/local.py`
- `src/watch_skill/transcribe/cloud.py`

#### 4. Persistent Evidence Index and Retrieval
The index persists videos, frames, transcripts, OCR, embeddings, and usage data. Retrieval combines full-text and vector search, with multilingual normalization as a core retrieval concern.
- `src/watch_skill/index/db.py`
- `src/watch_skill/index/store.py`
- `src/watch_skill/index/retrieval.py`

Embedding generation is isolated from storage/query logic, allowing provider/model evolution without changing the evidence model.
- `src/watch_skill/index/embeddings.py`
- `src/watch_skill/index/textnorm.py`

#### 5. Evidence-Grounded Answering and Derived Knowledge
The answer engine retrieves indexed evidence, applies a cost/quality ladder, localizes supporting moments, and returns confidence-aware cited answers. Crops provide focused visual evidence when needed.
- `src/watch_skill/answer/engine.py`
- `src/watch_skill/answer/ladder.py`
- `src/watch_skill/answer/localize.py`

Structured extraction and cross-video library synthesis consume the same index rather than reprocessing source media.
- `src/watch_skill/extract/chapters.py`
- `src/watch_skill/library/synthesize.py`

Lessons capture reported mistakes, classify applicability, inject corrections into later work, and support replayable evaluations.
- `src/watch_skill/lessons/store.py`
- `src/watch_skill/lessons/inject.py`

#### 6. Vision Provider Boundary
Visual QA is provider-pluggable behind a client/model registry, with pricing and cost accounting separated from pipeline behavior. It supports hosted vendors, OpenAI-compatible endpoints, and local Ollama-style operation.
- `src/watch_skill/vision/client.py`
- `src/watch_skill/vision/registry.py`
- `src/watch_skill/vision/cost.py`

#### 7. THE LOOP Verification Subsystem
THE LOOP is a parallel capture → critique → iteration → proof flow for browser, desktop/window, generated-video, game, and monitored-stream work. Capture artifacts and diffs are evaluated against plain-language criteria; results can be indexed and rendered for review.
- `src/watch_skill/loop/runner.py`
- `src/watch_skill/loop/capture.py`
- `src/watch_skill/loop/critic.py`

Reporting/viewing is an output boundary: standalone evidence reports and loop viewers package artifacts for sharing without requiring a live service.
- `src/watch_skill/viewer.py`
- `src/watch_skill/loop/viewer.py`

#### Runtime and Infrastructure
The package runs locally via Python/uv/pipx, optionally in Docker (`Dockerfile`). Local-first processing uses media/OCR/transcription binaries and models; health commands diagnose and bootstrap these dependencies.
- `src/watch_skill/health/doctor.py`
- `src/watch_skill/health/binaries.py`

Persistent local storage is central to reuse and offline workflows. Network calls are limited to acquisition sources and opt-in vision/cloud-transcription providers; MCP uses stdio, while REST is an optional HTTP service.

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_surfaces["Entry surfaces"]
  node_cli["CLI<br/>command surface<br/>[main.py]"]
  node_mcp["MCP server<br/>stdio surface<br/>[server.py]"]
  node_api["REST app<br/>HTTP surface<br/>[app.py]"]
  node_adapters["Framework adapters<br/>integration boundary<br/>[_core.py]"]
end

subgraph group_pipeline["Media pipeline"]
  node_watch{{"Watch workflow<br/>orchestrator<br/>[watch.py]"}}
  node_jobs["Jobs<br/>background work<br/>[jobs.py]"]
  node_batch["Batch processing<br/>batch work<br/>[batch.py]"]
  node_acquisition["Media acquisition<br/>source normalization<br/>[resolver.py]"]
  node_acquire_providers["Download providers<br/>external tooling<br/>[ytdlp.py]"]
  node_perception["Perception<br/>scene and OCR pipeline<br/>[engine.py]"]
  node_transcription["Transcription ladder<br/>speech pipeline<br/>[ladder.py]"]
  node_vision["Vision providers<br/>provider boundary<br/>[client.py]"]
end

subgraph group_evidence["Evidence and answers"]
  node_evidence_store[("Evidence store<br/>persistent index<br/>[store.py]")]
  node_retrieval["Hybrid retrieval<br/>search engine<br/>[retrieval.py]"]
  node_embeddings["Embeddings<br/>embedding provider layer<br/>[embeddings.py]"]
  node_answer{{"Evidence-grounded answers<br/>answer engine<br/>[engine.py]"}}
  node_derived["Extraction and synthesis<br/>derived knowledge<br/>[chapters.py]"]
  node_lessons["Lessons<br/>correction memory<br/>[inject.py]"]
end

subgraph group_verification["THE LOOP"]
  node_loop{{"Verification runner<br/>capture-critique loop<br/>[runner.py]"}}
  node_reports["Reports and viewers<br/>offline output<br/>[viewer.py]"]
end

node_health["Health checks<br/>runtime diagnostics<br/>[doctor.py]"]
node_config["Configuration and errors<br/>cross-cutting contracts<br/>[config.py]"]

node_cli -->|"runs"| node_watch
node_mcp -->|"invokes"| node_watch
node_api -->|"serves"| node_watch
node_adapters -->|"adapts"| node_watch
node_watch -->|"schedules"| node_jobs
node_batch -->|"processes collections"| node_watch
node_watch -->|"acquires"| node_acquisition
node_acquisition -->|"downloads via"| node_acquire_providers
node_watch -->|"extracts visual evidence"| node_perception
node_watch -->|"creates transcripts"| node_transcription
node_perception -.->|"uses visual QA"| node_vision
node_perception -->|"stores frames and OCR"| node_evidence_store
node_transcription -->|"stores segments"| node_evidence_store
node_evidence_store -->|"indexes content"| node_embeddings
node_embeddings -->|"supports vector search"| node_retrieval
node_evidence_store -->|"serves evidence"| node_retrieval
node_retrieval -->|"retrieves citations"| node_answer
node_lessons -->|"injects corrections"| node_answer
node_evidence_store -->|"reuses indexed evidence"| node_derived
node_loop -->|"indexes proof artifacts"| node_evidence_store
node_loop -->|"renders review artifacts"| node_reports
node_answer -->|"exports evidence reports"| node_reports
node_config -.->|"governs"| node_watch
node_health -.->|"checks runtime tooling"| node_acquisition

click node_cli "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/surfaces/cli/main.py"
click node_mcp "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/surfaces/mcp/server.py"
click node_api "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/surfaces/api/app.py"
click node_adapters "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/integrations/_core.py"
click node_watch "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/watch.py"
click node_jobs "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/jobs.py"
click node_batch "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/batch.py"
click node_acquisition "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/acquire/resolver.py"
click node_acquire_providers "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/acquire/ytdlp.py"
click node_perception "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/perceive/engine.py"
click node_transcription "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/transcribe/ladder.py"
click node_vision "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/vision/client.py"
click node_evidence_store "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/index/store.py"
click node_retrieval "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/index/retrieval.py"
click node_embeddings "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/index/embeddings.py"
click node_answer "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/answer/engine.py"
click node_derived "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/extract/chapters.py"
click node_lessons "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/lessons/inject.py"
click node_loop "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/loop/runner.py"
click node_reports "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/viewer.py"
click node_health "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/health/doctor.py"
click node_config "https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/config.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_mcp,node_api,node_adapters toneBlue
class node_watch,node_jobs,node_batch,node_acquisition,node_acquire_providers,node_perception,node_transcription,node_vision toneAmber
class node_evidence_store,node_retrieval,node_embeddings,node_answer,node_derived,node_lessons toneMint
class node_loop,node_reports toneRose
class node_health,node_config toneNeutral
```

## Components

### Entry surfaces

- [CLI](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/surfaces/cli/main.py): command surface · `src/watch_skill/surfaces/cli/main.py`
- [MCP server](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/surfaces/mcp/server.py): stdio surface · `src/watch_skill/surfaces/mcp/server.py`
- [REST app](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/surfaces/api/app.py): HTTP surface · `src/watch_skill/surfaces/api/app.py`
- [Framework adapters](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/integrations/_core.py): integration boundary · `src/watch_skill/integrations/_core.py`

### Media pipeline

- [Watch workflow](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/watch.py): orchestrator · Coordinates ingestion through reporting. · `src/watch_skill/watch.py`
- [Jobs](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/jobs.py): background work · `src/watch_skill/jobs.py`
- [Batch processing](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/batch.py): batch work · `src/watch_skill/batch.py`
- [Media acquisition](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/acquire/resolver.py): source normalization · Resolves sources and reuses cached media. · `src/watch_skill/acquire/resolver.py`
- [Download providers](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/acquire/ytdlp.py): external tooling · yt-dlp and Cobalt-compatible download mechanisms. · `src/watch_skill/acquire/ytdlp.py`
- [Perception](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/perceive/engine.py): scene and OCR pipeline · Budgets, scene selection, deduplication, and OCR evidence. · `src/watch_skill/perceive/engine.py`
- [Transcription ladder](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/transcribe/ladder.py): speech pipeline · Captions/local audio first, then optional cloud speech. · `src/watch_skill/transcribe/ladder.py`
- [Vision providers](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/vision/client.py): provider boundary · Pluggable visual QA clients with isolated cost accounting. · `src/watch_skill/vision/client.py`

### Evidence and answers

- [Evidence store](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/index/store.py): persistent index · Persists media evidence, embeddings, and usage data. · `src/watch_skill/index/store.py`
- [Hybrid retrieval](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/index/retrieval.py): search engine · Combines full-text, vector search, and multilingual normalization. · `src/watch_skill/index/retrieval.py`
- [Embeddings](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/index/embeddings.py): embedding provider layer · `src/watch_skill/index/embeddings.py`
- [Evidence-grounded answers](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/answer/engine.py): answer engine · Returns localized, confidence-aware cited answers. · `src/watch_skill/answer/engine.py`
- [Extraction and synthesis](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/extract/chapters.py): derived knowledge · Builds chapters and cross-video library knowledge from the index. · `src/watch_skill/extract/chapters.py`
- [Lessons](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/lessons/inject.py): correction memory · Injects reported corrections and supports replayable evaluation. · `src/watch_skill/lessons/inject.py`

### THE LOOP

- [Verification runner](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/loop/runner.py): capture-critique loop · Iterates capture, critique, and proof against plain-language criteria. · `src/watch_skill/loop/runner.py`
- [Reports and viewers](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/viewer.py): offline output · Packages evidence and loop artifacts for review. · `src/watch_skill/viewer.py`

### Other components

- [Health checks](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/health/doctor.py): runtime diagnostics · Diagnoses and bootstraps local binaries and models. · `src/watch_skill/health/doctor.py`
- [Configuration and errors](https://github.com/oxbshw/watch-skill/blob/main/src/watch_skill/config.py): cross-cutting contracts · Controls providers, privacy, budgets, storage, and repair paths. · `src/watch_skill/config.py`

## Connections

- CLI → Watch workflow: runs
- MCP server → Watch workflow: invokes
- REST app → Watch workflow: serves
- Framework adapters → Watch workflow: adapts
- Watch workflow → Jobs: schedules
- Batch processing → Watch workflow: processes collections
- Watch workflow → Media acquisition: acquires
- Media acquisition → Download providers: downloads via
- Watch workflow → Perception: extracts visual evidence
- Watch workflow → Transcription ladder: creates transcripts
- Perception → Vision providers: uses visual QA
- Perception → Evidence store: stores frames and OCR
- Transcription ladder → Evidence store: stores segments
- Evidence store → Embeddings: indexes content
- Embeddings → Hybrid retrieval: supports vector search
- Evidence store → Hybrid retrieval: serves evidence
- Hybrid retrieval → Evidence-grounded answers: retrieves citations
- Lessons → Evidence-grounded answers: injects corrections
- Evidence store → Extraction and synthesis: reuses indexed evidence
- Verification runner → Evidence store: indexes proof artifacts
- Verification runner → Reports and viewers: renders review artifacts
- Evidence-grounded answers → Reports and viewers: exports evidence reports
- Configuration and errors → Watch workflow: governs
- Health checks → Media acquisition: checks runtime tooling
