# Phase 1 Store Audit: Platform Dependency Analysis

Categorization of each store for migration readiness to `@agor/stores`.

## Category Definitions

- **CLEAN:** No platform dependencies. Can move to `@agor/stores` as-is.
- **BRIDGE-DEPENDENT:** Uses bridge adapters (Tauri invoke/listen). Needs BackendAdapter migration first.
- **PLATFORM-SPECIFIC:** Contains platform-specific logic (paths, APIs). Stays in app-specific layer.

---

## Store Analysis

### 1. agents.svelte.ts
**Category: CLEAN**

| Check | Result |
|-------|--------|
| Platform-specific paths | None |
| Persistence paths | None (pure in-memory) |
| Capability-conditioned defaults | None |
| Tauri/Bun imports | None |

**Notes:** Only import is `type AgentMessage` from `claude-messages` (type-only, already in `@agor/types` as `AgentMessage`). Pure reactive state with no I/O. Ready to move immediately.

---

### 2. workspace.svelte.ts
**Category: BRIDGE-DEPENDENT**

| Check | Result |
|-------|--------|
| Platform-specific paths | None directly (groups.json path resolved in Rust backend) |
| Persistence paths | `groups-bridge.ts` → Tauri `invoke('groups_load')` / `invoke('groups_save')` |
| Capability-conditioned defaults | None |
| Tauri/Bun imports | `groups-bridge` (Tauri invoke), `btmsg-bridge` (Tauri invoke) |

**Bridge dependencies:**
- `loadGroups()` / `saveGroups()` → already in BackendAdapter
- `getCliGroup()` → Tauri-specific CLI arg parsing, not in BackendAdapter
- `registerAgents()` → btmsg-bridge, not in BackendAdapter

**Notes:** `loadGroups`/`saveGroups` can migrate to `getBackend()`. `getCliGroup` and `registerAgents` need new BackendAdapter methods or remain as separate bridges. Cross-store imports (agents, health, conflicts, wake-scheduler) are all clean function calls.

---

### 3. layout.svelte.ts
**Category: BRIDGE-DEPENDENT**

| Check | Result |
|-------|--------|
| Platform-specific paths | None (SQLite path resolved in Rust) |
| Persistence paths | `session-bridge.ts` → 8 Tauri invoke commands |
| Capability-conditioned defaults | None |
| Tauri/Bun imports | `session-bridge` (Tauri invoke) |

**Bridge dependencies:**
- `listSessions`, `saveSession`, `deleteSession`, `updateSessionTitle`, `touchSession` → session CRUD
- `saveLayout`, `loadLayout` → layout persistence
- `updateSessionGroup` → group assignment

**Notes:** V2 legacy store. V3 uses workspace.svelte.ts. Session persistence commands not yet in BackendAdapter. Could be deferred or added as BackendAdapter extension.

---

### 4. health.svelte.ts
**Category: CLEAN**

| Check | Result |
|-------|--------|
| Platform-specific paths | None |
| Persistence paths | None (pure in-memory with timer) |
| Capability-conditioned defaults | None |
| Tauri/Bun imports | None |

**Notes:** Imports from stores only (agents, conflicts) and utils (attention-scorer). Pure computation + timers. Ready to move.

---

### 5. conflicts.svelte.ts
**Category: CLEAN**

| Check | Result |
|-------|--------|
| Platform-specific paths | None |
| Persistence paths | None (session-scoped, no persistence) |
| Capability-conditioned defaults | None |
| Tauri/Bun imports | None |

**Notes:** Only imports `types/ids`. Pure in-memory conflict tracking. Ready to move.

---

### 6. anchors.svelte.ts
**Category: BRIDGE-DEPENDENT**

| Check | Result |
|-------|--------|
| Platform-specific paths | None (SQLite path resolved in Rust) |
| Persistence paths | `anchors-bridge.ts` → 4 Tauri invoke commands |
| Capability-conditioned defaults | None |
| Tauri/Bun imports | `anchors-bridge` (Tauri invoke) |

**Bridge dependencies:**
- `saveSessionAnchors`, `loadSessionAnchors`, `deleteSessionAnchor`, `updateAnchorType`

**Notes:** Small, well-defined bridge surface. Could add anchor CRUD to BackendAdapter or keep as separate bridge temporarily.

---

### 7. theme.svelte.ts
**Category: BRIDGE-DEPENDENT**

| Check | Result |
|-------|--------|
| Platform-specific paths | None |
| Persistence paths | `settings-bridge.ts` → `getSetting`/`setSetting` (Tauri invoke) |
| Capability-conditioned defaults | None |
| Tauri/Bun imports | `settings-bridge` (Tauri invoke) |

**Bridge dependencies:**
- `getSetting('theme')`, `setSetting('theme', ...)` — theme persistence
- `getSetting('ui_font_family')` etc. — 4 font settings on init

**Platform-specific behavior:**
- `document.documentElement.style.setProperty()` — browser API, works on both Tauri and Electrobun webviews. Not platform-specific.

**Notes:** Simple migration — replace `getSetting`/`setSetting` with `getBackend().getSetting()`/`getBackend().setSetting()`.

---

### 8. plugins.svelte.ts
**Category: BRIDGE-DEPENDENT**

| Check | Result |
|-------|--------|
| Platform-specific paths | None (plugin config dir resolved in Rust) |
| Persistence paths | `settings-bridge.ts` → plugin enabled state; `plugins-bridge.ts` → plugin discovery |
| Capability-conditioned defaults | `supportsPluginSandbox` could gate plugin loading |
| Tauri/Bun imports | `plugins-bridge` (Tauri invoke), `settings-bridge` (Tauri invoke) |

**Bridge dependencies:**
- `discoverPlugins()` → plugins-bridge (not in BackendAdapter)
- `getSetting`/`setSetting` → plugin enabled state

**Notes:** Plugin discovery is not in BackendAdapter. Settings part can migrate. Plugin host (`plugin-host.ts`) is pure Web Worker logic — platform-independent.

---

### 9. machines.svelte.ts
**Category: BRIDGE-DEPENDENT**

| Check | Result |
|-------|--------|
| Platform-specific paths | None |
| Persistence paths | `remote-bridge.ts` → 5 invoke commands + 5 listen events |
| Capability-conditioned defaults | None |
| Tauri/Bun imports | `remote-bridge` (Tauri invoke + listen) |

**Bridge dependencies:**
- `listRemoteMachines`, `addRemoteMachine`, `removeRemoteMachine`, `connectRemoteMachine`, `disconnectRemoteMachine`
- 5 event listeners: `onRemoteMachineReady`, `onRemoteMachineDisconnected`, `onRemoteError`, `onRemoteMachineReconnecting`, `onRemoteMachineReconnectReady`

**Notes:** Heavy bridge dependency with event subscription lifecycle. Not in BackendAdapter. Defer migration.

---

### 10. wake-scheduler.svelte.ts
**Category: BRIDGE-DEPENDENT**

| Check | Result |
|-------|--------|
| Platform-specific paths | None |
| Persistence paths | `bttask-bridge.ts` → `listTasks`; `audit-bridge.ts` → `logAuditEvent` |
| Capability-conditioned defaults | None |
| Tauri/Bun imports | `bttask-bridge` (Tauri invoke), `audit-bridge` (Tauri invoke) |

**Bridge dependencies:**
- `listTasks(groupId)` → task listing for wake signal evaluation
- `logAuditEvent(...)` → audit logging

**Notes:** Neither bttask nor audit operations are in BackendAdapter. Cross-store reads (health, workspace, agents). Complex timer logic is pure JS — platform independent. Bridges are the only blockers.

---

### 11. notifications.svelte.ts
**Category: BRIDGE-DEPENDENT**

| Check | Result |
|-------|--------|
| Platform-specific paths | None |
| Persistence paths | None (ephemeral state) |
| Capability-conditioned defaults | `supportsDesktopNotifications` should gate `sendDesktopNotification` |
| Tauri/Bun imports | `notifications-bridge` (Tauri invoke) |

**Bridge dependencies:**
- `sendDesktopNotification(title, body, urgency)` — single function, fire-and-forget

**Notes:** Toast system is pure reactive state. Only the OS notification part needs the bridge. Easy to capability-gate: `if (getBackend().capabilities.supportsDesktopNotifications) sendDesktopNotification(...)`.

---

### BONUS: settings-scope.svelte.ts
**Category: BRIDGE-DEPENDENT**

| Check | Result |
|-------|--------|
| Platform-specific paths | None |
| Persistence paths | `settings-bridge.ts` → `getSetting`/`setSetting` |
| Capability-conditioned defaults | None |
| Tauri/Bun imports | `settings-bridge` (Tauri invoke) |

**Notes:** Thin scoping layer over settings-bridge. Migrates with Cluster 2 (Settings Domain).

---

### BONUS: sessions.svelte.ts
**Category: CLEAN**

| Check | Result |
|-------|--------|
| Platform-specific paths | None |
| Persistence paths | None |
| Capability-conditioned defaults | None |
| Tauri/Bun imports | None |

**Notes:** V2 legacy, minimal. Pure reactive state.

---

## Summary Table

| Store | Category | Bridge Deps | Migration Blocker |
|-------|----------|-------------|-------------------|
| agents | CLEAN | none | -- |
| conflicts | CLEAN | none | -- |
| sessions | CLEAN | none | -- |
| health | CLEAN | none | -- |
| theme | BRIDGE-DEPENDENT | settings-bridge | BackendAdapter.getSetting/setSetting (ready) |
| settings-scope | BRIDGE-DEPENDENT | settings-bridge | BackendAdapter.getSetting/setSetting (ready) |
| notifications | BRIDGE-DEPENDENT | notifications-bridge | Capability-gate sendDesktopNotification |
| anchors | BRIDGE-DEPENDENT | anchors-bridge | Need BackendAdapter anchor methods |
| plugins | BRIDGE-DEPENDENT | plugins-bridge, settings-bridge | Need BackendAdapter plugin discovery |
| layout | BRIDGE-DEPENDENT | session-bridge | Need BackendAdapter session methods |
| workspace | BRIDGE-DEPENDENT | groups-bridge, btmsg-bridge | BackendAdapter groups (ready), btmsg TBD |
| machines | BRIDGE-DEPENDENT | remote-bridge | Need BackendAdapter remote machine methods |
| wake-scheduler | BRIDGE-DEPENDENT | bttask-bridge, audit-bridge | Need BackendAdapter bttask/audit methods |

### Ready to Migrate Now (4 stores)
- `agents.svelte.ts` — CLEAN
- `conflicts.svelte.ts` — CLEAN
- `health.svelte.ts` — CLEAN
- `sessions.svelte.ts` — CLEAN

### Ready After Settings-Bridge Replacement (3 stores)
- `theme.svelte.ts` — settings-bridge only
- `settings-scope.svelte.ts` — settings-bridge only
- `plugins.svelte.ts` — settings-bridge + plugins-bridge

### Requires BackendAdapter Extension (6 stores)
- `notifications.svelte.ts` — 1 method
- `anchors.svelte.ts` — 4 methods
- `layout.svelte.ts` — 8 methods
- `workspace.svelte.ts` — groups ready, btmsg TBD
- `machines.svelte.ts` — 10 methods + events
- `wake-scheduler.svelte.ts` — bttask + audit
