@myagentroam/node 0.9.9 → 0.9.11

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 (214) hide show
  1. package/dist/capabilities.js +2 -92
  2. package/dist/claude-agent-sdk.js +2 -330
  3. package/dist/claude-channel.js +2 -44
  4. package/dist/codex-app-server.js +2 -503
  5. package/dist/config.js +2 -56
  6. package/dist/connector/node-connector-options.js +2 -1
  7. package/dist/connector/node-operation-router.js +2 -22
  8. package/dist/connector.js +2 -845
  9. package/dist/control-outbound-scheduler.js +2 -154
  10. package/dist/database.js +2 -1418
  11. package/dist/event-buffer.js +2 -19
  12. package/dist/fake-runner.js +2 -129
  13. package/dist/health.js +2 -3
  14. package/dist/main.js +2 -54
  15. package/dist/migrations/v001.js +3 -144
  16. package/dist/migrations/v002.js +2 -143
  17. package/dist/migrations/v003.js +2 -44
  18. package/dist/migrations/v004.js +34 -30
  19. package/dist/native-jsonl-reader.js +2 -186
  20. package/dist/native-session-history.js +2 -1119
  21. package/dist/opencode-runtime.js +2 -80
  22. package/dist/opencode-server.js +2 -263
  23. package/dist/operational.js +2 -122
  24. package/dist/process-tree.js +2 -18
  25. package/dist/rotating-log.js +2 -67
  26. package/dist/runner/abstract-runner.js +2 -232
  27. package/dist/runner/claude/managed-run-controller.js +2 -345
  28. package/dist/runner/claude-code-runner.js +2 -303
  29. package/dist/runner/codex/composer-image-markers.js +2 -0
  30. package/dist/runner/codex/conversation-parser.js +2 -861
  31. package/dist/runner/codex/managed-run-controller.js +2 -460
  32. package/dist/runner/codex-runner.js +2 -628
  33. package/dist/runner/fake-test-runner.js +2 -47
  34. package/dist/runner/opencode/conversation-parser.js +2 -221
  35. package/dist/runner/opencode/managed-run-controller.js +2 -537
  36. package/dist/runner/opencode-runner.js +2 -448
  37. package/dist/runner/runner-registry.js +2 -90
  38. package/dist/runner-command-engine.js +2 -70
  39. package/dist/runner-profiles.js +2 -215
  40. package/dist/runner-usage.js +2 -190
  41. package/dist/runtime-command-detector.js +2 -73
  42. package/dist/runtime-state.js +2 -982
  43. package/dist/service/attachment-domain-state.js +2 -7
  44. package/dist/service/conversation-history-service.js +2 -457
  45. package/dist/service/conversation-segment-service.js +2 -162
  46. package/dist/service/external-session-resume-service.js +2 -118
  47. package/dist/service/fake-managed-run-service.js +2 -60
  48. package/dist/service/managed-runner-session-service.js +2 -35
  49. package/dist/service/mcp-installation-verifier.js +2 -87
  50. package/dist/service/mcp-node-operation-service.js +2 -90
  51. package/dist/service/mcp-package-installer.js +2 -136
  52. package/dist/service/native-session-projection-service.js +2 -280
  53. package/dist/service/native-session-watch-service.js +2 -383
  54. package/dist/service/node-connection-lifecycle-service.js +2 -84
  55. package/dist/service/node-control-channel.js +2 -85
  56. package/dist/service/node-control-message-service.js +2 -107
  57. package/dist/service/node-request-service.js +2 -52
  58. package/dist/service/node-run-event-bridge.js +2 -83
  59. package/dist/service/node-terminal-channel.js +2 -182
  60. package/dist/service/node-upgrade-coordinator.js +2 -137
  61. package/dist/service/node-workspace-coordinator.js +2 -70
  62. package/dist/service/recent-run-projection-service.js +2 -78
  63. package/dist/service/run-attachment-service.js +2 -194
  64. package/dist/service/run-domain-state.js +2 -4
  65. package/dist/service/run-event-service.js +2 -193
  66. package/dist/service/run-workbench-service.js +2 -104
  67. package/dist/service/runner-channel-message-service.js +2 -20
  68. package/dist/service/runner-interaction-service.js +2 -243
  69. package/dist/service/runner-service.js +2 -71
  70. package/dist/service/session-catalog-service.js +2 -224
  71. package/dist/service/session-command-service.js +2 -76
  72. package/dist/service/session-context-service.js +2 -101
  73. package/dist/service/session-domain-state.js +2 -9
  74. package/dist/service/session-identity-service.js +2 -86
  75. package/dist/service/session-lifecycle-service.js +2 -240
  76. package/dist/service/session-message-service.js +2 -173
  77. package/dist/service/session-presentation-service.js +2 -43
  78. package/dist/service/session-query-service.js +2 -82
  79. package/dist/service/skill-directory-service.js +2 -238
  80. package/dist/service/skill-install-service.js +2 -434
  81. package/dist/service/skill-node-operation-service.js +2 -206
  82. package/dist/service/terminal-relay-state.js +2 -3
  83. package/dist/service/terminal-service.js +2 -52
  84. package/dist/service/workbench-event-service.js +2 -19
  85. package/dist/service/workbench-manifest-service.js +2 -69
  86. package/dist/service/workspace-change-service.js +2 -86
  87. package/dist/service/workspace-content-search-service.js +2 -477
  88. package/dist/service/workspace-domain-state.js +2 -41
  89. package/dist/service/workspace-file-service.js +2 -122
  90. package/dist/service/workspace-git-exclude-service.js +2 -119
  91. package/dist/service/workspace-queue-workbench-service.js +2 -304
  92. package/dist/service/workspace-service.js +2 -69
  93. package/dist/service/workspace-session-service.js +2 -139
  94. package/dist/service/workspace-upload-service.js +2 -262
  95. package/dist/service/workspace-watch-service.js +2 -146
  96. package/dist/service/workspace-workbench-service.js +2 -405
  97. package/dist/service.js +2 -38
  98. package/dist/storage.js +2 -32
  99. package/dist/supervisor.js +2 -136
  100. package/dist/terminal.js +2 -416
  101. package/dist/util/node-operation-parsers.js +2 -382
  102. package/dist/util/personal-instructions.js +2 -31
  103. package/dist/util/runner-error.js +2 -52
  104. package/dist/util/runner-native-session-parsers.js +2 -490
  105. package/dist/util/safe-error.js +2 -5
  106. package/dist/util/secret-environment.js +2 -25
  107. package/dist/workspace.js +2 -1519
  108. package/package.json +3 -3
  109. package/dist/capabilities.d.ts +0 -12
  110. package/dist/claude-agent-sdk.d.ts +0 -92
  111. package/dist/claude-channel.d.ts +0 -28
  112. package/dist/codex-app-server.d.ts +0 -133
  113. package/dist/config.d.ts +0 -18
  114. package/dist/connector/node-connector-options.d.ts +0 -27
  115. package/dist/connector/node-operation-router.d.ts +0 -9
  116. package/dist/connector.d.ts +0 -94
  117. package/dist/control-outbound-scheduler.d.ts +0 -29
  118. package/dist/database.d.ts +0 -305
  119. package/dist/event-buffer.d.ts +0 -9
  120. package/dist/fake-runner.d.ts +0 -42
  121. package/dist/health.d.ts +0 -4
  122. package/dist/main.d.ts +0 -2
  123. package/dist/migrations/v001.d.ts +0 -3
  124. package/dist/migrations/v002.d.ts +0 -4
  125. package/dist/migrations/v003.d.ts +0 -4
  126. package/dist/migrations/v004.d.ts +0 -4
  127. package/dist/native-jsonl-reader.d.ts +0 -35
  128. package/dist/native-session-history.d.ts +0 -126
  129. package/dist/opencode-runtime.d.ts +0 -33
  130. package/dist/opencode-server.d.ts +0 -49
  131. package/dist/operational.d.ts +0 -39
  132. package/dist/process-tree.d.ts +0 -9
  133. package/dist/rotating-log.d.ts +0 -17
  134. package/dist/runner/abstract-runner.d.ts +0 -172
  135. package/dist/runner/claude/managed-run-controller.d.ts +0 -51
  136. package/dist/runner/claude-code-runner.d.ts +0 -72
  137. package/dist/runner/codex/conversation-parser.d.ts +0 -59
  138. package/dist/runner/codex/managed-run-controller.d.ts +0 -90
  139. package/dist/runner/codex-runner.d.ts +0 -103
  140. package/dist/runner/fake-test-runner.d.ts +0 -26
  141. package/dist/runner/opencode/conversation-parser.d.ts +0 -31
  142. package/dist/runner/opencode/managed-run-controller.d.ts +0 -82
  143. package/dist/runner/opencode-runner.d.ts +0 -71
  144. package/dist/runner/runner-registry.d.ts +0 -19
  145. package/dist/runner-command-engine.d.ts +0 -28
  146. package/dist/runner-profiles.d.ts +0 -15
  147. package/dist/runner-usage.d.ts +0 -33
  148. package/dist/runtime-command-detector.d.ts +0 -3
  149. package/dist/runtime-state.d.ts +0 -171
  150. package/dist/service/attachment-domain-state.d.ts +0 -7
  151. package/dist/service/conversation-history-service.d.ts +0 -43
  152. package/dist/service/conversation-segment-service.d.ts +0 -20
  153. package/dist/service/external-session-resume-service.d.ts +0 -34
  154. package/dist/service/fake-managed-run-service.d.ts +0 -28
  155. package/dist/service/managed-runner-session-service.d.ts +0 -12
  156. package/dist/service/mcp-installation-verifier.d.ts +0 -9
  157. package/dist/service/mcp-node-operation-service.d.ts +0 -11
  158. package/dist/service/mcp-package-installer.d.ts +0 -8
  159. package/dist/service/native-session-projection-service.d.ts +0 -52
  160. package/dist/service/native-session-watch-service.d.ts +0 -62
  161. package/dist/service/node-connection-lifecycle-service.d.ts +0 -36
  162. package/dist/service/node-control-channel.d.ts +0 -32
  163. package/dist/service/node-control-message-service.d.ts +0 -27
  164. package/dist/service/node-request-service.d.ts +0 -14
  165. package/dist/service/node-run-event-bridge.d.ts +0 -40
  166. package/dist/service/node-terminal-channel.d.ts +0 -29
  167. package/dist/service/node-upgrade-coordinator.d.ts +0 -29
  168. package/dist/service/node-workspace-coordinator.d.ts +0 -29
  169. package/dist/service/recent-run-projection-service.d.ts +0 -14
  170. package/dist/service/run-attachment-service.d.ts +0 -38
  171. package/dist/service/run-domain-state.d.ts +0 -4
  172. package/dist/service/run-event-service.d.ts +0 -33
  173. package/dist/service/run-workbench-service.d.ts +0 -25
  174. package/dist/service/runner-channel-message-service.d.ts +0 -13
  175. package/dist/service/runner-interaction-service.d.ts +0 -39
  176. package/dist/service/runner-service.d.ts +0 -46
  177. package/dist/service/session-catalog-service.d.ts +0 -45
  178. package/dist/service/session-command-service.d.ts +0 -24
  179. package/dist/service/session-context-service.d.ts +0 -35
  180. package/dist/service/session-domain-state.d.ts +0 -9
  181. package/dist/service/session-identity-service.d.ts +0 -24
  182. package/dist/service/session-lifecycle-service.d.ts +0 -31
  183. package/dist/service/session-message-service.d.ts +0 -33
  184. package/dist/service/session-presentation-service.d.ts +0 -34
  185. package/dist/service/session-query-service.d.ts +0 -35
  186. package/dist/service/skill-directory-service.d.ts +0 -20
  187. package/dist/service/skill-install-service.d.ts +0 -21
  188. package/dist/service/skill-node-operation-service.d.ts +0 -44
  189. package/dist/service/terminal-relay-state.d.ts +0 -6
  190. package/dist/service/terminal-service.d.ts +0 -12
  191. package/dist/service/workbench-event-service.d.ts +0 -9
  192. package/dist/service/workbench-manifest-service.d.ts +0 -90
  193. package/dist/service/workspace-change-service.d.ts +0 -9
  194. package/dist/service/workspace-content-search-service.d.ts +0 -14
  195. package/dist/service/workspace-domain-state.d.ts +0 -79
  196. package/dist/service/workspace-file-service.d.ts +0 -18
  197. package/dist/service/workspace-git-exclude-service.d.ts +0 -4
  198. package/dist/service/workspace-queue-workbench-service.d.ts +0 -86
  199. package/dist/service/workspace-service.d.ts +0 -15
  200. package/dist/service/workspace-session-service.d.ts +0 -23
  201. package/dist/service/workspace-upload-service.d.ts +0 -39
  202. package/dist/service/workspace-watch-service.d.ts +0 -23
  203. package/dist/service/workspace-workbench-service.d.ts +0 -58
  204. package/dist/service.d.ts +0 -4
  205. package/dist/storage.d.ts +0 -2
  206. package/dist/supervisor.d.ts +0 -1
  207. package/dist/terminal.d.ts +0 -133
  208. package/dist/util/node-operation-parsers.d.ts +0 -92
  209. package/dist/util/personal-instructions.d.ts +0 -2
  210. package/dist/util/runner-error.d.ts +0 -6
  211. package/dist/util/runner-native-session-parsers.d.ts +0 -74
  212. package/dist/util/safe-error.d.ts +0 -2
  213. package/dist/util/secret-environment.d.ts +0 -1
  214. package/dist/workspace.d.ts +0 -217
package/dist/workspace.js CHANGED
@@ -1,1519 +1,2 @@
1
- import { createHash } from 'node:crypto';
2
- import { watch } from 'node:fs';
3
- import { lstat, mkdir, opendir, open, readdir, readFile, realpath, rename, rm, stat, unlink, writeFile } from 'node:fs/promises';
4
- import { homedir, platform as hostPlatform } from 'node:os';
5
- import { dirname, isAbsolute, posix, relative, resolve, sep, win32 } from 'node:path';
6
- import { spawn } from 'node:child_process';
7
- import { minimatch } from 'minimatch';
8
- const GIT_TIMEOUT_MS = 5_000;
9
- const GIT_OUTPUT_LIMIT = 512 * 1024;
10
- const FILE_READ_LIMIT = 512 * 1024;
11
- const DIRECTORY_PAGE_LIMIT = 200;
12
- const DIRECTORY_PICKER_LIMIT = 200;
13
- const SEARCH_RESULT_LIMIT = 200;
14
- const FILE_INDEX_IDLE_TTL_MS = 60 * 60 * 1_000;
15
- const FILE_INDEX_ENTRY_LIMIT = 100_000;
16
- const FILE_INDEX_FALLBACK_POLL_MS = 30_000;
17
- const FILE_INDEX_METADATA_CONCURRENCY = 32;
18
- const DEFAULT_QUICK_OPEN_EXCLUDES = [
19
- '**/.git/**',
20
- '**/node_modules/**',
21
- '**/bower_components/**',
22
- '**/.pnpm/**',
23
- '**/.yarn/**',
24
- '**/.cache/**',
25
- '**/.parcel-cache/**',
26
- '**/.turbo/**',
27
- '**/dist/**',
28
- '**/build/**',
29
- '**/out/**',
30
- '**/coverage/**',
31
- '**/test/runs/**',
32
- '**/.next/**',
33
- '**/.nuxt/**',
34
- '**/.svelte-kit/**',
35
- '**/.angular/**',
36
- '**/target/**',
37
- '**/.gradle/**',
38
- '**/bin/**',
39
- '**/obj/**',
40
- '**/vendor/**',
41
- '**/__pycache__/**',
42
- '**/.venv/**',
43
- '**/venv/**'
44
- ];
45
- const REF_PATTERN = /^(?!-)(?!.*\.\.)(?!.*@\{)[A-Za-z0-9][A-Za-z0-9._/-]{0,254}$/;
46
- export async function createWorkspaceDirectory(parentPath, directoryName, allowedRoots) {
47
- const name = directoryName.trim();
48
- if (name.length === 0 ||
49
- name.length > 255 ||
50
- name === '.' ||
51
- name === '..' ||
52
- name.includes('/') ||
53
- name.includes('\\') ||
54
- name.includes('\0'))
55
- throw new Error('WORKSPACE_DIRECTORY_NAME_INVALID');
56
- const roots = await Promise.all(allowedRoots.map((root) => realpath(root)));
57
- const parent = await realpath(parentPath).catch(() => {
58
- throw new Error('WORKSPACE_DIRECTORY_NOT_ALLOWED');
59
- });
60
- const metadata = await stat(parent).catch(() => undefined);
61
- if (metadata?.isDirectory() !== true || !isWithinAllowedRoot(parent, roots))
62
- throw new Error('WORKSPACE_DIRECTORY_NOT_ALLOWED');
63
- const target = resolve(parent, name);
64
- if (dirname(target) !== parent || !isWithinAllowedRoot(target, roots))
65
- throw new Error('WORKSPACE_DIRECTORY_NAME_INVALID');
66
- try {
67
- await mkdir(target);
68
- }
69
- catch (error) {
70
- if (error.code === 'EEXIST')
71
- throw new Error('WORKSPACE_DIRECTORY_EXISTS');
72
- throw error;
73
- }
74
- return target;
75
- }
76
- /** A per-workspace, process-local index for the Quick Open file picker. */
77
- export class WorkspaceFileIndex {
78
- workspaceRoot;
79
- limits;
80
- entries = [];
81
- truncated = false;
82
- root;
83
- loading;
84
- stale = true;
85
- watcher;
86
- expiryTimer;
87
- fallbackTimer;
88
- signature = '';
89
- constructor(workspaceRoot, limits = {}) {
90
- this.workspaceRoot = workspaceRoot;
91
- this.limits = limits;
92
- }
93
- /** Starts/renews the lightweight index observer without exposing file data. */
94
- async observe() {
95
- await this.ensureLoaded();
96
- this.touch();
97
- }
98
- async contentCandidates() {
99
- await this.ensureLoaded();
100
- this.touch();
101
- return {
102
- entries: this.entries.filter((entry) => entry.kind === 'FILE'),
103
- truncated: this.truncated
104
- };
105
- }
106
- dispose() {
107
- if (this.expiryTimer !== undefined)
108
- clearTimeout(this.expiryTimer);
109
- this.expiryTimer = undefined;
110
- this.watcher?.close();
111
- this.watcher = undefined;
112
- if (this.fallbackTimer !== undefined)
113
- clearInterval(this.fallbackTimer);
114
- this.fallbackTimer = undefined;
115
- this.entries = [];
116
- this.truncated = false;
117
- this.stale = true;
118
- this.signature = '';
119
- }
120
- async search(query, cursor, limit = SEARCH_RESULT_LIMIT, includeDirectories = false) {
121
- if (query.trim().length === 0 ||
122
- query.length > 256 ||
123
- !Number.isSafeInteger(limit) ||
124
- limit < 1 ||
125
- limit > SEARCH_RESULT_LIMIT)
126
- throw new Error('FILE_SEARCH_LIMIT_EXCEEDED');
127
- await this.ensureLoaded();
128
- this.touch();
129
- const after = decodeSearchCursor(cursor, query);
130
- const afterEntry = after === undefined
131
- ? undefined
132
- : this.entries.find((entry) => entry.path === after && (includeDirectories || entry.kind === 'FILE'));
133
- const afterScore = afterEntry === undefined ? -1 : fuzzyPathScore(afterEntry.path, query);
134
- const afterCandidate = afterEntry === undefined || afterScore < 0
135
- ? undefined
136
- : { entry: afterEntry, score: afterScore };
137
- const ranked = new RankedCandidateHeap(limit + 1);
138
- for (const entry of this.entries) {
139
- if (!includeDirectories && entry.kind !== 'FILE')
140
- continue;
141
- const score = fuzzyPathScore(entry.path, query);
142
- if (score < 0)
143
- continue;
144
- const candidate = { entry, score };
145
- if (afterCandidate !== undefined && compareRankedCandidate(candidate, afterCandidate) <= 0)
146
- continue;
147
- ranked.add(candidate);
148
- }
149
- const candidates = ranked.sorted();
150
- const page = candidates.slice(0, limit).map((candidate) => candidate.entry);
151
- const next = candidates[limit]?.entry.path;
152
- return {
153
- entries: page,
154
- nextCursor: next === undefined ? null : encodeSearchCursor(query, page.at(-1)?.path ?? after ?? ''),
155
- truncated: next !== undefined || this.truncated
156
- };
157
- }
158
- async ensureLoaded() {
159
- if (!this.stale && this.root !== undefined)
160
- return;
161
- if (this.loading === undefined) {
162
- this.loading = this.rebuild().finally(() => {
163
- this.loading = undefined;
164
- });
165
- }
166
- await this.loading;
167
- }
168
- touch() {
169
- if (this.expiryTimer !== undefined)
170
- clearTimeout(this.expiryTimer);
171
- this.expiryTimer = setTimeout(() => this.dispose(), this.limits.idleTtlMs ?? FILE_INDEX_IDLE_TTL_MS);
172
- this.expiryTimer.unref();
173
- }
174
- async rebuild() {
175
- const root = await realpath(this.workspaceRoot);
176
- const excludes = [...DEFAULT_QUICK_OPEN_EXCLUDES, ...(await workspaceExcludePatterns(root))];
177
- const indexed = [];
178
- const entryLimit = this.limits.entryLimit ?? FILE_INDEX_ENTRY_LIMIT;
179
- let truncated = false;
180
- const directories = ['.'];
181
- let directoryCursor = 0;
182
- while (directoryCursor < directories.length && !truncated) {
183
- const relativeDirectory = directories[directoryCursor];
184
- directoryCursor += 1;
185
- const directory = await resolveWorkspaceEntryFromCanonicalRoot(root, relativeDirectory, true).catch(() => undefined);
186
- if (directory === undefined)
187
- continue;
188
- const stream = await opendir(directory).catch(() => undefined);
189
- if (stream === undefined)
190
- continue;
191
- let pending = [];
192
- const appendPending = async () => {
193
- const resolvedEntries = await Promise.all(pending);
194
- pending = [];
195
- for (const entry of resolvedEntries) {
196
- if (entry === undefined)
197
- continue;
198
- if (entry.path === '.git' ||
199
- entry.path.startsWith('.git/') ||
200
- isExcluded(entry.path, excludes))
201
- continue;
202
- if (entry.kind === 'DIRECTORY')
203
- directories.push(entry.path);
204
- indexed.push(entry);
205
- if (indexed.length >= entryLimit) {
206
- truncated = true;
207
- break;
208
- }
209
- }
210
- };
211
- for await (const child of stream) {
212
- const candidatePath = relativeDirectory === '.'
213
- ? child.name
214
- : posix.join(relativeDirectory.replaceAll('\\', '/'), child.name);
215
- if (candidatePath === '.git' ||
216
- candidatePath.startsWith('.git/') ||
217
- isExcluded(candidatePath, excludes))
218
- continue;
219
- pending.push(inspectWorkspaceIndexEntry(root, candidatePath, child.name));
220
- if (pending.length >= FILE_INDEX_METADATA_CONCURRENCY)
221
- await appendPending();
222
- if (truncated)
223
- break;
224
- }
225
- if (!truncated && pending.length > 0)
226
- await appendPending();
227
- }
228
- this.root = root;
229
- this.entries = indexed;
230
- this.truncated = truncated;
231
- this.signature = fileIndexSignature(indexed, truncated);
232
- this.stale = false;
233
- this.watcher?.close();
234
- // fs.watch is advisory. Any change safely invalidates the in-memory index;
235
- // the next lookup rebuilds it and never trusts stale paths for file reads.
236
- try {
237
- this.watcher = watch(root, { persistent: false, recursive: true }, (_event, filename) => {
238
- if (filename !== null) {
239
- const path = filename.toString().replaceAll('\\', '/');
240
- if (path === '.git' || path.startsWith('.git/') || isExcluded(path, excludes))
241
- return;
242
- }
243
- this.invalidate();
244
- });
245
- this.watcher.on('error', () => {
246
- this.invalidate();
247
- this.watcher?.close();
248
- this.watcher = undefined;
249
- this.startFallbackPolling();
250
- });
251
- }
252
- catch {
253
- // Recursive watching is unavailable on some filesystems. A low-frequency
254
- // scan still rebuilds the index, but only emits after its metadata changed.
255
- this.watcher = undefined;
256
- this.startFallbackPolling();
257
- }
258
- }
259
- startFallbackPolling() {
260
- if (this.fallbackTimer !== undefined)
261
- return;
262
- this.fallbackTimer = setInterval(() => void this.pollFallback(), FILE_INDEX_FALLBACK_POLL_MS);
263
- this.fallbackTimer.unref();
264
- }
265
- async pollFallback() {
266
- if (this.loading !== undefined)
267
- return;
268
- const previous = this.signature;
269
- this.stale = true;
270
- try {
271
- await this.ensureLoaded();
272
- if (previous !== this.signature)
273
- this.limits.onInvalidated?.();
274
- }
275
- catch {
276
- // Keep the current last-known index. A later poll can recover when the
277
- // Workspace becomes readable again.
278
- this.stale = false;
279
- }
280
- }
281
- invalidate() {
282
- if (this.stale)
283
- return;
284
- this.stale = true;
285
- this.limits.onInvalidated?.();
286
- }
287
- }
288
- function fileIndexSignature(entries, truncated) {
289
- const hash = createHash('sha256');
290
- hash.update(truncated ? '1\0' : '0\0');
291
- for (const entry of entries)
292
- hash.update(`${entry.path}\0${String(entry.size)}\0${String(entry.modifiedAt)}\0`);
293
- return hash.digest('hex');
294
- }
295
- async function workspaceExcludePatterns(root) {
296
- const settingsPath = resolve(root, '.vscode/settings.json');
297
- const settings = (await readFile(settingsPath, 'utf8')
298
- .then(JSON.parse)
299
- .catch(() => undefined));
300
- if (typeof settings !== 'object' || settings === null)
301
- return [];
302
- return ['files.exclude', 'search.exclude'].flatMap((key) => {
303
- const value = settings[key];
304
- return typeof value === 'object' && value !== null
305
- ? Object.entries(value).flatMap(([pattern, enabled]) => (enabled === true ? [pattern] : []))
306
- : [];
307
- });
308
- }
309
- function isExcluded(path, patterns) {
310
- return patterns.some((pattern) => minimatch(path, pattern, { dot: true, nocase: hostPlatform() !== 'linux' }) ||
311
- minimatch(`${path}/`, pattern, { dot: true, nocase: hostPlatform() !== 'linux' }));
312
- }
313
- function compareRankedCandidate(left, right) {
314
- return right.score - left.score || left.entry.path.localeCompare(right.entry.path);
315
- }
316
- /** Keeps only the best page-sized candidate set, with the current worst item at the root. */
317
- class RankedCandidateHeap {
318
- capacity;
319
- values = [];
320
- constructor(capacity) {
321
- this.capacity = capacity;
322
- }
323
- add(candidate) {
324
- if (this.values.length < this.capacity) {
325
- this.values.push(candidate);
326
- this.bubbleUp(this.values.length - 1);
327
- return;
328
- }
329
- if (compareRankedCandidate(candidate, this.values[0]) >= 0)
330
- return;
331
- this.values[0] = candidate;
332
- this.sinkDown(0);
333
- }
334
- sorted() {
335
- return [...this.values].sort(compareRankedCandidate);
336
- }
337
- bubbleUp(start) {
338
- let index = start;
339
- while (index > 0) {
340
- const parent = Math.floor((index - 1) / 2);
341
- if (compareRankedCandidate(this.values[index], this.values[parent]) <= 0)
342
- break;
343
- [this.values[index], this.values[parent]] = [
344
- this.values[parent],
345
- this.values[index]
346
- ];
347
- index = parent;
348
- }
349
- }
350
- sinkDown(start) {
351
- let index = start;
352
- while (true) {
353
- const left = index * 2 + 1;
354
- if (left >= this.values.length)
355
- return;
356
- const right = left + 1;
357
- const worse = right < this.values.length &&
358
- compareRankedCandidate(this.values[right], this.values[left]) > 0
359
- ? right
360
- : left;
361
- if (compareRankedCandidate(this.values[worse], this.values[index]) <= 0)
362
- return;
363
- [this.values[index], this.values[worse]] = [
364
- this.values[worse],
365
- this.values[index]
366
- ];
367
- index = worse;
368
- }
369
- }
370
- }
371
- function fuzzyPathScore(path, query) {
372
- const source = path.toLocaleLowerCase();
373
- const needle = query.trim().toLocaleLowerCase();
374
- let cursor = 0;
375
- let score = 0;
376
- let previous = -2;
377
- for (const character of needle) {
378
- const index = source.indexOf(character, cursor);
379
- if (index === -1)
380
- return -1;
381
- score += index === previous + 1 ? 12 : 1;
382
- if (index === 0 || '/._-'.includes(source[index - 1] ?? ''))
383
- score += 8;
384
- previous = index;
385
- cursor = index + 1;
386
- }
387
- const name = path.slice(path.lastIndexOf('/') + 1).toLocaleLowerCase();
388
- if (name.includes(needle))
389
- score += 40;
390
- else if (source.includes(needle))
391
- score += 16;
392
- return score - path.length / 1_000;
393
- }
394
- /**
395
- * Lists directory names only for the Workspace picker. Browsing begins at the
396
- * first allowed root when configured, while the Node account home remains a
397
- * browse boundary and terminal default.
398
- */
399
- export async function listWorkspaceDirectories(requestedPath, allowedRoots, homePath = homedir()) {
400
- const home = await realpath(homePath);
401
- const roots = await Promise.all(allowedRoots.map((root) => realpath(root)));
402
- const browseRoots = [...new Set([home, ...roots])];
403
- const requested = requestedPath === undefined ? (roots[0] ?? home) : await realpath(requestedPath);
404
- const directory = await stat(requested);
405
- if (!directory.isDirectory() || !isWithinAllowedRoot(requested, browseRoots))
406
- throw new Error('WORKSPACE_DIRECTORY_NOT_ALLOWED');
407
- const children = await readdir(requested, { withFileTypes: true });
408
- const entries = [];
409
- for (const child of children.sort((left, right) => left.name.localeCompare(right.name))) {
410
- if (!child.isDirectory() && !child.isSymbolicLink())
411
- continue;
412
- const path = await realpath(resolve(requested, child.name)).catch(() => undefined);
413
- if (path === undefined || !isWithinAllowedRoot(path, browseRoots))
414
- continue;
415
- const metadata = await stat(path).catch(() => undefined);
416
- if (metadata === undefined || !metadata.isDirectory())
417
- continue;
418
- entries.push({ path, name: child.name, selectable: isWithinAllowedRoot(path, roots) });
419
- if (entries.length > DIRECTORY_PICKER_LIMIT)
420
- break;
421
- }
422
- const parent = dirname(requested);
423
- return {
424
- homePath: home,
425
- currentPath: requested,
426
- parentPath: parent === requested || !isWithinAllowedRoot(parent, browseRoots) ? null : parent,
427
- browseRoots: roots,
428
- selectable: isWithinAllowedRoot(requested, roots),
429
- entries: entries.slice(0, DIRECTORY_PICKER_LIMIT),
430
- truncated: entries.length > DIRECTORY_PICKER_LIMIT
431
- };
432
- }
433
- export async function listWorkspaceFiles(workspaceRoot, requestedPath = '.', cursor, limit = DIRECTORY_PAGE_LIMIT) {
434
- if (!Number.isSafeInteger(limit) || limit < 1 || limit > DIRECTORY_PAGE_LIMIT)
435
- throw new Error('DIRECTORY_CURSOR_INVALID');
436
- const directory = await resolveWorkspaceEntry(workspaceRoot, requestedPath, true);
437
- const entries = await readdir(directory, { withFileTypes: true });
438
- const root = await realpath(workspaceRoot);
439
- const cursorValue = decodeDirectoryCursor(cursor, requestedPath);
440
- const names = entries
441
- .filter((entry) => entry.name !== '.git' && !isWorkspaceUploadTemporaryName(entry.name))
442
- .map((entry) => entry.name)
443
- .sort((left, right) => left.localeCompare(right));
444
- const start = cursorValue === undefined ? 0 : names.findIndex((name) => name > cursorValue);
445
- if (cursorValue !== undefined && start === -1)
446
- return { entries: [], nextCursor: null, truncated: false };
447
- const pageNames = names.slice(start, start + limit);
448
- const output = [];
449
- for (const name of pageNames) {
450
- const child = await resolveWorkspaceEntry(root, relative(root, resolve(directory, name)), false).catch((error) => {
451
- if (isSkippableWorkspaceEntryError(error))
452
- return undefined;
453
- throw error;
454
- });
455
- if (child === undefined)
456
- continue;
457
- const metadata = await lstat(child).catch((error) => {
458
- if (error.code === 'ENOENT')
459
- return undefined;
460
- throw error;
461
- });
462
- if (metadata === undefined || (!metadata.isFile() && !metadata.isDirectory()))
463
- continue;
464
- output.push({
465
- path: relative(root, child).split(sep).join('/'),
466
- name,
467
- kind: metadata.isDirectory() ? 'DIRECTORY' : 'FILE',
468
- size: metadata.isFile() ? metadata.size : null,
469
- modifiedAt: metadata.mtimeMs
470
- });
471
- }
472
- const nextName = names[start + pageNames.length];
473
- return {
474
- entries: output,
475
- nextCursor: nextName === undefined || pageNames.length === 0
476
- ? null
477
- : encodeDirectoryCursor(requestedPath, pageNames[pageNames.length - 1]),
478
- truncated: nextName !== undefined
479
- };
480
- }
481
- export async function mutateWorkspaceFile(workspaceRoot, mutation) {
482
- const root = await realpath(workspaceRoot);
483
- if (mutation.action === 'CREATE_FILE' || mutation.action === 'CREATE_DIRECTORY') {
484
- const target = await resolveNewWorkspaceEntry(root, mutation.path);
485
- if (mutation.action === 'CREATE_FILE')
486
- await writeFile(target, '', { flag: 'wx' });
487
- else
488
- await mkdir(target);
489
- return { path: workspaceRelativePath(root, target) };
490
- }
491
- await assertWorkspaceMutationPathHasNoSymlinks(root, mutation.path);
492
- const source = await resolveWorkspaceEntryMetadata(root, mutation.path);
493
- if (workspaceRelativePath(root, source.path) === '.')
494
- throw new Error('FILE_ROOT_MUTATION_INVALID');
495
- if (mutation.action === 'DELETE') {
496
- await rm(source.path, { recursive: source.metadata.isDirectory(), force: false });
497
- return { deleted: true };
498
- }
499
- const destination = await resolveNewWorkspaceEntry(root, mutation.destination);
500
- if (source.metadata.isDirectory()) {
501
- const destinationFromSource = relative(source.path, destination);
502
- if (destinationFromSource === '' ||
503
- (!isAbsolute(destinationFromSource) &&
504
- destinationFromSource !== '..' &&
505
- !destinationFromSource.startsWith(`..${sep}`)))
506
- throw new Error('FILE_MOVE_DESCENDANT_INVALID');
507
- }
508
- await rename(source.path, destination);
509
- return { path: workspaceRelativePath(root, destination) };
510
- }
511
- async function resolveNewWorkspaceEntry(root, requestedPath) {
512
- const normalized = requestedPath.replaceAll('\\', '/');
513
- const segments = normalized.split('/');
514
- const name = segments.at(-1);
515
- if (requestedPath.includes('\0') ||
516
- normalized.startsWith('/') ||
517
- isAbsolute(requestedPath) ||
518
- win32.isAbsolute(normalized) ||
519
- name === undefined ||
520
- name.length === 0 ||
521
- segments.some(invalidWorkspaceMutationSegment))
522
- throw new Error('FILE_PATH_ESCAPE');
523
- const parentPath = segments.length === 1 ? '.' : segments.slice(0, -1).join('/');
524
- await assertWorkspaceMutationPathHasNoSymlinks(root, parentPath);
525
- const parent = await resolveWorkspaceEntryFromCanonicalRoot(root, parentPath, true);
526
- const target = resolve(parent, name);
527
- try {
528
- await lstat(target);
529
- throw new Error('FILE_ALREADY_EXISTS');
530
- }
531
- catch (error) {
532
- if (error.code !== 'ENOENT')
533
- throw error;
534
- }
535
- return target;
536
- }
537
- async function assertWorkspaceMutationPathHasNoSymlinks(root, requestedPath) {
538
- const normalized = requestedPath.replaceAll('\\', '/');
539
- if (normalized === '.')
540
- return;
541
- const segments = normalized.split('/');
542
- if (requestedPath.includes('\0') ||
543
- normalized.startsWith('/') ||
544
- isAbsolute(requestedPath) ||
545
- win32.isAbsolute(normalized) ||
546
- segments.some(invalidWorkspaceMutationSegment))
547
- throw new Error('FILE_PATH_ESCAPE');
548
- let candidate = root;
549
- for (const segment of segments) {
550
- candidate = resolve(candidate, segment);
551
- const metadata = await lstat(candidate).catch((error) => {
552
- if (error.code === 'ENOENT')
553
- throw new Error('FILE_NOT_FOUND');
554
- throw error;
555
- });
556
- if (metadata.isSymbolicLink())
557
- throw new Error('FILE_PATH_ESCAPE');
558
- }
559
- }
560
- function invalidWorkspaceMutationSegment(segment) {
561
- if (segment.length === 0 || segment === '.' || segment === '..' || segment === '.git')
562
- return true;
563
- if (hostPlatform() !== 'win32')
564
- return false;
565
- const normalized = segment.replace(/[. ]+$/u, '').toUpperCase();
566
- return (/[<>:"|?*]/u.test(segment) ||
567
- /^(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\..*)?$/u.test(normalized));
568
- }
569
- function workspaceRelativePath(root, path) {
570
- const value = relative(root, path).split(sep).join('/');
571
- return value.length === 0 ? '.' : value;
572
- }
573
- function isSkippableWorkspaceEntryError(error) {
574
- return (error instanceof Error &&
575
- (error.message === 'FILE_PATH_ESCAPE' ||
576
- error.message === 'FILE_NOT_FOUND' ||
577
- error.message === 'FILE_NOT_REGULAR'));
578
- }
579
- /** Validates an upload destination without following an existing target symlink. */
580
- export async function preflightWorkspaceUpload(workspaceRoot, requestedDirectory, name) {
581
- if (name.length === 0 ||
582
- name === '.' ||
583
- name === '..' ||
584
- name.includes('\0') ||
585
- name.includes('/') ||
586
- name.includes('\\') ||
587
- isWorkspaceUploadTemporaryName(name)) {
588
- return { path: '', absolutePath: '', status: 'INVALID_NAME' };
589
- }
590
- const root = await realpath(workspaceRoot);
591
- const directory = await resolveWorkspaceEntry(root, requestedDirectory, true);
592
- const absolutePath = resolve(directory, name);
593
- if (dirname(absolutePath) !== directory)
594
- throw new Error('FILE_PATH_ESCAPE');
595
- const relativePath = relative(root, absolutePath).split(sep).join('/');
596
- const metadata = await lstat(absolutePath).catch((error) => {
597
- if (error.code === 'ENOENT')
598
- return undefined;
599
- throw error;
600
- });
601
- if (metadata === undefined)
602
- return { path: relativePath, absolutePath, status: 'READY' };
603
- if (metadata.isSymbolicLink())
604
- throw new Error('FILE_PATH_ESCAPE');
605
- if (metadata.isFile())
606
- return { path: relativePath, absolutePath, status: 'EXISTS_FILE' };
607
- return { path: relativePath, absolutePath, status: 'EXISTS_DIRECTORY' };
608
- }
609
- export function workspaceUploadTemporaryName(uploadId) {
610
- return `.mar-upload-${uploadId}.part`;
611
- }
612
- function isWorkspaceUploadTemporaryName(name) {
613
- return /^\.mar-upload-[0-9a-f-]{36}\.part$/i.test(name);
614
- }
615
- export async function readWorkspaceTextFile(workspaceRoot, requestedPath, offset = 0, limit = FILE_READ_LIMIT) {
616
- if (!Number.isSafeInteger(offset) ||
617
- offset < 0 ||
618
- !Number.isSafeInteger(limit) ||
619
- limit < 1 ||
620
- limit > FILE_READ_LIMIT)
621
- throw new Error('FILE_RANGE_INVALID');
622
- const root = await realpath(workspaceRoot);
623
- const file = await resolveWorkspaceEntry(root, requestedPath, false);
624
- const metadata = await lstat(file);
625
- if (!metadata.isFile())
626
- throw new Error('FILE_NOT_REGULAR');
627
- if (metadata.size > FILE_READ_LIMIT * 16)
628
- throw new Error('FILE_TOO_LARGE');
629
- const source = await readFile(file);
630
- const binary = source.includes(0) || !isValidUtf8(source);
631
- if (binary) {
632
- const end = Math.min(source.length, offset + limit);
633
- const slice = source.subarray(offset, end);
634
- return {
635
- path: relative(root, file).split(sep).join('/'),
636
- encoding: 'base64',
637
- size: source.length,
638
- content: slice.toString('base64'),
639
- truncated: end < source.length,
640
- nextOffset: end < source.length ? end : null
641
- };
642
- }
643
- if (offset > 0 && offset < source.length && isUtf8ContinuationByte(source[offset]))
644
- throw new Error('FILE_RANGE_INVALID');
645
- let end = Math.min(source.length, offset + limit);
646
- if (end < source.length && isUtf8ContinuationByte(source[end])) {
647
- while (end > offset && isUtf8ContinuationByte(source[end]))
648
- end -= 1;
649
- if (end === offset) {
650
- end += 1;
651
- while (end < source.length && isUtf8ContinuationByte(source[end]))
652
- end += 1;
653
- }
654
- }
655
- const slice = source.subarray(offset, end);
656
- const content = new TextDecoder('utf-8', { fatal: true }).decode(slice);
657
- const nextOffset = end < source.length ? end : null;
658
- return {
659
- path: relative(root, file).split(sep).join('/'),
660
- encoding: 'utf-8',
661
- size: source.length,
662
- content,
663
- truncated: nextOffset !== null,
664
- nextOffset
665
- };
666
- }
667
- export async function readWorkspaceFileContentRange(workspaceRoot, requestedPath, offset = 0, limit = FILE_READ_LIMIT) {
668
- if (!Number.isSafeInteger(offset) ||
669
- offset < 0 ||
670
- !Number.isSafeInteger(limit) ||
671
- limit < 1 ||
672
- limit > FILE_READ_LIMIT)
673
- throw new Error('FILE_RANGE_INVALID');
674
- const root = await realpath(workspaceRoot);
675
- const file = await resolveWorkspaceEntry(root, requestedPath, false);
676
- const metadata = await lstat(file);
677
- if (!metadata.isFile())
678
- throw new Error('FILE_NOT_REGULAR');
679
- if (offset > metadata.size)
680
- throw new Error('FILE_RANGE_INVALID');
681
- const length = Math.min(limit, metadata.size - offset);
682
- const source = Buffer.allocUnsafe(length);
683
- const handle = await open(file, 'r');
684
- try {
685
- const { bytesRead } = await handle.read(source, 0, length, offset);
686
- const end = offset + bytesRead;
687
- return {
688
- path: relative(root, file).split(sep).join('/'),
689
- size: metadata.size,
690
- offset,
691
- contentBase64: source.subarray(0, bytesRead).toString('base64'),
692
- nextOffset: end < metadata.size ? end : null
693
- };
694
- }
695
- finally {
696
- await handle.close();
697
- }
698
- }
699
- /** Reads one absolute file only when the resolved target remains within a Node allowed root. */
700
- export async function readAllowedTextFile(requestedPath, allowedRoots, offset = 0, limit = FILE_READ_LIMIT) {
701
- if (!isAbsolute(requestedPath))
702
- throw new Error('FILE_PATH_ESCAPE');
703
- const file = await realpath(requestedPath).catch((error) => {
704
- if (error.code === 'ENOENT')
705
- throw new Error('FILE_NOT_FOUND');
706
- throw error;
707
- });
708
- const roots = await Promise.all(allowedRoots.map((root) => realpath(root)));
709
- if (!isWithinAllowedRoot(file, roots))
710
- throw new Error('FILE_PATH_ESCAPE');
711
- const metadata = await lstat(file);
712
- if (!metadata.isFile())
713
- throw new Error('FILE_NOT_REGULAR');
714
- if (metadata.size > FILE_READ_LIMIT * 16)
715
- throw new Error('FILE_TOO_LARGE');
716
- if (!Number.isSafeInteger(offset) ||
717
- offset < 0 ||
718
- !Number.isSafeInteger(limit) ||
719
- limit < 1 ||
720
- limit > FILE_READ_LIMIT)
721
- throw new Error('FILE_RANGE_INVALID');
722
- const source = await readFile(file);
723
- const binary = source.includes(0) || !isValidUtf8(source);
724
- const end = Math.min(source.length, offset + limit);
725
- if (binary) {
726
- const slice = source.subarray(offset, end);
727
- return {
728
- path: file,
729
- encoding: 'base64',
730
- size: source.length,
731
- content: slice.toString('base64'),
732
- truncated: end < source.length,
733
- nextOffset: end < source.length ? end : null
734
- };
735
- }
736
- if (offset > 0 && offset < source.length && isUtf8ContinuationByte(source[offset]))
737
- throw new Error('FILE_RANGE_INVALID');
738
- let textEnd = end;
739
- if (textEnd < source.length && isUtf8ContinuationByte(source[textEnd])) {
740
- while (textEnd > offset && isUtf8ContinuationByte(source[textEnd]))
741
- textEnd -= 1;
742
- if (textEnd === offset) {
743
- textEnd += 1;
744
- while (textEnd < source.length && isUtf8ContinuationByte(source[textEnd]))
745
- textEnd += 1;
746
- }
747
- }
748
- const nextOffset = textEnd < source.length ? textEnd : null;
749
- return {
750
- path: file,
751
- encoding: 'utf-8',
752
- size: source.length,
753
- content: new TextDecoder('utf-8', { fatal: true }).decode(source.subarray(offset, textEnd)),
754
- truncated: nextOffset !== null,
755
- nextOffset
756
- };
757
- }
758
- function isValidUtf8(source) {
759
- try {
760
- new TextDecoder('utf-8', { fatal: true }).decode(source);
761
- return true;
762
- }
763
- catch {
764
- return false;
765
- }
766
- }
767
- function isUtf8ContinuationByte(value) {
768
- return (value & 0b1100_0000) === 0b1000_0000;
769
- }
770
- /** Searches file names only, so an exploratory request cannot exfiltrate file contents. */
771
- export async function searchWorkspaceFiles(workspaceRoot, query, cursor, limit = SEARCH_RESULT_LIMIT, includeDirectories = false) {
772
- const index = new WorkspaceFileIndex(workspaceRoot);
773
- try {
774
- return await index.search(query, cursor, limit, includeDirectories);
775
- }
776
- finally {
777
- index.dispose();
778
- }
779
- }
780
- async function resolveWorkspaceEntry(workspaceRoot, requestedPath, directory) {
781
- const root = await realpath(workspaceRoot);
782
- return resolveWorkspaceEntryFromCanonicalRoot(root, requestedPath, directory);
783
- }
784
- async function resolveWorkspaceEntryFromCanonicalRoot(root, requestedPath, directory) {
785
- const entry = await resolveWorkspaceEntryMetadata(root, requestedPath);
786
- if (directory
787
- ? !entry.metadata.isDirectory()
788
- : !entry.metadata.isFile() && !entry.metadata.isDirectory())
789
- throw new Error(directory ? 'FILE_NOT_DIRECTORY' : 'FILE_NOT_REGULAR');
790
- return entry.path;
791
- }
792
- async function resolveWorkspaceEntryMetadata(root, requestedPath) {
793
- if (requestedPath.includes('\0') ||
794
- requestedPath.length === 0 ||
795
- requestedPath.startsWith('/') ||
796
- requestedPath.startsWith('\\'))
797
- throw new Error('FILE_PATH_ESCAPE');
798
- const normalized = requestedPath.replaceAll('\\', '/');
799
- if (normalized.split('/').some((segment) => segment === '..' || segment === '.git'))
800
- throw new Error('FILE_PATH_ESCAPE');
801
- let candidate;
802
- try {
803
- candidate = await realpath(resolve(root, normalized));
804
- }
805
- catch (error) {
806
- if (error.code === 'ENOENT')
807
- throw new Error('FILE_NOT_FOUND');
808
- throw error;
809
- }
810
- const pathToCandidate = relative(root, candidate);
811
- if (isAbsolute(pathToCandidate) ||
812
- pathToCandidate.startsWith('..') ||
813
- pathToCandidate === '..' ||
814
- pathToCandidate.startsWith(`..${sep}`))
815
- throw new Error('FILE_PATH_ESCAPE');
816
- const metadata = await lstat(candidate);
817
- return { path: candidate, metadata };
818
- }
819
- async function inspectWorkspaceIndexEntry(root, requestedPath, name) {
820
- try {
821
- const entry = await resolveWorkspaceEntryMetadata(root, requestedPath);
822
- if (!entry.metadata.isFile() && !entry.metadata.isDirectory())
823
- return undefined;
824
- const safePath = relative(root, entry.path).split(sep).join('/');
825
- return entry.metadata.isDirectory()
826
- ? {
827
- path: safePath,
828
- name,
829
- kind: 'DIRECTORY',
830
- size: null,
831
- modifiedAt: entry.metadata.mtimeMs
832
- }
833
- : {
834
- path: safePath,
835
- name,
836
- kind: 'FILE',
837
- size: entry.metadata.size,
838
- modifiedAt: entry.metadata.mtimeMs
839
- };
840
- }
841
- catch {
842
- return undefined;
843
- }
844
- }
845
- function encodeDirectoryCursor(path, name) {
846
- return Buffer.from(JSON.stringify({ path, name })).toString('base64url');
847
- }
848
- function decodeDirectoryCursor(cursor, expectedPath) {
849
- if (cursor === undefined)
850
- return undefined;
851
- try {
852
- const value = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
853
- if (typeof value !== 'object' ||
854
- value === null ||
855
- value.path !== expectedPath ||
856
- typeof value.name !== 'string')
857
- throw new Error();
858
- return value.name;
859
- }
860
- catch {
861
- throw new Error('DIRECTORY_CURSOR_INVALID');
862
- }
863
- }
864
- function encodeSearchCursor(query, path) {
865
- return Buffer.from(JSON.stringify({ query, path })).toString('base64url');
866
- }
867
- function decodeSearchCursor(cursor, expectedQuery) {
868
- if (cursor === undefined)
869
- return undefined;
870
- try {
871
- const value = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
872
- if (typeof value !== 'object' ||
873
- value === null ||
874
- value.query !== expectedQuery ||
875
- typeof value.path !== 'string')
876
- throw new Error();
877
- return value.path;
878
- }
879
- catch {
880
- throw new Error('DIRECTORY_CURSOR_INVALID');
881
- }
882
- }
883
- export function normalizeWorkspacePath(input, platform = hostPlatform()) {
884
- if (input.length === 0 || input.includes('\u0000')) {
885
- throw new Error('WORKSPACE_PATH_INVALID');
886
- }
887
- if (platform === 'win32') {
888
- // Device paths bypass normal Win32 resolution and must never be accepted.
889
- if (/^\\\\[?.]/.test(input)) {
890
- throw new Error('WORKSPACE_DEVICE_PATH_REJECTED');
891
- }
892
- const normalized = win32.normalize(input.replaceAll('/', '\\'));
893
- if (!win32.isAbsolute(normalized)) {
894
- throw new Error('WORKSPACE_PATH_NOT_ABSOLUTE');
895
- }
896
- return normalized.replace(/\\+$/, '').toLowerCase();
897
- }
898
- if (platform !== 'linux') {
899
- throw new Error('WORKSPACE_PLATFORM_UNSUPPORTED');
900
- }
901
- const normalized = posix.normalize(input);
902
- if (!posix.isAbsolute(normalized)) {
903
- throw new Error('WORKSPACE_PATH_NOT_ABSOLUTE');
904
- }
905
- return normalized === '/' ? normalized : normalized.replace(/\/+$/, '');
906
- }
907
- export function isWithinAllowedRoot(target, roots, platform = hostPlatform()) {
908
- const normalizedTarget = normalizeWorkspacePath(target, platform);
909
- const pathApi = platform === 'win32' ? win32 : posix;
910
- return roots.some((root) => {
911
- const normalizedRoot = normalizeWorkspacePath(root, platform);
912
- const relative = pathApi.relative(normalizedRoot, normalizedTarget);
913
- return relative === '' || (!relative.startsWith('..') && !pathApi.isAbsolute(relative));
914
- });
915
- }
916
- /** Resolving both candidate and roots rejects Linux symlinks which point outside a root. */
917
- export async function inspectWorkspace(requestedPath, allowedRoots) {
918
- const resolvedPath = await realpath(requestedPath);
919
- const resolvedRoots = await Promise.all(allowedRoots.map((root) => realpath(root)));
920
- const directory = await stat(resolvedPath);
921
- if (!directory.isDirectory() || !isWithinAllowedRoot(resolvedPath, resolvedRoots)) {
922
- throw new Error('WORKSPACE_NOT_ALLOWED');
923
- }
924
- try {
925
- const summary = await readGitSummary(resolvedPath);
926
- return { path: resolvedPath, kind: 'GIT_WORKSPACE', gitSummary: summary };
927
- }
928
- catch (error) {
929
- if ((error instanceof GitCommandError && error.code === 128) || isGitUnavailable(error)) {
930
- return { path: resolvedPath, kind: 'DIRECTORY' };
931
- }
932
- throw error;
933
- }
934
- }
935
- export async function readGitSummary(workspacePath) {
936
- const commonDir = (await runGit(workspacePath, ['rev-parse', '--git-common-dir'])).text.trim();
937
- const head = (await runGit(workspacePath, ['rev-parse', '--verify', 'HEAD'])).text.trim();
938
- const branchResult = await runGitAllowFailure(workspacePath, [
939
- 'symbolic-ref',
940
- '--quiet',
941
- '--short',
942
- 'HEAD'
943
- ]);
944
- const dirty = (await runGit(workspacePath, ['status', '--porcelain=v1', '-z'])).output.length > 0;
945
- const snapshotOutput = await runGit(workspacePath, ['status', '--porcelain=v1']).then((result) => result.text);
946
- return {
947
- commonDir,
948
- head,
949
- branch: branchResult.code === 0 ? branchResult.text.trim() : null,
950
- dirty,
951
- snapshot: summarizeText(snapshotOutput)
952
- };
953
- }
954
- export function assertSafeGitRef(ref) {
955
- if (!REF_PATTERN.test(ref)) {
956
- throw new Error('GIT_REF_INVALID');
957
- }
958
- }
959
- export async function readRestrictedDiff(workspacePath, fromRef, toRef) {
960
- assertSafeGitRef(fromRef);
961
- assertSafeGitRef(toRef);
962
- const result = await runGit(workspacePath, [
963
- 'diff',
964
- '--no-ext-diff',
965
- '--no-textconv',
966
- fromRef,
967
- toRef
968
- ]);
969
- const binary = result.output.includes(0) || result.text.includes('Binary files ');
970
- if (binary) {
971
- return {
972
- binary: true,
973
- summary: `binary diff sha256=${createHash('sha256').update(result.output).digest('hex')} bytes=${result.output.length}`,
974
- truncated: result.truncated
975
- };
976
- }
977
- return { binary: false, text: result.text, truncated: result.truncated };
978
- }
979
- function currentBranchFromStatusHeader(header) {
980
- const value = header.slice(3);
981
- if (value.startsWith('HEAD '))
982
- return null;
983
- const unborn = /^(?:No commits yet on|Initial commit on) (.+)$/.exec(value);
984
- if (unborn !== null)
985
- return unborn[1] ?? null;
986
- return value.split('...')[0]?.split(' ')[0] ?? null;
987
- }
988
- export async function readCurrentChangesSummary(workspacePath) {
989
- const result = await runGit(workspacePath, [
990
- 'status',
991
- '--porcelain=v1',
992
- '-z',
993
- '--branch',
994
- '--untracked-files=all'
995
- ]);
996
- const records = result.text.split('\0');
997
- const header = records.shift() ?? '';
998
- const output = [];
999
- for (let index = 0; index < records.length; index += 1) {
1000
- const record = records[index];
1001
- if (record.length < 4)
1002
- continue;
1003
- const indexState = record[0];
1004
- const worktreeState = record[1];
1005
- const path = record.slice(3);
1006
- if (indexState === '?' && worktreeState === '?') {
1007
- output.push({ path, state: 'UNTRACKED', change: 'ADDED' });
1008
- continue;
1009
- }
1010
- if (indexState !== ' ') {
1011
- output.push({ path, state: 'STAGED', change: gitChange(indexState) });
1012
- }
1013
- if (worktreeState !== ' ') {
1014
- output.push({ path, state: 'UNSTAGED', change: gitChange(worktreeState) });
1015
- }
1016
- // Porcelain v1 -z emits a second NUL-delimited source path for rename
1017
- // and copy records. It is metadata for the same entry, never another
1018
- // status record.
1019
- if (indexState === 'R' || indexState === 'C' || worktreeState === 'R' || worktreeState === 'C')
1020
- index += 1;
1021
- }
1022
- return {
1023
- branch: header.startsWith('## ') ? currentBranchFromStatusHeader(header) : null,
1024
- changes: output
1025
- };
1026
- }
1027
- export async function listInitializedSubmodulePaths(workspacePath) {
1028
- const result = await runGit(workspacePath, ['submodule', 'status', '--recursive']);
1029
- return result.text
1030
- .split(/\r?\n/)
1031
- .flatMap((line) => {
1032
- if (line.length < 42)
1033
- return [];
1034
- const marker = line[0];
1035
- if (marker === '-')
1036
- return [];
1037
- const match = /^.[0-9a-f]+\s+(.+?)(?:\s+\([^)]*\))?$/.exec(line);
1038
- const path = match?.[1]?.replaceAll('\\', '/');
1039
- return path === undefined || path.length === 0 ? [] : [path];
1040
- })
1041
- .sort((left, right) => left.localeCompare(right));
1042
- }
1043
- export async function resolveGitRepository(workspacePath, repositoryPath) {
1044
- if (repositoryPath.length === 0)
1045
- return realpath(workspacePath);
1046
- if (repositoryPath.includes('\0') ||
1047
- repositoryPath.startsWith('/') ||
1048
- repositoryPath.startsWith('\\') ||
1049
- repositoryPath
1050
- .split('/')
1051
- .some((segment) => segment.length === 0 || segment === '.' || segment === '..'))
1052
- throw new Error('GIT_REPOSITORY_INVALID');
1053
- const repositories = await listInitializedSubmodulePaths(workspacePath);
1054
- if (!repositories.includes(repositoryPath))
1055
- throw new Error('GIT_REPOSITORY_INVALID');
1056
- const repository = resolve(await realpath(workspacePath), repositoryPath);
1057
- try {
1058
- await readGitSummary(repository);
1059
- }
1060
- catch {
1061
- throw new Error('GIT_REPOSITORY_INVALID');
1062
- }
1063
- return repository;
1064
- }
1065
- export async function listGitHistoryRefs(repository) {
1066
- const result = await runGit(repository, [
1067
- 'for-each-ref',
1068
- '--format=%(refname)%09%(refname:short)%09%(objectname)%09%(HEAD)%09%(symref)',
1069
- 'refs/heads',
1070
- 'refs/remotes'
1071
- ]);
1072
- return result.text
1073
- .split(/\r?\n/)
1074
- .flatMap((line) => {
1075
- const [name, displayName, hash, head, symref] = line.split('\t');
1076
- if (name === undefined ||
1077
- displayName === undefined ||
1078
- hash === undefined ||
1079
- symref === undefined ||
1080
- symref.length > 0 ||
1081
- !/^[0-9a-f]{40,64}$/.test(hash))
1082
- return [];
1083
- const kind = name.startsWith('refs/heads/')
1084
- ? 'LOCAL'
1085
- : name.startsWith('refs/remotes/')
1086
- ? 'REMOTE'
1087
- : undefined;
1088
- return kind === undefined ? [] : [{ name, displayName, kind, hash, current: head === '*' }];
1089
- })
1090
- .sort((left, right) => left.kind.localeCompare(right.kind) || left.displayName.localeCompare(right.displayName));
1091
- }
1092
- function selectedHistoryRefs(available, requested) {
1093
- if (requested === undefined || requested.length === 0)
1094
- return available;
1095
- const unique = [...new Set(requested)];
1096
- const selected = unique.map((name) => available.find((entry) => entry.name === name));
1097
- if (selected.some((entry) => entry === undefined))
1098
- throw new Error('GIT_HISTORY_REF_INVALID');
1099
- return selected;
1100
- }
1101
- function historyCursor(offset, fingerprint) {
1102
- return Buffer.from(JSON.stringify({ offset, fingerprint })).toString('base64url');
1103
- }
1104
- function parseHistoryCursor(value, fingerprint) {
1105
- if (value === undefined)
1106
- return 0;
1107
- try {
1108
- const parsed = JSON.parse(Buffer.from(value, 'base64url').toString('utf8'));
1109
- if (!Number.isInteger(parsed.offset) ||
1110
- parsed.offset < 0 ||
1111
- parsed.fingerprint !== fingerprint)
1112
- throw new Error('invalid');
1113
- return parsed.offset;
1114
- }
1115
- catch {
1116
- throw new Error('GIT_HISTORY_CURSOR_INVALID');
1117
- }
1118
- }
1119
- export async function readGitHistory(repository, input) {
1120
- const available = await listGitHistoryRefs(repository);
1121
- const selected = selectedHistoryRefs(available, input.refs);
1122
- if (selected.length === 0)
1123
- return { commits: [], nextCursor: null };
1124
- const limit = input.limit ?? 50;
1125
- if (!Number.isInteger(limit) || limit < 1 || limit > 100)
1126
- throw new Error('GIT_HISTORY_LIMIT_INVALID');
1127
- const names = selected.map((entry) => entry.name).sort();
1128
- // Bind the offset cursor to the exact branch tips. Advancing a branch invalidates
1129
- // the cursor instead of silently skipping or duplicating commits between pages.
1130
- const fingerprint = createHash('sha256')
1131
- .update(selected
1132
- .map((entry) => `${entry.name}\0${entry.hash}`)
1133
- .sort()
1134
- .join('\0'))
1135
- .digest('hex');
1136
- const offset = parseHistoryCursor(input.cursor, fingerprint);
1137
- const result = await runGit(repository, [
1138
- 'log',
1139
- '--topo-order',
1140
- '--date-order',
1141
- `--skip=${offset}`,
1142
- `--max-count=${limit + 1}`,
1143
- '-z',
1144
- '--format=%H%x00%P%x00%an%x00%ae%x00%ct%x00%s',
1145
- ...names,
1146
- '--'
1147
- ]);
1148
- const refsByHash = new Map();
1149
- for (const entry of available) {
1150
- const refs = refsByHash.get(entry.hash) ?? [];
1151
- refs.push(entry.displayName);
1152
- refsByHash.set(entry.hash, refs);
1153
- }
1154
- const fields = result.text.split('\0');
1155
- const commits = [];
1156
- for (let index = 0; index + 5 < fields.length; index += 6) {
1157
- const [hash, parents = '', authorName = '', authorEmail = '', committedAt = '0', subject = ''] = fields.slice(index, index + 6);
1158
- if (hash === undefined || !/^[0-9a-f]{40,64}$/.test(hash))
1159
- continue;
1160
- commits.push({
1161
- hash,
1162
- parents: parents.length === 0 ? [] : parents.split(' '),
1163
- authorName,
1164
- authorEmail,
1165
- committedAt: Number(committedAt) * 1000,
1166
- subject,
1167
- refs: refsByHash.get(hash) ?? []
1168
- });
1169
- }
1170
- const hasMore = commits.length > limit;
1171
- return {
1172
- commits: commits.slice(0, limit),
1173
- nextCursor: hasMore ? historyCursor(offset + limit, fingerprint) : null
1174
- };
1175
- }
1176
- async function assertHistoryCommitReachable(repository, commit, refs) {
1177
- if (!/^[0-9a-f]{40,64}$/.test(commit))
1178
- throw new Error('GIT_HISTORY_COMMIT_INVALID');
1179
- const selected = selectedHistoryRefs(await listGitHistoryRefs(repository), refs);
1180
- for (const ref of selected) {
1181
- const result = await runGitAllowFailure(repository, [
1182
- 'merge-base',
1183
- '--is-ancestor',
1184
- commit,
1185
- ref.name
1186
- ]);
1187
- if (result.code === 0)
1188
- return;
1189
- }
1190
- throw new Error('GIT_HISTORY_COMMIT_INVALID');
1191
- }
1192
- export async function readGitHistoryFiles(repository, commit, refs) {
1193
- await assertHistoryCommitReachable(repository, commit, refs);
1194
- const result = await runGit(repository, [
1195
- 'diff-tree',
1196
- '--root',
1197
- '--first-parent',
1198
- '--no-commit-id',
1199
- '-r',
1200
- '-z',
1201
- '-M',
1202
- '-C',
1203
- '--name-status',
1204
- commit
1205
- ]);
1206
- const records = result.text.split('\0');
1207
- const files = [];
1208
- for (let index = 0; index < records.length; index += 1) {
1209
- const status = records[index];
1210
- if (status === undefined || status.length === 0)
1211
- continue;
1212
- const code = status[0] ?? 'M';
1213
- if (code === 'R' || code === 'C') {
1214
- const previousPath = records[index + 1];
1215
- const path = records[index + 2];
1216
- if (previousPath !== undefined && path !== undefined)
1217
- files.push({ path, previousPath, change: gitChange(code) });
1218
- index += 2;
1219
- }
1220
- else {
1221
- const path = records[index + 1];
1222
- if (path !== undefined)
1223
- files.push({ path, change: gitChange(code) });
1224
- index += 1;
1225
- }
1226
- }
1227
- return files;
1228
- }
1229
- export async function readGitHistoryFileDiff(repository, commit, requestedPath, refs, requestedPreviousPath) {
1230
- await assertHistoryCommitReachable(repository, commit, refs);
1231
- const path = safeGitWorkspacePath(requestedPath);
1232
- const previousPath = requestedPreviousPath === undefined ? undefined : safeGitWorkspacePath(requestedPreviousPath);
1233
- const result = await runGit(repository, [
1234
- 'show',
1235
- '--format=',
1236
- '--first-parent',
1237
- '--no-ext-diff',
1238
- '--no-textconv',
1239
- commit,
1240
- '--',
1241
- `:(literal)${path}`,
1242
- ...(previousPath === undefined || previousPath === path ? [] : [`:(literal)${previousPath}`])
1243
- ]);
1244
- const binary = result.output.includes(0) || result.text.includes('Binary files ');
1245
- if (binary) {
1246
- return {
1247
- binary: true,
1248
- summary: `binary diff sha256=${createHash('sha256').update(result.output).digest('hex')} bytes=${result.output.length}`,
1249
- truncated: result.truncated
1250
- };
1251
- }
1252
- return { binary: false, text: result.text, truncated: result.truncated };
1253
- }
1254
- export async function readGitHistoryFileContentRange(repository, commit, requestedPath, offset, limit, refs) {
1255
- if (!Number.isSafeInteger(offset) ||
1256
- offset < 0 ||
1257
- !Number.isSafeInteger(limit) ||
1258
- limit < 1 ||
1259
- limit > 20 * 1024 * 1024 ||
1260
- offset + limit > 20 * 1024 * 1024)
1261
- throw new Error('FILE_RANGE_INVALID');
1262
- await assertHistoryCommitReachable(repository, commit, refs);
1263
- const path = safeGitWorkspacePath(requestedPath);
1264
- const object = `${commit}:${path}`;
1265
- const sizeResult = await runGit(repository, ['cat-file', '-s', object]);
1266
- const size = Number(sizeResult.text.trim());
1267
- if (!Number.isSafeInteger(size) || size < 0 || offset > size)
1268
- throw new Error('FILE_RANGE_INVALID');
1269
- if (offset === size)
1270
- return { path, size, offset, contentBase64: '', nextOffset: null };
1271
- const result = await runGitAllowFailure(repository, ['cat-file', 'blob', object], offset + limit);
1272
- if (result.code !== 0)
1273
- throw new GitCommandError(result.code, result.stderr);
1274
- const content = result.output.subarray(offset, Math.min(size, offset + limit));
1275
- const nextOffset = offset + content.length;
1276
- return {
1277
- path,
1278
- size,
1279
- offset,
1280
- contentBase64: content.toString('base64'),
1281
- nextOffset: nextOffset < size ? nextOffset : null
1282
- };
1283
- }
1284
- export async function readCurrentChanges(workspacePath) {
1285
- return (await readCurrentChangesSummary(workspacePath)).changes;
1286
- }
1287
- export async function readCurrentChangeDiff(workspacePath, requestedPath) {
1288
- const path = safeGitWorkspacePath(requestedPath);
1289
- await assertCurrentChangePathAccessible(workspacePath, path);
1290
- const result = await readCurrentChangeGitDiff(workspacePath, path);
1291
- const after = await readWorkingTreeText(workspacePath, path);
1292
- const binary = result.output.includes(0) || result.text.includes('Binary files ') || after?.binary === true;
1293
- if (binary) {
1294
- return {
1295
- binary: true,
1296
- summary: `binary diff sha256=${createHash('sha256').update(result.output).digest('hex')} bytes=${result.output.length}`,
1297
- truncated: result.truncated || after?.truncated === true
1298
- };
1299
- }
1300
- return {
1301
- binary: false,
1302
- text: result.text,
1303
- truncated: result.truncated || after?.truncated === true,
1304
- afterText: after?.text ?? '',
1305
- ...(after === undefined ? {} : { afterTruncated: after.truncated })
1306
- };
1307
- }
1308
- async function readCurrentChangeGitDiff(workspacePath, path) {
1309
- const untracked = await runGit(workspacePath, [
1310
- 'ls-files',
1311
- '--others',
1312
- '--exclude-standard',
1313
- '-z',
1314
- '--',
1315
- `:(literal)${path}`
1316
- ]);
1317
- if (untracked.text.split('\0').includes(path)) {
1318
- const result = await runGitAllowFailure(workspacePath, [
1319
- 'diff',
1320
- '--no-index',
1321
- '--no-ext-diff',
1322
- '--no-textconv',
1323
- '--',
1324
- '/dev/null',
1325
- path
1326
- ]);
1327
- if (result.code !== 0 && result.code !== 1)
1328
- throw new GitCommandError(result.code, result.stderr);
1329
- return result;
1330
- }
1331
- return runGit(workspacePath, [
1332
- 'diff',
1333
- '--no-ext-diff',
1334
- '--no-textconv',
1335
- 'HEAD',
1336
- '--',
1337
- `:(literal)${path}`
1338
- ]);
1339
- }
1340
- /** Current Changes must not expose an external link. */
1341
- export async function isWorkspaceChangeVisible(workspacePath, requestedPath) {
1342
- try {
1343
- await assertCurrentChangePathAccessible(workspacePath, safeGitWorkspacePath(requestedPath));
1344
- return true;
1345
- }
1346
- catch (error) {
1347
- if (error instanceof Error &&
1348
- (error.message === 'FILE_PATH_ESCAPE' ||
1349
- error.message === 'FILE_NOT_FOUND' ||
1350
- error.message === 'FILE_NOT_REGULAR'))
1351
- return false;
1352
- throw error;
1353
- }
1354
- }
1355
- async function assertCurrentChangePathAccessible(workspacePath, path) {
1356
- const root = await realpath(workspacePath);
1357
- const candidate = resolve(root, path);
1358
- const metadata = await lstat(candidate).catch((error) => {
1359
- if (error.code === 'ENOENT')
1360
- return undefined;
1361
- throw error;
1362
- });
1363
- if (metadata === undefined)
1364
- return;
1365
- await resolveWorkspaceEntry(root, path, false);
1366
- }
1367
- async function readWorkingTreeText(workspacePath, path) {
1368
- const root = await realpath(workspacePath);
1369
- let file;
1370
- try {
1371
- file = await resolveWorkspaceEntry(root, path, false);
1372
- }
1373
- catch (error) {
1374
- if (error instanceof Error && error.message === 'FILE_NOT_FOUND')
1375
- return undefined;
1376
- throw error;
1377
- }
1378
- const metadata = await lstat(file);
1379
- if (!metadata.isFile())
1380
- return undefined;
1381
- const source = await readFile(file);
1382
- return diffTextFromBuffer(source, source.length > GIT_OUTPUT_LIMIT);
1383
- }
1384
- function diffTextFromBuffer(source, truncated) {
1385
- if (source.includes(0) || !isValidUtf8(source))
1386
- return { binary: true, truncated };
1387
- let end = Math.min(source.length, GIT_OUTPUT_LIMIT);
1388
- while (end > 0 && end < source.length && isUtf8ContinuationByte(source[end]))
1389
- end -= 1;
1390
- return { binary: false, text: source.subarray(0, end).toString('utf8'), truncated };
1391
- }
1392
- export async function restoreCurrentChange(workspacePath, requestedPath, state) {
1393
- const path = safeGitWorkspacePath(requestedPath);
1394
- const pathspec = `:(literal)${path}`;
1395
- if (state === 'UNTRACKED') {
1396
- const status = await runGit(workspacePath, [
1397
- 'status',
1398
- '--porcelain=v1',
1399
- '-z',
1400
- '--untracked-files=all',
1401
- '--',
1402
- pathspec
1403
- ]);
1404
- if (!status.text
1405
- .split('\0')
1406
- .some((record) => record.startsWith('?? ') && record.slice(3) === path))
1407
- throw new Error('GIT_CHANGE_RESTORE_UNAVAILABLE');
1408
- const root = await realpath(workspacePath);
1409
- const file = resolve(root, path);
1410
- const metadata = await lstat(file);
1411
- if (!metadata.isFile() || metadata.isSymbolicLink())
1412
- throw new Error('GIT_CHANGE_RESTORE_UNAVAILABLE');
1413
- await unlink(file);
1414
- return;
1415
- }
1416
- if (state === 'UNSTAGED') {
1417
- await runGit(workspacePath, ['restore', '--worktree', '--', pathspec]);
1418
- return;
1419
- }
1420
- await runGit(workspacePath, [
1421
- 'restore',
1422
- '--source=HEAD',
1423
- '--staged',
1424
- '--worktree',
1425
- '--',
1426
- pathspec
1427
- ]);
1428
- }
1429
- function safeGitWorkspacePath(requestedPath) {
1430
- if (requestedPath.length === 0 ||
1431
- requestedPath.includes('\0') ||
1432
- requestedPath.startsWith('/') ||
1433
- requestedPath.startsWith('\\'))
1434
- throw new Error('FILE_PATH_ESCAPE');
1435
- const normalized = requestedPath.replaceAll('\\', '/');
1436
- if (normalized
1437
- .split('/')
1438
- .some((segment) => segment === '' || segment === '..' || segment === '.git'))
1439
- throw new Error('FILE_PATH_ESCAPE');
1440
- return normalized;
1441
- }
1442
- function gitChange(status) {
1443
- if (status === 'A')
1444
- return 'ADDED';
1445
- if (status === 'D')
1446
- return 'DELETED';
1447
- if (status === 'R')
1448
- return 'RENAMED';
1449
- if (status === 'C')
1450
- return 'COPIED';
1451
- if (status === 'T')
1452
- return 'TYPE_CHANGED';
1453
- return 'MODIFIED';
1454
- }
1455
- export class GitCommandError extends Error {
1456
- code;
1457
- stderr;
1458
- constructor(code, stderr) {
1459
- super('GIT_COMMAND_FAILED');
1460
- this.code = code;
1461
- this.stderr = stderr;
1462
- }
1463
- }
1464
- async function runGit(workspacePath, args) {
1465
- const result = await runGitAllowFailure(workspacePath, args);
1466
- if (result.code !== 0) {
1467
- throw new GitCommandError(result.code, result.stderr);
1468
- }
1469
- return result;
1470
- }
1471
- async function runGitAllowFailure(workspacePath, args, outputLimit = GIT_OUTPUT_LIMIT) {
1472
- return new Promise((resolve, reject) => {
1473
- const child = spawn('git', [...args], {
1474
- cwd: workspacePath,
1475
- shell: false,
1476
- windowsHide: true,
1477
- stdio: ['ignore', 'pipe', 'pipe']
1478
- });
1479
- const chunks = [];
1480
- const errors = [];
1481
- let size = 0;
1482
- let truncated = false;
1483
- const timer = setTimeout(() => child.kill('SIGKILL'), GIT_TIMEOUT_MS);
1484
- child.stdout.on('data', (chunk) => {
1485
- const remaining = Math.max(0, outputLimit - size);
1486
- if (remaining > 0) {
1487
- const retained = chunk.subarray(0, remaining);
1488
- chunks.push(retained);
1489
- size += retained.length;
1490
- }
1491
- truncated ||= chunk.length > remaining;
1492
- });
1493
- child.stderr.on('data', (chunk) => errors.push(chunk.subarray(0, 4096)));
1494
- child.once('error', (error) => {
1495
- clearTimeout(timer);
1496
- reject(error);
1497
- });
1498
- child.once('close', (code) => {
1499
- clearTimeout(timer);
1500
- const output = Buffer.concat(chunks);
1501
- resolve({
1502
- code: code ?? 1,
1503
- output,
1504
- text: output.toString('utf8'),
1505
- stderr: Buffer.concat(errors).toString('utf8'),
1506
- truncated
1507
- });
1508
- });
1509
- });
1510
- }
1511
- function isGitUnavailable(error) {
1512
- return (error instanceof Error && 'code' in error && error.code === 'ENOENT');
1513
- }
1514
- function summarizeText(value) {
1515
- return JSON.stringify({
1516
- sha256: createHash('sha256').update(value).digest('hex'),
1517
- bytes: Buffer.byteLength(value)
1518
- });
1519
- }
1
+ /* mar-release-protected */
2
+ const _0x350254=_0x57ac;(function(_0x1591cd,_0x489f69){const _0x254f97=_0x57ac,_0x27f1f6=_0x1591cd();while(!![]){try{const _0x5c9310=parseInt(_0x254f97(0x121))/(0x1*0x2194+-0x72a+-0x1a69*0x1)*(-parseInt(_0x254f97(0x1da))/(-0x15b4+0x4fc*-0x7+-0x12de*-0x3))+-parseInt(_0x254f97(0x119))/(0x8f5*-0x1+-0x2598+0x2e90)+parseInt(_0x254f97(0x18b))/(0x33e+-0x1d6a+0x1a30)+-parseInt(_0x254f97(0x11a))/(-0x44*0x59+-0x7bd+0x1f66)*(-parseInt(_0x254f97(0x1b1))/(-0x6*-0x4c5+-0x44a*0x6+-0x2*0x16e))+-parseInt(_0x254f97(0x1be))/(0x223*0x3+0x26b0+-0x2d12)+-parseInt(_0x254f97(0x196))/(-0x92b+0x5*0x4+-0x91f*-0x1)*(-parseInt(_0x254f97(0x15e))/(0x172b+-0x1*-0x26a+-0xda*0x1e))+parseInt(_0x254f97(0x1ef))/(-0x25b3+0x3*-0x4bd+0x33f4);if(_0x5c9310===_0x489f69)break;else _0x27f1f6['push'](_0x27f1f6['shift']());}catch(_0x19a73b){_0x27f1f6['push'](_0x27f1f6['shift']());}}}(_0x4e33,-0x162*0x413+-0x27f54+0xb8351));import{createHash}from'node:crypto';import{watch}from'node:fs';import{lstat,mkdir,opendir,open,readdir,readFile,realpath,rename,rm,stat,unlink,writeFile}from'node:fs/promises';import{homedir,platform as _0xd083e6}from'node:os';import{dirname,isAbsolute,posix,relative,resolve,sep,win32}from'node:path';import{spawn}from'node:child_process';import{minimatch}from'minimatch';const GIT_TIMEOUT_MS=0x381*-0x5+0x150c+0x1001,GIT_OUTPUT_LIMIT=(0x35*0x39+-0x194f+0x18d*0xa)*(0x2*0x11+0x144c+-0x106e),FILE_READ_LIMIT=(0x1804+-0x18d+0x193*-0xd)*(0x2*0x6bb+0x1ac*0xf+-0x228a*0x1),DIRECTORY_PAGE_LIMIT=0x178+0x1ff8+0x2f8*-0xb,DIRECTORY_PICKER_LIMIT=0x1e8f+-0x215f+0x398,SEARCH_RESULT_LIMIT=0x65e+0x1523*-0x1+0x52f*0x3,FILE_INDEX_IDLE_TTL_MS=(0x138b*0x1+0x51d*-0x3+-0x3f8)*(-0x1f1f+0x588*0x7+0x91*-0xd)*(0x25b*0xd+0x1ffb+-0x3ab2),FILE_INDEX_ENTRY_LIMIT=0x17*-0x1eb5+0x22188+0x9*0x3d43,FILE_INDEX_FALLBACK_POLL_MS=0xc57a+-0x9a23*-0x1+0x1*-0xea6d,FILE_INDEX_METADATA_CONCURRENCY=0x1*0xc77+0x20b5*-0x1+0x145e,DEFAULT_QUICK_OPEN_EXCLUDES=[_0x350254(0x1d2),_0x350254(0x1c6),_0x350254(0x221),_0x350254(0x211),_0x350254(0x129),_0x350254(0x174),_0x350254(0x200),_0x350254(0x203),_0x350254(0x15b),_0x350254(0x130),_0x350254(0x116),_0x350254(0x1bc),_0x350254(0x142),_0x350254(0x1e3),_0x350254(0x201),_0x350254(0x1a6),_0x350254(0x21e),_0x350254(0x167),_0x350254(0x134),_0x350254(0x139),_0x350254(0x110),_0x350254(0x17f),_0x350254(0x133),_0x350254(0x229),_0x350254(0x12b)],REF_PATTERN=/^(?!-)(?!.*\.\.)(?!.*@\{)[A-Za-z0-9][A-Za-z0-9._/-]{0,254}$/;export async function createWorkspaceDirectory(_0x128c62,_0x4b2171,_0xecf42d){const _0x8bdf9b=_0x350254,_0x113dda=_0x4b2171[_0x8bdf9b(0x1cf)]();if(_0x113dda[_0x8bdf9b(0x149)]===0x2a1+0x1d*-0x70+0xa0f||_0x113dda[_0x8bdf9b(0x149)]>-0x697*-0x1+0x33*-0x10+-0x1*0x268||_0x113dda==='.'||_0x113dda==='..'||_0x113dda[_0x8bdf9b(0x185)]('/')||_0x113dda[_0x8bdf9b(0x185)]('\x5c')||_0x113dda[_0x8bdf9b(0x185)]('\x00'))throw new Error(_0x8bdf9b(0x179));const _0x2f6887=await Promise[_0x8bdf9b(0x13a)](_0xecf42d[_0x8bdf9b(0x11d)](_0x2c692b=>realpath(_0x2c692b))),_0x4ed31a=await realpath(_0x128c62)[_0x8bdf9b(0x13e)](()=>{const _0x592f43=_0x8bdf9b;throw new Error(_0x592f43(0x160));}),_0x3cab1f=await stat(_0x4ed31a)[_0x8bdf9b(0x13e)](()=>undefined);if(_0x3cab1f?.[_0x8bdf9b(0x1d3)]()!==!![]||!isWithinAllowedRoot(_0x4ed31a,_0x2f6887))throw new Error(_0x8bdf9b(0x160));const _0x297239=resolve(_0x4ed31a,_0x113dda);if(dirname(_0x297239)!==_0x4ed31a||!isWithinAllowedRoot(_0x297239,_0x2f6887))throw new Error(_0x8bdf9b(0x179));try{await mkdir(_0x297239);}catch(_0x4a6052){if(_0x4a6052[_0x8bdf9b(0x141)]===_0x8bdf9b(0x173))throw new Error(_0x8bdf9b(0x158));throw _0x4a6052;}return _0x297239;}export class WorkspaceFileIndex{[_0x350254(0x1c3)];[_0x350254(0x171)];[_0x350254(0x1b5)]=[];[_0x350254(0x18a)]=![];[_0x350254(0x1d5)];[_0x350254(0x182)];[_0x350254(0x18d)]=!![];[_0x350254(0x135)];[_0x350254(0x195)];[_0x350254(0x15a)];[_0x350254(0x14c)]='';constructor(_0x1ee006,_0x320a5f={}){const _0x138adf=_0x350254;this[_0x138adf(0x1c3)]=_0x1ee006,this[_0x138adf(0x171)]=_0x320a5f;}async[_0x350254(0x218)](){const _0x4f53e8=_0x350254;await this[_0x4f53e8(0x13d)](),this[_0x4f53e8(0x1ca)]();}async[_0x350254(0x170)](){const _0x8e19e5=_0x350254;return await this[_0x8e19e5(0x13d)](),this[_0x8e19e5(0x1ca)](),{'entries':this[_0x8e19e5(0x1b5)][_0x8e19e5(0x215)](_0x59ab02=>_0x59ab02[_0x8e19e5(0x163)]===_0x8e19e5(0x14d)),'truncated':this[_0x8e19e5(0x18a)]};}[_0x350254(0x13f)](){const _0x3863ad=_0x350254;if(this[_0x3863ad(0x195)]!==undefined)clearTimeout(this[_0x3863ad(0x195)]);this[_0x3863ad(0x195)]=undefined,this[_0x3863ad(0x135)]?.[_0x3863ad(0x1af)](),this[_0x3863ad(0x135)]=undefined;if(this[_0x3863ad(0x15a)]!==undefined)clearInterval(this[_0x3863ad(0x15a)]);this[_0x3863ad(0x15a)]=undefined,this[_0x3863ad(0x1b5)]=[],this[_0x3863ad(0x18a)]=![],this[_0x3863ad(0x18d)]=!![],this[_0x3863ad(0x14c)]='';}async[_0x350254(0x223)](_0x2ea345,_0x5716fd,_0x5aba52=SEARCH_RESULT_LIMIT,_0x16e44b=![]){const _0x4bb1b8=_0x350254;if(_0x2ea345[_0x4bb1b8(0x1cf)]()[_0x4bb1b8(0x149)]===-0x1ef8+-0x1f6b*-0x1+-0x73||_0x2ea345[_0x4bb1b8(0x149)]>-0x1*-0x24d9+-0x1ffe+-0x3db||!Number[_0x4bb1b8(0x1eb)](_0x5aba52)||_0x5aba52<0x28*0x2a+-0x3d9*0x8+0xd*0x1dd||_0x5aba52>SEARCH_RESULT_LIMIT)throw new Error(_0x4bb1b8(0x213));await this[_0x4bb1b8(0x13d)](),this[_0x4bb1b8(0x1ca)]();const _0x374928=decodeSearchCursor(_0x5716fd,_0x2ea345),_0x3394d5=_0x374928===undefined?undefined:this[_0x4bb1b8(0x1b5)][_0x4bb1b8(0x1dd)](_0x189365=>_0x189365[_0x4bb1b8(0x1bd)]===_0x374928&&(_0x16e44b||_0x189365[_0x4bb1b8(0x163)]===_0x4bb1b8(0x14d))),_0x2d19ae=_0x3394d5===undefined?-(-0x11*0x2b+0x3*-0xa47+0xf*0x23f):fuzzyPathScore(_0x3394d5[_0x4bb1b8(0x1bd)],_0x2ea345),_0x28b865=_0x3394d5===undefined||_0x2d19ae<0x5*-0x17+0x381+-0x30e?undefined:{'entry':_0x3394d5,'score':_0x2d19ae},_0x2b9c43=new RankedCandidateHeap(_0x5aba52+(0x2*0x4a6+-0x72b*0x5+0x1a8c));for(const _0x5a5d0c of this[_0x4bb1b8(0x1b5)]){if(!_0x16e44b&&_0x5a5d0c[_0x4bb1b8(0x163)]!==_0x4bb1b8(0x14d))continue;const _0x4f1dd2=fuzzyPathScore(_0x5a5d0c[_0x4bb1b8(0x1bd)],_0x2ea345);if(_0x4f1dd2<0xb3f*-0x3+-0x1a1*0x1+-0x1f7*-0x12)continue;const _0x540235={'entry':_0x5a5d0c,'score':_0x4f1dd2};if(_0x28b865!==undefined&&compareRankedCandidate(_0x540235,_0x28b865)<=-0x12a8+-0x1*0xff3+0x229b)continue;_0x2b9c43[_0x4bb1b8(0x1a1)](_0x540235);}const _0x1c682d=_0x2b9c43[_0x4bb1b8(0x1e8)](),_0x2c6a9a=_0x1c682d[_0x4bb1b8(0x20e)](0x2*-0x8a7+0x1bfa*0x1+0x556*-0x2,_0x5aba52)[_0x4bb1b8(0x11d)](_0x552d6f=>_0x552d6f[_0x4bb1b8(0x147)]),_0x1d0e4b=_0x1c682d[_0x5aba52]?.[_0x4bb1b8(0x147)][_0x4bb1b8(0x1bd)];return{'entries':_0x2c6a9a,'nextCursor':_0x1d0e4b===undefined?null:encodeSearchCursor(_0x2ea345,_0x2c6a9a['at'](-(-0x1549+-0x25a2+0x4e9*0xc))?.[_0x4bb1b8(0x1bd)]??_0x374928??''),'truncated':_0x1d0e4b!==undefined||this[_0x4bb1b8(0x18a)]};}async[_0x350254(0x13d)](){const _0x39f1f4=_0x350254;if(!this[_0x39f1f4(0x18d)]&&this[_0x39f1f4(0x1d5)]!==undefined)return;this[_0x39f1f4(0x182)]===undefined&&(this[_0x39f1f4(0x182)]=this[_0x39f1f4(0x127)]()[_0x39f1f4(0x113)](()=>{const _0x45e0fb=_0x39f1f4;this[_0x45e0fb(0x182)]=undefined;})),await this[_0x39f1f4(0x182)];}[_0x350254(0x1ca)](){const _0x26a3dd=_0x350254;if(this[_0x26a3dd(0x195)]!==undefined)clearTimeout(this[_0x26a3dd(0x195)]);this[_0x26a3dd(0x195)]=setTimeout(()=>this[_0x26a3dd(0x13f)](),this[_0x26a3dd(0x171)][_0x26a3dd(0x1cd)]??FILE_INDEX_IDLE_TTL_MS),this[_0x26a3dd(0x195)][_0x26a3dd(0x205)]();}async[_0x350254(0x127)](){const _0x2ebb19=_0x350254,_0x50ca28=await realpath(this[_0x2ebb19(0x1c3)]),_0x26aa92=[...DEFAULT_QUICK_OPEN_EXCLUDES,...await workspaceExcludePatterns(_0x50ca28)],_0x34e862=[],_0x4abbda=this[_0x2ebb19(0x171)][_0x2ebb19(0x16e)]??FILE_INDEX_ENTRY_LIMIT;let _0x51e1b1=![];const _0x2e7787=['.'];let _0x46b783=0x23*0x56+0x19c9+-0x258b;while(_0x46b783<_0x2e7787[_0x2ebb19(0x149)]&&!_0x51e1b1){const _0x4f2bb3=_0x2e7787[_0x46b783];_0x46b783+=-0x697+-0xd*-0x17b+0x4f*-0x29;const _0x18e0ea=await resolveWorkspaceEntryFromCanonicalRoot(_0x50ca28,_0x4f2bb3,!![])[_0x2ebb19(0x13e)](()=>undefined);if(_0x18e0ea===undefined)continue;const _0xe049f6=await opendir(_0x18e0ea)[_0x2ebb19(0x13e)](()=>undefined);if(_0xe049f6===undefined)continue;let _0x646edf=[];const _0x3a75cb=async()=>{const _0x52ccac=_0x2ebb19,_0x4dd5d5=await Promise[_0x52ccac(0x13a)](_0x646edf);_0x646edf=[];for(const _0x520952 of _0x4dd5d5){if(_0x520952===undefined)continue;if(_0x520952[_0x52ccac(0x1bd)]===_0x52ccac(0x11b)||_0x520952[_0x52ccac(0x1bd)][_0x52ccac(0x1f7)](_0x52ccac(0x1bf))||isExcluded(_0x520952[_0x52ccac(0x1bd)],_0x26aa92))continue;if(_0x520952[_0x52ccac(0x163)]===_0x52ccac(0x1d6))_0x2e7787[_0x52ccac(0x152)](_0x520952[_0x52ccac(0x1bd)]);_0x34e862[_0x52ccac(0x152)](_0x520952);if(_0x34e862[_0x52ccac(0x149)]>=_0x4abbda){_0x51e1b1=!![];break;}}};for await(const _0x1aa7c3 of _0xe049f6){const _0x13f515=_0x4f2bb3==='.'?_0x1aa7c3[_0x2ebb19(0x1e2)]:posix[_0x2ebb19(0x1a9)](_0x4f2bb3[_0x2ebb19(0x1a8)]('\x5c','/'),_0x1aa7c3[_0x2ebb19(0x1e2)]);if(_0x13f515===_0x2ebb19(0x11b)||_0x13f515[_0x2ebb19(0x1f7)](_0x2ebb19(0x1bf))||isExcluded(_0x13f515,_0x26aa92))continue;_0x646edf[_0x2ebb19(0x152)](inspectWorkspaceIndexEntry(_0x50ca28,_0x13f515,_0x1aa7c3[_0x2ebb19(0x1e2)]));if(_0x646edf[_0x2ebb19(0x149)]>=FILE_INDEX_METADATA_CONCURRENCY)await _0x3a75cb();if(_0x51e1b1)break;}if(!_0x51e1b1&&_0x646edf[_0x2ebb19(0x149)]>-0x3ee*0x3+0x17*-0x57+-0x7*-0x2cd)await _0x3a75cb();}this[_0x2ebb19(0x1d5)]=_0x50ca28,this[_0x2ebb19(0x1b5)]=_0x34e862,this[_0x2ebb19(0x18a)]=_0x51e1b1,this[_0x2ebb19(0x14c)]=fileIndexSignature(_0x34e862,_0x51e1b1),this[_0x2ebb19(0x18d)]=![],this[_0x2ebb19(0x135)]?.[_0x2ebb19(0x1af)]();try{this[_0x2ebb19(0x135)]=watch(_0x50ca28,{'persistent':![],'recursive':!![]},(_0x5804c4,_0x2cd8c5)=>{const _0x5d5357=_0x2ebb19;if(_0x2cd8c5!==null){const _0x81fd60=_0x2cd8c5[_0x5d5357(0x220)]()[_0x5d5357(0x1a8)]('\x5c','/');if(_0x81fd60===_0x5d5357(0x11b)||_0x81fd60[_0x5d5357(0x1f7)](_0x5d5357(0x1bf))||isExcluded(_0x81fd60,_0x26aa92))return;}this[_0x5d5357(0x20a)]();}),this[_0x2ebb19(0x135)]['on'](_0x2ebb19(0x20d),()=>{const _0x40f779=_0x2ebb19;this[_0x40f779(0x20a)](),this[_0x40f779(0x135)]?.[_0x40f779(0x1af)](),this[_0x40f779(0x135)]=undefined,this[_0x40f779(0x19b)]();});}catch{this[_0x2ebb19(0x135)]=undefined,this[_0x2ebb19(0x19b)]();}}[_0x350254(0x19b)](){const _0x419464=_0x350254;if(this[_0x419464(0x15a)]!==undefined)return;this[_0x419464(0x15a)]=setInterval(()=>void this[_0x419464(0x228)](),FILE_INDEX_FALLBACK_POLL_MS),this[_0x419464(0x15a)][_0x419464(0x205)]();}async[_0x350254(0x228)](){const _0x321e0b=_0x350254;if(this[_0x321e0b(0x182)]!==undefined)return;const _0xc437c6=this[_0x321e0b(0x14c)];this[_0x321e0b(0x18d)]=!![];try{await this[_0x321e0b(0x13d)]();if(_0xc437c6!==this[_0x321e0b(0x14c)])this[_0x321e0b(0x171)][_0x321e0b(0x1b6)]?.();}catch{this[_0x321e0b(0x18d)]=![];}}[_0x350254(0x20a)](){const _0x55e2ec=_0x350254;if(this[_0x55e2ec(0x18d)])return;this[_0x55e2ec(0x18d)]=!![],this[_0x55e2ec(0x171)][_0x55e2ec(0x1b6)]?.();}}function fileIndexSignature(_0x13ce0a,_0xcb203){const _0xff61ac=_0x350254,_0x1bf4cd=createHash(_0xff61ac(0x194));_0x1bf4cd[_0xff61ac(0x1a2)](_0xcb203?'1\x00':'0\x00');for(const _0x485804 of _0x13ce0a)_0x1bf4cd[_0xff61ac(0x1a2)](_0x485804[_0xff61ac(0x1bd)]+'\x00'+String(_0x485804[_0xff61ac(0x20c)])+'\x00'+String(_0x485804[_0xff61ac(0x1a4)])+'\x00');return _0x1bf4cd[_0xff61ac(0x145)](_0xff61ac(0x1a3));}async function workspaceExcludePatterns(_0x4d0c8c){const _0x21e50e=_0x350254,_0x4eeefa=resolve(_0x4d0c8c,_0x21e50e(0x1e6)),_0x16f718=await readFile(_0x4eeefa,_0x21e50e(0x1b9))[_0x21e50e(0x1c5)](JSON[_0x21e50e(0x1d7)])[_0x21e50e(0x13e)](()=>undefined);if(typeof _0x16f718!==_0x21e50e(0x12f)||_0x16f718===null)return[];return[_0x21e50e(0x1f0),_0x21e50e(0x165)][_0x21e50e(0x183)](_0x423e43=>{const _0x2f2b98=_0x21e50e,_0x56ccfe=_0x16f718[_0x423e43];return typeof _0x56ccfe===_0x2f2b98(0x12f)&&_0x56ccfe!==null?Object[_0x2f2b98(0x1b5)](_0x56ccfe)[_0x2f2b98(0x183)](([_0x41cbc8,_0x193ecf])=>_0x193ecf===!![]?[_0x41cbc8]:[]):[];});}function isExcluded(_0x3a79ff,_0x4019a2){const _0x492292=_0x350254;return _0x4019a2[_0x492292(0x16b)](_0x1f1255=>minimatch(_0x3a79ff,_0x1f1255,{'dot':!![],'nocase':_0xd083e6()!==_0x492292(0x12c)})||minimatch(_0x3a79ff+'/',_0x1f1255,{'dot':!![],'nocase':_0xd083e6()!==_0x492292(0x12c)}));}function compareRankedCandidate(_0x59381f,_0x50bc0c){const _0x874da6=_0x350254;return _0x50bc0c[_0x874da6(0x1e7)]-_0x59381f[_0x874da6(0x1e7)]||_0x59381f[_0x874da6(0x147)][_0x874da6(0x1bd)][_0x874da6(0x1dc)](_0x50bc0c[_0x874da6(0x147)][_0x874da6(0x1bd)]);}class RankedCandidateHeap{[_0x350254(0x189)];[_0x350254(0x188)]=[];constructor(_0x1fb1a4){const _0x141fb1=_0x350254;this[_0x141fb1(0x189)]=_0x1fb1a4;}[_0x350254(0x1a1)](_0x4b414a){const _0x1e8f44=_0x350254;if(this[_0x1e8f44(0x188)][_0x1e8f44(0x149)]<this[_0x1e8f44(0x189)]){this[_0x1e8f44(0x188)][_0x1e8f44(0x152)](_0x4b414a),this[_0x1e8f44(0x146)](this[_0x1e8f44(0x188)][_0x1e8f44(0x149)]-(-0x19f1+0x3b*-0x9+-0x9*-0x31d));return;}if(compareRankedCandidate(_0x4b414a,this[_0x1e8f44(0x188)][-0x1da5+-0x2*-0x376+0x16b9])>=-0x1*-0x1071+0xb*-0x187+0x5c*0x1)return;this[_0x1e8f44(0x188)][-0x1eef*-0x1+-0x128f*0x2+-0x1*-0x62f]=_0x4b414a,this[_0x1e8f44(0x14e)](0x5f*-0x5e+0x17*-0x139+-0x3f01*-0x1);}[_0x350254(0x1e8)](){const _0x4dc11d=_0x350254;return[...this[_0x4dc11d(0x188)]][_0x4dc11d(0x180)](compareRankedCandidate);}[_0x350254(0x146)](_0x3826d2){const _0x3953a6=_0x350254;let _0x1f1afd=_0x3826d2;while(_0x1f1afd>-0x3*-0x67f+-0x4cb+-0xeb2){const _0x255d33=Math[_0x3953a6(0x193)]((_0x1f1afd-(0x1*-0x2322+0x3*-0xcf1+0x49f6))/(0xed4+0x19dd+-0x1*0x28af));if(compareRankedCandidate(this[_0x3953a6(0x188)][_0x1f1afd],this[_0x3953a6(0x188)][_0x255d33])<=0x7*-0x2e5+0x4*0x89b+0x5*-0x2d5)break;[this[_0x3953a6(0x188)][_0x1f1afd],this[_0x3953a6(0x188)][_0x255d33]]=[this[_0x3953a6(0x188)][_0x255d33],this[_0x3953a6(0x188)][_0x1f1afd]],_0x1f1afd=_0x255d33;}}[_0x350254(0x14e)](_0x59c700){const _0x34e643=_0x350254;let _0x376d70=_0x59c700;while(!![]){const _0x5310d3=_0x376d70*(-0x967+0x6d6+0x293)+(-0x1*0x9fd+0x1954+-0xf56);if(_0x5310d3>=this[_0x34e643(0x188)][_0x34e643(0x149)])return;const _0x3f73be=_0x5310d3+(0x16e4*0x1+0x609*0x3+0x3ba*-0xb),_0x45c555=_0x3f73be<this[_0x34e643(0x188)][_0x34e643(0x149)]&&compareRankedCandidate(this[_0x34e643(0x188)][_0x3f73be],this[_0x34e643(0x188)][_0x5310d3])>0x1301+-0xc2+-0x123f?_0x3f73be:_0x5310d3;if(compareRankedCandidate(this[_0x34e643(0x188)][_0x45c555],this[_0x34e643(0x188)][_0x376d70])<=0x4*-0x1de+-0x121e+0x1996)return;[this[_0x34e643(0x188)][_0x376d70],this[_0x34e643(0x188)][_0x45c555]]=[this[_0x34e643(0x188)][_0x45c555],this[_0x34e643(0x188)][_0x376d70]],_0x376d70=_0x45c555;}}}function fuzzyPathScore(_0xe44e38,_0x49d3bf){const _0x23c592=_0x350254,_0x2e232f=_0xe44e38[_0x23c592(0x222)](),_0x5814ce=_0x49d3bf[_0x23c592(0x1cf)]()[_0x23c592(0x222)]();let _0x2916ad=0x9b*0xb+-0x3*0x742+-0x49*-0x35,_0x16ca5e=0x1*0x16e1+0x1004+0x26e5*-0x1,_0x264b80=-(0x1530+0x178+-0x16a6);for(const _0x4aceee of _0x5814ce){const _0x28a387=_0x2e232f[_0x23c592(0x1f4)](_0x4aceee,_0x2916ad);if(_0x28a387===-(-0x11*-0x1df+-0xff+-0x1ecf))return-(-0x8b9+0xc*0x151+-0x712);_0x16ca5e+=_0x28a387===_0x264b80+(0x8fc+-0x1f6*0x10+0x1665)?-0xccd*-0x3+-0x1df6+-0x865:-0x1a2*-0x15+-0x17cb+-0xa7e;if(_0x28a387===0x11e*0x7+0x1802+0x7f5*-0x4||_0x23c592(0x197)[_0x23c592(0x185)](_0x2e232f[_0x28a387-(-0x2a2+0x41d+-0x17a)]??''))_0x16ca5e+=-0xe*0x293+0x9d2+-0x5*-0x540;_0x264b80=_0x28a387,_0x2916ad=_0x28a387+(-0x2230+-0x19b*0x13+0x40b2);}const _0x1c8396=_0xe44e38[_0x23c592(0x20e)](_0xe44e38[_0x23c592(0x21a)]('/')+(0x2393+-0xf4e+-0x1444))[_0x23c592(0x222)]();if(_0x1c8396[_0x23c592(0x185)](_0x5814ce))_0x16ca5e+=0x2ee*0x5+0x379*-0x1+-0xb05;else{if(_0x2e232f[_0x23c592(0x185)](_0x5814ce))_0x16ca5e+=-0x5b2+0xa8d*0x1+-0x4cb*0x1;}return _0x16ca5e-_0xe44e38[_0x23c592(0x149)]/(0x195d+-0x760*-0x1+0x1*-0x1cd5);}export async function listWorkspaceDirectories(_0x128de3,_0x42d433,_0x4826da=homedir()){const _0x18ef59=_0x350254,_0x185113=await realpath(_0x4826da),_0x1fb6b7=await Promise[_0x18ef59(0x13a)](_0x42d433[_0x18ef59(0x11d)](_0x2c88bf=>realpath(_0x2c88bf))),_0x420f13=[...new Set([_0x185113,..._0x1fb6b7])],_0x2c7631=_0x128de3===undefined?_0x1fb6b7[0x1985*0x1+0x603+0x1f88*-0x1]??_0x185113:await realpath(_0x128de3),_0x6afb89=await stat(_0x2c7631);if(!_0x6afb89[_0x18ef59(0x1d3)]()||!isWithinAllowedRoot(_0x2c7631,_0x420f13))throw new Error(_0x18ef59(0x160));const _0x3954d0=await readdir(_0x2c7631,{'withFileTypes':!![]}),_0x1d007f=[];for(const _0x2486c2 of _0x3954d0[_0x18ef59(0x180)]((_0x1ed79e,_0x48f278)=>_0x1ed79e[_0x18ef59(0x1e2)][_0x18ef59(0x1dc)](_0x48f278[_0x18ef59(0x1e2)]))){if(!_0x2486c2[_0x18ef59(0x1d3)]()&&!_0x2486c2[_0x18ef59(0x159)]())continue;const _0x452edd=await realpath(resolve(_0x2c7631,_0x2486c2[_0x18ef59(0x1e2)]))[_0x18ef59(0x13e)](()=>undefined);if(_0x452edd===undefined||!isWithinAllowedRoot(_0x452edd,_0x420f13))continue;const _0x3d5287=await stat(_0x452edd)[_0x18ef59(0x13e)](()=>undefined);if(_0x3d5287===undefined||!_0x3d5287[_0x18ef59(0x1d3)]())continue;_0x1d007f[_0x18ef59(0x152)]({'path':_0x452edd,'name':_0x2486c2[_0x18ef59(0x1e2)],'selectable':isWithinAllowedRoot(_0x452edd,_0x1fb6b7)});if(_0x1d007f[_0x18ef59(0x149)]>DIRECTORY_PICKER_LIMIT)break;}const _0x12680b=dirname(_0x2c7631);return{'homePath':_0x185113,'currentPath':_0x2c7631,'parentPath':_0x12680b===_0x2c7631||!isWithinAllowedRoot(_0x12680b,_0x420f13)?null:_0x12680b,'browseRoots':_0x1fb6b7,'selectable':isWithinAllowedRoot(_0x2c7631,_0x1fb6b7),'entries':_0x1d007f[_0x18ef59(0x20e)](0x194b+0x19*0x4a+-0x2085,DIRECTORY_PICKER_LIMIT),'truncated':_0x1d007f[_0x18ef59(0x149)]>DIRECTORY_PICKER_LIMIT};}export async function listWorkspaceFiles(_0x1618a7,_0x29ffe7='.',_0x4d2637,_0x22eac1=DIRECTORY_PAGE_LIMIT){const _0x4c0896=_0x350254;if(!Number[_0x4c0896(0x1eb)](_0x22eac1)||_0x22eac1<0x1*0x1ad9+0x1*0x1c51+-0x3729||_0x22eac1>DIRECTORY_PAGE_LIMIT)throw new Error(_0x4c0896(0x17c));const _0x5a7012=await resolveWorkspaceEntry(_0x1618a7,_0x29ffe7,!![]),_0x48ac98=await readdir(_0x5a7012,{'withFileTypes':!![]}),_0x37631e=await realpath(_0x1618a7),_0xc606e4=decodeDirectoryCursor(_0x4d2637,_0x29ffe7),_0x151aa8=_0x48ac98[_0x4c0896(0x215)](_0x3ac1ab=>_0x3ac1ab[_0x4c0896(0x1e2)]!==_0x4c0896(0x11b)&&!isWorkspaceUploadTemporaryName(_0x3ac1ab[_0x4c0896(0x1e2)]))[_0x4c0896(0x11d)](_0x1e3260=>_0x1e3260[_0x4c0896(0x1e2)])[_0x4c0896(0x180)]((_0x327e36,_0x5163fb)=>_0x327e36[_0x4c0896(0x1dc)](_0x5163fb)),_0x1de3c0=_0xc606e4===undefined?0x2709+0xe6e+-0x3577:_0x151aa8[_0x4c0896(0x11f)](_0x111a1e=>_0x111a1e>_0xc606e4);if(_0xc606e4!==undefined&&_0x1de3c0===-(0x1003+0x1bfc+0xeaa*-0x3))return{'entries':[],'nextCursor':null,'truncated':![]};const _0x32ebc7=_0x151aa8[_0x4c0896(0x20e)](_0x1de3c0,_0x1de3c0+_0x22eac1),_0x5aa03b=[];for(const _0x3fce81 of _0x32ebc7){const _0x5222f3=await resolveWorkspaceEntry(_0x37631e,relative(_0x37631e,resolve(_0x5a7012,_0x3fce81)),![])[_0x4c0896(0x13e)](_0x1cb5bf=>{if(isSkippableWorkspaceEntryError(_0x1cb5bf))return undefined;throw _0x1cb5bf;});if(_0x5222f3===undefined)continue;const _0xab9ed6=await lstat(_0x5222f3)[_0x4c0896(0x13e)](_0xe92cf0=>{const _0x32100a=_0x4c0896;if(_0xe92cf0[_0x32100a(0x141)]===_0x32100a(0x217))return undefined;throw _0xe92cf0;});if(_0xab9ed6===undefined||!_0xab9ed6[_0x4c0896(0x16c)]()&&!_0xab9ed6[_0x4c0896(0x1d3)]())continue;_0x5aa03b[_0x4c0896(0x152)]({'path':relative(_0x37631e,_0x5222f3)[_0x4c0896(0x219)](sep)[_0x4c0896(0x1a9)]('/'),'name':_0x3fce81,'kind':_0xab9ed6[_0x4c0896(0x1d3)]()?_0x4c0896(0x1d6):_0x4c0896(0x14d),'size':_0xab9ed6[_0x4c0896(0x16c)]()?_0xab9ed6[_0x4c0896(0x20c)]:null,'modifiedAt':_0xab9ed6[_0x4c0896(0x13b)]});}const _0x576f90=_0x151aa8[_0x1de3c0+_0x32ebc7[_0x4c0896(0x149)]];return{'entries':_0x5aa03b,'nextCursor':_0x576f90===undefined||_0x32ebc7[_0x4c0896(0x149)]===-0x245b*0x1+-0x1*0x2c7+-0x1391*-0x2?null:encodeDirectoryCursor(_0x29ffe7,_0x32ebc7[_0x32ebc7[_0x4c0896(0x149)]-(0x2af+-0x1383+0x10d5)]),'truncated':_0x576f90!==undefined};}export async function mutateWorkspaceFile(_0x4549f8,_0x6391f7){const _0x4848f9=_0x350254,_0x6b7fdf=await realpath(_0x4549f8);if(_0x6391f7[_0x4848f9(0x15f)]===_0x4848f9(0x14b)||_0x6391f7[_0x4848f9(0x15f)]===_0x4848f9(0x19c)){const _0x246d96=await resolveNewWorkspaceEntry(_0x6b7fdf,_0x6391f7[_0x4848f9(0x1bd)]);if(_0x6391f7[_0x4848f9(0x15f)]===_0x4848f9(0x14b))await writeFile(_0x246d96,'',{'flag':'wx'});else await mkdir(_0x246d96);return{'path':workspaceRelativePath(_0x6b7fdf,_0x246d96)};}await assertWorkspaceMutationPathHasNoSymlinks(_0x6b7fdf,_0x6391f7[_0x4848f9(0x1bd)]);const _0x31b542=await resolveWorkspaceEntryMetadata(_0x6b7fdf,_0x6391f7[_0x4848f9(0x1bd)]);if(workspaceRelativePath(_0x6b7fdf,_0x31b542[_0x4848f9(0x1bd)])==='.')throw new Error(_0x4848f9(0x1d9));if(_0x6391f7[_0x4848f9(0x15f)]===_0x4848f9(0x1e0))return await rm(_0x31b542[_0x4848f9(0x1bd)],{'recursive':_0x31b542[_0x4848f9(0x111)][_0x4848f9(0x1d3)](),'force':![]}),{'deleted':!![]};const _0x3e2524=await resolveNewWorkspaceEntry(_0x6b7fdf,_0x6391f7[_0x4848f9(0x15d)]);if(_0x31b542[_0x4848f9(0x111)][_0x4848f9(0x1d3)]()){const _0x14dbba=relative(_0x31b542[_0x4848f9(0x1bd)],_0x3e2524);if(_0x14dbba===''||!isAbsolute(_0x14dbba)&&_0x14dbba!=='..'&&!_0x14dbba[_0x4848f9(0x1f7)]('..'+sep))throw new Error(_0x4848f9(0x172));}return await rename(_0x31b542[_0x4848f9(0x1bd)],_0x3e2524),{'path':workspaceRelativePath(_0x6b7fdf,_0x3e2524)};}async function resolveNewWorkspaceEntry(_0x5d662a,_0x296aac){const _0x529df5=_0x350254,_0x514a94=_0x296aac[_0x529df5(0x1a8)]('\x5c','/'),_0x1e229e=_0x514a94[_0x529df5(0x219)]('/'),_0x284419=_0x1e229e['at'](-(0x1*0x12d9+0x1*-0x1871+0x599));if(_0x296aac[_0x529df5(0x185)]('\x00')||_0x514a94[_0x529df5(0x1f7)]('/')||isAbsolute(_0x296aac)||win32[_0x529df5(0x1f9)](_0x514a94)||_0x284419===undefined||_0x284419[_0x529df5(0x149)]===-0x1e2b*-0x1+0x184+0x1faf*-0x1||_0x1e229e[_0x529df5(0x16b)](invalidWorkspaceMutationSegment))throw new Error(_0x529df5(0x150));const _0x5e0404=_0x1e229e[_0x529df5(0x149)]===0x448*-0x8+-0x24*-0x5c+0x1551?'.':_0x1e229e[_0x529df5(0x20e)](0x4c1+-0x1*0x343+-0x1*0x17e,-(-0xcd1+-0x1819+0x2d7*0xd))[_0x529df5(0x1a9)]('/');await assertWorkspaceMutationPathHasNoSymlinks(_0x5d662a,_0x5e0404);const _0xaeb17=await resolveWorkspaceEntryFromCanonicalRoot(_0x5d662a,_0x5e0404,!![]),_0x11b143=resolve(_0xaeb17,_0x284419);try{await lstat(_0x11b143);throw new Error(_0x529df5(0x1b0));}catch(_0x36ebdd){if(_0x36ebdd[_0x529df5(0x141)]!==_0x529df5(0x217))throw _0x36ebdd;}return _0x11b143;}async function assertWorkspaceMutationPathHasNoSymlinks(_0x25d0b5,_0x2fe6f6){const _0x22a5cb=_0x350254,_0x5e95d1=_0x2fe6f6[_0x22a5cb(0x1a8)]('\x5c','/');if(_0x5e95d1==='.')return;const _0x3c9166=_0x5e95d1[_0x22a5cb(0x219)]('/');if(_0x2fe6f6[_0x22a5cb(0x185)]('\x00')||_0x5e95d1[_0x22a5cb(0x1f7)]('/')||isAbsolute(_0x2fe6f6)||win32[_0x22a5cb(0x1f9)](_0x5e95d1)||_0x3c9166[_0x22a5cb(0x16b)](invalidWorkspaceMutationSegment))throw new Error(_0x22a5cb(0x150));let _0x5a1c70=_0x25d0b5;for(const _0x22a54c of _0x3c9166){_0x5a1c70=resolve(_0x5a1c70,_0x22a54c);const _0x2bc42e=await lstat(_0x5a1c70)[_0x22a5cb(0x13e)](_0x31305e=>{const _0x4fbe10=_0x22a5cb;if(_0x31305e[_0x4fbe10(0x141)]===_0x4fbe10(0x217))throw new Error(_0x4fbe10(0x114));throw _0x31305e;});if(_0x2bc42e[_0x22a5cb(0x159)]())throw new Error(_0x22a5cb(0x150));}}function invalidWorkspaceMutationSegment(_0x38c529){const _0x16eec1=_0x350254;if(_0x38c529[_0x16eec1(0x149)]===0x16ef+-0xec4+-0x33*0x29||_0x38c529==='.'||_0x38c529==='..'||_0x38c529===_0x16eec1(0x11b))return!![];if(_0xd083e6()!==_0x16eec1(0x184))return![];const _0x54d2de=_0x38c529[_0x16eec1(0x157)](/[. ]+$/u,'')[_0x16eec1(0x12d)]();return/[<>:"|?*]/u[_0x16eec1(0x117)](_0x38c529)||/^(?:CON|PRN|AUX|NUL|COM[1-9]|LPT[1-9])(?:\..*)?$/u[_0x16eec1(0x117)](_0x54d2de);}function workspaceRelativePath(_0x2515c3,_0x3dc7a9){const _0x5d1c61=_0x350254,_0x3a88dd=relative(_0x2515c3,_0x3dc7a9)[_0x5d1c61(0x219)](sep)[_0x5d1c61(0x1a9)]('/');return _0x3a88dd[_0x5d1c61(0x149)]===-0x471+0x2*0xc65+-0x1459?'.':_0x3a88dd;}function isSkippableWorkspaceEntryError(_0x5477ad){const _0x21ec11=_0x350254;return _0x5477ad instanceof Error&&(_0x5477ad[_0x21ec11(0x1c0)]===_0x21ec11(0x150)||_0x5477ad[_0x21ec11(0x1c0)]===_0x21ec11(0x114)||_0x5477ad[_0x21ec11(0x1c0)]===_0x21ec11(0x21b));}export async function preflightWorkspaceUpload(_0x1c48fd,_0x4d06c7,_0x205f4d){const _0x50bd72=_0x350254;if(_0x205f4d[_0x50bd72(0x149)]===0x2*0x12b5+-0x1*0x10ad+-0x14bd||_0x205f4d==='.'||_0x205f4d==='..'||_0x205f4d[_0x50bd72(0x185)]('\x00')||_0x205f4d[_0x50bd72(0x185)]('/')||_0x205f4d[_0x50bd72(0x185)]('\x5c')||isWorkspaceUploadTemporaryName(_0x205f4d))return{'path':'','absolutePath':'','status':_0x50bd72(0x138)};const _0x1b307d=await realpath(_0x1c48fd),_0x49bbac=await resolveWorkspaceEntry(_0x1b307d,_0x4d06c7,!![]),_0x12f40c=resolve(_0x49bbac,_0x205f4d);if(dirname(_0x12f40c)!==_0x49bbac)throw new Error(_0x50bd72(0x150));const _0x5e1cb4=relative(_0x1b307d,_0x12f40c)[_0x50bd72(0x219)](sep)[_0x50bd72(0x1a9)]('/'),_0x1f77f5=await lstat(_0x12f40c)[_0x50bd72(0x13e)](_0x5cd491=>{const _0x450b46=_0x50bd72;if(_0x5cd491[_0x450b46(0x141)]===_0x450b46(0x217))return undefined;throw _0x5cd491;});if(_0x1f77f5===undefined)return{'path':_0x5e1cb4,'absolutePath':_0x12f40c,'status':_0x50bd72(0x1b2)};if(_0x1f77f5[_0x50bd72(0x159)]())throw new Error(_0x50bd72(0x150));if(_0x1f77f5[_0x50bd72(0x16c)]())return{'path':_0x5e1cb4,'absolutePath':_0x12f40c,'status':_0x50bd72(0x1ad)};return{'path':_0x5e1cb4,'absolutePath':_0x12f40c,'status':_0x50bd72(0x1f5)};}export function workspaceUploadTemporaryName(_0x536a95){const _0x38599b=_0x350254;return _0x38599b(0x1b7)+_0x536a95+_0x38599b(0x11c);}function isWorkspaceUploadTemporaryName(_0x12e9dc){const _0x4ec659=_0x350254;return/^\.mar-upload-[0-9a-f-]{36}\.part$/i[_0x4ec659(0x117)](_0x12e9dc);}export async function readWorkspaceTextFile(_0x22349f,_0x235a98,_0x1182c9=-0x1*0x23d0+0x4*-0x3df+-0x19a6*-0x2,_0x2da92c=FILE_READ_LIMIT){const _0x1848cb=_0x350254;if(!Number[_0x1848cb(0x1eb)](_0x1182c9)||_0x1182c9<0x698+-0x1*-0x135b+0x1*-0x19f3||!Number[_0x1848cb(0x1eb)](_0x2da92c)||_0x2da92c<-0xc52*0x1+-0x6*0x51b+-0x7*-0x623||_0x2da92c>FILE_READ_LIMIT)throw new Error(_0x1848cb(0x1c2));const _0x366f90=await realpath(_0x22349f),_0x15223e=await resolveWorkspaceEntry(_0x366f90,_0x235a98,![]),_0xf6226c=await lstat(_0x15223e);if(!_0xf6226c[_0x1848cb(0x16c)]())throw new Error(_0x1848cb(0x21b));if(_0xf6226c[_0x1848cb(0x20c)]>FILE_READ_LIMIT*(-0x43f+0x1*0xaf4+0x3f*-0x1b))throw new Error(_0x1848cb(0x161));const _0x8b80b1=await readFile(_0x15223e),_0x419996=_0x8b80b1[_0x1848cb(0x185)](-0x79f*-0x1+-0xdf6*0x2+0x144d)||!isValidUtf8(_0x8b80b1);if(_0x419996){const _0x266514=Math[_0x1848cb(0x19e)](_0x8b80b1[_0x1848cb(0x149)],_0x1182c9+_0x2da92c),_0x4bab99=_0x8b80b1[_0x1848cb(0x16a)](_0x1182c9,_0x266514);return{'path':relative(_0x366f90,_0x15223e)[_0x1848cb(0x219)](sep)[_0x1848cb(0x1a9)]('/'),'encoding':_0x1848cb(0x168),'size':_0x8b80b1[_0x1848cb(0x149)],'content':_0x4bab99[_0x1848cb(0x220)](_0x1848cb(0x168)),'truncated':_0x266514<_0x8b80b1[_0x1848cb(0x149)],'nextOffset':_0x266514<_0x8b80b1[_0x1848cb(0x149)]?_0x266514:null};}if(_0x1182c9>-0xca2+-0x1656+-0x6*-0x5d4&&_0x1182c9<_0x8b80b1[_0x1848cb(0x149)]&&isUtf8ContinuationByte(_0x8b80b1[_0x1182c9]))throw new Error(_0x1848cb(0x1c2));let _0x137ed8=Math[_0x1848cb(0x19e)](_0x8b80b1[_0x1848cb(0x149)],_0x1182c9+_0x2da92c);if(_0x137ed8<_0x8b80b1[_0x1848cb(0x149)]&&isUtf8ContinuationByte(_0x8b80b1[_0x137ed8])){while(_0x137ed8>_0x1182c9&&isUtf8ContinuationByte(_0x8b80b1[_0x137ed8]))_0x137ed8-=-0x219+-0x1a*0x133+0x2148;if(_0x137ed8===_0x1182c9){_0x137ed8+=-0x485*0x7+-0x5*0x2c7+0x2d87;while(_0x137ed8<_0x8b80b1[_0x1848cb(0x149)]&&isUtf8ContinuationByte(_0x8b80b1[_0x137ed8]))_0x137ed8+=0x13b*-0x11+0x2635+-0x1149;}}const _0x39efd6=_0x8b80b1[_0x1848cb(0x16a)](_0x1182c9,_0x137ed8),_0x4eba95=new TextDecoder(_0x1848cb(0x1d8),{'fatal':!![]})[_0x1848cb(0x1f6)](_0x39efd6),_0x1c719e=_0x137ed8<_0x8b80b1[_0x1848cb(0x149)]?_0x137ed8:null;return{'path':relative(_0x366f90,_0x15223e)[_0x1848cb(0x219)](sep)[_0x1848cb(0x1a9)]('/'),'encoding':_0x1848cb(0x1d8),'size':_0x8b80b1[_0x1848cb(0x149)],'content':_0x4eba95,'truncated':_0x1c719e!==null,'nextOffset':_0x1c719e};}export async function readWorkspaceFileContentRange(_0x2c745f,_0x357e3e,_0x216c44=-0x2095+0x1b03+0x592,_0x53f405=FILE_READ_LIMIT){const _0x5e7860=_0x350254;if(!Number[_0x5e7860(0x1eb)](_0x216c44)||_0x216c44<0x191c+-0x23dd+0xac1||!Number[_0x5e7860(0x1eb)](_0x53f405)||_0x53f405<-0xeab+0x239d+-0x14f1||_0x53f405>FILE_READ_LIMIT)throw new Error(_0x5e7860(0x1c2));const _0x65929c=await realpath(_0x2c745f),_0x4f0d2b=await resolveWorkspaceEntry(_0x65929c,_0x357e3e,![]),_0x4440af=await lstat(_0x4f0d2b);if(!_0x4440af[_0x5e7860(0x16c)]())throw new Error(_0x5e7860(0x21b));if(_0x216c44>_0x4440af[_0x5e7860(0x20c)])throw new Error(_0x5e7860(0x1c2));const _0x250d2a=Math[_0x5e7860(0x19e)](_0x53f405,_0x4440af[_0x5e7860(0x20c)]-_0x216c44),_0xaf99c3=Buffer[_0x5e7860(0x19a)](_0x250d2a),_0x4f5f46=await open(_0x4f0d2b,'r');try{const {bytesRead:_0x2eae7e}=await _0x4f5f46[_0x5e7860(0x1ce)](_0xaf99c3,0x164+0xb57*-0x2+0x221*0xa,_0x250d2a,_0x216c44),_0x5362b9=_0x216c44+_0x2eae7e;return{'path':relative(_0x65929c,_0x4f0d2b)[_0x5e7860(0x219)](sep)[_0x5e7860(0x1a9)]('/'),'size':_0x4440af[_0x5e7860(0x20c)],'offset':_0x216c44,'contentBase64':_0xaf99c3[_0x5e7860(0x16a)](-0x1ee+0x1a2b+-0x183d,_0x2eae7e)[_0x5e7860(0x220)](_0x5e7860(0x168)),'nextOffset':_0x5362b9<_0x4440af[_0x5e7860(0x20c)]?_0x5362b9:null};}finally{await _0x4f5f46[_0x5e7860(0x1af)]();}}export async function readAllowedTextFile(_0x5764a3,_0x5e86b8,_0x2786a1=0x104+-0xacb*-0x3+0x1*-0x2165,_0x4455b6=FILE_READ_LIMIT){const _0x12f65a=_0x350254;if(!isAbsolute(_0x5764a3))throw new Error(_0x12f65a(0x150));const _0x259244=await realpath(_0x5764a3)[_0x12f65a(0x13e)](_0x1e5130=>{const _0x452058=_0x12f65a;if(_0x1e5130[_0x452058(0x141)]===_0x452058(0x217))throw new Error(_0x452058(0x114));throw _0x1e5130;}),_0x494a38=await Promise[_0x12f65a(0x13a)](_0x5e86b8[_0x12f65a(0x11d)](_0x170280=>realpath(_0x170280)));if(!isWithinAllowedRoot(_0x259244,_0x494a38))throw new Error(_0x12f65a(0x150));const _0x53de50=await lstat(_0x259244);if(!_0x53de50[_0x12f65a(0x16c)]())throw new Error(_0x12f65a(0x21b));if(_0x53de50[_0x12f65a(0x20c)]>FILE_READ_LIMIT*(-0x1763+-0xb7d*0x3+-0x1*-0x39ea))throw new Error(_0x12f65a(0x161));if(!Number[_0x12f65a(0x1eb)](_0x2786a1)||_0x2786a1<0x31c+-0x3*0x71e+0x123e||!Number[_0x12f65a(0x1eb)](_0x4455b6)||_0x4455b6<0x1899+-0x8*0xb+0x610*-0x4||_0x4455b6>FILE_READ_LIMIT)throw new Error(_0x12f65a(0x1c2));const _0x228550=await readFile(_0x259244),_0x54418b=_0x228550[_0x12f65a(0x185)](0x8ad+0x1*0x1165+-0x1a12)||!isValidUtf8(_0x228550),_0x6488a2=Math[_0x12f65a(0x19e)](_0x228550[_0x12f65a(0x149)],_0x2786a1+_0x4455b6);if(_0x54418b){const _0x54c824=_0x228550[_0x12f65a(0x16a)](_0x2786a1,_0x6488a2);return{'path':_0x259244,'encoding':_0x12f65a(0x168),'size':_0x228550[_0x12f65a(0x149)],'content':_0x54c824[_0x12f65a(0x220)](_0x12f65a(0x168)),'truncated':_0x6488a2<_0x228550[_0x12f65a(0x149)],'nextOffset':_0x6488a2<_0x228550[_0x12f65a(0x149)]?_0x6488a2:null};}if(_0x2786a1>0x1*-0x20a1+0x1238+0xe69&&_0x2786a1<_0x228550[_0x12f65a(0x149)]&&isUtf8ContinuationByte(_0x228550[_0x2786a1]))throw new Error(_0x12f65a(0x1c2));let _0x1b1112=_0x6488a2;if(_0x1b1112<_0x228550[_0x12f65a(0x149)]&&isUtf8ContinuationByte(_0x228550[_0x1b1112])){while(_0x1b1112>_0x2786a1&&isUtf8ContinuationByte(_0x228550[_0x1b1112]))_0x1b1112-=-0x7eb+0xb5f+-0x373;if(_0x1b1112===_0x2786a1){_0x1b1112+=0x2660+0xee7+-0x3546;while(_0x1b1112<_0x228550[_0x12f65a(0x149)]&&isUtf8ContinuationByte(_0x228550[_0x1b1112]))_0x1b1112+=0xded+-0x226e+0x1482;}}const _0x304f2f=_0x1b1112<_0x228550[_0x12f65a(0x149)]?_0x1b1112:null;return{'path':_0x259244,'encoding':_0x12f65a(0x1d8),'size':_0x228550[_0x12f65a(0x149)],'content':new TextDecoder(_0x12f65a(0x1d8),{'fatal':!![]})[_0x12f65a(0x1f6)](_0x228550[_0x12f65a(0x16a)](_0x2786a1,_0x1b1112)),'truncated':_0x304f2f!==null,'nextOffset':_0x304f2f};}function isValidUtf8(_0x1fa135){const _0x51b025=_0x350254;try{return new TextDecoder(_0x51b025(0x1d8),{'fatal':!![]})[_0x51b025(0x1f6)](_0x1fa135),!![];}catch{return![];}}function isUtf8ContinuationByte(_0x48adfa){return(_0x48adfa&0x28d*0x9+0x114b+-0x8*0x4f0)===0xc24+-0x203c+-0x293*-0x8;}export async function searchWorkspaceFiles(_0x561fd4,_0x21bd8f,_0x136901,_0x4ec71a=SEARCH_RESULT_LIMIT,_0x1cf101=![]){const _0x4ec4a1=_0x350254,_0x270ed9=new WorkspaceFileIndex(_0x561fd4);try{return await _0x270ed9[_0x4ec4a1(0x223)](_0x21bd8f,_0x136901,_0x4ec71a,_0x1cf101);}finally{_0x270ed9[_0x4ec4a1(0x13f)]();}}async function resolveWorkspaceEntry(_0x473fb4,_0xd1b994,_0x54a8a1){const _0x1c9b46=await realpath(_0x473fb4);return resolveWorkspaceEntryFromCanonicalRoot(_0x1c9b46,_0xd1b994,_0x54a8a1);}async function resolveWorkspaceEntryFromCanonicalRoot(_0x583a47,_0x57a9f7,_0xe01e00){const _0x1407ae=_0x350254,_0x2c6bc6=await resolveWorkspaceEntryMetadata(_0x583a47,_0x57a9f7);if(_0xe01e00?!_0x2c6bc6[_0x1407ae(0x111)][_0x1407ae(0x1d3)]():!_0x2c6bc6[_0x1407ae(0x111)][_0x1407ae(0x16c)]()&&!_0x2c6bc6[_0x1407ae(0x111)][_0x1407ae(0x1d3)]())throw new Error(_0xe01e00?_0x1407ae(0x18c):_0x1407ae(0x21b));return _0x2c6bc6[_0x1407ae(0x1bd)];}async function resolveWorkspaceEntryMetadata(_0x37973b,_0x522647){const _0x24ca87=_0x350254;if(_0x522647[_0x24ca87(0x185)]('\x00')||_0x522647[_0x24ca87(0x149)]===0x24d*0x2+-0x1*-0x1889+-0x1*0x1d23||_0x522647[_0x24ca87(0x1f7)]('/')||_0x522647[_0x24ca87(0x1f7)]('\x5c'))throw new Error(_0x24ca87(0x150));const _0x33f0b7=_0x522647[_0x24ca87(0x1a8)]('\x5c','/');if(_0x33f0b7[_0x24ca87(0x219)]('/')[_0x24ca87(0x16b)](_0x230fcb=>_0x230fcb==='..'||_0x230fcb===_0x24ca87(0x11b)))throw new Error(_0x24ca87(0x150));let _0x454d58;try{_0x454d58=await realpath(resolve(_0x37973b,_0x33f0b7));}catch(_0x1ec848){if(_0x1ec848[_0x24ca87(0x141)]===_0x24ca87(0x217))throw new Error(_0x24ca87(0x114));throw _0x1ec848;}const _0x1d7cb7=relative(_0x37973b,_0x454d58);if(isAbsolute(_0x1d7cb7)||_0x1d7cb7[_0x24ca87(0x1f7)]('..')||_0x1d7cb7==='..'||_0x1d7cb7[_0x24ca87(0x1f7)]('..'+sep))throw new Error(_0x24ca87(0x150));const _0x49c9f3=await lstat(_0x454d58);return{'path':_0x454d58,'metadata':_0x49c9f3};}async function inspectWorkspaceIndexEntry(_0x3d9a0c,_0x329d44,_0x4c0316){const _0x3fa30d=_0x350254;try{const _0x1c1767=await resolveWorkspaceEntryMetadata(_0x3d9a0c,_0x329d44);if(!_0x1c1767[_0x3fa30d(0x111)][_0x3fa30d(0x16c)]()&&!_0x1c1767[_0x3fa30d(0x111)][_0x3fa30d(0x1d3)]())return undefined;const _0x59b2be=relative(_0x3d9a0c,_0x1c1767[_0x3fa30d(0x1bd)])[_0x3fa30d(0x219)](sep)[_0x3fa30d(0x1a9)]('/');return _0x1c1767[_0x3fa30d(0x111)][_0x3fa30d(0x1d3)]()?{'path':_0x59b2be,'name':_0x4c0316,'kind':_0x3fa30d(0x1d6),'size':null,'modifiedAt':_0x1c1767[_0x3fa30d(0x111)][_0x3fa30d(0x13b)]}:{'path':_0x59b2be,'name':_0x4c0316,'kind':_0x3fa30d(0x14d),'size':_0x1c1767[_0x3fa30d(0x111)][_0x3fa30d(0x20c)],'modifiedAt':_0x1c1767[_0x3fa30d(0x111)][_0x3fa30d(0x13b)]};}catch{return undefined;}}function _0x57ac(_0x3ee6a3,_0x7c5196){_0x3ee6a3=_0x3ee6a3-(0x7a7*-0x1+-0xfd3+-0x15d*-0x12);const _0x512a67=_0x4e33();let _0x460dc0=_0x512a67[_0x3ee6a3];if(_0x57ac['eKLugk']===undefined){var _0x3d9a8f=function(_0x32e543){const _0x2033ef='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x4bf711='',_0x4c9eee='';for(let _0x43df65=-0xd57+-0x25dd+0x1d*0x1c4,_0x2bbcae,_0x37bbde,_0x2bcce3=0x209f+-0x8c*0x20+0x31*-0x4f;_0x37bbde=_0x32e543['charAt'](_0x2bcce3++);~_0x37bbde&&(_0x2bbcae=_0x43df65%(0x1*-0xf9f+0x32*0xb8+-0x1*0x144d)?_0x2bbcae*(-0x1ebe+0x1804+0x6fa)+_0x37bbde:_0x37bbde,_0x43df65++%(0x56*0x2b+0xb*0x2a7+0xb7*-0x3d))?_0x4bf711+=String['fromCharCode'](0xa*0x2+-0x2154+0x223f&_0x2bbcae>>(-(-0xe6f*-0x2+0x1f16+-0x3bf2)*_0x43df65&-0x21b4+0x65e+0xdae*0x2)):-0x1b*-0x169+0xea*0x1f+0x4269*-0x1){_0x37bbde=_0x2033ef['indexOf'](_0x37bbde);}for(let _0x376d63=-0x77*0x29+0x1f1f*-0x1+0x10ba*0x3,_0xa99c00=_0x4bf711['length'];_0x376d63<_0xa99c00;_0x376d63++){_0x4c9eee+='%'+('00'+_0x4bf711['charCodeAt'](_0x376d63)['toString'](0x25b*0xd+0x1ffb+-0x3e8a))['slice'](-(0x1*-0x2351+0x1b47+0x14*0x67));}return decodeURIComponent(_0x4c9eee);};_0x57ac['BguahL']=_0x3d9a8f,_0x57ac['zKeojI']={},_0x57ac['eKLugk']=!![];}const _0x5bd606=_0x512a67[0x20ea+-0x19b1*-0x1+0x3*-0x1389];_0x57ac['OQNEQC']!==_0x5bd606&&(_0x57ac['zKeojI']={},_0x57ac['OQNEQC']=_0x5bd606);const _0x1a206=_0x57ac['zKeojI'][_0x3ee6a3];return _0x1a206===undefined?(_0x460dc0=_0x57ac['BguahL'](_0x460dc0),_0x57ac['zKeojI'][_0x3ee6a3]=_0x460dc0):_0x460dc0=_0x1a206,_0x460dc0;}function encodeDirectoryCursor(_0x39ca37,_0x2d0aee){const _0x5b7381=_0x350254;return Buffer[_0x5b7381(0x120)](JSON[_0x5b7381(0x123)]({'path':_0x39ca37,'name':_0x2d0aee}))[_0x5b7381(0x220)](_0x5b7381(0x187));}function decodeDirectoryCursor(_0x53b306,_0x3841af){const _0x5f0786=_0x350254;if(_0x53b306===undefined)return undefined;try{const _0x4ce307=JSON[_0x5f0786(0x1d7)](Buffer[_0x5f0786(0x120)](_0x53b306,_0x5f0786(0x187))[_0x5f0786(0x220)](_0x5f0786(0x1b9)));if(typeof _0x4ce307!==_0x5f0786(0x12f)||_0x4ce307===null||_0x4ce307[_0x5f0786(0x1bd)]!==_0x3841af||typeof _0x4ce307[_0x5f0786(0x1e2)]!==_0x5f0786(0x19d))throw new Error();return _0x4ce307[_0x5f0786(0x1e2)];}catch{throw new Error(_0x5f0786(0x17c));}}function encodeSearchCursor(_0x73bc45,_0x15293e){const _0x1deaf4=_0x350254;return Buffer[_0x1deaf4(0x120)](JSON[_0x1deaf4(0x123)]({'query':_0x73bc45,'path':_0x15293e}))[_0x1deaf4(0x220)](_0x1deaf4(0x187));}function decodeSearchCursor(_0x302b06,_0x42061e){const _0x51de9a=_0x350254;if(_0x302b06===undefined)return undefined;try{const _0x43124f=JSON[_0x51de9a(0x1d7)](Buffer[_0x51de9a(0x120)](_0x302b06,_0x51de9a(0x187))[_0x51de9a(0x220)](_0x51de9a(0x1b9)));if(typeof _0x43124f!==_0x51de9a(0x12f)||_0x43124f===null||_0x43124f[_0x51de9a(0x19f)]!==_0x42061e||typeof _0x43124f[_0x51de9a(0x1bd)]!==_0x51de9a(0x19d))throw new Error();return _0x43124f[_0x51de9a(0x1bd)];}catch{throw new Error(_0x51de9a(0x17c));}}export function normalizeWorkspacePath(_0x58b33c,_0x491db3=_0xd083e6()){const _0x1ea757=_0x350254;if(_0x58b33c[_0x1ea757(0x149)]===0xaa9*-0x1+-0xdfd*-0x2+-0x1151||_0x58b33c[_0x1ea757(0x185)]('\u0000'))throw new Error(_0x1ea757(0x202));if(_0x491db3===_0x1ea757(0x184)){if(/^\\\\[?.]/[_0x1ea757(0x117)](_0x58b33c))throw new Error(_0x1ea757(0x227));const _0x599d31=win32[_0x1ea757(0x1ee)](_0x58b33c[_0x1ea757(0x1a8)]('/','\x5c'));if(!win32[_0x1ea757(0x1f9)](_0x599d31))throw new Error(_0x1ea757(0x1bb));return _0x599d31[_0x1ea757(0x157)](/\\+$/,'')[_0x1ea757(0x1ba)]();}if(_0x491db3!==_0x1ea757(0x12c))throw new Error(_0x1ea757(0x140));const _0x270f55=posix[_0x1ea757(0x1ee)](_0x58b33c);if(!posix[_0x1ea757(0x1f9)](_0x270f55))throw new Error(_0x1ea757(0x1bb));return _0x270f55==='/'?_0x270f55:_0x270f55[_0x1ea757(0x157)](/\/+$/,'');}export function isWithinAllowedRoot(_0x2b5db5,_0x52cc06,_0x1a9b98=_0xd083e6()){const _0x201310=_0x350254,_0x540a81=normalizeWorkspacePath(_0x2b5db5,_0x1a9b98),_0x4f0044=_0x1a9b98===_0x201310(0x184)?win32:posix;return _0x52cc06[_0x201310(0x16b)](_0x223003=>{const _0x9af94a=_0x201310,_0x409bd0=normalizeWorkspacePath(_0x223003,_0x1a9b98),_0x15fe13=_0x4f0044[_0x9af94a(0x14a)](_0x409bd0,_0x540a81);return _0x15fe13===''||!_0x15fe13[_0x9af94a(0x1f7)]('..')&&!_0x4f0044[_0x9af94a(0x1f9)](_0x15fe13);});}export async function inspectWorkspace(_0xd72dec,_0x2da7bb){const _0x349c98=_0x350254,_0x20b0c1=await realpath(_0xd72dec),_0x40d83e=await Promise[_0x349c98(0x13a)](_0x2da7bb[_0x349c98(0x11d)](_0x39e612=>realpath(_0x39e612))),_0x13521f=await stat(_0x20b0c1);if(!_0x13521f[_0x349c98(0x1d3)]()||!isWithinAllowedRoot(_0x20b0c1,_0x40d83e))throw new Error(_0x349c98(0x1d4));try{const _0x6ec246=await readGitSummary(_0x20b0c1);return{'path':_0x20b0c1,'kind':_0x349c98(0x224),'gitSummary':_0x6ec246};}catch(_0x5c487d){if(_0x5c487d instanceof GitCommandError&&_0x5c487d[_0x349c98(0x141)]===-0x1a47*-0x1+0x5*0x209+-0x23f4||isGitUnavailable(_0x5c487d))return{'path':_0x20b0c1,'kind':_0x349c98(0x1d6)};throw _0x5c487d;}}export async function readGitSummary(_0x21a6da){const _0x2989cb=_0x350254,_0x5c4883=(await runGit(_0x21a6da,[_0x2989cb(0x1b8),_0x2989cb(0x1c8)]))[_0x2989cb(0x14f)][_0x2989cb(0x1cf)](),_0x18686d=(await runGit(_0x21a6da,[_0x2989cb(0x1b8),_0x2989cb(0x225),_0x2989cb(0x154)]))[_0x2989cb(0x14f)][_0x2989cb(0x1cf)](),_0x155802=await runGitAllowFailure(_0x21a6da,[_0x2989cb(0x18f),_0x2989cb(0x1c4),_0x2989cb(0x143),_0x2989cb(0x154)]),_0xb9fb75=(await runGit(_0x21a6da,[_0x2989cb(0x1a0),_0x2989cb(0x132),'-z']))[_0x2989cb(0x125)][_0x2989cb(0x149)]>0x220*0xc+-0x6d+0x31*-0x83,_0x23f04c=await runGit(_0x21a6da,[_0x2989cb(0x1a0),_0x2989cb(0x132)])[_0x2989cb(0x1c5)](_0x16cb2d=>_0x16cb2d[_0x2989cb(0x14f)]);return{'commonDir':_0x5c4883,'head':_0x18686d,'branch':_0x155802[_0x2989cb(0x141)]===0x1b51+-0x27*0x63+0x74*-0x1b?_0x155802[_0x2989cb(0x14f)][_0x2989cb(0x1cf)]():null,'dirty':_0xb9fb75,'snapshot':summarizeText(_0x23f04c)};}export function assertSafeGitRef(_0x494bf9){const _0x5cb506=_0x350254;if(!REF_PATTERN[_0x5cb506(0x117)](_0x494bf9))throw new Error(_0x5cb506(0x122));}export async function readRestrictedDiff(_0x24129d,_0x482733,_0x1b8958){const _0x9ec07d=_0x350254;assertSafeGitRef(_0x482733),assertSafeGitRef(_0x1b8958);const _0x4cd416=await runGit(_0x24129d,[_0x9ec07d(0x1ab),_0x9ec07d(0x18e),_0x9ec07d(0x1e9),_0x482733,_0x1b8958]),_0x42413d=_0x4cd416[_0x9ec07d(0x125)][_0x9ec07d(0x185)](0x24d6+-0x237d+-0x159)||_0x4cd416[_0x9ec07d(0x14f)][_0x9ec07d(0x185)](_0x9ec07d(0x206));if(_0x42413d)return{'binary':!![],'summary':_0x9ec07d(0x156)+createHash(_0x9ec07d(0x194))[_0x9ec07d(0x1a2)](_0x4cd416[_0x9ec07d(0x125)])[_0x9ec07d(0x145)](_0x9ec07d(0x1a3))+_0x9ec07d(0x20b)+_0x4cd416[_0x9ec07d(0x125)][_0x9ec07d(0x149)],'truncated':_0x4cd416[_0x9ec07d(0x18a)]};return{'binary':![],'text':_0x4cd416[_0x9ec07d(0x14f)],'truncated':_0x4cd416[_0x9ec07d(0x18a)]};}function currentBranchFromStatusHeader(_0x60df63){const _0xb3f13d=_0x350254,_0x329b33=_0x60df63[_0xb3f13d(0x20e)](0xe76+-0x163b+-0xf9*-0x8);if(_0x329b33[_0xb3f13d(0x1f7)](_0xb3f13d(0x112)))return null;const _0x383b65=/^(?:No commits yet on|Initial commit on) (.+)$/[_0xb3f13d(0x12e)](_0x329b33);if(_0x383b65!==null)return _0x383b65[-0x1557+-0x1b*-0x12b+-0xa31*0x1]??null;return _0x329b33[_0xb3f13d(0x219)](_0xb3f13d(0x1fd))[-0xe5d+0x1*-0xfd4+0x3b*0x83]?.[_0xb3f13d(0x219)]('\x20')[-0x1*-0x3d7+0x1*0x1a93+0xf35*-0x2]??null;}export async function readCurrentChangesSummary(_0x2a9250){const _0x3d0ddd=_0x350254,_0x27702b=await runGit(_0x2a9250,[_0x3d0ddd(0x1a0),_0x3d0ddd(0x132),'-z',_0x3d0ddd(0x1e4),_0x3d0ddd(0x1cc)]),_0x3e0b8d=_0x27702b[_0x3d0ddd(0x14f)][_0x3d0ddd(0x219)]('\x00'),_0x390499=_0x3e0b8d[_0x3d0ddd(0x1d0)]()??'',_0x234d33=[];for(let _0x41cd47=0x14*-0x107+0x2587+-0x10fb;_0x41cd47<_0x3e0b8d[_0x3d0ddd(0x149)];_0x41cd47+=0xfd7+-0x1437+0x461){const _0x501248=_0x3e0b8d[_0x41cd47];if(_0x501248[_0x3d0ddd(0x149)]<0xa91+-0x9c1+-0xcc)continue;const _0x10591c=_0x501248[-0x1*0x1b05+-0x2*-0x33b+0x1*0x148f],_0x24dec1=_0x501248[0x69*0x1e+-0x1a55+0xe08],_0x5b1833=_0x501248[_0x3d0ddd(0x20e)](0x293+0x12ea+-0x157a);if(_0x10591c==='?'&&_0x24dec1==='?'){_0x234d33[_0x3d0ddd(0x152)]({'path':_0x5b1833,'state':_0x3d0ddd(0x1ae),'change':_0x3d0ddd(0x1f3)});continue;}_0x10591c!=='\x20'&&_0x234d33[_0x3d0ddd(0x152)]({'path':_0x5b1833,'state':_0x3d0ddd(0x1ed),'change':gitChange(_0x10591c)});_0x24dec1!=='\x20'&&_0x234d33[_0x3d0ddd(0x152)]({'path':_0x5b1833,'state':_0x3d0ddd(0x1f8),'change':gitChange(_0x24dec1)});if(_0x10591c==='R'||_0x10591c==='C'||_0x24dec1==='R'||_0x24dec1==='C')_0x41cd47+=0xad9*0x1+0x23*0x4c+-0x153c;}return{'branch':_0x390499[_0x3d0ddd(0x1f7)](_0x3d0ddd(0x1fe))?currentBranchFromStatusHeader(_0x390499):null,'changes':_0x234d33};}export async function listInitializedSubmodulePaths(_0x21d083){const _0x11a81c=_0x350254,_0x1c39e9=await runGit(_0x21d083,[_0x11a81c(0x181),_0x11a81c(0x1a0),_0x11a81c(0x17b)]);return _0x1c39e9[_0x11a81c(0x14f)][_0x11a81c(0x219)](/\r?\n/)[_0x11a81c(0x183)](_0x5bb524=>{const _0xc3a1c1=_0x11a81c;if(_0x5bb524[_0xc3a1c1(0x149)]<-0x109d+0x79c+0x92b)return[];const _0x181937=_0x5bb524[0x2316+0x1762+-0x3a78];if(_0x181937==='-')return[];const _0x164cf1=/^.[0-9a-f]+\s+(.+?)(?:\s+\([^)]*\))?$/[_0xc3a1c1(0x12e)](_0x5bb524),_0x26be17=_0x164cf1?.[0x1fe1+0x2176+-0x2*0x20ab]?.[_0xc3a1c1(0x1a8)]('\x5c','/');return _0x26be17===undefined||_0x26be17[_0xc3a1c1(0x149)]===0xcb5*0x1+0x1aeb+0x2*-0x13d0?[]:[_0x26be17];})[_0x11a81c(0x180)]((_0xca3c21,_0x1f84cf)=>_0xca3c21[_0x11a81c(0x1dc)](_0x1f84cf));}export async function resolveGitRepository(_0x17d897,_0xa2a066){const _0x51f7a3=_0x350254;if(_0xa2a066[_0x51f7a3(0x149)]===0x2fc+0x856*-0x2+-0x248*-0x6)return realpath(_0x17d897);if(_0xa2a066[_0x51f7a3(0x185)]('\x00')||_0xa2a066[_0x51f7a3(0x1f7)]('/')||_0xa2a066[_0x51f7a3(0x1f7)]('\x5c')||_0xa2a066[_0x51f7a3(0x219)]('/')[_0x51f7a3(0x16b)](_0x2054e2=>_0x2054e2[_0x51f7a3(0x149)]===0x2106+0x6*-0x3b7+-0x1*0xabc||_0x2054e2==='.'||_0x2054e2==='..'))throw new Error(_0x51f7a3(0x210));const _0x4b1363=await listInitializedSubmodulePaths(_0x17d897);if(!_0x4b1363[_0x51f7a3(0x185)](_0xa2a066))throw new Error(_0x51f7a3(0x210));const _0x3e3c29=resolve(await realpath(_0x17d897),_0xa2a066);try{await readGitSummary(_0x3e3c29);}catch{throw new Error(_0x51f7a3(0x210));}return _0x3e3c29;}export async function listGitHistoryRefs(_0x26f634){const _0x23eee4=_0x350254,_0xd1bdcf=await runGit(_0x26f634,[_0x23eee4(0x153),_0x23eee4(0x1ff),_0x23eee4(0x190),_0x23eee4(0x204)]);return _0xd1bdcf[_0x23eee4(0x14f)][_0x23eee4(0x219)](/\r?\n/)[_0x23eee4(0x183)](_0x35afea=>{const _0x5cd114=_0x23eee4,[_0x4e36f8,_0x329a97,_0x34b440,_0x3f19db,_0x3e455e]=_0x35afea[_0x5cd114(0x219)]('\x09');if(_0x4e36f8===undefined||_0x329a97===undefined||_0x34b440===undefined||_0x3e455e===undefined||_0x3e455e[_0x5cd114(0x149)]>-0x1ec4+0x40*-0x28+0x28c4||!/^[0-9a-f]{40,64}$/[_0x5cd114(0x117)](_0x34b440))return[];const _0x1b4544=_0x4e36f8[_0x5cd114(0x1f7)](_0x5cd114(0x1aa))?_0x5cd114(0x11e):_0x4e36f8[_0x5cd114(0x1f7)](_0x5cd114(0x164))?_0x5cd114(0x126):undefined;return _0x1b4544===undefined?[]:[{'name':_0x4e36f8,'displayName':_0x329a97,'kind':_0x1b4544,'hash':_0x34b440,'current':_0x3f19db==='*'}];})[_0x23eee4(0x180)]((_0x12aa6f,_0x1336bc)=>_0x12aa6f[_0x23eee4(0x163)][_0x23eee4(0x1dc)](_0x1336bc[_0x23eee4(0x163)])||_0x12aa6f[_0x23eee4(0x1f2)][_0x23eee4(0x1dc)](_0x1336bc[_0x23eee4(0x1f2)]));}function selectedHistoryRefs(_0x5a5e40,_0x9e3d4e){const _0x57963f=_0x350254;if(_0x9e3d4e===undefined||_0x9e3d4e[_0x57963f(0x149)]===0x1ae1+-0x42e*-0x4+0x1*-0x2b99)return _0x5a5e40;const _0x256d56=[...new Set(_0x9e3d4e)],_0x1575f8=_0x256d56[_0x57963f(0x11d)](_0x8aef4a=>_0x5a5e40[_0x57963f(0x1dd)](_0x4304f9=>_0x4304f9[_0x57963f(0x1e2)]===_0x8aef4a));if(_0x1575f8[_0x57963f(0x16b)](_0x46e74f=>_0x46e74f===undefined))throw new Error(_0x57963f(0x151));return _0x1575f8;}function historyCursor(_0x1fe512,_0x144af2){const _0x21bcfb=_0x350254;return Buffer[_0x21bcfb(0x120)](JSON[_0x21bcfb(0x123)]({'offset':_0x1fe512,'fingerprint':_0x144af2}))[_0x21bcfb(0x220)](_0x21bcfb(0x187));}function parseHistoryCursor(_0x1e6e07,_0x1e7620){const _0x1a55f9=_0x350254;if(_0x1e6e07===undefined)return 0x5*0x78d+-0x5ce*0x2+0x45*-0x61;try{const _0x252046=JSON[_0x1a55f9(0x1d7)](Buffer[_0x1a55f9(0x120)](_0x1e6e07,_0x1a55f9(0x187))[_0x1a55f9(0x220)](_0x1a55f9(0x1b9)));if(!Number[_0x1a55f9(0x17e)](_0x252046[_0x1a55f9(0x1f1)])||_0x252046[_0x1a55f9(0x1f1)]<0x3f*0x3+-0x11a1+0x10e4||_0x252046[_0x1a55f9(0x137)]!==_0x1e7620)throw new Error(_0x1a55f9(0x124));return _0x252046[_0x1a55f9(0x1f1)];}catch{throw new Error(_0x1a55f9(0x1b4));}}export async function readGitHistory(_0x240b22,_0x19d426){const _0x28ef4d=_0x350254,_0x4dfdfc=await listGitHistoryRefs(_0x240b22),_0x2a5b35=selectedHistoryRefs(_0x4dfdfc,_0x19d426[_0x28ef4d(0x214)]);if(_0x2a5b35[_0x28ef4d(0x149)]===-0x1be3+-0xb7a+0x275d)return{'commits':[],'nextCursor':null};const _0x40034b=_0x19d426[_0x28ef4d(0x1c9)]??0x39f+0xcbd+-0x102a*0x1;if(!Number[_0x28ef4d(0x17e)](_0x40034b)||_0x40034b<0x6c*-0x1e+0x1a39*0x1+0x70*-0x1f||_0x40034b>0xaa*0x2f+-0x2371*-0x1+-0x4243)throw new Error(_0x28ef4d(0x212));const _0x41100e=_0x2a5b35[_0x28ef4d(0x11d)](_0x16f733=>_0x16f733[_0x28ef4d(0x1e2)])[_0x28ef4d(0x180)](),_0x1b90bf=createHash(_0x28ef4d(0x194))[_0x28ef4d(0x1a2)](_0x2a5b35[_0x28ef4d(0x11d)](_0x415156=>_0x415156[_0x28ef4d(0x1e2)]+'\x00'+_0x415156[_0x28ef4d(0x162)])[_0x28ef4d(0x180)]()[_0x28ef4d(0x1a9)]('\x00'))[_0x28ef4d(0x145)](_0x28ef4d(0x1a3)),_0x159246=parseHistoryCursor(_0x19d426[_0x28ef4d(0x155)],_0x1b90bf),_0x4bf1cd=await runGit(_0x240b22,[_0x28ef4d(0x1fa),_0x28ef4d(0x178),_0x28ef4d(0x1e5),_0x28ef4d(0x177)+_0x159246,_0x28ef4d(0x207)+(_0x40034b+(0x2070+-0x160b+0x85*-0x14)),'-z',_0x28ef4d(0x175),..._0x41100e,'--']),_0x5706c7=new Map();for(const _0x4962d0 of _0x4dfdfc){const _0x563a2a=_0x5706c7[_0x28ef4d(0x115)](_0x4962d0[_0x28ef4d(0x162)])??[];_0x563a2a[_0x28ef4d(0x152)](_0x4962d0[_0x28ef4d(0x1f2)]),_0x5706c7[_0x28ef4d(0x13c)](_0x4962d0[_0x28ef4d(0x162)],_0x563a2a);}const _0x52ca52=_0x4bf1cd[_0x28ef4d(0x14f)][_0x28ef4d(0x219)]('\x00'),_0xa8b70b=[];for(let _0x4bc283=-0xd*-0x1bd+-0xfbb+0x1*-0x6de;_0x4bc283+(-0x175c+0x1164+0xdb*0x7)<_0x52ca52[_0x28ef4d(0x149)];_0x4bc283+=0x34*0x34+-0x19c*-0x11+-0x25e6){const [_0x16f0f6,_0x25c24e='',_0x597879='',_0x208064='',_0x59b5d5='0',_0x46afcc='']=_0x52ca52[_0x28ef4d(0x20e)](_0x4bc283,_0x4bc283+(-0x61*-0x1d+0xd1*0xd+-0x1594));if(_0x16f0f6===undefined||!/^[0-9a-f]{40,64}$/[_0x28ef4d(0x117)](_0x16f0f6))continue;_0xa8b70b[_0x28ef4d(0x152)]({'hash':_0x16f0f6,'parents':_0x25c24e[_0x28ef4d(0x149)]===-0x1039+0x2*0x548+0x5a9?[]:_0x25c24e[_0x28ef4d(0x219)]('\x20'),'authorName':_0x597879,'authorEmail':_0x208064,'committedAt':Number(_0x59b5d5)*(-0x2*0xec5+-0x18de*-0x1+0xf4*0x9),'subject':_0x46afcc,'refs':_0x5706c7[_0x28ef4d(0x115)](_0x16f0f6)??[]});}const _0x2fba24=_0xa8b70b[_0x28ef4d(0x149)]>_0x40034b;return{'commits':_0xa8b70b[_0x28ef4d(0x20e)](-0x5c6+0x1f*-0xc2+-0x1*-0x1d44,_0x40034b),'nextCursor':_0x2fba24?historyCursor(_0x159246+_0x40034b,_0x1b90bf):null};}async function assertHistoryCommitReachable(_0x1a4a55,_0x5883bf,_0x1a4369){const _0x503f1b=_0x350254;if(!/^[0-9a-f]{40,64}$/[_0x503f1b(0x117)](_0x5883bf))throw new Error(_0x503f1b(0x1ec));const _0xb955ca=selectedHistoryRefs(await listGitHistoryRefs(_0x1a4a55),_0x1a4369);for(const _0x577ce6 of _0xb955ca){const _0x5d0857=await runGitAllowFailure(_0x1a4a55,[_0x503f1b(0x1db),_0x503f1b(0x12a),_0x5883bf,_0x577ce6[_0x503f1b(0x1e2)]]);if(_0x5d0857[_0x503f1b(0x141)]===-0x157*0x1+-0x1*-0x1633+-0x14dc)return;}throw new Error(_0x503f1b(0x1ec));}export async function readGitHistoryFiles(_0x34396b,_0x4d3d03,_0x2a2086){const _0x404c79=_0x350254;await assertHistoryCommitReachable(_0x34396b,_0x4d3d03,_0x2a2086);const _0x3a1931=await runGit(_0x34396b,[_0x404c79(0x1cb),_0x404c79(0x1fb),_0x404c79(0x1a7),_0x404c79(0x144),'-r','-z','-M','-C',_0x404c79(0x209),_0x4d3d03]),_0x2de919=_0x3a1931[_0x404c79(0x14f)][_0x404c79(0x219)]('\x00'),_0x27b14c=[];for(let _0x54a0ad=-0x19ca+0x1*0x532+-0x1498*-0x1;_0x54a0ad<_0x2de919[_0x404c79(0x149)];_0x54a0ad+=0x5bb*-0x1+-0x559+-0x1*-0xb15){const _0x36e3cb=_0x2de919[_0x54a0ad];if(_0x36e3cb===undefined||_0x36e3cb[_0x404c79(0x149)]===0x25ae+0x1f5b+0x89*-0x81)continue;const _0x415e1b=_0x36e3cb[-0x212d+0xd69+0x14*0xfd]??'M';if(_0x415e1b==='R'||_0x415e1b==='C'){const _0x50cbee=_0x2de919[_0x54a0ad+(-0x5*0x100+-0x17b3+0x1*0x1cb4)],_0x34745e=_0x2de919[_0x54a0ad+(0x61b*0x4+0x223a+-0x3aa4)];if(_0x50cbee!==undefined&&_0x34745e!==undefined)_0x27b14c[_0x404c79(0x152)]({'path':_0x34745e,'previousPath':_0x50cbee,'change':gitChange(_0x415e1b)});_0x54a0ad+=0x1f88*0x1+-0x1*-0x222b+-0xfb*0x43;}else{const _0x170937=_0x2de919[_0x54a0ad+(-0x1*0x24f5+-0x3af*-0x2+0x1d98)];if(_0x170937!==undefined)_0x27b14c[_0x404c79(0x152)]({'path':_0x170937,'change':gitChange(_0x415e1b)});_0x54a0ad+=-0x103*0x1d+0x46a+0x18ee;}}return _0x27b14c;}export async function readGitHistoryFileDiff(_0x269f45,_0x3a1cdd,_0x259d41,_0x1e5e05,_0x19637f){const _0x5ada25=_0x350254;await assertHistoryCommitReachable(_0x269f45,_0x3a1cdd,_0x1e5e05);const _0x162c20=safeGitWorkspacePath(_0x259d41),_0x1f690e=_0x19637f===undefined?undefined:safeGitWorkspacePath(_0x19637f),_0x26ce78=await runGit(_0x269f45,[_0x5ada25(0x198),_0x5ada25(0x136),_0x5ada25(0x1a7),_0x5ada25(0x18e),_0x5ada25(0x1e9),_0x3a1cdd,'--',_0x5ada25(0x1df)+_0x162c20,..._0x1f690e===undefined||_0x1f690e===_0x162c20?[]:[_0x5ada25(0x1df)+_0x1f690e]]),_0x2f2237=_0x26ce78[_0x5ada25(0x125)][_0x5ada25(0x185)](0x2d4*0xb+-0xb*-0x1a3+0x105f*-0x3)||_0x26ce78[_0x5ada25(0x14f)][_0x5ada25(0x185)](_0x5ada25(0x206));if(_0x2f2237)return{'binary':!![],'summary':_0x5ada25(0x156)+createHash(_0x5ada25(0x194))[_0x5ada25(0x1a2)](_0x26ce78[_0x5ada25(0x125)])[_0x5ada25(0x145)](_0x5ada25(0x1a3))+_0x5ada25(0x20b)+_0x26ce78[_0x5ada25(0x125)][_0x5ada25(0x149)],'truncated':_0x26ce78[_0x5ada25(0x18a)]};return{'binary':![],'text':_0x26ce78[_0x5ada25(0x14f)],'truncated':_0x26ce78[_0x5ada25(0x18a)]};}export async function readGitHistoryFileContentRange(_0x1d5139,_0x13e612,_0x49921d,_0x16f3d1,_0x363aca,_0x55af30){const _0x54eb7b=_0x350254;if(!Number[_0x54eb7b(0x1eb)](_0x16f3d1)||_0x16f3d1<-0x94b+0x1f44+-0x15f9||!Number[_0x54eb7b(0x1eb)](_0x363aca)||_0x363aca<0x4a2+0xf26+-0x13c7||_0x363aca>(-0x2*0x3f5+-0x433+0xc31)*(-0x14e9+-0x252c+0x2b3*0x17)*(0x2b6*-0xd+0x1*0x15f0+0x114e*0x1)||_0x16f3d1+_0x363aca>(-0x437+0x1517*0x1+-0x10cc)*(0xf43+0x103b+-0x1b7e)*(0x5c3+0x115*0xb+-0xb*0x13e))throw new Error(_0x54eb7b(0x1c2));await assertHistoryCommitReachable(_0x1d5139,_0x13e612,_0x55af30);const _0x48955d=safeGitWorkspacePath(_0x49921d),_0x1661f9=_0x13e612+':'+_0x48955d,_0x3fbc6b=await runGit(_0x1d5139,[_0x54eb7b(0x21f),'-s',_0x1661f9]),_0x19ce2e=Number(_0x3fbc6b[_0x54eb7b(0x14f)][_0x54eb7b(0x1cf)]());if(!Number[_0x54eb7b(0x1eb)](_0x19ce2e)||_0x19ce2e<-0xa71*0x3+-0xffb+-0xad*-0x46||_0x16f3d1>_0x19ce2e)throw new Error(_0x54eb7b(0x1c2));if(_0x16f3d1===_0x19ce2e)return{'path':_0x48955d,'size':_0x19ce2e,'offset':_0x16f3d1,'contentBase64':'','nextOffset':null};const _0x1ce794=await runGitAllowFailure(_0x1d5139,[_0x54eb7b(0x21f),_0x54eb7b(0x199),_0x1661f9],_0x16f3d1+_0x363aca);if(_0x1ce794[_0x54eb7b(0x141)]!==0xb2e+0x37*-0x97+0x1543)throw new GitCommandError(_0x1ce794[_0x54eb7b(0x141)],_0x1ce794[_0x54eb7b(0x128)]);const _0x121c2e=_0x1ce794[_0x54eb7b(0x125)][_0x54eb7b(0x16a)](_0x16f3d1,Math[_0x54eb7b(0x19e)](_0x19ce2e,_0x16f3d1+_0x363aca)),_0x4ed329=_0x16f3d1+_0x121c2e[_0x54eb7b(0x149)];return{'path':_0x48955d,'size':_0x19ce2e,'offset':_0x16f3d1,'contentBase64':_0x121c2e[_0x54eb7b(0x220)](_0x54eb7b(0x168)),'nextOffset':_0x4ed329<_0x19ce2e?_0x4ed329:null};}export async function readCurrentChanges(_0x2548bc){const _0x856937=_0x350254;return(await readCurrentChangesSummary(_0x2548bc))[_0x856937(0x16f)];}export async function readCurrentChangeDiff(_0x22fb84,_0x94caf1){const _0x4b3203=_0x350254,_0x28e478=safeGitWorkspacePath(_0x94caf1);await assertCurrentChangePathAccessible(_0x22fb84,_0x28e478);const _0x5ed534=await readCurrentChangeGitDiff(_0x22fb84,_0x28e478),_0x5608bc=await readWorkingTreeText(_0x22fb84,_0x28e478),_0x1c7408=_0x5ed534[_0x4b3203(0x125)][_0x4b3203(0x185)](-0x1460+0x2077+-0xc17)||_0x5ed534[_0x4b3203(0x14f)][_0x4b3203(0x185)](_0x4b3203(0x206))||_0x5608bc?.[_0x4b3203(0x131)]===!![];if(_0x1c7408)return{'binary':!![],'summary':_0x4b3203(0x156)+createHash(_0x4b3203(0x194))[_0x4b3203(0x1a2)](_0x5ed534[_0x4b3203(0x125)])[_0x4b3203(0x145)](_0x4b3203(0x1a3))+_0x4b3203(0x20b)+_0x5ed534[_0x4b3203(0x125)][_0x4b3203(0x149)],'truncated':_0x5ed534[_0x4b3203(0x18a)]||_0x5608bc?.[_0x4b3203(0x18a)]===!![]};return{'binary':![],'text':_0x5ed534[_0x4b3203(0x14f)],'truncated':_0x5ed534[_0x4b3203(0x18a)]||_0x5608bc?.[_0x4b3203(0x18a)]===!![],'afterText':_0x5608bc?.[_0x4b3203(0x14f)]??'',..._0x5608bc===undefined?{}:{'afterTruncated':_0x5608bc[_0x4b3203(0x18a)]}};}async function readCurrentChangeGitDiff(_0x28b358,_0x358445){const _0x31e54b=_0x350254,_0x52736f=await runGit(_0x28b358,[_0x31e54b(0x1ea),_0x31e54b(0x192),_0x31e54b(0x21c),'-z','--',_0x31e54b(0x1df)+_0x358445]);if(_0x52736f[_0x31e54b(0x14f)][_0x31e54b(0x219)]('\x00')[_0x31e54b(0x185)](_0x358445)){const _0x171442=await runGitAllowFailure(_0x28b358,[_0x31e54b(0x1ab),_0x31e54b(0x148),_0x31e54b(0x18e),_0x31e54b(0x1e9),'--',_0x31e54b(0x118),_0x358445]);if(_0x171442[_0x31e54b(0x141)]!==-0x8a*0x47+0x23f5+0x251&&_0x171442[_0x31e54b(0x141)]!==0xd9e+-0x1*-0xd5a+-0x1af7)throw new GitCommandError(_0x171442[_0x31e54b(0x141)],_0x171442[_0x31e54b(0x128)]);return _0x171442;}return runGit(_0x28b358,[_0x31e54b(0x1ab),_0x31e54b(0x18e),_0x31e54b(0x1e9),_0x31e54b(0x154),'--',_0x31e54b(0x1df)+_0x358445]);}export async function isWorkspaceChangeVisible(_0x66674,_0x38beed){const _0x130d8c=_0x350254;try{return await assertCurrentChangePathAccessible(_0x66674,safeGitWorkspacePath(_0x38beed)),!![];}catch(_0x576837){if(_0x576837 instanceof Error&&(_0x576837[_0x130d8c(0x1c0)]===_0x130d8c(0x150)||_0x576837[_0x130d8c(0x1c0)]===_0x130d8c(0x114)||_0x576837[_0x130d8c(0x1c0)]===_0x130d8c(0x21b)))return![];throw _0x576837;}}async function assertCurrentChangePathAccessible(_0x2520d0,_0x5ea00c){const _0xd1a12b=_0x350254,_0x3c6585=await realpath(_0x2520d0),_0x42f0b8=resolve(_0x3c6585,_0x5ea00c),_0x510bcd=await lstat(_0x42f0b8)[_0xd1a12b(0x13e)](_0x2e172a=>{const _0x242f92=_0xd1a12b;if(_0x2e172a[_0x242f92(0x141)]===_0x242f92(0x217))return undefined;throw _0x2e172a;});if(_0x510bcd===undefined)return;await resolveWorkspaceEntry(_0x3c6585,_0x5ea00c,![]);}async function readWorkingTreeText(_0x18e76f,_0x1ea051){const _0x5c964d=_0x350254,_0x27b9d4=await realpath(_0x18e76f);let _0x1f80f6;try{_0x1f80f6=await resolveWorkspaceEntry(_0x27b9d4,_0x1ea051,![]);}catch(_0x25b1d8){if(_0x25b1d8 instanceof Error&&_0x25b1d8[_0x5c964d(0x1c0)]===_0x5c964d(0x114))return undefined;throw _0x25b1d8;}const _0x24f175=await lstat(_0x1f80f6);if(!_0x24f175[_0x5c964d(0x16c)]())return undefined;const _0x568386=await readFile(_0x1f80f6);return diffTextFromBuffer(_0x568386,_0x568386[_0x5c964d(0x149)]>GIT_OUTPUT_LIMIT);}function diffTextFromBuffer(_0x2ee516,_0x402675){const _0x5d6637=_0x350254;if(_0x2ee516[_0x5d6637(0x185)](0x25*0xd4+-0x1294*-0x2+-0x4*0x10f3)||!isValidUtf8(_0x2ee516))return{'binary':!![],'truncated':_0x402675};let _0x3e847d=Math[_0x5d6637(0x19e)](_0x2ee516[_0x5d6637(0x149)],GIT_OUTPUT_LIMIT);while(_0x3e847d>0x20e3+0x22f1+-0x43d4&&_0x3e847d<_0x2ee516[_0x5d6637(0x149)]&&isUtf8ContinuationByte(_0x2ee516[_0x3e847d]))_0x3e847d-=0x7f4+-0x18b1+0x2*0x85f;return{'binary':![],'text':_0x2ee516[_0x5d6637(0x16a)](-0x433+-0x87*-0x11+-0x5*0xf4,_0x3e847d)[_0x5d6637(0x220)](_0x5d6637(0x1b9)),'truncated':_0x402675};}function _0x4e33(){const _0xbfc41e=['kIOVyNvPBgqVkIO','yMLUyxj5','ls1WB3jJzwXHAw49DJe','kIOVx19WEwnHy2HLx18VkIO','kIOVlMDYywrSzs8QkG','D2f0y2HLCG','ls1MB3jTyxq9','zMLUz2vYChjPBNq','su5wquXjrf9oqu1f','kIOVyMLUlYOQ','ywXS','BxrPBwvnCW','C2v0','zw5ZDxjLtg9HzgvK','y2f0y2G','zgLZCg9Zzq','v09ss1nqqunfx1bmqvrgt1jnx1vou1vque9sveve','y29Kzq','kIOVDgvZDc9YDw5ZlYOQ','ls1ZAg9YDa','ls1UBY1JB21TAxqTAwq','zgLNzxn0','yNvIyMXLvxa','zw50CNK','ls1UBY1PBMrLEa','BgvUz3rO','CMvSyxrPDMu','q1jfqvrfx0zjteu','C2LNBMf0DxjL','rKLmrq','C2LUA0rVD24','Dgv4Da','rKLmrv9qqvrix0vtq0fqrq','r0Lux0Hju1rpuLLFuKvgx0LovKfmsuq','ChvZAa','zM9YlwvHy2GTCMvM','sevbra','y3vYC29Y','yMLUyxj5igrPzMyGC2HHmJu2pq','CMvWBgfJzq','v09ss1nqqunfx0rjuKvdve9swv9fweLtvfm','AxntEw1IB2XPy0XPBMS','zMfSBgjHy2TuAw1LCG','kIOVzgLZDc8QkG','ls1ZB3vYy2u9sevbra','zgvZDgLUyxrPB24','mJC5nJiXvwjlq3P4','ywn0Aw9U','v09ss1nqqunfx0rjuKvdve9swv9ot1rFquXmt1Dfra','rKLmrv9ut09Ftefsr0u','AgfZAa','A2LUza','CMvMCY9Yzw1VDgvZlW','C2vHCMnOlMv4y2X1zgu','y29Uy2f0','kIOVDgfYz2v0lYOQ','yMfZzty0','zgf0yq','C3vIyxjYyxK','C29Tzq','AxngAwXL','q09qsuve','zw50CNLmAw1PDa','y2HHBMDLCW','y29UDgvUDenHBMrPzgf0zxm','BgLTAxrZ','rKLmrv9nt1zfx0rfu0nftKrbtLrFsu5wquXjra','ruvysvnu','kIOVlMnHy2HLlYOQ','ls1MB3jTyxq9juGLEdaWjvaLEdaWjwfUjxGWmcvHzsv4mdaLy3qLEdaWjxm','yNL0zuXLBMD0Aa','ls1ZA2LWpq','ls10B3bVlw9YzgvY','v09ss1nqqunfx0rjuKvdve9swv9oqu1fx0LovKfmsuq','Bwf4','ls1Yzwn1CNnPDMu','reLsrunut1jzx0nvuLnpuL9jtLzbteLe','pZ8G','AxnjBNrLz2vY','kIOVDMvUzg9YlYOQ','C29YDa','C3vIBw9KDwXL','Bg9HzgLUzW','zMXHDe1HCa','D2LUmZi','Aw5JBhvKzxm','ls1ZDgfNzwq','yMfZzty0DxjS','DMfSDwvZ','y2fWywnPDhK','Dhj1BMnHDgvK','mZiWmdeYDNLTwgzO','rKLmrv9ot1rFreLsrunut1jz','C3rHBgu','ls1UBY1LEhqTzgLMzG','C3LTyM9SAwmTCMvM','CMvMCY9OzwfKCW','r0Lux0nptu1btKrFrKfjteve','ls1VDgHLCNm','zMXVB3i','C2HHmJu2','zxHWAxj5vgLTzxi','odbIy0fAqMG','lY5Flq','C2HVDW','yMXVyG','ywXSB2nvBNnHzMu','C3rHCNrgywXSyMfJA1bVBgXPBMC','q1jfqvrfx0rjuKvdve9swq','C3rYAw5N','BwLU','CxvLCNK','C3rHDhvZ','ywrK','DxbKyxrL','Agv4','Bw9KAwzPzwrbDa','z2L0','kIOVlNn2zwX0zs1RAxqVkIO','ls1MAxjZDc1WyxjLBNq','CMvWBgfJzufSBa','AM9PBG','CMvMCY9OzwfKCY8','zgLMzG','CMvZDg9Yzq','rvHju1rtx0zjteu','vu5uuKfds0ve','y2XVC2u','rKLmrv9btfjfqurzx0vysvnuuW','mJrHzNfizwK','uKvbrfK','AwDUB3jL','r0Lux0Hju1rpuLLFq1vsu09sx0LovKfmsuq','zw50CMLLCW','B25jBNzHBgLKyxrLza','lM1HCI11CgXVywqT','CMv2lxbHCNnL','DxrMoa','Dg9mB3DLCKnHC2u','v09ss1nqqunfx1bbveHFtK9ux0fcu09mvvrf','kIOVy292zxjHz2uVkIO','Cgf0Aa','mJq2mZCZne9otuzICq','lMDPDc8','BwvZC2fNzq','uKvoqu1fra','rKLmrv9squ5hrv9jtLzbteLe','D29YA3nWywnLuM9VDa','ls1XDwLLDa','DgHLBG','kIOVBM9Kzv9TB2r1BgvZlYOQ','ls13B3jRDhjLzq','ls1NAxqTy29TBw9UlwrPCG','BgLTAxq','Dg91y2G','zgLMzI10CMvL','ls11BNrYywnRzwqTzMLSzxm9ywXS','AwrSzvr0Be1Z','CMvHza','DhjPBq','C2HPzNq','u0Lhs0Lmta','kIOVlMDPDc8QkG','AxneAxjLy3rVCNK','v09ss1nqqunfx05pvf9bteXpv0ve','CM9VDa','reLsrunut1jz','CgfYC2u','DxrMltG','rKLmrv9st09ux01vvefusu9ox0LovKfmsuq','nMLND1r0AG','BwvYz2uTyMfZzq','Bg9JywXLq29TCgfYzq','zMLUza','A2LSBa','oIHSAxrLCMfSkq','revmrvrf','vfLqrv9dsefor0ve','BMfTzq','kIOVlM5LEhqVkIO','ls1ICMfUy2G','ls1KyxrLlw9YzgvY','lNzZy29Kzs9Zzxr0Aw5NCY5QC29U','C2nVCMu','C29YDgvK','ls1UBY10zxH0y29UDG','BhmTzMLSzxm','AxntywzLsw50zwDLCG','r0Lux0Hju1rpuLLFq09ntuLux0LovKfmsuq','u1rbr0ve','BM9YBwfSAxPL','odyYmJaYmhbpCM5vua','zMLSzxmUzxHJBhvKzq','B2zMC2v0','zgLZCgXHEu5HBwu','qureruq','Aw5KzxHpzG','rvHju1rtx0rjuKvdve9swq','zgvJB2rL','C3rHCNrZv2L0Aa','vu5tvefhruq','AxnbyNnVBhv0zq','Bg9N','ls1YB290','CgLWzq','lI4U','iYmG','ls1MB3jTyxq9jsHYzwzUyw1LksuWosuOCMvMBMfTztPZAg9YDcKLmdKLkg9IAMvJDg5HBwuPjta5jsHirufeksuWosuOC3LTCMvMkq','kIOVlNbHCMnLBc1JywnOzs8QkG','kIOVlM51EhqVkIO','v09ss1nqqunfx1bbveHFsu5wquXjra','kIOVlNr1CMjVlYOQ','CMvMCY9Yzw1VDgvZ','Dw5Yzwy','qMLUyxj5igzPBgvZia','ls1TyxGTy291BNq9','B25Jzq','ls1Uyw1Llxn0yxr1CW','Aw52ywXPzgf0zq','igj5DgvZpq','C2L6zq','zxjYB3i','C2XPy2u','r0Lux0niqu5hrv9srvnut1jfx1voqvzbsuXbqKXf','r0Lux1jfue9tsvrpuLLFsu5wquXjra','kIOVlNbUCg0VkIO','r0Lux0Hju1rpuLLFteLnsvrFsu5wquXjra','rKLmrv9trufsq0HFteLnsvrFrvHdruveruq','CMvMCW','zMLSDgvY','C3rKB3v0','ru5pru5u','B2jZzxj2zq','C3bSAxq','BgfZDeLUzgv4t2y','rKLmrv9ot1rFuKvhvuXbuG','ls1LEgnSDwrLlxn0yw5KyxjK','revmrvrfra','kIOVlMfUz3vSyxiVkIO','y2f0lwzPBgu','Dg9tDhjPBMC','kIOVyM93zxjFy29TCg9Uzw50CY8QkG','Dg9mB2nHBgvmB3DLCKnHC2u','C2vHCMnO','r0Lux1DpuKTtuefdrq','ls12zxjPzNK','tu9esuzjruq','v09ss1nqqunfx0rfvKLdrv9qqvrix1jfsKvdveve','Cg9SBezHBgXIywnR','kIOVlNzLBNyVkIO','kIOVB2jQlYOQ','Bwv0ywrHDge','sevbrca','zMLUywXSEq','rKLmrv9ot1rFrK9vtKq','z2v0','kIOVB3v0lYOQ','DgvZDa','l2rLDI9UDwXS','otCWmZK4thzTsvDi','mta3nJmWq0v6EMnc','lMDPDa','lNbHCNq','BwfW','te9dquW','zMLUzeLUzgv4','zNjVBq','mtq3mZe2r3rTELfQ','r0Lux1jfrL9jtLzbteLe','C3rYAw5NAwz5','Aw52ywXPza','B3v0Chv0','uKvnt1rf','CMvIDwLSza','C3rKzxjY','kIOVlNLHCM4VkIO','ls1PCY1HBMnLC3rVCG','kIOVDMvUDI8QkG','BgLUDxG','Dg9vChbLCKnHC2u','zxHLyW','B2jQzwn0'];_0x4e33=function(){return _0xbfc41e;};return _0x4e33();}export async function restoreCurrentChange(_0xb47ce8,_0x3a8944,_0x1213d1){const _0x1614c0=_0x350254,_0x440740=safeGitWorkspacePath(_0x3a8944),_0x217940=_0x1614c0(0x1df)+_0x440740;if(_0x1213d1===_0x1614c0(0x1ae)){const _0xe0d7f=await runGit(_0xb47ce8,[_0x1614c0(0x1a0),_0x1614c0(0x132),'-z',_0x1614c0(0x1cc),'--',_0x217940]);if(!_0xe0d7f[_0x1614c0(0x14f)][_0x1614c0(0x219)]('\x00')[_0x1614c0(0x16b)](_0x57e16b=>_0x57e16b[_0x1614c0(0x1f7)](_0x1614c0(0x17d))&&_0x57e16b[_0x1614c0(0x20e)](-0x2057*0x1+0x18e2+0x778)===_0x440740))throw new Error(_0x1614c0(0x20f));const _0x4c964d=await realpath(_0xb47ce8),_0x16347a=resolve(_0x4c964d,_0x440740),_0x13cd91=await lstat(_0x16347a);if(!_0x13cd91[_0x1614c0(0x16c)]()||_0x13cd91[_0x1614c0(0x159)]())throw new Error(_0x1614c0(0x20f));await unlink(_0x16347a);return;}if(_0x1213d1===_0x1614c0(0x1f8)){await runGit(_0xb47ce8,[_0x1614c0(0x1ac),_0x1614c0(0x1c7),'--',_0x217940]);return;}await runGit(_0xb47ce8,[_0x1614c0(0x1ac),_0x1614c0(0x15c),_0x1614c0(0x186),_0x1614c0(0x1c7),'--',_0x217940]);}function safeGitWorkspacePath(_0x291cb4){const _0x3a41be=_0x350254;if(_0x291cb4[_0x3a41be(0x149)]===-0x21b4+-0x3fa+0x25ae||_0x291cb4[_0x3a41be(0x185)]('\x00')||_0x291cb4[_0x3a41be(0x1f7)]('/')||_0x291cb4[_0x3a41be(0x1f7)]('\x5c'))throw new Error(_0x3a41be(0x150));const _0x1d7b03=_0x291cb4[_0x3a41be(0x1a8)]('\x5c','/');if(_0x1d7b03[_0x3a41be(0x219)]('/')[_0x3a41be(0x16b)](_0xe6e7fc=>_0xe6e7fc===''||_0xe6e7fc==='..'||_0xe6e7fc===_0x3a41be(0x11b)))throw new Error(_0x3a41be(0x150));return _0x1d7b03;}function gitChange(_0x371124){const _0x75f8ff=_0x350254;if(_0x371124==='A')return _0x75f8ff(0x1f3);if(_0x371124==='D')return _0x75f8ff(0x21d);if(_0x371124==='R')return _0x75f8ff(0x1c1);if(_0x371124==='C')return _0x75f8ff(0x16d);if(_0x371124==='T')return _0x75f8ff(0x1e1);return _0x75f8ff(0x226);}export class GitCommandError extends Error{[_0x350254(0x141)];[_0x350254(0x128)];constructor(_0x558050,_0x2a9a36){const _0x2ca1c9=_0x350254;super(_0x2ca1c9(0x191)),this[_0x2ca1c9(0x141)]=_0x558050,this[_0x2ca1c9(0x128)]=_0x2a9a36;}}async function runGit(_0x374842,_0x5b8d11){const _0x460567=_0x350254,_0xc7b73f=await runGitAllowFailure(_0x374842,_0x5b8d11);if(_0xc7b73f[_0x460567(0x141)]!==0x4b1*-0x3+-0x5cf*0x3+0x1f80)throw new GitCommandError(_0xc7b73f[_0x460567(0x141)],_0xc7b73f[_0x460567(0x128)]);return _0xc7b73f;}async function runGitAllowFailure(_0x653f80,_0x2d24ad,_0x1d992e=GIT_OUTPUT_LIMIT){return new Promise((_0x183818,_0x252814)=>{const _0x3a6ec4=_0x57ac,_0x585429=spawn(_0x3a6ec4(0x1a5),[..._0x2d24ad],{'cwd':_0x653f80,'shell':![],'windowsHide':!![],'stdio':[_0x3a6ec4(0x1b3),_0x3a6ec4(0x1fc),_0x3a6ec4(0x1fc)]}),_0x432097=[],_0x574a3a=[];let _0xf5f302=0x1f57+-0x1*0x1c81+0xf2*-0x3,_0x3064b9=![];const _0x311e68=setTimeout(()=>_0x585429[_0x3a6ec4(0x1de)](_0x3a6ec4(0x1d1)),GIT_TIMEOUT_MS);_0x585429[_0x3a6ec4(0x216)]['on'](_0x3a6ec4(0x169),_0x356985=>{const _0x1a7ef7=_0x3a6ec4,_0xc843cf=Math[_0x1a7ef7(0x17a)](-0x25e4+0x1ced*-0x1+0x42d1,_0x1d992e-_0xf5f302);if(_0xc843cf>-0x24+-0x1e35+-0x11*-0x1c9){const _0x4604b0=_0x356985[_0x1a7ef7(0x16a)](-0xb94+-0x1*0x81+-0x407*-0x3,_0xc843cf);_0x432097[_0x1a7ef7(0x152)](_0x4604b0),_0xf5f302+=_0x4604b0[_0x1a7ef7(0x149)];}_0x3064b9||=_0x356985[_0x1a7ef7(0x149)]>_0xc843cf;}),_0x585429[_0x3a6ec4(0x128)]['on'](_0x3a6ec4(0x169),_0x472832=>_0x574a3a[_0x3a6ec4(0x152)](_0x472832[_0x3a6ec4(0x16a)](-0x122e+0x22db+-0x10ad,0x1d1+-0x1f4*0x12+-0x11*-0x2e7))),_0x585429[_0x3a6ec4(0x208)](_0x3a6ec4(0x20d),_0xd16ea9=>{clearTimeout(_0x311e68),_0x252814(_0xd16ea9);}),_0x585429[_0x3a6ec4(0x208)](_0x3a6ec4(0x1af),_0x52f1b1=>{const _0x1ea5ea=_0x3a6ec4;clearTimeout(_0x311e68);const _0x19f8df=Buffer[_0x1ea5ea(0x166)](_0x432097);_0x183818({'code':_0x52f1b1??-0x10eb*-0x1+-0x2113+0x1029,'output':_0x19f8df,'text':_0x19f8df[_0x1ea5ea(0x220)](_0x1ea5ea(0x1b9)),'stderr':Buffer[_0x1ea5ea(0x166)](_0x574a3a)[_0x1ea5ea(0x220)](_0x1ea5ea(0x1b9)),'truncated':_0x3064b9});});});}function isGitUnavailable(_0x217339){const _0x3b4d21=_0x350254;return _0x217339 instanceof Error&&_0x3b4d21(0x141)in _0x217339&&_0x217339[_0x3b4d21(0x141)]===_0x3b4d21(0x217);}function summarizeText(_0x3ea869){const _0x442201=_0x350254;return JSON[_0x442201(0x123)]({'sha256':createHash(_0x442201(0x194))[_0x442201(0x1a2)](_0x3ea869)[_0x442201(0x145)](_0x442201(0x1a3)),'bytes':Buffer[_0x442201(0x176)](_0x3ea869)});}