feat(runtime): add claude.md with runtime overview#15098
feat(runtime): add claude.md with runtime overview#15098jancionear merged 11 commits intonear:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive documentation for the NEAR runtime in a CLAUDE.md file. The documentation provides an overview of how the runtime works, covering key concepts like receipts, actions, accounts, and the receipt processing flow. It's designed to serve as "long-term memory" for AI assistants working with the runtime codebase.
Changes:
- Added CLAUDE.md documentation file explaining runtime architecture and key concepts
- Included Rust struct definitions for core types (ReceiptV0, ActionReceiptV2, Action, AccountV2)
- Documented receipt types, execution flow, and important features like yield/resume and congestion control
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
runtime/runtime/CLAUDE.md
Outdated
| pub struct ActionReceiptV2 { | ||
| /// A signer of the original transaction | ||
| pub signer_id: AccountId, | ||
| /// The receiver of any balance refunds from this receipt if it is different from receiver_id. |
There was a problem hiding this comment.
In the Rust snippet, the comment says "refunds form this receipt" which looks like a typo; it should be "refunds from this receipt" for clarity.
| /// The receiver of any balance refunds from this receipt if it is different from receiver_id. | |
| /// The receiver of any balance refunds from this receipt if it is different from receiver_id. | |
| /// A signer of the original transaction | |
| /// The receiver of any balance refunds from this receipt if it is different from receiver_id. |
runtime/runtime/CLAUDE.md
Outdated
| /// that means we have all the `ReceivedData` input which will be then converted to a | ||
| /// `PromiseResult::Successful(value)` or `PromiseResult::Failed` |
There was a problem hiding this comment.
In the Rust snippet, "will be than converted" should be "will be then converted" ("than" is comparative and reads incorrectly here).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #15098 +/- ##
===========================================
+ Coverage 1.29% 69.00% +67.70%
===========================================
Files 726 921 +195
Lines 141763 204023 +62260
Branches 141763 204023 +62260
===========================================
+ Hits 1839 140783 +138944
+ Misses 139871 57385 -82486
- Partials 53 5855 +5802
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I think we should make it AGENTS.md and symlink CLAUDE.md for compatibility with other agents, as AGENTS.md is standard https://agents.md/ |
runtime/runtime/CLAUDE.md
Outdated
| ```rust | ||
| pub struct ReceiptV0 { | ||
| /// An issuer account_id of a particular receipt. | ||
| /// `predecessor_id` could be either `Transaction` `signer_id` or intermediate contract's `account_id`. |
There was a problem hiding this comment.
Maybe we can omit the code and add reference to keep the context shorter.
There was a problem hiding this comment.
I agree in principle, Claude says:
Copy-pasting structs is mostly a waste of tokens.
What actually helps:
- Reference by name and location: JsonRpcHandler in chain/jsonrpc/src/lib.rs:322 - anyone can jump there
- Describe the why, not the what: "holds async senders to the four backend actors" is more useful than listing every field
- Call out non-obvious fields: If one field has a surprising role or subtle semantics, mention that specific field with a one-liner
explanation
There was a problem hiding this comment.
Removed code, left only names of the structs. I thought about location, but this will be hard to maintain. Claude should be able to grep for the structs by their name.
ssavenko-near
left a comment
There was a problem hiding this comment.
Would be good to add something like "life of a contract". I can do it later, after this is merged. Please address the comment from Darioush and Andrea regarding the code sections. Otherwise LGTM.
| - If the applied chunk is missing (old_chunk), skip the rest | ||
| - Read buffered outgoing receipts and send out as many as possible within the outgoing limits | ||
| - Process transactions in the chunk and convert them to the receipts | ||
| - Process receipts, executing them and producing new outgoing receipts |
There was a problem hiding this comment.
Shall we mention that these are (usually) not the receipts from the previous step?
There was a problem hiding this comment.
I don't know, for local receipts they are often processed in the same chunk as the transaction that created them. Feels like a detail that LLM doesn't need to know about.
runtime/runtime/CLAUDE.md
Outdated
| - Read buffered outgoing receipts and send out as many as possible within the outgoing limits | ||
| - Process transactions in the chunk and convert them to the receipts | ||
| - Process receipts, executing them and producing new outgoing receipts | ||
| - Finalize the post-state |
There was a problem hiding this comment.
That is not very informative in itself. Perhaps worth extending a bit.
There was a problem hiding this comment.
True, not very useful, removed it to save tokens
|
|
||
| Executing actions costs gas. Each receipt has some amount of gas attached to it. If the gas runs out, receipt execution fails. Unused gas is sent back to the transaction author as a gas refund. | ||
|
|
||
| ReceiptSink takes new outgoing receipts and tries to send them out to other shards. If the receipt can't be sent because of outgoing limits, the receipt is stored in a buffer in the shard's trie and will be sent later. |
There was a problem hiding this comment.
This creates an impression that this is the only responsibility of ReceiptSink. At least when I read it. Maybe rephrase to emphasize that this describes the life of outgoing receipts, rather than specifies the ReceiptSink behavior.
There was a problem hiding this comment.
Most of the outgoing receipt management code is in ReceiptSink, so imo we can say that this is its main responsibility.
I'm gonna merge it, should be good enough to start with, we can improve it in the future. The file is 982 words long. From what I read, Claude Opus 4.6 has ~150k words of context. Claude says that it's ok, and could even be bigger. If we wanted to make it smaller we could make it readable on demand? Or split into smaller files. I'll leave that for later. |
Add a CLAUDE.md with a summary of how things work in the runtime.
Hopefully this can serve as a sort of "long-term memory", so that claude doesn't have to relearn everything each time it goes to the runtime.
AFAIU claude should read it whenever it goes into the runtime directory.
It's 100% human-generated
Claude is actually a good motivation to write docs :)