Worked Example - Working Memory and the Scaffolding Loop
Companion to Chapter 6. A scaffolding-loop trace for a real task: refactoring a payment-processing module across four files while a session limit looms. The example shows how NOTES.md protects state across the context-cliff that would otherwise force a restart.
The task
Refactor PaymentProcessor from a single 800-line class into four cohesive modules (input validation, gateway interaction, ledger write, notification dispatch) without breaking the 47 tests that cover the existing behavior.
The discipline
Three of the seven commitments carry the loop here:
- Verifiable stop - the test suite is the stop. No iteration is "done" until
npm testreturns 0. - Externalized memory -
NOTES.mdholds the refactor plan and per-iteration state. Survives a/compact. - Debt accumulation - the "tried and abandoned" section records dead-ends so the loop does not revisit them.
Iteration 1 - frame and plan
NOTES.md after iteration 1
Iteration 2 - extract InputValidator
Extract validators to src/payment/InputValidator.ts; update PaymentProcessor to delegate. Run tests.
Test result
NOTES.md update
Iteration 3 - extract GatewayClient, hit a test failure
Test result
NOTES.md update - failure captured
Iteration 4 - context-cliff event
Session hits the working-memory limit. The harness runs /compact. Earlier conversation is summarized; only the most recent exchanges remain in the rolling window.
Without NOTES.md, the loop would lose state: the partner would not remember which modules were already extracted, what failure modes were tried, or that the GatewayClient test fixture had been updated. With NOTES.md, the next iteration reads the file and resumes:
The context cliff is invisible to the loop's progress because the loop's state was never in the context to begin with - it was in the file.
Iterations 5–6 - finish and verify
LedgerWriter extracts cleanly (47/47). NotificationDispatcher extracts cleanly (47/47). Final PaymentProcessor.ts is 180 lines (the orchestration); the four extracted modules sum to 620 lines (down from the original 800 due to deduplication).
Architectural takeaway
The scaffolding loop did not make the partner smarter. It made the partner's state survivable. The same task without NOTES.md would have hit the context cliff and started losing track of what was done. With it, the loop ran for as long as the task needed.
Three commitments carried this trace; the other four (maker/checker, materiality gating, frame before solve, visible verification) are present but less load-bearing in this particular example. See the seven-commitments deep treatment for the failure mode of each when absent.
Practitioner templates
The working-memory prompts page hosts the NOTES.md template used in this trace, plus the scaffolding-loop contract and the verifiable-stop checklist.