feat(web): recall prompt history from the plugin with a browser fallback
The composer's ↑/↓ history is the web port of pi2.nvim's prompt buffer, so it has to walk the archive nvim walks — not a copy of it. Three tiers: the plugin owns the text, the daemon relays one live-only read, the browser keeps a mirror. - `features/chat/prompt-history.ts`: the readline rules (`appendEntry`: blank ignored, consecutive dedupe, newest 500), the `localStorage` mirror (`pi2-prompt-history`, per workspace, 40 workspaces LRU), the `PromptHistorySource` seam, and `PromptHistoryNav` — the per-composer cursor with a stashed draft, independent positions, and a reset on edit/send - `features/chat/prompt-history-feed.ts`: `usePromptHistory(workspaceId)` reads `GET /workspaces/:id/prompt-history`, appends a send optimistically, refreshes the mirror from every successful read, and falls back to the mirror whenever the relay cannot answer (no plugin, no capability, a 404 from an older daemon, an offline browser). One workspace-scoped read per page, never per keystroke. - composer: ↑ recalls from the first line, ↓ from the last line or while browsing, `<C-p>`/`<C-n>` always recall; an IME composition and a text selection keep their keys; the caret lands at the end of a recalled prompt and a manual edit ends recall - fixes a mirror bug found while testing it: a full list that accepts one more entry and drops the oldest has the same length, so the old "unchanged" check silently stopped recording after 500 prompts - `docs/prompt-history.md` records the tiers, the key map, the storage contract and what is deliberately not shared yet (cross-host, history without nvim); the UI mock server answers the new endpoint so the visual harness stays honest Version skew is boring by design: an old daemon (404) or an old plugin (no capability) keeps recall working from the mirror.
This commit is contained in:
1 parent
32292873f9
commit
b8f1fca5bd
11 files changed
+1324
-6
No files matched your search
@@ -37,6 +37,7 @@ import { useSessionHistory } from "@/features/chat/history";
|
||||
import { ChatLayout } from "@/features/chat/layout";
|
||||
import { MessageStream } from "@/features/chat/message-stream";
|
||||
import { onSessionMigration, replaceChatUrl } from "@/features/chat/migration";
|
||||
import { usePromptHistory } from "@/features/chat/prompt-history-feed";
|
||||
import { DispatchModal, RenameDialog, TaskOutputModal, type DispatchInput } from "@/features/chat/modals";
|
||||
import { SessionTray } from "@/features/chat/session-tray";
|
||||
import { sessionTitle } from "@/features/chat/session-title";
|
||||
@@ -143,6 +144,10 @@ function ChatExperience({ sessionId }: { sessionId?: string }) {
|
||||
active?.workspaceId ?? workspaceId,
|
||||
);
|
||||
const models = useChatModels(workspaceId, paired);
|
||||
// Composer ↑/↓ recall: the plugin owns the archive, the daemon relays a
|
||||
// live-only read, and the browser mirror covers a cold workspace or an old
|
||||
// plugin. Never spawns an nvim (see docs/prompt-history.md).
|
||||
const promptHistory = usePromptHistory(workspaceId, paired);
|
||||
const workspace = workspaces.find((item) => item.workspaceId === workspaceId);
|
||||
// pi2.nvim's placeholder vocabulary, and the display title of the routed
|
||||
// session: name → first message → `(unnamed)`. Never the session id.
|
||||
@@ -724,6 +729,7 @@ function ChatExperience({ sessionId }: { sessionId?: string }) {
|
||||
connected={connected}
|
||||
paired={paired}
|
||||
sending={sending}
|
||||
history={promptHistory.source}
|
||||
onSend={(text, images, mode) => void handleSend(text, images, mode)}
|
||||
onAbort={() => {
|
||||
setSending(null);
|
||||
|
||||
Reference in new issue
Block a user