--- name: b7-wiring-anchor-state-rs description: memory note b7-wiring-anchor-state-rs metadata: type: project --- --- name: b7-wiring-anchor-state-rs description: Ancre runtime précise pour câbler B7 (tâches de fond) dans app-tauri/state.rs — repérée par Main pour dé-risquer la délégation DevBackend. metadata: type: reference --- # B7 — Ancre de câblage runtime (crates/app-tauri/src/state.rs) Composition root = builder `AppState` dans `crates/app-tauri/src/state.rs`. Repères exacts (lecture Main 2026-07-02, base `feature/background-tasks-first-class`) : - **Mailbox / inbox** construits l.1207-1242 : `InMemoryMailbox::new()` (1207) → `mailbox` (1208, `dyn AgentMailbox`) → `MediatedInbox::with_pty(...)` (1213) → `input_mediator` (1242, `dyn InputMediator`). C'est LA file existante ; B4 (`AgentInbox`) s'y branche. - **clock** dispo : `Arc` (cloné partout, ex. 1255, 1384). - **Pattern de boucle de fond OBLIGATOIRE** : `tauri::async_runtime::spawn` (PAS `tokio::spawn` — `build` tourne dans le hook `setup` sans runtime tokio ambiant). Exemples : sweep_stalled l.1234, drain scheduler session-limit l.1317. Le sink B3 + bridge B4 + wake B5 doivent être spawnés sur ce même pattern. - **Builder OrchestratorService** l.1356-1454 : chaîne `.with_input_mediator` (1369), `.with_events`, `.with_record_turn`, `.with_live_state`/`.with_live_state_read` (providers PAR ROOT, root fixée par appel), `.with_ask_liveness_probe`, `.with_ask_ceiling`, `.with_structured` (1453). **⚠ POINT CLÉ : `.with_background_tasks(store, clock)` de B6 N'EST PAS présent ici** → le rendez-vous-as-task est DORMANT au runtime. B7 doit l'ajouter. - **Nuance per-root** : `FsBackgroundTaskStore` écrit `/.ideai/background-tasks/.json` (per-projet), mais `OrchestratorService` est GLOBAL multi-projets. Suivre le précédent `AppLiveStateProvider` / `AppReconcileLiveState` (provider keyé par root, câblé dans `open_project`, cf. commentaire l.1247-1252) plutôt qu'une instance de store globale unique. - **Reconcile au boot** : précédent = `reconcile_live_state` (l.1252) appelé dans `open_project` (commands.rs l.134). Le reconcile des tâches de fond + ré-enqueue des complétions non livrées peut se greffer au même endroit (per project root à l'ouverture). Point d'accroche B8 (déféré, couplage PTY) : création commande longue côté `pty.rs` / `LocalProcessSpawner` → créer `BackgroundTask{kind:Command}` au spawn + pousser exit/stdout dans le sink. Lien : [[background-tasks-first-class-design]], [[checkpoint-b2-bootstrap-applied-await-codex-reset-1430]].