refactor: consolidate skill docs, add anti-drift tests, and apply audit fixes

DLO-13: Restructure vlm-library-workflow skill as safety contract layer.
- Rewrite SKILL.md (69 lines): safety contract, execution threshold semantics,
  six-step high-risk loop, decision rules, phase skeleton
- Delete redundant references (cli-reference, workflow, command-recipes, dev-guide)
- Add triage.md (failure mapping + preflight) and dev-map.md (module→test mapping)
- Add tests/test_docs_consistency.py: 78 parametrized tests verifying documented
  vlm commands exist in CLI registry
- Add CSV path mismatch test to test_plan_review.py (4th safety gate path)
- Delete vlm-expert.skill (Gemini package, 7 months stale) and README Gemini section

DLO-2 audit fixes: rate limiter injection, symmetric quarantine categories,
review-plan safety gates, parser improvements, planner validation.

CLI modularization: commands/ directory with one module per command group.
This commit is contained in:
windyboy
2026-09-25 13:50:09 +08:00
parent c7a55190d7
commit dfa18ed405
35 changed files with 1116 additions and 621 deletions
@@ -1,31 +0,0 @@
# Documentation Status
- Updated to current CLI options on 2026-06-01. Default artifact paths are under `artifacts/`.
# VLM CLI Reference
## Configuration
- `vlm config init`: Create default config.
- `vlm config show`: Display current settings.
- `vlm config validate`: Check config for errors.
## Core Commands
- `vlm scan [--output PATH]`: Discover video files.
- `vlm parse [--input CSV] [--output JSON] [--inventory CSV]`: Parse filenames.
- `vlm enrich [--input JSON] [--output JSON] [--refresh-all]`: Fetch TMDB metadata.
- `vlm analyze [--input JSON] [--output JSON]`: Find gaps and duplicates.
- `vlm plan [--input JSON] [--analysis JSON] [--output JSON]`: Generate operations.
- `vlm review-plan [--input JSON] [--output CSV] [--tui]`: Export manual review CSV (optional Textual UI).
- `vlm apply-review [--plan JSON] [--csv PATH]`: Sync edited review CSV into plan.
- `vlm execute [--plan JSON] [--confirm] [--yes] [--verbose-ops] [--safe-mode] [--preserve-directories]`: Move/Rename/Quarantine operations with safety guards.
- `vlm rollback [--log PATH]`: Undo operations.
## Management & Reporting
- `vlm quarantine list|add|restore`: Manage the `.quarantine` directory.
- `vlm report inventory|completeness|duplicates|summary`: Generate human-readable reports.
- `vlm state show|set|query|clear`: Track manual review status for files.
## Important Config Options (`~/.vlm/config.yaml`)
- `library_root`: Path to the video collection.
- `templates`: Naming patterns for movies and series.
- `plan.duplicate_keep`: Strategy for duplicates (`by_quality`, `by_reputation`, `by_reputation_quality_time`, `first_seen`, `manual`).
- `enrichment.api_keys`: TMDB and OpenAI keys.
@@ -1,67 +0,0 @@
# Documentation Status
- Synced with artifacts/ baseline on 2026-06-01.
# VLM Command Recipes
## Baseline
Run from repository root unless the user specifies otherwise.
```bash
vlm --help
vlm config show
vlm config validate
```
If `vlm` is not on PATH:
```bash
uv run vlm --help
uv run vlm config show
uv run vlm config validate
```
## End-to-End Pipeline
Default artifact paths match CLI defaults under `artifacts/`:
```bash
vlm scan
vlm parse --inventory artifacts/inventory.csv
vlm enrich
vlm analyze --inventory artifacts/inventory.csv
vlm plan --analysis artifacts/analysis.json
vlm review-plan --input artifacts/plan.json --output artifacts/plan_manual_review.csv
vlm apply-review
vlm execute
vlm execute --confirm
```
## Artifact Expectations
1. `artifacts/inventory.csv` — discovered files with filesystem and optional ffprobe metadata.
2. `artifacts/identities.json` — parsed identities (v2 when parse used `--inventory`).
3. `artifacts/analysis.json` — completeness gaps and duplicate groups.
4. `artifacts/plan.json` — planned operations (`move`, `rename`, `quarantine`, `no-op`).
5. `artifacts/plan_manual_review.csv` — high-risk rows for human review before `--confirm`.
Do not commit these files to Git.
## Focused Workflows
```bash
vlm parse --inventory artifacts/inventory.csv
vlm analyze --input artifacts/identities.json --output artifacts/analysis.json --inventory artifacts/inventory.csv
vlm plan --input artifacts/identities.json --analysis artifacts/analysis.json --output artifacts/plan.json
vlm rollback
```
## Frequent Failure Triage
1. Missing config: `vlm config init`, set `library_root`.
2. Invalid config: `vlm config validate`.
3. Missing input artifact: run prerequisite stage (scan → parse → analyze → plan).
4. Unexpected duplicate decisions: check `plan.duplicate_keep`, rerun `vlm plan --analysis artifacts/analysis.json`.
5. Unsafe execution: `vlm rollback`, re-run `review-plan` / `apply-review`.
6. `vlm` not found: use `uv run vlm ...`.
7. TMDB rate limits: lower `enrichment.max_concurrency` in config and retry later.
@@ -1,33 +0,0 @@
# Documentation Status
- Updated for the modular command architecture on 2026-02-16.
# VLM Developer Guide
## Project Structure
- `src/vlm/cli.py`: Entry point and thin command wrappers.
- `src/vlm/parser.py`: Regex-based filename parsing logic.
- `src/vlm/enrichment.py`: Pipeline for external metadata fetching.
- `src/vlm/providers/`: API implementations (e.g., TMDB).
- `src/vlm/planner.py`: Logic for mapping identities to filesystem operations.
- `src/vlm/executor.py`: Safe file manipulation and rollback logging.
## Adding a New Command
1. Create a new module in `src/vlm/commands/`.
2. Define the command using `@click.command()`.
3. Register it in `src/vlm/cli.py` with a Click-decorated function that delegates to the module implementation.
## Modifying the Parser
- The parser uses a sequence of regex patterns in `src/vlm/parser.py`.
- Add new patterns to the `PATTERNS` list or improve existing ones.
- Always run `pytest tests/test_parser.py` after changes.
## Data Models
See `src/vlm/models.py` for core data structures:
- `VideoFile`: Basic file metadata.
- `MovieIdentity` / `SeriesIdentity`: Parsed/enriched identity records.
- `FileOperation`: Definition of a move/rename/quarantine/no-op/preserve-directory operation.
## Testing
- **Unit Tests**: `pytest`
- **Property-based Tests**: `pytest tests/test_analysis_properties.py` (uses Hypothesis).
- **Integration Tests**: `pytest tests/test_reports_integration.py`.
@@ -0,0 +1,25 @@
# Developer Map
## Module → Test → Verification
| Module | Tests | When to run |
|--------|-------|-------------|
| `scanner.py` | `tests/test_scanner.py` | File discovery, metadata extraction |
| `parser.py` | `tests/test_parser.py` | Filename parsing changes |
| `enrichment.py`, `providers/` | `tests/test_enrichment.py` | TMDB/API changes |
| `planner.py` | `tests/test_planner.py` | Operation generation, duplicate resolution |
| `executor.py` | `tests/test_executor.py` | File operations, rollback |
| `plan_review.py` | `tests/test_plan_review.py` | Review gate, CSV handling |
| `commands/*.py` | `tests/test_cli_*.py` | CLI flag/behavior changes |
| `analysis.py` | `tests/test_analysis_properties.py` | Property-based tests (Hypothesis) |
| Full integration | `pytest` | Before any commit |
## Adding a New Command
1. Create module in `src/vlm/commands/`.
2. Define with `@click.command()`.
3. Import and register in `src/vlm/cli.py` via `main.add_command(...)`.
## Key Models
See `src/vlm/models.py`: `VideoFile`, `MovieIdentity`, `SeriesIdentity`, `FileOperation`, `ExecutionPlan`.
@@ -0,0 +1,23 @@
# Triage & Preflight
## Preflight Checks
Before executing workflow commands:
1. Confirm working directory is repository root.
2. Run `vlm --help`; if unavailable, switch to `uv run vlm`.
3. Run `<subcommand> --help` when options are uncertain.
4. Run `vlm config validate` after config edits.
5. Verify required input files exist before downstream stages.
6. Treat `execute --confirm` as destructive; require explicit user confirmation.
## Failure Triage
| Problem | Command |
|---------|---------|
| Missing config | `vlm config init`, then set `library_root` |
| Invalid config values | `vlm config validate` and fix reported keys |
| Missing input artifact | Run prerequisite stage (scan → parse → analyze → plan) |
| Unexpected duplicate decisions | Check `plan.duplicate_keep` in config, rerun `vlm plan --analysis` |
| Unsafe execution results | `vlm rollback`, inspect plan, re-run `execute --confirm` |
| `vlm` not found | Use `uv run vlm ...` fallback |
@@ -1,74 +0,0 @@
# Documentation Status
- Synced with artifacts/ baseline on 2026-06-01.
# VLM Workflow Guide
This guide details the standard end-to-end process for organizing a video library using VLM.
## 1. Setup and Discovery
### Initialize Configuration
```bash
vlm config init
```
Edit `~/.vlm/config.yaml` to set `library_root` and optionally `workspace_dir: artifacts`.
### Library Scan
```bash
vlm scan
```
- **Goal**: Create `artifacts/inventory.csv`.
- **Note**: Ensure `ffprobe` is installed for resolution and codec metadata.
## 2. Identification
### Filename Parsing
```bash
vlm parse --inventory artifacts/inventory.csv
```
- **Goal**: Create `artifacts/identities.json`.
- **Why --inventory?**: Embeds video metadata (v2 schema) required for quality-based duplicate resolution.
### Metadata Enrichment
```bash
vlm enrich
```
- **Goal**: Update `artifacts/identities.json` with TMDB data.
- **Troubleshooting**: Check `enrichment.api_keys` in config; never commit `~/.vlm/config.yaml`.
## 3. Analysis and Planning
### Detect Issues
```bash
vlm analyze
```
- **Goal**: Create `artifacts/analysis.json`.
- **Outputs**: Episode gaps and duplicate groups.
### Create Execution Plan
```bash
vlm plan --analysis artifacts/analysis.json
```
- **Goal**: Create `artifacts/plan.json`.
- **Strategy**: Uses `plan.duplicate_keep` (default: `by_reputation`) for duplicate decisions.
## 4. Review and Execution
### Human review
```bash
vlm review-plan
# Optional: vlm review-plan --tui (requires textual extra)
vlm apply-review # after editing artifacts/plan_manual_review.csv
```
### Execute Changes
```bash
vlm execute # Dry-run
vlm execute --confirm # Actual operations (explicit confirmation)
```
### Reverting Changes
```bash
vlm rollback
```
Restores files using the latest log in `~/.vlm/rollback/`.