Skip to content

feat(tui): add prompt.history_scope to recall only the session's own prompts - #55902

Open
Nowaker wants to merge 1 commit into
anomalyco:v1from
Nowaker:history-scope
Open

Nowaker wants to merge 1 commit into
anomalyco:v1from
Nowaker:history-scope

Conversation

@Nowaker

@Nowaker Nowaker commented Oct 16, 2026

Copy link
Copy Markdown

Note: I'm aware v1 is now the maintenance branch and new features go to v2 only. This PR is here for others to use, and I'll submit the v2 version once I've migrated my whole plugin system to it.

Issue for this PR

Refs #52154

The v2 counterpart is #55261 by @asamarts, against dev. This PR uses the same key and values (prompt.history_scope: "global" | "session"), so a tui.json written for one works with the other.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

up and down in the prompt walk one history file shared by every session and every OpenCode window on the machine, so a session recalls prompts written for unrelated work in another terminal.

  • prompt.history_scope in tui.json: "global" (default, today's behavior) or "session", where a session walks only the prompts submitted in it.
  • Each prompt-history.jsonl entry records its sessionID. The first prompt sent from the home screen is recorded with the session it creates. Recall filters at read time (promptHistoryView), so switching the setting needs no migration.
  • The home screen has no session yet, so it keeps walking every session's prompts in both scopes. Entries written by older versions have no session: only the home screen and global recall them.
  • Shell-mode (!) entries, paste placeholders and cleared drafts come back exactly as before; that is why history stays in the file rather than being derived from the session's user messages, which lose all three.
  • Retention follows the scope. global keeps the newest 50 entries, as before. session keeps the newest 50 of each of the 50 most recently used sessions, so a busy session cannot push a quiet one's history out.
  • A trim rereads the file before rewriting it, so a TUI that has been open for hours does not drop entries other TUIs appended since it loaded.

How did you verify your code works?

  • bun typecheck in packages/tui; bun test test/prompt test/config.test.tsx pass. history.test.ts covers both scopes' views and retention, the home-screen fallback and shell mode.
  • A real TUI in tmux with isolated XDG dirs, two processes, shell-mode prompts. session: session B recalls only echo beta-1; reopened session A recalls echo alpha-2, then echo alpha-1, in shell mode, and nothing from B. global: session B recalls echo beta-1, echo alpha-2, echo alpha-1.

Screenshots / recordings

Behavior-only change, no visual change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

This PR is AI generated, but under direct supervision and on request of @Nowaker.

…prompts

Up and down in the prompt walk one history file shared by every
session and every OpenCode window on the machine, so a session recalls
prompts that were written for unrelated work. prompt.history_scope
chooses between 'global' (the default, unchanged behaviour) and
'session', where a session walks only the prompts submitted in it.

Each prompt-history.jsonl entry now records the session it was
submitted in. The first prompt sent from the home screen is recorded
with the session it creates. The view is filtered at recall time
(promptHistoryView in packages/tui/src/prompt/history.tsx), so
switching the setting needs no migration and the home screen, which
has no session yet, keeps walking every session's prompts.

Tagging the file was chosen over deriving history from the session's
user messages: messages lose what history needs to bring a prompt back
as typed - shell mode ('!' commands are stored as tool parts), paste
placeholders with their sources, and cleared drafts, which never
become messages. Entries written by older versions have no session and
are recalled only on the home screen and with the global scope.

Retention follows the scope. Global keeps the newest 50 entries, as
before. Session keeps the newest 50 of each of the 50 most recently
used sessions, so a busy session cannot push a quiet one's history
out. A trim rereads the file before rewriting it, so a TUI that has
been open for hours does not drop entries other TUIs appended.
@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

This branch has not been deployed

No deployments
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.

1 participant