# RetrieX Shop Meta Context Hint Frontend Fix

Patch-only fix for the referential shop follow-up flow:

```text
welcher pockettester ist fuer Redox messung gut
suche im shop
```

## Problem

The backend fallback for meta-only shop prompts such as `suche im shop` can only resolve a concrete shop query when the previous turn is available through server history or through the frontend `contextHint`.

The previous frontend hint used only the in-memory `lastCompletedUserPrompt` / `lastCompletedAssistantText` state. If that state was empty, overwritten, or lost after a reload/reconnect sequence, the next `/ask-jobs` request sent an empty hint. The backend then had no concrete product/search context and returned:

```text
Ich habe keine konkrete Shop-Suchanfrage erkannt. Bitte nenne das Produkt, Zubehör oder die Artikelnummer.
```

A failed meta-only turn could also overwrite the frontend's last useful context, making immediate retries fragile.

## Fix

`public/assets/js/base.js` now builds the request `contextHint` more defensively:

1. Reconstruct the latest completed visible chat turn from the DOM before sending a new prompt.
2. Persist the last completed turn in `sessionStorage` as a per-tab fallback.
3. Do not overwrite the useful last turn with the generic no-concrete-shop-query response for meta-only prompts.
4. Clear the stored fallback when the user clears the chat history.

## Scope

Changed file:

```text
public/assets/js/base.js
```

No changes to retrieval, scoring, PromptBuilder, AgentRunner, ShopSearchService, SSE job replay, or YAML prompt logic.

## Validation

```bash
node --check public/assets/js/base.js
```

Expected regression flow:

```text
Was ist der niedrigste Grenzwert fuer die Wasserhaerte, welcher mit einem Testomaten ueberwacht werden kann?
mit welchem indikator wird der wert gemessen
was kostet der indikator
```

Expected shop meta flow:

```text
welcher pockettester ist fuer Redox messung gut
suche im shop
```

The second prompt should reuse the previous Redox/Pockettester context and no longer return the generic no-concrete-shop-query message.
