Repository navigation
feat(tui): report the session to resume after a terminal restart (OSC 7577) - #66586
Open
oriori1703 wants to merge 1 commit into
Open
oriori1703 wants to merge 1 commit into
oriori1703 wants to merge 1 commit into
Conversation
… 7577) Terminals that implement the Program Resume Protocol (Rex, herdr) set OSC7577_TOKEN. The CLI takes it out of the environment at startup, so the background service, tool commands, editors and plugins never inherit it, and the TUI reports `opencode --session <id>` (plus --server, --standalone or --auto) for the session on screen through OpenTUI's setProgramResume. Leaving the session view or quitting clears it; SIGHUP and SIGTERM keep it, and fg after a suspend reports it again.
oriori1703
force-pushed
the
program-resume
branch
from
November 26, 2026 13:31
0d4d931 to
05f8e96
Compare
oriori1703
marked this pull request as ready for review
November 28, 2026 00:08
Contributor
There was a problem hiding this comment.
I couldn't run this end to end: it needs the unreleased renderer.setProgramResume from anomalyco/opentui#2213 and a terminal that sets OSC7577_TOKEN. The new program-resume unit tests pass (4/4). tsc -b in packages/tui fails only on the missing OpenTUI API (setProgramResume, ProgramResume), as you note, so this can't merge until OpenTUI is bumped.
I read through the rest and found no problems:
- The token is removed from the environment during module import, before any child process starts.
- The password check matches how
endpoint.authis set for--server. --sessionfinds the session by ID, so the resume command works whatever directory the session belongs to.- The clear is sent before the renderer is destroyed.
- A hangup goes through
destroyRendererrather thanexit(), so the resume command is kept.
Public API: the only addition is that the CLI now reads and removes the terminal-provided OSC7577_TOKEN environment variable. This is backwards compatible; nothing changes unless a terminal sets it.
No other concerns.
Related: #66324
This branch has not been deployed
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.
Issue for this PR
Closes #66462
Depends on anomalyco/opentui#2213 (
renderer.setProgramResume). Draft until that is released and OpenTUI is bumped here; until thentypecheckfails because 0.9.9 doesn't have the API.Type of change
What does this PR do?
Rex and herdr implement the Program Resume Protocol (OSC 7577): a program tells the terminal how to bring it back after the terminal restarts. This makes the TUI report the session on screen, so a Rex restart reopens it.
OSC7577_TOKENout of the environment at startup (env.ts), in every mode. The background service, tool commands, editors and plugins never get it, so they can't replace the command or register their own.opencode --session <id>plus--server,--standaloneor--autoif it was started with them, with the current directory ascwd. The command is the name this build installs as (opencode, oropencode2-nodefor the Node build), so a restart doesn't pick up a differentopencodeon PATH.--serverand a password, the TUI doesn't report. The resumed command starts in a fresh environment withoutOPENCODE_PASSWORD, and putting the password in the command would store it in the terminal's record.exit()) clears it. SIGHUP and SIGTERM keep it, since that's when the terminal needs it. Afterfgit reports again, because another program may have replaced it while opencode was stopped.No feature flag: nothing happens unless the terminal opts in by setting the token.
How did you verify your code works?
test/context/program-resume.test.tscovers when the TUI reports, clears, and retries.tschas no errors in opencode's files, andtest/app-lifecycle.test.tsxpasses (43/43).Screenshots / recordings
N/A, no UI.
Checklist
Added by the opencode bot (AI-generated).
Related: #66324
Public API: the CLI now reads and removes the terminal-provided OSC7577_TOKEN environment variable (additive, backwards compatible)