=============== LIBRARY RULES =============== From library maintainers: - Install with pip install osc7577 (Python 3.11+) and import from osc7577: report, clear, supported, scrub_env, encode, verify. - report() and clear() do nothing and return False unless the terminal set OSC7577_TOKEN; check supported() first if you need to know. - The first argv element must be an absolute path or a bare command name, and cwd must be an absolute path; otherwise report() sends a clear and raises ReportError. - Call clear() on a normal quit so the terminal does not resume a program the user closed on purpose. - Start child processes with env=scrub_env() so they cannot see the token or report commands in your place. - Never print or log OSC7577_TOKEN. ### Install osc7577 with pip Source: https://github.com/ysskrishna/osc7577/blob/main/README.md Install the osc7577 library from PyPI. ```bash pip install osc7577 ``` -------------------------------- ### Scrub environment for child processes Source: https://github.com/ysskrishna/osc7577/blob/main/README.md Start child processes with env=scrub_env() so they cannot see the token or report commands in your place. ```python import subprocess from osc7577 import scrub_env subprocess.run(["git", "--version"], env=scrub_env(), check=True) ``` -------------------------------- ### Claude Code hook configuration for OSC 7577 Source: https://github.com/ysskrishna/osc7577/blob/main/README.md Add hooks in ~/.claude/settings.json to report and clear resume commands for Claude Code until it supports OSC 7577 natively. On start it reports 'claude --resume ' with the session's directory; on normal quit it clears the record. ```json { "hooks": { "SessionStart": [{"hooks": [{"type": "command", "command": "osc7577 claude-hook"}]}], "SessionEnd": [{"hooks": [{"type": "command", "command": "osc7577 claude-hook"}]}] } } ``` -------------------------------- ### build_body(*, pid, argv, cwd, clear, time, windows) -> str Source: https://github.com/ysskrishna/osc7577/blob/main/README.md The body without the final `:mac=` pair. ```APIDOC ## build_body(*, pid, argv, cwd, clear, time, windows) -> str ### Description The body without the final `:mac=` pair. ### Method Function call ### Signature `build_body(*, pid, argv, cwd, clear, time, windows) -> str` ### Parameters - `pid` (keyword) - Required - Process ID. - `argv` (keyword) - Required - Command arguments. - `cwd` (keyword) - Required - Current working directory. - `clear` (keyword) - Required - Clear flag. - `time` (keyword) - Required - Timestamp. - `windows` (keyword) - Required - Windows platform flag. ### Returns - `str` - The body without the final `:mac=` pair. ``` -------------------------------- ### report(argv, *, cwd, pid, token, stream, tty_path, env) -> bool Source: https://github.com/ysskrishna/osc7577/blob/main/README.md Write a resume report. Sends 'clear' and raises ReportError when the command cannot be reported. ```APIDOC ## report(argv, *, cwd, pid, token, stream, tty_path, env) -> bool ### Description Write a resume report. Sends `clear` and raises `ReportError` when the command cannot be reported. ### Method Function call ### Signature `report(argv, *, cwd, pid, token, stream, tty_path, env) -> bool` ### Parameters - `argv` - Required - Command arguments. - `cwd` (keyword) - Required - Current working directory. - `pid` (keyword) - Required - Process ID. - `token` (keyword) - Required - Authentication token. - `stream` (keyword) - Required - Output stream. - `tty_path` (keyword) - Required - TTY path. - `env` (keyword) - Required - Environment. ### Returns - `bool` - True on success. ### Errors - `ReportError` - Raised when the command cannot be reported. ``` -------------------------------- ### supported(env=None) -> bool Source: https://github.com/ysskrishna/osc7577/blob/main/README.md True when the terminal set `OSC7577_TOKEN`. ```APIDOC ## supported(env=None) -> bool ### Description True when the terminal set `OSC7577_TOKEN`. ### Method Function call ### Signature `supported(env=None) -> bool` ### Parameters - `env` (optional) - Environment to check. ### Returns - `bool` - True if `OSC7577_TOKEN` is set. ``` -------------------------------- ### scrub_env(env=None) -> dict Source: https://github.com/ysskrishna/osc7577/blob/main/README.md A copy of the environment without `OSC7577_TOKEN`. ```APIDOC ## scrub_env(env=None) -> dict ### Description A copy of the environment without `OSC7577_TOKEN`. ### Method Function call ### Signature `scrub_env(env=None) -> dict` ### Parameters - `env` (optional) - Environment to copy. ### Returns - `dict` - Environment copy without `OSC7577_TOKEN`. ``` -------------------------------- ### is_absolute(path, windows=None), is_bare_command(name, windows=None) Source: https://github.com/ysskrishna/osc7577/blob/main/README.md The spec's path rules. `windows` defaults to the running platform. ```APIDOC ## is_absolute(path, windows=None), is_bare_command(name, windows=None) ### Description The spec's path rules. `windows` defaults to the running platform. ### Method Function call ### Signatures - `is_absolute(path, windows=None)` - `is_bare_command(name, windows=None)` ### Parameters - `path` - Required - Path to check. - `name` - Required - Command name to check. - `windows` (optional) - Windows platform flag. ### Returns - `bool` - True if the path is absolute or the command is bare. ``` -------------------------------- ### TOKEN_ENV Source: https://github.com/ysskrishna/osc7577/blob/main/README.md `"OSC7577_TOKEN"`. ```APIDOC ## TOKEN_ENV ### Description `"OSC7577_TOKEN"`. ### Value - `"OSC7577_TOKEN"` ``` -------------------------------- ### clear(*, pid, token, stream, tty_path, env) -> bool Source: https://github.com/ysskrishna/osc7577/blob/main/README.md Remove this program's record. Send it on a normal quit. ```APIDOC ## clear(*, pid, token, stream, tty_path, env) -> bool ### Description Remove this program's record. Send it on a normal quit. ### Method Function call ### Signature `clear(*, pid, token, stream, tty_path, env) -> bool` ### Parameters - `pid` (keyword) - Required - Process ID. - `token` (keyword) - Required - Authentication token. - `stream` (keyword) - Required - Output stream. - `tty_path` (keyword) - Required - TTY path. - `env` (keyword) - Required - Environment. ### Returns - `bool` - True on success. ``` -------------------------------- ### encode(*, token, pid, argv, cwd, clear, time, terminator, strict_limits, windows) -> str Source: https://github.com/ysskrishna/osc7577/blob/main/README.md Build one full sequence. Does not write. ```APIDOC ## encode(*, token, pid, argv, cwd, clear, time, terminator, strict_limits, windows) -> str ### Description Build one full sequence. Does not write. ### Method Function call ### Signature `encode(*, token, pid, argv, cwd, clear, time, terminator, strict_limits, windows) -> str` ### Parameters - `token` (keyword) - Required - Authentication token. - `pid` (keyword) - Required - Process ID. - `argv` (keyword) - Required - Command arguments. - `cwd` (keyword) - Required - Current working directory. - `clear` (keyword) - Required - Clear flag. - `time` (keyword) - Required - Timestamp. - `terminator` (keyword) - Required - Sequence terminator. - `strict_limits` (keyword) - Required - Enforce strict limits. - `windows` (keyword) - Required - Windows platform flag. ### Returns - `str` - The full sequence. ``` -------------------------------- ### verify(data, token, *, now, window, implemented, windows) -> Report Source: https://github.com/ysskrishna/osc7577/blob/main/README.md Check a report as a terminal must. Raises `Ignored` or `Rejected`. ```APIDOC ## verify(data, token, *, now, window, implemented, windows) -> Report ### Description Check a report as a terminal must. Raises `Ignored` or `Rejected`. ### Method Function call ### Signature `verify(data, token, *, now, window, implemented, windows) -> Report` ### Parameters - `data` - Required - The report data. - `token` - Required - Authentication token. - `now` (keyword) - Required - Current time. - `window` (keyword) - Required - Time window. - `implemented` (keyword) - Required - Implemented features. - `windows` (keyword) - Required - Windows platform flag. ### Returns - `Report` - The parsed report. ### Errors - `Ignored` - Raised when the report is ignored. - `Rejected` - Raised when the report is rejected. ``` -------------------------------- ### Wrap any command with osc7577 wrap Source: https://github.com/ysskrishna/osc7577/blob/main/README.md Wrap a command so it reports 'osc7577 wrap ssh devbox' with the current directory, then runs the command without the token. Also supports 'osc7577 report -- CMD' and 'osc7577 clear' for the parent shell. ```bash osc7577 wrap -- ssh devbox ``` -------------------------------- ### Report and clear program resume command Source: https://github.com/ysskrishna/osc7577/blob/main/README.md Report a resume command and clear it on normal exit. Only works if the terminal set OSC7577_TOKEN; otherwise report and clear return False. The first argument must be an absolute path or bare command name, and cwd must be absolute; violations send clear and raise ReportError. ```python import atexit from osc7577 import clear, report, supported if supported(): # the terminal set OSC7577_TOKEN report(["myrepl", "--session", "/home/me/.local/state/myrepl/42.json"], cwd="/home/me/proj") atexit.register(clear) # a normal quit should not be resumed ``` -------------------------------- ### Verify OSC 7577 sequence on terminal side Source: https://github.com/ysskrishna/osc7577/blob/main/README.md Verify a sequence with a token, checking MAC first, then time (60 s window), then keys. Handle Ignored (no effect) and Rejected (remove this owner's records) exceptions. ```python from osc7577 import Ignored, Rejected, encode, verify token = "dummy-token-replace-me" sequence = encode(token=token, pid=74877, argv=["lazygit"], cwd="/home/user/src/project") try: rep = verify(sequence, token) # checks mac first, then time (60 s window), then keys print(rep.pid, rep.argv, rep.cwd) except Ignored: pass # no effect except Rejected: pass # remove this owner's records ``` -------------------------------- ### Report Source: https://github.com/ysskrishna/osc7577/blob/main/README.md Data class with fields `pid`, `time`, `argv`, `cwd`, `clear`, `extra`. ```APIDOC ## Report ### Description Data class with fields `pid`, `time`, `argv`, `cwd`, `clear`, `extra`. ### Fields - `pid` - Process ID. - `time` - Timestamp. - `argv` - Command arguments. - `cwd` - Current working directory. - `clear` - Clear flag. - `extra` - Extra data. ``` -------------------------------- ### compute_mac(body, token) -> str Source: https://github.com/ysskrishna/osc7577/blob/main/README.md SHA-256 of `body:token` as 64 hex characters (not an HMAC). ```APIDOC ## compute_mac(body, token) -> str ### Description SHA-256 of `body:token` as 64 hex characters (not an HMAC). ### Method Function call ### Signature `compute_mac(body, token) -> str` ### Parameters - `body` - Required - The body string. - `token` - Required - Authentication token. ### Returns - `str` - 64 hex characters. ``` -------------------------------- ### ReportError, Ignored, Rejected Source: https://github.com/ysskrishna/osc7577/blob/main/README.md Errors. `ReportError` is a `ValueError`. ```APIDOC ## ReportError, Ignored, Rejected ### Description Errors. `ReportError` is a `ValueError`. ### Types - `ReportError` - A `ValueError`. - `Ignored` - Error raised when a report is ignored. - `Rejected` - Error raised when a report is rejected. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.