# Track E — Migrate LocalMemGPT (Cross-Link + Package Migrations)

> **Repo:** `learning_ai_local_memory_gpt`
> **Can start:** After Tracks A, B, and C are complete
> **Estimated time:** ~3 hours
> **Roadmap:** `../LOCAL_AI_CONSOLIDATION_ROADMAP.md`

---

## Prerequisites

Before starting this track, confirm:

- [ ] **Track A** complete — LLM Lab workspace removed, cross-link added
- [ ] **Track B** complete — `@bytelyst/ollama-client` published to Gitea registry
- [ ] **Track C** complete — `@bytelyst/fastify-sse` updated with per-request helpers

---

## Task 1 — Add LLM Lab Cross-Link

Add a link from LocalMemGPT to LLM Lab for model management.

1. Add a "Model Management →" link in the Settings panel (`web/src/components/SettingsPanel.tsx`)
2. Link to `http://localhost:3000` (LLM Lab dashboard default port)
3. Make URL configurable via `LOCALLLMLAB_URL` env var (default: `http://localhost:3000`)
4. Add `LOCALLLMLAB_URL` to `web/.env.example`

**Commit:** `feat(web): add LLM Lab cross-link in settings`

---

## Task 2 — Migrate to `@bytelyst/ollama-client`

Replace the hand-rolled Ollama client with the shared package.

1. Add `@bytelyst/ollama-client` dependency (from Gitea registry)
2. Replace `backend/src/lib/ollama.ts` (117 lines) with imports from the package:

   | Old (lib/ollama.ts)   | New (@bytelyst/ollama-client)                                |
   | --------------------- | ------------------------------------------------------------ |
   | `listOllamaModels()`  | `import { listModels } from '@bytelyst/ollama-client'`       |
   | `checkOllamaHealth()` | `import { checkHealth } from '@bytelyst/ollama-client'`      |
   | `streamChat()`        | `import { streamChat } from '@bytelyst/ollama-client'`       |
   | `getEmbedding()`      | `import { getEmbedding } from '@bytelyst/ollama-client'`     |
   | `OllamaModel` type    | `import type { OllamaModel } from '@bytelyst/ollama-client'` |

3. Update all consumers of `lib/ollama.ts` to use new import paths
4. Delete `backend/src/lib/ollama.ts`
5. Verify: `cd backend && npm test && npm run typecheck && npm run build`

**Commit:** `refactor(backend): migrate to @bytelyst/ollama-client`

---

## Task 3 — Migrate to `@bytelyst/fastify-sse` Per-Request Helpers

Replace the hand-rolled SSE helpers with the shared package exports.

1. Update `@bytelyst/fastify-sse` dependency to latest version (with per-request helpers)
2. Replace `backend/src/lib/sse-helpers.ts` (26 lines) with imports:
   ```ts
   import { startSSE, sendSSEData, sendSSEEvent, endSSE } from '@bytelyst/fastify-sse';
   ```
3. Update consumers:
   - `backend/src/modules/chat/routes.ts`
   - `backend/src/modules/compare/routes.ts`
4. Delete `backend/src/lib/sse-helpers.ts`
5. Verify: `cd backend && npm test && npm run typecheck && npm run build`

**Commit:** `refactor(backend): migrate to @bytelyst/fastify-sse per-request helpers`

---

## Verification

After all 3 tasks, run the full test suite and confirm all ~104 tests pass:

```bash
cd backend && npm test && npm run typecheck && npm run build
cd ../web && npm run typecheck && npm run build
```
