Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ capabilities at the edge, not assumptions in the core domain model.
and password login with an optional two-step code that issues the session
cookie;
and an experimental M-Team adapter with session, account, search, and
detail reads through the official API and a site-issued API key.
detail reads plus acknowledged metafile fetch through the official API and a
site-issued API key.
- **Downloaders:** qBittorrent and Transmission reads, plus reviewed stopped
adoption, recheck/start, stop, and keep-data removal of one exact job.
- **Reconciliation:** one report that keeps site, downloader, metafile, and
Expand All @@ -72,7 +73,7 @@ The complete inventory, including what is deliberately not implemented, is in
|---|---|---|
| Zero-write | `torrent inspect/verify`, `storage probe/map`, `seed discover/plan`, `client status/list`, ordinary `site` reads and `site bonus review`, `reconcile report`, and every `plan`, `status`, `list`, and `inspect` subcommand | None. Reads can still update atime, hydrate offline placeholders, or be recorded by the remote side. |
| Private store | `metafile store init/import`, `storage profile create`, `storage index refresh/refresh-discover`, `reconcile refresh-report`, `site bonus exchange prepare` | The explicit command itself. Owner-only and no-clobber; not encrypted. |
| Tracker-visible | `site metafile fetch` (one GET), `site bonus exchange submit` (at most one POST), `site login` (one POST and one verifying GET) | `--acknowledge-site-effect`, `--acknowledge-bonus-exchange`; `site login` is the command itself, with the cookie saved only to an owner-only file or a pipe |
| Tracker-visible | `site metafile fetch` (one GET; on M-Team, a token POST and the signed-link GET, plus at most one redirect hop), `site bonus exchange submit` (at most one POST), `site login` (one POST and one verifying GET) | `--acknowledge-site-effect`, `--acknowledge-bonus-exchange`; `site login` is the command itself, with the cookie saved only to an owner-only file or a pipe |
| Target filesystem | `seed materialize run/resume/abandon` | `--acknowledge-filesystem-write`, `--acknowledge-abandon` |
| Downloader | `client adopt/activate/stop/remove run/resume` | `--acknowledge-client-add`, `--acknowledge-client-recheck`, `--acknowledge-client-stop`, `--acknowledge-client-removal`; repeats, re-adds, and observation-only adoption have their own flags |
| Source deletion | `seed retire run/resume`, `seed retire parent-cleanup run/resume` | `--acknowledge-source-deletion`, `--acknowledge-empty-parent-removal` |
Expand Down
20 changes: 12 additions & 8 deletions docs/ADDING_A_SITE.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ preflight from the network:
- **Opening a session** builds process-local state only. It must reject a
canceled context and an undeclared auth method without sending anything.
- **Reading** sends at most one request; `MaxRequests` is fixed at one in the
detail, metafile, and bonus-review limits. Each receipt echoes the pinned
detail, metafile, and bonus-review limits. The one exception is a linked
metafile route, declared with `site.NewLinkedMetafileFetchConfig`: before its
one metafile `GET` it may make up to `MaxLinkRequests` (at most two) requests
for a site-issued link, counted in `LinkRequestsAttempted`, and must treat
that link as a secret (`httpguard.SecretLink`). Each receipt echoes the pinned
origin and route ID. An invalid input, a done context, or a closed session
must fail with zero requests. Their stop reasons are `invalid_reference` or
`invalid_selector`, `context_done` (wrapping `context.Canceled`), and
Expand Down Expand Up @@ -255,23 +259,23 @@ and do it in a separate behavior-preserving commit.
| NexusPHP forks, including TJUPT | Cookie sessions match `cookie_header`, and HTML responses match the existing ports. | Page recognition and parsers for that fork, with synthetic fixtures. Forks differ, so do not assume TJUPT's pages. |
| Unit3D | Cookie-session web pages fit. | Using its token-authenticated API instead runs into the gaps below. |
| Gazelle-based trackers | Cookie sessions fit; their JSON responses need a JSON parser rather than HTML recognition. | Where an API key replaces the session cookie, the gaps below apply. |
| M-Team | Status, account, search, and detail are implemented in `internal/site/mteam` over the JSON API with an API key. | The two-step download: the open gap below. |
| M-Team | Status, account, search, detail, and the signed-link metafile download are implemented in `internal/site/mteam` over the JSON API with an API key. | Bonus commands and reconciliation: the open gaps below. |

## Gaps for API-token sites

These are the places that assumed a cookie, HTML, or a single origin. The
M-Team adapter closed what its four reads needed; the rest is design work for
whichever pull request first needs it. Each open item changes a public contract
M-Team adapter closed what its four reads and its download needed; the rest is
design work for whichever pull request first needs it. Each open item changes a public contract
or a security control, so it needs its own review.

| Gap | Status | Where | What is left |
|---|---|---|---|
| Only one auth method existed | Done | `domain.AuthMethodAPIKeyHeader` (`api_key_header`); `knownAuthMethod` in `internal/site/descriptor.go` | Nothing. |
| Credential input was cookie-only | Partly done | `--api-key-stdin` and `readAPIKeyCredential` in `internal/cli` serve `site status`, `account`, `search`, and `detail` | `site metafile fetch`, bonus commands, and `reconcile` (`--site-cookie-stdin`, the bundle's `site_cookie`) still take cookies only. |
| The CLI gated on cookies | Partly done | `siteRead` in `internal/cli/site.go` and `site detail` check the method the caller chose | Four `SupportsAuth(domain.AuthMethodCookieHeader)` checks remain, in `site_bonus.go`, `site_metafile.go`, `site_bonus_exchange.go`, and `reconcile.go`. |
| Credential input was cookie-only | Partly done | `--api-key-stdin` and `readAPIKeyCredential` in `internal/cli` serve `site status`, `account`, `search`, and `detail`; `site metafile fetch` reads it with `readEffectfulAPIKeyCredential` | Bonus commands and `reconcile` (`--site-cookie-stdin`, the bundle's `site_cookie`) still take cookies only. |
| The CLI gated on cookies | Partly done | `siteRead` in `internal/cli/site.go`, `site detail`, and `site metafile fetch` check the method the caller chose | Three `SupportsAuth(domain.AuthMethodCookieHeader)` checks remain, in `site_bonus.go`, `site_bonus_exchange.go`, and `reconcile.go`. |
| The transport only sent `Cookie` | Done | `httpguard.NewWithHeaderCredential` binds one validated, non-reserved header | Nothing. |
| Redaction did not know the header | Done | `security.Redact` covers `x-api-key` header lines and `apiKey`-style fields | Nothing. |
| No JSON requests | Done | `httpguard.Client.PostReadOnce`: one bounded, non-replayable POST with no redirect and no retry, covered in the threat model | Nothing for reads. Effectful API calls still need their own acknowledged port. |
| One origin per site | Done for reads | The API origin is the descriptor `BaseURL` | A download served from another host needs a design decision before that host is contacted. |
| The download is two requests | Open | `MetafileFetchLimits.MaxRequests` must be exactly one, and the receipt has one route ID | A new port or versioned limits and receipts for token-then-download, an acknowledgement that names both requests, and handling of a signed URL that is itself a secret. See [MTEAM_ADAPTER.md](MTEAM_ADAPTER.md#not-supported-yet). |
| One origin per site | Done | The API origin is the descriptor `BaseURL`; a signed link and its one redirect may reach only hosts the adapter allowlists (`siteHost` in `internal/site/mteam/metafile.go`), each on a fresh credential-free client | A new site's allowlist needs the same review before its hosts are contacted. |
| The download is two requests | Done | `site.NewLinkedMetafileFetchConfig` declares a linked route; `MetafileFetchLimits.MaxLinkRequests` and `MetafileFetchUsage.LinkRequestsAttempted` count the requests before the one metafile `GET`, and the sealed record checks them; `httpguard.SecretLink` and `GetLinkOnce` keep the signed URL secret | Nothing. Both fields are omitted for direct routes, so TJUPT records are unchanged. See [MTEAM_ADAPTER.md](MTEAM_ADAPTER.md#metafile-download). |
| Site-specific CLI text | Done | `detailRouteWarnings` in `internal/cli/site_detail.go` keys the `site detail` warning by route ID; an unlisted route gets only the generic sentence | Add a sentence there when a new detail route has something specific to say. |
34 changes: 26 additions & 8 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,12 @@ uninitialized staging entries are not counted as committed artifacts.
metafile artifact:

```text
site metafile fetch --cookie-stdin --acknowledge-site-effect
site metafile fetch (--cookie-stdin | --api-key-stdin) --acknowledge-site-effect
--metafile-store DIR SITE REMOTE_ID
-> validate one site, one remote ID, limits, capability, and store
-> read the cookie only after that zero-write preflight succeeds
-> send one bounded GET, with no redirect and no retry
-> validate one site, one remote ID, limits, capability, auth method, and store
-> read the credential only after that zero-write preflight succeeds
-> linked routes only: request a site-issued link, bounded by MaxLinkRequests
-> send one bounded metafile GET, with no automatic redirect and no retry
-> strictly validate the complete exact response
-> publish only through the existing private, no-clobber store primitive
-> after successful artifact import, publish a sealed historical binding
Expand All @@ -715,7 +716,22 @@ mode. The store must already be initialized; fetch never turns an arbitrary
directory into a store. A site adapter must explicitly declare
`torrent.metafile.read_effectful`, support the selected stdin authentication
method, and validate its own remote-ID syntax without credentials. This keeps
the CLI and report generic when a second site adapter is added.
the CLI and report generic across site adapters.

Most routes are direct: TJUPT's single cookie-authenticated GET on the site
origin. M-Team's `mteam.download_by_token.v1` is a linked route, declared with
`site.NewLinkedMetafileFetchConfig`. Its session first POSTs the API for a
signed link, pauses for the site's request interval, then GETs that link on a
fresh credential-free client bound to the link's host. A 3xx answer whose
target is an HTTPS host under the adapter's own domains is GET once more on
another such client; any other target, or a second redirect, stops as
`redirect_rejected` without being contacted. `httpguard.SecretLink` carries the
signed link and redirect target, redacts them when formatted, and never puts
them in an error. `MaxRequests` stays one and still counts only the metafile
GET; the token request and a redirect hop are `LinkRequestsAttempted`, bounded
by `MaxLinkRequests` (at most two), and `RedirectsFollowed` stays zero because
no hop is followed by the HTTP stack. The CLI accepts a successful linked fetch
only when the session made exactly `1 + LinkRequestsAttempted` requests.

The site-to-metafile relation first becomes an invocation-scoped
`observed_exact_variant` only when the store import explicitly returns a valid
Expand All @@ -729,7 +745,9 @@ the report-only observation.
B2 adds a binding-last `site.metafile.binding.v1` commit marker only after the
artifact import returns complete success. The sealed record preserves the
canonical site ref, adapter origin/route, whole-raw artifact link, bounded
single-request account, and historical observation interval. Its publication
single-request account, and historical observation interval. A linked route
adds its bounded link-request account in fields that direct routes omit, so
TJUPT records keep their exact bytes. Its publication
and every load jointly verify the record and referenced private artifact in one
operation-bound physical store session. This is not a two-object transaction:
an artifact may remain as an unreferenced immutable object if marker publication
Expand All @@ -751,8 +769,8 @@ post-commit completion is not confirmed. Request attempts and logical store
writes are therefore reported separately; neither is inferred from the other
or from the overall outcome.

Raw response bytes, request and redirect URLs, cookies, announce URLs,
passkeys, server filenames, object paths, and temporary paths never enter JSON,
Raw response bytes, request and redirect URLs, site-issued download links,
cookies, API keys, announce URLs, passkeys, server filenames, object paths, and temporary paths never enter JSON,
human output, errors, or a side record. The ordinary store-root path disclosure
remains opt-in. Non-usage failures are reported before the command returns its
operational or integrity exit; site fetch itself does not use exit `4`.
Expand Down
6 changes: 3 additions & 3 deletions docs/AUTOMATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ Per-command details are in

| Flag | Used by | Stdin content |
|---|---|---|
| `--cookie-stdin` | `site` reads, `site bonus exchange submit` for cookie-only sites, `site metafile fetch` | The complete `Cookie` header value |
| `--api-key-stdin` | `site status`, `site account`, `site search`, and `site detail` for sites that authenticate with an API key (M-Team) | The site-issued API key |
| `--cookie-stdin` | `site` reads, `site bonus exchange submit` for cookie-only sites, `site metafile fetch` for cookie sites (TJUPT) | The complete `Cookie` header value |
| `--api-key-stdin` | `site status`, `site account`, `site search`, `site detail`, and `site metafile fetch` for sites that authenticate with an API key (M-Team) | The site-issued API key |
| `--password-stdin` | `client` commands, `seed retire` commands that contact a downloader, and `reconcile` with a downloader | The downloader password |
| `--site-cookie-stdin` | `reconcile report` with a live site observation and no downloader | The complete `Cookie` header value |
| `--credential-bundle-stdin` | `reconcile report` with both a live site observation and a downloader | `{"schema":"ptctl.credentials/v1","site_cookie":"...","downloader_password":"..."}` |
Expand Down Expand Up @@ -142,7 +142,7 @@ to proceed if it no longer matches.

| Flag | Command | Authorizes |
|---|---|---|
| `--acknowledge-site-effect` | `site metafile fetch` | One tracker-visible GET of a private metafile into the private store |
| `--acknowledge-site-effect` | `site metafile fetch` | One tracker-visible GET of a private metafile into the private store, preceded on a linked route (M-Team) by at most two counted requests for a site-issued link |
| `--acknowledge-bonus-exchange` | `site bonus exchange submit` | At most one bonus-exchange POST after a durable attempt marker |
| `--acknowledge-state-prune` | `site bonus exchange prune` | Replacing one terminal exchange's records with a tombstone |
| `--acknowledge-history-forget` | `site bonus exchange forget` | Irreversibly deleting that last historical evidence |
Expand Down
9 changes: 7 additions & 2 deletions docs/FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,13 @@ deliberately does not. For step-by-step usage, see the
seeders, leechers, promotion factors, and category names, and torrent detail
for one remote ID, through one read-only POST per invocation to the official
JSON API, authenticated by a site-issued API key read only from stdin, with
no redirect, proxy, or retry; M-Team metafile download is not implemented
yet;
no redirect, proxy, or retry;
- an explicitly acknowledged M-Team metafile fetch for one remote ID: one
token POST for a signed download link, one credential-free GET of that link,
and at most one further GET only for a redirect to an M-Team HTTPS host, with
the link treated as a secret that is never printed or stored, the link
requests counted separately from the one metafile GET, and the same strict
validation and private-store publication as TJUPT;
- qBittorrent and Transmission status and torrent-list reads over HTTPS (or
explicit numeric loopback HTTP), with passwords accepted only through stdin;
- read-only reconciliation that can first observe one authenticated live site
Expand Down
Loading
Loading