Historical Phase One Engineering Specification
This is the original implementation sequence, retained as historical design context. Phase One remediation is closed in the remediation plan, and media implementation merged in PR #31 on 2026-10-15. For current scope, see the roadmap. The tasks, coverage thresholds and output collection below describe the original plan, not current work or operating rules. Current gates and documentation policy are owned by AGENTS.md, the task registry and workflows.
Original Objectives
- Deliver a production-ready public interface (HTTP API, SSE, CLI) for torrent orchestration.
- Ship FsOps-backed artefacts through API, CLI, telemetry, and documentation with demonstrable reliability.
- Produce release artefacts (containers, binaries, documentation) that satisfy existing security, observability, and quality gates.
Scope Overview
-
Public HTTP API & SSE Enhancements
/v1/torrentsCRUD-style endpoints with cursor pagination, filtering, torrent actions, file selection updates, rate adjustments, and Problem+JSON responses.- SSE stream upgrades: Last-Event-ID replay, subscription filters, duplicate suppression, jitter-tolerant reconnect logic.
/health/fullexposing engine/FsOps/config readiness, dependency metrics, and revision metadata.- Regenerated OpenAPI (JSON + examples) reflecting the full public surface.
-
CLI Parity
- Commands covering list/status/select/action/tail flows with shared filtering + pagination options.
- SSE-backed
tailcommand with Last-Event-ID resume, dedupe, and retry semantics aligned with the API. - Problem+JSON error output, structured exit codes (
0success,2validation,>2runtime failures).
-
Packaging & Documentation
- Release-ready Docker image (non-root, readonly FS, volumes, healthcheck) bundling API server + docs.
- Provenance-signed binaries for supported architectures, plus GitHub Actions workflows for build, docker, msrv, and coverage gates.
- Updated ADRs, runbook, user guides, OpenAPI artefacts, and release checklist referencing the telemetry and security posture.
- Documentation of new metrics/traces/guardrails (config watcher latency, FsOps events, API counters).
Security & Observability Requirements (Cross-Cutting)
- All new API routes enforce API-key authentication with per-key rate limiting and guard-rail metrics.
- Problem+JSON responses are mandatory; eliminate
unwrap/panic paths and includeinvalid_paramspointers on validation failure. - Trace propagation from API → engine → FsOps; CLI should emit/propagate TraceId when available.
- Metrics: extend existing Prometheus registry with route labels, FsOps step counters, config watcher latency/failure gauges, and rate-limiter guardrails.
- Health degradation events (
Event::HealthChanged) must accompany any new guard-rail/latency breach or pipeline failure. - CLI commands should mask secrets in logs and optionally emit telemetry when configured (
REVAER_TELEMETRY_ENDPOINT).
Detailed Work Breakdown
1. Public API & SSE
Design Considerations
- Introduce DTO module (
api::models) for request/response structs to share with the CLI. - Cursor pagination: encode UUID/timestamp as opaque cursor in
nexttoken; align Last-Event-ID semantics with event stream IDs. - Filtering: support state, tracker, extension, tags, and name substring; guard invalid combinations with Problem+JSON.
- SSE filtering: permit query parameters for torrent subset, replays based on event type/state.
Implementation Tasks
- Routes:
POST /v1/torrents– magnet or .torrent upload (streamed, payload size guard).GET /v1/torrents– cursor pagination + filters.GET /v1/torrents/{id}– detail view with FsOps metadata.POST /v1/torrents/{id}/select– file selection update with validation.POST /v1/torrents/{id}/action– pause/resume/remove (with data), reannounce, recheck, sequential toggle, rate limits.
- SSE:
- Accept
Last-Event-IDheader, deduplicate by event ID, filter streams by torrent ID/state. - Simulate jitter/disconnects in tests (
tokio::time::pause,transport::Stream).
- Accept
- Health endpoint:
- Aggregate config watcher metrics (latency, failures), FsOps status, engine guardrails, revision hash.
- Problem+JSON mapping for all new errors with
invalid_paramspointer data. - OpenAPI:
- Regenerate spec covering new endpoints, Problem responses, SSE details, and sample payloads.
- Testing:
- Unit tests for filter parsing, DTO validation, Problem+JSON outputs.
- Integration tests using
tower::Serviceharness for each route. - SSE reconnection tests with simulated delays and Last-Event-ID resume.
/health/fullintegration test verifying new fields and degraded scenarios.
2. CLI Parity
Design Considerations
- Reuse DTOs from API models; consider shared crate/module for request structs and Problem+JSON parsing.
- Introduce output formatting with optional JSON/pretty table modes.
- Provide configuration via env vars and CLI flags; align defaults with API (e.g.,
REVAER_API_URL,REVAER_API_KEY).
Implementation Tasks
- Commands:
revaer ls– list torrents, support pagination (--cursor,--limit), filters (state/tracker/extension/tags).revaer status <id>– torrent detail view, optional follow mode.revaer select <id>– send selection rules from file/JSON (validate before submit).revaer action <id>– actions (pause,resume,remove,remove-data,reannounce,recheck,sequential,rate).revaer tail– SSE tail with Last-Event-ID persist (local file) and dedupe.
- Problem+JSON handling:
- Standardised pretty printer summarising
title,detail,invalid_params; respect exit codes.
- Standardised pretty printer summarising
- Telemetry:
- Optional metrics emission (success/failure counters) when telemetry endpoint configured.
- Testing:
- Integration tests using
httpmockto assert HTTP interactions and exit codes. - SSE tail tests with mocked stream delivering duplicates/disconnects.
- Snapshot tests for JSON outputs (ensuring deterministic fields).
- Integration tests using
3. Packaging & Documentation
Design Considerations
- Multi-stage Docker build: compile with Rust image, run on minimal base (distroless/alpine/ubi) with non-root user.
- Healthcheck script hitting
/health/fullwith timeout. - Release workflows should run on GitHub Actions with provenance metadata (supply-chain compliance).
Implementation Tasks
- Dockerfile +
Makefile/justtarget:- Build release binary, copy
docs/api/openapi.json, set/appas workdir. - Define volumes for data/config, create user
revaer, configure entrypoint.
- Build release binary, copy
- GitHub Actions (update
.github/workflows):build-release: runjust build-release,just api-export, attach binaries/docs.docker: build image, rundocker scan(trivy/grype), and push on release tags.msrv: runjust fmt lint testwith pinned toolchain (documented in workflow).cov: ensurejust covgate passes (≥80% lines/functions).
- Documentation:
- ADRs: update
003-libtorrent-session-runner, add FsOps design ADR, API/CLI contract ADR, security posture update (API keys, rate limits). - Runbook: scripted scenario covering bootstrap → torrent add → FsOps pipeline → restart resume → rate throttle adjustments → degraded health simulation → recovery.
- User guides: CLI usage, metrics/telemetry reference, operational setup (keys, rate limits, config watcher health).
- OpenAPI: regenerate JSON, include sample Problem+JSON payloads and SSE description.
- Release checklist: steps to run
just ci, verify coverage, run docker scan, execute runbook, and tag release.
- ADRs: update
- Testing:
- Validate Docker container runtime (healthcheck, volume mounts, non-root permissions).
- Perform coverage review ensuring new tests bring line/function coverage ≥80%.
- Execute runbook; capture logs/metrics and link in docs.
Cross-Cutting Deliverables
- API key lifecycle (issue/rotate/revoke) extended with per-key rate limiting, recorded in telemetry and docs.
- Config watcher telemetry integrated into
/health/fulland metrics registry. - CLI and API emit guard-rail telemetry on violations (loopback enforcement, FsOps errors, rate-limit breaches).
- All new code paths covered by unit/integration tests; follow-up to update
just covgating. - Documentation kept up-to-date with implementation details and tested flows.
Sequencing (Suggested)
- Build API models and endpoints (foundation for CLI).
- Implement SSE enhancements while adding API integration tests.
- Extend CLI commands leveraging shared DTOs.
- Embed telemetry (metrics/traces) throughout API/CLI/FsOps changes.
- Stand up Docker build + CI workflows.
- Update ADRs, runbook, user guides, OpenAPI, and release checklist.
- Execute full QA cycle (coverage, docker scan, runbook, manual verification) and prepare for release tagging.
Acceptance Criteria
just lint,just test,just covand fulljust cipass locally and in CI.- Coverage (lines + functions) ≥ 80% across workspace.
- Docker image passes security scan with zero unwaived high severity findings.
- Runbook executed end-to-end; results referenced in documentation.
- OpenAPI specification and CLI docs match implemented behaviour.
- Release checklist completed with artefacts attached (binaries, Docker image, OpenAPI, docs).