# Library search across titles and bodies (#144) > **Date:** 2026-11-03 > **Type:** issue > **Reference:** [museion-#144](https://git.babylondreams.de/AlexKucera/museion/issues/144) — [museion-FEAT-004] Library search across titles and bodies ## Goal Ship FEAT-004 (Argus cycle-1 smallest-win, effort S): search across post titles and bodies over the whole library. Fix direction pinned in the ticket: in-memory title filter + body scan scoped to the library roots, debounce, no new persistence. Full spec (UI sketch, code, constraints) in `~/argus-audits/audit/2026-11-02/museion-features.md` §FEAT-004. ## What Was Done - `PostsLibraryColumn` (Museion/PostsPaneView.swift) gains the search: `query`/`matches` view state below `collapsed`, `isSearching`/`trimmedQuery` computed, the plain-text `searchField` row under the Posts header (magnifyingglass + clear ✕, bottom hairline), `searchResults(_:)` (flat list, mono count line, title matches first) and `searchEmptyState`. - The scan: `.task(id: trimmedQuery)` → 250 ms debounce → `await Self.search(...)` — a `nonisolated static func` running the disk reads off MainActor but *inside* the structured task, with a per-piece `Task.isCancelled` check. - `postRow(_:)` extracted (`LibraryPostRow` + full context menu) — sections and search results render the same row; results carry Rename/Convert/Move/Archive/Trash too. - DOX closeout: `Museion/AGENTS.md` PostsPaneView entry gains the `**#144:**` line (field, debounce, off-main posture, frontmatter exclusion, ordering, both render surfaces). - Verification: build SUCCEEDED; suite 574/574 (xcresult executed count); swiftformat idempotent; swiftlint adds zero error-severity violations. ## Decisions & Rationale | Decision | Rationale | |----------|-----------| | `nonisolated static` async helper instead of the spec's `Task.detached` | Finish-audit converged finding (security + general): `Task.detached` is unstructured — `.task(id:)` cancellation never reaches it, and the spec's comment claimed it did. A nonisolated async func awaited from the `.task` runs off MainActor (doesn't inherit the actor) while staying on the same *task*, so SwiftUI's cancellation actually lands; per-piece check stops superseded sweeps between files. Single pass also killed the double title-predicate. | | `.task(id: trimmedQuery)` not `query` | Whitespace-only edits ("foo"→"foo ") must not restart the debounce+scan for identical trimmed input; the id now agrees with the render gate's source of truth. | | `postRow(_:)` extraction | Search results lacked the context menu (Rename/Move/etc. unreachable from results); one row+menu source for both sites beats duplicating the menu block. | | Stale-while-revalidate during debounce (`matches` nils only on clear) | Spec's exact code: later keystrokes keep showing prior results through the 250 ms window instead of a spinner flicker; ProgressView is the first-search state. | | No `readBody` size gate | `Post.scan` already reads every post.md unbounded at startup — search adds no new exposure class; a gate would change shared-function behavior beyond this diff. Ceiling documented as a `ponytail:` note with the `PostScanCache`-style memo upgrade path (LearningsIndex posture). | | No unit test for the filter | View-local state, no pure logic added — the spec's verification is manual smoke; the repo has no component-render harness (named unpinned delta in the audit report). | | Two `PostsLibraryColumn` instances (unfocused layout + focus reveal) keep separate query state | Matches #108's documented per-view `collapsed` posture; only one is alive at a time; AGENTS.md row promises availability, not shared state. Reviewer confirmed fine. | ## Gotchas & Fixes | Problem | Root Cause | Fix | |---------|------------|-----| | swiftlint `opening_brace` violation after formatting | swiftformat pushed a wrapped `else if` condition's brace to its own line (#142's known trap) | Hoisted the body read into a local (`let body = …`) so the condition never wraps — don't fight the formatter | | Test-run exit 1 with all tests passing | My xcresult-summary one-liner ran while the bundle was still finalizing (#33's race, live again — a piped wait isn't enough) | Read the bundle in a separate later call: 574/574, 0 failed | | swiftlint gate exits 2 repo-wide | Pre-existing: 289 violations / 72 serious at HEAD, identical with the diff; earlier chained runs piped through `tail` masked the exit code | Proven pre-existing via stash control (same 289/72); named here and in the commit; my file adds zero errors | | GitNexus `detect-changes` said "No changes detected" despite a dirty tree | Stale index after an earlier incremental analyze | Re-ran `analyze` (full, 5,820 nodes) → detect-changes then reported the true scope (`PostsLibraryColumn` + docs) | | Review flag: comment claimed `.task(id:)` cancels the in-flight scan | `Task.detached` never receives parent cancellation — the prose promised an invariant the code didn't have | Structured-concurrency fix above; the comment is now true | ## Files Changed | File | Change Summary | |------|---------------| | `Museion/PostsPaneView.swift` | +164/−23: search state, field, results, empty state, structured scan, `postRow(_:)` extraction | | `Museion/AGENTS.md` | `**#144:**` line on the PostsPaneView entry (DOX closeout) | | `AGENTS.md` | write-log window refresh + gitnexus index-stats churn | ## Open Items & Next Steps - [ ] Deferred: re-filter when a watcher rescan lands while a query sits unchanged (any keystroke refreshes; a later slice if it bites) - [ ] Deferred: `folder(of:)` re-walk per piece per sweep — `PostScanCache`-style body memo if it ever measures hot (named in `search()`'s ponytail note; see the `local-store-caching` skill) - [ ] Manual smoke: type a known word into Search posts → flat match list; clear → sections return; right-click a result → full menu --- *Log written by write-log skill*