codex-overleaf-link 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +457 -0
  3. package/bin/codex-overleaf-link.mjs +223 -0
  4. package/extension/src/shared/agentTranscript.js +1175 -0
  5. package/extension/src/shared/auditRecords.js +568 -0
  6. package/extension/src/shared/compatibility.js +372 -0
  7. package/extension/src/shared/compileAdapter.js +176 -0
  8. package/extension/src/shared/governanceRules.js +252 -0
  9. package/extension/src/shared/i18n.js +565 -0
  10. package/extension/src/shared/models.js +106 -0
  11. package/extension/src/shared/otText.js +505 -0
  12. package/extension/src/shared/projectFiles.js +180 -0
  13. package/extension/src/shared/reviewing.js +99 -0
  14. package/extension/src/shared/sensitiveScan.js +116 -0
  15. package/extension/src/shared/sessionState.js +1084 -0
  16. package/extension/src/shared/staleGuard.js +150 -0
  17. package/extension/src/shared/storageDb.js +986 -0
  18. package/extension/src/shared/storageKeys.js +29 -0
  19. package/extension/src/shared/storageMigration.js +168 -0
  20. package/extension/src/shared/summary.js +248 -0
  21. package/extension/src/shared/undoOperations.js +369 -0
  22. package/native-host/src/codexArgs.js +43 -0
  23. package/native-host/src/codexHome.js +538 -0
  24. package/native-host/src/codexModels.js +247 -0
  25. package/native-host/src/codexPrompt.js +192 -0
  26. package/native-host/src/codexPromptAssembly.js +411 -0
  27. package/native-host/src/codexSessionRunner.js +1247 -0
  28. package/native-host/src/commandApproval.js +914 -0
  29. package/native-host/src/debugLog.js +78 -0
  30. package/native-host/src/diffEngine.js +247 -0
  31. package/native-host/src/index.js +132 -0
  32. package/native-host/src/launcher.js +81 -0
  33. package/native-host/src/localSkills.js +476 -0
  34. package/native-host/src/manifest.js +226 -0
  35. package/native-host/src/mirrorSensitiveScan.js +119 -0
  36. package/native-host/src/mirrorWorkspace.js +1019 -0
  37. package/native-host/src/nativeDoctor.js +826 -0
  38. package/native-host/src/nativeEnvironment.js +315 -0
  39. package/native-host/src/nativeHostPlatform.js +112 -0
  40. package/native-host/src/nativeMessaging.js +60 -0
  41. package/native-host/src/nativeQuotas.js +294 -0
  42. package/native-host/src/nativeResponseBudget.js +194 -0
  43. package/native-host/src/runtimeInstaller.js +357 -0
  44. package/native-host/src/taskRunner.js +3 -0
  45. package/native-host/src/taskRunnerRuntime.js +1083 -0
  46. package/native-host/src/textPatch.js +287 -0
  47. package/package.json +40 -0
  48. package/scripts/codex-json-agent.mjs +269 -0
  49. package/scripts/install-native-host.mjs +255 -0
  50. package/scripts/npm-package-files-v1.1.1.txt +52 -0
  51. package/scripts/uninstall-native-host.mjs +298 -0
  52. package/scripts/verify-npm-package.mjs +296 -0
@@ -0,0 +1,150 @@
1
+ (function initStaleGuard(root, factory) {
2
+ if (typeof module === 'object' && module.exports) {
3
+ module.exports = factory();
4
+ } else {
5
+ root.CodexOverleafStaleGuard = factory();
6
+ }
7
+ })(typeof globalThis !== 'undefined' ? globalThis : window, function staleGuardFactory() {
8
+ 'use strict';
9
+
10
+ function buildBaseFileLookup(files) {
11
+ if (!Array.isArray(files) || files.length === 0) {
12
+ return null;
13
+ }
14
+
15
+ const lookup = new Map();
16
+ for (const file of files) {
17
+ if (typeof file?.path === 'string') {
18
+ const path = normalizePath(file.path);
19
+ if (path) {
20
+ lookup.set(path, normalizeText(file.content));
21
+ }
22
+ }
23
+ }
24
+ return lookup.size ? lookup : null;
25
+ }
26
+
27
+ function checkOperationFreshness(operation, currentContent, baseFileLookup) {
28
+ if (!baseFileLookup || operation?.type !== 'edit') {
29
+ return { ok: true };
30
+ }
31
+
32
+ const filePath = normalizePath(operation.path);
33
+ if (!filePath || !baseFileLookup.has(filePath)) {
34
+ return {
35
+ ok: false,
36
+ code: 'missing_base_file',
37
+ reasonKey: 'missingBaseFile',
38
+ reasonParams: { filePath },
39
+ reason: `${filePath || '这个文件'} 在任务开始时没有被 Codex 读到。Codex 没有覆盖它;请刷新项目内容后重试。`
40
+ };
41
+ }
42
+
43
+ const baseContent = baseFileLookup.get(filePath);
44
+ const current = normalizeText(currentContent);
45
+ if (current !== baseContent) {
46
+ const patchRangeFreshness = checkPatchRangeFreshness(operation, current);
47
+ if (patchRangeFreshness) {
48
+ return patchRangeFreshness;
49
+ }
50
+ return {
51
+ ok: false,
52
+ code: 'stale_snapshot',
53
+ reasonKey: 'staleSnapshot',
54
+ reasonParams: { filePath },
55
+ reason: `${filePath} 在任务执行期间被你或协作者改过,Codex 没有覆盖它。请查看差异后重试。`
56
+ };
57
+ }
58
+
59
+ return { ok: true };
60
+ }
61
+
62
+ function checkPatchRangeFreshness(operation, currentContent) {
63
+ const patches = Array.isArray(operation?.patches) ? operation.patches : [];
64
+ if (!patches.length) {
65
+ return null;
66
+ }
67
+
68
+ const current = normalizeText(currentContent);
69
+ for (const rawPatch of patches) {
70
+ const from = Number(rawPatch?.from);
71
+ const to = Number(rawPatch?.to);
72
+ const expected = String(rawPatch?.expected ?? '');
73
+ if (!Number.isInteger(from) || !Number.isInteger(to) || from < 0 || to < from || to > current.length) {
74
+ return {
75
+ ok: false,
76
+ code: 'stale_patch_range',
77
+ reasonKey: 'stalePatchLocation',
78
+ reason: 'Codex 要修改的位置已经无法和当前 Overleaf 内容对齐,所以没有写入。请重新运行任务。'
79
+ };
80
+ }
81
+ if (current.slice(from, to) !== expected) {
82
+ return {
83
+ ok: false,
84
+ code: 'stale_patch_range',
85
+ reasonKey: 'stalePatchConflict',
86
+ reason: 'Codex 要修改的具体位置已经被你或协作者改过,所以没有覆盖它。请查看差异后重试。'
87
+ };
88
+ }
89
+ }
90
+
91
+ return {
92
+ ok: true,
93
+ reconciled: true,
94
+ strategy: 'patch-range'
95
+ };
96
+ }
97
+
98
+ function updateExpectedFileContent(baseFileLookup, filePath, content) {
99
+ const path = normalizePath(filePath);
100
+ if (!baseFileLookup || !path) {
101
+ return;
102
+ }
103
+ baseFileLookup.set(path, normalizeText(content));
104
+ }
105
+
106
+ function removeExpectedFile(baseFileLookup, filePath) {
107
+ const path = normalizePath(filePath);
108
+ if (!baseFileLookup || !path) {
109
+ return;
110
+ }
111
+ baseFileLookup.delete(path);
112
+ }
113
+
114
+ function moveExpectedFile(baseFileLookup, fromPath, toPath) {
115
+ const from = normalizePath(fromPath);
116
+ const to = normalizePath(toPath);
117
+ if (!baseFileLookup || !from || !to) {
118
+ return;
119
+ }
120
+ if (!baseFileLookup.has(from)) {
121
+ return;
122
+ }
123
+ const content = baseFileLookup.get(from);
124
+ baseFileLookup.delete(from);
125
+ baseFileLookup.set(to, content);
126
+ }
127
+
128
+ function normalizeText(value) {
129
+ return String(value ?? '').replace(/\r\n/g, '\n');
130
+ }
131
+
132
+ function normalizePath(value) {
133
+ return String(value || '')
134
+ .replace(/\s+/g, ' ')
135
+ .replace(/\\/g, '/')
136
+ .trim()
137
+ .replace(/^\/+/, '');
138
+ }
139
+
140
+ return {
141
+ buildBaseFileLookup,
142
+ checkOperationFreshness,
143
+ updateExpectedFileContent,
144
+ removeExpectedFile,
145
+ moveExpectedFile,
146
+ checkPatchRangeFreshness,
147
+ normalizeText,
148
+ normalizePath
149
+ };
150
+ });