> For the complete documentation index, see [llms.txt](https://ai-os-and-trend-finder.gitbook.io/ai-os-and-trend-finder-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai-os-and-trend-finder.gitbook.io/ai-os-and-trend-finder-docs/.spec_system/archive/phases/phase_35/session_06_simulation_ownership_refactor.md).

# Session 06: Simulation Ownership Refactor

**Session ID**: `phase35-session06-simulation-ownership-refactor` **Status**: Not Started **Estimated Tasks**: \~12-25 **Estimated Duration**: 2-4 hours

***

## Objective

Narrow AI Rogue runtime public APIs and move run-state mutations fully behind simulation-owned transitions.

***

## Scope

### In Scope (MVP)

* Split the runtime barrel into a narrow mount/controller entrypoint, simulation internals, and explicit testing fixtures.
* Keep production route code from depending on fixture-only entrypoints or query-driven generation changes.
* Move selected-upgrade and pre-start progression-loadout application into simulation APIs or `createAiRogueRun` options.
* Prepare or execute the first simulation split by run creation, snapshot, command dispatch, movement, player actions, enemy turns, floor progression, and turn finalization.

### Out of Scope

* User-facing content expansion.
* Renderer extraction work assigned to Session 07 except where imports must be adjusted for the new simulation boundary.

***

## Prerequisites

* [ ] Session 02 command correctness and blocker coverage is in place.
* [ ] Session 05 durable save and claim contracts are stable.

***

## Deliverables

1. Runtime API boundary changes for AR-D1-001 and AR-D1-003.
2. Simulation-owned pre-run initialization APIs with tests.
3. Import-cycle and public-barrel checks or tests that protect the new boundary.

***

## Success Criteria

* [ ] Renderer code no longer directly mutates run state for selected upgrades or progression loadout.
* [ ] Production Play behavior cannot be changed by test fixture query params.
* [ ] Simulation command behavior remains deterministic across same-seed tests.
* [ ] Typecheck and AI Rogue simulation/content tests pass.

## Folded Audit Detail Routed To This Session

### Finding IDs Owned

* AR-D1-001: renderer mutates run state outside simulation APIs.
* AR-D1-003: runtime public surface is too wide for refactor safety.
* AR-D2-001: command finalization after lethal turn-start status damage must stay centralized before reducer splits.
* Refactor Map sequencing orders runtime API narrowing and pre-run state mutation before simulation reducer splits.

### Source Locations From Audit

* `src/extensions/ai-rogue/runtime/renderer.ts:852`: selected-upgrade mutation.
* `src/extensions/ai-rogue/runtime/renderer.ts:1052`: helper mutates player health and max health.
* `src/extensions/ai-rogue/runtime/index.ts:3`: broad barrel historically exported simulation, content, fixtures, and mount entrypoint together.
* `src/extensions/ai-rogue/runtime/simulation.ts:2419`: lethal turn-start gap that must remain protected.

### Refactor Map Rows Owned

* Workstream 1: narrow runtime API and move pre-run state mutation into simulation.
* Workstream 3: split simulation by reducer pipeline after AR-D2-001 is characterized or fixed.
* `runtime/simulation.ts` split targets: `run-factory`, `snapshot`, `command-dispatch`, `movement`, `player-actions`, `enemy-turns`, `floor-progression`, and `turn-finalizer`.

### Acceptance Evidence Required

* [ ] Production code imports a narrow mount/controller API.
* [ ] Test fixtures are available only through an explicit testing entrypoint.
* [ ] Renderer requests run-state transitions instead of editing run state.
* [ ] Lethal status, same-seed replay, progression/loadout, floor descent, and objective tests protect the split.


---

# 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://ai-os-and-trend-finder.gitbook.io/ai-os-and-trend-finder-docs/.spec_system/archive/phases/phase_35/session_06_simulation_ownership_refactor.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.
