codex-overleaf-link 1.9.1 → 1.9.3
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/README.md +30 -30
- package/extension/bootstrap/background.js +23 -8
- package/extension/bootstrap/manifest.template.json +1 -1
- package/extension/bootstrap/popup.html +1 -0
- package/extension/bootstrap/popup.js +5 -1
- package/extension/bootstrap/updateStatus.js +78 -0
- package/extension/src/shared/compatibility.js +1 -1
- package/native-host/src/codexSessionRunner.js +52 -9
- package/native-host/src/mirrorWorkspace.js +45 -0
- package/native-host/src/updateManager.js +64 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<h1>Codex Overleaf Link</h1>
|
|
4
4
|
<p><strong>Empower Overleaf with Codex.</strong></p>
|
|
5
5
|
<p>
|
|
6
|
-
<img src="https://img.shields.io/badge/version-1.9.
|
|
6
|
+
<img src="https://img.shields.io/badge/version-1.9.3-blue" alt="version">
|
|
7
7
|
<img src="https://img.shields.io/badge/platform-macOS%20%2F%20Windows%20%2F%20Linux-lightgrey" alt="platform">
|
|
8
8
|
<img src="https://img.shields.io/badge/chrome-MV3-green" alt="chrome manifest v3">
|
|
9
9
|
<img src="https://img.shields.io/badge/node-%3E%3D20-brightgreen" alt="node version">
|
|
@@ -33,33 +33,33 @@ Either way, the final **Load unpacked** click is manual — Chrome does not let
|
|
|
33
33
|
|
|
34
34
|
### Option A — installer script (recommended)
|
|
35
35
|
|
|
36
|
-
One command installs the native host **and**
|
|
36
|
+
One command installs the managed native host **and** managed extension runtime. On macOS/Linux it also creates the visible `~/Codex Overleaf Link Extension` shortcut pointing to the managed extension, copies that path to your clipboard, and opens `chrome://extensions` for you. Future signed stable updates target this same managed directory.
|
|
37
37
|
|
|
38
38
|
macOS / Linux:
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
|
-
CODEX_OVERLEAF_REF=v1.9.
|
|
41
|
+
CODEX_OVERLEAF_REF=v1.9.3 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.3/install.sh)"
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Windows PowerShell:
|
|
45
45
|
|
|
46
46
|
```powershell
|
|
47
|
-
iwr https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.
|
|
48
|
-
$env:CODEX_OVERLEAF_REF='v1.9.
|
|
47
|
+
iwr https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.3/install.ps1 -OutFile install.ps1
|
|
48
|
+
$env:CODEX_OVERLEAF_REF='v1.9.3'
|
|
49
49
|
powershell -ExecutionPolicy Bypass -File install.ps1
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
Then, in the `chrome://extensions` tab the script opened: enable **Developer mode**, click **Load unpacked**, and choose the prepared extension folder (its path is already on your clipboard). That is the only manual step.
|
|
53
53
|
|
|
54
|
-
### Option B — npm
|
|
54
|
+
### Option B — npm managed install
|
|
55
55
|
|
|
56
|
-
`npm exec` installs
|
|
56
|
+
`npm exec` installs the same managed native host and extension runtime without keeping a source checkout. Use it if you prefer a pinned npm package.
|
|
57
57
|
|
|
58
58
|
```bash
|
|
59
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
59
|
+
npm exec --yes codex-overleaf-link@1.9.3 -- install-managed
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
Then
|
|
62
|
+
Then, in `chrome://extensions`, enable **Developer mode**, click **Load unpacked**, and select the managed extension path printed by the command. The Release extension zip remains available for explicitly unmanaged/manual installations.
|
|
63
63
|
|
|
64
64
|
### Open Overleaf
|
|
65
65
|
|
|
@@ -80,31 +80,31 @@ Then load `extension/` as an unpacked extension in Chrome. If Chrome assigns a d
|
|
|
80
80
|
|
|
81
81
|
</details>
|
|
82
82
|
|
|
83
|
-
## npm
|
|
83
|
+
## npm Managed CLI
|
|
84
84
|
|
|
85
|
-
npm installs, updates,
|
|
85
|
+
npm installs, updates, and uninstalls the coordinated managed extension/native pair. Diagnostics still target the native host. The legacy `install-native` command remains available only for explicitly unmanaged extension directories.
|
|
86
86
|
|
|
87
87
|
| Action | Command |
|
|
88
88
|
|--------|---------|
|
|
89
|
-
| Install / update | `npm exec --yes codex-overleaf-link@1.9.
|
|
90
|
-
| Diagnose | `npm exec --yes codex-overleaf-link@1.9.
|
|
91
|
-
| Uninstall | `npm exec --yes codex-overleaf-link@1.9.
|
|
89
|
+
| Install / update | `npm exec --yes codex-overleaf-link@1.9.3 -- install-managed` |
|
|
90
|
+
| Diagnose | `npm exec --yes codex-overleaf-link@1.9.3 -- doctor` |
|
|
91
|
+
| Uninstall | `npm exec --yes codex-overleaf-link@1.9.3 -- uninstall-managed` |
|
|
92
92
|
|
|
93
93
|
Use `--extension-id <chrome-extension-id>` only for a custom/dev unpacked extension id that differs from the official bundled id.
|
|
94
94
|
|
|
95
95
|
## Update
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
Managed installations discover signed stable updates automatically and apply them only while all Overleaf tabs and the native host are idle. Re-run `install-managed` only for recovery or migration, including when the panel reports **Native host update required**. Explicitly unmanaged installations still require a manual extension/native update. After recovery, reload the extension in `chrome://extensions` and refresh Overleaf.
|
|
98
98
|
|
|
99
99
|
## GitHub Release Artifacts
|
|
100
100
|
|
|
101
|
-
The v1.9.
|
|
101
|
+
The v1.9.3 GitHub Release contains:
|
|
102
102
|
|
|
103
|
-
- `codex-overleaf-link-extension-v1.9.
|
|
104
|
-
- `codex-overleaf-native-host-v1.9.
|
|
105
|
-
- `codex-overleaf-link-1.9.
|
|
106
|
-
- `install.sh`: release-pinned macOS / Linux installer that defaults to `v1.9.
|
|
107
|
-
- `install.ps1`: release-pinned Windows PowerShell installer that defaults to `v1.9.
|
|
103
|
+
- `codex-overleaf-link-extension-v1.9.3.zip`: loadable Chrome extension package for manual unpacked installation.
|
|
104
|
+
- `codex-overleaf-native-host-v1.9.3.tar.gz`: native host runtime files used by the installer and release verification.
|
|
105
|
+
- `codex-overleaf-link-1.9.3.tgz`: npm native host CLI package for pinned install, doctor, and uninstall flows.
|
|
106
|
+
- `install.sh`: release-pinned macOS / Linux installer that defaults to `v1.9.3` when run directly from the release artifact.
|
|
107
|
+
- `install.ps1`: release-pinned Windows PowerShell installer that defaults to `v1.9.3` when run directly from the release artifact.
|
|
108
108
|
- `uninstall-native-host.mjs`: native host uninstaller that removes the Chrome Native Messaging manifest, bridge executable, and runtime copy.
|
|
109
109
|
- `nativeHostPlatform.js`, `manifest.js`, `runtimeInstaller.js`: helper files required by the loose uninstaller asset.
|
|
110
110
|
- `SHA256SUMS` and `release-manifest.json`: checksum and artifact metadata for release verification.
|
|
@@ -115,7 +115,7 @@ The v1.9.1 GitHub Release contains:
|
|
|
115
115
|
Remove the native host (use `--browser chromium` on Linux Chromium):
|
|
116
116
|
|
|
117
117
|
```bash
|
|
118
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
118
|
+
npm exec --yes codex-overleaf-link@1.9.3 -- uninstall-managed
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
The same command works on Windows PowerShell. If you installed from a manual checkout or source installer, you can also run `npm run uninstall:native` inside the repo, use `node ~/.codex-overleaf/source/scripts/uninstall-native-host.mjs` on macOS / Linux, or use `node $env:LOCALAPPDATA\CodexOverleaf\source\scripts\uninstall-native-host.mjs` on Windows PowerShell.
|
|
@@ -150,13 +150,13 @@ Then remove the extension from `chrome://extensions`. To delete local data: on m
|
|
|
150
150
|
Linux Chromium install or update:
|
|
151
151
|
|
|
152
152
|
```bash
|
|
153
|
-
CODEX_OVERLEAF_REF=v1.9.
|
|
153
|
+
CODEX_OVERLEAF_REF=v1.9.3 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.3/install.sh)" -- --browser chromium
|
|
154
154
|
```
|
|
155
155
|
|
|
156
156
|
Linux Chromium uninstall:
|
|
157
157
|
|
|
158
158
|
```bash
|
|
159
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
159
|
+
npm exec --yes codex-overleaf-link@1.9.3 -- uninstall-managed --browser chromium
|
|
160
160
|
```
|
|
161
161
|
|
|
162
162
|
## Features
|
|
@@ -291,7 +291,7 @@ Composer attachments are turn-scoped Codex context. Limits are 8 attachments per
|
|
|
291
291
|
Re-run any [native host installer](#install), reload the extension in `chrome://extensions`, then refresh the Overleaf tab. This also fixes extension/native version mismatch and native protocol mismatch.
|
|
292
292
|
|
|
293
293
|
```bash
|
|
294
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
294
|
+
npm exec --yes codex-overleaf-link@1.9.3 -- install-managed
|
|
295
295
|
```
|
|
296
296
|
|
|
297
297
|
**The Windows popup or panel shows a Bash recovery command**
|
|
@@ -340,8 +340,8 @@ Use this matrix for release-candidate signoff and compatibility reports. Record
|
|
|
340
340
|
| Browser/channel/version | Google Chrome channel and version. | Google Chrome channel and version. | Google Chrome channel and version. | Chromium channel/package and version. |
|
|
341
341
|
| Install mode | Manual unpacked extension from GitHub Release zip or checkout. | Manual unpacked extension from GitHub Release zip or checkout. | Manual unpacked extension from GitHub Release zip or checkout. | Manual unpacked extension from GitHub Release zip or checkout; native host installed with `--browser chromium`. |
|
|
342
342
|
| Extension id | Bundled id `illdpneeeopfffmiepaejglgmhpmdhdc`, or actual custom id passed with `--extension-id`. | Bundled id `illdpneeeopfffmiepaejglgmhpmdhdc`, or actual custom id passed with `--extension-id`. | Bundled id `illdpneeeopfffmiepaejglgmhpmdhdc`, or actual custom id passed with `--extension-id`. | Bundled id `illdpneeeopfffmiepaejglgmhpmdhdc`, or actual custom id passed with `--extension-id`. |
|
|
343
|
-
| Installer/update command | `npm exec --yes codex-overleaf-link@1.9.
|
|
344
|
-
| Uninstall command | `npm exec --yes codex-overleaf-link@1.9.
|
|
343
|
+
| Installer/update command | `npm exec --yes codex-overleaf-link@1.9.3 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.3 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.3 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.3 -- install-managed --browser chromium` |
|
|
344
|
+
| Uninstall command | `npm exec --yes codex-overleaf-link@1.9.3 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.3 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.3 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.3 -- uninstall-managed --browser chromium` |
|
|
345
345
|
| Manifest/registry path | `~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.codex.overleaf.json` | `HKCU\Software\Google\Chrome\NativeMessagingHosts\com.codex.overleaf` -> `%LOCALAPPDATA%\CodexOverleaf\native-host-runtime\com.codex.overleaf.json` | `~/.config/google-chrome/NativeMessagingHosts/com.codex.overleaf.json` | `~/.config/chromium/NativeMessagingHosts/com.codex.overleaf.json` |
|
|
346
346
|
| Bridge/runtime/source path | Bridge `~/.codex-overleaf/codex-overleaf-bridge`; runtime `~/.codex-overleaf/native-host-runtime`; source `~/.codex-overleaf/source`. | Bridge `%LOCALAPPDATA%\CodexOverleaf\codex-overleaf-bridge.cmd`; runtime `%LOCALAPPDATA%\CodexOverleaf\native-host-runtime`; source `%LOCALAPPDATA%\CodexOverleaf\source`. | Bridge `~/.codex-overleaf/codex-overleaf-bridge`; runtime `~/.codex-overleaf/native-host-runtime`; source `~/.codex-overleaf/source`. | Bridge `~/.codex-overleaf/codex-overleaf-bridge`; runtime `~/.codex-overleaf/native-host-runtime`; source `~/.codex-overleaf/source`. |
|
|
347
347
|
| Node/Git/Codex/TeX | Node.js >= 20; Git; Codex CLI installed and logged in; TeX optional. | Node.js >= 20; Git; Codex CLI installed and logged in; TeX optional. | Node.js >= 20; Git; Codex CLI installed and logged in; TeX optional. | Node.js >= 20; Git; Codex CLI installed and logged in; TeX optional. |
|
|
@@ -377,7 +377,7 @@ Contributions are welcome. Please open an issue before submitting large changes
|
|
|
377
377
|
The recommended v1.9 installation owns one stable unpacked-extension directory and a versioned native-host directory:
|
|
378
378
|
|
|
379
379
|
```bash
|
|
380
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
380
|
+
npm exec --yes codex-overleaf-link@1.9.3 -- install-managed
|
|
381
381
|
```
|
|
382
382
|
|
|
383
383
|
Load the printed extension path once from `chrome://extensions`. Starting with the next signed stable release, Codex Overleaf Link checks GitHub Releases automatically, downloads and verifies the coordinated extension/native-host bundle, waits until every connected Overleaf tab is saved and idle, and then updates both components together. A failed health check restores the previous version automatically.
|
|
@@ -387,11 +387,11 @@ The stable updater ignores drafts and prereleases, performs no telemetry, and ca
|
|
|
387
387
|
The legacy native-only installer remains available for source or unmanaged extension directories:
|
|
388
388
|
|
|
389
389
|
```bash
|
|
390
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
390
|
+
npm exec --yes codex-overleaf-link@1.9.3 -- install-native
|
|
391
391
|
```
|
|
392
392
|
|
|
393
393
|
Legacy native-only installations can be removed with:
|
|
394
394
|
|
|
395
395
|
```bash
|
|
396
|
-
npm exec --yes codex-overleaf-link@1.9.
|
|
396
|
+
npm exec --yes codex-overleaf-link@1.9.3 -- uninstall-native
|
|
397
397
|
```
|
|
@@ -16,6 +16,7 @@ let runtimeLoadError = null;
|
|
|
16
16
|
try {
|
|
17
17
|
globalThis.__CODEX_OVERLEAF_RUNTIME_BASE__ = 'runtime';
|
|
18
18
|
importScripts(
|
|
19
|
+
chrome.runtime.getURL('bootstrap/updateStatus.js'),
|
|
19
20
|
chrome.runtime.getURL('runtime/src/shared/compatibility.js'),
|
|
20
21
|
chrome.runtime.getURL('runtime/src/background.js')
|
|
21
22
|
);
|
|
@@ -118,10 +119,13 @@ async function checkAndStage(options = {}) {
|
|
|
118
119
|
if (APPLYING_STATES.has(current.state)) {
|
|
119
120
|
return current;
|
|
120
121
|
}
|
|
122
|
+
if (['staged', 'waiting_for_idle'].includes(current.state) && current.transactionId) {
|
|
123
|
+
return tryApplyStagedUpdate();
|
|
124
|
+
}
|
|
121
125
|
if (!options.manual && Number(current.postponeUntil || 0) > Date.now()) {
|
|
122
126
|
return current;
|
|
123
127
|
}
|
|
124
|
-
await setUpdateState({ ...current, state: 'checking', code: '', message: '' });
|
|
128
|
+
await setUpdateState({ ...current, state: 'checking', blocker: '', blockers: [], code: '', message: '' });
|
|
125
129
|
const checked = await requestInternal({
|
|
126
130
|
method: 'update.check',
|
|
127
131
|
params: {
|
|
@@ -170,7 +174,9 @@ async function checkAndStage(options = {}) {
|
|
|
170
174
|
currentVersion: chrome.runtime.getManifest().version,
|
|
171
175
|
latestVersion: staged.result.targetVersion,
|
|
172
176
|
transactionId: staged.result.transactionId,
|
|
173
|
-
stagedAt: Date.now()
|
|
177
|
+
stagedAt: Date.now(),
|
|
178
|
+
blocker: '',
|
|
179
|
+
blockers: []
|
|
174
180
|
});
|
|
175
181
|
await broadcastUpdateState('staged');
|
|
176
182
|
chrome.alarms.create(IDLE_ALARM, { delayInMinutes: 0.1 });
|
|
@@ -187,20 +193,25 @@ async function tryApplyStagedUpdate() {
|
|
|
187
193
|
}
|
|
188
194
|
const tabs = await chrome.tabs.query({ url: OVERLEAF_MATCHES });
|
|
189
195
|
const probes = await Promise.all(tabs.map(tab => probeTabIdle(tab)));
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
196
|
+
const nativeGate = await requestInternal({ method: 'update.canApply', params: {} }).catch(error => ({
|
|
197
|
+
ok: false,
|
|
198
|
+
error: { code: safeCode(error), message: safeMessage(error) }
|
|
199
|
+
}));
|
|
200
|
+
const blockers = globalThis.CodexOverleafUpdateStatus?.collectBlockers(probes, nativeGate)
|
|
201
|
+
|| ['busy'];
|
|
202
|
+
if (blockers.length) {
|
|
193
203
|
const waiting = await setUpdateState({
|
|
194
204
|
...state,
|
|
195
205
|
state: 'waiting_for_idle',
|
|
196
|
-
blocker:
|
|
206
|
+
blocker: blockers[0],
|
|
207
|
+
blockers
|
|
197
208
|
});
|
|
198
209
|
chrome.alarms.create(IDLE_ALARM, { delayInMinutes: 1 });
|
|
199
210
|
return waiting;
|
|
200
211
|
}
|
|
201
212
|
|
|
202
213
|
await chrome.storage.local.set({ [UPDATE_RELOAD_TABS_KEY]: tabs.map(tab => tab.id).filter(Number.isInteger) });
|
|
203
|
-
await setUpdateState({ ...state, state: 'applying', blocker: '' });
|
|
214
|
+
await setUpdateState({ ...state, state: 'applying', blocker: '', blockers: [] });
|
|
204
215
|
await broadcastUpdateState('applying');
|
|
205
216
|
const applied = await requestInternal({
|
|
206
217
|
method: 'update.apply',
|
|
@@ -353,6 +364,9 @@ async function getUpdateState() {
|
|
|
353
364
|
}
|
|
354
365
|
|
|
355
366
|
async function setUpdateState(next) {
|
|
367
|
+
const blockers = globalThis.CodexOverleafUpdateStatus?.normalizeBlockers(
|
|
368
|
+
Array.isArray(next.blockers) ? next.blockers : (next.blocker ? [next.blocker] : [])
|
|
369
|
+
) || [];
|
|
356
370
|
const value = {
|
|
357
371
|
state: next.state || 'idle',
|
|
358
372
|
managed: next.managed !== false,
|
|
@@ -363,7 +377,8 @@ async function setUpdateState(next) {
|
|
|
363
377
|
stagedAt: Number(next.stagedAt || 0),
|
|
364
378
|
postponeUntil: Number(next.postponeUntil || 0),
|
|
365
379
|
transactionId: next.transactionId || '',
|
|
366
|
-
blocker:
|
|
380
|
+
blocker: blockers[0] || '',
|
|
381
|
+
blockers,
|
|
367
382
|
code: next.code || '',
|
|
368
383
|
message: String(next.message || '').slice(0, 300)
|
|
369
384
|
};
|
|
@@ -5,6 +5,7 @@ const updateVersions = document.getElementById('update-versions');
|
|
|
5
5
|
const updateDetail = document.getElementById('update-detail');
|
|
6
6
|
const checkButton = document.getElementById('check-update');
|
|
7
7
|
const postponeButton = document.getElementById('postpone-update');
|
|
8
|
+
const UpdateStatus = globalThis.CodexOverleafUpdateStatus;
|
|
8
9
|
|
|
9
10
|
checkButton.addEventListener('click', async () => {
|
|
10
11
|
checkButton.disabled = true;
|
|
@@ -33,7 +34,10 @@ async function refreshUpdateState() {
|
|
|
33
34
|
if (state.managed === false) {
|
|
34
35
|
updateDetail.textContent = 'Run install-managed once to enable automatic extension and native-host updates.';
|
|
35
36
|
} else if (state.state === 'waiting_for_idle') {
|
|
36
|
-
|
|
37
|
+
const blockerDetail = UpdateStatus?.formatBlockers(state.blockers || [state.blocker]) || '';
|
|
38
|
+
updateDetail.textContent = blockerDetail
|
|
39
|
+
? `Downloaded and verified. ${blockerDetail}`
|
|
40
|
+
: 'Downloaded and verified. Waiting until every Overleaf tab is saved and idle.';
|
|
37
41
|
} else if (state.state === 'rolled_back') {
|
|
38
42
|
updateDetail.textContent = 'The previous version was restored after a failed health check.';
|
|
39
43
|
} else if (state.state === 'committed') {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
(function initCodexOverleafUpdateStatus(root) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const BLOCKER_MESSAGES = Object.freeze({
|
|
5
|
+
run: 'A Codex run is still active.',
|
|
6
|
+
cancelling: 'A Codex cancellation is still settling.',
|
|
7
|
+
storage: 'Extension state is still being saved.',
|
|
8
|
+
reviewAction: 'An Accept or Undo action is still running.',
|
|
9
|
+
dialog: 'A confirmation dialog is still open.',
|
|
10
|
+
save_state_unverified: 'Overleaf has not confirmed that the document is saved.',
|
|
11
|
+
recent_user_activity: 'Recent editor activity must be idle for 30 seconds.',
|
|
12
|
+
save_state_not_stable: 'The saved state must remain stable for 3 seconds.',
|
|
13
|
+
idle_probe_failed: 'The Overleaf idle check failed.',
|
|
14
|
+
tab_unavailable: 'An Overleaf tab is unavailable.',
|
|
15
|
+
tab_probe_timeout: 'An Overleaf tab did not answer the idle check in time.',
|
|
16
|
+
tab_probe_unavailable: 'Reload an Overleaf tab so the updater can verify that it is idle.',
|
|
17
|
+
tab_not_idle: 'An Overleaf tab is still busy.',
|
|
18
|
+
native_project_locked: 'The native host still holds a project lock.',
|
|
19
|
+
native_run_active: 'The native host is still processing a Codex run.',
|
|
20
|
+
native_gate_unavailable: 'The native host could not report whether it is idle.',
|
|
21
|
+
native_not_idle: 'The native host is still busy.',
|
|
22
|
+
busy: 'An update safety check is still busy.'
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
function normalizeBlockers(values = []) {
|
|
26
|
+
const result = [];
|
|
27
|
+
const seen = new Set();
|
|
28
|
+
const visit = value => {
|
|
29
|
+
if (Array.isArray(value)) {
|
|
30
|
+
value.forEach(visit);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const code = String(value || '').trim();
|
|
34
|
+
if (!code || seen.has(code)) return;
|
|
35
|
+
seen.add(code);
|
|
36
|
+
result.push(code);
|
|
37
|
+
};
|
|
38
|
+
visit(values);
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function collectBlockers(probes = [], nativeGate = null) {
|
|
43
|
+
const blockers = [];
|
|
44
|
+
for (const probe of probes || []) {
|
|
45
|
+
if (probe?.idle === true) continue;
|
|
46
|
+
if (Array.isArray(probe?.blockers) && probe.blockers.length) {
|
|
47
|
+
blockers.push(probe.blockers);
|
|
48
|
+
} else {
|
|
49
|
+
blockers.push('tab_not_idle');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (!nativeGate?.ok) {
|
|
53
|
+
blockers.push(nativeGate?.error?.code || 'native_gate_unavailable');
|
|
54
|
+
} else if (nativeGate.result?.idle !== true) {
|
|
55
|
+
blockers.push(nativeGate.result?.blockers?.length ? nativeGate.result.blockers : 'native_not_idle');
|
|
56
|
+
}
|
|
57
|
+
return normalizeBlockers(blockers);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function describeBlocker(code) {
|
|
61
|
+
const normalized = String(code || '').trim();
|
|
62
|
+
if (!normalized) return '';
|
|
63
|
+
return BLOCKER_MESSAGES[normalized]
|
|
64
|
+
|| `Update is waiting on: ${normalized.replaceAll('_', ' ')}.`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function formatBlockers(blockers = []) {
|
|
68
|
+
return normalizeBlockers(blockers).map(describeBlocker).filter(Boolean).join(' ');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
root.CodexOverleafUpdateStatus = Object.freeze({
|
|
72
|
+
BLOCKER_MESSAGES,
|
|
73
|
+
collectBlockers,
|
|
74
|
+
describeBlocker,
|
|
75
|
+
formatBlockers,
|
|
76
|
+
normalizeBlockers
|
|
77
|
+
});
|
|
78
|
+
})(typeof window !== 'undefined' ? window : globalThis);
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
const MIN_NATIVE_VERSION = '1.0.0';
|
|
13
13
|
const MIN_COMPATIBLE_NATIVE_VERSION = '1.0.0';
|
|
14
14
|
const MIN_COMPATIBLE_EXTENSION_VERSION = '1.0.0';
|
|
15
|
-
const BUILD_TARGET_VERSION = '1.9.
|
|
15
|
+
const BUILD_TARGET_VERSION = '1.9.3';
|
|
16
16
|
const DEFAULT_CHROME_EXTENSION_ID = 'illdpneeeopfffmiepaejglgmhpmdhdc';
|
|
17
17
|
const REQUIRED_CAPABILITIES = Object.freeze([
|
|
18
18
|
'bridgePing',
|
|
@@ -1125,8 +1125,8 @@ function isAllowedLocalCommand(params = {}) {
|
|
|
1125
1125
|
}
|
|
1126
1126
|
|
|
1127
1127
|
const allowed = new Set([
|
|
1128
|
-
'rg', 'grep', 'cat', '
|
|
1129
|
-
'wc', 'diff', 'sort', 'tr', '
|
|
1128
|
+
'rg', 'grep', 'cat', 'head', 'tail', 'nl', 'find', 'ls',
|
|
1129
|
+
'wc', 'diff', 'sort', 'tr', 'printf', 'cut', 'uniq',
|
|
1130
1130
|
'stat', 'file', 'basename', 'dirname', 'realpath',
|
|
1131
1131
|
'shasum', 'md5', 'md5sum',
|
|
1132
1132
|
'latexmk', 'pdflatex', 'xelatex', 'lualatex', 'bibtex', 'biber',
|
|
@@ -1201,13 +1201,34 @@ function isUnsafeShellToken(token) {
|
|
|
1201
1201
|
function hasDisallowedCommandArguments(executable, args = []) {
|
|
1202
1202
|
const flags = args.map(String);
|
|
1203
1203
|
if (executable === 'find') {
|
|
1204
|
-
return flags.some(flag => [
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
}
|
|
1209
|
-
if (executable === '
|
|
1210
|
-
return flags.some(
|
|
1204
|
+
return flags.some(flag => [
|
|
1205
|
+
'-exec', '-execdir', '-delete', '-ok', '-okdir',
|
|
1206
|
+
'-fprint', '-fprint0', '-fprintf', '-fls'
|
|
1207
|
+
].includes(flag));
|
|
1208
|
+
}
|
|
1209
|
+
if (executable === 'rg') {
|
|
1210
|
+
return flags.some(flag => flag === '--pre' || flag.startsWith('--pre='));
|
|
1211
|
+
}
|
|
1212
|
+
if (executable === 'sort') {
|
|
1213
|
+
return flags.some(flag => flag === '-o'
|
|
1214
|
+
|| flag.startsWith('-o')
|
|
1215
|
+
|| flag === '--output'
|
|
1216
|
+
|| flag.startsWith('--output=')
|
|
1217
|
+
|| flag === '-T'
|
|
1218
|
+
|| flag.startsWith('-T')
|
|
1219
|
+
|| flag === '--temporary-directory'
|
|
1220
|
+
|| flag.startsWith('--temporary-directory='));
|
|
1221
|
+
}
|
|
1222
|
+
if (executable === 'latexmk') {
|
|
1223
|
+
return !flags.includes('-norc')
|
|
1224
|
+
|| flags.some(isUnsafeLatexmkArgument)
|
|
1225
|
+
|| flags.some(isUnsafeTexEngineArgument);
|
|
1226
|
+
}
|
|
1227
|
+
if (['pdflatex', 'xelatex', 'lualatex'].includes(executable)) {
|
|
1228
|
+
if (executable === 'lualatex' && !flags.some(flag => flag === '--safer' || flag === '-safer')) {
|
|
1229
|
+
return true;
|
|
1230
|
+
}
|
|
1231
|
+
return flags.some(isUnsafeTexEngineArgument);
|
|
1211
1232
|
}
|
|
1212
1233
|
if (executable === 'shasum' || executable === 'md5sum') {
|
|
1213
1234
|
return flags.some(flag => flag === '-c' || flag === '--check');
|
|
@@ -1215,6 +1236,28 @@ function hasDisallowedCommandArguments(executable, args = []) {
|
|
|
1215
1236
|
return false;
|
|
1216
1237
|
}
|
|
1217
1238
|
|
|
1239
|
+
function isUnsafeLatexmkArgument(value) {
|
|
1240
|
+
const flag = String(value || '').toLowerCase();
|
|
1241
|
+
return /^-(?:e|r)(?:$|=)/.test(flag)
|
|
1242
|
+
|| /^-(?:usepretex|useposttex)(?:$|=)/.test(flag)
|
|
1243
|
+
|| /^-(?:pdflatex|xelatex|lualatex|latex|bibtex|biber|makeindex|dvi_filter|ps_filter|pdf_previewer)(?:$|=)/.test(flag);
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
function isUnsafeTexEngineArgument(value) {
|
|
1247
|
+
const flag = String(value || '').toLowerCase();
|
|
1248
|
+
if (/(?:shell-escape|shell-restricted|write18)/.test(flag)) {
|
|
1249
|
+
return true;
|
|
1250
|
+
}
|
|
1251
|
+
if (/^--?(?:output-directory|aux-directory|outdir|auxdir)(?:$|=)/.test(flag)) {
|
|
1252
|
+
return true;
|
|
1253
|
+
}
|
|
1254
|
+
if (flag === '-jobname' || flag === '--jobname') {
|
|
1255
|
+
return true;
|
|
1256
|
+
}
|
|
1257
|
+
const jobName = flag.match(/^--?jobname=(.*)$/)?.[1] || '';
|
|
1258
|
+
return Boolean(jobName && (jobName.includes('..') || /[\\/]/.test(jobName)));
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1218
1261
|
function pathBasename(value) {
|
|
1219
1262
|
return String(value || '').split(/[\\/]/).pop();
|
|
1220
1263
|
}
|
|
@@ -42,8 +42,13 @@ async function syncOverleafToMirror({ projectId, project, rootDir }) {
|
|
|
42
42
|
const previous = readBaseline(mirror.baselinePath);
|
|
43
43
|
const fullProjectSnapshot = project?.capabilities?.fullProjectSnapshot !== false;
|
|
44
44
|
|
|
45
|
+
const mirrorRoot = path.dirname(mirror.projectRoot);
|
|
46
|
+
assertSafeMirrorPathBeforeCreate(mirror.workspacePath, mirrorRoot);
|
|
47
|
+
assertSafeMirrorPathBeforeCreate(mirror.metadataPath, mirrorRoot);
|
|
45
48
|
fs.mkdirSync(mirror.workspacePath, { recursive: true });
|
|
46
49
|
fs.mkdirSync(mirror.metadataPath, { recursive: true });
|
|
50
|
+
assertSafeMirrorPathBeforeCreate(mirror.workspacePath, mirrorRoot);
|
|
51
|
+
assertSafeMirrorPathBeforeCreate(mirror.metadataPath, mirrorRoot);
|
|
47
52
|
|
|
48
53
|
if (fullProjectSnapshot) {
|
|
49
54
|
for (const filePath of listWorkspaceFiles(mirror.workspacePath)) {
|
|
@@ -52,6 +57,7 @@ async function syncOverleafToMirror({ projectId, project, rootDir }) {
|
|
|
52
57
|
}
|
|
53
58
|
const target = resolveWorkspacePath(mirror.workspacePath, filePath);
|
|
54
59
|
if (fs.existsSync(target)) {
|
|
60
|
+
assertSafeWorkspaceTarget(mirror.workspacePath, target, filePath);
|
|
55
61
|
fs.rmSync(target, { force: true });
|
|
56
62
|
removeEmptyParents(path.dirname(target), mirror.workspacePath);
|
|
57
63
|
}
|
|
@@ -63,6 +69,7 @@ async function syncOverleafToMirror({ projectId, project, rootDir }) {
|
|
|
63
69
|
|
|
64
70
|
for (const file of files) {
|
|
65
71
|
const target = resolveWorkspacePath(mirror.workspacePath, file.path);
|
|
72
|
+
assertSafeWorkspaceTarget(mirror.workspacePath, target, file.path);
|
|
66
73
|
const prev = previousByPath.get(file.path);
|
|
67
74
|
const nextHash = hashProjectFile(file);
|
|
68
75
|
if (prev && prev.hash === nextHash && workspaceFileMatchesBaseline(target, prev)) {
|
|
@@ -530,6 +537,9 @@ function listWorkspaceFiles(workspacePath) {
|
|
|
530
537
|
}
|
|
531
538
|
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
532
539
|
const absolute = path.join(dir, entry.name);
|
|
540
|
+
if (entry.isSymbolicLink()) {
|
|
541
|
+
throw new Error(`Unsafe mirror symlink: ${relative}`);
|
|
542
|
+
}
|
|
533
543
|
if (entry.isDirectory()) {
|
|
534
544
|
walk(absolute, relative);
|
|
535
545
|
} else if (entry.isFile()) {
|
|
@@ -753,6 +763,7 @@ async function applyFileOverlays({ projectId, overlays, rootDir }) {
|
|
|
753
763
|
}
|
|
754
764
|
const normalizedPath = normalizeRelativePath(overlay.path);
|
|
755
765
|
const target = resolveWorkspacePath(mirror.workspacePath, normalizedPath);
|
|
766
|
+
assertSafeWorkspaceTarget(mirror.workspacePath, target, normalizedPath);
|
|
756
767
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
757
768
|
fs.writeFileSync(target, overlay.content, 'utf8');
|
|
758
769
|
|
|
@@ -803,6 +814,9 @@ async function confirmWritebackFiles({ projectId, paths, rootDir }) {
|
|
|
803
814
|
} catch (error) {
|
|
804
815
|
return { ok: false, reason: 'unsafe_path', path: normalizedPath };
|
|
805
816
|
}
|
|
817
|
+
if (!isSafeWorkspaceWriteTarget(mirror.workspacePath, target)) {
|
|
818
|
+
return { ok: false, reason: 'unsafe_path', path: normalizedPath };
|
|
819
|
+
}
|
|
806
820
|
let content;
|
|
807
821
|
try {
|
|
808
822
|
content = fs.readFileSync(target, 'utf8');
|
|
@@ -1017,6 +1031,34 @@ function isSafeWorkspaceWriteTarget(workspacePath, target) {
|
|
|
1017
1031
|
}
|
|
1018
1032
|
}
|
|
1019
1033
|
|
|
1034
|
+
function assertSafeWorkspaceTarget(workspacePath, target, filePath = '') {
|
|
1035
|
+
if (!isSafeWorkspaceWriteTarget(workspacePath, target)) {
|
|
1036
|
+
throw new Error(`Unsafe mirror path: ${filePath || target}`);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
function assertSafeMirrorPathBeforeCreate(target, boundary) {
|
|
1041
|
+
const root = path.resolve(boundary);
|
|
1042
|
+
const resolvedTarget = path.resolve(target);
|
|
1043
|
+
if (resolvedTarget === root || !resolvedTarget.startsWith(root + path.sep)) {
|
|
1044
|
+
throw new Error(`Unsafe mirror root path: ${target}`);
|
|
1045
|
+
}
|
|
1046
|
+
let current = root;
|
|
1047
|
+
const parts = path.relative(root, resolvedTarget).split(path.sep).filter(Boolean);
|
|
1048
|
+
for (let index = -1; index < parts.length; index += 1) {
|
|
1049
|
+
if (index >= 0) {
|
|
1050
|
+
current = path.join(current, parts[index]);
|
|
1051
|
+
}
|
|
1052
|
+
if (!fs.existsSync(current)) {
|
|
1053
|
+
continue;
|
|
1054
|
+
}
|
|
1055
|
+
const stat = fs.lstatSync(current);
|
|
1056
|
+
if (stat.isSymbolicLink() || (index < parts.length - 1 && !stat.isDirectory())) {
|
|
1057
|
+
throw new Error(`Unsafe mirror root path: ${current}`);
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1020
1062
|
function markMirrorDirty({ projectId, rootDir, reason = 'dirty_mirror' }) {
|
|
1021
1063
|
const mirror = getProjectMirror(projectId, { rootDir });
|
|
1022
1064
|
const baseline = readBaseline(mirror.baselinePath);
|
|
@@ -1040,6 +1082,9 @@ function verifyWorkspaceMatchesBaseline(workspacePath, baselineFiles = []) {
|
|
|
1040
1082
|
if (!fs.existsSync(target)) {
|
|
1041
1083
|
return { ok: false, reason: 'workspace_mismatch', path: file.path };
|
|
1042
1084
|
}
|
|
1085
|
+
if (!isSafeWorkspaceWriteTarget(workspacePath, target)) {
|
|
1086
|
+
return { ok: false, reason: 'unsafe_path', path: file.path };
|
|
1087
|
+
}
|
|
1043
1088
|
if (file.kind === 'binary') {
|
|
1044
1089
|
if (hashBytes(fs.readFileSync(target)) !== file.hash) {
|
|
1045
1090
|
return { ok: false, reason: 'workspace_mismatch', path: file.path };
|
|
@@ -172,6 +172,23 @@ async function stageCandidate(context, options = {}) {
|
|
|
172
172
|
if (!isNewerStableVersion(manifest.version, activeVersion)) {
|
|
173
173
|
throw updateError('update_candidate_stale', 'The staged update is no longer newer than the active version.');
|
|
174
174
|
}
|
|
175
|
+
const existingJournal = readJournal(context);
|
|
176
|
+
if (existingJournal?.state === 'staged' && existingJournal.targetVersion === manifest.version) {
|
|
177
|
+
try {
|
|
178
|
+
verifyStagedPair(existingJournal.payloadRoot, manifest.version);
|
|
179
|
+
return {
|
|
180
|
+
transactionId: existingJournal.id,
|
|
181
|
+
targetVersion: existingJournal.targetVersion,
|
|
182
|
+
state: existingJournal.state,
|
|
183
|
+
reused: true
|
|
184
|
+
};
|
|
185
|
+
} catch (_error) {
|
|
186
|
+
cleanupStage(existingJournal.stageRoot);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (existingJournal && ['applying', 'awaiting_health'].includes(existingJournal.state)) {
|
|
190
|
+
throw updateError('update_transaction_in_progress', 'A managed update transaction is already being applied.');
|
|
191
|
+
}
|
|
175
192
|
const transactionId = crypto.randomUUID();
|
|
176
193
|
const stageRoot = path.join(context.updatesRoot, 'staging-' + transactionId);
|
|
177
194
|
fs.mkdirSync(stageRoot, { recursive: true, mode: 0o700 });
|
|
@@ -202,6 +219,7 @@ async function stageCandidate(context, options = {}) {
|
|
|
202
219
|
updatedAt: new Date().toISOString()
|
|
203
220
|
};
|
|
204
221
|
writeJournal(context, journal);
|
|
222
|
+
cleanupOrphanStageRoots(context.updatesRoot, [stageRoot]);
|
|
205
223
|
return { transactionId, targetVersion: manifest.version, state: journal.state };
|
|
206
224
|
}
|
|
207
225
|
|
|
@@ -247,6 +265,7 @@ function applyStagedUpdate(context, params = {}, options = {}) {
|
|
|
247
265
|
atomicWriteText(path.join(context.nativeRoot, 'previous-version'), journal.sourceVersion + '\n');
|
|
248
266
|
atomicWriteText(path.join(context.nativeRoot, 'active-version'), journal.targetVersion + '\n');
|
|
249
267
|
rewriteManagedManifestVersion(manifestPath, journal.targetVersion);
|
|
268
|
+
syncManagedMarkerVersions(context, journal.targetVersion);
|
|
250
269
|
} catch (error) {
|
|
251
270
|
rollbackFiles(context, { ...journal, previousManifest });
|
|
252
271
|
throw updateError('update_apply_failed', 'Managed update could not be applied atomically.', { cause: error });
|
|
@@ -282,6 +301,7 @@ function confirmUpdate(context, params = {}) {
|
|
|
282
301
|
});
|
|
283
302
|
pruneNativeVersions(context.nativeRoot, new Set([journal.targetVersion, journal.sourceVersion]));
|
|
284
303
|
cleanupStage(journal.stageRoot);
|
|
304
|
+
cleanupOrphanStageRoots(context.updatesRoot);
|
|
285
305
|
return { version: journal.targetVersion, state: 'committed' };
|
|
286
306
|
}
|
|
287
307
|
|
|
@@ -306,6 +326,7 @@ function rollbackUpdate(context, params = {}) {
|
|
|
306
326
|
previousManifest: undefined
|
|
307
327
|
});
|
|
308
328
|
cleanupStage(journal.stageRoot);
|
|
329
|
+
cleanupOrphanStageRoots(context.updatesRoot);
|
|
309
330
|
return { version: journal.sourceVersion, state: 'rolled_back' };
|
|
310
331
|
}
|
|
311
332
|
|
|
@@ -329,6 +350,45 @@ function rollbackFiles(context, journal) {
|
|
|
329
350
|
} else {
|
|
330
351
|
fs.rmSync(path.join(context.nativeRoot, 'previous-version'), { force: true });
|
|
331
352
|
}
|
|
353
|
+
if (parseSemver(journal.sourceVersion)) {
|
|
354
|
+
syncManagedMarkerVersions(context, journal.sourceVersion);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function syncManagedMarkerVersions(context, version) {
|
|
359
|
+
rewriteManagedMarkerVersion(context.extensionRoot, EXTENSION_MARKER, 'extension', version);
|
|
360
|
+
rewriteManagedMarkerVersion(context.nativeRoot, NATIVE_MARKER, 'native', version);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function rewriteManagedMarkerVersion(root, filename, kind, version) {
|
|
364
|
+
const markerPath = path.join(root, filename);
|
|
365
|
+
const marker = readJsonSafe(markerPath, null);
|
|
366
|
+
if (!isManagedMarker(marker, kind)) {
|
|
367
|
+
throw updateError('update_marker_invalid', `The managed ${kind} marker is missing or invalid.`);
|
|
368
|
+
}
|
|
369
|
+
atomicWriteJson(markerPath, {
|
|
370
|
+
...marker,
|
|
371
|
+
version,
|
|
372
|
+
updatedAt: new Date().toISOString()
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function cleanupOrphanStageRoots(updatesRoot, retainedRoots = []) {
|
|
377
|
+
const resolvedRoot = path.resolve(String(updatesRoot || ''));
|
|
378
|
+
if (!resolvedRoot || resolvedRoot === path.parse(resolvedRoot).root) return;
|
|
379
|
+
const retained = new Set((retainedRoots || []).map(value => path.resolve(String(value || ''))));
|
|
380
|
+
let entries;
|
|
381
|
+
try {
|
|
382
|
+
entries = fs.readdirSync(resolvedRoot, { withFileTypes: true });
|
|
383
|
+
} catch (_error) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
for (const entry of entries) {
|
|
387
|
+
if (!entry.isDirectory() || !/^staging-[0-9a-f-]{36}$/i.test(entry.name)) continue;
|
|
388
|
+
const candidate = path.join(resolvedRoot, entry.name);
|
|
389
|
+
if (retained.has(path.resolve(candidate))) continue;
|
|
390
|
+
fs.rmSync(candidate, { recursive: true, force: true });
|
|
391
|
+
}
|
|
332
392
|
}
|
|
333
393
|
|
|
334
394
|
function recoverAndReadStatus(context) {
|
|
@@ -539,10 +599,13 @@ module.exports = {
|
|
|
539
599
|
GITHUB_LATEST_URL,
|
|
540
600
|
applyStagedUpdate,
|
|
541
601
|
checkForUpdate,
|
|
602
|
+
cleanupOrphanStageRoots,
|
|
542
603
|
confirmUpdate,
|
|
543
604
|
getApplyGate,
|
|
544
605
|
getManagedContext,
|
|
545
606
|
handleUpdateRequest,
|
|
546
607
|
isUpdateMethod,
|
|
547
|
-
rollbackUpdate
|
|
608
|
+
rollbackUpdate,
|
|
609
|
+
stageCandidate,
|
|
610
|
+
syncManagedMarkerVersions
|
|
548
611
|
};
|