Rewrites the RFCs in a Zotero library as standard items, attaches their canonical full text, and merges duplicates.
README.md

claude-zotero #

Four scripts that keep the RFCs in a Zotero library in order: they add one by number, rewrite each as a standard item from the RFC Editor's own index, attach its canonical full text, and merge the duplicates that accumulate when the same RFC is imported twice from two different places. A fifth puts every attachment's file where the Zotero desktop will look for it.

$ nix develop
$ python3 rfc_add.py --collection thing 9221   # add RFCs a project cites
$ python3 rfc_standardize.py --dry-run     # what would be rewritten
$ python3 rfc_standardize.py               # rewrite it
$ python3 rfc_attach.py                    # fetch and attach the full text
$ python3 merge_duplicates.py              # fold duplicates together
$ python3 storage_restore.py               # put stray files on WebDAV

Every script takes --dry-run, and every script is idempotent: run it twice and the second run finds nothing to do. Credentials come from ~/.config/zot/config.toml, which is zot's config file and the only place either tool looks for a key. A library whose files sync over WebDAV also needs that server named there; see Where the files go.

Where this lives #

The repository lives in three places that carry the same history. The Forgejo instance at https://git.jcollie.dev/jeff/claude-zotero is the web-visible one:

$ git clone https://git.jcollie.dev/jeff/claude-zotero.git

it is mirrored on Tangled at https://tangled.org/jcollie.dev/claude-zotero, and it is also on the Radicle network, where the repository's identifier is

rad:z38TceTtQvkbN295pZ4rMZbcJFEKy

and rad clone rad:z38TceTtQvkbN295pZ4rMZbcJFEKy fetches it from any node that seeds it. Any of the three is the whole project.

Adding an RFC that was never imported #

rfc_standardize.py and rfc_attach.py both work on RFCs the library already holds — the first rewrites whatever an importer made of one, the second fetches its text. Neither creates one, so an RFC that was never imported at all had no way in short of finding it in a browser and letting a translator produce the wrong item type for rfc_standardize.py to correct afterwards.

rfc_add.py goes straight to the answer, and builds the item by calling rfc_standardize.py's own build — so there is one definition of what an RFC looks like in this library rather than two that can drift.

$ python3 rfc_add.py --collection zig-quic 9221 8899 9204
RFC 8899  add   Packetization Layer Path MTU Discovery for Datagram Tran
RFC 9204  add   QPACK: Field Compression for HTTP/3
RFC 9221  add   An Unreliable Datagram Extension to QUIC

3 of 3 written; run rfc_attach.py to give them their text

It is idempotent in the way that matters for a library several projects share: an RFC that is already there is not added again, and if --collection names one the existing item is not in, the item is filed into it rather than duplicated. "Make sure this project's collection lists RFC 9221" is the thing a caller usually wants, and it is not the same request as "create RFC 9221".

The collection is named rather than keyed, because a caller thinks in project names and nobody remembers a key. A name shared by two collections is an error rather than a guess: filing an item into whichever one came back first puts it somewhere the caller did not ask for and will not look.

Why these exist rather than zot #

zot is the right tool for reading a Zotero library — it reads zotero.sqlite directly and answers instantly. Two things it cannot do are the whole of what this repository is for.

zot update cannot change an item's type. It sets fields on an item that already exists as whatever it was imported as, and an RFC is never imported as the right thing: the IETF datatracker translator produces a report, and a DOI lookup against 10.17487/… produces a book or a journalArticle. Changing the type means sending the whole item back through the Web API.

zot attach cannot upload a file, at least not to the API as it now behaves. Zotero answers an upload authorization request in one of two shapes: the older one hands back prefix and suffix, ready-made multipart strings to put the bytes between, and the current one hands back params, an S3 POST policy whose fields have to be assembled into a multipart body — every field first, the file last. zot knows only the first shape and reports Upload failed with nothing further when it meets the second. zotero.py handles both. And even a zot attach that worked would only reach Zotero's own file storage, which a library syncing over WebDAV never reads; see Where the files go.

What an RFC becomes #

Metadata comes from rfc-index.xml, a single file covering every RFC ever published — the only source that knows an RFC has been obsoleted, which is the fact most worth having and the one no importer records.

standard field Value
number RFC 5321
type Request for Comments
status Internet Standard, Proposed Standard, Informational, …
organization by stream: Internet Engineering Task Force (IETF), Independent Submission, and for the pre-stream RFCs Network Working Group, which is what they say on their own first page
committee httpbis Working Group, where the RFC came from one, and empty where it did not — the index says NON WORKING GROUP rather than saying nothing, and that sentinel is not a name
publisher, libraryCatalog RFC Editor
shortTitle RFC 5321, so that a short citation reads as the number
extra STD 97 or BCP 9, then Obsoleted by … and Updated by …

The item key is kept, so attachments, collection membership and dateAdded all survive the rewrite. Every field the type has is written even when empty, so that what the old type left behind — publicationTitle, reportType, pages — is gone rather than lingering out of sight.

Identifying an RFC is deliberately strict: a whole-field match on the DOI, the report number, or an rfc-editor.org / datatracker.ietf.org URL. Searching loosely finds things that merely cite an RFC — the openspf.org test suite records its filename as test/rfc7208-tests.yml, and a loose match rewrites it into RFC 7208, title and all.

The full text #

rfc_attach.py gives every RFC the canonical text from /rfc/rfcNNNN.txt. For most RFCs that plain text is the published document, so it is the authoritative thing to hold rather than a fallback. Only the 9xxx-era RFCs also have a publisher PDF; the /rfc/pdfrfc/ path that once served generated PDFs for the older ones now answers 404, and a PDF typeset locally would be our artifact rather than something the RFC Editor published. So the older RFCs get text alone, and nothing is missing when they do.

RFCs are freely redistributable under BCP 78 [RFC5378].

An attachment item carrying a filename but no md5 is a half-made one from an interrupted run — nothing was uploaded behind it. rfc_attach.py clears those rather than counting them as present.

Duplicates #

Nothing in the Web API merges two items, so merge_duplicates.py does what Zotero's desktop Merge Items does: the survivor takes the union of the collections and tags, claims the loser's URI through dc:replaces so that anything already citing the old key still resolves, adopts its child attachments, and the loser goes to the trash. --purge empties the trash afterwards, which is permanent and not undoable.

The older item is kept as the survivor, because it holds the unsuffixed citation key — Better BibTeX gives the second arrival a trailing a, and the unsuffixed one is what anything written so far will have cited.

Writing to Zotero #

Both write paths go through POST /users/<library_id>/items, at most fifty items per call, each carrying the version it was last read at. A stale version fails that one item with an HTTP 412 and lets the rest of the batch through, so the recovery is to re-read the versions and re-send only what was refused, never to start the batch over.

Where the files go #

A Zotero library keeps its attachment files in one of two places, chosen in the desktop's sync preferences: Zotero's own file storage, or a WebDAV server. The desktop only ever looks in the one it was told to use. The Web API can only upload to Zotero's own storage, so a file uploaded through it to a library that syncs over WebDAV turns up as an attachment the desktop lists and cannot open — the file is not on disk, and not on the WebDAV server either.

So the upload in zotero.py goes where the desktop will look. When ~/.config/zot/config.toml has a [webdav] table, files go to that server:

[webdav]
url = "https://zotero.example.org"   # as in the desktop's sync preferences
username = "me"
password = "…"

They are laid out as the desktop lays them out [ZOTERO-WEBDAV]: zotero/ is appended to the URL, and each attachment is two files there — <KEY>.zip, holding the file, and <KEY>.prop, a scrap of XML giving the file's mtime in milliseconds and its md5. The .zip goes first and the .prop second, so an interrupted upload leaves nothing that claims a file is there. The attachment item is then given the same md5 and mtime, which is how the desktop learns which version the server holds; the Web API accepts those two fields directly only for WebDAV libraries.

Without a [webdav] table, files go to Zotero's own storage in four steps: create the attachment item, ask for upload authorization with the file's md5, name, size and mtime, post the bytes where the answer says, then register the upload. If authorization answers exists, Zotero's storage already held those bytes under that md5 and there is nothing to send — which says nothing about whether a desktop syncing over WebDAV can open the file. For that reason an upload is refused outright when there is no [webdav] table but the desktop on the same machine (its profile's prefs.js) syncs over WebDAV.

storage_restore.py repairs a library where that has already happened. It checks every stored attachment's .prop on the WebDAV server, and for each one missing or naming a different md5 it copies the file there from wherever a copy with the right md5 turns up: the desktop's storage directory, then Zotero's own storage. --local also writes missing files into the desktop's storage directory, <data_dir>/storage/<KEY>/<filename>, stamped with the item's mtime; that is the way back on a machine with no WebDAV configured.

Licence #

MIT, and REUSE compliant — nix develop -c reuse lint is the check.

References cited #

  • [RFC-INDEX] RFC Editor, "RFC Index", rfc-index.xml, https://www.rfc-editor.org/rfc-index.xml. Every RFC's title, authors, date, page count, abstract, status, stream, working group, DOI, and the is-also, obsoleted-by and updated-by cross references. The whole of what rfc_standardize.py writes comes from here.
  • [ZOTERO-API] Corporation for Digital Scholarship, "Zotero Web API v3", https://www.zotero.org/support/dev/web_api/v3/start. Item writes, the fifty-item batch limit, and the If-Unmodified-Since-Version and per-item version conditions that make a concurrent edit fail rather than be overwritten.
  • [ZOTERO-UPLOAD] Corporation for Digital Scholarship, "File Upload Authorization", Zotero Web API v3, https://www.zotero.org/support/dev/web_api/v3/file_upload. The four-step upload, and the exists answer that means the server already held the bytes. The params authorization shape that zot attach does not handle was read off the live API rather than from here.
  • [ZOTERO-WEBDAV] Corporation for Digital Scholarship, Zotero, chrome/content/zotero/xpcom/storage/webdav.js, commit db41b99, https://github.com/zotero/zotero/blob/db41b99fddcc52d38897c59c161b6adaca036afb/chrome/content/zotero/xpcom/storage/webdav.js. The desktop's WebDAV file sync: the zotero/ directory under the configured URL, the <KEY>.zip and <KEY>.prop pair, and the .prop's <properties version="1"> format.
  • [ZOTERO-SCHEMA] Corporation for Digital Scholarship, "Zotero Item Type and Field Schema", https://api.zotero.org/schema. Which fields the standard item type has, and that it takes author, editor and contributor creators.
  • [RFC5378] Bradner, S., Ed. and J. Contreras, Ed., "Rights Contributors Provide to the IETF Trust", BCP 78, RFC 5378, November 2008, https://www.rfc-editor.org/info/rfc5378. Why the full text of an RFC can be copied into a library at all.