osc7577 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- osc7577-1.0.0/.github/CODEOWNERS +2 -0
- osc7577-1.0.0/.github/FUNDING.yml +4 -0
- osc7577-1.0.0/.github/SECURITY.md +15 -0
- osc7577-1.0.0/.github/workflows/publish.yml +78 -0
- osc7577-1.0.0/.github/workflows/test.yml +45 -0
- osc7577-1.0.0/.gitignore +11 -0
- osc7577-1.0.0/.python-version +1 -0
- osc7577-1.0.0/CHANGELOG.md +22 -0
- osc7577-1.0.0/CONTRIBUTING.md +144 -0
- osc7577-1.0.0/LICENSE +21 -0
- osc7577-1.0.0/PKG-INFO +201 -0
- osc7577-1.0.0/README.md +174 -0
- osc7577-1.0.0/context7.json +34 -0
- osc7577-1.0.0/osc7577/__init__.py +14 -0
- osc7577-1.0.0/osc7577/__main__.py +55 -0
- osc7577-1.0.0/osc7577/claude_hook.py +93 -0
- osc7577-1.0.0/osc7577/encode.py +115 -0
- osc7577-1.0.0/osc7577/paths.py +31 -0
- osc7577-1.0.0/osc7577/py.typed +0 -0
- osc7577-1.0.0/osc7577/terminal.py +82 -0
- osc7577-1.0.0/osc7577/verify.py +131 -0
- osc7577-1.0.0/pyproject.toml +58 -0
- osc7577-1.0.0/tests/conftest.py +12 -0
- osc7577-1.0.0/tests/pty_e2e.py +19 -0
- osc7577-1.0.0/tests/test_claude_hook.py +39 -0
- osc7577-1.0.0/tests/test_encode_rules.py +40 -0
- osc7577-1.0.0/tests/test_terminal.py +58 -0
- osc7577-1.0.0/tests/test_vectors.py +113 -0
- osc7577-1.0.0/tests/test_windows_paths.py +50 -0
- osc7577-1.0.0/uv.lock +79 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Supported versions
|
|
4
|
+
|
|
5
|
+
Only the latest release of OSC 7577 receives security fixes.
|
|
6
|
+
|
|
7
|
+
Upgrade with `pip install -U osc7577`.
|
|
8
|
+
|
|
9
|
+
## Reporting a vulnerability
|
|
10
|
+
|
|
11
|
+
Please **do not** open a public issue for security problems.
|
|
12
|
+
|
|
13
|
+
Report it privately through GitHub instead: open the [Security tab](https://github.com/ysskrishna/osc7577/security/advisories/new) of this repository and choose **Report a vulnerability**. Include the affected version, steps to reproduce, and the impact you expect.
|
|
14
|
+
|
|
15
|
+
You will get an acknowledgement within 7 days. Once a fix is released the advisory is published with credit to the reporter (unless you ask to stay anonymous).
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
name: "Publish"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
# Publish on full version tags, e.g., v1.0.0
|
|
7
|
+
- "v*.*.*"
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: false
|
|
12
|
+
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
build:
|
|
18
|
+
name: Build distributions
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
permissions:
|
|
21
|
+
contents: read
|
|
22
|
+
steps:
|
|
23
|
+
- name: Checkout
|
|
24
|
+
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
|
|
25
|
+
with:
|
|
26
|
+
persist-credentials: false
|
|
27
|
+
- name: Install uv
|
|
28
|
+
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
|
|
29
|
+
with:
|
|
30
|
+
enable-cache: false
|
|
31
|
+
python-version: "3.11"
|
|
32
|
+
- name: Build
|
|
33
|
+
run: uv build
|
|
34
|
+
- name: Upload distributions
|
|
35
|
+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
|
36
|
+
with:
|
|
37
|
+
name: dist
|
|
38
|
+
path: dist/
|
|
39
|
+
|
|
40
|
+
publish:
|
|
41
|
+
name: Publish to PyPI
|
|
42
|
+
needs: build
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
environment:
|
|
45
|
+
name: pypi
|
|
46
|
+
permissions:
|
|
47
|
+
id-token: write # trusted publishing (OIDC); no PyPI token is stored in the repo
|
|
48
|
+
steps:
|
|
49
|
+
- name: Install uv
|
|
50
|
+
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
|
|
51
|
+
with:
|
|
52
|
+
enable-cache: false
|
|
53
|
+
python-version: "3.11"
|
|
54
|
+
- name: Download distributions
|
|
55
|
+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
|
|
56
|
+
with:
|
|
57
|
+
name: dist
|
|
58
|
+
path: dist/
|
|
59
|
+
- name: Generate PEP 740 attestations
|
|
60
|
+
uses: astral-sh/attest-action@f589a42a7efb6fe400b4f400de60b4bc90390027 # v0.0.6
|
|
61
|
+
- name: Publish
|
|
62
|
+
run: uv publish
|
|
63
|
+
|
|
64
|
+
release:
|
|
65
|
+
name: Create GitHub Release
|
|
66
|
+
needs: publish
|
|
67
|
+
runs-on: ubuntu-latest
|
|
68
|
+
permissions:
|
|
69
|
+
contents: write
|
|
70
|
+
steps:
|
|
71
|
+
- name: Checkout
|
|
72
|
+
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
|
|
73
|
+
with:
|
|
74
|
+
fetch-depth: 0
|
|
75
|
+
persist-credentials: false
|
|
76
|
+
|
|
77
|
+
- name: Create GitHub release from changelog
|
|
78
|
+
uses: ysskrishna/changelog-release-action@v1
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
concurrency:
|
|
10
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
11
|
+
cancel-in-progress: true
|
|
12
|
+
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
test:
|
|
18
|
+
runs-on: ${{ matrix.os }}
|
|
19
|
+
strategy:
|
|
20
|
+
fail-fast: false
|
|
21
|
+
matrix:
|
|
22
|
+
os: [ubuntu-latest]
|
|
23
|
+
python-version: ["3.11", "3.12", "3.13", "3.14"]
|
|
24
|
+
include:
|
|
25
|
+
- os: macos-latest
|
|
26
|
+
python-version: "3.14"
|
|
27
|
+
- os: windows-latest
|
|
28
|
+
python-version: "3.14"
|
|
29
|
+
|
|
30
|
+
steps:
|
|
31
|
+
- name: Checkout
|
|
32
|
+
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
|
|
33
|
+
with:
|
|
34
|
+
persist-credentials: false
|
|
35
|
+
|
|
36
|
+
- name: Install uv
|
|
37
|
+
uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
|
|
38
|
+
with:
|
|
39
|
+
python-version: ${{ matrix.python-version }}
|
|
40
|
+
|
|
41
|
+
- name: Install dependencies
|
|
42
|
+
run: uv sync --locked --dev
|
|
43
|
+
|
|
44
|
+
- name: Run tests
|
|
45
|
+
run: uv run pytest
|
osc7577-1.0.0/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.11
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0] - 2026-12-05
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `encode()` builds one OSC 7577 report or clear for Program Resume Protocol revision 0.6, with the spec's `time` and token hash (`mac`)
|
|
13
|
+
- `report()` and `clear()` write that report to the terminal. They return `False` when the terminal did not set `OSC7577_TOKEN`
|
|
14
|
+
- A command that cannot be reported (a relative path, control characters, over 2048 bytes or 64 elements) sends `clear` and raises `ReportError`, so an older command is not resumed in its place
|
|
15
|
+
- `supported()` and `scrub_env()`. Child processes started with `scrub_env()` cannot see the token
|
|
16
|
+
- `verify()` parses and checks a report the way a terminal must, raising `Ignored` or `Rejected`
|
|
17
|
+
- Revision 0.6 Windows path rules: `is_absolute()` and `is_bare_command()`. `encode()`, `build_body()` and `verify()` take `windows=`, which defaults to the running platform
|
|
18
|
+
- CLI: `osc7577 report`, `osc7577 clear`, `osc7577 wrap -- CMD` and `osc7577 claude-hook`
|
|
19
|
+
- Zero runtime dependencies
|
|
20
|
+
- Python 3.11+
|
|
21
|
+
|
|
22
|
+
[1.0.0]: https://github.com/ysskrishna/osc7577/releases/tag/v1.0.0
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Contributing to osc7577
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to `osc7577`! This document provides guidelines and instructions for contributing.
|
|
4
|
+
|
|
5
|
+
## Getting Started
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
|
|
9
|
+
- Python 3.11 or higher
|
|
10
|
+
- [uv](https://github.com/astral-sh/uv)
|
|
11
|
+
|
|
12
|
+
### Setting Up the Development Environment
|
|
13
|
+
|
|
14
|
+
1. **Clone the repository**:
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/ysskrishna/osc7577.git
|
|
17
|
+
cd osc7577
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
2. **Install dependencies**:
|
|
21
|
+
```bash
|
|
22
|
+
uv sync --locked --dev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
3. **Verify the setup**:
|
|
26
|
+
```bash
|
|
27
|
+
uv run pytest
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Development Workflow
|
|
31
|
+
|
|
32
|
+
### Running Tests
|
|
33
|
+
|
|
34
|
+
Run the test suite to ensure everything works:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
uv run pytest
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Run a specific test file:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
uv run pytest tests/test_vectors.py
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Code Style
|
|
47
|
+
|
|
48
|
+
- Follow [PEP 8](https://pep8.org/) style guidelines
|
|
49
|
+
- Use type hints for all function parameters and return values
|
|
50
|
+
- Keep functions simple and focused
|
|
51
|
+
- Add docstrings to all public functions
|
|
52
|
+
|
|
53
|
+
### Changing a report
|
|
54
|
+
|
|
55
|
+
The byte format and the mac live in `osc7577/encode.py`. Path rules live in `osc7577/paths.py`. Writing to the terminal lives in `osc7577/terminal.py`, and the terminal-side checks live in `osc7577/verify.py`.
|
|
56
|
+
|
|
57
|
+
1. Add a failing test in `tests/` for the sequence or the error
|
|
58
|
+
2. Change the encoder, the writer or the verifier
|
|
59
|
+
3. Run `uv run pytest`
|
|
60
|
+
4. Open a pull request into `main`
|
|
61
|
+
|
|
62
|
+
The spec's published examples are in `tests/test_vectors.py`. A change that alters one of those bytes or macs is a spec change, not a fix.
|
|
63
|
+
|
|
64
|
+
Never print or log the token. Child processes start with `scrub_env()`, so they cannot see it.
|
|
65
|
+
|
|
66
|
+
## Submitting Changes
|
|
67
|
+
|
|
68
|
+
### Pull Request Process
|
|
69
|
+
|
|
70
|
+
1. **Create a branch**:
|
|
71
|
+
```bash
|
|
72
|
+
git checkout -b feature/your-feature-name
|
|
73
|
+
# or
|
|
74
|
+
git checkout -b fix/your-fix-name
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
2. **Make your changes**:
|
|
78
|
+
- Write your code
|
|
79
|
+
- Add tests for new functionality
|
|
80
|
+
- Ensure all tests pass
|
|
81
|
+
- Update documentation if needed
|
|
82
|
+
|
|
83
|
+
3. **Commit your changes**:
|
|
84
|
+
```bash
|
|
85
|
+
git add .
|
|
86
|
+
git commit -m "Description of your changes"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Use clear, descriptive commit messages. Follow the format:
|
|
90
|
+
- `feat: add new feature`
|
|
91
|
+
- `fix: fix bug description`
|
|
92
|
+
- `docs: update documentation`
|
|
93
|
+
- `test: add tests for feature`
|
|
94
|
+
- `refactor: improve code structure`
|
|
95
|
+
|
|
96
|
+
4. **Push to your fork**:
|
|
97
|
+
```bash
|
|
98
|
+
git push origin feature/your-feature-name
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
5. **Create a Pull Request** into `main`:
|
|
102
|
+
- Go to the repository on GitHub
|
|
103
|
+
- Click "New Pull Request"
|
|
104
|
+
- Select your branch
|
|
105
|
+
- Fill out the PR description with:
|
|
106
|
+
- Description of changes
|
|
107
|
+
- Related issues (if any)
|
|
108
|
+
- Testing instructions
|
|
109
|
+
|
|
110
|
+
### Pull Request Guidelines
|
|
111
|
+
|
|
112
|
+
- Keep PRs focused on a single feature or fix
|
|
113
|
+
- Ensure all tests pass
|
|
114
|
+
- Update documentation if you're adding new features
|
|
115
|
+
- Write clear commit messages
|
|
116
|
+
- Reference any related issues
|
|
117
|
+
|
|
118
|
+
## Reporting Issues
|
|
119
|
+
|
|
120
|
+
When reporting issues, please include:
|
|
121
|
+
|
|
122
|
+
- Python version
|
|
123
|
+
- Package version
|
|
124
|
+
- Operating system and version
|
|
125
|
+
- Steps to reproduce
|
|
126
|
+
- Expected behavior
|
|
127
|
+
- Actual behavior
|
|
128
|
+
- Any relevant error messages or stack traces
|
|
129
|
+
|
|
130
|
+
## Code of Conduct
|
|
131
|
+
|
|
132
|
+
- Be respectful and considerate
|
|
133
|
+
- Welcome newcomers and help them learn
|
|
134
|
+
- Focus on constructive feedback
|
|
135
|
+
- Be open to feedback and suggestions
|
|
136
|
+
|
|
137
|
+
## Questions?
|
|
138
|
+
|
|
139
|
+
If you have questions about contributing, feel free to:
|
|
140
|
+
|
|
141
|
+
- Open an issue on GitHub
|
|
142
|
+
- Check existing issues and discussions
|
|
143
|
+
|
|
144
|
+
Thank you for contributing to `osc7577`!
|
osc7577-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Y. Siva Sai Krishna
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
osc7577-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: osc7577
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Tell the terminal how to resume your program, with OSC 7577 (Program Resume Protocol).
|
|
5
|
+
Project-URL: Homepage, https://github.com/ysskrishna/osc7577
|
|
6
|
+
Project-URL: Repository, https://github.com/ysskrishna/osc7577.git
|
|
7
|
+
Project-URL: Issues, https://github.com/ysskrishna/osc7577/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/ysskrishna/osc7577/blob/main/CHANGELOG.md
|
|
9
|
+
Author-email: "Y. Siva Sai Krishna" <sivasaikrishnassk@gmail.com>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: claude-code,cli,osc,osc7577,resume,session,terminal
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: POSIX
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Terminals
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# OSC 7577
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
[](https://www.python.org/downloads/)
|
|
32
|
+
[](https://github.com/ysskrishna/osc7577/blob/main/LICENSE)
|
|
33
|
+
[](https://github.com/ysskrishna/osc7577/actions/workflows/test.yml)
|
|
34
|
+
[](https://pypi.org/project/osc7577/)
|
|
35
|
+
[](https://pepy.tech/projects/osc7577)
|
|
36
|
+
[](https://ysskrishna.space)
|
|
37
|
+
[](https://context7.com/ysskrishna/osc7577)
|
|
38
|
+
[](https://deepwiki.com/ysskrishna/osc7577)
|
|
39
|
+
|
|
40
|
+
Tell the terminal how to bring your program back after it restarts, with OSC 7577.
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
- **Report and clear**: `report(argv, cwd=...)` and `clear()`, with the spec's `time` and token hash (`mac`)
|
|
45
|
+
- **Spec checks before sending**: relative paths, control characters, an empty first argument, and the 2048-byte and 64-element limits. A command that cannot be reported sends `clear`, so an older command is not resumed in its place
|
|
46
|
+
- **Token hygiene**: the token never appears in output, and `scrub_env()` drops `OSC7577_TOKEN` for child processes
|
|
47
|
+
- **Verifier**: `verify()` parses and checks a report the way a terminal must (ignored or rejected), for terminal authors and tests
|
|
48
|
+
- **CLI**: `osc7577 report`, `osc7577 clear`, `osc7577 wrap -- CMD`, and `osc7577 claude-hook`
|
|
49
|
+
- **Windows paths**: `C:\...`, `C:/...` and `\\server\share` count as absolute; `\code`, `/code`, `C:code` and `/C:/...` do not
|
|
50
|
+
- **Zero dependencies**: the library only uses the Python standard library
|
|
51
|
+
- **Spec examples as tests**: every published example in the spec is reproduced byte for byte
|
|
52
|
+
|
|
53
|
+
## Why OSC 7577?
|
|
54
|
+
|
|
55
|
+
When a terminal restarts, it can reopen its tabs and their directories, but not the programs that ran in them. A shell does not know that your REPL was open on session 42, or that an agent was in the middle of a conversation.
|
|
56
|
+
|
|
57
|
+
OSC 7577 lets the program tell the terminal the exact command that brings it back. The terminal hands each program a random token in `OSC7577_TOKEN`, and every report carries a hash of that token, so another program cannot register a command in your name. A terminal that does not know the sequence never sets the token, and this library then sends nothing.
|
|
58
|
+
|
|
59
|
+
Spec: [Program Resume Protocol, revision 0.6](https://www.superlogical.com/rex/docs/build/program-resume) (2026-12-01).
|
|
60
|
+
|
|
61
|
+
Sibling of [osc7501](https://github.com/ysskrishna/osc7501), which reports program status.
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install osc7577
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Usage Examples
|
|
70
|
+
|
|
71
|
+
### Report and clear
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import atexit
|
|
75
|
+
from osc7577 import clear, report, supported
|
|
76
|
+
|
|
77
|
+
if supported(): # the terminal set OSC7577_TOKEN
|
|
78
|
+
report(["myrepl", "--session", "/home/me/.local/state/myrepl/42.json"], cwd="/home/me/proj")
|
|
79
|
+
atexit.register(clear) # a normal quit should not be resumed
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The first argument must be an absolute path or a bare command name, and `cwd` must be an absolute path. A command that breaks a rule sends `clear` and raises `ReportError`.
|
|
83
|
+
|
|
84
|
+
`report()` and `clear()` write to `/dev/tty`. They return `True` only when bytes were written, and `False` when the terminal did not set the token.
|
|
85
|
+
|
|
86
|
+
### Child processes
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import subprocess
|
|
90
|
+
from osc7577 import scrub_env
|
|
91
|
+
|
|
92
|
+
subprocess.run(["git", "--version"], env=scrub_env(), check=True)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Start children with `env=scrub_env()` so they cannot see the token or report commands in your place.
|
|
96
|
+
|
|
97
|
+
### Wrap any command
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
osc7577 wrap -- ssh devbox
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`wrap` reports `osc7577 wrap ssh devbox` with the current directory, then runs the command without the token. `osc7577 report -- CMD` and `osc7577 clear` report for the parent shell.
|
|
104
|
+
|
|
105
|
+
### Claude Code
|
|
106
|
+
|
|
107
|
+
Until Claude Code reports OSC 7577 itself ([anthropics/claude-code#112408](https://github.com/anthropics/claude-code/issues/112408)), add a hook in `~/.claude/settings.json`:
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"hooks": {
|
|
112
|
+
"SessionStart": [{"hooks": [{"type": "command", "command": "osc7577 claude-hook"}]}],
|
|
113
|
+
"SessionEnd": [{"hooks": [{"type": "command", "command": "osc7577 claude-hook"}]}]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
On start, resume and clear it reports `claude --resume <session id>` with the session's directory, owned by the `claude` process and written to its tty (hook output is captured, so stdout would not reach the terminal). On a normal quit it clears the record. Other endings leave it, so the terminal can resume.
|
|
119
|
+
|
|
120
|
+
### Verify (terminal side)
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from osc7577 import Ignored, Rejected, encode, verify
|
|
124
|
+
|
|
125
|
+
token = "dummy-token-replace-me"
|
|
126
|
+
sequence = encode(token=token, pid=74877, argv=["lazygit"], cwd="/home/user/src/project")
|
|
127
|
+
|
|
128
|
+
try:
|
|
129
|
+
rep = verify(sequence, token) # checks mac first, then time (60 s window), then keys
|
|
130
|
+
print(rep.pid, rep.argv, rep.cwd)
|
|
131
|
+
except Ignored:
|
|
132
|
+
pass # no effect
|
|
133
|
+
except Rejected:
|
|
134
|
+
pass # remove this owner's records
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## API Reference
|
|
138
|
+
|
|
139
|
+
| Name | Description |
|
|
140
|
+
|------|-------------|
|
|
141
|
+
| `report(argv, *, cwd, pid, token, stream, tty_path, env) -> bool` | Write a resume report. Sends `clear` and raises `ReportError` when the command cannot be reported. |
|
|
142
|
+
| `clear(*, pid, token, stream, tty_path, env) -> bool` | Remove this program's record. Send it on a normal quit. |
|
|
143
|
+
| `supported(env=None) -> bool` | True when the terminal set `OSC7577_TOKEN`. |
|
|
144
|
+
| `scrub_env(env=None) -> dict` | A copy of the environment without `OSC7577_TOKEN`. |
|
|
145
|
+
| `encode(*, token, pid, argv, cwd, clear, time, terminator, strict_limits, windows) -> str` | Build one full sequence. Does not write. |
|
|
146
|
+
| `build_body(*, pid, argv, cwd, clear, time, windows) -> str` | The body without the final `:mac=` pair. |
|
|
147
|
+
| `compute_mac(body, token) -> str` | SHA-256 of `body:token` as 64 hex characters (not an HMAC). |
|
|
148
|
+
| `verify(data, token, *, now, window, implemented, windows) -> Report` | Check a report as a terminal must. Raises `Ignored` or `Rejected`. |
|
|
149
|
+
| `Report` | `pid`, `time`, `argv`, `cwd`, `clear`, `extra`. |
|
|
150
|
+
| `is_absolute(path, windows=None)`, `is_bare_command(name, windows=None)` | The spec's path rules. `windows` defaults to the running platform. |
|
|
151
|
+
| `ReportError`, `Ignored`, `Rejected` | Errors. `ReportError` is a `ValueError`. |
|
|
152
|
+
| `TOKEN_ENV` | `"OSC7577_TOKEN"`. |
|
|
153
|
+
|
|
154
|
+
## Learn More
|
|
155
|
+
|
|
156
|
+
- [Program Resume Protocol (OSC 7577)](https://www.superlogical.com/rex/docs/build/program-resume)
|
|
157
|
+
- [Rex](https://www.superlogical.com/rex)
|
|
158
|
+
- [osc7501](https://github.com/ysskrishna/osc7501), the Program Status Protocol for Python
|
|
159
|
+
|
|
160
|
+
## Acknowledgments
|
|
161
|
+
|
|
162
|
+
- [Superlogical](https://www.superlogical.com/rex), for the Rex terminal and the Program Resume Protocol
|
|
163
|
+
|
|
164
|
+
## Contributing
|
|
165
|
+
|
|
166
|
+
We welcome contributions! Please see our [Contributing Guide](https://github.com/ysskrishna/osc7577/blob/main/CONTRIBUTING.md) for details.
|
|
167
|
+
|
|
168
|
+
## Built and maintained by
|
|
169
|
+
|
|
170
|
+
OSC 7577 is built and maintained by:
|
|
171
|
+
|
|
172
|
+
| | Name | GitHub | Role |
|
|
173
|
+
|---|------|--------|------|
|
|
174
|
+
| <img src="https://github.com/ysskrishna.png?size=120" width="60" height="60" alt="Y. Siva Sai Krishna"> | **Y. Siva Sai Krishna** | [@ysskrishna](https://github.com/ysskrishna) | Creator |
|
|
175
|
+
|
|
176
|
+
## Changelog
|
|
177
|
+
|
|
178
|
+
See [CHANGELOG](CHANGELOG.md) for release history.
|
|
179
|
+
|
|
180
|
+
## Support
|
|
181
|
+
|
|
182
|
+
If you find this library helpful:
|
|
183
|
+
|
|
184
|
+
- ⭐ Star the repository
|
|
185
|
+
- 🐛 [Report issues](https://github.com/ysskrishna/osc7577/issues)
|
|
186
|
+
- 🔀 Submit pull requests
|
|
187
|
+
- 💝 [Sponsor on GitHub](https://github.com/sponsors/ysskrishna)
|
|
188
|
+
|
|
189
|
+
## License
|
|
190
|
+
|
|
191
|
+
MIT © [Y. Siva Sai Krishna](https://github.com/ysskrishna) - see [LICENSE](LICENSE) for details.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
<p align="left">
|
|
196
|
+
<a href="https://github.com/ysskrishna">Author's GitHub</a> •
|
|
197
|
+
<a href="https://linkedin.com/in/ysskrishna">Author's LinkedIn</a> •
|
|
198
|
+
<a href="https://ysskrishna.space">Author's site</a> •
|
|
199
|
+
<a href="https://pypi.org/project/osc7577/">Package on PyPI</a> •
|
|
200
|
+
<a href="https://github.com/ysskrishna/osc7577/issues">Report Issues</a>
|
|
201
|
+
</p>
|