progresume

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

progresume

Go Reference

tuios.dev/progresume is a Go package for the Program Resume Protocol, OSC 7577. A program tells its terminal how to start it again after the terminal restarts. The terminal puts a token in the environment of the first process of each pane. The program signs each report with that token, so text that only passes through a pane cannot make a record.

The package has both sides of the protocol:

  • The program side. Report and Clear read the token, take it out of the environment, sign the report and write it to the controlling terminal.
  • The terminal side. Parse checks the mac, the time and the grammar in the order of the specification, and says if a report is ignored, rejected or accepted.
  • cmd/resume-wrap, the wrapper of the specification in Go.

The package uses only the standard library. tuios uses it in its daemon and its client.

The specification is at superlogical.com/rex/docs/build/program-resume. This package follows revision 0.5 (2026-11-25).

Install

go get tuios.dev/progresume

Report from a program

package main

import "tuios.dev/progresume"

func main() {
	// Start me again with this session file. ErrNoToken means that the
	// terminal does not support the protocol.
	_ = progresume.Report([]string{"nvim", "-S", "/home/user/.local/state/nvim/sessions/8f2c1d.vim"}, "")
	run()
	// The person quit on purpose: there is nothing to resume.
	_ = progresume.Clear()
}

argv[0] is a bare name, which the terminal looks up on PATH, or an absolute path. The second argument is the folder to start the program in, or "" for none. A report that breaks a rule of the specification is not sent, and the error says which rule.

Wrap any program

go install tuios.dev/progresume/cmd/resume-wrap@latest
resume-wrap ssh devbox

resume-wrap reports itself, the command and its folder, and then becomes the command. The command never gets the token.

License

MIT. See LICENSE.

Documentation

Overview

Package progresume reads and writes the Program Resume Protocol (OSC 7577), revision 0.5.

A program tells its terminal how to bring it back after the terminal restarts: an argument list, an owning pid, the time, and a hash that proves the program knows a token the terminal put in the environment of the pane's first process (OSC7577_TOKEN). The terminal checks the hash and the time before anything else, so text that only passes through a pane (a file shown with cat, the output of a remote host) cannot make a record.

Parse is the terminal side. Report and Clear are the program side: they read the token once, take it out of the environment, sign the report and write it to the controlling terminal. Sequence builds a signed report for a caller that writes it itself. Parse keeps no state: the record store, the owner check and the order of reports for one pid are the terminal's.

Example

A program reports how to start it again when it opens a session file, and clears the report when the person quits it on purpose.

package main

import (
	"errors"
	"log"

	"tuios.dev/progresume"
)

func main() {
	err := progresume.Report([]string{"nvim", "-S", "/home/user/.local/state/nvim/sessions/8f2c1d.vim"}, "")
	if err != nil && !errors.Is(err, progresume.ErrNoToken) {
		log.Printf("cannot report: %v", err)
	}
	// ... the program runs ...
	_ = progresume.Clear()
}

Index

Examples

Constants

View Source
const Command = 7577

Command is the OSC number of the protocol.

View Source
const MaxArgv = 64

MaxArgv is the most argv elements accepted, the minimum the specification asks for.

View Source
const MaxSequence = 2048

MaxSequence is the longest report accepted, in bytes, counted over the whole sequence from the OSC opener to the terminator. It is the minimum the specification asks a terminal to accept.

View Source
const TokenEnv = "OSC7577_TOKEN"

TokenEnv is the variable that holds a pane's token. A program that finds it may report, and a program that does not has no token to sign with.

View Source
const Window = 60 * time.Second

Window is how far a report's time may be from the terminal's clock.

Variables

View Source
var ErrInvalid = errors.New("progresume: the report is not valid")

ErrInvalid is what Report returns for a report that breaks a rule of the protocol. Nothing was sent.

View Source
var ErrNoToken = errors.New("progresume: the terminal gave no " + TokenEnv)

ErrNoToken is what Report and Clear return when the terminal gave this process no token. The terminal does not support the protocol, or another process already took the token. A program can ignore it.

View Source
var Implemented = []string{"pid", "time", "mac", "argv", "cwd", "clear", "need"}

Implemented is every key this package reads, which is what a report's need key may name.

Functions

func Clear

func Clear() error

Clear tells the terminal that this program has nothing to resume. See Reporter.Clear.

func Mac

func Mac(body, token string) string

Mac is the hex SHA-256 of body, ":" and token.

func NewToken

func NewToken() (string, error)

NewToken returns a fresh token of 32 characters of [A-Za-z0-9_-] from the system's secure random source.

func Report

func Report(argv []string, cwd string) error

Report tells the terminal how to start this program again. See Reporter.Report. The first call of Report, Clear or TakeToken takes the token out of the environment. ErrNoToken means the terminal gave none.

func Sequence

func Sequence(r Message, token string) string

Sequence is the whole OSC 7577 sequence for r, signed with token, ended with ST. A report with Clear set carries no argv or cwd.

func TakeToken

func TakeToken()

TakeToken removes OSC7577_TOKEN from the environment of this process without sending anything, so the programs it starts do not get the token. Report and Clear still work after it.

func ValidToken

func ValidToken(tok string) bool

ValidToken reports whether tok has the form the specification allows: 22 to 64 characters of [A-Za-z0-9_-].

Types

type Message

type Message struct {
	// PID is the owning process. 0 when the report named no usable pid.
	PID int
	// Time is when the report was made, in seconds since the Unix epoch.
	Time int64
	// Argv is the resume command. Empty for a clear.
	Argv []string
	// Cwd is the folder to resume in, "" when the report named none.
	Cwd string
	// Clear asks to remove the owner's record.
	Clear bool
}

Message is one report, decoded.

type Outcome

type Outcome int

Outcome is what a terminal does with a report.

const (
	// Ignored has no effect at all: the mac or the time is wrong, or the
	// report is cut short.
	Ignored Outcome = iota
	// Rejected passed the mac and the time but breaks a rule. The owner's
	// records are removed, when the report names a usable pid.
	Rejected
	// Accepted passed every check of the protocol.
	Accepted
)

type Reporter

type Reporter struct {
	// Token is the terminal's token.
	Token string
	// PID is the owner the reports name: the process the terminal should
	// watch. Report and Clear use the pid of this process.
	PID int
	// Out is where the reports go: the controlling terminal for Report and
	// Clear.
	Out io.Writer
	// Now is the clock. nil uses time.Now.
	Now func() time.Time
}

Reporter sends reports for one program, with the token, pid and output its fields name. The package functions Report and Clear share one Reporter made from the environment.

func (*Reporter) Clear

func (r *Reporter) Clear() error

Clear tells the terminal that the program has nothing to resume, for example when the person quit it on purpose.

func (*Reporter) Report

func (r *Reporter) Report(argv []string, cwd string) error

Report tells the terminal how to start the program again: argv is the command, with argv[0] a bare name that the terminal looks up on PATH or an absolute path. cwd is the folder to start it in, "" for none. A report that breaks a rule of the protocol is not sent, and the error says which.

type Result

type Result struct {
	Outcome Outcome
	Message Message
	// Reason says why a report was ignored or rejected, for a debug log. It
	// never holds a value of the report.
	Reason string
}

Result is a parsed report and what to do with it. Message.PID and Message.Time are set for a rejected report when it named them.

func Parse

func Parse(payload []byte, token string, now time.Time) Result

Parse reads the payload of one OSC 7577 sequence, "7577;" and the body, as the emulator hands it over. token is the pane's token and now the terminal's clock. The order is the specification's: the mac, then the time, then the grammar. A report whose time is earlier than the last accepted for its pid must be ignored as well; the caller holds those times.

Directories

Path Synopsis
cmd
resume-wrap command
Command resume-wrap runs a command so that the terminal can bring it back after a restart (OSC 7577, the Program Resume Protocol).
Command resume-wrap runs a command so that the terminal can bring it back after a restart (OSC 7577, the Program Resume Protocol).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL