Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goat: repo inspect --mst flag for displaying MST structure #885

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

devinivy
Copy link
Contributor

@devinivy devinivy commented Dec 20, 2024

This adds a flag --mst to goat's repo inspect command. When passed, the command will output a representation of the repository's MST structure. It may also be used to display the partial MST of a repository, i.e. in the case of a record proof.

As part of this work I exposed the NodeData and TreeEntry types from the mst module, which are sufficient for working with raw MST data.

The output is intended to be a faithful representation of the MST:

  • Siblings items are entries within a single data node.
  • The dots (....) represent the length of the key prefix.
  • The text after the dots is the rest of the key.
  • The hashes in parens are the last 7 characters of the CID pointer represented in base32.
  • Each CID pointer points to either a. a subtree (i.e. another data node) when they appear alone or b. a record block when they appear next to a key.
  • The appears in the output when the block behind a CID pointer is not present, which should not occur when inspecting a full repository but is generally expected when inspecting a proof.

Example:

$ curl 'https://morel.us-east.host.bsky.network/xrpc/com.atproto.sync.getRecord?did=did:plc:l3rouwludahu3ui3bt66mfvj&collection=app.bsky.feed.like&rkey=3jwnnk25rrk2s' > record-proof.car
$ goat repo inspect --mst ./record-proof.car
(lxmb3rm)
├── (cpibfny)
│   ├── (veqbjjq)
│   │   └── (s4zluvy)
│   │       ├── (6qiyhle) ✗
│   │       ├── app.bsky.feed.like/3jqa6sh7bic2a (edo6qsa) ✗
│   │       ├── (xswayqm) ✗
│   │       ├── .....................sfpt3arg22b (glnh3mi) ✗
│   │       ├── (55dhu6q) ✗
│   │       ├── .....................urpqzpats2e (xqygjyq) ✗
│   │       ├── (pblbwl4) ✗
│   │       ├── .....................wnnk25rrk2s (feoom4e)
│   │       └── (3jwkksm) ✗
│   ├── app.bsky.feed.like/3kb4ztebs4324 (hc4ruf4) ✗
│   └── (t4os5oq) ✗
├── app.bsky.feed.post/3kps37ajdyk24 (yk4ymya) ✗
└── (chuh4na) ✗

@bnewbold
Copy link
Collaborator

I like it! And cool how (relatively) little code this is.

A couple high-level notes before I dig in to code and play with it myself:

  • I think this could be a separate command: goat repo mst
  • would be very open to color for this. I don't think we have a CLI color library in go but would be open to adding a small one as a dep
  • the partial CIDs make me double-take. what if we prefixed like cid:lxmb3rm? or maybe in square brackets with elipses [lxmb3rm…]? color might help. maybe a CLI flag/arg to control "full CID" vs "partial CID" (for those of us with big monitors?)
  • I like visually differentiating the partial "key" structure, but don't like the collision that technically a period could appear in MST text (even if that would be invalid at the "atproto repo" layer). we could print the full key (collection/rkey) and use "grey text" vs "bold white" to visually emphasize?

Additional feature brainstorming:

  • any special display for the "commit" object as a node above the "root MST" node?
  • ability to visualize entire tree, but highlight the "proof chain" to a single record (by collection/rkey path)
  • ability to parse a full repo CAR file, but display only the proof chain to a single record (distinct from highlighting within the full tree structure)
  • some kind of JSON output structure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants