- Reorder docs/roadmap.md into an MVP-first vertical slice strategy (M2 Safe Walking Skeleton MVP followed by M3 hardening, M4 SSO/SSE/autocomplete UX, and M5 production Traefik deploy) while preserving all DEC-1 through DEC-8 invariants. - Move former M1.8 (Base32 info_hash normalization and Alembic migration 003) into M3.1 so Milestone 1 closes cleanly in sync with Gitea Milestone #13 (6/6 issues), and enforce urn:btih:<40-hex> + [imdbid-...] checks in M2. - Capture clean-room reproducibility constraints in M2 specs: fail-closed BFF AUTH_ENABLED=true default overridden in local Compose, canonical deployment env vars, relative template resolution inside services/bff/src, PUID:PGID bind-mount ownership, lazy Transmission client initialization, regular-file-only st_nlink checks, and incomplete-dir-enabled disabled. - Update AGENTS.md section 2.5 to enforce four-way planning sync across docs/roadmap.md, todo.txt, Gitea issues/milestones, and Project Board #2. - Narrow todo.txt active items strictly to the next immediate deliverable (Milestone 2: M2.1-M2.4).
5.1 KiB
5.1 KiB
Project Guidelines & Safety Rules for AI Agents
1. Mission & Authority
MagNetFlix is a self-hosted, automated media acquisition pipeline built around FastAPI (BFF) + gRPC (Worker) + UV Workspaces + SQLite3 WAL + Transmission + Reverse Proxy / OIDC SSO.
- Architecture Documentation (
docs/architecture.md), Roadmap (docs/roadmap.md), and Deployment Specifications (docs/deployment.md) define the authoritative design. - Implementation autonomy ≠ Architectural autonomy. Do not replace technologies, dependencies, or storage strategies without explicit approval.
2. Working Tree Authority & Safety (MANDATORY)
The working tree represents the user's active work.
- Inspect First: Run
git statusand list/read target directories/files before creating or modifying anything. - Check for Existing Files: Before creating any new file, verify whether the file (or a user equivalent) already exists on disk. Never overwrite or re-scaffold user work.
- Never Overwrite Blindly: Use available file-reading tools. Preserve user comments, links, and conventions. Prefer surgical edits over wholesale overwrites.
- No Destructive Git Commands: Never run
reset --hard,clean -fd,restore,checkout,stash,rebase, oramendwithout explicit permission. - Live Planning & Task Synchronization: Keep planning artifacts synchronized with code reality whenever a task completes or scope shifts across all four places:
- Repository roadmap (
docs/roadmap.md) — authoritative milestone sequencing and exit criteria. - Immediate checklist (
todo.txt) — focused strictly on a granular breakdown of the next immediate deliverable milestone; mark completed items (x YYYY-MM-DD ...) immediately upon verification. - Gitea issues & milestones (
kiskaadee/MagNetFlix) — open/update/close issues and milestones so Gitea remains the authoritative backlog. - Gitea Kanban board (
MagNetFlix Pipeline, Project#2) — attach active deliverable issues and milestone epics to keep board status aligned.
- Repository roadmap (
- Final Diff Verification: Before completing work, run
git statusandgit diffto verify that no unrelated user changes were modified or discarded. Distinguish user changes from agent changes in completion reports.
3. Architecture & Component Contracts (Progressive Triggers)
- Mandatory Architecture Review: Always read
docs/architecture.mdbefore making any changes affecting API routes, gRPC definitions, database models, directory layouts, or component boundaries. - Read
docs/deployment.mdbefore altering networking, reverse proxy routing, SSO middleware, or Docker volume bindings. - Stop and Ask: If an implementation conflicts with documentation or an ambiguous requirement materially affects architecture, stop and ask the user rather than guessing or silently changing the design.
- No Speculative Robustness: Do not add unrequested fallback layers, complex generic abstractions, or future-proofing bloat.
4. Operational Invariants
4.1 Persistence & Audit (SQLite3 WAL)
- Database must operate in WAL mode (
PRAGMA journal_mode=WAL;) with foreign keys enabled (PRAGMA foreign_keys=ON;) andPRAGMA synchronous=NORMAL;. - Use SQLAlchemy's async interface via
aiosqlite. - Do not create ad-hoc connections outside the application session/engine lifecycle.
- Store database strictly on local volume mounts (
/data/magnetflix.sqlite3). Never place SQLite on network shares (NFS/SMB). - All schema changes must be managed through Alembic migrations.
4.2 Tooling, Dependencies & Protobuf
- Python Workspaces: Use
uvat the workspace root. Never manually edituv.lock(runuv lock). Never use rawpip. - Protobuf & Code Generation:
- Define proto contracts strictly in
proto/magnetflix/v1/. - Regenerate stubs using
uv run buf generate(ormake generate). - Every proto service, RPC, message, and field must include descriptive
//comments.
- Define proto contracts strictly in
- Code Quality: All code must pass
uv run ruff check .anduv run pyright.
4.3 Pipeline Safety & File-System Invariants
- Isolated Staging: Downloads must be confined to an isolated temporary scratch path (e.g.,
/data/staging/<job_id>). - File Whitelist Sanitization:
- Whitelist: Video (
.mkv,.mp4,.avi,.webm) and Subtitles (.srt,.vtt,.sub,.ass). - Quarantine / Reject: Executables, binaries, scripts, or archives (case-insensitive:
.exe,.bat,.cmd,.sh,.scr,.vbs,.ps1,.lnk,.iso,.zip,.rar,.7z).
- Whitelist: Video (
- Clean up staging directories immediately after successful file relocation or upon terminal failure.
5. Verification & Completion
Every task must be verified before declaring completion:
- Run linters, formatters, and type checks:
uv run ruff check .anduv run pyright. - Run test suites when tests are present:
uv run pytest. - Verify protobuf stubs compile cleanly when
.protofiles are touched:uv run buf generate. - Report: (1) What changed, (2) Files modified/created, (3) Verification performed, (4) Unverified areas/risks.