Skip to content

feat(tui): report the session to resume after a terminal restart (OSC 7577) - #66586

Open
oriori1703 wants to merge 1 commit into
anomalyco:devfrom
oriori1703:program-resume
Open

oriori1703 wants to merge 1 commit into
anomalyco:devfrom
oriori1703:program-resume

Conversation

@oriori1703

@oriori1703 oriori1703 commented Nov 26, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #66462

Depends on anomalyco/opentui#2213 (renderer.setProgramResume). Draft until that is released and OpenTUI is bumped here; until then typecheck fails because 0.9.9 doesn't have the API.

Type of change

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

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.

  • The CLI takes OSC7577_TOKEN out 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.
  • The TUI reports opencode --session <id> plus --server, --standalone or --auto if it was started with them, with the current directory as cwd. The command is the name this build installs as (opencode, or opencode2-node for the Node build), so a restart doesn't pick up a different opencode on PATH.
  • With --server and a password, the TUI doesn't report. The resumed command starts in a fresh environment without OPENCODE_PASSWORD, and putting the password in the command would store it in the terminal's record.
  • Leaving the session view or quitting (any exit()) clears it. SIGHUP and SIGTERM keep it, since that's when the terminal needs it. After fg it reports again, because another program may have replaced it while opencode was stopped.
  • Encoding and signing live in OpenTUI.

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.ts covers when the TUI reports, clears, and retries.
  • Against a locally linked build of the OpenTUI PR: tsc has no errors in opencode's files, and test/app-lifecycle.test.tsx passes (43/43).
  • Not yet tried live in Rex.

Screenshots / recordings

N/A, no UI.

Checklist

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

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)

… 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
oriori1703 marked this pull request as ready for review November 28, 2026 00:08

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.auth is set for --server.
  • --session finds 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 destroyRenderer rather than exit(), 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

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.

[FEATURE]: Support OSC7577 for resumption of conversations after a terminal restarts

1 participant