Learning AI-DLC building a game, part 19: reading the code first
This is part 19 of a series on learning AI-DLC by building a game, World Rift Conflict, in Godot with an AWS backend. Part 18 showed that every piece of work on this game ran a different set of stages. One stage ran in all of them except the first: Reverse Engineering. This post is about what it does, and what seven runs of it on the same codebase found.
Parts so far:
- Part 1: setup
- Part 2: a proof of concept
- Part 3: automated E2E tests
- Part 4: what the reviews caught
- Part 5: inside a stage
- Part 6: a bugfix intent
- Part 7: ideation
- Part 8: inception
- Part 9: an AppSync deploy error
- Part 10: walking skeleton
- Part 11: retrospective
- Part 12: guards and hooks
- Part 13: a UI pass and a release
- Part 14: the memory layers
- Part 15: the agents and roles
- Part 16: when auto mode said no
- Part 17: AI rivals that explain
- Part 18: how scopes pick stages
- Part 19: reading the code first (this post)
The problem
An agent that changes code it has not read guesses. It guesses where things live, which patterns the project uses, and what already exists. Some guesses are wrong, and a wrong guess about existing code is expensive: a design that duplicates a module, a requirement for something already built, a fix in the wrong file.
Reverse Engineering is the first Inception stage. Before any requirement is written, an agent reads the code and writes down what it found.
What it writes
The output is a code knowledge base: nine Markdown files, stored once per space and shared by every later piece of work, in aidlc/spaces/default/codekb/world-rift-conflict/:
business-overview.md: what the product does, for whom, as the code describes it;architecture.md: the parts and how they talk;component-inventory.md: every component, with its files;code-structure.md,dependencies.mdandtechnology-stack.md: folders, packages and tools;api-documentation.md: the operations and messages between parts;code-quality-assessment.md: tests, linting, debt, and the gaps against the new work;reverse-engineering-timestamp.md: when, at which commit, and what was read how closely.
The last file is the one I did not expect to care about. It holds a small YAML block that says which paths were analyzed line by line and which were only skimmed (shallow). The current one, shortened:
kind: partial
intent: export-reports-filter
analyzed:
paths:
- game/export_presets.cfg
- amplify.yml
- package.json
# ...six more
shallow:
paths:
- ./
- game/addons/aws-amplify/
# ...31 more
That block is what lets AI-DLC decide, next time, whether the store can be trusted.
When it runs
The proof of concept in part 2 had no code yet, so the stage was skipped. Its state file says so: "2.1 (reverse-engineering — greenfield)". Every piece of work after that was brownfield and ran it.
At the start of the stage, AI-DLC compares the store with the code:
aidlc engine workspace codekb-scope-diff
After the first scan it found the store stale every time, because the previous piece of work had changed the code. The AI rivals run printed:
STALE: the analyzed paths have changed since the store was built (intent: 261106-game-ui-ux)
Then one question: "A full rescan replaces it; a focused scan merges into it. How should the scan run?" A full rescan reads the whole repository again. A focused scan reads only the paths near the work and keeps the rest of the old store, marked as no longer verified.
After the scan, two checks run before the store is published. The scope check reads the YAML block, for example "VALID: kind full, 1 analyzed path(s), 78 component(s), 25 shallow path(s). The fingerprint matches the source now." The coverage compare checks that the new store does not quietly read less than the old one: "COVERS: the incoming scan covers everything the store analyzed."
Seven scans of the same codebase
| Piece of work | Scan | What the records say |
|---|---|---|
| E2E test automation (part 3) | first | Nine files, with the options for the open choices in the quality assessment |
| E2E review fixes | full | An "Intent issues" section located each issue by file and line |
| E2E follow-ups | full | Re-sized five findings, R-01 to R-05 |
| The game's MVP (part 8) | full | 44 components, 4 shallow paths, about 11 minutes, gaps G1 to G7 |
| UI/UX pass (part 13) | full | 78 components, 25 shallow paths, about 13 minutes and 161 tool calls, gaps UX-G1 to UX-G16 |
| AI rivals (part 17) | full | About 18 minutes and 417,589 tokens, gaps G-AUTH-2 to G-AUTH-7 and G-AI-1 to G-AI-8 |
| Export-filter fix | focused | 9 paths, 4 components, 33 shallow paths, gaps G-RPT-1 to G-RPT-7 |
The component count went from 44 to 78 in eight days, which is the MVP being built. The focused scan is the only one whose coverage compare printed NARROWER instead of COVERS. That was expected: a focused scan of a stale store moves the old whole-repository coverage to shallow, and the approval gate said so before I approved.
Gaps with IDs
Since the MVP, each scan was briefed to record, as observations and not designs, where the code falls short of the new work, with stable IDs. That became a project rule after the MVP's scan.
The IDs are what make the gaps useful. Requirements Analysis starts from the list instead of rediscovering it, and later stages can cite "UX-G14" instead of a paragraph. For the UI pass, UX-G14 was "no existing test can catch the clipping. The off-screen check measures against the root that grows." That gap became requirement FR10.1: "The fit check measures against the window's visible rectangle, not the screen root."
What the scans caught
Two findings changed the work.
Problems the review had missed. The E2E review fixes started from three issues a code review had raised. The scan's "Intent issues" section located each one by file and line, and found two more: the backup of the outputs file was neither git-ignored nor caught by the secrets check, and a missing amplifyAppId let a run continue silently. Both became requirements of the fix (the second is FR2.2: stop when amplifyAppId is missing).
A shortcut that was already gone. I started the AI rivals work with "AI-run countries that negotiate in words and fix the sign-in shortcut". The shortcut was a password sign-in flow the proof of concept had used, and an old note said it was still there. The scan said it was not: the player app client allows only the code flow and refresh (amplify/backend.ts:265-270), and a test asserts the password flow appears nowhere (amplify/backend-synth.test.ts:372). The agent checked those lines itself before reporting it. What was left of the old flow was recorded as G-AUTH-2 to G-AUTH-7, and the sign-in half of the work shrank to cleaning that up.
It also found a smaller thing: the team's practices said the pre-push hook ran 16 checks, and the script ran 17. The next stage corrected the practice from the code without asking me.
What it costs
The three full scans whose time was recorded took about 11, 13 and 18 minutes, and the last one used 417,589 tokens. With collaborators off, one developer agent both reads and writes, so the time is one agent's time.
After the AI rivals scan I kept two rules to keep that down:
- a full scan may read on two levels: the areas the new work touches, line by line, and the rest through each file's header comment and function outline, with the timestamp file saying which level each area got;
- test files, scenes, assets and data are counted by a script and listed, not read line by line, and no pass rate is stated unless the tests were run.
The export-filter fix then used a focused scan of nine files. For a fix in one corner of the build, that was enough.
What I would tell myself
- Pick full or focused by what changed since the last scan, not by the size of the new work. A small fix after a big feature still finds a stale store.
- Read the gap list before Requirements Analysis. It is the cheapest place to learn that part of your request is already done.
- Check old notes against the code. My note about the sign-in shortcut was out of date, and the scan caught it before I wrote requirements for it.
- Look at the shallow paths. They tell you what the store does not know, and a focused scan makes that list longer.
What is next
Measuring the cost of a real match with the model on, on the test backend, before switching the AI rivals on in production.