Ask Copilot to Fix It
You saw the bug in the previous section: APPLE against SPEED, second P comes back yellow when it should be gray. The buggy logic is in src/lib/evaluate.ts. Let’s hand it to Copilot.
Write the Prompt
In the Chat view, start a new chat (the + button) and type:
I think there is a bug in this app. When I guess APPLE against target SPEED, the second P in APPLE comes back as "present" when it should be "absent". I think each letter in the target should only be claimable once. Can you figure out what's wrong and propose a fix?

On my computer, when I tried this prompt, Copilot immediately responded with:
I’m going to inspect the word-evaluation logic and reproduce the duplicate-letter case so I can pinpoint exactly why the second P is being marked present and then patch it safely.
It took a moment, and then it said:
I’m now gathering the exact evaluator and related state usage so I can trace how duplicate letters are currently handled and identify the minimal, correct fix.
It then took another moment to review two files (evaluate.ts and game-store.ts) and then it continued:
I found the root cause: the evaluator uses
target.includes(...)per letter, which over-credits duplicates. I’ll confirm there is no existing test harness and then patchevaluateGuessto use a two-pass “consume letter counts” algorithm.
It then reviewed two more files (package.json and README.md) and said:
I’m applying a focused fix in the evaluator now: mark exact matches first, then allocate remaining target letters to “present” at most once each so duplicates are handled correctly.
It then edited evaluate.ts. The edited code is highlighted in the file as a diff, as shown in this screenshot:

Copilot next said:
I’m validating the fix with a direct evaluator check plus project health checks, then I’ll report the exact result for
APPLEvsSPEED.
It then showed me a prompt where it asks for my permission to run this code:
pnpm dlx tsx -e "import { evaluateGuess } from './src/lib/evaluate.ts'; console.log(evaluateGuess('APPLE','SPEED'));"

I clicked on the “Allow” button, and it ran the code. The output was:
[ 'absent', 'correct', 'absent', 'absent', 'present' ]
It then asked for my permission to build the project:

Once the build was successful, it finished with:
You were exactly right about the bug.
Problem:
The evaluator in `evaluate.ts` used `target.includes(guess[i])` for each letter independently. That makes duplicate letters in the guess over-claim matches from the target.
Why `APPLE` vs `SPEED` was wrong before:
- First `P` is `correct` at index 1.
- Second `P` should be `absent` because the only `P` in `SPEED` is already consumed.
- Old logic still saw `P` "exists in target" and marked it `present`.
Fix applied in evaluate.ts:
1. First pass marks `correct` letters and counts only unmatched target letters.
2. Second pass marks `present` only if that letter still has remaining count, then decrements it.
This enforces "each target letter is claimable once."
Validation:
- Direct check now returns `['absent', 'correct', 'absent', 'absent', 'present']` for `APPLE` vs `SPEED` (correct behavior).
- `pnpm run build` passes.
Made changes.
This is the kind of task Copilot is good at. You described a concrete bug, and it found the relevant code, proposed a plausible fix, and checked the specific case you gave it.
Verify in the Browser
Run the app in the browser if it is not already:
pnpm dev
Refresh the page (the target resets to SPEED). Type APPLE and press Enter.

The second P is now gray, the first P is still green, and the E is still yellow. So the bug is gone in the browser for the case we reproduced. That is worth checking, but it is only one case.
Click on the “keep” button in the Copilot chat view to finalize the change. Then read the evaluateGuess function in evaluate.ts, which is where the fix happened, and try to follow the two-pass logic it uses to enforce the “claim once” rule for target letters. Ask Copilot if you have questions about how the new code works.
Checkpoint: Commit your progress.
git add .
git commit -m "wordle-1: Fix duplicate-letter bug in evaluateGuess with Copilot"
git push