> For the complete documentation index, see [llms.txt](https://faction-os.gitbook.io/faction-os-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://faction-os.gitbook.io/faction-os-docs/.spec_system/archive/sessions/phase22-session05-store-folding-and-selectors/code-review.md).

# Code Review and Repair Report

**Session ID**: `phase22-session05-store-folding-and-selectors` **Package**: apps/web **Reviewed**: 2026-07-05 **Base Commit**: ec25d6f1b172b9f8cc32f8f805e510c8e0cbef63 **Scope**: All changes since the base commit (uncommitted work plus mid-session commits) **Result**: RESOLVED

## Review Surface

**Files reviewed** (all changes since the base commit before this report):

* `.spec_system/state.json` - tracked-modified
* `.spec_system/specs/phase22-session05-store-folding-and-selectors/spec.md` - untracked
* `.spec_system/specs/phase22-session05-store-folding-and-selectors/tasks.md` - untracked
* `.spec_system/specs/phase22-session05-store-folding-and-selectors/implementation-notes.md` - untracked
* `apps/web/src/store/useGameStore.ts` - tracked-modified
* `apps/web/tests/gameProjectionStore.test.ts` - untracked
* `docs/game-design/README_game-design.md` - tracked-modified
* `docs/game-design/14-implemented-phases.md` - untracked
* `docs/game-design/15-phases-yet-to-be-implemented.md` - untracked

**Inventory commands**: `git status`, `git log --oneline "$BASE"..HEAD`, `git diff "$BASE"`, `git diff --cached "$BASE"`, `git ls-files --others --exclude-standard`

## Findings by Severity

### Critical

No findings.

### High

No findings.

### Medium

No findings.

### Low

* `.spec_system/state.json:493` - The session state diff had removed the existing `phase21-session05-quest-board-and-war-room-parity` `validated` history entry while setting the current Phase 22 Session 05 pointer. Fix: restored the historical entry and left only the intended current-session and Session 05 planned bookkeeping changes. Status: FIXED.
* `docs/game-design/15-phases-yet-to-be-implemented.md:10` - The new backlog document contained non-ASCII punctuation and symbols, but the session workflow requires ASCII-only output. Fix: converted the new file to ASCII equivalents and tightened the converted wording where needed. Status: FIXED.

## Assumptions and Deliberate Non-Fixes

* The new `docs/game-design/14-implemented-phases.md` and `docs/game-design/15-phases-yet-to-be-implemented.md` files are outside the app-code deliverables for Session 05, but they are linked from `docs/game-design/README_game-design.md` and act as design-package tracking artifacts. I left them in place after fixing the ASCII issue because they do not affect runtime behavior, package checks, or the store projection contract.

## Behavior Changes

* Review fixes changed no runtime behavior.
* The reviewed implementation intentionally adds store-level projection hydration, one fold per `applyEvent`, selectors, and reset memory behavior per `spec.md`.

## Evidence Ledger

| Check                    | Command or Inspection                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Result                                                                                                          | Evidence / Blocker                                                                                                            |
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| Analyzer                 | `if [ -d .spec_system/scripts ]; then bash .spec_system/scripts/analyze-project.sh --json; else bash /home/aiwithapex/.codex/plugins/cache/apexdev/apex-spec/2.2.18-codex/skills/apex-spec/scripts/analyze-project.sh --json; fi`                                                                                                                                                                                                                                                                                                 | PASS                                                                                                            | Current session resolved to `phase22-session05-store-folding-and-selectors`; monorepo true; package list includes `apps/web`. |
| Inventory                | `git status --short`; `git log --oneline "$BASE"..HEAD`; `git diff "$BASE"`; `git diff --cached "$BASE"`; `git ls-files --others --exclude-standard`                                                                                                                                                                                                                                                                                                                                                                              | PASS                                                                                                            | No mid-session commits; no staged changes; tracked changes plus six untracked implementation/docs files inventoried.          |
| Source inspection        | \`nl -ba apps/web/src/store/useGameStore.ts                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | sed -n '450,520p'`;` sed -n '1288,1348p'`;` sed -n '1620,1685p'`;` sed -n '2428,2498p'`;` sed -n '3540,3625p'\` | PASS                                                                                                                          |
| Test inspection          | \`nl -ba apps/web/tests/gameProjectionStore.test.ts                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | sed -n '1,360p'\`                                                                                               | PASS                                                                                                                          |
| Reducer inspection       | \`nl -ba apps/web/src/lib/gameProjection.ts                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | sed -n '1080,1145p'`;` sed -n '1640,1725p'`;` sed -n '1940,2105p'\`                                             | PASS                                                                                                                          |
| Documentation inspection | `sed -n '1,520p' docs/game-design/15-phases-yet-to-be-implemented.md`; `sed -n '1,260p' docs/game-design/14-implemented-phases.md`; `git diff -- docs/game-design/README_game-design.md`                                                                                                                                                                                                                                                                                                                                          | PASS                                                                                                            | New docs are linked and inspected; ASCII repair applied to the backlog doc.                                                   |
| Focused tests            | `npm test -- apps/web/tests/gameProjectionStore.test.ts apps/web/tests/gameProjection.test.ts`                                                                                                                                                                                                                                                                                                                                                                                                                                    | PASS                                                                                                            | 2 files passed; 33 tests passed.                                                                                              |
| Web typecheck            | `npm --workspace @factionos/web run typecheck`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | PASS                                                                                                            | `tsc -b --noEmit` exited 0.                                                                                                   |
| Changed-file Biome       | `npm exec -- biome check apps/web/src/store/useGameStore.ts apps/web/src/lib/gameProjection.ts apps/web/tests/gameProjectionStore.test.ts`                                                                                                                                                                                                                                                                                                                                                                                        | PASS                                                                                                            | 3 files checked; no fixes applied.                                                                                            |
| State JSON parse         | `node -e "JSON.parse(require('fs').readFileSync('.spec_system/state.json','utf8')); console.log('state json ok')"`                                                                                                                                                                                                                                                                                                                                                                                                                | PASS                                                                                                            | State file parsed successfully after the history restoration.                                                                 |
| Formatter                | `npm run format:check`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | PASS                                                                                                            | 774 files checked; no fixes applied.                                                                                          |
| Linter                   | `npm run lint`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | PASS                                                                                                            | 776 files checked; no fixes applied.                                                                                          |
| Type checker             | `npm run typecheck`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               | PASS                                                                                                            | All configured workspace typecheck scripts passed.                                                                            |
| Tests                    | `npm test`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | PASS                                                                                                            | 276 files passed, 1 skipped; 3192 tests passed, 1 skipped.                                                                    |
| ASCII                    | `LC_ALL=C grep -n '[^[:print:][:space:]]' .spec_system/state.json .spec_system/specs/phase22-session05-store-folding-and-selectors/spec.md .spec_system/specs/phase22-session05-store-folding-and-selectors/tasks.md .spec_system/specs/phase22-session05-store-folding-and-selectors/implementation-notes.md apps/web/src/store/useGameStore.ts apps/web/tests/gameProjectionStore.test.ts docs/game-design/README_game-design.md docs/game-design/14-implemented-phases.md docs/game-design/15-phases-yet-to-be-implemented.md` | PASS                                                                                                            | No non-ASCII bytes found.                                                                                                     |
| LF endings               | `grep -l $'\r' .spec_system/state.json .spec_system/specs/phase22-session05-store-folding-and-selectors/spec.md .spec_system/specs/phase22-session05-store-folding-and-selectors/tasks.md .spec_system/specs/phase22-session05-store-folding-and-selectors/implementation-notes.md apps/web/src/store/useGameStore.ts apps/web/tests/gameProjectionStore.test.ts docs/game-design/README_game-design.md docs/game-design/14-implemented-phases.md docs/game-design/15-phases-yet-to-be-implemented.md`                            | PASS                                                                                                            | No CRLF files found.                                                                                                          |
| Privacy/debug scan       | \`rg -n "debugger                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 | console\\.log                                                                                                   | TODO                                                                                                                          |
| Final diff re-read       | `git diff "$BASE"` plus full reads of untracked text files                                                                                                                                                                                                                                                                                                                                                                                                                                                                        | PASS                                                                                                            | Remaining changes match the session scope plus linked design tracking docs; no unresolved findings remain.                    |

## Summary

1. Reviewed nine implementation and documentation files present before this report, plus the base-commit diff and untracked text inventory.
2. Fixed two low-severity findings: restored a removed state-history entry and converted the new backlog doc to ASCII.
3. Deliberately left the linked design tracking docs in place as non-runtime documentation artifacts.
4. Evidence passed for focused tests, full Vitest, formatter, linter, workspace typecheck, changed-file Biome, JSON parsing, ASCII, LF endings, and final diff reread.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://faction-os.gitbook.io/faction-os-docs/.spec_system/archive/sessions/phase22-session05-store-folding-and-selectors/code-review.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
