codex-overleaf-link 1.9.12 → 2.0.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/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.12-blue" alt="version">
6
+ <img src="https://img.shields.io/badge/version-2.0.0-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">
@@ -38,14 +38,14 @@ One command installs the managed native host **and** managed extension runtime.
38
38
  macOS / Linux:
39
39
 
40
40
  ```bash
41
- CODEX_OVERLEAF_REF=v1.9.12 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.12/install.sh)"
41
+ CODEX_OVERLEAF_REF=v2.0.0 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v2.0.0/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.12/install.ps1 -OutFile install.ps1
48
- $env:CODEX_OVERLEAF_REF='v1.9.12'
47
+ iwr https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v2.0.0/install.ps1 -OutFile install.ps1
48
+ $env:CODEX_OVERLEAF_REF='v2.0.0'
49
49
  powershell -ExecutionPolicy Bypass -File install.ps1
50
50
  ```
51
51
 
@@ -56,7 +56,7 @@ Then, in the `chrome://extensions` tab the script opened: enable **Developer mod
56
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.12 -- install-managed
59
+ npm exec --yes codex-overleaf-link@2.0.0 -- install-managed
60
60
  ```
61
61
 
62
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.
@@ -86,9 +86,9 @@ npm installs, updates, and uninstalls the coordinated managed extension/native p
86
86
 
87
87
  | Action | Command |
88
88
  |--------|---------|
89
- | Install / update | `npm exec --yes codex-overleaf-link@1.9.12 -- install-managed` |
90
- | Diagnose | `npm exec --yes codex-overleaf-link@1.9.12 -- doctor` |
91
- | Uninstall | `npm exec --yes codex-overleaf-link@1.9.12 -- uninstall-managed` |
89
+ | Install / update | `npm exec --yes codex-overleaf-link@2.0.0 -- install-managed` |
90
+ | Diagnose | `npm exec --yes codex-overleaf-link@2.0.0 -- doctor` |
91
+ | Uninstall | `npm exec --yes codex-overleaf-link@2.0.0 -- 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
 
@@ -98,13 +98,13 @@ Managed installations discover signed stable updates automatically and apply the
98
98
 
99
99
  ## GitHub Release Artifacts
100
100
 
101
- The v1.9.12 GitHub Release contains:
101
+ The v2.0.0 GitHub Release contains:
102
102
 
103
- - `codex-overleaf-link-extension-v1.9.12.zip`: loadable Chrome extension package for manual unpacked installation.
104
- - `codex-overleaf-native-host-v1.9.12.tar.gz`: native host runtime files used by the installer and release verification.
105
- - `codex-overleaf-link-1.9.12.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.12` when run directly from the release artifact.
107
- - `install.ps1`: release-pinned Windows PowerShell installer that defaults to `v1.9.12` when run directly from the release artifact.
103
+ - `codex-overleaf-link-extension-v2.0.0.zip`: loadable Chrome extension package for manual unpacked installation.
104
+ - `codex-overleaf-native-host-v2.0.0.tar.gz`: native host runtime files used by the installer and release verification.
105
+ - `codex-overleaf-link-2.0.0.tgz`: npm native host CLI package for pinned install, doctor, and uninstall flows.
106
+ - `install.sh`: release-pinned macOS / Linux installer that defaults to `v2.0.0` when run directly from the release artifact.
107
+ - `install.ps1`: release-pinned Windows PowerShell installer that defaults to `v2.0.0` 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.12 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.12 -- uninstall-managed
118
+ npm exec --yes codex-overleaf-link@2.0.0 -- 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.12 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v1.9.12/install.sh)" -- --browser chromium
153
+ CODEX_OVERLEAF_REF=v2.0.0 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Ghqqqq/codex-overleaf-link/v2.0.0/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.12 -- uninstall-managed --browser chromium
159
+ npm exec --yes codex-overleaf-link@2.0.0 -- 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.12 -- install-managed
294
+ npm exec --yes codex-overleaf-link@2.0.0 -- 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.12 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.12 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.12 -- install-managed` | `npm exec --yes codex-overleaf-link@1.9.12 -- install-managed --browser chromium` |
344
- | Uninstall command | `npm exec --yes codex-overleaf-link@1.9.12 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.12 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.12 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@1.9.12 -- uninstall-managed --browser chromium` |
343
+ | Installer/update command | `npm exec --yes codex-overleaf-link@2.0.0 -- install-managed` | `npm exec --yes codex-overleaf-link@2.0.0 -- install-managed` | `npm exec --yes codex-overleaf-link@2.0.0 -- install-managed` | `npm exec --yes codex-overleaf-link@2.0.0 -- install-managed --browser chromium` |
344
+ | Uninstall command | `npm exec --yes codex-overleaf-link@2.0.0 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@2.0.0 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@2.0.0 -- uninstall-managed` | `npm exec --yes codex-overleaf-link@2.0.0 -- 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.12 -- install-managed
380
+ npm exec --yes codex-overleaf-link@2.0.0 -- 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.12 -- install-native
390
+ npm exec --yes codex-overleaf-link@2.0.0 -- 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.12 -- uninstall-native
396
+ npm exec --yes codex-overleaf-link@2.0.0 -- uninstall-native
397
397
  ```
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Codex Overleaf Link",
4
- "version": "1.9.12",
4
+ "version": "2.0.0",
5
5
  "description": "Connect the active Overleaf project to a local Codex bridge.",
6
6
  "icons": {
7
7
  "16": "assets/icons/icon16.png",
@@ -20,6 +20,7 @@
20
20
  "src/shared/sessionState.js",
21
21
  "src/shared/storageKeys.js",
22
22
  "src/shared/staleGuard.js",
23
+ "src/shared/storageRunActions.js",
23
24
  "src/shared/storageDb.js",
24
25
  "src/shared/storageMigration.js",
25
26
  "src/shared/compileAdapter.js",
@@ -4,6 +4,8 @@
4
4
  const UPDATE_STATE_KEY = 'codex-overleaf-managed-update-state-v1';
5
5
  const CONSENT_STATE_KEY = 'codex-overleaf-update-consent-v1';
6
6
  const CHECK_ALARM = 'codex-overleaf-consent-update-check';
7
+ const STARTUP_CHECK_SESSION_KEY = 'codex-overleaf-startup-update-check-v1';
8
+ const STARTUP_CHECK_CLAIMED_FLAG = '__codexOverleafStartupUpdateCheckClaimed';
7
9
  const CHECK_INTERVAL_MINUTES = 24 * 60;
8
10
  const SNOOZE_MS = 24 * 60 * 60 * 1000;
9
11
  const CANDIDATE_MAX_AGE_MS = 5 * 60 * 1000;
@@ -68,6 +70,24 @@
68
70
  await settleTerminalConsent();
69
71
  await armLegacyGuard();
70
72
  await publishView();
73
+ if (await claimStartupCheck()) {
74
+ void enqueuePolicyAction(() => checkOnly({ manual: false })).catch(() => {});
75
+ }
76
+ }
77
+
78
+ async function claimStartupCheck() {
79
+ if (root[STARTUP_CHECK_CLAIMED_FLAG] === true) return false;
80
+ root[STARTUP_CHECK_CLAIMED_FLAG] = true;
81
+ const sessionStorage = chrome.storage?.session;
82
+ if (!sessionStorage?.get || !sessionStorage?.set) return true;
83
+ try {
84
+ const stored = await sessionStorage.get(STARTUP_CHECK_SESSION_KEY);
85
+ if (stored?.[STARTUP_CHECK_SESSION_KEY] === true) return false;
86
+ await sessionStorage.set({ [STARTUP_CHECK_SESSION_KEY]: true });
87
+ return true;
88
+ } catch (_error) {
89
+ return true;
90
+ }
71
91
  }
72
92
 
73
93
  async function handleMessage(message) {
@@ -6090,7 +6090,7 @@
6090
6090
  focusFiles: Array.isArray(session.focusFiles) ? session.focusFiles : [],
6091
6091
  createdAt: session.createdAt,
6092
6092
  updatedAt: session.updatedAt
6093
- })
6093
+ }, { preserveRunActionPayload: true })
6094
6094
  ));
6095
6095
  if (sessionRecords.length) {
6096
6096
  await StorageDb.putRecords('sessions', sessionRecords);
@@ -88,7 +88,9 @@
88
88
  skipped
89
89
  };
90
90
  }
91
- const snapshotUndo = await restoreExpectedFilesWithNoTraceUndo(expectedFiles, postFiles);
91
+ const snapshotUndo = await restoreExpectedFilesWithNoTraceUndo(expectedFiles, postFiles, {
92
+ runProjectId: params.runProjectId
93
+ });
92
94
  if (snapshotUndo.attempted) {
93
95
  applied.push(...snapshotUndo.applied);
94
96
  skipped.push(...snapshotUndo.skipped);
@@ -291,6 +293,7 @@
291
293
  .filter(file => file?.path && typeof file.content === 'string')
292
294
  .map(file => [normalizeSafeProjectPath(file.path), file.content])
293
295
  .filter(([path]) => path));
296
+ let snapshotContextRebased = false;
294
297
  const paths = Array.from(expectedByPath.keys()).filter(path => postByPath.has(path));
295
298
  if (!paths.length) {
296
299
  return {
@@ -313,30 +316,63 @@
313
316
  // the reject path relies on (its primary path).
314
317
  const appliedBeforeUndo = applied.length;
315
318
  const editorUndo = await rejectTrackedChangesViaEditorUndo(expectedFiles, postFiles, applied);
319
+ let undoReady = editorUndo.ok === true;
320
+ let snapshotUndo = null;
321
+ // A page refresh preserves the run checkpoint but clears CodeMirror's
322
+ // in-memory undo history. When the native editor undo made no progress,
323
+ // reuse Undo's guarded snapshot path: it first verifies that every file is
324
+ // still exactly at this run's post-write content, then restores the
325
+ // persisted pre-write content with Track Changes disabled. The normal
326
+ // Accept replay below can then apply the post-write patch untracked.
327
+ if (!undoReady && applied.length === appliedBeforeUndo) {
328
+ snapshotUndo = await restoreExpectedFilesWithNoTraceUndo(expectedFiles, postFiles, {
329
+ runProjectId: params.runProjectId
330
+ });
331
+ if (snapshotUndo.ok) {
332
+ applied.push(...snapshotUndo.applied);
333
+ for (const file of snapshotUndo.rebasedExpectedFiles || []) {
334
+ expectedByPath.set(file.path, file.content);
335
+ }
336
+ for (const file of snapshotUndo.rebasedPostFiles || []) {
337
+ if (postByPath.get(file.path) !== file.content) {
338
+ snapshotContextRebased = true;
339
+ }
340
+ postByPath.set(file.path, file.content);
341
+ }
342
+ undoReady = true;
343
+ }
344
+ }
316
345
  pushDiagnostic('editorUndo', {
317
- ok: editorUndo.ok === true,
346
+ ok: undoReady,
318
347
  attempted: editorUndo.attempted === true,
319
348
  code: editorUndo.code || '',
320
349
  reason: editorUndo.reason || '',
321
- pathsProcessed: applied.length - appliedBeforeUndo
350
+ pathsProcessed: applied.length - appliedBeforeUndo,
351
+ snapshotFallbackAttempted: snapshotUndo?.attempted === true,
352
+ snapshotFallbackOk: snapshotUndo?.ok === true,
353
+ snapshotFallbackApplied: snapshotUndo?.applied?.length || 0,
354
+ snapshotFallbackSkipped: snapshotUndo?.skipped?.length || 0
322
355
  });
323
- if (!editorUndo.ok) {
324
- // Drift bail: the editor-undo could not reach the pre-write state. Do NOT
325
- // re-write — that would only make the document worse. Return not-ok so the
326
- // run stays pending and the user can retry, same as Undo.
356
+ if (!undoReady) {
357
+ // Drift or a partial editor undo still bails. The snapshot fallback is
358
+ // allowed only when editor undo made no progress, and its own post-state
359
+ // verification prevents overwriting edits made after this run.
360
+ const snapshotFailure = snapshotUndo?.skipped?.[0]?.result;
327
361
  return {
328
362
  ok: false,
329
- applied: [],
330
- skipped: [{
331
- trackedChange: null,
332
- result: editorUndo.attempted || editorUndo.code
333
- ? editorUndo
334
- : {
335
- ok: false,
336
- code: 'accept_editor_undo_unavailable',
337
- reason: '没有可执行的 Overleaf 原生撤销来清掉本轮留痕;Codex 没有接受这轮改动。'
338
- }
339
- }],
363
+ applied: snapshotUndo?.applied || [],
364
+ skipped: snapshotUndo?.skipped?.length
365
+ ? snapshotUndo.skipped
366
+ : [{
367
+ trackedChange: null,
368
+ result: snapshotFailure || (editorUndo.attempted || editorUndo.code
369
+ ? editorUndo
370
+ : {
371
+ ok: false,
372
+ code: 'accept_editor_undo_unavailable',
373
+ reason: '没有可执行的 Overleaf 原生撤销或安全快照回滚来清掉本轮留痕;Codex 没有接受这轮改动。'
374
+ })
375
+ }],
340
376
  diagnostics
341
377
  };
342
378
  }
@@ -417,7 +453,12 @@
417
453
  // applyOperationsCore — never a whole-file replaceAll, which would clobber
418
454
  // any unrelated content and produce one giant tracked change if anything
419
455
  // about the mode switch were imperfect.
420
- const operationsResult = buildAcceptReplayOperations(paths, expectedByPath, postByPath, params.appliedOperations);
456
+ const operationsResult = buildAcceptReplayOperations(
457
+ paths,
458
+ expectedByPath,
459
+ postByPath,
460
+ snapshotContextRebased ? [] : params.appliedOperations
461
+ );
421
462
  if (!operationsResult.ok) {
422
463
  if (weToggledOff) {
423
464
  await setReviewingEnabled(true, { waitMs: 1800 });
@@ -975,7 +1016,7 @@
975
1016
  return { ok: true, attempted: true };
976
1017
  }
977
1018
 
978
- async function restoreExpectedFilesWithNoTraceUndo(expectedFiles, postFiles) {
1019
+ async function restoreExpectedFilesWithNoTraceUndo(expectedFiles, postFiles, options = {}) {
979
1020
  const expectedByPath = new Map((expectedFiles || [])
980
1021
  .filter(file => file?.path && typeof file.content === 'string')
981
1022
  .map(file => [normalizeSafeProjectPath(file.path), file.content])
@@ -985,12 +1026,16 @@
985
1026
  .map(file => [normalizeSafeProjectPath(file.path), file.content])
986
1027
  .filter(([path]) => path));
987
1028
  const paths = Array.from(expectedByPath.keys()).filter(path => postByPath.has(path));
1029
+ const rebasedExpectedByPath = new Map();
1030
+ const rebasedPostByPath = new Map();
988
1031
  if (!paths.length) {
989
1032
  return {
990
1033
  ok: false,
991
1034
  attempted: false,
992
1035
  applied: [],
993
- skipped: []
1036
+ skipped: [],
1037
+ rebasedExpectedFiles: [],
1038
+ rebasedPostFiles: []
994
1039
  };
995
1040
  }
996
1041
 
@@ -1008,30 +1053,40 @@
1008
1053
  };
1009
1054
  }
1010
1055
  }
1011
- const ready = await waitForActiveEditorExpectedText(path, postByPath.get(path), 1500);
1056
+ const ready = await waitForActiveEditorCheckpoint(
1057
+ path,
1058
+ expectedByPath.get(path),
1059
+ postByPath.get(path),
1060
+ 1500
1061
+ );
1012
1062
  if (!ready.ok) {
1013
1063
  return {
1014
1064
  ok: false,
1015
1065
  attempted: false,
1016
1066
  applied: [],
1017
1067
  skipped: [],
1068
+ rebasedExpectedFiles: [],
1069
+ rebasedPostFiles: [],
1018
1070
  code: 'snapshot_undo_current_mismatch',
1019
1071
  reason: `${path} 当前内容已经不是本轮写入后的内容;为避免覆盖你的后续修改,Codex 不执行快照撤销。`
1020
1072
  };
1021
1073
  }
1074
+ rebasedExpectedByPath.set(path, ready.expectedContent);
1075
+ rebasedPostByPath.set(path, ready.postContent);
1022
1076
  }
1023
1077
 
1024
1078
  const operations = paths.map(path => ({
1025
1079
  type: 'edit',
1026
1080
  path,
1027
- replaceAll: expectedByPath.get(path),
1081
+ replaceAll: rebasedExpectedByPath.get(path),
1028
1082
  reason: 'Undo tracked edit'
1029
1083
  }));
1030
1084
  const result = await applyOperationsWithNoTraceUndo(operations, {
1031
1085
  baseFiles: paths.map(path => ({
1032
1086
  path,
1033
- content: postByPath.get(path)
1034
- }))
1087
+ content: rebasedPostByPath.get(path)
1088
+ })),
1089
+ runProjectId: typeof options.runProjectId === 'string' ? options.runProjectId : ''
1035
1090
  });
1036
1091
  const toTrackedResult = item => ({
1037
1092
  trackedChange: {
@@ -1046,7 +1101,66 @@
1046
1101
  ok: !(result.skipped || []).length,
1047
1102
  attempted: true,
1048
1103
  applied: (result.applied || []).map(toTrackedResult),
1049
- skipped: (result.skipped || []).map(toTrackedResult)
1104
+ skipped: (result.skipped || []).map(toTrackedResult),
1105
+ rebasedExpectedFiles: paths.map(path => ({
1106
+ path,
1107
+ content: rebasedExpectedByPath.get(path)
1108
+ })),
1109
+ rebasedPostFiles: paths.map(path => ({
1110
+ path,
1111
+ content: rebasedPostByPath.get(path)
1112
+ }))
1113
+ };
1114
+ }
1115
+
1116
+ async function waitForActiveEditorCheckpoint(filePath, expectedContent, postContent, timeoutMs) {
1117
+ const deadline = Date.now() + Math.max(0, Number(timeoutMs) || 0);
1118
+ let actual = readActiveEditorText();
1119
+ while (Date.now() < deadline) {
1120
+ const activeFileMatches = !filePath || getActiveFilePath() === filePath;
1121
+ actual = readActiveEditorText();
1122
+ if (activeFileMatches) {
1123
+ const rebased = rebaseCheckpointPair(actual, expectedContent, postContent);
1124
+ if (rebased.ok) {
1125
+ return rebased;
1126
+ }
1127
+ }
1128
+ await delay(60);
1129
+ }
1130
+ return {
1131
+ ok: false,
1132
+ text: actual
1133
+ };
1134
+ }
1135
+
1136
+ function rebaseCheckpointPair(actualContent, expectedContent, postContent) {
1137
+ const actual = String(actualContent ?? '');
1138
+ const expected = String(expectedContent ?? '');
1139
+ const post = String(postContent ?? '');
1140
+ if (actual === post) {
1141
+ return {
1142
+ ok: true,
1143
+ expectedContent: expected,
1144
+ postContent: post,
1145
+ prefixLength: 0,
1146
+ suffixLength: 0
1147
+ };
1148
+ }
1149
+ if (!post) {
1150
+ return { ok: false };
1151
+ }
1152
+ const matchIndex = actual.indexOf(post);
1153
+ if (matchIndex < 0 || actual.indexOf(post, matchIndex + 1) >= 0) {
1154
+ return { ok: false };
1155
+ }
1156
+ const prefix = actual.slice(0, matchIndex);
1157
+ const suffix = actual.slice(matchIndex + post.length);
1158
+ return {
1159
+ ok: true,
1160
+ expectedContent: prefix + expected + suffix,
1161
+ postContent: actual,
1162
+ prefixLength: prefix.length,
1163
+ suffixLength: suffix.length
1050
1164
  };
1051
1165
  }
1052
1166
 
@@ -1319,6 +1433,20 @@
1319
1433
 
1320
1434
 
1321
1435
 
1436
+ function diffTrackedChangeRefs(before = [], after = []) {
1437
+ const beforeKeys = new Set((before || []).map(ref => ref.key).filter(Boolean));
1438
+ const seen = new Set();
1439
+ const added = [];
1440
+ for (const ref of after || []) {
1441
+ if (!ref?.key || beforeKeys.has(ref.key) || seen.has(ref.key)) {
1442
+ continue;
1443
+ }
1444
+ seen.add(ref.key);
1445
+ added.push(ref);
1446
+ }
1447
+ return added;
1448
+ }
1449
+
1322
1450
  async function waitForTrackedChangeDiff(trackedBefore, paths, options = {}) {
1323
1451
  const waitMs = Number.isFinite(Number(options.waitMs)) ? Number(options.waitMs) : 3000;
1324
1452
  const intervalMs = Number.isFinite(Number(options.intervalMs)) ? Number(options.intervalMs) : 180;
@@ -791,19 +791,17 @@
791
791
  }
792
792
  const trackedChanges = [];
793
793
  if (observeTrackedChanges) {
794
- const trackedDiff = forbidTrackedChanges
795
- ? await waitForTrackedChangeDiff(trackedBefore, operationPaths, {
796
- waitMs: 3600,
797
- intervalMs: 180
798
- })
799
- : (() => null)();
800
- if (trackedDiff) {
801
- trackedChanges.push(...trackedDiff.trackedChanges);
802
- } else {
803
- await delay(120);
804
- const trackedAfter = collectTrackedChangeRefsForPaths(operationPaths);
805
- trackedChanges.push(...diffTrackedChangeRefs(trackedBefore, trackedAfter));
806
- }
794
+ // Overleaf renders review markers asynchronously after the editor text
795
+ // has already changed. A single 120 ms snapshot intermittently missed
796
+ // those markers, leaving a Reviewing write with Undo but no Accept.
797
+ // Poll both paths: normal Reviewing writes get a shorter capture window,
798
+ // while Accept replay keeps the longer safety window used to prove that
799
+ // it did not create fresh tracked changes.
800
+ const trackedDiff = await waitForTrackedChangeDiff(trackedBefore, operationPaths, {
801
+ waitMs: forbidTrackedChanges ? 3600 : 1800,
802
+ intervalMs: 180
803
+ });
804
+ trackedChanges.push(...trackedDiff.trackedChanges);
807
805
  if (forbidTrackedChanges && trackedChanges.length > 0) {
808
806
  return {
809
807
  ok: false,
@@ -1707,20 +1705,6 @@
1707
1705
  }
1708
1706
 
1709
1707
 
1710
- function diffTrackedChangeRefs(before = [], after = []) {
1711
- const beforeKeys = new Set((before || []).map(ref => ref.key).filter(Boolean));
1712
- const seen = new Set();
1713
- const added = [];
1714
- for (const ref of after || []) {
1715
- if (!ref?.key || beforeKeys.has(ref.key) || seen.has(ref.key)) {
1716
- continue;
1717
- }
1718
- seen.add(ref.key);
1719
- added.push(ref);
1720
- }
1721
- return added;
1722
- }
1723
-
1724
1708
  function mergeTrackedChangeRefs(refs = []) {
1725
1709
  return normalizeTrackedChangeRefs(refs);
1726
1710
  }
@@ -7,12 +7,12 @@
7
7
  })(typeof globalThis !== 'undefined' ? globalThis : window, function compatibilityFactory() {
8
8
  'use strict';
9
9
 
10
- const EXTENSION_PROTOCOL_VERSION = 1;
11
- const SUPPORTED_NATIVE_PROTOCOL = Object.freeze({ min: 1, max: 1 });
10
+ const EXTENSION_PROTOCOL_VERSION = 2;
11
+ const SUPPORTED_NATIVE_PROTOCOL = Object.freeze({ min: 1, max: 2 });
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.12';
15
+ const BUILD_TARGET_VERSION = '2.0.0';
16
16
  const DEFAULT_CHROME_EXTENSION_ID = 'illdpneeeopfffmiepaejglgmhpmdhdc';
17
17
  const REQUIRED_CAPABILITIES = Object.freeze([
18
18
  'bridgePing',
@@ -153,7 +153,7 @@
153
153
  return { status: 'native_too_old', classification: 'incompatible' };
154
154
  }
155
155
 
156
- if (!reportsProtocolOne(native)) {
156
+ if (!reportsSupportedProtocol(native)) {
157
157
  return { status: 'protocol_unsupported', classification: 'incompatible' };
158
158
  }
159
159
 
@@ -233,8 +233,10 @@
233
233
  return requiredCapabilities.filter(capability => capabilities[capability] !== true);
234
234
  }
235
235
 
236
- function reportsProtocolOne(native) {
237
- if (native.protocolVersion !== EXTENSION_PROTOCOL_VERSION) {
236
+ function reportsSupportedProtocol(native) {
237
+ if (!Number.isInteger(native.protocolVersion) ||
238
+ native.protocolVersion < SUPPORTED_NATIVE_PROTOCOL.min ||
239
+ native.protocolVersion > SUPPORTED_NATIVE_PROTOCOL.max) {
238
240
  return false;
239
241
  }
240
242
  if (native.supportedProtocol === undefined || native.supportedProtocol === null) {
@@ -1,13 +1,17 @@
1
1
  (function initStorageDb(root, factory) {
2
2
  if (typeof module === 'object' && module.exports) {
3
- module.exports = factory();
3
+ module.exports = factory(require('./storageRunActions'));
4
4
  } else {
5
- root.CodexOverleafStorageDb = factory();
5
+ root.CodexOverleafStorageDb = factory(root.CodexOverleafStorageRunActions);
6
6
  }
7
- })(typeof globalThis !== 'undefined' ? globalThis : window, function storageDbFactory() {
7
+ })(typeof globalThis !== 'undefined' ? globalThis : window, function storageDbFactory(StorageRunActions) {
8
8
  'use strict';
9
-
10
- var TARGET_SCHEMA_VERSION = 2;
9
+ if (!StorageRunActions?.compactRunsForStorage || !StorageRunActions?.compactRunActionPayload) {
10
+ throw new Error('Codex Overleaf storage run-action helpers are unavailable.');
11
+ }
12
+ // IndexedDB versions are monotonic; v2.0 RC profiles have already opened v3.
13
+ // Lowering it hides otherwise-intact session history behind fallback state.
14
+ var TARGET_SCHEMA_VERSION = 3;
11
15
  var DB_NAME = 'codex-overleaf';
12
16
  var CUSTOM_INSTRUCTIONS_MAX_CHARS = 12000;
13
17
  var PROJECT_PREF_KEY_MAX_CHARS = 160;
@@ -235,7 +239,8 @@
235
239
 
236
240
  // --- Record builders ---
237
241
 
238
- function buildSessionRecord(input) {
242
+ function buildSessionRecord(input, options) {
243
+ options = options || {};
239
244
  var now = new Date().toISOString();
240
245
  var titleSource = input.titleSource === 'manual' ? 'manual' : 'auto';
241
246
  var updatedAt = typeof input.updatedAt === 'string' ? input.updatedAt : now;
@@ -268,7 +273,7 @@
268
273
  status: typeof input.status === 'string' && input.status ? input.status : 'active',
269
274
  focusFiles: normalizePathList(input.focusFiles),
270
275
  history: compactHistoryForStorage(input.history),
271
- runs: compactRunsForStorage(input.runs),
276
+ runs: compactRunsForStorage(input.runs, options),
272
277
  task: normalizeDisplayTextForStorage(input.task, SESSION_STORAGE_LIMITS.taskChars),
273
278
  mode: typeof input.mode === 'string' ? input.mode : '',
274
279
  model: typeof input.model === 'string' ? input.model : '',
@@ -628,14 +633,17 @@
628
633
  });
629
634
  }
630
635
 
631
- function compactRunsForStorage(runs) {
632
- return (Array.isArray(runs) ? runs : [])
633
- .filter(function (run) { return run && typeof run.id === 'string'; })
634
- .slice(-SESSION_STORAGE_LIMITS.maxRunsPerSession)
635
- .map(compactRunForStorage);
636
+ function compactRunsForStorage(runs, options) {
637
+ return StorageRunActions.compactRunsForStorage(
638
+ runs,
639
+ options,
640
+ SESSION_STORAGE_LIMITS.maxRunsPerSession,
641
+ compactRunForStorage
642
+ );
636
643
  }
637
644
 
638
- function compactRunForStorage(run) {
645
+ function compactRunForStorage(run, keepActionPayload) {
646
+ var actionPayload = StorageRunActions.compactRunActionPayload(run, keepActionPayload);
639
647
  var compact = {
640
648
  id: run.id,
641
649
  task: normalizeDisplayTextForStorage(run.task || 'untitled task', SESSION_STORAGE_LIMITS.taskChars),
@@ -650,11 +658,11 @@
650
658
  finishedAt: typeof run.finishedAt === 'string' ? redactSecretLikeText(run.finishedAt) : '',
651
659
  events: compactRunEventsForStorage(run.events),
652
660
  attachments: compactRunAttachmentsForStorage(run.attachments),
653
- appliedOperations: [],
654
- undoOperations: [],
655
- undoBaseFiles: [],
656
- undoTrackedChanges: [],
657
- undoExpectedFiles: [],
661
+ appliedOperations: actionPayload.appliedOperations,
662
+ undoOperations: actionPayload.undoOperations,
663
+ undoBaseFiles: actionPayload.undoBaseFiles,
664
+ undoTrackedChanges: actionPayload.undoTrackedChanges,
665
+ undoExpectedFiles: actionPayload.undoExpectedFiles,
658
666
  undoStatus: normalizeDisplayTextForStorage(run.undoStatus, SESSION_STORAGE_LIMITS.statusTextChars)
659
667
  };
660
668
  if (VALID_TRACKED_CHANGE_STATUSES[run.trackedChangeStatus] === true) {
@@ -0,0 +1,99 @@
1
+ (function initStorageRunActions(root, factory) {
2
+ if (typeof module === 'object' && module.exports) {
3
+ module.exports = factory();
4
+ } else {
5
+ root.CodexOverleafStorageRunActions = factory();
6
+ }
7
+ })(typeof globalThis !== 'undefined' ? globalThis : window, function storageRunActionsFactory() {
8
+ 'use strict';
9
+
10
+ var MAX_PERSISTED_ACTION_RUNS_PER_SESSION = 2;
11
+ var MAX_PERSISTED_ACTION_BYTES_PER_RUN = 320 * 1024;
12
+
13
+ function compactRunsForStorage(runs, options, maxRuns, compactRun) {
14
+ if (typeof compactRun !== 'function') {
15
+ throw new TypeError('compactRun must be a function.');
16
+ }
17
+ var selectedRuns = (Array.isArray(runs) ? runs : [])
18
+ .filter(function (run) { return run && typeof run.id === 'string'; })
19
+ .slice(-Math.max(0, Number(maxRuns) || 0));
20
+ var actionRunIds = new Set();
21
+ if (options && options.preserveRunActionPayload === true) {
22
+ for (var index = selectedRuns.length - 1;
23
+ index >= 0 && actionRunIds.size < MAX_PERSISTED_ACTION_RUNS_PER_SESSION;
24
+ index -= 1) {
25
+ if (hasReloadableRunActionPayload(selectedRuns[index])) {
26
+ actionRunIds.add(selectedRuns[index].id);
27
+ }
28
+ }
29
+ }
30
+ return selectedRuns.map(function (run) {
31
+ return compactRun(run, actionRunIds.has(run.id));
32
+ });
33
+ }
34
+
35
+ function hasReloadableRunActionPayload(run) {
36
+ var trackedStatus = run && run.trackedChangeStatus;
37
+ var trackedLifecycle = (trackedStatus === 'pending' || trackedStatus === 'needs_review')
38
+ && Array.isArray(run.undoTrackedChanges) && run.undoTrackedChanges.length > 0
39
+ && Array.isArray(run.undoExpectedFiles) && run.undoExpectedFiles.length > 0
40
+ && Array.isArray(run.appliedOperations) && run.appliedOperations.length > 0;
41
+ var legacyUndo = Array.isArray(run && run.undoOperations) && run.undoOperations.length > 0;
42
+ return trackedLifecycle || legacyUndo;
43
+ }
44
+
45
+ function compactRunActionPayload(run, keepActionPayload) {
46
+ var empty = emptyActionPayload();
47
+ if (!keepActionPayload || !hasReloadableRunActionPayload(run)) {
48
+ return empty;
49
+ }
50
+ var payload = {
51
+ appliedOperations: cloneSerializableArray(run.appliedOperations),
52
+ undoOperations: cloneSerializableArray(run.undoOperations),
53
+ undoBaseFiles: cloneSerializableArray(run.undoBaseFiles),
54
+ undoTrackedChanges: cloneSerializableArray(run.undoTrackedChanges),
55
+ undoExpectedFiles: cloneSerializableArray(run.undoExpectedFiles)
56
+ };
57
+ var serialized;
58
+ try {
59
+ serialized = JSON.stringify(payload);
60
+ } catch (_error) {
61
+ return empty;
62
+ }
63
+ return getUtf8ByteLength(serialized) <= MAX_PERSISTED_ACTION_BYTES_PER_RUN ? payload : empty;
64
+ }
65
+
66
+ function emptyActionPayload() {
67
+ return {
68
+ appliedOperations: [],
69
+ undoOperations: [],
70
+ undoBaseFiles: [],
71
+ undoTrackedChanges: [],
72
+ undoExpectedFiles: []
73
+ };
74
+ }
75
+
76
+ function cloneSerializableArray(value) {
77
+ if (!Array.isArray(value)) {
78
+ return [];
79
+ }
80
+ try {
81
+ var clone = JSON.parse(JSON.stringify(value));
82
+ return Array.isArray(clone) ? clone : [];
83
+ } catch (_error) {
84
+ return [];
85
+ }
86
+ }
87
+
88
+ function getUtf8ByteLength(value) {
89
+ if (typeof TextEncoder === 'function') {
90
+ return new TextEncoder().encode(value).byteLength;
91
+ }
92
+ return value.length * 2;
93
+ }
94
+
95
+ return {
96
+ compactRunsForStorage: compactRunsForStorage,
97
+ compactRunActionPayload: compactRunActionPayload
98
+ };
99
+ });
@@ -48,7 +48,7 @@ async function handleRequest(request, env = process.env, emit = () => {}) {
48
48
  return okResponse(request.id, {
49
49
  host: HOST_NAME,
50
50
  platform: getNativeRuntimePlatform({ env }),
51
- protocolVersion: 1,
51
+ protocolVersion: 2,
52
52
  supportedProtocol: { ...SUPPORTED_NATIVE_PROTOCOL },
53
53
  capabilities: Object.fromEntries(REQUIRED_CAPABILITIES.map(capability => [capability, true])),
54
54
  minExtensionVersion: MIN_COMPATIBLE_EXTENSION_VERSION,
@@ -58,7 +58,8 @@ function validateReleaseManifest(manifest, options = {}) {
58
58
  throw updateError('update_manifest_origin_mismatch', 'Update manifest repository or channel does not match this installation.');
59
59
  }
60
60
  const version = parseSemver(manifest.version);
61
- if (!version || manifest.tag !== 'v' + manifest.version) {
61
+ const expectedTag = options.tag || 'v' + manifest.version;
62
+ if (!version || manifest.tag !== expectedTag) {
62
63
  throw updateError('update_manifest_version_invalid', 'Update manifest version or tag is invalid.');
63
64
  }
64
65
  if (!Number.isInteger(manifest.bootstrapProtocol) || manifest.bootstrapProtocol !== bootstrapProtocol) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codex-overleaf-link",
3
- "version": "1.9.12",
3
+ "version": "2.0.0",
4
4
  "description": "Cross-platform Chrome bridge that connects Codex to the active Overleaf project.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",