Skip to content

Persist search and query history with FX_HISTORY_FILE - #444

Open
ykakade wants to merge 2 commits into
antonmedv:masterfrom
ykakade:feat/332-persistent-search-history
Open

ykakade wants to merge 2 commits into
antonmedv:masterfrom
ykakade:feat/332-persistent-search-history

Conversation

@ykakade

@ykakade ykakade commented Oct 31, 2026

Copy link
Copy Markdown

Closes #332

Set FX_HISTORY_FILE to keep / searches and interactive queries between fx sessions. Use Up and Down to recall searches, with the current draft restored after the newest entry.

How it works

Searches and JavaScript queries use separate arrays in one JSON file. Each history keeps 100 entries and skips consecutive duplicates. Only Enter adds an entry, and @ selections are excluded.

flowchart LR
  F[FX_HISTORY_FILE] --> L[Load histories at startup]
  L --> S[Search input]
  L --> Q[Query input]
  S -->|Enter| W[Write private temporary file]
  Q -->|Enter| W
  W --> R[Replace history file]
Loading

Writes use a temporary file with mode 0600 in the same directory, followed by a rename. Read and write errors appear in the command line. Invalid files stay untouched, and fx keeps working with history in memory.

How to test

  1. Run FX_HISTORY_FILE=/tmp/fx-history.json go run . testdata/example.json.
  2. Submit a / search with Enter, then quit.
  3. Run the same command and press /, then Up.
  4. Check that the previous search appears.

Notes

An unset or empty FX_HISTORY_FILE keeps the existing in-memory behavior. The parent directory must exist. Concurrent sessions use the last saved history. History files are limited to 1 MiB.

Checklist

  • Add separate search history and Up/Down navigation
  • Save and load search and query history with FX_HISTORY_FILE
  • Document file permissions, limits, and concurrent sessions
  • Test recall across models, draft restoration, cancellation, duplicates, limits, and file errors
  • Run go test ./...
  • Run go test -race . -run TestHistory -count=1 and go vet ./...
  • Run node test.js in npm

@ykakade
ykakade marked this pull request as ready for review October 31, 2026 20:47
@ykakade ykakade mentioned this pull request Oct 31, 2026
Comment thread README.md Outdated
The parent directory must already exist. The file contains JSON and is created
with owner-only permissions. An unset or empty variable keeps history in memory.
Only inputs submitted with Enter are saved. Fuzzy JSON path selections (`@`) are
not saved. Concurrent sessions use the last saved history.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wtf? I will not merge this readme update.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. I removed the README change in 23751dd. The PR now changes only the code and tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Add search history

2 participants