Repository navigation
Conversation
Add a stateless OSC 7577 decoder (kind: "resume") to zigpty/osc and a new zigpty/resume subpath with ResumeTracker (IPtyConsumer), verifyResumeReport, formatResumeReport and createResumeToken. Implements spec rev 0.5: SHA-256 mac with constant-time compare, time window + per-pid monotonic time, strict grammar, and ignored vs rejected semantics.
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.
Bring programs back after your terminal host restarts
If you build a terminal host on zigpty (an Electron/Tauri terminal, a web terminal, an agent dashboard), a restart normally drops every pane back to an empty shell. The user's editor session, git TUI, or agent conversation is gone.
This PR adds experimental support for the Program Resume Protocol (OSC 7577). With it, a program running in a pane can tell the host how to resume itself, e.g.
nvim -S ~/.local/state/nvim/sessions/8f2c1d.vimormyagent --resume <session-id>. The host can then run that command when it starts again. The report is signed with a random per-pane token. Text that is just printed to the pane (cat-ed files, logs, output fromsshsessions) doesn't have the token, so it can't register a command.Host side —
zigpty/resumeOn the next start, read the saved record back. If you decide to restore it, spawn the user's shell in
record.cwdand runrecord.argvthere. Pass each element as a separate argument and never build a shell string from it. Use a newResumeTrackerfor the restored pane, because tokens must not be reused. The resumed program is expected to report again.Program side —
formatResumeReportThis is for CLIs and TUIs that want to be resumable in any terminal that supports OSC 7577:
It throws if the command can't be reported, for example a relative program path, control characters, or both
argvandclear.Decoder —
zigpty/oscdecodeOSC()now decodes OSC 7577 into{ kind: "resume", valid, pid, time, argv?, cwd?, clear, need?, mac, signed }.signedis the exact text themaccovers. A malformed report still decodes askind: "resume"withvalid: falseand anerror, and keeps whatevermac/pid/timecould be parsed. The decoder has no token, so a decoded report is not proof of anything. UseverifyResumeReport(report, token)to getaccepted/ignored/rejected.What zigpty handles vs. what your app handles
resume.envresume.envonly to the pane's first process, with one tracker per paneESC \orBELonChangesomewhere only the user can readmacwith a constant-time compare, thetimewindow (60s by default), and thattimenever goes backwards for a pidcwd, runningargvwithout shell-quotingpidmust be the PTY's process or one of its descendants (usespty.stats())clear()when the user closes the pane on purposezigpty does not save records, restore or exec programs, integrate with shells, or clear a record when its owner process exits. The last one is deliberate: when the host shuts down, the PTY exits too, and that is exactly when the record is needed.
This follows spec rev 0.5 (2026-11-25), which is new and may change. The
zigpty/resumeAPI and theresumedecoded shape may change with it in a future release.Verification
clear, the owner check, a report at the spec's minimum limits (64 argv elements, 2048 bytes) and one too long to parse.formatResumeReportreproduces the spec examples byte-for-byte.bun run test(zig build test+ vitest) passes on Linux: 211 passed, 2 skipped.bun run fmt:checkandbun run buildare clean, andtscreports no errors insrc/.shscript usingbase64andsha256sum(the spec's wrapper example, not zigpty code) reported its resume command, andResumeTrackeraccepted it.🤖 Generated with AI assistant