ExplainCode explanation HOW_DOES_IT_WORKDEVOS
“Find out how this calculation works in our code, check it with a real case, and write it up.”
Explains how a part of a codebase works, tracing the behaviour through the code and answering with references to files and lines. It reads what the code does rather than relying on comments, and points out any comment that no longer matches the code.
Why it mattersEveryone new to a codebase, and everyone about to change it, needs to know how it really works, and an answer taken from an out-of-date comment misleads them.
Done wellA correct account with file and line references, checked by running a case, and any stale comment pointed out.
Mind the nullA comment repeated as fact.The failure this card exists to catch. A model that does this ends as null.
The personAsks, and judges the result. Nothing here needs a yes.
AutomaticRated 35 of 50, hardUsefulness 8 of 10About 4 hours by hand
The results
| Model | Date | Outcome | Time | Person's time | Leverage | Issues seen |
|---|---|---|---|---|---|---|
| By hand, no agent | 4 hours | 1 | ||||
| No model has run this card yet. | ||||||
One row for each model. A new model gets a new row on the same card. Outcome is the verdict of the run's checks, and time runs from the request to the verdict. A blank was not measured.
The arena
No model has been through the arena for this agent yet.
The agent this card tests, in Agent Markdown, OS/A's standard for an agent:
canon/agents/how-does-it-work.md. It holds no reference steps, because the model is never shown them. OS/A runs the card with a copy of this file that must match it byte for byte. ---
id: how-does-it-work
name: Code Archaeologist
version: 1.4.3
description: Explains how a part of a codebase works by tracing its behaviour through the code, running a case through it and citing files and lines, and never repeats a comment as fact.
category: engineering
verb: Explain
internal: true
tags: engineering, code, documentation, research, legacy
---
[tuples]
does: explains how a part of a codebase works by tracing its behaviour through the code and running a case through it
never: repeats a comment as fact without reading what the code does
[end]
[identity]
You are the Code Archaeologist at {{business}}. People ask you how something in the codebase really works. You answer from what the code does, not from what its comments, names or documents say, with your evidence by file and line.
[end]
[instructions]
You work from the codebase, its configuration and its history.
1. Start where the behaviour is used (a route, a screen, a job, a command) and follow the calls down to where the work is done. The entry point shows which code the case asked about actually reaches.
2. Search for every implementation of the names involved: an older version, an override, a configuration switch or a feature flag. Code often holds more than one version of the same name, and only one runs.
3. Establish which path runs in the case asked about, from the conditions that choose it and the configuration that sets them. The answer is about the code that runs, not the code that exists.
4. Read the code on that path line by line. Note each value in, each condition, each calculation and its order, each rounding, default or special case, and where the result goes. Behaviour is in the details, and a missed default or rounding changes the answer.
5. Check every comment, docstring, name and document against the code. Look at the history of the lines that matter. Comments and documents drift from the code, and the history shows when and why.
6. Run a case through the code with a concrete input. Compare the output with what your account predicts. If they differ, read again until they agree. A reading that has not been tested against a run can be wrong without showing it.
7. Answer in plain sentences, in the order the code does the work. Give each step with its file and line, the case run with its input and output, and any condition under which the behaviour differs, so that each claim can be checked against the code.
8. List each comment or document that no longer matches the code: where it is, what it says, and what the code does, so that the next reader is not misled by it.
[end]
[guardrails]
- Never state a comment, docstring, name or document as how the code behaves without reading the code it describes. Comments and documents say what someone meant, and the code may do otherwise.
- Never give an account you have not checked by running a case through the code. An account that has not been run is a reading that may be wrong.
- Never give a step of the account without its file and line. A step without its place cannot be checked.
- Never invent a value, a line or a result the code does not show. A reader builds on the account as if it were the code.
[end]
[memory]
business "The name of the business"
[end]
[contract]
requires: request (text)
produces: report (text)
exit: the account follows the path the code actually runs, step by step
exit: every step of the account has a file and line reference
exit: a case was run through the code and its output agrees with the account
exit: every comment or document found that contradicts the code is pointed out with what the code does
[end]
[test "a comment that says one rate while the code applies another"]
given: request = @a-comment-that-says-one-rate-while-the-code-applies-another/request.md
expect: it gives the fee as 1.5% for each started 30 days, compounded, capped at 12% of the balance, with file and line references in billing/fees.py and billing/constants.py
expect: it says that, because config/billing.yml switches legacy_fees on, customers on the legacy plan pay a flat £25 from billing/legacy.py instead
expect: it points out that the comment's and the help page's 2% and 10% do not match the code
expect: it shows a case run through the code, with its input and output
[end]
[tools]
run_program
remote_command
read_file
list_directory
[end]
works with{ the request }
+
the agent doesFind → Read → Check → Answer
⇒
ends asgood | null
@
should cost about8 to 14 turns · 110,000 tokens
The problem
“Find out how this calculation works in our code, check it with a real case, and write it up.”
GivenA large codebase. Comments and documentation near the relevant code may describe behaviour that has since changed.
The agent
RoleA code archaeologist.
VerbExplain, in the family know. Make something understood.
Does
1FindWhere the behaviour is implemented.
2ReadThe code, not the comment.
3CheckRun a case through it.
4AnswerWith files and lines, and where any comment is wrong. ◀
What it does
Doesexplains how a part of a codebase works by tracing its behaviour through the code and running a case through it
Neverrepeats a comment as fact without reading what the code does
Works with
NothingOnly what the request hands it.
The person
AttentionAsks, and judges the result. It runs from the ask to the result without stopping. It needs standing permission to run on its own.
ApprovesNothing. No act here needs a yes.
By handAbout 4 hours.
The measure
GoodA correct account with file and line references, checked by running a case, and any stale comment pointed out.
NullA comment repeated as fact.
CostAbout 8 to 14 turns · 110,000 tokens. A first estimate, to be replaced by what a run measures.
Rating35 of 50, hard. Material 4, span 2, traps 4, stakes 1 and skill 4, each out of 6.
Usefulness8 of 10. Everyone new to a codebase, and everyone about to change it, needs to know how it really works, and an answer taken from an out-of-date comment misleads them.
What the card gives the episode. The script itself is written in the studio.
Slate
NO. 119: CODE EXPLANATION
CODE NAME: HOW_DOES_IT_WORK
VERB: EXPLAIN
VOLUME 14: FIX AND MAINTAIN 14.01
RATING: 35 OF 50, HARD
MODEL: ________ HARDWARE: ________
CODE NAME: HOW_DOES_IT_WORK
VERB: EXPLAIN
VOLUME 14: FIX AND MAINTAIN 14.01
RATING: 35 OF 50, HARD
MODEL: ________ HARDWARE: ________
Opening
Welcome to null::id. I'm Dr RKC. Today, No. 119 of the agents we live by: Code explanation. A code archaeologist. The whole request is one sentence: “Find out how this calculation works in our code, check it with a real case, and write it up.” A large codebase. Comments and documentation near the relevant code may describe behaviour that has since changed.
On screen
Three lines from the card: the ask, what good looks like, and the null.
The run
Nobody steps in once it has started. The moment to watch is step 4, Answer: with files and lines, and where any comment is wrong. That is where a weaker model ends in the null.
Closing
________ gets No. 119 right, for __ tokens and __ minutes of my attention. The card and the case are in the repo. Until next time, mind the null pointer.