feat(ipc): add history query method and CLI subcommand#136
Merged
Conversation
Add a new `history` JSON-RPC method that queries the SQLite history database and returns matching entries as JSON. The method is handled directly on the server thread (no R interaction needed), making it available even when R is busy. CLI: `arf ipc history` with --limit, --session-only, --cwd, --grep, --since filters. Output is pretty-printed on terminal, compact when piped. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add 6 tests covering: basic query, --limit, --grep, --session-only, metadata (timestamp/cwd/exit_status), and --no-history error. Also fix headless history entries missing session_id — the save_to_headless_history function was not setting session_id on the HistoryItem, causing NULL in the database. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Validate limit > 0 in query_history() and restrict CLI --limit to positive values via clap value_parser range - Replace serde_json::to_value().unwrap() with proper error handling in the history dispatch path - Add comment explaining why set_history_db_info is called before the DB file exists in REPL mode (with_file creates it on open) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Add arf ipc history CLI section with parameter table and examples. Update Available Methods table to include history method. Note that history and session methods work when R is busy. Also add missing --history-dir and --no-history to headless options. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds a new IPC surface for querying command history from a running arf session, plus a corresponding arf ipc history CLI subcommand and end-to-end tests.
Changes:
- Introduces
historyJSON-RPC method + client CLI plumbing (arf ipc history) with filtering options. - Stores history DB path/session ID in-process and uses it to query history and to populate headless
session_idon saved entries. - Adds headless integration tests and updates shell completion snapshots.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/arf-console/src/ipc/protocol.rs | Adds HistoryParams, HistoryEntry, HistoryResult types for the new JSON-RPC method. |
| crates/arf-console/src/ipc/server.rs | Routes "history" requests and handles them on the server thread. |
| crates/arf-console/src/ipc/mod.rs | Adds global history DB info + implements query_history; sets headless history item session_id. |
| crates/arf-console/src/ipc/client.rs | Implements cmd_history client request + terminal-aware JSON formatting. |
| crates/arf-console/src/cli.rs | Adds arf ipc history subcommand and flags/help text. |
| crates/arf-console/src/main.rs | Registers history DB info at startup (REPL + headless) and wires new IPC action. |
| crates/arf-console/tests/headless_tests.rs | Adds IPC history integration tests and a helper to invoke arf ipc history. |
| crates/arf-console/src/snapshots/arf__cli__tests__completions_*.snap | Updates completion snapshots for the new subcommand/options. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ssions The primary value of querying history via IPC is accessing the current session's entries. Querying all sessions can be done by reading the SQLite DB directly. - Default to current session only (was all sessions) - Replace --session-only with --all-sessions opt-in flag - Rename JSON-RPC param from session_only to all_sessions - Update docs, tests, and shell completion snapshots Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Use read-only rusqlite connection instead of SqliteBackedHistory::with_file to avoid WAL/DDL conflicts with the main history connection (same pattern as pager/history_browser.rs) - Allow history method through alternate mode guard (like session) - Return INVALID_PARAMS for validation errors (limit, since format), INTERNAL_ERROR only for DB/serialization failures - Return error when session_id is unavailable and all_sessions=false - Log warning on duplicate set_history_db_info calls - Fix since doc comment to mention YYYY-MM-DD format Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
LIKE interprets % and _ as wildcards even in parameterized queries, so user input containing those characters would match more rows than intended. Switch to instr() for exact substring matching, which is the same approach reedline uses for its Substring search. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Treat missing/null params as empty object in history method so callers can omit params and rely on defaults - Correct "always succeeds" wording for history in mutual exclusion section — history may fail if disabled or DB inaccessible - Document that only completed commands appear in history results (in both CLI help and IPC docs) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
historyJSON-RPC method andarf ipc historyCLI subcommand for querying command history from a running session--all-sessionsto include all)session_idin the databaseDetails
CLI usage
JSON-RPC protocol
{ "method": "history", "params": { "limit": 50, // max entries (default 50, must be positive) "all_sessions": false, // false = current session only (default) "cwd": null, // filter by exact working directory "grep": null, // substring search on command line "since": null // ISO 8601 / YYYY-MM-DD timestamp filter } }Architecture
OnceLockat startup (both REPL and headless)rusqlite::Connection(same pattern aspager/history_browser.rs) to avoid WAL/DDL conflictssessionmethodINVALID_PARAMS(-32602), DB errors returnINTERNAL_ERROR(-32603)Test plan
test_ipc_history_basic— basic query returns evaluated commandstest_ipc_history_limit—--limitrestricts entry counttest_ipc_history_grep—--grepfilters by command substringtest_ipc_history_default_session_scoped— default query scoped to current sessiontest_ipc_history_metadata— entries include timestamp, cwd, exit_statustest_ipc_history_disabled— error when history is disabledcargo clippycleandocs/ipc.mdupdated🤖 Generated with Claude Code