> 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/phases/phase_23/session_02_ranking_and_presentation_selectors.md).

# Session 02: Ranking And Presentation Selectors

**Session ID**: `phase23-session02-ranking-and-presentation-selectors` **Package**: apps/web **Status**: Not Started **Estimated Tasks**: \~15 **Estimated Duration**: 2-4 hours

***

## Objective

Add pure selectors that rank and trim camps for Champion Mode without changing the source camp census.

***

## Scope

### In Scope (MVP)

* Extend `apps/web/src/lib/legionCamps.ts` with visible camp ranking selectors.
* Implement roster-size camp limits for zero-hero, solo, duo, squad, and army boards.
* Prioritize selected context when it maps to a sector, then tier, HP, lower entrenchment, newest timestamp, and stable camp id.
* Expose presentation metadata for muted or edge-placed entrenched camps.
* Add pure ranking tests to `apps/web/tests/legionCamps.test.ts`.

### Out of Scope

* Rendering singular champion copy.
* Golden Age or scan lifecycle presentation.
* Quest Board filtering.
* Changes to the full camp census or scanner source data.

***

## Detailed Requirements

* Camp visibility should scale with roster size.
* Initial visibility constants:

  ```ts
  const CAMP_VISIBLE_LIMITS = {
    solo: 3,
    duo: 4,
    squad: 6,
    army: 9,
  } as const;
  ```
* Suggested mapping:
  * 0 heroes: show up to 3 camps plus Golden Age if clean.
  * 1 hero: show up to 3 camps.
  * 2 heroes: show up to 4 camps.
  * 3-6 heroes: show up to 6 camps.
  * 7+ heroes: show up to 9 camps.
* Ranking order:
  1. camps associated with the selected hero's active context, if known
  2. higher tier
  3. higher HP
  4. lower entrenchment, so stale muted camps stop dominating
  5. newest issue timestamp
  6. stable camp id
* If the active context cannot be mapped to a sector yet, fall back to the rest of the order.
* If scanner issue timestamps are unavailable, use the snapshot time supplied by the reducer for newest-issue ranking.
* For one or two heroes, visual richness should favor the hero and the nearest few camps rather than filling the whole board.
* The army fantasy should emerge as the user runs more agents, not be assumed for the modal one-hero setup.
* Expose presentation metadata for muted or entrenched camp treatment while keeping `entrenchedScans` as the source of truth.
* Ranking output should carry enough presentation metadata for Session 06 to render stale entrenched camps as quieter sector-edge debt without changing their underlying camp data.

***

## Required Tests

* `apps/web/tests/legionCamps.test.ts`
  * visible camp ranking
  * zero-hero, solo, duo, squad, and army limits
  * selected-context priority when a sector mapping exists
  * fallback ranking when selected context cannot map to a sector
  * lower-entrenchment priority so stale muted camps stop dominating
  * muted or edge-placement metadata for entrenched camps
  * newest timestamp fallback to snapshot time
  * stable tie-breaking by camp id

***

## Prerequisites

* [ ] Session 01 reconciliation output is available.

***

## Deliverables

1. Pure `rankVisibleLegionCamps` selectors and typed input/output shapes.
2. Tests for Champion Mode limits, selected-context priority, entrenchment priority, newest timestamp fallback, and stable tie-breaking.

***

## Dependencies / Notes

* Depends on Session 01 camp and sector output shapes.
* Rendering singular champion copy and zero-hero battlefield language belong to Sessions 06 and 07.

***

## Success Criteria

* [ ] One-hero and two-hero inputs return only the documented number of visible camps while preserving the full census for Quest Board inspection.
* [ ] Stale entrenched camps stop dominating when fresher or higher-priority camps exist.
* [ ] Ranking remains deterministic across identical inputs.
* [ ] Selectors expose enough metadata for Session 06 to render quieter entrenched camps without changing underlying camp data.


---

# 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/phases/phase_23/session_02_ranking_and_presentation_selectors.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.
