> 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_03_legion_enemy_reducer.md).

# Session 03: Legion Enemy Reducer

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

***

## Objective

Implement Phase 22 live-enemy reducer cases without creating rewards, combat strikes, or new rendering state.

***

## Scope

### In Scope (MVP)

* Fold `test_failure`, `build_error`, `build_fix`, `ts_errors`, and `lint_error` into the serializable `legion` aggregate.
* Fold `task_stalled`, `task_near_stall`, and task escalation events into a single siege state with stable stalled-task refs.
* Fold failed `tool_result` events into per-hero wraith stacks with the Phase 22 cap and no board-level multiplication.
* Recompute `alertFocus` after lower-priority enemy state changes so siege, ram, skirmisher, and new-camp priorities promote only when higher-priority sources are absent.
* Add reducer tests for enemy upsert/clear behavior, wraith cap behavior, replay no-accumulation behavior, and focus promotion from enemy state.

### 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 02.
* Failed tool-result stacking is allowed as enemy state, but replay mode must not farm repeated stacks.
* Out of scope: camp coalescing, camp kills, XP, loot, essence, combat strike queues, SFX, animation pulses, and rendering.

***

## Prerequisites

* [ ] Session 02 completed and validated.

***

## Deliverables

1. Tested Legion reducer coverage for Phase 22's live error and stalled-task signals.
2. Projection-owned enemy attention that remains aggregate state, not animation state or score.

***

## Success Criteria

* [ ] Build, test, type, lint, stalled-task, and failed-tool events mutate only the documented Legion aggregate fields.
* [ ] Replay mode cannot increase progress-like enemy counters that would later become rewards.
* [ ] Lower-priority `alertFocus` sources appear only when flare and gate attention are absent.
* [ ] Serialized projection state remains bounded and contains no strike queue, toast queue, audio cue, or animation pulse.


---

# 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_03_legion_enemy_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.
