> 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_30/session_05_persistence_and_save_contracts.md).

# Session 05: Persistence And Save Contracts

**Session ID**: `phase30-session05-persistence-and-save-contracts` **Status**: Not Started **Estimated Tasks**: \~12-25 **Estimated Duration**: 2-4 hours

***

## Objective

Add versioned browser-local persistence for preferences, wallet, ledger, run history, saves, and reset behavior.

***

## Scope

### In Scope (MVP)

* Define Zod schemas for preferences, wallet, ledger, save metadata, run history, and future migration boundaries.
* Store tiny preferences in `localStorage` and larger state in IndexedDB.
* Add parsers and migration tests for valid, missing, stale, and malformed local data.
* Wire save/load/reset behavior into the React shell and game runtime boundary at coarse state boundaries.
* Ensure generated private runtime data never enters committed files.

### Out of Scope

* Simulation and combat logic (Session 06).
* Run-affecting upgrades and asset wiring (Session 07).

***

## Prerequisites

* [ ] Session 04 wallet and ledger contracts in place.

***

## Deliverables

1. `save-schema` and persistence helpers with versioned parsing.
2. Local wallet, ledger, preferences, run history, and save storage plumbing.
3. Reset controls for Settings and run-level restart behavior.

***

## Success Criteria

* [ ] Preferences survive refresh, malformed data is handled safely, and reset clears only AI Rogue local state.
* [ ] Wallet and ledger persistence preserves claim idempotency across reloads.
* [ ] Save migration tests prove older or partial records do not crash the extension.


---

# 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_30/session_05_persistence_and_save_contracts.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.
