> 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_22/session_02_hero_attention_reducer.md).

# Session 02: Hero Attention Reducer

**Session ID**: `phase22-session02-hero-attention-reducer` **Package**: apps/web **Status**: Not Started **Estimated Tasks**: \~12-25 **Estimated Duration**: 2-4 hours

***

## Objective

Implement the hero lifecycle, player-attention, and gate portions of the pure reducer with one deterministic `alertFocus` authority.

***

## Scope

### In Scope (MVP)

* Implement `reduceGameProjection(state, event, ctx)` as a pure no-mutation reducer with injected `now`.
* Implement unknown-event same-reference behavior and explicit snapshot-vs-accumulation helper semantics.
* Fold hero lifecycle events: `internal_hero_spawn`, `roster_update`, and `hero_dismissed` without deleting earned aggregates or copying roster source-of-truth data.
* Fold `awaiting_input` and `input_received` with flare state, flare ceremony counters, swift-command timing, and replay-safe accumulation behavior.
* Fold gate attention from `permission_request`, `permission_response`, `guarded_action_update`, and `command_center_permission_update`, or explicitly defer any unsupported gate source with tests and a code comment.
* Implement `recomputeAlertFocus(state)` with the priority ladder `flare > gate > siege > ram > skirmisher > newCamp > null`.
* Add reducer tests for purity, hero snapshot reconciliation, alert priority promotion, flare clearing, gate clearing, and replay-safe swift-command behavior.

### Out of Scope

* Follow the explicit out-of-scope and deferred-work boundaries in the Dependencies / Notes section below.
* Do not add rendering, audio, hosted persistence, protocol changes, or a second game state authority unless this session explicitly lists that work as in scope.

***

## Dependencies / Notes

* Depends on Session 01.
* Any persisted pending refs needed to promote lower-priority alerts must be serializable aggregate state and intentionally documented in `GameProjection`; they must not be animation or toast state.
* Legacy permissions, guarded actions, and Command Center permissions should enter one gate tier; if a source cannot be folded safely in this session, leave a narrow deferred case with tests.
* Out of scope: Legion enemy reducers, camp linkage, XP, levels, title grants, relics, essence income, building XP, War Tide gains/losses, council objectives, nemesis promotion, fog, territory changes, and Dawn Report diffs.

***

## Prerequisites

* [ ] Session 01 completed and validated.

***

## Deliverables

1. Tested pure reducer cases for hero lifecycle and attention authority.
2. A single projection-owned focus computation that later components can read instead of recomputing pulse priority.

***

## Success Criteria

* [ ] `reduceGameProjection` never mutates its inputs and returns the original reference for ignored events.
* [ ] Hero and attention snapshot events do not mint XP, essence, banners, kills, titles, War Tide progress, or other progress numbers.
* [ ] Replay mode can clear or reconcile attention but cannot accumulate swift-command counters or other progress-like values.
* [ ] Clearing a higher-priority focus promotes the next eligible focus and never leaves multiple simultaneous pulse authorities.


---

# 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_22/session_02_hero_attention_reducer.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.
