Skip to content

Feature: Add file viewer with search (F3)#1

Merged
vdavid merged 16 commits into
mainfrom
claude/add-file-viewer-d2Iev
Jan 28, 2026
Merged

Feature: Add file viewer with search (F3)#1
vdavid merged 16 commits into
mainfrom
claude/add-file-viewer-d2Iev

Conversation

@vdavid
Copy link
Copy Markdown
Owner

@vdavid vdavid commented Jan 24, 2026

Add a text file viewer that opens in a separate window when pressing F3.
Includes case-insensitive search with match highlighting, line numbers,
and keyboard navigation (Cmd+F to search, ESC to close).

claude and others added 16 commits January 27, 2026 22:41
Add a text file viewer that opens in a separate window when pressing F3.
Includes case-insensitive search with match highlighting, line numbers,
and keyboard navigation (Cmd+F to search, ESC to close).
- Extract function key handling to reduce handleKeyDown complexity
- Fix template literal type in open-viewer.ts
- Add keys to {#each} blocks in viewer page
- Remove useless mustache interpolation
Depends on Tauri WebviewWindow API, not unit-testable.
Replace the simple read_file_content approach with a session-based three-backend
architecture that handles files of any size:

- FullLoadBackend: files ≤ 1 MB, instant random access in RAM
- ByteSeekBackend: instant open for large files, byte-offset seeking
- LineIndexBackend: sparse line index (every 256 lines), built in background

ViewerSession orchestrator picks the right backend and transparently upgrades
from ByteSeek to LineIndex once the background scan completes.

Frontend uses virtual scrolling (only renders visible lines + 50-line buffer)
with on-demand line fetching from the backend. Search runs server-side with
cancellation support and progress reporting.

64 new Rust tests covering all backends and orchestrator. Old client-side
search utilities removed.
- Use SvelteMap instead of Map for reactive line cache
- Extract async poll logic out of setInterval callback
- Remove unnecessary type assertion on search status
- Use await instead of return for void invoke calls
To change file focus right when clicking
Now it works very well in all three modes, and displays state nicely on the UI.
@vdavid vdavid force-pushed the claude/add-file-viewer-d2Iev branch from df91e08 to add6700 Compare January 28, 2026 12:23
@vdavid vdavid merged commit add6700 into main Jan 28, 2026
8 checks passed
vdavid added a commit that referenced this pull request Mar 21, 2026
- Extract prompts to `SEARCH_PROMPT_TEMPLATE` and `REFINEMENT_RULES` constants, `build_search_system_prompt()` is now just date injection
- 8234 → ~3200 chars (61% smaller): drop 37-item system dir list, verbose field descriptions, "FIRST PASS" framing, 8 redundant examples
- Compact field table and category→extension mapping replace prose bullet lists
- Add "Never guess paths like ~/projects — omit if unsure" to `searchPaths` — the #1 source of pass-1 failures
- Keep 6 targeted examples: naming convention, `includeSystemDirs`, `excludeDirs`, caveat, date range, screenshot
- Refinement rules condensed to 5 bullets + flag preservation one-liner
- Add pass-2 `searchPaths` fallback (retry full-drive when LLM-guessed paths resolve to 0) — mirrors existing pass-1 fallback
- DEBUG logging for full system prompt and user message on both passes
@vdavid vdavid deleted the claude/add-file-viewer-d2Iev branch May 19, 2026 09:04
vdavid added a commit that referenced this pull request May 20, 2026
Three fixes that all touch the same flow: existing OS-mounted SMB shares can now reach the fast direct-smb2 path automatically (or via MCP for agents), and agents can see which volumes are on which path.

Auto-upgrade for dev profiles (#1): `upgrade_existing_smb_mounts` now takes an `AppHandle` and calls `crate::network::ensure_mdns_started` itself when it finds SMB mounts to upgrade. The `firstTriggerDone` gate is gone from this call site — the function is a no-op when there are no SMB mounts (no network activity, no macOS Local Network prompt), so the gate was protecting nothing useful. With mounts present and `network.directSmbConnection` on (default true), mDNS now starts at launch and the upgrade can resolve hostname-keyed Keychain creds the same way the manual "Connect directly" button does. Dev profiles with `firstTriggerDone == false` and an auto-reconnected SMB share previously stayed on the slow OS-mount path indefinitely; that's the bug.

MCP visibility (#3): `cmdr://state`'s volumes section now emits structured entries for SMB volumes with `name`, `id`, and `smbConnectionState` (`direct` | `os_mount` | `disconnected`). Non-SMB volumes stay as bare `- {name}` lines for compactness. Agents can now distinguish which SMB shares are on the fast path.

MCP trigger (#2): new `upgrade_smb_to_direct` tool, sibling of `connect_to_server` and `remove_manual_server` in the network category. Thin wrapper around the same upgrade flow the manual UI uses. Calls a newly-extracted `upgrade_to_smb_volume_inner` helper (the Tauri command's body minus the concrete-AppHandle mDNS kick) so the MCP executor — generic over `Runtime` — can reuse the logic. Tool description steers agents: if mDNS isn't running and hostname-keyed Keychain creds matter, take a network action first.

Refactor along the way: `enrich_smb_connection_state` was duplicated across `commands/volumes.rs` (for `list_volumes`) and `volume_broadcast.rs` (for `volumes-changed`) with a "must stay in sync" gotcha. With MCP becoming a third caller, the sync risk grew. Extracted to `volumes::enrich_smb_connection_state`; all three call sites now share it. CLAUDE.md gotcha → decision.

Tests / docs:
- MCP `test_all_tools_count` / `test_network_tools_count` bumped (29 → 30, 2 → 3).
- MCP `test_total_tool_count` bumped to 30.
- file_system/volume/CLAUDE.md startup-upgrade lifecycle entry updated to reflect the new mDNS-kick path and no-gate semantics.
- mcp/CLAUDE.md tool count, network category list, and `cmdr://state` volumes-shape description updated.
- volumes/CLAUDE.md "two-site sync" gotcha replaced with a single-source decision entry.

Verified: full `./scripts/check.sh` green (50 checks, 1983 unit + 32 integration + every linter), including the 189 MCP unit tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants