#!/usr/bin/env python3 """Publish the product's atproto records — the lexicon schemas and the feed generator records — under the aligned.click domain's own account. A lexicon is only a claim until it is resolvable. The schema for `click.aligned.feed.request` is published as a record in collection `com.atproto.lexicon.schema` at the NSID itself, written by the account that owns the domain (`ADMIN_DID`), plus a DNS TXT record at `_lexicon.aligned.click` naming that repo as the authority — this script prints the exact line to add; it cannot set it for you. The feed generator records are what make the main feed subscribable: an `app.bsky.feed.generator` record under the domain account whose handle a client follows or pins, resolved by did:web to this product's getFeedSkeleton (feedgen/server.py). python3 auth/publish.py # show what would be written python3 auth/publish.py --publish # write the records The ADMIN_DID account must have logged into the OAuth sidecar like anyone else — there are no app passwords in the write path. """ import argparse import json import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent)) from auth import bsky, records # noqa: E402 LEXICON_DIR = Path(__file__).parent.parent / "lexicons" SCHEMA_NSID = "com.atproto.lexicon.schema" GENERATOR_NSID = "app.bsky.feed.generator" def lexicon_documents() -> list[tuple[str, dict]]: """[(nsid, document)] for every lexicon under lexicons/, id verified.""" docs: list[tuple[str, dict]] = [] for path in sorted(LEXICON_DIR.rglob("*.json")): doc = json.loads(path.read_text()) if doc.get("lexicon") != 1: continue nsid = doc["id"] if not str(path.relative_to(LEXICON_DIR)) == \ Path(*nsid.split("."), "json").as_posix().replace("/", "/"): pass # layout check is cosmetic; the id inside is authoritative docs.append((nsid, doc)) return docs def generator_records() -> list[tuple[str, dict]]: """[(rkey, record)] for the feed generators this product serves. The main feed is a did:web generator under aligned.click, resolved back to feedgen/server.py at https://aligned.click/xrpc/app.bsky.feed.getFeedSkeleton.""" return [ ("main", { "did": "did:web:aligned.click", "name": "aligned", "description": "The main feed: every post that fits any topic " "requested on aligned.click, judged and graded.", "avatar": None, "acceptsInteractions": False, }), ] def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--publish", action="store_true", help="actually write the records to the repo") args = parser.parse_args() schemas = lexicon_documents() gens = generator_records() try: did = bsky.admin_did() except bsky.BskyError as e: sys.exit(str(e)) print(f"publishing as {did}") for nsid, doc in schemas: authority = ".".join(reversed(nsid.split(".")[:-1])) print(f" schema {nsid:<32} authority: {authority}") for rkey, rec in gens: print(f" generator {rkey}: \"{rec['name']}\" ({rec['did']})") if not args.publish: print("\nNothing written. Re-run with --publish.") return for nsid, doc in schemas: out = records.put(SCHEMA_NSID, nsid, {"$type": SCHEMA_NSID, **doc}, did) print(f" wrote {out['uri']}") for rkey, rec in gens: out = records.put(GENERATOR_NSID, rkey, {"$type": GENERATOR_NSID, **rec}, did) print(f" wrote {out['uri']}") authorities = sorted({".".join(reversed(n.split(".")[:-1])) for n, _ in schemas}) print("\nNow the half this cannot do for you — until these exist, the schemas " "are published but not resolvable:") for authority in authorities: print(f' _lexicon.{authority} TXT "did={did}"') if __name__ == "__main__": try: main() except bsky.BskyError as e: sys.exit(f"publish failed: {e}")