codex-preserve 0.1.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.
Files changed (36) hide show
  1. codex_preserve-0.1.0/LICENSE +202 -0
  2. codex_preserve-0.1.0/MANIFEST.in +12 -0
  3. codex_preserve-0.1.0/PKG-INFO +241 -0
  4. codex_preserve-0.1.0/README.md +218 -0
  5. codex_preserve-0.1.0/examples/README.md +76 -0
  6. codex_preserve-0.1.0/examples/fail/ConversationExport.receipt.json +295 -0
  7. codex_preserve-0.1.0/examples/fail/package.manifest.json +47 -0
  8. codex_preserve-0.1.0/examples/fail//345/257/271/350/257/235/350/256/260/345/275/225.md +132 -0
  9. codex_preserve-0.1.0/examples/fail//350/276/223/345/207/272/346/226/207/344/273/266//350/276/223/345/207/272/347/264/242/345/274/225.md +5 -0
  10. codex_preserve-0.1.0/examples/pass/ConversationExport.receipt.json +295 -0
  11. codex_preserve-0.1.0/examples/pass/package.manifest.json +47 -0
  12. codex_preserve-0.1.0/examples/pass//345/257/271/350/257/235/350/256/260/345/275/225.md +132 -0
  13. codex_preserve-0.1.0/examples/pass//350/276/223/345/207/272/346/226/207/344/273/266//350/276/223/345/207/272/347/264/242/345/274/225.md +5 -0
  14. codex_preserve-0.1.0/examples/run_examples.sh +46 -0
  15. codex_preserve-0.1.0/examples/unverifiable/ConversationExport.receipt.json +295 -0
  16. codex_preserve-0.1.0/examples/unverifiable/package.manifest.json +47 -0
  17. codex_preserve-0.1.0/examples/unverifiable//345/257/271/350/257/235/350/256/260/345/275/225.md +132 -0
  18. codex_preserve-0.1.0/examples/unverifiable//350/276/223/345/207/272/346/226/207/344/273/266//350/276/223/345/207/272/347/264/242/345/274/225.md +5 -0
  19. codex_preserve-0.1.0/pyproject.toml +45 -0
  20. codex_preserve-0.1.0/setup.cfg +4 -0
  21. codex_preserve-0.1.0/src/codex_preserve/__init__.py +11 -0
  22. codex_preserve-0.1.0/src/codex_preserve/__main__.py +8 -0
  23. codex_preserve-0.1.0/src/codex_preserve/cli.py +103 -0
  24. codex_preserve-0.1.0/src/codex_preserve/exporter.py +6239 -0
  25. codex_preserve-0.1.0/src/codex_preserve/verify.py +502 -0
  26. codex_preserve-0.1.0/src/codex_preserve.egg-info/PKG-INFO +241 -0
  27. codex_preserve-0.1.0/src/codex_preserve.egg-info/SOURCES.txt +34 -0
  28. codex_preserve-0.1.0/src/codex_preserve.egg-info/dependency_links.txt +1 -0
  29. codex_preserve-0.1.0/src/codex_preserve.egg-info/entry_points.txt +2 -0
  30. codex_preserve-0.1.0/src/codex_preserve.egg-info/top_level.txt +1 -0
  31. codex_preserve-0.1.0/tests/__init__.py +1 -0
  32. codex_preserve-0.1.0/tests/test_cli_and_verify.py +897 -0
  33. codex_preserve-0.1.0/tests/test_codex_conversation_export.py +4002 -0
  34. codex_preserve-0.1.0/tests/test_examples.py +126 -0
  35. codex_preserve-0.1.0/tests/test_public_hygiene.py +295 -0
  36. codex_preserve-0.1.0/tools/public_hygiene_scan.py +306 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,12 @@
1
+ # The sdist is meant to be a source distribution you can actually verify:
2
+ # unpack it, run the test suite, run the hygiene scan, run the examples.
3
+ # Without these grafts setuptools ships a partial `tests/` directory whose
4
+ # fixtures, scanner and package marker are all missing, so the suite it
5
+ # carries cannot run at all.
6
+ graft tests
7
+ graft examples
8
+ graft tools
9
+
10
+ global-exclude *.py[cod]
11
+ global-exclude .DS_Store
12
+ prune **/__pycache__
@@ -0,0 +1,241 @@
1
+ Metadata-Version: 2.4
2
+ Name: codex-preserve
3
+ Version: 0.1.0
4
+ Summary: Export OpenAI Codex sessions to durable, human-readable packages and verify them against a manifest.
5
+ License-Expression: Apache-2.0
6
+ Keywords: codex,session,export,archive,provenance,integrity
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Environment :: Console
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3 :: Only
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Software Development :: Version Control
18
+ Classifier: Topic :: System :: Archiving
19
+ Requires-Python: >=3.9
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Dynamic: license-file
23
+
24
+ # codex-preserve
25
+
26
+ `codex-preserve` exports an OpenAI Codex session out of Codex into durable,
27
+ human-readable files, and verifies that every manifest-attested member is
28
+ present and byte-identical to the SHA-256 and size recorded in the manifest.
29
+ It reads a Codex session; it never modifies one.
30
+
31
+ > **This is not `codex archive`.** The built-in `codex archive` command changes
32
+ > a saved session's lifecycle state *inside* Codex. `codex-preserve` exports a
33
+ > durable copy *outside* Codex and verifies the exported package. It does not
34
+ > modify session state, and it is not a replacement for `codex archive`.
35
+
36
+ **Not affiliated with OpenAI.** `codex-preserve` is an independent, unofficial
37
+ tool. It is not affiliated with, endorsed by, sponsored by, or certified by
38
+ OpenAI, and it is not an OpenAI product or a first-party Codex component. It
39
+ ships no OpenAI logo or other visual branding. It is named for the Codex
40
+ sessions it reads.
41
+
42
+ ## What it does
43
+
44
+ - **Exports** one already-persisted local Codex rollout into a per-session
45
+ package: a readable conversation file, a machine receipt, input attachments
46
+ and output files, and a manifest.
47
+ - **Verifies** an exported package against that manifest: every attested
48
+ member must be present with the attested size and SHA-256. See
49
+ [What verification does and does not prove](#what-verification-does-and-does-not-prove).
50
+ - **Records provenance** for exported artifacts and attachments, including
51
+ which turn produced them and whether the payload is complete.
52
+ - **Normalizes and redacts** by default: home paths are normalized for
53
+ readability, and credential-shaped values are removed before anything is
54
+ written.
55
+ - **Fails closed.** What the tool cannot prove mechanically is reported as
56
+ unknown rather than guessed, and a package that cannot be verified is never
57
+ reported as intact.
58
+
59
+ ## What it does not do
60
+
61
+ - It does not modify, archive, unarchive, delete or move Codex sessions.
62
+ - It makes no model call and no network call. There is no daemon, no hook, no
63
+ telemetry and no event database. It does run local read-only `git` queries by
64
+ default — see [What it reads](#what-it-reads).
65
+ - It does not decode opaque or encrypted reasoning. Such items are counted,
66
+ never reconstructed.
67
+ - It does not sign anything. The manifest attests SHA-256 completeness and
68
+ integrity; that is not a cryptographic signature and says nothing about who
69
+ produced a package.
70
+
71
+ ## What verification does and does not prove
72
+
73
+ `codex-preserve verify` answers exactly one question: **is every member the
74
+ manifest attests present, and do its bytes still hash to the SHA-256 and size
75
+ the manifest records?**
76
+
77
+ That is worth having. It detects accidental loss, truncation, corruption in
78
+ transit or storage, and edits made to a payload without also rewriting the
79
+ manifest.
80
+
81
+ It is not tamper-proofing, and the following are outside the proof:
82
+
83
+ - **The manifest is co-distributed and is not independently signed.** It
84
+ travels inside the package it describes. There is no signature, no
85
+ certificate, no trust root and no transparency log, so the check is
86
+ *manifest-relative* integrity, not authenticity. It says nothing about who
87
+ produced the package.
88
+ - **A coordinated rewrite is not detected.** Anyone who edits a payload *and*
89
+ recomputes its manifest row produces a package that verifies. Detecting that
90
+ requires a trust anchor this tool does not have.
91
+ - **Extra files are not part of the current check.** Verification walks the
92
+ members the manifest lists. A file added to the package directory that the
93
+ manifest never mentions does not make verification fail, so "complete" means
94
+ "nothing attested is missing", not "nothing else is present".
95
+
96
+ If you need authenticity rather than integrity, sign the exported package with
97
+ a tool built for that. `codex-preserve` deliberately does not implement one.
98
+
99
+ ## What it reads
100
+
101
+ Export is local and read-only, but it is not limited to the one rollout file
102
+ you name. On a normal run it may also:
103
+
104
+ - **read `~/.codex/session_index.jsonl`**, read-only, to recover the session's
105
+ display name. The lookup is filtered by session id and returns silently if
106
+ the file is absent or unreadable. Nothing under `~/.codex` is ever written.
107
+ - **run local read-only `git` queries in the session's recorded workspace**
108
+ (`rev-parse`, `branch --show-current`, `remote get-url`, `merge-base`) to
109
+ record where the work happened. These are local repository queries; they
110
+ contact no network and no remote.
111
+ - **include a normalized repository identity such as `owner/repo`** in the
112
+ exported provenance, in the receipt and in the human-readable file.
113
+ The raw remote URL is discarded and never exported — but if you share an
114
+ export, the `owner/repo` name goes with it.
115
+
116
+ Pass `--no-git-probe` to skip the live git queries entirely. That is the
117
+ entire scope of the flag: it stops the export from *asking* the local
118
+ repository anything. It does not erase repository identity that is already
119
+ persisted in the rollout's own session metadata. A persisted identity is
120
+ still normalized to `owner/repo` and may appear in the receipt, in the
121
+ human-readable export, in the stable output basename, and in the output
122
+ directory / bucket names. The raw remote URL is discarded and never
123
+ exported, with or without the flag.
124
+
125
+ ## Install
126
+
127
+ ```bash
128
+ pip install .
129
+ ```
130
+
131
+ Python 3.9 or newer. No runtime dependencies.
132
+
133
+ ## Try it in one command
134
+
135
+ You do not need a Codex session to see what this tool does. Three synthetic
136
+ example packages ship with the repository and exercise the entire
137
+ verification contract:
138
+
139
+ ```bash
140
+ ./examples/run_examples.sh
141
+ ```
142
+
143
+ That prints one `PASS`, one `FAIL` and one `UNVERIFIABLE` verdict and checks
144
+ that each exits `0`, `1` and `2` respectively. See
145
+ [examples/README.md](examples/README.md) for what each one demonstrates and
146
+ why. The same three packages are asserted by the test suite, so they stay
147
+ honest.
148
+
149
+ ## Use
150
+
151
+ ```bash
152
+ # See the surfaces.
153
+ codex-preserve --help
154
+
155
+ # List the sessions that could be exported (sanitized output).
156
+ codex-preserve --list-candidates
157
+
158
+ # Export one session by id.
159
+ codex-preserve --session-id <uuid> --output-dir ./exports
160
+
161
+ # The same export surface, named explicitly.
162
+ codex-preserve export --session-id <uuid> --output-dir ./exports
163
+
164
+ # Verify an exported package.
165
+ codex-preserve verify ./exports/<bucket>/<package-dir>
166
+
167
+ # Machine-readable verification receipt.
168
+ codex-preserve verify ./exports/<bucket>/<package-dir> --json
169
+ ```
170
+
171
+ `codex-preserve export --help` lists the full export option set, including
172
+ selection (`--rollout`, `--session-id`, `--workspace`, `--since-hours`),
173
+ provenance (`--artifact ROLE=PATH`, `--review-bundle`, `--no-git-probe`) and
174
+ policy (`--no-normalize`, `--reasoning-cap`, `--max-package-bytes`).
175
+
176
+ Sessions are discovered under `~/.codex/sessions` and
177
+ `~/.codex/archived_sessions` only. The home directory is never scanned
178
+ broadly.
179
+
180
+ ### Verify exit codes
181
+
182
+ | exit | meaning |
183
+ | ---- | ------- |
184
+ | `0` | every manifest-attested member is present and matches |
185
+ | `1` | a manifest-attested member is missing or altered |
186
+ | `2` | the package could not be verified at all — fails closed |
187
+
188
+ The reason is always printed. `--json` emits the same verdict as a receipt
189
+ with per-member reason codes.
190
+
191
+ Manifest-attested package members must be real files under the package tree;
192
+ symlinked member paths are rejected.
193
+
194
+ Exit 2 also covers a manifest this build cannot interpret: an unrecognized or
195
+ missing `package_schema_version`, or a manifest collection or row whose shape
196
+ is not the expected JSON array/object. A verifier that cannot read the
197
+ manifest reports UNVERIFIABLE rather than claiming the members it never looked
198
+ at are fine.
199
+
200
+ ## Development
201
+
202
+ ```bash
203
+ PYTHONPATH=src python3 -m unittest discover -t . -s tests
204
+ python3 tools/public_hygiene_scan.py .
205
+ ./examples/run_examples.sh
206
+ ```
207
+
208
+ The test suite is deterministic and entirely synthetic: it builds its own
209
+ rollout fixtures in a temporary directory and never reads a real Codex session
210
+ directory.
211
+
212
+ `tools/public_hygiene_scan.py` is a deterministic check that no private
213
+ coordinate or credential-shaped literal has entered the tree.
214
+
215
+ ## Localization
216
+
217
+ Package member filenames and the default output directory are currently
218
+ Simplified Chinese, because they are part of the already-proven package format
219
+ this tool exports. Changing them is a package-format decision rather than a
220
+ cosmetic one, and it is still open. Everything else — the CLI, the receipts,
221
+ the manifest keys and this documentation — is English.
222
+
223
+ ## License
224
+
225
+ Apache License 2.0. See [LICENSE](LICENSE) for the full text.
226
+
227
+ ```text
228
+ SPDX-License-Identifier: Apache-2.0
229
+ ```
230
+
231
+ ## Status
232
+
233
+ Version 0.1.0, first public release line. The export/verify contract
234
+ described above — the three verdicts, the exit codes, and the limits of what
235
+ the manifest proves — is what this version commits to. Package member
236
+ filenames are still an open question; see [Localization](#localization).
237
+
238
+ **Not affiliated with OpenAI.** `codex-preserve` is an independent, unofficial
239
+ tool. It is not affiliated with, endorsed by, sponsored by, or certified by
240
+ OpenAI, and it is not an OpenAI product or a first-party Codex component. It
241
+ ships no OpenAI logo or other visual branding.
@@ -0,0 +1,218 @@
1
+ # codex-preserve
2
+
3
+ `codex-preserve` exports an OpenAI Codex session out of Codex into durable,
4
+ human-readable files, and verifies that every manifest-attested member is
5
+ present and byte-identical to the SHA-256 and size recorded in the manifest.
6
+ It reads a Codex session; it never modifies one.
7
+
8
+ > **This is not `codex archive`.** The built-in `codex archive` command changes
9
+ > a saved session's lifecycle state *inside* Codex. `codex-preserve` exports a
10
+ > durable copy *outside* Codex and verifies the exported package. It does not
11
+ > modify session state, and it is not a replacement for `codex archive`.
12
+
13
+ **Not affiliated with OpenAI.** `codex-preserve` is an independent, unofficial
14
+ tool. It is not affiliated with, endorsed by, sponsored by, or certified by
15
+ OpenAI, and it is not an OpenAI product or a first-party Codex component. It
16
+ ships no OpenAI logo or other visual branding. It is named for the Codex
17
+ sessions it reads.
18
+
19
+ ## What it does
20
+
21
+ - **Exports** one already-persisted local Codex rollout into a per-session
22
+ package: a readable conversation file, a machine receipt, input attachments
23
+ and output files, and a manifest.
24
+ - **Verifies** an exported package against that manifest: every attested
25
+ member must be present with the attested size and SHA-256. See
26
+ [What verification does and does not prove](#what-verification-does-and-does-not-prove).
27
+ - **Records provenance** for exported artifacts and attachments, including
28
+ which turn produced them and whether the payload is complete.
29
+ - **Normalizes and redacts** by default: home paths are normalized for
30
+ readability, and credential-shaped values are removed before anything is
31
+ written.
32
+ - **Fails closed.** What the tool cannot prove mechanically is reported as
33
+ unknown rather than guessed, and a package that cannot be verified is never
34
+ reported as intact.
35
+
36
+ ## What it does not do
37
+
38
+ - It does not modify, archive, unarchive, delete or move Codex sessions.
39
+ - It makes no model call and no network call. There is no daemon, no hook, no
40
+ telemetry and no event database. It does run local read-only `git` queries by
41
+ default — see [What it reads](#what-it-reads).
42
+ - It does not decode opaque or encrypted reasoning. Such items are counted,
43
+ never reconstructed.
44
+ - It does not sign anything. The manifest attests SHA-256 completeness and
45
+ integrity; that is not a cryptographic signature and says nothing about who
46
+ produced a package.
47
+
48
+ ## What verification does and does not prove
49
+
50
+ `codex-preserve verify` answers exactly one question: **is every member the
51
+ manifest attests present, and do its bytes still hash to the SHA-256 and size
52
+ the manifest records?**
53
+
54
+ That is worth having. It detects accidental loss, truncation, corruption in
55
+ transit or storage, and edits made to a payload without also rewriting the
56
+ manifest.
57
+
58
+ It is not tamper-proofing, and the following are outside the proof:
59
+
60
+ - **The manifest is co-distributed and is not independently signed.** It
61
+ travels inside the package it describes. There is no signature, no
62
+ certificate, no trust root and no transparency log, so the check is
63
+ *manifest-relative* integrity, not authenticity. It says nothing about who
64
+ produced the package.
65
+ - **A coordinated rewrite is not detected.** Anyone who edits a payload *and*
66
+ recomputes its manifest row produces a package that verifies. Detecting that
67
+ requires a trust anchor this tool does not have.
68
+ - **Extra files are not part of the current check.** Verification walks the
69
+ members the manifest lists. A file added to the package directory that the
70
+ manifest never mentions does not make verification fail, so "complete" means
71
+ "nothing attested is missing", not "nothing else is present".
72
+
73
+ If you need authenticity rather than integrity, sign the exported package with
74
+ a tool built for that. `codex-preserve` deliberately does not implement one.
75
+
76
+ ## What it reads
77
+
78
+ Export is local and read-only, but it is not limited to the one rollout file
79
+ you name. On a normal run it may also:
80
+
81
+ - **read `~/.codex/session_index.jsonl`**, read-only, to recover the session's
82
+ display name. The lookup is filtered by session id and returns silently if
83
+ the file is absent or unreadable. Nothing under `~/.codex` is ever written.
84
+ - **run local read-only `git` queries in the session's recorded workspace**
85
+ (`rev-parse`, `branch --show-current`, `remote get-url`, `merge-base`) to
86
+ record where the work happened. These are local repository queries; they
87
+ contact no network and no remote.
88
+ - **include a normalized repository identity such as `owner/repo`** in the
89
+ exported provenance, in the receipt and in the human-readable file.
90
+ The raw remote URL is discarded and never exported — but if you share an
91
+ export, the `owner/repo` name goes with it.
92
+
93
+ Pass `--no-git-probe` to skip the live git queries entirely. That is the
94
+ entire scope of the flag: it stops the export from *asking* the local
95
+ repository anything. It does not erase repository identity that is already
96
+ persisted in the rollout's own session metadata. A persisted identity is
97
+ still normalized to `owner/repo` and may appear in the receipt, in the
98
+ human-readable export, in the stable output basename, and in the output
99
+ directory / bucket names. The raw remote URL is discarded and never
100
+ exported, with or without the flag.
101
+
102
+ ## Install
103
+
104
+ ```bash
105
+ pip install .
106
+ ```
107
+
108
+ Python 3.9 or newer. No runtime dependencies.
109
+
110
+ ## Try it in one command
111
+
112
+ You do not need a Codex session to see what this tool does. Three synthetic
113
+ example packages ship with the repository and exercise the entire
114
+ verification contract:
115
+
116
+ ```bash
117
+ ./examples/run_examples.sh
118
+ ```
119
+
120
+ That prints one `PASS`, one `FAIL` and one `UNVERIFIABLE` verdict and checks
121
+ that each exits `0`, `1` and `2` respectively. See
122
+ [examples/README.md](examples/README.md) for what each one demonstrates and
123
+ why. The same three packages are asserted by the test suite, so they stay
124
+ honest.
125
+
126
+ ## Use
127
+
128
+ ```bash
129
+ # See the surfaces.
130
+ codex-preserve --help
131
+
132
+ # List the sessions that could be exported (sanitized output).
133
+ codex-preserve --list-candidates
134
+
135
+ # Export one session by id.
136
+ codex-preserve --session-id <uuid> --output-dir ./exports
137
+
138
+ # The same export surface, named explicitly.
139
+ codex-preserve export --session-id <uuid> --output-dir ./exports
140
+
141
+ # Verify an exported package.
142
+ codex-preserve verify ./exports/<bucket>/<package-dir>
143
+
144
+ # Machine-readable verification receipt.
145
+ codex-preserve verify ./exports/<bucket>/<package-dir> --json
146
+ ```
147
+
148
+ `codex-preserve export --help` lists the full export option set, including
149
+ selection (`--rollout`, `--session-id`, `--workspace`, `--since-hours`),
150
+ provenance (`--artifact ROLE=PATH`, `--review-bundle`, `--no-git-probe`) and
151
+ policy (`--no-normalize`, `--reasoning-cap`, `--max-package-bytes`).
152
+
153
+ Sessions are discovered under `~/.codex/sessions` and
154
+ `~/.codex/archived_sessions` only. The home directory is never scanned
155
+ broadly.
156
+
157
+ ### Verify exit codes
158
+
159
+ | exit | meaning |
160
+ | ---- | ------- |
161
+ | `0` | every manifest-attested member is present and matches |
162
+ | `1` | a manifest-attested member is missing or altered |
163
+ | `2` | the package could not be verified at all — fails closed |
164
+
165
+ The reason is always printed. `--json` emits the same verdict as a receipt
166
+ with per-member reason codes.
167
+
168
+ Manifest-attested package members must be real files under the package tree;
169
+ symlinked member paths are rejected.
170
+
171
+ Exit 2 also covers a manifest this build cannot interpret: an unrecognized or
172
+ missing `package_schema_version`, or a manifest collection or row whose shape
173
+ is not the expected JSON array/object. A verifier that cannot read the
174
+ manifest reports UNVERIFIABLE rather than claiming the members it never looked
175
+ at are fine.
176
+
177
+ ## Development
178
+
179
+ ```bash
180
+ PYTHONPATH=src python3 -m unittest discover -t . -s tests
181
+ python3 tools/public_hygiene_scan.py .
182
+ ./examples/run_examples.sh
183
+ ```
184
+
185
+ The test suite is deterministic and entirely synthetic: it builds its own
186
+ rollout fixtures in a temporary directory and never reads a real Codex session
187
+ directory.
188
+
189
+ `tools/public_hygiene_scan.py` is a deterministic check that no private
190
+ coordinate or credential-shaped literal has entered the tree.
191
+
192
+ ## Localization
193
+
194
+ Package member filenames and the default output directory are currently
195
+ Simplified Chinese, because they are part of the already-proven package format
196
+ this tool exports. Changing them is a package-format decision rather than a
197
+ cosmetic one, and it is still open. Everything else — the CLI, the receipts,
198
+ the manifest keys and this documentation — is English.
199
+
200
+ ## License
201
+
202
+ Apache License 2.0. See [LICENSE](LICENSE) for the full text.
203
+
204
+ ```text
205
+ SPDX-License-Identifier: Apache-2.0
206
+ ```
207
+
208
+ ## Status
209
+
210
+ Version 0.1.0, first public release line. The export/verify contract
211
+ described above — the three verdicts, the exit codes, and the limits of what
212
+ the manifest proves — is what this version commits to. Package member
213
+ filenames are still an open question; see [Localization](#localization).
214
+
215
+ **Not affiliated with OpenAI.** `codex-preserve` is an independent, unofficial
216
+ tool. It is not affiliated with, endorsed by, sponsored by, or certified by
217
+ OpenAI, and it is not an OpenAI product or a first-party Codex component. It
218
+ ships no OpenAI logo or other visual branding.