fix(history-storage): restored session_id column and prompt-history ranking

- Fixed `session_id` never being created or populated; every history row had `NULL` for session.
- Added schema migration (`ALTER TABLE history ADD COLUMN session_id`) for pre-existing databases.
- Wired interactive mode to call `setSessionResolver(...)` so prompts are stamped with the active session at submission time.
- Re-enabled session ranking in `--resume` and in-session pickers via `matchingSessionIds()`, merging fuzzy and prompt-history signals.
This commit is contained in:
can1357
2026-06-02 05:15:56 +02:00
parent c1f1e8022d
commit 783971f575
9 changed files with 345 additions and 15 deletions
+2 -1
View File
@@ -323,7 +323,8 @@ This separation keeps `SessionManager` logic independent from storage backend an
`packages/coding-agent/src/session/history-storage.ts` (`HistoryStorage`) is not conversation state restoration.
- Stores prompt history in SQLite (`history.db`) with FTS5 index (`history_fts`).
- APIs are `add(prompt, cwd?)`, `getRecent(limit)`, `search(query, limit)`.
- APIs are `add(prompt, cwd?, sessionId?)`, `getRecent(limit)`, `search(query, limit)`, `matchingSessionIds(query, limit?)`.
- Each row records the originating session via the `session_id` column (surfaced as `HistoryEntry.sessionId`), so prompts can be traced back to the session they were submitted from (e.g. for `--resume`). Interactive mode registers a resolver via `setSessionResolver(...)` so prompts added without an explicit id are stamped with the session active at `add()` time, tracking fork/resume switches.
- Uses singleton `HistoryStorage.open(...)` and asynchronous insert (`setImmediate`) with duplicate-last-prompt suppression.
This is command/input recall data; it does not rebuild agent message trees.