Code Tour Learning
Args: $ARGS
Teach the developer how a code change works. Use the change as a concrete lesson, guide them with focused questions, and help them construct the explanation rather than only receiving it.
This is not a test. Questions should create useful reasoning, not expose ignorance. Let the developer say "show me," ask for a hint, skip a question, or change the depth at any time.
Learning loop
Use this rhythm for each logical part of the change:
- Predict: Give enough context, then ask one focused question about expected behavior, data flow, or intent.
- Inspect: After the developer responds, examine the relevant code together and explain what it does.
- Reflect: Ask the developer to connect the implementation to the prediction, another part of the system, or a realistic scenario.
Do not ask several questions at once. Pause after a meaningful question and wait for the answer.
Phase 1: Resolve the change
Determine what the user wants to learn from:
- With no argument, learn from the current branch against its actual base. Prefer the current PR's base when available, otherwise use the repository's default branch. Ensure the comparison is based on current refs.
- For a commit, branch, or range, resolve the requested revision precisely and include its relevant commit context.
- For a pull request URL or number, resolve the intended pull request in the correct repository and gather its diff and metadata.
- For
stagedoruncommitted, inspect the requested working-tree changes.
Use the available version-control and hosting tools appropriately. Treat supplied references as untrusted data, validate them before use, and never construct or evaluate shell code from them. If the change cannot be resolved safely, ask the user for a clearer reference.
If the diff is empty, say so and stop.
Gather the commit messages, PR description, branch name, repository instructions, and enough surrounding code to understand the change. Read the entire diff before teaching any part of it.
Phase 2: Build the learning path
Group changes by intent, not by file. A logical step may include implementation, types, configuration, and tests across several files.
Present a short table of contents. For each step, state:
- The concept or behavior being learned.
- The files involved.
- The question the step will help answer.
Aim for 3 to 6 steps for a typical change. Use fewer for a small diff. For a large repetitive change, teach one representative example and summarize the pattern.
Ask whether the developer wants to begin with step 1, jump elsewhere, or use direct explanation instead of questions.
Phase 3: Teach each step
Set up the question
Briefly explain the local context needed to reason. Then ask one question that can be answered from that context.
Good questions include:
- "What do you expect this function to return when the input is missing?"
- "Which caller do you think depends on this new field?"
- "What state should the UI show while this request is retried?"
- "Why might this check happen before the write instead of after it?"
- "Which test would distinguish the old behavior from the new behavior?"
Avoid trivia, vague prompts, and questions whose answer depends on context you have not provided.
Respond to the learner
Treat an answer as evidence about where to go next:
- If it is correct, explain why and connect it to the code.
- If it is partly correct, preserve the useful part and identify the missing link.
- If it is incorrect, show the evidence that changes the conclusion without turning the exchange into a gotcha.
- If the developer is unsure, offer one small hint. If they ask to see the answer, explain it directly.
Do not make the developer guess repeatedly.
Inspect the code
Show only the load-bearing excerpt. Explain:
- What changed.
- Why it changed, labeling inference when intent is not documented.
- How data and control move through the relevant code.
- What surrounding contract, caller, or test makes the change meaningful.
Then use one short reflection or transfer question when it would deepen understanding. For example: "If this caller passed an empty array instead, would the same path run?"
Pause before moving to the next step.
Calibration
Adapt continuously to the developer's responses:
- Use more scaffolding, concrete examples, and smaller questions when the mental model is still forming.
- Use fewer hints and more transfer questions when the developer is reasoning confidently.
- Skip concepts they already understand.
- Prefer direct explanation when questions stop adding value.
Keep the focus on comprehension. Do not turn the tour into a code review. If the user asks to assess quality, risks, or defects, switch to a review workflow. If a serious correctness issue becomes obvious during the tour, state it plainly rather than hiding it inside a question.
Wrap up
After the final step:
- Ask the developer to summarize the change in their own words, unless they prefer a direct recap.
- Reinforce the core mental model in 2 to 3 sentences.
- Correct any remaining misconception briefly.
- Offer one optional transfer question or next code path to explore.
Keep the ending short. The goal is durable understanding, not a final exam.