> 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/phase23-session02-ranking-and-presentation-selectors/code-review.md).

# Code Review and Repair Report

**Session ID**: `phase23-session02-ranking-and-presentation-selectors` **Package**: apps/web **Reviewed**: 2026-07-05 **Base Commit**: ed83e7a7670c654c228db767abd018e7f4f39f63 **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):

* `.spec_system/state.json` - tracked-modified session state
* `apps/web/src/lib/legionCamps.ts` - tracked-modified pure selector implementation
* `apps/web/tests/legionCamps.test.ts` - tracked-modified focused Vitest coverage
* `.spec_system/specs/phase23-session02-ranking-and-presentation-selectors/spec.md` - untracked session spec
* `.spec_system/specs/phase23-session02-ranking-and-presentation-selectors/tasks.md` - untracked task checklist
* `.spec_system/specs/phase23-session02-ranking-and-presentation-selectors/implementation-notes.md` - untracked implementation notes
* `.spec_system/specs/phase23-session02-ranking-and-presentation-selectors/code-review.md` - creview report generated by this command

**Inventory commands**: `git status --short`, `git log --oneline ed83e7a7670c654c228db767abd018e7f4f39f63..HEAD`, `git diff ed83e7a7670c654c228db767abd018e7f4f39f63`, `git diff --cached --stat ed83e7a7670c654c228db767abd018e7f4f39f63`, `git ls-files --others --exclude-standard`

## Findings by Severity

### Critical

* None.

### High

* None.

### Medium

* `apps/web/src/lib/legionCamps.ts:219` - The roster-mode boundary promoted 5-hero and 6-hero inputs to `army`, which returned up to 9 visible camps. The Phase 23 Session 02 PRD requires 3-6 heroes to stay in `squad` mode with a 6-camp limit, and 7+ heroes to use `army`. | Fix: changed the squad boundary to `<= 6` and expanded the table-driven test to cover 5, 6, and 7 hero counts at `apps/web/tests/legionCamps.test.ts:419`. | Status: FIXED

### Low

* None.

## Assumptions and Deliberate Non-Fixes

* The Phase 23 Session 02 PRD detailed requirements are the source of truth for roster boundaries when the session `spec.md` is less explicit. Evidence: targeted inspection of `.spec_system/PRD/phase_23/session_02_ranking_and_presentation_selectors.md` lists 3-6 heroes as squad and 7+ heroes as army.
* No deliberate non-fixes remain.

## Behavior Changes

* Five-hero and six-hero ranking inputs now return `rosterMode: "squad"` and `visibleLimit: 6` instead of `rosterMode: "army"` and `visibleLimit: 9`. This matches the Phase 23 Session 02 PRD and preserves the Champion Mode goal of avoiding an overfilled board for non-army rosters.

## Evidence Ledger

| Check                      | Command or Inspection                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Result | Evidence / Blocker                                                                                                  |
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------ | ------------------------------------------------------------------------------------------------------------------- |
| Project state              | `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 `phase23-session02-ranking-and-presentation-selectors`; monorepo package is `apps/web`. |
| Base commit                | `git rev-parse --verify --quiet ed83e7a7670c654c228db767abd018e7f4f39f63^{commit}`                                                                                                                                                                                                                                                                                                                                                                                                                                       | PASS   | Resolved the recorded base commit exactly.                                                                          |
| Mid-session commits        | `git log --oneline ed83e7a7670c654c228db767abd018e7f4f39f63..HEAD`                                                                                                                                                                                                                                                                                                                                                                                                                                                       | PASS   | No mid-session commits were present.                                                                                |
| Review inventory           | `git status --short`; `git ls-files --others --exclude-standard`; `git diff --stat ed83e7a7670c654c228db767abd018e7f4f39f63`                                                                                                                                                                                                                                                                                                                                                                                             | PASS   | Reviewed 3 tracked modified files and 3 untracked session files before generating this report.                      |
| PRD boundary inspection    | `cat .spec_system/PRD/phase_23/session_02_ranking_and_presentation_selectors.md`                                                                                                                                                                                                                                                                                                                                                                                                                                         | PASS   | Confirmed 3-6 heroes should map to squad and 7+ to army.                                                            |
| Targeted source inspection | `nl -ba apps/web/src/lib/legionCamps.ts`; `nl -ba apps/web/tests/legionCamps.test.ts`                                                                                                                                                                                                                                                                                                                                                                                                                                    | PASS   | Verified selector ranking, selected-context mapping, cloning, metadata, and tests after repair.                     |
| JSON validity              | `jq empty .spec_system/state.json`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       | PASS   | Session state JSON parses successfully.                                                                             |
| Formatter write            | `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npx biome format --write apps/web/src/lib/legionCamps.ts apps/web/tests/legionCamps.test.ts`                                                                                                                                                                                                                                                                                                                                                                            | PASS   | Formatted 2 files; no fixes were needed.                                                                            |
| Focused formatter          | `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npx biome format apps/web/src/lib/legionCamps.ts apps/web/tests/legionCamps.test.ts`                                                                                                                                                                                                                                                                                                                                                                                    | PASS   | Checked 2 files; no fixes were needed.                                                                              |
| Root formatter             | `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npm run format:check`                                                                                                                                                                                                                                                                                                                                                                                                                                                   | PASS   | Checked 777 files; no fixes were needed.                                                                            |
| Focused linter             | `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npx biome lint apps/web/src/lib/legionCamps.ts apps/web/tests/legionCamps.test.ts`                                                                                                                                                                                                                                                                                                                                                                                      | PASS   | Checked 2 files; no fixes were needed.                                                                              |
| Root linter                | `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npm run lint`                                                                                                                                                                                                                                                                                                                                                                                                                                                           | PASS   | Checked 779 files; no fixes were needed.                                                                            |
| Focused tests              | `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npm test -- apps/web/tests/legionCamps.test.ts`                                                                                                                                                                                                                                                                                                                                                                                                                         | PASS   | 1 file passed; 15 tests passed.                                                                                     |
| Full tests                 | `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npm test`                                                                                                                                                                                                                                                                                                                                                                                                                                                               | PASS   | 278 test files passed, 1 skipped; 3222 tests passed, 1 skipped.                                                     |
| Web type checker           | `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npm --workspace @factionos/web run typecheck`                                                                                                                                                                                                                                                                                                                                                                                                                           | PASS   | `tsc -b --noEmit` completed successfully.                                                                           |
| Workspace type checker     | `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npm run typecheck --workspaces --if-present`                                                                                                                                                                                                                                                                                                                                                                                                                            | PASS   | Typecheck passed for adapters, server, warroom, web, protocol, and public-website.                                  |
| ASCII                      | `perl -ne 'if (/[^\\x00-\\x7F]/) { print "$ARGV:$.:$_"; $bad=1 } END { exit($bad ? 1 : 0) }' apps/web/src/lib/legionCamps.ts apps/web/tests/legionCamps.test.ts .spec_system/specs/phase23-session02-ranking-and-presentation-selectors/spec.md .spec_system/specs/phase23-session02-ranking-and-presentation-selectors/tasks.md .spec_system/specs/phase23-session02-ranking-and-presentation-selectors/implementation-notes.md .spec_system/specs/phase23-session02-ranking-and-presentation-selectors/code-review.md` | PASS   | No non-ASCII bytes found in checked code or session files, including this report.                                   |
| LF line endings            | `if grep -n $'\\r' apps/web/src/lib/legionCamps.ts apps/web/tests/legionCamps.test.ts .spec_system/specs/phase23-session02-ranking-and-presentation-selectors/spec.md .spec_system/specs/phase23-session02-ranking-and-presentation-selectors/tasks.md .spec_system/specs/phase23-session02-ranking-and-presentation-selectors/implementation-notes.md .spec_system/specs/phase23-session02-ranking-and-presentation-selectors/code-review.md; then exit 1; else exit 0; fi`                                             | PASS   | No CRLF line endings found in checked code or session files, including this report.                                 |
| Whitespace                 | `git diff --check ed83e7a7670c654c228db767abd018e7f4f39f63`                                                                                                                                                                                                                                                                                                                                                                                                                                                              | PASS   | No whitespace errors.                                                                                               |
| Final diff re-read         | `git diff ed83e7a7670c654c228db767abd018e7f4f39f63` plus untracked session files                                                                                                                                                                                                                                                                                                                                                                                                                                         | PASS   | No remaining code, test, state, or session-file issues after the roster-boundary repair.                            |

## Summary

1. Reviewed all changes since base commit `ed83e7a7670c654c228db767abd018e7f4f39f63`: 3 tracked modified files plus the untracked session spec, tasks, and implementation notes; this report was then generated.
2. Findings: 0 critical, 0 high, 1 medium, 0 low. The medium finding was a roster-boundary mismatch for 5-hero and 6-hero inputs, fixed in code and covered by tests.
3. Deliberate non-fixes: none.
4. Evidence: focused and full tests, focused and root lint/format checks, web and workspace typechecks, JSON parse, ASCII/LF checks, whitespace check, and final diff re-read all passed.

## Validation Fix Addendum

**Reviewed**: 2026-07-05 **Scope**: Validation-time comparator and regression-test correction in `apps/web/src/lib/legionCamps.ts`, `apps/web/tests/legionCamps.test.ts`, and session notes. **Result**: RESOLVED

### Finding

* `apps/web/src/lib/legionCamps.ts:721` - Validation found the final tie-break still considered sector label before camp id, while `spec.md` and the Phase 23 Session 02 PRD require stable camp id after timestamp. | Fix: removed the sector-label comparator and added a regression where sector label order conflicts with camp-id order in `apps/web/tests/legionCamps.test.ts`. | Status: FIXED

### Evidence

* Command/check: `nl -ba apps/web/src/lib/legionCamps.ts | sed -n '713,724p'`
  * Result: PASS - comparator now orders selected-context match, tier, HP, lower entrenchment, newest timestamp, and stable camp id.
* Command/check: `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npm test -- apps/web/tests/legionCamps.test.ts`
  * Result: PASS - focused Vitest passed, 1 file and 15 tests.
* Command/check: `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npm --workspace @factionos/web run typecheck`
  * Result: PASS - web TypeScript check completed successfully.
* Command/check: `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npm run format:check`
  * Result: PASS - checked 777 files; no fixes were needed.
* Command/check: `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npm run lint`
  * Result: PASS - checked 779 files; no fixes were needed.
* Command/check: `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npm run typecheck --workspaces --if-present`
  * Result: PASS - adapters, server, warroom, web, protocol, and public-website typechecks passed.
* Command/check: `. ~/.nvm/nvm.sh && nvm use 26.2.0 >/dev/null && npm test`
  * Result: PASS - full Vitest suite reported 278 files passed, 1 skipped, 3222 tests passed, 1 skipped.


---

# 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/phase23-session02-ranking-and-presentation-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.
