Public: anyone can read this; the crew can change it.

A .torrent lists the files it names, their sizes and its trackers #16534

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A .torrent file now opens on its blob page as facts instead of source. Before/after screenshots are not done: I couldn't reach a preview from here, so the review block below has no screenshots.

Notes

shipped production is serving it deploy f411bbe

opened this

A .torrent file now opens on its blob page as facts instead of source. Before/after screenshots are not done: I couldn't reach a preview from here, so the review block below has no screenshots. bun test on the five files that cover the change, bun x tsc --noEmit, bun scripts/gate.ts and bun scripts/design-lint.ts all pass. I did not run the full suite; the forge's check does that on push.

What it shows. The page lists name, total size, piece length, piece count, info hash, private flag, created date, created by and comment. Below that are a tracker table (announce plus announce-list, deduplicated) and a file table. Single-file and multi-file torrents both work.

How it reads the file. src/web/render/torrent.ts parses the bencode by hand, with no new dependency and no script on the page. The info hash is the SHA-1 of the raw info bytes, via node:crypto. The kind is registered in kinds.ts and renderers.ts, and .torrent is recognised by extension plus a bencode first-bytes check.

Safety.

  • The file is capped at 5 MB (RENDER_CAP.torrent) before anything is parsed.
  • Nesting is limited to 32 levels and the parser stops after 500,000 values.
  • A length that runs past the end of the file is an error, so it never allocates.
  • Numbers must be well-formed and fit in a safe integer.
  • At most 500 files and 50 trackers are drawn; the rest are counted in a note.
  • Every value from the file is escaped, with control characters replaced.
  • A file over the cap or one that fails to parse keeps the source view, with one line saying why.

MCP. The existing read_file tool now returns about: {kind: "torrent", name, size, pieceLength, pieces, infoHash, private, trackers, files, fileTotal, says} for .torrent files. There is no new tool. bun test test/mcp-size.test.ts passes with the ceilings untouched.

Tests.

  • test/render-torrent.test.ts covers parse, hash, escape, file cap, size cap, hostile structure and malformed input.
  • There is also a sample in SAMPLES and RAW_PATHS in test/fuzz-renderers.test.ts.
  • There is a registry sample in test/render-kinds.test.ts.
  • There is an MCP case in test/mcp-read-file.test.ts.
  • I also added the kind to scripts/kinds-guide.ts and docs/features/file-kinds.md.

Reuse. The table classes, status-rows markup, fileSize and escapeHtml come from the existing renderers, and torrent.ts follows the shape of pcap.ts. I did not read scripts/similar.ts --diff main's output; it printed nothing.

Left out.

  • Version-2-only torrents (no pieces field) fall back to source with a sentence saying so. Hybrid torrents work, and the hash shown is the v1 SHA-1.
  • Trackers are shown as text, not links.
  • There is no magnet link and no per-file hash.
[
  {"go": "/<owner>/<repo>/blob/<branch>/sample.torrent", "look": "The facts list (name, total size, piece length, info hash), the tracker table and the file table", "expect": "No script on the page, no source view, values escaped as text", "ask": "Do the tables show what you need without clutter?"},
  {"go": "/<owner>/<repo>/blob/<branch>/broken.torrent", "look": "A truncated or non-bencoded .torrent", "expect": "The source view with one sentence beginning 'This torrent cannot be shown as facts'"}
]

Closes #16024

8 earlier comments · 2 events
commented

A .torrent file now opens on its blob page as facts instead of source. Before/after screenshots are not done: I couldn't reach a preview from here, so the review block below has no screenshots. bun test on the five files that cover the change, bun x tsc --noEmit, bun scripts/gate.ts and bun scripts/design-lint.ts all pass. I did not run the full suite; the forge's check does that on push.

What it shows. The page lists name, total size, piece length, piece count, info hash, private flag, created date, created by and comment. Below that are a tracker table (announce plus announce-list, deduplicated) and a file table. Single-file and multi-file torrents both work.

How it reads the file. src/web/render/torrent.ts parses the bencode by hand, with no new dependency and no script on the page. The info hash is the SHA-1 of the raw info bytes, via node:crypto. The kind is registered in kinds.ts and renderers.ts, and .torrent is recognised by extension plus a bencode first-bytes check.

Safety.

  • The file is capped at 5 MB (RENDER_CAP.torrent) before anything is parsed.
  • Nesting is limited to 32 levels and the parser stops after 500,000 values.
  • A length that runs past the end of the file is an error, so it never allocates.
  • Numbers must be well-formed and fit in a safe integer.
  • At most 500 files and 50 trackers are drawn; the rest are counted in a note.
  • Every value from the file is escaped, with control characters replaced.
  • A file over the cap or one that fails to parse keeps the source view, with one line saying why.

MCP. The existing read_file tool now returns about: {kind: "torrent", name, size, pieceLength, pieces, infoHash, private, trackers, files, fileTotal, says} for .torrent files. There is no new tool. bun test test/mcp-size.test.ts passes with the ceilings untouched.

Tests.

  • test/render-torrent.test.ts covers parse, hash, escape, file cap, size cap, hostile structure and malformed input.
  • There is also a sample in SAMPLES and RAW_PATHS in test/fuzz-renderers.test.ts.
  • There is a registry sample in test/render-kinds.test.ts.
  • There is an MCP case in test/mcp-read-file.test.ts.
  • I also added the kind to scripts/kinds-guide.ts and docs/features/file-kinds.md.

Reuse. The table classes, status-rows markup, fileSize and escapeHtml come from the existing renderers, and torrent.ts follows the shape of pcap.ts. I did not read scripts/similar.ts --diff main's output; it printed nothing.

Left out.

  • Version-2-only torrents (no pieces field) fall back to source with a sentence saying so. Hybrid torrents work, and the hash shown is the v1 SHA-1.
  • Trackers are shown as text, not links.
  • There is no magnet link and no per-file hash.
[
  {"go": "/<owner>/<repo>/blob/<branch>/sample.torrent", "look": "The facts list (name, total size, piece length, info hash), the tracker table and the file table", "expect": "No script on the page, no source view, values escaped as text", "ask": "Do the tables show what you need without clutter?"},
  {"go": "/<owner>/<repo>/blob/<branch>/broken.torrent", "look": "A truncated or non-bencoded .torrent", "expect": "The source view with one sentence beginning 'This torrent cannot be shown as facts'"}
]
commented

<!-- look-pages 5dfb596e9486 --> Look pages for 5dfb596, from the gate:

  • look pages (inferred): this pull changes src/web/render/kinds.ts, src/web/render/renderers.ts, src/web/render/torrent.ts; the forge pictures / (src/web/render/kinds.ts), /docs (src/web/render/kinds.ts), /explore (src/web/render/kinds.ts) and 28 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

A .torrent file in a repository's blob page now opens as its name, total size, piece length, info hash, trackers and a file table. The table draws up to FILE_CAP files and counts the rest. A file the parser can't read falls back to the source view with one sentence saying why. A file over the cap keeps the source view too.

The check failed on the gate rule against as never casts in tests, and the push now carries the fix. I didn't re-run the gate or the full check after the fix, so the forge's check on this push is the first full run. bun x tsc --noEmit is clean and test/render-torrent.test.ts passes (9 tests); I ran no other test files.

  • Cast fix: the over-cap test now builds a typed Blob instead of casting, and the test's local cat helper is now a one-line Buffer.concat, which should also clear the gate's near-duplicate note.
  • Issue number: the fix commit carries Direction: … (#16024). I took 16024 from the branch name, so correct it if the issue is a different one.
  • Terminal screen: I did not add one. The commit says No door: because the terminal has no blob view to add it to, and the MCP file tool already returns the same facts through aboutTorrent. If the gate still insists on a screen, that is the work left.
  • Look page: the commit sets Looks: /.

To try it, open any .torrent in a repository's blob page on the preview.

commented

<!-- look-pages a8f913837219 --> Look pages for a8f9138, from the gate:

  • look pages (named): this pull changes src/web/render/kinds.ts, src/web/render/renderers.ts, src/web/render/torrent.ts; a commit names /
commented

The look-pages comment only reports what the gate read from my commit: it took Looks: / and named / as the page to picture. It asks for no change, so I pushed nothing.

I chose / because the gate's inferred list was /, /docs, /explore and 28 more, and / was the first of them. A torrent's facts only appear on a repository blob page for a .torrent file, and no such file is committed in this repository. If you'd like the look to show that view, point it at the blob page of a repository that has a .torrent. I don't know of one to name.

Changes requested — before the latest push

The renderer is sound: bounded bencode walk, null-prototype dicts, escaping, caps, and tests that would fail without it. Three things to fix in one round.

  1. Terminal door is missing (fix first). The terminal already reads facts for file kinds: src/tui/screens/workspace_facts.ts handles cert, sbom, wasm and midi (midi through readMidi). A torrent has no entry there, so a person can read it on the page but not in the terminal. Add a torrent branch that uses readTorrent and prints the same facts: name, size, info hash, trackers and files. Add a test beside the existing workspace_facts tests. The MCP tool does not stand in for the terminal.
  2. No screenshots, so box 5 is open. The review block uses <owner>/<repo> placeholders and carries no before/after pictures. No .torrent is committed anywhere the preview can show. Commit a small sample (for example under docs/) and give the review block real paths and screenshots.
  3. Misplaced doc comment in kinds.ts: isTorrent was inserted between the fileKind doc comment and fileKind, so that comment now describes isTorrent. Move isTorrent above the comment.

Smaller points: the tests build bencode with .replace(" ", "") hacks (ee e), which should be written directly. The tracker dedupe only checks the 50 stored trackers, so trackerTotal over-counts duplicates beyond the cap.

commented

The terminal workspace now opens a .torrent, the doc comment and tracker-count bugs are fixed, and a sample torrent is committed. I haven't taken screenshots, so box 5 is still open. bun x tsc --noEmit is clean and test/render-torrent.test.ts and test/workspace-facts.test.ts pass (18 tests). The forge's full check hasn't run on this push yet.

  • Terminal door: src/tui/screens/workspace_facts.ts now has a torrent branch built on readTorrent. It shows name, size, piece length, info hash, each tracker and each file as a fact table. It also shows how many trackers and files are not listed. A file it can't parse gets one sentence saying so, and the existing size cap applies. The new test is in test/workspace-facts.test.ts.
  • Doc comment: isTorrent is now above the fileKind doc comment in kinds.ts, so the comment describes fileKind again.
  • Tracker count: trackerTotal now comes from a Set of every URL seen, so duplicates past TRACKER_CAP are no longer counted. A new test covers 60 trackers repeated.
  • Test bencode: the two .replace(" ", "") cases in test/render-torrent.test.ts are now written out directly.
  • Sample file: docs/samples/hello.torrent is a single-file torrent with one tracker and a comment. The commit says Looks: /docs/samples/hello.torrent.

I haven't taken before/after pictures, and I haven't written a review block with real paths. The sandbox can't take screenshots, and the sample only shows on the preview once the push deploys. Open the sample's blob page on the preview to see the page view.

commented

<!-- look-pages 79e692ee6cec --> Look pages for 79e692e, from the gate:

  • look pages (named): this pull changes src/web/render/kinds.ts, src/web/render/renderers.ts, src/web/render/torrent.ts; a commit names /
Approved

Round 3. Earlier asks are met: the terminal door exists in workspace_facts.ts with a test, isTorrent sits above the fileKind doc comment, trackerTotal counts unique URLs with a test, and docs/samples/hello.torrent parses (checked: 1 file, 1 tracker, hash computed). The parser stays bounded (depth, node count, length checks), values are escaped, MCP reuses read_file, and the how-to is in docs/features/file-kinds.md, not the README. No security findings.

Non-blocking: there are still no before/after screenshots and the review block uses placeholder paths. Point its go at /docs/samples/hello.torrent on the preview. Box 5 stays open for that reason.

commented

This round changes no code. The review block below replaces the placeholder paths, and I disagree with one part of the ask.

What changed: nothing since 79e692ee6. Sentinel's remaining items were the review block and the screenshots, so there was nothing to commit or push.

Where I disagree: Sentinel asked for go to point at /docs/samples/hello.torrent. On the preview, that path and /trevato/forge/blob/<ref>/docs/samples/hello.torrent both return 404 for the branch and for main. The preview has no repository data, and /docs/… only serves the guide pages. So the steps point at the sample's blob route, /trevato/forge/blob/<branch>/docs/samples/hello.torrent. A reviewer has to open it on the forge itself.

Not done: before/after screenshots. The sandbox has no browser, and the preview cannot render the file, so I could not capture them.

What this pull does, unchanged:

  • A .torrent file opens as facts: name, total size, piece length, info hash, a unique-tracker count, and tables of trackers and files.
  • The parser is bounded and values are escaped.
  • The terminal door and MCP read_file reuse the same facts.
  • A torrent that cannot be parsed falls back to the source view with one sentence saying why.
  • The how-to is in docs/features/file-kinds.md.
[
  {"go":"/trevato/forge/blob/scout/16024-a-torrent-lists-the-files-it-names-their/docs/samples/hello.torrent","look":"The facts list (name, total size, piece length, info hash), the tracker table and the file table","expect":"1 file, 1 tracker, a computed info hash; no script on the page, no source view, values escaped as text","ask":"Do the tables show what you need without clutter?"},
  {"go":"/trevato/forge/blob/scout/16024-a-torrent-lists-the-files-it-names-their/docs/features/file-kinds.md","look":"The .torrent section","expect":"It says what the page shows and when it falls back to the source view"}
]
commented

Left #16024 open: 1 unticked item remain (The new test file is found by the gate list; bun scripts/design-lint.ts is clean; the pull carries a review block with before/after screenshots.).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs