diff --git a/AGENTS.md b/AGENTS.md index 8fc33cc..2a88548 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -117,7 +117,7 @@ No CI is configured; no rustfmt.toml/clippy.toml — default `cargo fmt`/`clippy - **Errors**: `anyhow::Result` everywhere in core; no custom error enums. The server converts to `ApiError { status, message }` (`routes.rs`) with helpers `not_found`/`bad_request`/`unauthorized`/`forbidden`; any `anyhow` error maps to 500. - **Async**: Tokio only at the server boundary (`#[tokio::main]`, async handlers, `tokio::spawn` for the 24h session-cleanup task). **Core is synchronous** — blocking `reqwest`, subprocess downloaders, sync `rusqlite`. Keep it that way; don't introduce async into archivr-core. - **State**: Axum `AppState { registry, auth_db_path, login_attempts }` via `State` extractor; middleware stack = `setup_guard` (503 until owner exists) → `login_rate_limit` (5/15min per IP) → `security_headers`. -- **Auth extraction**: `AuthUser` implements `FromRequestParts` — session cookie (`session`) or `Authorization: Bearer` token (stored SHA3-256-hashed). Passwords are Argon2. +- **Auth extraction**: `AuthUser` implements `FromRequestParts` — session cookie (`session`) or `Authorization: Bearer` token (stored SHA3-256-hashed). Passwords are Argon2. Read-scope Bearer tokens are limited to GET/HEAD/OPTIONS by `token_scope.rs`. Target-aware admin rules (manage, not self, last owner) go through `guards.rs`; don't re-implement them inline. Keep `file://` capture locators limited to staged uploads (`temp/uploads/`) in the API; the CLI is the only place local paths are read directly. - **Logging**: `eprintln!` with `info:`/`warn:` prefixes. No `tracing`/`log` — don't add structured logging piecemeal. - **External tools by env var**: `ARCHIVR_YT_DLP`, `ARCHIVR_DENO`, `ARCHIVR_JS_RUNTIME`, `ARCHIVR_CHROME`, `ARCHIVR_SINGLE_FILE`, `ARCHIVR_TWEET_PYTHON`, `ARCHIVR_TWEET_SCRAPER`, `ARCHIVR_STATIC_DIR`, `ARCHIVR_BIND`, `ARCHIVR_FFMPEG`. Local transcription: `ARCHIVR_TRANSCRIBE_ENGINES` (the gate; unset = off), `ARCHIVR_TRANSCRIBE_TIMEOUT` (default 3600s, whole job), `ARCHIVR_WHISPER_BACKEND` (`whisper_cpp`|`script`) / `ARCHIVR_WHISPER_CLI` / `ARCHIVR_WHISPER_MODEL` / `ARCHIVR_WHISPER_LANGUAGES`, `ARCHIVR_PARAKEET_CLI` / `ARCHIVR_PARAKEET_MODEL` / `ARCHIVR_PARAKEET_LANGUAGES`, `ARCHIVR_PHONON2_CLI` / `ARCHIVR_PHONON2_MODEL`. Downloaders shell out to subprocesses; resolve binaries through these vars. Env helpers (`required_env`, `env_or`, `optional_env`, `env_timeout`, `resolve_cli`) live in `env_config.rs`; bounded subprocesses go through `process::run_with_timeout` (yt-dlp calls keep `ytdlp.rs`'s private runner). - **yt-dlp is resolved, not just read**: `ARCHIVR_YT_DLP` (set by the flake wrappers) is only the @@ -141,7 +141,14 @@ No CI is configured; no rustfmt.toml/clippy.toml — default `cargo fmt`/`clippy ## Important Files - `crates/archivr-server/src/main.rs` — server bootstrap: config load, archive mounting, auth DB init, stalled-job recovery (running → failed on startup), X Article title backfill (`capture::backfill_x_article_titles`; idempotent, startup only — CLI-only installs never run it). -- `crates/archivr-server/src/routes.rs` — all HTTP handlers and the router; grep here first for API work. +- `crates/archivr-server/src/routes.rs` — HTTP router and most handlers; grep here first for API work. Newer account/admin/job handlers live in the modules below, but their routes are still registered in this file's router. +- `crates/archivr-server/src/admin_users.rs` — admin user delete and status, role CRUD (`/api/admin/roles`), and user role assignment. +- `crates/archivr-server/src/credentials.rs` — own sessions (`/api/auth/sessions`), API token scope/expiry, admin password reset and per-user session/token revocation. +- `crates/archivr-server/src/guards.rs` — `ensure_can_manage`, `ensure_not_self`, `ensure_not_last_owner` shared by the admin and credential handlers. +- `crates/archivr-server/src/token_scope.rs` — middleware that enforces read-scope tokens (GET/HEAD/OPTIONS only). +- `crates/archivr-server/src/jobs.rs` — capture job list and detail (`created_by` filter, `items_truncated` at 200 items), with the `created_by` visibility rule. +- `crates/archivr-server/src/effective_config.rs` — `GET /api/admin/effective-config`, the `ENV_VARS` registry and its drift test, and `GET /api/archives/:id/info`. +- `crates/archivr-server/src/test_support.rs` — shared test helpers (router, auth DB and user/session setup) for the `oneshot` tests. - `crates/archivr-core/src/capture.rs` — `perform_capture()`, `Source` enum, shorthand parsing; tweet titles prefer an X Article's `article.title` (` — @handle`). - `crates/archivr-core/src/downloader/ytdlp.rs` — every yt-dlp shell-out (playlist/channel probe and download, sync mode, subtitle planning/args/staging, the combined media+subtitle call with its media-only retry, and the subtitles-only `download_subtitles`) **plus** the binary resolver: `resolve_yt_dlp()`, `state_dir()`, `probe_version()`. - `crates/archivr-core/src/subtitles.rs` — `subtitle` artifacts: archive/register (deduped per entry+blob), `subtitle_to_transcript()` (VTT/SRT reduction, rolling-caption dedup), `subtitle_track_rank()`, and summary-time `fetch_subtitles_for_entry()`. @@ -191,7 +198,7 @@ No CI is configured; no rustfmt.toml/clippy.toml — default `cargo fmt`/`clippy ## Testing & QA -- **Rust**: unit tests only, in `#[cfg(test)]` modules inside source files (e.g. `capture.rs`, `database.rs`, `registry.rs`, `routes.rs`, `hash.rs`, and newer: `summarizer.rs` — 53 tests over provider construction, CLI/env resolution, output extraction, HTML/text/JSON input reduction, tweet-thread joining, YouTube subtitle selection/digest/no-subtitles errors and the transcription fallback order; `downloader/ytdlp.rs` — tests covering resolver priority and refresh, version tie-breaking, `yt_dlp_command_with` args, subtitle planning, argument construction, staging, the media-only retry decision and the timeout runner; `downloader/js_runtime.rs` — runtime spec parsing, Deno version parsing, candidate priority/ties/minimum version and the winning role, PATH fallback via `resolve_js_runtime_with_path` (never mutate the process `PATH`), refresh and `--js-runtimes` args; `downloader/deno_install.rs` — 7 tests: asset selection, release parsing and `verify_staged` (version mismatch, the "cannot execute" case); `downloader/ytdlp_tools.rs` — 2; `subtitles.rs` — 13 tests over VTT/SRT reduction, rolling-caption dedup, track ranking and artifact dedup; `transcriber.rs` — 40 (env config, argument builders, Phonon JSON → VTT against a real sample, language gating, end-to-end with fake engines); `process.rs` — 5; `env_config.rs` — 2; `thread_title.rs` — 8). Test locks: tests that set resolver env vars take `downloader::RESOLVER_ENV_LOCK` and call `refresh_*()` on cleanup so the cache never points into a deleted tempdir; tests that set transcription env vars or run `transcribe_entry` (including `summarizer.rs`'s fallback tests) take `transcriber::TRANSCRIBE_TEST_LOCK`; `summarizer.rs` and `env_config.rs` provider-env tests use their module-local `ENV_LOCK`. Tests that exec a freshly written script write it to a fresh path and wait out ETXTBSY first (`fake_deno`/`deno_install::tests::write_script` in core, `write_script` in the CLI). No `tests/` integration dir. Patterns: `tempfile` for scratch archives, config round-trip assertions, regex/parser validation. Run `cargo test` or `cargo test -p <crate>`. +- **Rust**: unit tests only, in `#[cfg(test)]` modules inside source files (e.g. `capture.rs`, `database.rs`, `registry.rs`, `routes.rs`, `hash.rs`, and newer: `summarizer.rs` — 53 tests over provider construction, CLI/env resolution, output extraction, HTML/text/JSON input reduction, tweet-thread joining, YouTube subtitle selection/digest/no-subtitles errors and the transcription fallback order; `downloader/ytdlp.rs` — tests covering resolver priority and refresh, version tie-breaking, `yt_dlp_command_with` args, subtitle planning, argument construction, staging, the media-only retry decision and the timeout runner; `downloader/js_runtime.rs` — runtime spec parsing, Deno version parsing, candidate priority/ties/minimum version and the winning role, PATH fallback via `resolve_js_runtime_with_path` (never mutate the process `PATH`), refresh and `--js-runtimes` args; `downloader/deno_install.rs` — 7 tests: asset selection, release parsing and `verify_staged` (version mismatch, the "cannot execute" case); `downloader/ytdlp_tools.rs` — 2; `subtitles.rs` — 13 tests over VTT/SRT reduction, rolling-caption dedup, track ranking and artifact dedup; `transcriber.rs` — 40 (env config, argument builders, Phonon JSON → VTT against a real sample, language gating, end-to-end with fake engines); `process.rs` — 5; `env_config.rs` — 2; `thread_title.rs` — 8). Test locks: tests that set resolver env vars take `downloader::RESOLVER_ENV_LOCK` and call `refresh_*()` on cleanup so the cache never points into a deleted tempdir; tests that set transcription env vars or run `transcribe_entry` (including `summarizer.rs`'s fallback tests) take `transcriber::TRANSCRIBE_TEST_LOCK`; `summarizer.rs` and `env_config.rs` provider-env tests use their module-local `ENV_LOCK`. Tests that exec a freshly written script write it to a fresh path and wait out ETXTBSY first (`fake_deno`/`deno_install::tests::write_script` in core, `write_script` in the CLI). No `tests/` integration dir. Server `oneshot` tests share their helpers in `crates/archivr-server/src/test_support.rs` (router, auth DB, owner/admin/user/guest session fixtures, API token setup); reuse those rather than copying setup code. Patterns: `tempfile` for scratch archives, config round-trip assertions, regex/parser validation. Run `cargo test` or `cargo test -p <crate>`. - **Env var registry**: when you add an `ARCHIVR_*` env var, add it to `ENV_VARS` in `crates/archivr-server/src/effective_config.rs` (name, group, description, secret flag, default). `GET /api/admin/effective-config` serves that table (secrets as `set` only, URLs without userinfo/query), and a drift test greps every crate's `src/**/*.rs` for `"ARCHIVR_*"` literals and fails on any missing entry (test-only `ARCHIVR_TEST_*` names are ignored). - **Frontend**: component render tests are colocated `*.test.jsx` files on `bun:test` (`bun test` from `frontend/`); there is no Storybook. - Manual smoke test for server changes: build frontend, `cargo run -p archivr-server -- <config.toml>`, exercise `/api/*`. diff --git a/ARCHIVR-MENTAL-MODEL.md b/ARCHIVR-MENTAL-MODEL.md index 6b0cfb1..e2a2b5d 100644 --- a/ARCHIVR-MENTAL-MODEL.md +++ b/ARCHIVR-MENTAL-MODEL.md @@ -375,7 +375,14 @@ fetch is in flight (`has_pending_subtitle_fetches`). Every one of these calls is | `entry_summaries` schema and summary CRUD | `crates/archivr-core/src/database.rs` | | CLI commands, argument parsing, terminal output | `crates/archivr-cli/src/main.rs` | | Server API routes | `crates/archivr-server/src/routes.rs` | -| Auth model (users, sessions, tokens, roles) | `crates/archivr-server/src/auth.rs` | +| Auth model (users, sessions, tokens, roles), Bearer/cookie extraction | `crates/archivr-server/src/auth.rs` | +| Own sessions and API tokens (`/api/auth/sessions`, token scope/expiry), admin password reset and per-user session/token revocation | `crates/archivr-server/src/credentials.rs` | +| Admin user delete/status, role CRUD and assignment | `crates/archivr-server/src/admin_users.rs` | +| Target-aware guards (manage, not self, last owner) | `crates/archivr-server/src/guards.rs` | +| Read-scope token enforcement (non-GET/HEAD/OPTIONS → 403) | `crates/archivr-server/src/token_scope.rs` | +| Capture job list/detail, `created_by` visibility, run visibility | `crates/archivr-server/src/jobs.rs` | +| Effective config and `ENV_VARS` registry, archive info | `crates/archivr-server/src/effective_config.rs` | +| Shared server test helpers | `crates/archivr-server/src/test_support.rs` | | Mounted archive config model | `crates/archivr-server/src/registry.rs` | | Frontend root state + routing | `frontend/src/App.jsx` | | Frontend API client | `frontend/src/api.js` | @@ -409,4 +416,14 @@ The server both reads and writes archive data. Capture jobs are asynchronous: `P searched as text, so generated `tags` participate. Older completed summaries stay searchable while a newer request is pending or failed; rows with no completed summary contribute no summary-derived match. -**Admin view** covers mounted archives, users, sessions, and API tokens. +**Token scope and expiry.** API tokens carry `scope` (`full` or `read`) and an optional expiry. `token_scope.rs` answers 403 `read-only token` to a read-scope Bearer request that is not GET, HEAD or OPTIONS. Cookie sessions bypass this check. Bearer use goes through `auth_credentials::touch_token_throttled`, so `last_used_at` is written at most once per 60 seconds. + +**Guards.** Management endpoints call `guards.rs` after their coarse `require_role(ROLE_ADMIN)` check: `ensure_can_manage` (only an OWNER may act on a target that has OWNER or ADMIN), `ensure_not_self` (409), and `ensure_not_last_owner` (409, counts active owners). Keep new management endpoints on these helpers rather than re-deriving the rules. + +**Capture job visibility.** `capture_jobs.created_by` stores the creator's `user_uid`. Job endpoints show a caller only jobs they created unless they hold ADMIN; rows with no creator are admin-only. `GET /api/archives/:id/runs` follows access: admins see all runs, other callers see runs whose job they created or that produced at least one entry they can see. + +**File locators.** `POST /api/archives/:id/captures` accepts `file://` only for a file staged under `temp/uploads/`, so an API caller cannot capture and read back arbitrary server files. The CLI reads local paths directly and is unaffected. + +**Inert settings.** `public_index_enabled`, `public_entry_content_enabled` and `open_registration_enabled` are stored and returned by the instance-settings endpoints, but no server logic reads them yet. + +**Admin view** covers mounted archives, users, sessions, and API tokens. `admin_users.rs` handles user delete and status, and role CRUD and assignment. `credentials.rs` handles password reset and per-user session and token revocation (`GET /api/admin/users/:uid/tokens`, `DELETE .../tokens/:token_uid`). `GET /api/admin/effective-config` (`effective_config.rs`) serves the static `ENV_VARS` table, with secrets shown only as `set`. `GET /api/archives/:id/info` gives counts and sizes without paths, and `GET /api/archives` returns `archive_path` to admins only. diff --git a/docs/README.md b/docs/README.md index 365ff7a..961f43e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -49,7 +49,7 @@ Archivr is a self-hosted tool for capturing and preserving digital content — Y - **Deduplication** — SHA3-256 content-addressed blob store shared across all captures; identical files are stored once - **Tags and search** — hierarchical tag tree, full-text search (including the latest completed summary and its generated JSON tags), filterable entry list - **Multiple archives** — the server mounts any number of separate archives from a single TOML config -- **Role-based auth** — Guest / User / Admin / Owner roles; session cookies and API tokens; Argon2 passwords; the Owner can choose which roles (including custom ones) may reorder child entries +- **Role-based auth** — Guest / User / Admin / Owner roles; session cookies and API tokens (`full` or read-only scope, optional expiry); Argon2 passwords; the Owner can choose which roles (including custom ones) may reorder child entries; users manage their own sessions and tokens, and admins manage other accounts within the guard rules below - **Quality selection** — choose video quality or audio-only per capture; a live metadata probe populates the selector before download - **LLM summaries** — regenerable per-entry summary via the Anthropic HTTP API, an OpenAI-compatible HTTP API, a local `claude` CLI, or a local `codex` CLI; triggered manually from the entry rail, never automatically on capture; text-only by default, with an explicit `Include attached images` option; YouTube videos are summarized from their subtitles - **Text notes** — capture a plain-text or Markdown note with a title and no URL; the byte-preserving note is stored as a normal deduplicated blob and opens in the usual entry-rail preview @@ -121,7 +121,7 @@ my-archive/ └── temp/ # staging area during capture ``` -A separate auth database (`archivr-auth.sqlite`, path set in TOML) holds users, sessions, API tokens, and role bits. It is independent of individual archives. +A separate auth database (`archivr-auth.sqlite`, path set in TOML) holds users, sessions, API tokens (with scope and expiry), and role bits. It is independent of individual archives. ## Supported Inputs @@ -129,7 +129,7 @@ A separate auth database (`archivr-auth.sqlite`, path set in TOML) holds users, | Platform | Input examples | |---|---| -| Local file | `file:///absolute/path/to/file.pdf` | +| Local file | `file:///absolute/path/to/file.pdf` (CLI only; the HTTP API accepts `file://` only for files staged by an upload, see [Security](#security)) | | YouTube video / short | `https://youtube.com/watch?v=ID` · `yt:video/ID` · `yt:short/ID` | | YouTube playlist | `https://youtube.com/playlist?list=ID` | | YouTube channel | `https://youtube.com/@handle` | @@ -576,6 +576,17 @@ Deno and exits 0 (the UI shows the Deno outcome as `skipped: …`). `archivr-server` binds to `127.0.0.1:8080` by default. Do not expose it to a public network without understanding the risks. When started on a non-loopback address the server logs a warning to stderr. +Access rules enforced by the server: + +- **Local files over the API.** A `file://` capture locator is accepted only for a file staged by an upload (under the archive's `temp/uploads/`); any other `file://` path returns 400. The CLI still reads local paths directly. +- **Read-only tokens.** A Bearer token with `scope: read` gets 403 (`read-only token`) on any method other than GET, HEAD or OPTIONS. Cookie sessions are not affected. Bearer use updates `last_used_at`, at most once per 60 seconds. +- **Archive paths.** `GET /api/archives` returns each archive's `archive_path` to admins only. `GET /api/archives/:id/info` returns counts and sizes, never filesystem paths. +- **Account guards.** Only an owner may manage an owner or admin account. Nobody can disable or delete their own account, and the last active owner cannot be removed or demoted (409). +- **Capture jobs.** A user sees only the capture jobs they created (`created_by`); admins see all. Jobs with no recorded creator are admin-only. A run is listed when the caller is an admin, created its job, or can see at least one entry it produced. +- **Admin endpoints.** `GET /api/admin/effective-config` lists every `ARCHIVR_*` setting; secret values are shown only as `set`, and URLs lose their userinfo and query string. + +The instance settings `public_index_enabled`, `public_entry_content_enabled` and `open_registration_enabled` are stored and returned by the API but no server logic reads them yet. + ### Hosting on NixOS The flake exposes `nixosModules.default`: diff --git a/docs/superpowers/specs/2026-10-08-mcp-api-extensions.md b/docs/superpowers/specs/2026-10-08-mcp-api-extensions.md index 32a4b33..d3cb920 100644 --- a/docs/superpowers/specs/2026-10-08-mcp-api-extensions.md +++ b/docs/superpowers/specs/2026-10-08-mcp-api-extensions.md @@ -1,6 +1,6 @@ # Spec: Archivr API extensions for the MCP server -- **Status:** Contract (R0 foundation landed; endpoints are implemented by streams R1-R4). +- **Status:** Contract (implemented on `mcp-api-extensions`, archivr HEAD 10afef9). Where the code and this text differed, the text now describes the code (see the "as implemented" notes in 1.5, 1.6 and 2.10). - **Date:** 2026-10-08 - **Audience:** the Archivr (Rust) streams R1-R4 and the MCP (TypeScript) streams M0-M5. The MCP server is built against this document with a mocked `fetch`; the Rust streams implement it. Anything not written here is not part of the contract. - **Read first:** `AGENTS.md`, `ARCHIVR-MENTAL-MODEL.md`. @@ -143,7 +143,9 @@ Errors: 400, 401, 403, 404 (unknown archive). "source_kind": "string", "entity_kind": "string", "status": "pending|in_progress|completed|failed", "error_text": "string|null", "entry_uid": "string|null"}]} ``` -`items` come from `archive_run_items` of the job's run (empty while `run_uid` is null), ordered by `ordinal`; `entry_uid` is the produced entry (`produced_entry_id`), and `entry_uids` is the de-duplicated non-null list in item order. A caller who is neither the creator nor ADMIN gets `404` (not `403`), so job existence is not disclosed. `created_by` is also included. +`items` come from `archive_run_items` of the job's run (empty while `run_uid` is null), ordered by `ordinal`; `entry_uid` is the produced entry (`produced_entry_id`), and `entry_uids` is the de-duplicated non-null list in item order. A caller who is neither the creator nor ADMIN gets `404` (not `403`), so job existence is not disclosed. + +As implemented, J2 also returns `created_by` (the submitter's `user_uid`, or `null`) and `items_truncated: bool`. `items` is capped at 200 (`JOB_ITEMS_MAX`); `items_truncated` is `true` when the run had more items than were returned. `created_by` is also present on every row of J1. **J3.** Response unchanged in shape (array of run summaries): ```json @@ -159,26 +161,34 @@ but filtered: a run is visible if the caller is ADMIN, **or** created the job th | I1 | `GET /api/archives/:id/info` | ADMIN | | I2 | `GET /api/admin/effective-config` | ADMIN | -**I1.** Counts and sizes only; no filesystem paths. Response `200`: +**I1.** Counts and sizes only. `name` is the archive's display name from its own metadata; no filesystem paths are returned. Response `200`: ```json -{"archive_id": "string", "label": "string", - "entry_count": 0, "root_entry_count": 0, "artifact_count": 0, "blob_count": 0, "blob_bytes": 0, +{"archive_id": "string", "label": "string", "name": "string|null", + "entry_count": 0, "root_entry_count": 0, "child_entry_count": 0, + "artifact_count": 0, "blob_count": 0, "blob_bytes": 0, "tag_count": 0, "collection_count": 0, "run_count": 0, "summary_count": 0, - "job_counts": {"pending": 0, "running": 0, "completed": 0, "failed": 0}} + "job_counts": {"pending": 0, "running": 0, "completed": 0, "failed": 0}, + "db_bytes": 0} ``` -Errors: 401/403/404 (unknown archive). +`child_entry_count` = `entry_count - root_entry_count`. `db_bytes` is the size of the archive's SQLite file (0 if it cannot be read). Errors: 401/403/404 (unknown archive). -**I2.** Read-only view of env-derived configuration, from a static `ENV_VARS` table in `effective_config.rs` (every `ARCHIVR_*` variable the code reads; a unit test greps the crates' source for `ARCHIVR_*` literals and fails on drift). Response `200`: +**I2.** Read-only view of the server's configuration, from a static `ENV_VARS` table in `effective_config.rs` (every `ARCHIVR_*` variable the code reads; a unit test greps the crates' source for `ARCHIVR_*` literals and fails on drift). Response `200`, top-level keys as below: ```json -{"env_vars": [{"name": "ARCHIVR_ANTHROPIC_API_KEY", "group": "summaries", "description": "string", +{"server": {"version": "string", "bind": {"value": "string", "source": "env|toml|default"}, + "archives": [{"id": "string", "label": "string"}]}, + "env_vars": [{"name": "ARCHIVR_ANTHROPIC_API_KEY", "group": "summaries", "description": "string", "secret": true, "default": "string|null", "set": true, "value": "string|null"}], "summary_providers": [{"kind": "anthropic_http", "configured": true, "model": "string|null", "error": "string|null"}], - "title_models": {"anthropic_http": {"model": "string", "source": "instance|env|default"}}} + "title_models": {"anthropic_http": {"model": "string", "source": "instance|env|default"}}, + "transcription_engines": [{"kind": "string", "enabled": true, "configured": true, "label": "string|null", + "english_only": "bool|null", "languages": "string[]|null", "error": "string|null"}], + "extensions": {"ublock": {"available": true}, "cookie_consent": {"available": false}}} ``` - `secret: true` entries never carry a value: `value` is `null`, only `set` (true when the variable is set and non-empty) is reported. - Non-secret `value` is the effective string, or `null` when unset. URL-valued variables lose userinfo and query string (`https://user:pw@host/p?k=v` -> `https://host/p`). - `group` is one of `server`, `tools`, `summaries`, `titles`, `transcription`. - `summary_providers[].error` is the (secret-free) reason `provider_from_env` fails, e.g. which variable is missing. +- `server` and `extensions` are not in the original R4 list; they were added during implementation. `server.bind.value` is the effective bind address and never carries secrets. ## 2. Hardening of existing endpoints @@ -193,6 +203,8 @@ Behavior changes to endpoints that already exist (R1 owns status/roles, R2 owns 7. **Read-scope tokens**: Bearer requests authenticated by a token with `scope = "read"` get `403 {"error": "read-only token"}` on any method other than `GET`, `HEAD`, `OPTIONS`. Cookie sessions are unaffected. Implemented as middleware in `token_scope.rs`. 8. Bearer tokens past `expires_at` are rejected: the request is treated as unauthenticated (`401` on endpoints that require auth). (Already enforced in `database::get_user_for_token`; covered by a regression test.) 9. `capture_jobs.created_by` is now recorded (the submitter's `user_uid`) by `capture_handler`, text capture, and rearchive via `database::create_capture_job_as`; other callers keep `create_capture_job` (NULL owner). +10. **Inert instance settings (as implemented).** `public_index_enabled`, `public_entry_content_enabled` and `open_registration_enabled` (column `public_archive_submission_enabled`) are stored and returned by `PATCH` / `GET` instance settings, but no server logic reads them yet. Setting them changes nothing in behavior. Do not document them as enforced until a stream wires them in. +11. **`file://` rule (as implemented).** The check of item 3 lives in the capture handler in `routes.rs`; the regression tests are in `jobs.rs` (`file:///etc/hosts` -> `400`, staged upload -> accepted). Out of scope (not proposed): entry metadata edits beyond title, job cancel, server-side entry pagination, frontend/UI updates, admin edit of email/display name. @@ -218,9 +230,9 @@ pub fn get_user_uid(conn, user_id: i64) -> Result<Option<String>>; `list_user_tokens` and therefore the existing `GET /api/auth/tokens` response gained `expires_at` and `scope` (additive; this is T2). `CaptureJobRecord` is unchanged (add `created_by` there in R3 if needed). -### 3.3 Module stubs +### 3.3 Modules -Core: `auth_users.rs`, `auth_credentials.rs`, `capture_jobs.rs` (empty, declared in `lib.rs`). Server: `admin_users`, `credentials`, `jobs`, `effective_config` (each `pub fn routes() -> Router<AppState>` returning `Router::new()`, merged in `app_with_state`), `token_scope` (stub `routes()` plus a pass-through `enforce_read_scope` middleware signature; not wired yet), `guards` (implemented, see 0.1), `test_support` (`#[cfg(test)]`). +R0 created these as stubs; all are now implemented. Server: `admin_users.rs` (U1-U5, R1, R2), `credentials.rs` (S1-S3, T1/T2), `jobs.rs` (J1-J3), `effective_config.rs` (I1, I2), `guards.rs` (0.1), `token_scope.rs` (read-scope middleware, item 2.7), each merged in `app_with_state`. Core: `auth_users.rs`, `auth_credentials.rs`, `capture_jobs.rs`. `test_support` is `#[cfg(test)]`. ### 3.4 `guards.rs` (implemented)