Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

docs(05-01): complete unified search server foundation plan

Adam Eivyb70d4cd389ff
diff --git a/.changelog/v1.14.x.md b/.changelog/v1.14.x.md
index 9a5a8a88a6..09d0b033f7 100644
--- a/.changelog/v1.14.x.md
+++ b/.changelog/v1.14.x.md
@@ -24,6 +24,8 @@ Genome migration cleanup — completed the meatspace data migration so genome, C
- **Insights dashboard UI** — tabbed page at `/insights/:tab` with four deep-linked views: Overview (3 clickable domain summary cards), Genome-Health (category-grouped marker cards with confidence badges, blood value matching, collapsible provenance), Taste-Identity (LLM theme cards with evidence lists and refresh), Cross-Domain (narrative with ReactDiffViewer diff toggle on refresh)
- **Insights shared components** — `ConfidenceBadge` (color-coded strong/moderate/weak/significant), `InsightCard` (shared card shell with badge and source tags), `ProvenancePanel` (collapsible references), `EmptyState` (guided empty states with nav links)
- **Insights navigation** — "Insights" sidebar entry with Lightbulb icon, alphabetically positioned between Instances and MeatSpace
+- **Unified search API** — `GET /api/search?q=<query>` fans out keyword search to Brain (inbox/people/projects/ideas/links), CoS Memory (BM25), Apps, History, and Health metrics in parallel via Promise.allSettled for fault isolation. Returns `{ query, sources }` with categorized results, each including id/title/snippet/url/type fields. Sources with zero results are omitted.
+- **Search client function** — `search(q)` added to `client/src/services/api.js` for use by the overlay component
## Improvements
diff --git a/.planning/REQUIREMENTS.md b/.planning/REQUIREMENTS.md
index 3f0d7e3639..2496c5d8d5 100644
--- a/.planning/REQUIREMENTS.md
+++ b/.planning/REQUIREMENTS.md
@@ -42,8 +42,8 @@ Requirements for this milestone batch. Each maps to roadmap phases.
### Unified Search
- [ ] **SRC-01**: Cmd+K / Ctrl+K opens search overlay from any page
-- [ ] **SRC-02**: Server-side `/api/search` endpoint fans out keyword queries to existing service search functions
-- [ ] **SRC-03**: Results categorized by source (Brain, Memory, Apps, History, Health, etc.) with icons and snippets
+- [x] **SRC-02**: Server-side `/api/search` endpoint fans out keyword queries to existing service search functions
+- [x] **SRC-03**: Results categorized by source (Brain, Memory, Apps, History, Health, etc.) with icons and snippets
- [ ] **SRC-04**: Click result navigates to deep-linked location (specific brain capture, agent run, health entry, etc.)
## v2 Requirements
@@ -110,8 +110,8 @@ Which phases cover which requirements. Updated during roadmap creation.
| INS-03 | Phase 4 | Complete |
| INS-04 | Phase 4 | Complete |
| SRC-01 | Phase 5 | Pending |
-| SRC-02 | Phase 5 | Pending |
-| SRC-03 | Phase 5 | Pending |
+| SRC-02 | Phase 5 | Complete |
+| SRC-03 | Phase 5 | Complete |
| SRC-04 | Phase 5 | Pending |
**Coverage:**
diff --git a/.planning/ROADMAP.md b/.planning/ROADMAP.md
index 760f34e3c1..e07043ac1a 100644
--- a/.planning/ROADMAP.md
+++ b/.planning/ROADMAP.md
@@ -107,4 +107,4 @@ Note: Phases 1 and 2 have no dependency on each other and can execute in paralle
| 2. Data Backup & Recovery | 2/2 | Complete | 2026-02-26 |
| 3. Apple Health Integration | 2/3 | Complete | 2026-02-26 |
| 4. Cross-Domain Insights Engine | 2/2 | Complete | 2026-02-26 |
-| 5. Unified Search (Cmd+K) | 0/2 | Not started | - |
+| 5. Unified Search (Cmd+K) | 1/2 | In Progress| |
diff --git a/.planning/STATE.md b/.planning/STATE.md
index a08c29207d..2685402db3 100644
--- a/.planning/STATE.md
+++ b/.planning/STATE.md
@@ -3,12 +3,12 @@ gsd_state_version: 1.0
milestone: v1.0
milestone_name: milestone
status: unknown
-last_updated: "2026-02-26T23:53:00.000Z"
+last_updated: "2026-02-27T00:01:05.000Z"
progress:
total_phases: 5
- completed_phases: 3
- total_plans: 8
- completed_plans: 7
+ completed_phases: 4
+ total_plans: 9
+ completed_plans: 8
---
# Project State
@@ -18,16 +18,16 @@ progress:
See: .planning/PROJECT.md (updated 2026-02-26)
**Core value:** Ship five next actions that transform PortOS from siloed features into a connected, protected, and searchable system
-**Current focus:** Phase 4 (cross-domain insights engine) — Plans 01-02 complete, awaiting UI verification checkpoint
+**Current focus:** Phase 5 (unified search) — Plan 01 complete (server foundation), Plan 02 next (search overlay UI)
## Current Position
-Phase: 4 of 5 (Cross-Domain Insights Engine) — IN PROGRESS
-Plan: 2 of 2 in current phase (04-02 at human-verify checkpoint)
-Status: Plan 04-02 tasks 1-2 complete — Insights dashboard UI built, awaiting human verification (Task 3 checkpoint)
-Last activity: 2026-02-26 -- Plan 04-02 Tasks 1-2 complete (insights components, page, routes, nav)
+Phase: 5 of 5 (Unified Search) — IN PROGRESS
+Plan: 1 of 2 in current phase (05-01 complete)
+Status: Plan 05-01 complete — search service + route + schema + client API function built
+Last activity: 2026-02-26 -- Plan 05-01 complete (fanOutSearch engine, GET /api/search route, searchQuerySchema, search() client fn)
-Progress: [████████░░] 80%
+Progress: [█████████░] 90%
## Performance Metrics
@@ -47,6 +47,7 @@ Progress: [████████░░] 80%
| 03-apple-health-integration | 3 | ~15min | ~15min |
| 04-cross-domain-insights-engine | 1 | 174s | 174s |
| 04-cross-domain-insights-engine | 2 | 238s | 238s |
+| 05-unified-search | 1 | ~8min | ~8min |
**Recent Trend:**
- Last 5 plans: 03-01 (210s), 03-02 (180s), 03-03 (~15min), 04-01 (174s), 04-02 (238s)
@@ -91,6 +92,9 @@ Recent decisions affecting current work:
- [Phase 04-cross-domain-insights-engine plan 02]: Insights nav entry is a single item (not expandable) — sub-tabs navigate from within the page
- [Phase 04-cross-domain-insights-engine plan 02]: /insights added to isFullWidth paths in Layout.jsx for proper full-height rendering matching MeatSpace pattern
- [Phase 04-cross-domain-insights-engine plan 02]: CrossDomainTab diff only shows after refresh triggers and previousText differs (trimmed comparison prevents false diffs)
+- [Phase 05-unified-search plan 01]: Health adapter is synchronous (no I/O) — searches known metric names + display aliases in-memory, no file reads needed
+- [Phase 05-unified-search plan 01]: fanOutSearch returns only non-empty sources — zero-result sources are omitted from the response
+- [Phase 05-unified-search plan 01]: Brain adapter fans out to 5 sub-types via Promise.allSettled and merges into a single source block
### Pending Todos
@@ -103,5 +107,5 @@ None yet.
## Session Continuity
Last session: 2026-02-26
-Stopped at: 04-02-PLAN.md Task 3 checkpoint:human-verify — Insights dashboard UI built, awaiting verification at http://localhost:5555/insights
+Stopped at: 05-01-PLAN.md complete — fanOutSearch engine, GET /api/search route, searchQuerySchema, search() client fn all shipped
Resume file: None
diff --git a/.planning/phases/05-unified-search/05-01-SUMMARY.md b/.planning/phases/05-unified-search/05-01-SUMMARY.md
new file mode 100644
index 0000000000..eb3d9236e6
--- /dev/null
+++ b/.planning/phases/05-unified-search/05-01-SUMMARY.md
@@ -0,0 +1,115 @@
+---
+phase: 05-unified-search
+plan: 01
+subsystem: api
+tags: [search, fan-out, bm25, express, zod, promise-allsettled]
+
+# Dependency graph
+requires:
+ - phase: 03-apple-health-integration
+ provides: appleHealthQuery.listDayFiles referenced for health source adapter
+ - phase: 04-cross-domain-insights-engine
+ provides: memory BM25 index and brainStorage services used as search sources
+
+provides:
+ - fanOutSearch engine in server/services/search.js
+ - GET /api/search?q= route with Zod validation
+ - searchQuerySchema in server/lib/validation.js
+ - search(q) client API function in client/src/services/api.js
+
+affects: [05-02-search-overlay-ui]
+
+# Tech tracking
+tech-stack:
+ added: []
+ patterns:
+ - Promise.allSettled for fault-isolated fan-out search across multiple data sources
+ - extractSnippet helper for keyword-centered 100-char excerpts with ellipsis trimming
+ - Source adapters return { id, label, icon, results } with results as { id, title, snippet, url, type }
+ - Sources with zero results filtered from response before return
+
+key-files:
+ created:
+ - server/services/search.js
+ - server/routes/search.js
+ modified:
+ - server/lib/validation.js
+ - server/index.js
+ - client/src/services/api.js
+
+key-decisions:
+ - "Health adapter is synchronous (no I/O) — searches known metric names + display aliases in-memory, no file reads needed"
+ - "Memory adapter uses Promise.allSettled internally to isolate BM25 failures from memory index failures"
+ - "Brain adapter fans out to all 5 sub-types (inbox/people/projects/ideas/links) via Promise.allSettled and aggregates into one source block"
+ - "fanOutSearch returns only non-empty sources — zero-result sources are omitted from the response"
+
+patterns-established:
+ - "Search route pattern: asyncHandler + validateRequest(searchQuerySchema, req.query) + service call"
+ - "Source adapter contract: async fn(query) => { id, label, icon, results[] } where results are { id, title, snippet, url, type }"
+
+requirements-completed: [SRC-02, SRC-03]
+
+# Metrics
+duration: 8min
+completed: 2026-02-26
+---
+
+# Phase 5 Plan 01: Unified Search — Server Foundation Summary
+
+**Fan-out keyword search engine with 5 source adapters (Brain/Memory/Apps/History/Health), GET /api/search?q= route, Zod schema, and client search() function**
+
+## Performance
+
+- **Duration:** ~8 min
+- **Started:** 2026-02-26T23:54:25Z
+- **Completed:** 2026-02-27T00:01:05Z
+- **Tasks:** 2
+- **Files modified:** 5
+
+## Accomplishments
+- Built `server/services/search.js` with `fanOutSearch()` engine and 5 source adapters using Promise.allSettled for complete fault isolation
+- Implemented `extractSnippet()` helper that finds keyword match position and extracts a ~100-char window with `...` padding
+- Created `GET /api/search` route with Zod min-2/max-200 query validation and structured `{ query, sources }` response
+- Added `search(q)` client API function to `client/src/services/api.js` for use by the overlay component in Plan 05-02
+
+## Task Commits
+
+Each task was committed atomically:
+
+1. **Task 1: Create search service with source adapters and fan-out engine** - `226b850` (feat)
+2. **Task 2: Create search route, Zod schema, register in index.js, and add client API function** - `ea077ee` (feat)
+
+**Plan metadata:** (docs commit — see state update)
+
+## Files Created/Modified
+- `server/services/search.js` - Fan-out search engine with 5 source adapters and extractSnippet helper
+- `server/routes/search.js` - GET /api/search route handler with asyncHandler + Zod validation
+- `server/lib/validation.js` - Added searchQuerySchema (q: min 2, max 200, trimmed)
+- `server/index.js` - Registered searchRoutes at /api/search (alphabetically after /api/screenshots)
+- `client/src/services/api.js` - Added search(q) function using encodeURIComponent
+
+## Decisions Made
+- Health adapter has no I/O — it matches keyword against a static list of known metric names and display aliases (e.g., "step_count" / "Steps"), making it synchronous and zero-latency
+- Memory adapter guards both BM25 and memory index calls with Promise.allSettled internally, returns empty results if either fails
+- Brain adapter fans out to 5 sub-sources (inbox/people/projects/ideas/links) via Promise.allSettled and merges into a single "Brain" source block, takes first 5 across all sub-types
+- `fanOutSearch` filters out sources with zero results before returning, keeping the response lean
+
+## Deviations from Plan
+
+None - plan executed exactly as written.
+
+## Issues Encountered
+None.
+
+## User Setup Required
+None - no external service configuration required.
+
+## Next Phase Readiness
+- `GET /api/search?q=` is live and ready for the overlay UI component in Plan 05-02
+- `search(q)` client function available in `api.js` for immediate import
+- Response shape `{ query, sources: [{ id, label, icon, results: [{ id, title, snippet, url, type }] }] }` is stable
+- All 5 source adapters operational; Health is always synchronous, others degrade gracefully on empty data
+
+---
+*Phase: 05-unified-search*
+*Completed: 2026-02-26*