> 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-session03-legion-enemy-reducer/tasks.md).

# Task Checklist

**Session ID**: `phase22-session03-legion-enemy-reducer` **Total Tasks**: 20 **Estimated Duration**: 3-4 hours **Created**: 2026-07-05

***

Legend: `[x]` completed; `[ ]` pending; `[P]` parallelizable; `[SNNMM]` session ref; `TNNN` task ID.

***

## Setup (3 tasks)

* [x] T001 \[S2203] Verify Session 02 validation evidence and dependency scope (`.spec_system/specs/phase22-session02-hero-attention-reducer/validation.md`)
* [x] T002 \[S2203] Review current projection reducer, Legion shape, attention finalization, and parser guards (`apps/web/src/lib/gameProjection.ts`)
* [x] T003 \[S2203] Review protocol event shapes for dev-health, stalled-task, and tool-result enemy inputs (`packages/protocol/src/events.ts`)

***

## Foundation (4 tasks)

* [x] T004 \[S2203] Add bounded enemy ref constants and helpers for path/detail normalization, deterministic keys, stack caps, and no-op comparisons (`apps/web/src/lib/gameProjection.ts`)
* [x] T005 \[S2203] Add immutable Legion update helpers for skirmishers, ram, gremlins, siege, and wraith records with copy-on-write behavior (`apps/web/src/lib/gameProjection.ts`)
* [x] T006 \[S2203] Add siege severity mapping for `task_near_stall`, `task_stalled`, and `task_escalation` with sorted unique stalled-task refs (`apps/web/src/lib/gameProjection.ts`)
* [x] T007 \[S2203] Add typed Vitest event builders for dev-health, stalled-task, and tool-result reducer inputs with sensitive payload fixtures (`apps/web/tests/gameProjection.test.ts`)

***

## Implementation (7 tasks)

* [x] T008 \[S2203] Implement `test_failure` skirmisher folding with bounded path refs, message exclusion, duplicate no-op behavior, and focus recomputation (`apps/web/src/lib/gameProjection.ts`)
* [x] T009 \[S2203] Implement `build_error` and `build_fix` ram folding with bounded detail, explicit clear behavior, same-reference no-op handling, and focus promotion (`apps/web/src/lib/gameProjection.ts`)
* [x] T010 \[S2203] Implement `ts_errors` gremlin reconciliation with current-count semantics, zero-count clearing, same-reference no-op behavior, and focus recomputation (`apps/web/src/lib/gameProjection.ts`)
* [x] T011 \[S2203] Implement `lint_error` gremlin pressure folding with bounded accumulation, replay no-accumulation, message exclusion, and explicit unchanged handling (`apps/web/src/lib/gameProjection.ts`)
* [x] T012 \[S2203] Implement `task_near_stall`, `task_stalled`, and `task_escalation` siege folding with schema-aligned input handling, stable refs, severity promotion, and focus recomputation (`apps/web/src/lib/gameProjection.ts`)
* [x] T013 \[S2203] Implement failed `tool_result` wraith folding with neutral hero creation, stack cap enforcement, replay no-accumulation, preview exclusion, and same-reference no-op behavior (`apps/web/src/lib/gameProjection.ts`)
* [x] T014 \[S2203] Audit enemy reducer finalization so `alertFocus` priority remains `flare > gate > siege > ram > skirmisher > newCamp > null` without manual drift (`apps/web/src/lib/gameProjection.ts`)

***

## Testing (6 tasks)

* [x] T015 \[S2203] Add tests for dev-health enemy upsert and clear behavior, duplicate no-ops, and exclusion of failure/build/lint messages (`apps/web/tests/gameProjection.test.ts`)
* [x] T016 \[S2203] Add tests for siege reconciliation, stable sorted task refs, level promotion, and focus priority beneath flare and gate refs (`apps/web/tests/gameProjection.test.ts`)
* [x] T017 \[S2203] Add tests for failed-tool wraith stack creation, cap behavior, hero aggregate creation, successful-result no-op behavior, replay no-accumulation, and preview exclusion (`apps/web/tests/gameProjection.test.ts`)
* [x] T018 \[S2203] Add tests for enemy alert-focus promotion across siege, ram, skirmisher, newCamp, and null after higher-priority refs clear (`apps/web/tests/gameProjection.test.ts`)
* [x] T019 \[S2203] Run focused reducer test command and fix any failures (`npm test -- apps/web/tests/gameProjection.test.ts`)
* [x] T020 \[S2203] Run web typecheck and ASCII/LF validation for changed code and session artifacts (`npm --workspace @factionos/web run typecheck`)

***

## Completion Checklist

* [x] All tasks marked `[x]`
* [x] All tests and checks passing
* [x] All files ASCII-encoded with LF line endings
* [x] implementation-notes.md updated
* [x] Ready for `creview` (next step in the implement -> creview -> validate sequence)

***

## Next Steps

Run the `implement` workflow step.


---

# 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-session03-legion-enemy-reducer/tasks.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.
