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.
- package/LICENSE +21 -0
- package/README.md +457 -0
- package/bin/codex-overleaf-link.mjs +223 -0
- package/extension/src/shared/agentTranscript.js +1175 -0
- package/extension/src/shared/auditRecords.js +568 -0
- package/extension/src/shared/compatibility.js +372 -0
- package/extension/src/shared/compileAdapter.js +176 -0
- package/extension/src/shared/governanceRules.js +252 -0
- package/extension/src/shared/i18n.js +565 -0
- package/extension/src/shared/models.js +106 -0
- package/extension/src/shared/otText.js +505 -0
- package/extension/src/shared/projectFiles.js +180 -0
- package/extension/src/shared/reviewing.js +99 -0
- package/extension/src/shared/sensitiveScan.js +116 -0
- package/extension/src/shared/sessionState.js +1084 -0
- package/extension/src/shared/staleGuard.js +150 -0
- package/extension/src/shared/storageDb.js +986 -0
- package/extension/src/shared/storageKeys.js +29 -0
- package/extension/src/shared/storageMigration.js +168 -0
- package/extension/src/shared/summary.js +248 -0
- package/extension/src/shared/undoOperations.js +369 -0
- package/native-host/src/codexArgs.js +43 -0
- package/native-host/src/codexHome.js +538 -0
- package/native-host/src/codexModels.js +247 -0
- package/native-host/src/codexPrompt.js +192 -0
- package/native-host/src/codexPromptAssembly.js +411 -0
- package/native-host/src/codexSessionRunner.js +1247 -0
- package/native-host/src/commandApproval.js +914 -0
- package/native-host/src/debugLog.js +78 -0
- package/native-host/src/diffEngine.js +247 -0
- package/native-host/src/index.js +132 -0
- package/native-host/src/launcher.js +81 -0
- package/native-host/src/localSkills.js +476 -0
- package/native-host/src/manifest.js +226 -0
- package/native-host/src/mirrorSensitiveScan.js +119 -0
- package/native-host/src/mirrorWorkspace.js +1019 -0
- package/native-host/src/nativeDoctor.js +826 -0
- package/native-host/src/nativeEnvironment.js +315 -0
- package/native-host/src/nativeHostPlatform.js +112 -0
- package/native-host/src/nativeMessaging.js +60 -0
- package/native-host/src/nativeQuotas.js +294 -0
- package/native-host/src/nativeResponseBudget.js +194 -0
- package/native-host/src/runtimeInstaller.js +357 -0
- package/native-host/src/taskRunner.js +3 -0
- package/native-host/src/taskRunnerRuntime.js +1083 -0
- package/native-host/src/textPatch.js +287 -0
- package/package.json +40 -0
- package/scripts/codex-json-agent.mjs +269 -0
- package/scripts/install-native-host.mjs +255 -0
- package/scripts/npm-package-files-v1.1.1.txt +52 -0
- package/scripts/uninstall-native-host.mjs +298 -0
- package/scripts/verify-npm-package.mjs +296 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
(function initGovernanceRules(root, factory) {
|
|
2
|
+
if (typeof module === 'object' && module.exports) {
|
|
3
|
+
let projectFiles = null;
|
|
4
|
+
try {
|
|
5
|
+
projectFiles = require('./projectFiles');
|
|
6
|
+
} catch (_error) {
|
|
7
|
+
projectFiles = null;
|
|
8
|
+
}
|
|
9
|
+
module.exports = factory(projectFiles);
|
|
10
|
+
} else {
|
|
11
|
+
root.CodexOverleafGovernanceRules = factory(root.CodexOverleafProjectFiles);
|
|
12
|
+
}
|
|
13
|
+
})(typeof globalThis !== 'undefined' ? globalThis : window, function governanceRulesFactory(projectFiles) {
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
const WRITE_OPERATION_TYPES = new Set([
|
|
17
|
+
'edit',
|
|
18
|
+
'create',
|
|
19
|
+
'delete',
|
|
20
|
+
'rename',
|
|
21
|
+
'move',
|
|
22
|
+
'binary-create',
|
|
23
|
+
'overwrite-binary'
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
function normalizeGovernanceRules(rules = {}) {
|
|
27
|
+
return {
|
|
28
|
+
readonlyPatterns: normalizePatternList(rules.readonlyPatterns),
|
|
29
|
+
writablePatterns: normalizePatternList(rules.writablePatterns),
|
|
30
|
+
sensitiveCheckEnabled: rules.sensitiveCheckEnabled !== false,
|
|
31
|
+
sensitiveConfirmAllowed: rules.sensitiveConfirmAllowed === true
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function normalizePatternList(patterns) {
|
|
36
|
+
if (!Array.isArray(patterns)) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const result = [];
|
|
41
|
+
const seen = new Set();
|
|
42
|
+
for (const pattern of patterns) {
|
|
43
|
+
if (typeof pattern !== 'string') {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const normalized = normalizeProjectPath(pattern);
|
|
47
|
+
if (!normalized || seen.has(normalized)) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
seen.add(normalized);
|
|
51
|
+
result.push(normalized);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function evaluateGovernedOperations(operations, rules = {}) {
|
|
57
|
+
const normalizedRules = normalizeGovernanceRules(rules);
|
|
58
|
+
const allowed = [];
|
|
59
|
+
const blocked = [];
|
|
60
|
+
|
|
61
|
+
for (const operation of Array.isArray(operations) ? operations : []) {
|
|
62
|
+
const normalizedOperation = normalizeOperation(operation);
|
|
63
|
+
if (!isWriteOperation(normalizedOperation.type)) {
|
|
64
|
+
allowed.push(normalizedOperation);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const invalidPath = getInvalidOperationProjectPath(normalizedOperation);
|
|
69
|
+
if (invalidPath) {
|
|
70
|
+
blocked.push({ operation: normalizedOperation, reason: 'invalid_project_path', path: invalidPath });
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const paths = getOperationPaths(normalizedOperation);
|
|
75
|
+
const readonlyPath = paths.find(path => matchesAnyPattern(path, normalizedRules.readonlyPatterns));
|
|
76
|
+
if (readonlyPath) {
|
|
77
|
+
blocked.push({ operation: normalizedOperation, reason: 'readonly', path: readonlyPath });
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (
|
|
82
|
+
normalizedRules.writablePatterns.length > 0 &&
|
|
83
|
+
paths.some(path => !matchesAnyPattern(path, normalizedRules.writablePatterns))
|
|
84
|
+
) {
|
|
85
|
+
blocked.push({ operation: normalizedOperation, reason: 'writable_allowlist' });
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
allowed.push(normalizedOperation);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return { allowed, blocked, rules: normalizedRules };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function normalizeOperation(operation = {}) {
|
|
96
|
+
const result = Object.assign({}, operation);
|
|
97
|
+
result.type = typeof operation.type === 'string' ? operation.type : '';
|
|
98
|
+
result.path = normalizeSafeOperationPath(operation.path);
|
|
99
|
+
if (operation.path !== undefined && String(operation.path || '').trim() && !result.path) {
|
|
100
|
+
result.invalidProjectPath = true;
|
|
101
|
+
}
|
|
102
|
+
if (operation.destinationPath !== undefined) {
|
|
103
|
+
result.destinationPath = normalizeSafeOperationPath(operation.destinationPath);
|
|
104
|
+
if (String(operation.destinationPath || '').trim() && !result.destinationPath) {
|
|
105
|
+
result.invalidProjectDestinationPath = true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (operation.destPath !== undefined && !result.destinationPath) {
|
|
109
|
+
result.destinationPath = normalizeSafeOperationPath(operation.destPath);
|
|
110
|
+
if (String(operation.destPath || '').trim() && !result.destinationPath) {
|
|
111
|
+
result.invalidProjectDestinationPath = true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (operation.to !== undefined && !result.destinationPath) {
|
|
115
|
+
result.destinationPath = normalizeSafeOperationPath(operation.to);
|
|
116
|
+
if (String(operation.to || '').trim() && !result.destinationPath) {
|
|
117
|
+
result.invalidProjectDestinationPath = true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function getInvalidOperationProjectPath(operation = {}) {
|
|
124
|
+
if (operation.invalidProjectPath || !operation.path) {
|
|
125
|
+
return 'operation path';
|
|
126
|
+
}
|
|
127
|
+
if ((operation.type === 'rename' || operation.type === 'move')
|
|
128
|
+
&& (operation.invalidProjectDestinationPath || !operation.destinationPath)) {
|
|
129
|
+
return 'operation destination path';
|
|
130
|
+
}
|
|
131
|
+
return '';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function getOperationPaths(operation) {
|
|
135
|
+
const paths = [];
|
|
136
|
+
if (operation.path) {
|
|
137
|
+
paths.push(operation.path);
|
|
138
|
+
}
|
|
139
|
+
if ((operation.type === 'rename' || operation.type === 'move') && operation.destinationPath) {
|
|
140
|
+
paths.push(operation.destinationPath);
|
|
141
|
+
}
|
|
142
|
+
return paths;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function isWriteOperation(type) {
|
|
146
|
+
return WRITE_OPERATION_TYPES.has(type);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function matchesAnyPattern(path, patterns) {
|
|
150
|
+
return patterns.some(pattern => matchesGovernancePattern(path, pattern));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function matchesGovernancePattern(path, pattern) {
|
|
154
|
+
const normalizedPath = normalizeProjectPath(path);
|
|
155
|
+
const normalizedPattern = normalizeProjectPath(pattern);
|
|
156
|
+
if (!normalizedPath || !normalizedPattern) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
const regex = new RegExp('^' + globToRegex(normalizedPattern) + '$');
|
|
160
|
+
return regex.test(normalizedPath);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function globToRegex(pattern) {
|
|
164
|
+
let regex = '';
|
|
165
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
166
|
+
const char = pattern[i];
|
|
167
|
+
if (char === '*') {
|
|
168
|
+
if (pattern[i + 1] === '*') {
|
|
169
|
+
regex += '.*';
|
|
170
|
+
i++;
|
|
171
|
+
} else {
|
|
172
|
+
regex += '[^/]*';
|
|
173
|
+
}
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (char === '?') {
|
|
177
|
+
regex += '[^/]';
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
regex += escapeRegex(char);
|
|
181
|
+
}
|
|
182
|
+
return regex;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function escapeRegex(value) {
|
|
186
|
+
return String(value).replace(/[|\\{}()[\]^$+?.]/g, '\\$&');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function normalizeProjectPath(path) {
|
|
190
|
+
return String(path || '')
|
|
191
|
+
.replace(/\s+/g, ' ')
|
|
192
|
+
.replace(/\\/g, '/')
|
|
193
|
+
.trim()
|
|
194
|
+
.replace(/^\/+/, '')
|
|
195
|
+
.replace(/\/+/g, '/');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function normalizeSafeOperationPath(path) {
|
|
199
|
+
if (projectFiles && typeof projectFiles.normalizeSafeProjectPath === 'function') {
|
|
200
|
+
return projectFiles.normalizeSafeProjectPath(path);
|
|
201
|
+
}
|
|
202
|
+
return normalizeSafeProjectPathFallback(path);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function normalizeSafeProjectPathFallback(value) {
|
|
206
|
+
if (typeof value !== 'string' || /[\u0000-\u001f\u007f]/.test(value)) {
|
|
207
|
+
return '';
|
|
208
|
+
}
|
|
209
|
+
const trimmed = value.trim();
|
|
210
|
+
if (!trimmed || trimmed.startsWith('/') || trimmed.includes('\\') || /^[A-Za-z]:/.test(trimmed)) {
|
|
211
|
+
return '';
|
|
212
|
+
}
|
|
213
|
+
let decoded = trimmed;
|
|
214
|
+
for (let index = 0; index < 3; index += 1) {
|
|
215
|
+
if (/%(?:2f|5c)/i.test(decoded)) {
|
|
216
|
+
return '';
|
|
217
|
+
}
|
|
218
|
+
let next;
|
|
219
|
+
try {
|
|
220
|
+
next = decodeURIComponent(decoded);
|
|
221
|
+
} catch (_error) {
|
|
222
|
+
return '';
|
|
223
|
+
}
|
|
224
|
+
if (next === decoded) {
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
decoded = next;
|
|
228
|
+
}
|
|
229
|
+
if (/[\u0000-\u001f\u007f]/.test(decoded)
|
|
230
|
+
|| decoded.startsWith('/')
|
|
231
|
+
|| decoded.includes('\\')
|
|
232
|
+
|| /^[A-Za-z]:/.test(decoded)) {
|
|
233
|
+
return '';
|
|
234
|
+
}
|
|
235
|
+
const normalized = decoded.replace(/\/+/g, '/').trim();
|
|
236
|
+
if (!normalized) {
|
|
237
|
+
return '';
|
|
238
|
+
}
|
|
239
|
+
const segments = normalized.split('/');
|
|
240
|
+
return segments.some(segment => !segment || segment === '.' || segment === '..')
|
|
241
|
+
? ''
|
|
242
|
+
: normalized;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
WRITE_OPERATION_TYPES,
|
|
247
|
+
normalizeGovernanceRules,
|
|
248
|
+
normalizeProjectPath,
|
|
249
|
+
matchesGovernancePattern,
|
|
250
|
+
evaluateGovernedOperations
|
|
251
|
+
};
|
|
252
|
+
});
|