Library 의 / 키가 활성화. App.search slot 이 lazy 채워지고 (run loop 가 SwitchPane(Search) 받을 때),
debounce 200 ms 후 kebab-app::search 호출, 선택된 hit 의 chunk 를 preview pane 에 표시.
g 키로 $EDITOR (vim/nvim/code/cursor 자동 감지) 에서 citation 위치 열림.
핵심:
- SearchState 본체 (`app.rs` 의 forward decl 채움) — input / mode / hits /
selected_hit / input_dirty_at / last_query / searching / preview.
- `src/search.rs` (신규):
- `render_search(f, area, state)` — 3-pane layout (input bar / 결과 리스트 / preview).
각 hit 는 §1.5 dense 4-line format (rank.score URI / heading / snippet).
- `handle_key_search`: typing → input + dirty mark. Tab → mode 순환. Enter →
immediate refresh. j/k → 선택 이동 + preview invalidate. g → editor jump
(RAII raw-mode suspend). Esc → Library 복귀.
- `build_jump_command(citation, editor_env, workspace_root)` 가 vim 류
`+<line> path` / VS Code `code -g path:line` / cursor `cursor -g`
자동 분기. unit test 로 잠금.
- `jump_to_citation` 가 raw-mode + AltScreen 을 RAII 로 suspend/restore
(panic 안전).
- run-loop hook 4 함수: `debounce_due` / `fire_search` /
`refresh_preview` (private to crate).
- run.rs:
- Pane::Search arm 이 `handle_key_search` 로 dispatch + `render_search`.
- SwitchPane(Search) 시 `app.search = Some(SearchState::default())` lazy init.
- Idle tick 마다 debounce_due → fire_search, preview None → refresh_preview.
- 테스트 13개 (`tests/search.rs`) — Esc/typing/backspace/Tab cycle/Enter
refresh/j-k 이동/jump cmd vim+code+args/render w/hits/empty render/no slot.
Spec deviation (HOTFIXES `2026-05-02 P9-2`):
- `render_search<B: Backend>` generic 제거 (P9-1 와 동일 사유 — ratatui 0.28
Frame backend-agnostic).
- `jump_to_citation` 가 `workspace_root: &Path` 인자 추가. Citation.path 가
workspace 상대 라 editor 호출 시 절대 경로 필요. spec literal 의 시그니처
는 unimplementable.
Docs (sync rule):
- README: TUI 행 \"Library + Search 패널, ask/inspect 진행 중\" + Quick start
의 `kebab tui` 코멘트 갱신.
- HANDOFF: 한 줄 요약 + Phase status (P9 1/5 → 2/5) + deviation 한 줄 추가.
- HOTFIXES: P9-2 entry 추가.
- tasks/p9/p9-2 status: completed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5.6 KiB
5.6 KiB
phase, component, task_id, title, status, depends_on, unblocks, contract_source, contract_sections
| phase | component | task_id | title | status | depends_on | unblocks | contract_source | contract_sections | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| P9 | kebab-tui (search pane) | p9-2 | TUI Search pane: input + result list + preview + editor jump | completed |
|
../../docs/superpowers/specs/2026-04-27-kebab-final-form-design.md |
|
p9-2 — TUI Search pane
Goal
Add a Search pane to the TUI that drives kebab-app::search, renders dense results (rank+score / path#frag / heading / snippet), and supports g (editor jump to citation) for the selected hit.
Why now / why this size
Search is the most-used surface. Confining it to one pane leverages the App skeleton from p9-1 without rebuilding key dispatch.
Allowed dependencies
kebab-corekebab-configkebab-appkebab-tui(extends p9-1)ratatui,crosstermtracingthiserror
Forbidden dependencies
kebab-source-fs,kebab-parse-*,kebab-normalize,kebab-chunk,kebab-store-*,kebab-embed*,kebab-search,kebab-llm*,kebab-rag,kebab-desktop
Inputs
| input | type | source |
|---|---|---|
kebab-app::search(query) |
facade | runtime |
| keyboard events | crossterm |
terminal |
| selected hit's citation | kebab_core::Citation |
App state |
Outputs
| output | type | downstream |
|---|---|---|
| Ratatui frame for Search pane | render | user |
| External editor process spawn | std::process::Command |
OS |
Public surface (signatures only — no new types)
pub fn render_search<B: ratatui::backend::Backend>(f: &mut ratatui::Frame, area: ratatui::layout::Rect, state: &App);
pub fn handle_key_search(state: &mut App, key: crossterm::event::KeyEvent) -> KeyOutcome;
pub fn jump_to_citation(citation: &kebab_core::Citation, editor_env: &str /* $EDITOR */) -> anyhow::Result<()>;
This task fills the body of kebab_tui::SearchState (forward-declared in p9-1). The App struct itself is NOT edited — only SearchState gets fields:
pub struct SearchState {
pub input: String,
pub mode: kebab_core::SearchMode,
pub hits: Vec<kebab_core::SearchHit>,
pub selected_hit: usize,
pub last_query_at: Option<time::OffsetDateTime>, // debounce timer
}
The Library pane's keypress handler (in p9-1) sets app.search = Some(SearchState::default()) on pane switch; p9-2's render_search/handle_key_search read app.search.as_mut() exclusively. Parallel-safety contract from p9-1 holds.
Behavior contract
- Layout: top input bar (search query + mode badge
[hybrid|lexical|vector]), middle result list (one hit per 4 lines per design §1.5 dense format), bottom preview pane (full chunk text fetched lazily viakebab-app::inspect_chunk). - Key bindings (Search pane):
- typing → updates
search_input; debounced (200 ms) re-search Tab→ cyclessearch_modeLexical → Vector → Hybrid → LexicalEnter→ forces re-search immediatelyj/kor arrow keys → move selected hitg→ calljump_to_citation(&hits[selected].citation, &env::var("EDITOR").unwrap_or_else(|_| "vi".into()))Esc→ switch back to Library pane
- typing → updates
jump_to_citation:- For
Citation::Line { path, start, .. }: spawneditor +<start> <workspace_root>/<path>. Common editorsvim/nvim/vi/emacs/hxaccept+N. Fallback:code -g <path>:<start>if$EDITORcontains "code". - For other citation kinds: open the file in
$EDITORwithout line jump (best effort). - Use
std::process::Command::status()blocking; suspend the TUI (disable_raw_mode) before launch and restore on return.
- For
- The search call runs synchronously; for hybrid mode that may take seconds, render a centered "searching…" overlay until complete.
- All search results rendered must conform to design §1.5 dense format (4 lines:
<rank>. <score> <path#frag>/<section_label>/<snippet line 1>/<snippet line 2>). - Errors → popup overlay (consistent with p9-1).
- Stable terminal restoration on panic and process exit.
Storage / wire effects
- Reads only. No DB writes.
- Spawns external editor process; that process can mutate user files. The TUI does not interfere.
Test plan
| kind | description | fixture / data |
|---|---|---|
| unit | typing into search_input triggers re-search after debounce | inline timer mock |
| unit | Tab cycles mode through 3 values back to Lexical |
inline |
| unit | j / k move selection within bounds |
inline |
| unit | jump_to_citation for Line builds +<line> <path> command (assert via mocked Command runner) |
inline |
| snapshot | rendered Search pane with 3 hits + preview stable | TestBackend |
| integration | mocked kebab-app::search returning fixture hits drives render |
inline |
All tests under cargo test -p kebab-tui search.
Definition of Done
cargo check -p kebab-tuipassescargo test -p kebab-tui searchpassesgkeybinding launches$EDITORwith correct+<line>argument (manual smoke against vim)- No imports outside Allowed dependencies
- PR links design §1.5/1.6, §3.7
Out of scope
- Inline citation render of LLM answers (Ask pane = p9-3).
- Full
--explainretrieval trace (mention but defer to a future toggle). - Mouse selection.
Risks / notes
- Suspending and restoring crossterm raw mode around the editor spawn is finicky; code defensively (RAII guard).
- Different editors take different jump syntaxes. Provide an env override
KEBAB_EDITOR_JUMP_FORMAT="vim"for users on exotic editors. - Long snippet text wrap: clamp to viewport width and ellipsize per design §1.5 (
…already in dense template).