feat: Add support IPC socket control over menu.

This commit is contained in:
2026-03-14 17:02:16 -04:00
parent cd1927fa9f
commit aad4c16d6e
15 changed files with 1501 additions and 185 deletions

View File

@@ -212,22 +212,68 @@ CSV/TSV input parsing and columnar table rendering.
**Done when:** `echo "name,age\nalice,30\nbob,25" | pikl --input-format csv`
renders a navigable table with headers.
## Phase 6: Sessions & IPC
## Phase 6: IPC & Session History
Persistence and external control.
Two independent features bundled together. IPC adds live
external control over a Unix socket. Session history gives
lightweight filter recall for repeated workflows.
### IPC (External Control)
Opt-in Unix socket server for live control of a running
pikl instance by external processes.
**Deliverables:**
- `--session name` for state persistence
- Session state: filter, scroll position, selections
- Session history log file
- Unix socket IPC while running
- IPC commands: push/remove/update items, set filter,
read selection, close
- Protocol: newline-delimited JSON
- `--ipc` flag to enable the socket listener (off by
default, pikl is ephemeral and shouldn't have side
effects unless asked)
- Socket path: `/run/user/$UID/pikl-{session}.sock`
(named session) or `/run/user/$UID/pikl-{pid}.sock`
(no session name)
- Socket path logged via tracing on startup
- Cleanup on exit (normal, cancel, SIGTERM)
- Protocol: newline-delimited JSON, one message per line
- Write commands: `add_items`, `replace_items`,
`remove_items`, `set_filter`, `confirm`, `cancel`,
`close`, plus navigation actions (`move_up`,
`move_down`, `move_to_top`, `move_to_bottom`,
`page_up`, `page_down`, `toggle_select`, `select_all`,
`clear_selections`)
- Read commands: `get_state` (filter, cursor, counts,
mode), `get_selection` (selected items). Both require
an `id` field, response echoes it back.
- Event subscription: `subscribe` with event type list,
`unsubscribe` to stop. Subscribed events pushed as
`{"event": "...", ...}` lines.
- Multiple simultaneous client connections
- Auth: Unix socket permissions (user-only)
- IPC is just another frontend: deserializes JSON into
Actions, optionally subscribes to MenuEvent broadcast
**Done when:** You can close and reopen a session and find
your state intact. External scripts can push items into a
running pikl instance.
**Not in scope:**
- `get_items` (full item list read, potentially large)
- Auto-enable with `--session`
- Auth beyond Unix socket permissions
### Session Filter History
**Deliverables:**
- `--session name` flag
- On any confirm (single, multi, quicklist), append
current filter text to
`~/.local/state/pikl/sessions/{name}.history`
- Skip empty filters and consecutive duplicates
- Load history on startup if session file exists
- Ctrl+P / Ctrl+N in insert mode to cycle through
filter history
- Selecting a history entry replaces the current filter
text
- Per-session only, no global history
**Done when:** An external script can connect to a running
pikl instance over the socket, push items, read state, and
subscribe to events. A named session remembers filter
history across invocations.
## Phase 7: Streaming & Watched Sources