codex-plus-patcher 0.1.0
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.
- package/LICENSE +198 -0
- package/README.md +121 -0
- package/package.json +33 -0
- package/src/cli.js +224 -0
- package/src/core/asar.js +90 -0
- package/src/core/patch-engine.js +219 -0
- package/src/core/plist.js +31 -0
- package/src/core/release.js +46 -0
- package/src/patches/26.616.41845-4198.js +262 -0
- package/src/patches/26.616.51431-4212.js +334 -0
- package/src/patches/index.js +8 -0
- package/src/plus/repositories.js +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
|
|
135
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
136
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
137
|
+
except as required for reasonable and customary use in describing the
|
|
138
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
139
|
+
|
|
140
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
141
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
142
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
143
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
144
|
+
implied, including, without limitation, any warranties or conditions
|
|
145
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
146
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
147
|
+
appropriateness of using or redistributing the Work and assume any
|
|
148
|
+
risks associated with Your exercise of permissions under this License.
|
|
149
|
+
|
|
150
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
151
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
152
|
+
unless required by applicable law (such as deliberate and grossly
|
|
153
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
154
|
+
liable to You for damages, including any direct, indirect, special,
|
|
155
|
+
incidental, or consequential damages of any character arising as a
|
|
156
|
+
result of this License or out of the use or inability to use the
|
|
157
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
158
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
159
|
+
other commercial damages or losses), even if such Contributor
|
|
160
|
+
has been advised of the possibility of such damages.
|
|
161
|
+
|
|
162
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
163
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
164
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
165
|
+
or other liability obligations and/or rights consistent with this
|
|
166
|
+
License. However, in accepting such obligations, You may act only
|
|
167
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
168
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
169
|
+
defend, and hold each Contributor harmless for any liability
|
|
170
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
171
|
+
of your accepting any such warranty or additional liability.
|
|
172
|
+
|
|
173
|
+
END OF TERMS AND CONDITIONS
|
|
174
|
+
|
|
175
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
176
|
+
|
|
177
|
+
To apply the Apache License to your work, attach the following
|
|
178
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
179
|
+
replaced with your own identifying information. (Don't include
|
|
180
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
181
|
+
comment syntax for the file format. We also recommend that a
|
|
182
|
+
file or class name and description of purpose be included on the
|
|
183
|
+
same "printed page" as the copyright notice for easier
|
|
184
|
+
identification within third-party archives.
|
|
185
|
+
|
|
186
|
+
Copyright [yyyy] [name of copyright owner]
|
|
187
|
+
|
|
188
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
189
|
+
you may not use this file except in compliance with the License.
|
|
190
|
+
You may obtain a copy of the License at
|
|
191
|
+
|
|
192
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
193
|
+
|
|
194
|
+
Unless required by applicable law or agreed to in writing, software
|
|
195
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
196
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
197
|
+
See the License for the specific language governing permissions and
|
|
198
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Codex Plus Patcher
|
|
2
|
+
|
|
3
|
+
`codex-plus-patcher` creates a local `Codex Plus.app` from an installed `Codex.app` by applying version-checked ASAR patch queues. It does not ship `Codex.app` or any OpenAI app binaries.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Codex Plus is an experimental local demonstrator for changes that can be layered onto an installed Codex desktop app without redistributing the app itself. The patcher is meant for technically curious users who want to inspect, test, or iterate on small binary patch sets against their own local copy.
|
|
8
|
+
|
|
9
|
+
The current built-in patches rename the copied app, add patch provenance to the About dialog, expose nested repositories in the Review pane, and add diagnostic detail for selected app-shell errors.
|
|
10
|
+
|
|
11
|
+
## How It Works
|
|
12
|
+
|
|
13
|
+
The patcher reads the installed `Codex.app`, verifies the exact Codex version, bundle version, and original `Contents/Resources/app.asar` SHA-256, then selects the matching patch queue. Unsupported app versions fail closed so a patch written for one bundle is not applied to a different bundle by accident.
|
|
14
|
+
|
|
15
|
+
When applying patches, the tool copies `Codex.app` to the target `Codex Plus.app`, rewrites selected packed ASAR files with ordered text transforms, updates bundle metadata such as the app name and identifier, refreshes Electron ASAR integrity metadata, and signs the copied app ad hoc. The source app is not modified.
|
|
16
|
+
|
|
17
|
+
## Disclaimer
|
|
18
|
+
|
|
19
|
+
**Disclaimer of Warranty and Limitation of Liability**
|
|
20
|
+
|
|
21
|
+
THIS SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. This is a modified, binary-patched demonstrator provided strictly for experimental or demonstration purposes.
|
|
22
|
+
|
|
23
|
+
The upstream developers, contributors, and maintainers assume NO responsibility or liability for any errors, malfunctions, data loss, or damages—including consequential or incidental damages—arising from the installation or use of this patched version. You use, test, or distribute this patched app at your sole and absolute risk.
|
|
24
|
+
|
|
25
|
+
The original authors and upstream suppliers are under no obligation to provide support, updates, fixes, or assistance with any issues, mess, or conflicts caused by this modified build.
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
Install the CLI:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install -g codex-plus-patcher
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Or run it without a global install:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npx codex-plus-patcher apply
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Show help:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
codex-plus-patcher
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Apply built-in patches with defaults:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
codex-plus-patcher apply
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
By default this reads `/Applications/Codex.app` and creates `~/Applications/Codex Plus.app`.
|
|
54
|
+
|
|
55
|
+
Validate the installed Codex version without copying or signing:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
codex-plus-patcher apply --dry-run
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Apply a local development patch queue:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
codex-plus-patcher apply --mode dev --patch-dir ./src/patches --target "./work/Codex Plus.app"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Apply patches from a GitHub release asset:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
codex-plus-patcher apply \
|
|
71
|
+
--mode release \
|
|
72
|
+
--github-repo OWNER/REPO
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Print the machine-readable result:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
codex-plus-patcher apply --dry-run --json
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
For local development of the CLI wrapper:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
npm link
|
|
85
|
+
codex-plus-patcher --help
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Patch Format
|
|
89
|
+
|
|
90
|
+
Patch queues export `patchSets` from `index.js`. Each patch set declares:
|
|
91
|
+
|
|
92
|
+
- exact Codex version, bundle version, and original `app.asar` SHA-256
|
|
93
|
+
- an ordered `patches` array with stable patch IDs
|
|
94
|
+
- optional bundle metadata updates for the copied app
|
|
95
|
+
- ordered file transforms applied to packed ASAR files
|
|
96
|
+
|
|
97
|
+
Unsupported app versions fail closed.
|
|
98
|
+
|
|
99
|
+
## Development
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm test
|
|
103
|
+
npm run check
|
|
104
|
+
npm pack --dry-run
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Business logic that can be tested outside Codex lives under `src/plus/`. The current nested repository TOML parser is shared by tests and the injected worker patch source.
|
|
108
|
+
|
|
109
|
+
## Porting Patches To A New Codex Version
|
|
110
|
+
|
|
111
|
+
1. Install the new `Codex.app`.
|
|
112
|
+
2. Record `CFBundleShortVersionString`, `CFBundleVersion`, and raw `Contents/Resources/app.asar` SHA-256.
|
|
113
|
+
3. Copy the closest existing patch set in `src/patches/`.
|
|
114
|
+
4. Update target chunk filenames and fail-closed anchor strings by inspecting the new ASAR.
|
|
115
|
+
5. Run `npm test`, `npm run check`, and a dry run.
|
|
116
|
+
6. Apply the patch to a copied app and verify `codesign --verify --deep --strict`.
|
|
117
|
+
7. Launch manually and validate Review pane nested repository behavior.
|
|
118
|
+
|
|
119
|
+
## Update Hook Direction
|
|
120
|
+
|
|
121
|
+
The update hook should be implemented as a separate patch in the queue. V1 should detect Codex update completion, check GitHub Releases for a matching patch bundle, and offer to repatch `Codex Plus.app`. Silent auto-apply should be avoided until patch availability and signing failures are handled reliably.
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "codex-plus-patcher",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Patch queue tool for building a local Codex Plus.app from an installed Codex.app.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/michaelw/codex-plus-patcher.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/michaelw/codex-plus-patcher/issues"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/michaelw/codex-plus-patcher#readme",
|
|
14
|
+
"bin": {
|
|
15
|
+
"codex-plus-patcher": "src/cli.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"src/",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "node --test",
|
|
24
|
+
"check": "node --check src/cli.js && node --check src/core/asar.js && node --check src/core/patch-engine.js && node --check src/core/plist.js && node --check src/core/release.js && node --check src/patches/index.js && node --check src/patches/26.616.41845-4198.js && node --check src/patches/26.616.51431-4212.js && node --check src/plus/repositories.js"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20"
|
|
28
|
+
},
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"ora": "^9.4.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/cli.js
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const os = require("node:os");
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
|
|
5
|
+
const { patchCodexApp } = require("./core/patch-engine");
|
|
6
|
+
const { resolveReleasePatchDirectory } = require("./core/release");
|
|
7
|
+
const { patchSets: builtInPatchSets } = require("./patches");
|
|
8
|
+
|
|
9
|
+
function expandPath(input) {
|
|
10
|
+
if (input === "~") return os.homedir();
|
|
11
|
+
if (input.startsWith("~/")) return path.join(os.homedir(), input.slice(2));
|
|
12
|
+
return input;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function parseArgs(argv) {
|
|
16
|
+
const args = {
|
|
17
|
+
command: argv.length === 0 ? "help" : "apply",
|
|
18
|
+
source: "/Applications/Codex.app",
|
|
19
|
+
target: path.join(os.homedir(), "Applications", "Codex Plus.app"),
|
|
20
|
+
mode: "builtin",
|
|
21
|
+
releaseAsset: "codex-plus-patches.tgz",
|
|
22
|
+
releaseTag: "latest",
|
|
23
|
+
dryRun: false,
|
|
24
|
+
json: false,
|
|
25
|
+
debug: false,
|
|
26
|
+
};
|
|
27
|
+
const rest = [...argv];
|
|
28
|
+
if (rest[0] && !rest[0].startsWith("--")) args.command = rest.shift();
|
|
29
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
30
|
+
const arg = rest[index];
|
|
31
|
+
const next = () => {
|
|
32
|
+
index += 1;
|
|
33
|
+
if (index >= rest.length) throw new Error(`Missing value for ${arg}`);
|
|
34
|
+
return rest[index];
|
|
35
|
+
};
|
|
36
|
+
if (arg === "--source") args.source = path.resolve(expandPath(next()));
|
|
37
|
+
else if (arg === "--target") args.target = path.resolve(expandPath(next()));
|
|
38
|
+
else if (arg === "--mode") args.mode = next();
|
|
39
|
+
else if (arg === "--patch-dir") args.patchDir = path.resolve(expandPath(next()));
|
|
40
|
+
else if (arg === "--github-repo") args.githubRepo = next();
|
|
41
|
+
else if (arg === "--release-tag") args.releaseTag = next();
|
|
42
|
+
else if (arg === "--release-asset") args.releaseAsset = next();
|
|
43
|
+
else if (arg === "--dry-run") args.dryRun = true;
|
|
44
|
+
else if (arg === "--debug") args.debug = true;
|
|
45
|
+
else if (arg === "--json" || arg === "--format=json") args.json = true;
|
|
46
|
+
else if (arg === "--format") {
|
|
47
|
+
const format = next();
|
|
48
|
+
if (format !== "json") throw new Error(`Unknown format: ${format}`);
|
|
49
|
+
args.json = true;
|
|
50
|
+
}
|
|
51
|
+
else if (arg === "--help" || arg === "-h") args.command = "help";
|
|
52
|
+
else throw new Error(`Unknown argument: ${arg}`);
|
|
53
|
+
}
|
|
54
|
+
return args;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function helpText() {
|
|
58
|
+
return `Usage:
|
|
59
|
+
codex-plus-patcher
|
|
60
|
+
codex-plus-patcher apply [options]
|
|
61
|
+
|
|
62
|
+
Options:
|
|
63
|
+
--source <path> Source Codex.app. Default: /Applications/Codex.app
|
|
64
|
+
--target <path> Target Codex Plus.app. Default: ~/Applications/Codex Plus.app
|
|
65
|
+
--mode <builtin|dev|release>
|
|
66
|
+
--patch-dir <path> Dev mode patch directory containing index.js
|
|
67
|
+
--github-repo <owner/repo>
|
|
68
|
+
--release-tag <tag> Release mode tag. Default: latest
|
|
69
|
+
--release-asset <name> Release mode asset. Default: codex-plus-patches.tgz
|
|
70
|
+
--dry-run Select and report the patch without copying/signing
|
|
71
|
+
--debug Print stack traces for CLI errors
|
|
72
|
+
--json Print the machine-readable result
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function printHelp() {
|
|
77
|
+
console.log(helpText());
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function loadPatchSets(args) {
|
|
81
|
+
if (args.mode === "builtin") return builtInPatchSets;
|
|
82
|
+
if (args.mode === "dev") {
|
|
83
|
+
if (!args.patchDir) throw new Error("--patch-dir is required in dev mode");
|
|
84
|
+
return requirePatchSetModule(args.patchDir).patchSets;
|
|
85
|
+
}
|
|
86
|
+
if (args.mode === "release") {
|
|
87
|
+
if (!args.githubRepo) throw new Error("--github-repo is required in release mode");
|
|
88
|
+
const patchDir = await resolveReleasePatchDirectory({
|
|
89
|
+
repo: args.githubRepo,
|
|
90
|
+
tag: args.releaseTag,
|
|
91
|
+
assetName: args.releaseAsset,
|
|
92
|
+
});
|
|
93
|
+
return requirePatchSetModule(patchDir).patchSets;
|
|
94
|
+
}
|
|
95
|
+
throw new Error(`Unknown mode: ${args.mode}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function requirePatchSetModule(patchDir) {
|
|
99
|
+
const candidates = [
|
|
100
|
+
path.join(patchDir, "index.js"),
|
|
101
|
+
path.join(patchDir, "src", "patches", "index.js"),
|
|
102
|
+
path.join(patchDir, "patches", "index.js"),
|
|
103
|
+
];
|
|
104
|
+
const found = candidates.find((candidate) => {
|
|
105
|
+
try {
|
|
106
|
+
return require("node:fs").statSync(candidate).isFile();
|
|
107
|
+
} catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
if (!found) throw new Error(`Could not find patch index in ${patchDir}`);
|
|
112
|
+
return require(found);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function formatResult(result) {
|
|
116
|
+
const lines = [
|
|
117
|
+
result.dryRun ? "Codex Plus dry run succeeded." : "Codex Plus app created.",
|
|
118
|
+
`Source: ${result.sourceApp}`,
|
|
119
|
+
`Target: ${result.targetApp}`,
|
|
120
|
+
`Patch set: ${result.patchSet}`,
|
|
121
|
+
`Patches: ${result.patches.join(", ")}`,
|
|
122
|
+
];
|
|
123
|
+
if (result.patchedAsarSha) lines.push(`Patched app.asar SHA-256: ${result.patchedAsarSha}`);
|
|
124
|
+
if (!result.dryRun) lines.push(`Open: open ${JSON.stringify(result.targetApp)}`);
|
|
125
|
+
return `${lines.join("\n")}\n`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function formatError(error, { debug = false } = {}) {
|
|
129
|
+
if (debug || process.env.CODEX_PLUS_PATCHER_DEBUG === "1") return error.stack || error.message || String(error);
|
|
130
|
+
return `Error: ${error.message || String(error)}`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function shouldShowApplyProgress(args, stream = process.stderr) {
|
|
134
|
+
return !args.dryRun && !args.json && Boolean(stream.isTTY);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function createApplyProgress(args, { stream = process.stderr, importOra = (specifier) => import(specifier) } = {}) {
|
|
138
|
+
if (!shouldShowApplyProgress(args, stream)) return null;
|
|
139
|
+
const { default: ora } = await importOra("ora");
|
|
140
|
+
const spinner = ora({
|
|
141
|
+
color: "cyan",
|
|
142
|
+
spinner: "dots",
|
|
143
|
+
stream,
|
|
144
|
+
});
|
|
145
|
+
let active = false;
|
|
146
|
+
|
|
147
|
+
const progress = ({ status = "start", step, total, label }) => {
|
|
148
|
+
const text = `[${step}/${total}] ${label}`;
|
|
149
|
+
if (status === "start") {
|
|
150
|
+
if (active) spinner.succeed();
|
|
151
|
+
spinner.text = text;
|
|
152
|
+
spinner.start();
|
|
153
|
+
active = true;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (!active) return;
|
|
157
|
+
if (status === "succeed") spinner.succeed(text);
|
|
158
|
+
else if (status === "fail") spinner.fail(text);
|
|
159
|
+
active = false;
|
|
160
|
+
};
|
|
161
|
+
progress.start = (text) => {
|
|
162
|
+
if (active) spinner.succeed();
|
|
163
|
+
spinner.text = text;
|
|
164
|
+
spinner.start();
|
|
165
|
+
active = true;
|
|
166
|
+
};
|
|
167
|
+
progress.succeed = (text) => {
|
|
168
|
+
if (!active) return;
|
|
169
|
+
spinner.succeed(text);
|
|
170
|
+
active = false;
|
|
171
|
+
};
|
|
172
|
+
progress.fail = () => {
|
|
173
|
+
if (!active) return;
|
|
174
|
+
spinner.fail();
|
|
175
|
+
active = false;
|
|
176
|
+
};
|
|
177
|
+
return progress;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function main() {
|
|
181
|
+
const args = parseArgs(process.argv.slice(2));
|
|
182
|
+
if (args.command === "help") {
|
|
183
|
+
printHelp();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (args.command !== "apply") throw new Error(`Unknown command: ${args.command}`);
|
|
187
|
+
|
|
188
|
+
const patchSets = await loadPatchSets(args);
|
|
189
|
+
const progress = await createApplyProgress(args);
|
|
190
|
+
let result;
|
|
191
|
+
try {
|
|
192
|
+
result = await patchCodexApp({
|
|
193
|
+
sourceApp: args.source,
|
|
194
|
+
targetApp: args.target,
|
|
195
|
+
patchSets,
|
|
196
|
+
dryRun: args.dryRun,
|
|
197
|
+
progress,
|
|
198
|
+
});
|
|
199
|
+
} catch (error) {
|
|
200
|
+
if (progress) progress.fail();
|
|
201
|
+
throw error;
|
|
202
|
+
}
|
|
203
|
+
process.stdout.write(args.json ? `${JSON.stringify(result, null, 2)}\n` : formatResult(result));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (require.main === module) {
|
|
207
|
+
main().catch((error) => {
|
|
208
|
+
const debug = process.argv.includes("--debug") || process.env.CODEX_PLUS_PATCHER_DEBUG === "1";
|
|
209
|
+
console.error(formatError(error, { debug }));
|
|
210
|
+
process.exitCode = 1;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
module.exports = {
|
|
215
|
+
createApplyProgress,
|
|
216
|
+
expandPath,
|
|
217
|
+
formatError,
|
|
218
|
+
formatResult,
|
|
219
|
+
helpText,
|
|
220
|
+
loadPatchSets,
|
|
221
|
+
parseArgs,
|
|
222
|
+
requirePatchSetModule,
|
|
223
|
+
shouldShowApplyProgress,
|
|
224
|
+
};
|
package/src/core/asar.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const crypto = require("node:crypto");
|
|
2
|
+
const fs = require("node:fs");
|
|
3
|
+
|
|
4
|
+
function sha256(buffer) {
|
|
5
|
+
return crypto.createHash("sha256").update(buffer).digest("hex");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function sha256File(file) {
|
|
9
|
+
return sha256(fs.readFileSync(file));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function readAsar(asarPath) {
|
|
13
|
+
const buffer = fs.readFileSync(asarPath);
|
|
14
|
+
const jsonSize = buffer.readUInt32LE(12);
|
|
15
|
+
const header = JSON.parse(buffer.subarray(16, 16 + jsonSize).toString("utf8"));
|
|
16
|
+
return { buffer, dataStart: 16 + jsonSize, header };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function walkFiles(node, prefix = "", out = []) {
|
|
20
|
+
if (!node.files) return out;
|
|
21
|
+
for (const [name, child] of Object.entries(node.files)) {
|
|
22
|
+
const next = prefix ? `${prefix}/${name}` : name;
|
|
23
|
+
if (child.files) walkFiles(child, next, out);
|
|
24
|
+
else out.push([next, child]);
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function fileIntegrity(buffer) {
|
|
30
|
+
const blockSize = 4 * 1024 * 1024;
|
|
31
|
+
const blocks = [];
|
|
32
|
+
for (let offset = 0; offset < buffer.length; offset += blockSize) {
|
|
33
|
+
blocks.push(sha256(buffer.subarray(offset, offset + blockSize)));
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
algorithm: "SHA256",
|
|
37
|
+
hash: sha256(buffer),
|
|
38
|
+
blockSize,
|
|
39
|
+
blocks,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function patchAsar(asarPath, fileTransforms, transformContext = {}) {
|
|
44
|
+
const archive = readAsar(asarPath);
|
|
45
|
+
const entries = walkFiles(archive.header);
|
|
46
|
+
const contents = new Map();
|
|
47
|
+
|
|
48
|
+
for (const [filePath, node] of entries) {
|
|
49
|
+
if (node.unpacked) continue;
|
|
50
|
+
const offset = archive.dataStart + Number(node.offset || 0);
|
|
51
|
+
contents.set(filePath, Buffer.from(archive.buffer.subarray(offset, offset + Number(node.size || 0))));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
for (const [filePath, transform] of fileTransforms) {
|
|
55
|
+
const original = contents.get(filePath);
|
|
56
|
+
if (!original) throw new Error(`Could not find ${filePath} in app.asar`);
|
|
57
|
+
const patched = transform(original.toString("utf8"), transformContext);
|
|
58
|
+
contents.set(filePath, Buffer.from(patched, "utf8"));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let dataOffset = 0;
|
|
62
|
+
const dataBuffers = [];
|
|
63
|
+
for (const [filePath, node] of entries) {
|
|
64
|
+
if (node.unpacked) continue;
|
|
65
|
+
const content = contents.get(filePath);
|
|
66
|
+
node.size = content.length;
|
|
67
|
+
node.offset = String(dataOffset);
|
|
68
|
+
node.integrity = fileIntegrity(content);
|
|
69
|
+
dataBuffers.push(content);
|
|
70
|
+
dataOffset += content.length;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const json = Buffer.from(JSON.stringify(archive.header), "utf8");
|
|
74
|
+
const header = Buffer.alloc(16);
|
|
75
|
+
header.writeUInt32LE(4, 0);
|
|
76
|
+
header.writeUInt32LE(json.length + 8, 4);
|
|
77
|
+
header.writeUInt32LE(json.length + 4, 8);
|
|
78
|
+
header.writeUInt32LE(json.length, 12);
|
|
79
|
+
|
|
80
|
+
fs.writeFileSync(asarPath, Buffer.concat([header, json, ...dataBuffers]));
|
|
81
|
+
return sha256File(asarPath);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = {
|
|
85
|
+
patchAsar,
|
|
86
|
+
readAsar,
|
|
87
|
+
sha256,
|
|
88
|
+
sha256File,
|
|
89
|
+
walkFiles,
|
|
90
|
+
};
|