@openchamber/web 1.23.1 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CodeMirrorCommentWidgets-DL0imnlI.js → CodeMirrorCommentWidgets-C9kV-n7r.js} +1 -1
- package/dist/assets/DiffView-B7YkbY-u.js +4 -0
- package/dist/assets/DirtyBranchSwitchDialog-CU0A93Zx.js +1 -0
- package/dist/assets/FilesView-vjJx7VaM.js +13 -0
- package/dist/assets/GitView-BLhlMYEY.js +6 -0
- package/dist/assets/GuestAttachDialog-B-fwE8r3.js +3 -0
- package/dist/assets/{JsonTreeView-BPBDPY9B.js → JsonTreeView-D_4G5X6-.js} +1 -1
- package/dist/assets/LinearIssuesView-1uKhePfH.js +1 -0
- package/dist/assets/{MarkdownImageGallery-BNjimjiI.js → MarkdownImageGallery-Ix7N_2wp.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-Deel_y5S.js +12 -0
- package/dist/assets/{OnboardingScreen-CWXxIIAH.js → OnboardingScreen-ToIakxb_.js} +1 -1
- package/dist/assets/{PatchDiff-B6J3p3br.js → PatchDiff-BjMgezr1.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BjTRJJ1D.js → PierreDiffViewer-53Ghfnlr.js} +5 -5
- package/dist/assets/PlanView-BGAzxDwD.js +5 -0
- package/dist/assets/SettingsView-n2X-jfBB.js +29 -0
- package/dist/assets/SettingsWindow-Bi8LE9XI.js +1 -0
- package/dist/assets/SubmoduleDiffSummary--YFqK6Ih.js +1 -0
- package/dist/assets/ToolOutputDialog-DRWBvdaJ.js +15 -0
- package/dist/assets/{ToolPartDiffPreview-DRifZ2YH.js → ToolPartDiffPreview-BxZJCU28.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-BOeQtAWV.js → VirtualizedFileDiff-DCXjBGRf.js} +3 -3
- package/dist/assets/{WalkthroughView-BD4p0vhD.js → WalkthroughView-CfIPvWWa.js} +2 -2
- package/dist/assets/appThemeRegistry-DDROzcUO.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-FZI1j1rE.js → computeVirtualFileMetrics-DHgQIkUq.js} +1 -1
- package/dist/assets/de-CX_f-T5U.js +10 -0
- package/dist/assets/es-BERmWNn_.js +16 -0
- package/dist/assets/fr-BjYYE_-z.js +14 -0
- package/dist/assets/index-DpzTz2UH.css +1 -0
- package/dist/assets/index-Dy8xgawx.js +40 -0
- package/dist/assets/{index-DddhnFNK.js → index-WjufPkIV.js} +1 -1
- package/dist/assets/{isDiffPlainText-D4ld2G-2.js → isDiffPlainText-D9faP70y.js} +1 -1
- package/dist/assets/{isFilePlainText-BW1Xfw0F.js → isFilePlainText-6qOcz5Ky.js} +1 -1
- package/dist/assets/ja-DxqeAk9N.js +16 -0
- package/dist/assets/ko-Dty1aUod.js +16 -0
- package/dist/assets/main-BOYSXfYn.js +896 -0
- package/dist/assets/{main-BBqRX3Po.js → main-Bjcre_GE.js} +2 -2
- package/dist/assets/{markdown-shiki.worker-D5fBU-lw.js → markdown-shiki.worker-CahLvHIq.js} +5 -5
- package/dist/assets/markdownCore-DPrwM1rU.js +5 -0
- package/dist/assets/{miniChat-CygpKLC_.js → miniChat-Dz_bPgMc.js} +2 -2
- package/dist/assets/{mobile-CSmUm4vb.js → mobile-BbZPBJrK.js} +2 -2
- package/dist/assets/{patchFileDiff-u4JuidC_.js → patchFileDiff-BvU6KOQC.js} +3 -3
- package/dist/assets/pl-CX-_ROkr.js +16 -0
- package/dist/assets/pt-BR-DhRR1arx.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-uNEUkeAI.js +2 -0
- package/dist/assets/renderMobileApp-BK1kFlcJ.js +25 -0
- package/dist/assets/runtimeEndpointReset-BULHvOwb.js +25 -0
- package/dist/assets/{scheduledTasksApi-Og3jfb4K.js → scheduledTasksApi-DW3xqMQ8.js} +1 -1
- package/dist/assets/shikiHighlight-DsxD9QEa.js +1 -0
- package/dist/assets/textMateThemeFromAppTheme-Da7ed8qM.js +1 -0
- package/dist/assets/tr-cIQtYBpg.js +7 -0
- package/dist/assets/uk-CD21CXFV.js +16 -0
- package/dist/assets/useAppFontEffects-hfv2s6mZ.js +7333 -0
- package/dist/assets/useInlineCommentController-BmtfVbo8.js +2 -0
- package/dist/assets/useRootScrollLock-Cwc4kSl2.js +1 -0
- package/dist/assets/{vendor-base-ui-BY_5qla_.js → vendor-base-ui-CsXYnR5c.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-D5hG1bL9.js → vendor-codemirror-language-data-BPMJpOpT.js} +2 -2
- package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +1 -0
- package/dist/assets/{vendor-motion-dom-D_o3BTI3.js → vendor-motion-dom-DcCgeG69.js} +1 -1
- package/dist/assets/{vendor-remixicon-react-Dil0zKKT.js → vendor-remixicon-react-BDmGmFCA.js} +1 -1
- package/dist/assets/vendor-strip-json-comments-5dJlOkP1.js +4 -0
- package/dist/assets/{vendor-zod-B6551dwG.js → vendor-zod-fZppILAM.js} +4 -4
- package/dist/assets/{web-components-DCyJti1c.js → web-components-U-hWbgJo.js} +2 -2
- package/dist/assets/zh-CN-BWvlPHY-.js +16 -0
- package/dist/assets/zh-TW-CRp5dJU2.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +8 -6
- package/server/built-in-extensions/registry.json +4 -0
- package/server/index.d.ts +2 -0
- package/server/index.js +15 -3
- package/server/lib/fs/DOCUMENTATION.md +8 -0
- package/server/lib/fs/git-process.test.js +77 -0
- package/server/lib/fs/routes.js +2 -1
- package/server/lib/fs/search.js +2 -1
- package/server/lib/git/DOCUMENTATION.md +3 -1
- package/server/lib/git/routes.js +16 -3
- package/server/lib/git/service.js +112 -8
- package/server/lib/git/service.test.js +127 -0
- package/server/lib/guests/DOCUMENTATION.md +66 -0
- package/server/lib/guests/auth-store.js +184 -0
- package/server/lib/guests/auth-store.test.js +112 -0
- package/server/lib/guests/builtins.js +34 -0
- package/server/lib/guests/builtins.test.js +174 -0
- package/server/lib/guests/catalog.js +466 -0
- package/server/lib/guests/catalog.test.js +390 -0
- package/server/lib/guests/clone.js +297 -0
- package/server/lib/guests/extract-zip.js +136 -0
- package/server/lib/guests/extract-zip.test.js +109 -0
- package/server/lib/guests/files.js +308 -0
- package/server/lib/guests/files.test.js +262 -0
- package/server/lib/guests/grant-scope.js +81 -0
- package/server/lib/guests/grant-scope.test.js +75 -0
- package/server/lib/guests/host-session.js +73 -0
- package/server/lib/guests/host-session.test.js +30 -0
- package/server/lib/guests/html-styles.js +6 -0
- package/server/lib/guests/html-styles.test.js +45 -0
- package/server/lib/guests/html-tokens.js +73 -0
- package/server/lib/guests/html-tokens.test.js +53 -0
- package/server/lib/guests/install.js +406 -0
- package/server/lib/guests/install.test.js +338 -0
- package/server/lib/guests/oauth.js +501 -0
- package/server/lib/guests/oauth.test.js +481 -0
- package/server/lib/guests/persist.js +336 -0
- package/server/lib/guests/persist.test.js +288 -0
- package/server/lib/guests/request.js +112 -0
- package/server/lib/guests/request.test.js +206 -0
- package/server/lib/guests/routes.js +838 -0
- package/server/lib/guests/service.js +538 -0
- package/server/lib/guests/service.test.js +277 -0
- package/server/lib/guests/sockets.js +129 -0
- package/server/lib/guests/sockets.test.js +110 -0
- package/server/lib/guests/ssh-install.test.js +188 -0
- package/server/lib/guests/storage.js +68 -0
- package/server/lib/guests/storage.test.js +59 -0
- package/server/lib/guests/updates.js +294 -0
- package/server/lib/guests/updates.test.js +334 -0
- package/server/lib/guests/upload.js +50 -0
- package/server/lib/guests/upload.test.js +131 -0
- package/server/lib/linear/DOCUMENTATION.md +1 -1
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -0
- package/server/lib/openchamber-sessions/routes.js +44 -11
- package/server/lib/openchamber-sessions/routes.test.js +47 -0
- package/server/lib/opencode/DOCUMENTATION.md +54 -0
- package/server/lib/opencode/core-routes.js +39 -1
- package/server/lib/opencode/feature-routes-runtime.js +10 -0
- package/server/lib/opencode/lifecycle-process.test.js +84 -0
- package/server/lib/opencode/lifecycle.js +54 -67
- package/server/lib/opencode/openchamber-routes.js +72 -14
- package/server/lib/opencode/openchamber-routes.test.js +71 -3
- package/server/lib/opencode/settings-helpers.js +5 -0
- package/server/lib/opencode/settings-helpers.test.js +13 -1
- package/server/lib/opencode/settings-normalization-runtime.js +2 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +13 -0
- package/server/lib/opencode/settings-registry.json +7 -0
- package/server/lib/opencode/shutdown-runtime.js +3 -0
- package/server/lib/opencode/shutdown-runtime.test.js +24 -0
- package/server/lib/opencode/theme-archive.js +53 -0
- package/server/lib/opencode/theme-catalog.js +171 -0
- package/server/lib/opencode/theme-catalog.test.js +125 -0
- package/server/lib/opencode/theme-import.test.js +144 -0
- package/server/lib/opencode/theme-runtime.js +100 -28
- package/server/lib/opencode/theme-runtime.test.js +15 -0
- package/server/lib/quota/DOCUMENTATION.md +0 -1
- package/server/lib/quota/providers/index.js +0 -7
- package/server/lib/terminal/DOCUMENTATION.md +2 -0
- package/server/lib/terminal/runtime.js +17 -2
- package/server/lib/terminal/runtime.test.js +45 -0
- package/server/lib/ui-auth/ui-auth.js +43 -8
- package/server/lib/ui-auth/ui-auth.test.js +40 -0
- package/dist/assets/DiffView-q6z6MFdZ.js +0 -4
- package/dist/assets/DirtyBranchSwitchDialog-to6K1rXL.js +0 -1
- package/dist/assets/FilesView-uwvKGOeu.js +0 -13
- package/dist/assets/GitView-CAqrkFYg.js +0 -6
- package/dist/assets/LinearIssuesView-Dq4Nz_DL.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BIYG3j5A.js +0 -12
- package/dist/assets/PlanView-Cs7Aa22g.js +0 -5
- package/dist/assets/SettingsView-DROvkdyX.js +0 -28
- package/dist/assets/SettingsWindow-AtPQGcRJ.js +0 -1
- package/dist/assets/ToolOutputDialog-DmAZDzlT.js +0 -15
- package/dist/assets/appThemeRegistry-BK0dHKa6.js +0 -1
- package/dist/assets/de-Byg3syd1.js +0 -10
- package/dist/assets/es-B-FGkjnQ.js +0 -16
- package/dist/assets/fr-Dvzik_Jj.js +0 -14
- package/dist/assets/index-zhgg-SDz.css +0 -1
- package/dist/assets/index-zzfsbdBe.js +0 -40
- package/dist/assets/ja-CFnftYdc.js +0 -16
- package/dist/assets/ko-CgZ13aWV.js +0 -16
- package/dist/assets/main-BX3ip8Oc.js +0 -930
- package/dist/assets/markdownCore-TRGNObm0.js +0 -5
- package/dist/assets/pl-BDk6AWIE.js +0 -16
- package/dist/assets/pt-BR-DV5hPNsk.js +0 -16
- package/dist/assets/registerCustomTheme-BBXUCRnG.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-Bfh77YcY.js +0 -2
- package/dist/assets/renderMobileApp-DsYwHQBL.js +0 -25
- package/dist/assets/runtimeEndpointReset-MtnTGkZz.js +0 -41
- package/dist/assets/shikiHighlight-CVE7qsu3.js +0 -1
- package/dist/assets/tr-BwS5J324.js +0 -7
- package/dist/assets/uk-Dp60Q7VN.js +0 -16
- package/dist/assets/useAppFontEffects-DQXEYu1N.js +0 -7282
- package/dist/assets/useGitComparison-DjFXbxbu.js +0 -1
- package/dist/assets/useInlineCommentController-B4Vhtx-T.js +0 -2
- package/dist/assets/useRootScrollLock-B32nj08w.js +0 -1
- package/dist/assets/vendor-framer-motion-livSKyyV.js +0 -1
- package/dist/assets/zh-CN-D1MXOnJ7.js +0 -16
- package/dist/assets/zh-TW-MqRc5ECP.js +0 -16
- package/server/lib/quota/providers/crof.js +0 -96
- package/server/lib/quota/providers/crof.test.js +0 -98
|
@@ -37,8 +37,10 @@ HTTP remains the authenticated command plane for create, resize, appearance upda
|
|
|
37
37
|
- Deduplicated create responses may describe another client's execution. Cancellation cleanup closes only the terminal ID allocated for the cancelled request; it never closes an adopted peer execution.
|
|
38
38
|
- Create and restart validate the working directory with a real `stat` and answer HTTP 400 `Invalid working directory` when it is not a directory. When the path does not exist at all (`ENOENT`/`ENOTDIR`, a worktree deleted outside OpenChamber) the body also carries `code: "TERMINAL_CWD_MISSING"`. The client shows the failure without moving the session. The runtime never substitutes a parent directory on its own.
|
|
39
39
|
- Restarts are serialized per terminal. Each restart spawns and wires the replacement before terminating the old process, retaining the terminal ID. Command-mode sessions reject restart with HTTP 400 instead of silently turning into interactive shells with stale action metadata.
|
|
40
|
+
- A restart rechecks session ownership before and after PTY creation. Close, force-kill, idle removal, or shutdown can invalidate it while spawn is pending. A late replacement is terminated instead of being attached to a retired session.
|
|
40
41
|
- A delete that arrives while create is still pending leaves a cancellation tombstone. When the PTY arrives, the runtime terminates it immediately, never inserts the session into the live map, and returns a create error while the delete still succeeds.
|
|
41
42
|
- Close uses SIGTERM with bounded SIGKILL escalation. Force-kill, idle cleanup, and runtime shutdown terminate process groups immediately where supported. Removal explicitly sends a fatal scoped closure and evicts client projections even when a PTY backend fails to emit `onExit`; attached terminals are not considered idle.
|
|
43
|
+
- Shutdown is single-flight, rejects new creates, cancels pending creates, and waits for pending creates and restarts before clearing live sessions. A PTY that arrives during shutdown follows the same cancellation cleanup as a pending create that was explicitly closed.
|
|
42
44
|
|
|
43
45
|
## Security And Relay
|
|
44
46
|
|
|
@@ -100,6 +100,7 @@ export function createTerminalRuntime({
|
|
|
100
100
|
const pendingTerminations = new Set();
|
|
101
101
|
const runtime = typeof globalThis.Bun === 'undefined' ? 'node' : 'bun';
|
|
102
102
|
let ptyProviderPromise = null;
|
|
103
|
+
let shutdownPromise = null;
|
|
103
104
|
let wsServer = new WebSocketServer({ noServer: true, maxPayload: TERMINAL_WS_MAX_PAYLOAD_BYTES });
|
|
104
105
|
const shellResolver = createTerminalShellResolver({ fs, path, searchPathFor, isExecutable, buildAugmentedPath });
|
|
105
106
|
|
|
@@ -282,6 +283,7 @@ export function createTerminalRuntime({
|
|
|
282
283
|
};
|
|
283
284
|
|
|
284
285
|
const createSession = async ({ sessionId, cwd, cols = 80, rows = 24, themeMode, terminalBackground, terminalForeground, shell = 'auto', loginShell = false, mode, command, purpose }) => {
|
|
286
|
+
if (shutdownPromise) throw new Error('Terminal runtime is shutting down');
|
|
285
287
|
if (!validateSize(cols, 1000) || !validateSize(rows, 500)) throw new Error('Invalid terminal dimensions');
|
|
286
288
|
if (typeof loginShell !== 'boolean') throw new Error('Invalid terminal login mode');
|
|
287
289
|
const normalizedShell = normalizeTerminalShell(shell);
|
|
@@ -507,10 +509,15 @@ export function createTerminalRuntime({
|
|
|
507
509
|
const previousRestart = pendingSessionRestarts.get(session.id) ?? Promise.resolve();
|
|
508
510
|
const restart = previousRestart.catch(() => {}).then(async () => {
|
|
509
511
|
await validateCwd(cwd);
|
|
512
|
+
if (shutdownPromise || sessions.get(session.id) !== session) throw new Error('Terminal session was closed during restart');
|
|
510
513
|
if (!validateSize(cols, 1000) || !validateSize(rows, 500)) throw new Error('Invalid terminal dimensions');
|
|
511
514
|
if (typeof loginShell !== 'boolean') throw new Error('Invalid terminal login mode');
|
|
512
515
|
const oldProcess = session.process;
|
|
513
516
|
const spawned = await spawnPty({ cwd, cols, rows, themeMode, shell, loginShell });
|
|
517
|
+
if (shutdownPromise || sessions.get(session.id) !== session) {
|
|
518
|
+
await terminateProcess(spawned.process, true);
|
|
519
|
+
throw new Error('Terminal session was closed during restart');
|
|
520
|
+
}
|
|
514
521
|
session.process = spawned.process; session.backend = spawned.backend; session.shell = spawned.shell; session.loginShell = spawned.loginShell; session.cwd = cwd; session.cols = cols; session.rows = rows;
|
|
515
522
|
session.history = ''; session.pendingHistoryControlSequence = ''; session.pendingThemeControlSequence = ''; session.themeModeEnabled = false; session.status = 'running'; session.exitCode = null; session.signal = null; session.eventQueue.length = 0;
|
|
516
523
|
session.themeMode = themeMode === 'light' ? 'light' : 'dark'; session.terminalBackground = terminalBackground; session.terminalForeground = terminalForeground;
|
|
@@ -560,9 +567,13 @@ export function createTerminalRuntime({
|
|
|
560
567
|
}
|
|
561
568
|
}, 5 * 60 * 1000);
|
|
562
569
|
|
|
563
|
-
const
|
|
570
|
+
const stop = async () => {
|
|
564
571
|
server.off('upgrade', upgradeHandler); clearInterval(idleSweep);
|
|
565
|
-
|
|
572
|
+
for (const pending of pendingSessionCreates.values()) pending.cancelled = true;
|
|
573
|
+
await Promise.allSettled([
|
|
574
|
+
...[...pendingSessionCreates.values()].map((pending) => pending.promise),
|
|
575
|
+
...pendingSessionRestarts.values(),
|
|
576
|
+
]);
|
|
566
577
|
for (const session of sessions.values()) void terminateProcess(session.process, true);
|
|
567
578
|
sessions.clear();
|
|
568
579
|
await Promise.allSettled([...pendingTerminations]);
|
|
@@ -574,5 +585,9 @@ export function createTerminalRuntime({
|
|
|
574
585
|
]);
|
|
575
586
|
wsServer = null;
|
|
576
587
|
};
|
|
588
|
+
const shutdown = () => {
|
|
589
|
+
if (!shutdownPromise) shutdownPromise = stop();
|
|
590
|
+
return shutdownPromise;
|
|
591
|
+
};
|
|
577
592
|
return { shutdown };
|
|
578
593
|
}
|
|
@@ -210,6 +210,51 @@ describe('terminal runtime', () => {
|
|
|
210
210
|
} finally { await harness.runtime.shutdown(); }
|
|
211
211
|
});
|
|
212
212
|
|
|
213
|
+
it('reaps a pending create during shutdown and rejects later creates', async () => {
|
|
214
|
+
const gate = deferred();
|
|
215
|
+
const harness = createHarness({ spawnDeferred: gate });
|
|
216
|
+
const create = harness.routes.post.get('/api/terminal/create');
|
|
217
|
+
const response = createResponse();
|
|
218
|
+
const creation = create({ body: { sessionId: 'pending', cwd: '/repo' } }, response);
|
|
219
|
+
const closing = harness.runtime.shutdown();
|
|
220
|
+
gate.resolve();
|
|
221
|
+
await Promise.all([creation, closing]);
|
|
222
|
+
expect(harness.processes).toHaveLength(1);
|
|
223
|
+
expect(harness.processes[0].killed).toBe(true);
|
|
224
|
+
expect(response.statusCode).toBe(400);
|
|
225
|
+
const later = createResponse();
|
|
226
|
+
await create({ body: { sessionId: 'later', cwd: '/repo' } }, later);
|
|
227
|
+
expect(later.statusCode).toBe(400);
|
|
228
|
+
expect(harness.processes).toHaveLength(1);
|
|
229
|
+
await harness.runtime.shutdown();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
for (const removal of ['close', 'force-kill']) {
|
|
233
|
+
it(`reaps a replacement PTY when ${removal} wins a pending restart`, async () => {
|
|
234
|
+
const gate = { promise: Promise.resolve() };
|
|
235
|
+
const harness = createHarness({ spawnDeferred: gate });
|
|
236
|
+
try {
|
|
237
|
+
await harness.routes.post.get('/api/terminal/create')({ body: { sessionId: 'terminal', cwd: '/repo' } }, createResponse());
|
|
238
|
+
const replacement = deferred();
|
|
239
|
+
gate.promise = replacement.promise;
|
|
240
|
+
const response = createResponse();
|
|
241
|
+
const restarting = harness.routes.post.get('/api/terminal/:sessionId/restart')({ params: { sessionId: 'terminal' }, body: {} }, response);
|
|
242
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
243
|
+
const removed = createResponse();
|
|
244
|
+
if (removal === 'close') {
|
|
245
|
+
await harness.routes.delete.get('/api/terminal/:sessionId')({ params: { sessionId: 'terminal' } }, removed);
|
|
246
|
+
} else {
|
|
247
|
+
harness.routes.post.get('/api/terminal/force-kill')({ body: { sessionId: 'terminal' } }, removed);
|
|
248
|
+
}
|
|
249
|
+
replacement.resolve();
|
|
250
|
+
await restarting;
|
|
251
|
+
expect(harness.processes).toHaveLength(2);
|
|
252
|
+
expect(harness.processes.every((child) => child.killed)).toBe(true);
|
|
253
|
+
expect(response.statusCode).toBe(400);
|
|
254
|
+
} finally { await harness.runtime.shutdown(); }
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
213
258
|
it('retains completed output when the replacement command fails to start', async () => {
|
|
214
259
|
let available = true;
|
|
215
260
|
const harness = createHarness({ fs: { promises: { stat: async () => ({ isDirectory: () => available }) } } });
|
|
@@ -291,6 +291,25 @@ const isWebSocketUpgrade = (req) => {
|
|
|
291
291
|
return String(upgradeValue || '').toLowerCase() === 'websocket';
|
|
292
292
|
};
|
|
293
293
|
|
|
294
|
+
const GUEST_URL_AUTH_SCOPE = /^guest:([a-z][a-z0-9-]*)$/;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* A URL token scope narrows where the token is accepted. `guest:<id>` is
|
|
298
|
+
* minted for a guest iframe and only opens that guest's own package files:
|
|
299
|
+
* the iframe URL is readable by the guest's script, so the token must be
|
|
300
|
+
* worthless anywhere else.
|
|
301
|
+
* @returns {{ kind: 'guest', id: string } | null | undefined} `undefined` when the value is not a scope
|
|
302
|
+
*/
|
|
303
|
+
const parseUrlAuthScope = (value) => {
|
|
304
|
+
const raw = Array.isArray(value) ? value[0] : value;
|
|
305
|
+
if (raw === undefined || raw === null || raw === '') return null;
|
|
306
|
+
if (typeof raw !== 'string') return undefined;
|
|
307
|
+
const match = raw.trim().match(GUEST_URL_AUTH_SCOPE);
|
|
308
|
+
return match ? { kind: 'guest', id: match[1] } : undefined;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
const isGuestScopedPath = (pathname, guestId) => pathname.startsWith(`/api/guests/${guestId}/`);
|
|
312
|
+
|
|
294
313
|
const isUrlAuthReadableHttpPath = (pathname) => {
|
|
295
314
|
return pathname === '/api/event'
|
|
296
315
|
|| pathname === '/api/global/event'
|
|
@@ -301,7 +320,9 @@ const isUrlAuthReadableHttpPath = (pathname) => {
|
|
|
301
320
|
|| pathname === '/api/fs/serve'
|
|
302
321
|
|| pathname.startsWith('/api/fs/serve/')
|
|
303
322
|
|| pathname.startsWith('/api/preview/proxy/')
|
|
304
|
-
|| /^\/api\/projects\/[^/]+\/icon$/.test(pathname)
|
|
323
|
+
|| /^\/api\/projects\/[^/]+\/icon$/.test(pathname)
|
|
324
|
+
|| pathname === '/api/guests'
|
|
325
|
+
|| /^\/api\/guests\/[a-z][a-z0-9-]*\//.test(pathname);
|
|
305
326
|
};
|
|
306
327
|
|
|
307
328
|
const isUrlAuthWebSocketPath = (pathname) => {
|
|
@@ -314,9 +335,12 @@ const isUrlAuthWebSocketPath = (pathname) => {
|
|
|
314
335
|
|| pathname.startsWith('/api/preview/proxy/');
|
|
315
336
|
};
|
|
316
337
|
|
|
317
|
-
const canUseUrlAuthTokenForRequest = (req) => {
|
|
338
|
+
const canUseUrlAuthTokenForRequest = (req, scope = null) => {
|
|
318
339
|
const method = typeof req?.method === 'string' ? req.method.toUpperCase() : 'GET';
|
|
319
340
|
const pathname = getRequestPathname(req);
|
|
341
|
+
if (scope?.kind === 'guest') {
|
|
342
|
+
return !isWebSocketUpgrade(req) && method === 'GET' && isGuestScopedPath(pathname, scope.id);
|
|
343
|
+
}
|
|
320
344
|
if (isWebSocketUpgrade(req)) {
|
|
321
345
|
return isUrlAuthWebSocketPath(pathname);
|
|
322
346
|
}
|
|
@@ -425,16 +449,15 @@ export const createUiAuth = ({
|
|
|
425
449
|
}
|
|
426
450
|
};
|
|
427
451
|
|
|
428
|
-
const issueUrlAuthTokenForSession = (sessionToken) => {
|
|
452
|
+
const issueUrlAuthTokenForSession = (sessionToken, scope = null) => {
|
|
429
453
|
sweepUrlAuthTokens();
|
|
430
454
|
const token = `${URL_AUTH_TOKEN_PREFIX}${crypto.randomBytes(24).toString('base64url')}`;
|
|
431
455
|
const expiresAt = Date.now() + URL_AUTH_TOKEN_TTL_MS;
|
|
432
|
-
urlAuthTokens.set(token, { sessionToken, expiresAt });
|
|
456
|
+
urlAuthTokens.set(token, { sessionToken, expiresAt, scope });
|
|
433
457
|
return { token, expiresAt };
|
|
434
458
|
};
|
|
435
459
|
|
|
436
460
|
const authenticateUrlAuthToken = (req) => {
|
|
437
|
-
if (!canUseUrlAuthTokenForRequest(req)) return null;
|
|
438
461
|
const token = getUrlAuthTokenFromRequest(req);
|
|
439
462
|
if (!token || !token.startsWith(URL_AUTH_TOKEN_PREFIX)) return null;
|
|
440
463
|
const entry = urlAuthTokens.get(token);
|
|
@@ -442,9 +465,13 @@ export const createUiAuth = ({
|
|
|
442
465
|
urlAuthTokens.delete(token);
|
|
443
466
|
return null;
|
|
444
467
|
}
|
|
468
|
+
if (!canUseUrlAuthTokenForRequest(req, entry.scope)) return null;
|
|
445
469
|
return { ok: true, sessionToken: entry.sessionToken || 'url:authenticated' };
|
|
446
470
|
};
|
|
447
471
|
|
|
472
|
+
/** Scope requested on `POST /auth/url-token`: `?scope=guest:<id>` or `{ scope }` in the body. */
|
|
473
|
+
const readRequestedUrlAuthScope = (req) => parseUrlAuthScope(req?.body?.scope ?? req?.query?.scope);
|
|
474
|
+
|
|
448
475
|
const authenticateClientRequest = async (req, { allowUrlToken = true } = {}) => {
|
|
449
476
|
if (allowUrlToken) {
|
|
450
477
|
const urlAuth = authenticateUrlAuthToken(req);
|
|
@@ -566,17 +593,21 @@ export const createUiAuth = ({
|
|
|
566
593
|
res.status(400).json({ error: 'UI password not configured' });
|
|
567
594
|
},
|
|
568
595
|
handleUrlAuthToken: async (req, res) => {
|
|
596
|
+
const scope = readRequestedUrlAuthScope(req);
|
|
597
|
+
if (scope === undefined) {
|
|
598
|
+
return res.status(400).json({ error: 'Unknown URL token scope' });
|
|
599
|
+
}
|
|
569
600
|
const clientAuth = await authenticateClientRequest(req, { allowUrlToken: false });
|
|
570
601
|
if (clientAuth) {
|
|
571
602
|
res.setHeader('Cache-Control', 'no-store');
|
|
572
|
-
return res.json(issueUrlAuthTokenForSession(clientSessionToken(clientAuth)));
|
|
603
|
+
return res.json(issueUrlAuthTokenForSession(clientSessionToken(clientAuth), scope));
|
|
573
604
|
}
|
|
574
605
|
if (requireClientAuth) {
|
|
575
606
|
return res.status(401).json({ error: 'Client authentication required', locked: true, clientAuthRequired: true });
|
|
576
607
|
}
|
|
577
608
|
const sessionToken = await ensureSessionToken(req, res);
|
|
578
609
|
res.setHeader('Cache-Control', 'no-store');
|
|
579
|
-
return res.json(issueUrlAuthTokenForSession(sessionToken));
|
|
610
|
+
return res.json(issueUrlAuthTokenForSession(sessionToken, scope));
|
|
580
611
|
},
|
|
581
612
|
handlePasskeyStatus: (_req, res) => {
|
|
582
613
|
res.json({ enabled: false, hasPasskeys: false, passkeyCount: 0, rpID: null });
|
|
@@ -799,13 +830,17 @@ export const createUiAuth = ({
|
|
|
799
830
|
};
|
|
800
831
|
|
|
801
832
|
const handleUrlAuthToken = async (req, res) => {
|
|
833
|
+
const scope = readRequestedUrlAuthScope(req);
|
|
834
|
+
if (scope === undefined) {
|
|
835
|
+
return res.status(400).json({ error: 'Unknown URL token scope' });
|
|
836
|
+
}
|
|
802
837
|
const sessionToken = await resolveAuthenticatedSessionToken(req, { allowUrlToken: false });
|
|
803
838
|
if (!sessionToken) {
|
|
804
839
|
clearSessionCookie(req, res);
|
|
805
840
|
return respondUnauthorized(req, res);
|
|
806
841
|
}
|
|
807
842
|
res.setHeader('Cache-Control', 'no-store');
|
|
808
|
-
return res.json(issueUrlAuthTokenForSession(sessionToken));
|
|
843
|
+
return res.json(issueUrlAuthTokenForSession(sessionToken, scope));
|
|
809
844
|
};
|
|
810
845
|
|
|
811
846
|
const handleSessionCreate = async (req, res) => {
|
|
@@ -213,6 +213,46 @@ describe('ui auth client credential seam', () => {
|
|
|
213
213
|
});
|
|
214
214
|
expect(mountedServeCalled).toBe(true);
|
|
215
215
|
|
|
216
|
+
const guestReq = { method: 'GET', path: '/api/guests/hello/panel/index.html', url: `/api/guests/hello/panel/index.html?oc_url_token=${encodeURIComponent(urlToken)}`, headers: {} };
|
|
217
|
+
const guestRes = createResponse();
|
|
218
|
+
let guestCalled = false;
|
|
219
|
+
await auth.requireAuth(guestReq, guestRes, () => {
|
|
220
|
+
guestCalled = true;
|
|
221
|
+
});
|
|
222
|
+
expect(guestCalled).toBe(true);
|
|
223
|
+
|
|
224
|
+
// A guest-scoped token opens only that guest's files. It is the token a
|
|
225
|
+
// sandboxed guest page can read from its own URL, so it must fail on every
|
|
226
|
+
// system path and on another guest's files.
|
|
227
|
+
const guestMintReq = { method: 'POST', path: '/auth/url-token', query: { scope: 'guest:hello' }, headers: { authorization: 'Bearer client-token', accept: 'application/json' } };
|
|
228
|
+
const guestMintRes = createResponse();
|
|
229
|
+
await auth.handleUrlAuthToken(guestMintReq, guestMintRes);
|
|
230
|
+
const guestToken = guestMintRes.body.token;
|
|
231
|
+
expect(typeof guestToken).toBe('string');
|
|
232
|
+
const guestScopedReq = { method: 'GET', path: '/api/guests/hello/panel/main.js', url: `/api/guests/hello/panel/main.js?oc_url_token=${encodeURIComponent(guestToken)}`, headers: {} };
|
|
233
|
+
let guestScopedCalled = false;
|
|
234
|
+
await auth.requireAuth(guestScopedReq, createResponse(), () => {
|
|
235
|
+
guestScopedCalled = true;
|
|
236
|
+
});
|
|
237
|
+
expect(guestScopedCalled).toBe(true);
|
|
238
|
+
for (const forbidden of [
|
|
239
|
+
{ method: 'GET', path: '/api/fs/raw', url: `/api/fs/raw?path=%2Ftmp%2Fimage.png&oc_url_token=${encodeURIComponent(guestToken)}` },
|
|
240
|
+
{ method: 'GET', path: '/api/event', url: `/api/event?oc_url_token=${encodeURIComponent(guestToken)}` },
|
|
241
|
+
{ method: 'GET', path: '/api/guests/other/panel/main.js', url: `/api/guests/other/panel/main.js?oc_url_token=${encodeURIComponent(guestToken)}` },
|
|
242
|
+
{ method: 'GET', path: '/api/guests', url: `/api/guests?oc_url_token=${encodeURIComponent(guestToken)}` },
|
|
243
|
+
]) {
|
|
244
|
+
const forbiddenRes = createResponse();
|
|
245
|
+
let forbiddenCalled = false;
|
|
246
|
+
await auth.requireAuth({ ...forbidden, headers: {} }, forbiddenRes, () => {
|
|
247
|
+
forbiddenCalled = true;
|
|
248
|
+
});
|
|
249
|
+
expect(forbiddenCalled).toBe(false);
|
|
250
|
+
expect(forbiddenRes.statusCode).toBe(401);
|
|
251
|
+
}
|
|
252
|
+
const badScopeRes = createResponse();
|
|
253
|
+
await auth.handleUrlAuthToken({ ...guestMintReq, query: { scope: 'admin' } }, badScopeRes);
|
|
254
|
+
expect(badScopeRes.statusCode).toBe(400);
|
|
255
|
+
|
|
216
256
|
const dictationWsReq = {
|
|
217
257
|
method: 'GET',
|
|
218
258
|
path: '/api/dictation/ws',
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import{R as i,f as Ye,j as t}from"./vendor-react-BUCujlKS.js";import{u as le,K as Fe,a as De}from"./index-zzfsbdBe.js";import{c as Fn,b as Dn,u as An,a as Vn,B as En,C as Ln,P as Tt,h as Tn,e as Mn,g as Bn,i as In,f as Pn}from"./patchFileDiff-u4JuidC_.js";import{c as On,b as zn,i as _n,u as Kn,a as Hn,d as Gn}from"./useGitComparison-DjFXbxbu.js";import{f as Pe,B as he,I as V,h as je,Y as $t,ae as $n,J as ee,af as qn,bd as Wn,H as Un,ag as Jn,ai as Xn,y as Mt,k as Yn,cO as qt,t as Je,ic as Qn,av as Xe,a9 as Zn,aa as es,ab as ts,i2 as Wt,id as ns,aw as Ut,f_ as ss,at as Ue,au as rs,bT as Jt,ap as is,ar as os,as,ao as ls}from"./useAppFontEffects-DQXEYu1N.js";import{d as cs,b as us}from"./runtimeEndpointReset-MtnTGkZz.js";import{P as fs}from"./PierreDiffViewer-BjTRJJ1D.js";import{u as ds,v as ms,g as ps,W as hs}from"./main-BX3ip8Oc.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-B6551dwG.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./VirtualizedFileDiff-BOeQtAWV.js";import"./web-components-DCyJti1c.js";import"./computeVirtualFileMetrics-FZI1j1rE.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./isDiffPlainText-D4ld2G-2.js";import"./vendor-diff-C3JhlQdm.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BY_5qla_.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./contextPanelEmbeddedChat-CirXEPJq.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-D5hG1bL9.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./Virtualizer-D_a8gKmg.js";import"./useInlineCommentController-B4Vhtx-T.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";import"./useRootScrollLock-B32nj08w.js";import"./scheduledTasksApi-Og3jfb4K.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";const gs=i.memo(function(e){const s=Ye.c(13),{index:u,staged:h,busyHunk:m,disabled:x,onAction:j}=e,{t:C}=Pe();let c;s[0]!==h?(c=h?["unstage"]:["discard","stage"],s[0]=h,s[1]=c):c=s[1];const w=c;let v;s[2]===Symbol.for("react.memo_cache_sentinel")?(v={top:"var(--oc-hunk-action-offset, 0.25rem)"},s[2]=v):v=s[2];let d;s[3]!==w||s[4]!==m||s[5]!==x||s[6]!==u||s[7]!==j||s[8]!==C?(d=t.jsx("div",{className:"pointer-events-auto flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-sm backdrop-blur-md",children:w.map(b=>{const _=C(b==="stage"?"diffView.hunk.stageTitle":b==="unstage"?"diffView.hunk.unstageTitle":"diffView.hunk.discardTitle",{index:u+1}),P=m?.index===u&&m.action===b;return t.jsx(he,{variant:"ghost",size:"xs",className:je("rounded-full bg-transparent text-muted-foreground hover:bg-transparent hover:text-foreground",b==="discard"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",b==="stage"&&"text-[var(--status-success)] hover:text-[var(--status-success)]"),disabled:x||m!==null,title:_,"aria-label":_,onPointerDown:xs,onClick:f=>{f.stopPropagation(),j(u,b)},children:t.jsx(V,{name:P?"loader-4":b==="stage"?"add":"arrow-go-back",className:je(b==="stage"?"size-4":"size-3.5",P&&"animate-spin")})},b)})}),s[3]=w,s[4]=m,s[5]=x,s[6]=u,s[7]=j,s[8]=C,s[9]=d):d=s[9];let E;return s[10]!==u||s[11]!==d?(E=t.jsx("div",{className:"pointer-events-none absolute right-3 z-20",style:v,"data-hunk-actions":u,children:d}),s[10]=u,s[11]=d,s[12]=E):E=s[12],E});function xs(o){return o.stopPropagation()}const Bt=(o,e)=>{if(e.length===0)return null;let s=null,u=null;for(const m of e)m.top<=o?(!s||m.top>s.top)&&(s=m):(!u||m.top<u.top)&&(u=m);const h=s??u;return h?{path:h.path,topOffset:h.top-o}:null},ys=(o,e,s,u)=>Math.min(Math.max(0,u),Math.max(0,o+s-e)),It=o=>{if(!o)return null;const e=o.split(`
|
|
2
|
-
`);let s=null;for(const u of e){const h=u.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(h){const m=Number.parseInt(h[1]??"",10);s=Number.isFinite(m)&&m>=1?m:null;continue}if(s!==null){if(u.startsWith(" ")){s+=1;continue}if(u.startsWith("+"))return s;if(u.startsWith("-"))return Math.max(1,s)}}return null},ws=1100,bs=15e3,Pt=500,Ot=300,Xt=1e6,xt=3,js=o=>o<=6?o:o<=12?6:o<=25?4:2,zt={status:"loading"},vs=3,Ss=i.memo(()=>{const o=Ye.c(4),{t:e}=Pe();let s;o[0]!==e?(s=e("diffView.binary.unavailable"),o[0]=e,o[1]=s):s=o[1];let u;return o[2]!==s?(u=t.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:t.jsx("div",{className:"typography-meta text-muted-foreground",children:s})}),o[2]=s,o[3]=u):u=o[3],u}),Yt={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},Ns=Yt.M,ks=o=>{const e=o.index?.trim(),s=o.working_dir?.trim();return e&&e!=="?"?e.charAt(0):s?s.charAt(0):e?.charAt(0)||s?.charAt(0)||"M"},Qt=o=>{const e=ks(o);return Yt[e]??Ns},Cs=o=>{const{index:e,working_dir:s}=o;return e==="A"||s==="A"||e==="?"||s==="?"},_t=o=>{const e=o.index?.trim();return!!(e&&e!=="?")},Kt=o=>!!o.working_dir?.trim()||o.index==="?",Rs=(o,e)=>ss(o,e),Ht=o=>(o||"").replace(/\\/g,"/").replace(/\/+$/,""),Gt=(o,e)=>{const s=o.split(`
|
|
3
|
-
`),u=e.split(`
|
|
4
|
-
`),h=Math.min(s.length,u.length);for(let m=0;m<h;m+=1)if(s[m]!==u[m])return m+1;return u.length>s.length?s.length+1:s.length>u.length?Math.max(1,u.length):1},Fs=o=>Array.isArray(o)?o.filter(e=>!e||typeof e!="object"?!1:typeof e.file=="string"):[],Ds=o=>o==="added"?"A":o==="deleted"?"D":"M",yt=(o,e,s)=>In(e)?{original:"",modified:"",isBinary:!0,patch:e,contextMode:s}:{original:"",modified:"",patch:e,fileDiff:Pn(o,e),contextMode:s},Zt=(o,e,s)=>{const u=o??0,h=e??0;return!u&&!h?null:t.jsxs("span",{className:je("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",s?.className),children:[u?t.jsxs("span",{style:{color:"var(--status-success)"},children:["+",u]}):null,h?t.jsxs("span",{style:{color:"var(--status-error)"},children:["-",h]}):null]})},As=i.memo(o=>{const e=Ye.c(68),{scope:s,workingCount:u,stagedCount:h,turnCount:m,branchCount:x,commitCount:j,prCount:C,showCommitOption:c,showBranchOption:w,onScopeChange:v}=o,{t:d}=Pe(),[E,b]=i.useState(!1),_=s==="pr"?C??0:s==="staged"?h:s==="turn"?m:s==="branch"?x??0:s==="commit"?j??0:u;let P;e[0]!==s||e[1]!==d?(P=d(s==="pr"?"session.githubIntegration.tabs.pullRequests":s==="staged"?"diffView.scope.staged":s==="turn"?"diffView.scope.lastTurn":s==="branch"?"diffView.scope.branch":s==="commit"?"commitComparison.mode":"diffView.scope.changed"),e[0]=s,e[1]=d,e[2]=P):P=e[2];const f=P;let ge;e[3]!==d?(ge=d("diffView.scope.selectorAria"),e[3]=d,e[4]=ge):ge=e[4];let xe;e[5]!==_?(xe=t.jsxs("span",{className:"diff-toolbar__scope-count",children:[": ",_]}),e[5]=_,e[6]=xe):xe=e[6];let Y;e[7]!==f||e[8]!==xe?(Y=t.jsxs("span",{className:"whitespace-nowrap",children:[f,xe]}),e[7]=f,e[8]=xe,e[9]=Y):Y=e[9];let F;e[10]===Symbol.for("react.memo_cache_sentinel")?(F=t.jsx(V,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"}),e[10]=F):F=e[10];let L;e[11]!==ge||e[12]!==Y?(L=t.jsx(is,{asChild:!0,children:t.jsxs("button",{type:"button",className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-ui-label font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring","aria-label":ge,children:[Y,F]})}),e[11]=ge,e[12]=Y,e[13]=L):L=e[13];let S;e[14]!==v?(S=J=>{(J==="working"||J==="staged"||J==="turn"||J==="branch"||J==="commit"||J==="pr")&&(v?.(J),b(!1))},e[14]=v,e[15]=S):S=e[15];let te;e[16]!==d?(te=d("diffView.scope.changed"),e[16]=d,e[17]=te):te=e[17];let ne;e[18]!==te?(ne=t.jsx("span",{children:te}),e[18]=te,e[19]=ne):ne=e[19];let ce;e[20]!==u?(ce=t.jsx("span",{className:"typography-meta text-muted-foreground",children:u}),e[20]=u,e[21]=ce):ce=e[21];let se;e[22]!==ce||e[23]!==ne?(se=t.jsx(Ue,{value:"working",children:t.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[ne,ce]})}),e[22]=ce,e[23]=ne,e[24]=se):se=e[24];let ue;e[25]!==d?(ue=d("diffView.scope.staged"),e[25]=d,e[26]=ue):ue=e[26];let Q;e[27]!==ue?(Q=t.jsx("span",{children:ue}),e[27]=ue,e[28]=Q):Q=e[28];let W;e[29]!==h?(W=t.jsx("span",{className:"typography-meta text-muted-foreground",children:h}),e[29]=h,e[30]=W):W=e[30];let fe;e[31]!==Q||e[32]!==W?(fe=t.jsx(Ue,{value:"staged",children:t.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[Q,W]})}),e[31]=Q,e[32]=W,e[33]=fe):fe=e[33];let T;e[34]!==d?(T=d("diffView.scope.lastTurn"),e[34]=d,e[35]=T):T=e[35];let A;e[36]!==T?(A=t.jsx("span",{children:T}),e[36]=T,e[37]=A):A=e[37];let $;e[38]!==m?($=t.jsx("span",{className:"typography-meta text-muted-foreground",children:m}),e[38]=m,e[39]=$):$=e[39];let K;e[40]!==A||e[41]!==$?(K=t.jsx(Ue,{value:"turn",children:t.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[A,$]})}),e[40]=A,e[41]=$,e[42]=K):K=e[42];let de;e[43]!==x||e[44]!==w||e[45]!==d?(de=w?t.jsx(Ue,{value:"branch",children:t.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[t.jsx("span",{children:d("diffView.scope.branch")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:x??"…"})]})}):null,e[43]=x,e[44]=w,e[45]=d,e[46]=de):de=e[46];let U;e[47]!==j||e[48]!==c||e[49]!==d?(U=c&&t.jsx(Ue,{value:"commit",children:t.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[t.jsx("span",{children:d("commitComparison.mode")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:j??"…"})]})}),e[47]=j,e[48]=c,e[49]=d,e[50]=U):U=e[50];let O;e[51]!==C||e[52]!==c||e[53]!==d?(O=c&&t.jsx(Ue,{value:"pr",children:t.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[t.jsx("span",{children:d("session.githubIntegration.tabs.pullRequests")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:C??"…"})]})}),e[51]=C,e[52]=c,e[53]=d,e[54]=O):O=e[54];let q;e[55]!==s||e[56]!==se||e[57]!==fe||e[58]!==K||e[59]!==de||e[60]!==U||e[61]!==O||e[62]!==S?(q=t.jsx(os,{align:"start",className:"w-40",children:t.jsxs(as,{value:s,onValueChange:S,children:[se,fe,K,de,U,O]})}),e[55]=s,e[56]=se,e[57]=fe,e[58]=K,e[59]=de,e[60]=U,e[61]=O,e[62]=S,e[63]=q):q=e[63];let ve;return e[64]!==E||e[65]!==q||e[66]!==L?(ve=t.jsxs(ls,{open:E,onOpenChange:b,children:[L,q]}),e[64]=E,e[65]=q,e[66]=L,e[67]=ve):ve=e[67],ve}),Vs=i.memo(o=>{const e=Ye.c(11),{changedFiles:s,selectedFile:u,onSelectFile:h}=o,{t:m}=Pe();if(s.length===0)return null;let x;if(e[0]!==s||e[1]!==h||e[2]!==u||e[3]!==m){let C;e[5]!==h||e[6]!==u||e[7]!==m?(C=c=>{const w=Qt(c),v=u===c.path;return t.jsx("li",{children:t.jsxs("button",{type:"button",onClick:()=>h(c.path),className:je("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",v?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[t.jsx(Ut,{filePath:c.path,className:"h-3.5 w-3.5 flex-shrink-0"}),t.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:w.color},title:m(w.descriptionKey),"aria-label":m(w.descriptionKey),children:w.code}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:c.path,children:c.path}),Zt(c.insertions,c.deletions)]})},c.path)},e[5]=h,e[6]=u,e[7]=m,e[8]=C):C=e[8],x=s.map(C),e[0]=s,e[1]=h,e[2]=u,e[3]=m,e[4]=x}else x=e[4];let j;return e[9]!==x?(j=t.jsx(Jt,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:t.jsx("ul",{className:"flex flex-col gap-1",children:x})}),e[9]=x,e[10]=j):j=e[10],j}),Es=i.memo(o=>{const e=Ye.c(20),{filePath:s,diff:u,renderSideBySide:h}=o,{t:m}=Pe(),x=u.original.length>0,j=u.modified.length>0,C=h?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",c=h?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w={contain:"layout"},e[0]=w):w=e[0];let v;e[1]!==u.original||e[2]!==s||e[3]!==x||e[4]!==c||e[5]!==h||e[6]!==m?(v=x&&t.jsxs("div",{className:c,children:[t.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:m("diffView.image.original")}),t.jsx("img",{src:u.original,alt:m("diffView.image.originalAlt",{path:s}),className:h?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=u.original,e[2]=s,e[3]=x,e[4]=c,e[5]=h,e[6]=m,e[7]=v):v=e[7];let d;e[8]!==u.modified||e[9]!==s||e[10]!==j||e[11]!==x||e[12]!==c||e[13]!==h||e[14]!==m?(d=j&&t.jsxs("div",{className:c,children:[t.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:m(x?"diffView.image.modified":"diffView.image.new")}),t.jsx("img",{src:u.modified,alt:m("diffView.image.modifiedAlt",{path:s}),className:h?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=u.modified,e[9]=s,e[10]=j,e[11]=x,e[12]=c,e[13]=h,e[14]=m,e[15]=d):d=e[15];let E;return e[16]!==C||e[17]!==v||e[18]!==d?(E=t.jsx("div",{className:"w-full overflow-auto p-4",style:w,children:t.jsxs("div",{className:C,children:[v,d]})}),e[16]=C,e[17]=v,e[18]=d,e[19]=E):E=e[19],E}),Ls=i.memo(o=>{const e=Ye.c(17),{filePath:s,diff:u,renderSideBySide:h,wrapLines:m,hunkActions:x}=o;let j;e[0]!==s?(j=rs(s)||"text",e[0]=s,e[1]=j):j=e[1];const C=j;if(u.isBinary){let v;return e[2]===Symbol.for("react.memo_cache_sentinel")?(v=t.jsx(Ss,{}),e[2]=v):v=e[2],v}if(Xe(s)){let v;return e[3]!==u||e[4]!==s||e[5]!==h?(v=t.jsx(Es,{filePath:s,diff:u,renderSideBySide:h}),e[3]=u,e[4]=s,e[5]=h,e[6]=v):v=e[6],v}let c;e[7]===Symbol.for("react.memo_cache_sentinel")?(c={contain:"layout"},e[7]=c):c=e[7];let w;return e[8]!==u.fileDiff||e[9]!==u.modified||e[10]!==u.original||e[11]!==s||e[12]!==x||e[13]!==C||e[14]!==h||e[15]!==m?(w=t.jsx("div",{className:"w-full",style:c,children:t.jsx(fs,{original:u.original,modified:u.modified,fileDiff:u.fileDiff,language:C,fileName:s,renderSideBySide:h,wrapLines:m,layout:"inline",hunkActions:x})}),e[8]=u.fileDiff,e[9]=u.modified,e[10]=u.original,e[11]=s,e[12]=x,e[13]=C,e[14]=h,e[15]=m,e[16]=w):w=e[16],w}),Ts=i.memo(({visible:o=!0,directory:e,file:s,layout:u,wrapLines:h,isSelected:m,isExpanded:x,isMounted:j,onSelect:C,onExpandedChange:c,registerSectionRef:w,showOpenInEditorAction:v=!1,isOpeningInEditor:d=!1,onOpenInEditor:E,staged:b=!1,loadFullFiles:_=!1,initialDiffData:P=null,comparisonDiff:f,onRetryComparisonDiff:ge,readOnlyActions:xe=!1,hunkActionsEnabled:Y=!1})=>{const{t:F}=Pe(),{git:L}=$t(),S=ee(i.useCallback(g=>g.directories.get(e)?.diffCache.get(s.path)??null,[e,s.path])),te=ee(g=>g.setDiff),ne=ee(g=>g.fetchStatus),ce=le(g=>g.setDiffFileLayout),[se,ue]=i.useState(0),[Q,W]=i.useState(null),[fe,T]=i.useState(!1),A=f?f.status==="error"?f.message:null:Q,$=f?f.status==="loading":fe,[K,de]=i.useState(null),U=i.useRef(!1),[O,q]=i.useState(null),[ve,J]=i.useState(!1),[re,Qe]=i.useState(null),[it,Ae]=i.useState(null),ye=i.useRef(null),ut=i.useRef(null),Oe=i.useMemo(()=>Qt(s),[s]),ze=u==="side-by-side",Ve=_?"full":"patch",we=`${s.index}:${s.working_dir}:${s.insertions}:${s.deletions}`,a=Y&&!xe&&!P&&!f&&!Xe(s.path),Se=JSON.stringify([De(),e,s.path,b,we,se]),z=O?.scope===Se?O.patch:null,me=i.useMemo(()=>f?f.status==="ready"?f.data:null:P||(b?it:re||(S?{original:S.original,modified:S.modified,isBinary:S.isBinary,contextMode:"full"}:null)),[f,S,P,re,b,it]),Ne=me?.contextMode===Ve,ot=i.useCallback(g=>{ut.current=g,w(s.path,g)},[s.path,w]),_e=i.useCallback(g=>{c(s.path,g)},[s.path,c]),Ze=i.useCallback(()=>{C(s.path)},[s.path,C]),et=i.useRef({fileStatusKey:we,staged:b});i.useEffect(()=>{if(!o)return;const g=et.current;g.fileStatusKey===we&&g.staged===b||(et.current={fileStatusKey:we,staged:b},b?Ae(null):Qe(null),W(null),ye.current=null)},[we,b,o]),i.useEffect(()=>{if(!o||!x||!j||Q)return;if(!e||f||P||me&&Ne&&(!a||z!==null)){ye.current=null,T(!1);return}const g=`${e}::${s.path}::${b?"staged":"unstaged"}::${we}::${Ve}::${se}`;if(ye.current===g)return;ye.current=g,W(null),T(!0);let M=!1;const ie=De(),Ge=_?Xt:xt,X=Xe(s.path)?L.getGitFileDiff(e,{path:s.path,staged:b}):!_&&z!==null?Promise.resolve({diff:z}):L.getGitDiff(e,{path:s.path,staged:b,contextLines:Ge}),ft=a&&_&&z===null?L.getGitDiff(e,{path:s.path,staged:b,contextLines:xt}).then(R=>R.diff):Promise.resolve(z),Ee=Promise.all([X,ft]),Le=bs;let pe;const H=new Promise((R,oe)=>{pe=setTimeout(()=>oe(new Error(`Timed out after ${Le}ms`)),Le)});return Promise.race([Ee,H]).then(([R,oe])=>{if(M||ie!==De())return;const ke="diff"in R&&!_?R.diff:oe;if(a&&_&&ke!==null&&/^@@\s/m.test(ke)&&"diff"in R&&R.diff!==ke&&!Tn(R.diff,ke))throw q(null),new Error(F("diffView.hunk.unavailable"));if(a&&ke!==null&&q({scope:Se,patch:ke}),"diff"in R){const Ce=yt(s.path,R.diff,Ve);b?Ae(Ce):Qe(Ce)}else{const Ce={original:R.original??"",modified:R.modified??"",isBinary:R.isBinary,contextMode:"full"};b?Ae(Ce):te(e,s.path,Ce,ie)}T(!1)}).catch(R=>{if(M||ie!==De())return;const oe=R instanceof Error?R.message:String(R);W(oe),T(!1)}).finally(()=>clearTimeout(pe)),()=>{M=!0,clearTimeout(pe),ye.current===g&&(ye.current=null)}},[z,a,Se,f,Ve,me,Ne,se,e,s.path,we,L,P,x,j,_,Q,te,b,F,o]);const tt=i.useCallback(()=>{_e(!x),Ze()},[_e,Ze,x]),Ke=i.useCallback(()=>{W(null),q(null),Qe(null),Ae(null),ye.current=null,ue(g=>g+1)},[]),nt=i.useCallback(async(g,M)=>{if(!e||!a||$||A||U.current||K!==null)return;const ie=z?Mn(z,g):null;if(!ie){Je.error(F("diffView.hunk.unavailable"));return}if(b&&M!=="unstage"||!b&&M==="unstage")return;U.current=!0;const Ge=De();de({index:g,action:M});try{const X=M==="stage"?L.stageGitHunk:M==="unstage"?L.unstageGitHunk:L.revertGitHunk;if(!X){Je.error(F("diffView.hunk.unsupported"));return}if(await X(e,s.path,ie),Ge!==De())return;Ke(),qt.requestGitRefresh({directory:e,paths:[s.path]}),await ne(e,L)}catch(X){if(Ge!==De())return;Ke(),Je.error(X instanceof Error&&X.message?X.message:F("diffView.hunk.unavailable"))}finally{U.current=!1,de(X=>X?.index===g&&X.action===M?null:X)}},[z,a,$,A,e,ne,s.path,L,K,Ke,b,F]),be=i.useMemo(()=>a&&z!==null?Bn(z):[],[z,a]),He=i.useCallback(g=>t.jsx(gs,{index:g,staged:b,busyHunk:K,disabled:$||!!A,onAction:nt}),[A,nt,K,$,b]),st=i.useMemo(()=>be.length>0?{anchors:be,render:He}:void 0,[be,He]);return t.jsxs("div",{ref:ot,className:"scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0",children:[t.jsx("div",{className:"sticky top-0 z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80",children:t.jsxs("div",{role:"button",tabIndex:0,onClick:tt,onKeyDown:g=>{g.target===g.currentTarget&&(g.key==="Enter"||g.key===" ")&&(g.preventDefault(),tt())},className:je("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",m?"bg-[var(--interactive-selection)]/35":null),children:[t.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),t.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[t.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:x?t.jsx(V,{name:"arrow-down-s",className:"size-4"}):t.jsx(V,{name:"arrow-right-s",className:"size-4"})}),t.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:Oe.color},title:F(Oe.descriptionKey),"aria-label":F(Oe.descriptionKey),children:Oe.code}),t.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:s.path,children:t.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[t.jsx(Ut,{filePath:s.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const g=s.path.lastIndexOf("/");if(g===-1)return t.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:s.path});const M=s.path.slice(0,g),ie=s.path.slice(g+1);return t.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[t.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:M}),t.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[t.jsx("span",{className:"text-muted-foreground",children:"/"}),t.jsx("span",{className:"text-foreground",children:ie})]})]})})()]})})]}),t.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[Zt(s.insertions,s.deletions),v&&E?t.jsx(he,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:F("diffView.actions.openFileInEditorAtChange"),onClick:g=>{g.stopPropagation(),E(s.path,me)},disabled:d,children:d?t.jsx(V,{name:"loader-4",className:"size-3.5 animate-spin"}):t.jsx(V,{name:"edit",className:"size-3.5"})}):null,t.jsx(Wt,{mode:ze?"side-by-side":"unified",onModeChange:g=>{const M=g==="side-by-side"?"side-by-side":"inline";ce(s.path,M)},className:"opacity-70"})]})]})}),x&&t.jsxs("div",{className:"relative bg-background overflow-hidden",children:[!j&&!A?t.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,A?t.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[t.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:F("diffView.state.failedToLoadDiff")}),t.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:A}),t.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>f?ge?.():Ke(),children:F("diffView.actions.retry")})]}):null,j&&$&&!me&&!A?t.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[t.jsx(V,{name:"loader-4",className:"size-4 animate-spin"}),F("diffView.state.loadingDiff")]}):null,j&&me&&!ve&&s.insertions+s.deletions>Pt?t.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[t.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:F("diffView.state.largeDiff",{count:s.insertions+s.deletions})}),t.jsx("div",{className:"typography-meta text-muted-foreground",children:F("diffView.state.largeDiffDescription")}),t.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>J(!0),children:F("diffView.actions.renderAnyway")})]}):null,j&&me&&(ve||s.insertions+s.deletions<=Pt)?t.jsx(t.Fragment,{children:t.jsx(Ls,{filePath:s.path,diff:me,renderSideBySide:ze,wrapLines:h,hunkActions:st})}):null]})]})}),Yi=({visible:o=!0,hideStackedFileSidebar:e=!1,stackedDefaultCollapsedAll:s=!1,pinSelectedFileHeaderToTopOnNavigate:u=!1,showOpenInEditorAction:h=!1,diffScope:m="all",onDiffScopeChange:x,targetFilePath:j=null,flushContent:C=!1})=>{const{t:c}=Pe(),{git:w,files:v}=$t(),d=$n(),E=ee(n=>n.runtimeKey),{rootIsGitRepo:b,gitDirectory:_,nestedRepos:P}=qn(d??null,{enabled:o}),f=_??d,ge=le(n=>n.openContextSurface),xe=ds(n=>n.requestSource),{screenWidth:Y,isMobile:F}=Wn(),L=Un(f??null),S=Jn(f??null),te=Xn(f??null),ne=ee(n=>n.setActiveDirectory),ce=ee(n=>n.ensureStatus),se=ee(n=>n.selectNestedRepo),ue=ee(n=>n.fetchStatus),Q=ee(n=>n.fetchBranches),W=ee(n=>n.clearDiffCache),fe=ee(n=>n.setDiff),[T,A]=i.useState(null),[$,K]=i.useState(!1),[de,U]=i.useState(null),[O,q]=i.useState(()=>new Set),[ve,J]=i.useState(()=>new Set),[re,Qe]=i.useState(!1),[it,Ae]=i.useState(0),[ye,ut]=i.useState(()=>new Map),[Oe,ze]=i.useState(!1),[Ve,we]=i.useState(!1),[a,Se]=i.useState(m);i.useEffect(()=>{Se(m)},[m]);const z=le(n=>n.pendingDiffFile),me=le(n=>n.pendingDiffStaged),Ne=le(n=>n.pendingDiffScope),ot=le(n=>n.setPendingDiffFile),_e=le(n=>n.diffLayoutPreference),Ze=le(n=>n.diffFileLayout),et=le(n=>n.setDiffFileLayout),tt=le(n=>n.diffWrapLines),Ke=le(n=>n.setDiffWrapLines),nt=le(n=>n.openContextFileAtLine),be=Mt(n=>n.currentSessionId),He=Yn(a==="turn"?be??"":"",d??void 0),st=tt,g=a==="staged"?!0:a==="working"?!1:null,M=g??$,ie=F||Y<=768,Ge=!!be&&a!=="turn"&&a!=="commit"&&a!=="pr"&&!ie&&!Fe(),X=a!=="turn"&&!ie&&!Fe(),ft=!e&&!ie&&Y>=1024,Ee=i.useRef(null),Le=i.useRef(new Map),pe=i.useRef(null),H=i.useRef(null),R=i.useRef(!1),oe=i.useRef(null),ke=i.useRef(null),Ce=i.useRef(null),dt=i.useRef(null),wt=i.useCallback(()=>{const n=Ee.current;if(!n)return null;const r=n.getBoundingClientRect().top,l=[];for(const[p,y]of Le.current)y&&l.push({path:p,top:y.getBoundingClientRect().top});return Bt(r,l)},[]),$e=i.useCallback(()=>{pe.current=null,R.current=!1,U(null),H.current!==null&&(window.cancelAnimationFrame(H.current),H.current=null)},[]),qe=i.useCallback(n=>{q(r=>{if(r.has(n))return r;const l=new Set(r);return l.add(n),l})},[]),rt=i.useMemo(()=>{for(let n=He.length-1;n>=0;n-=1){const r=He[n];if(r.role==="user")return Fs(r.summary?.diffs)}return[]},[He]),en=i.useMemo(()=>{const n=new Map;for(const r of rt)if(r.file){if(typeof r.patch=="string"){n.set(r.file,yt(r.file,r.patch,"patch"));continue}n.set(r.file,{original:r.before??"",modified:r.after??"",contextMode:"full"})}return n},[rt]),tn=i.useMemo(()=>S?.files?S.files.filter(Kt).length:0,[S]),nn=i.useMemo(()=>S?.files?S.files.filter(_t).length:0,[S]),sn=rt.length,G=S?.current??null,Te=Fn(f??null,G,o&&a==="pr"&&!Fe()),Me=Te.selectedSource,Be=Dn(f??null,G,o&&a==="commit"&&!Fe()),Ie=Be.selectedCommit?.hash??null;i.useEffect(()=>{(a==="commit"||a==="pr")&&Fe()&&(Se("working"),x?.("working"))},[a,x]);const We=ee(n=>f?n.directories.get(f)?.branches??null:null),rn=ee(n=>f?n.directories.get(f)?.isLoadingBranches??!1:!1),on=i.useCallback(()=>{f&&Q(f,w)},[f,Q,w]),an=On(f??null,o&&L!==!1,rn,!!We,on,vs),bt=i.useMemo(()=>{const n=S?.tracking?.trim().split("/")[0];return(n&&We?.defaultBranches?.[n])??We?.defaultBranches?.origin??null},[We,S?.tracking]),jt=!Fe()&&zn(G,bt),ln=S!==null,vt=Fe()||an||_n(G,bt,ln,We!==null),cn=An(n=>n.setOverride),{base:Re,resolved:un,revision:St}=Vn(f??null,G,o&&jt&&a==="branch"),[fn,dn]=i.useState(0);i.useEffect(()=>{const n=Gn(a,!vt);n!==a&&(Se(n),n==="working"&&x?.("working"))},[a,vt,x]);const mn=i.useMemo(()=>a==="pr"?Me:a==="commit"&&Ie?{kind:"commit",hash:Ie}:a==="branch"&&Re&&G?{kind:"branch",baseRef:Re,headRef:G}:null,[a,Re,G,Ie,Me]),D=Kn(f??null,mn,o&&!Fe(),a==="branch"?St:""),{fetchDiff:Nt}=D,kt=a==="commit"?D.files:null,Ct=a==="commit"?D.error:null,at=a==="branch"?D.files:null,Rt=a==="branch"?D.error:null,Ft=D.files?a==="pr"?JSON.stringify([D.key,D.revision]):D.key:null,pn=i.useMemo(()=>a==="branch"||a==="commit"||a==="pr"?Array.from(O).sort().join("\0"):"",[a,O]),hn=i.useCallback(async n=>{try{const r=re&&a!=="pr",l=await Nt(n,r?Xt:xt);return{status:"ready",data:yt(n,l.diff,r?"full":"patch")}}catch(r){return{status:"error",message:r instanceof Error?r.message:c("diffView.state.failedToLoadDiff")}}},[a,Nt,re,c]),gn=Hn(Ft,o?pn:"",Ft?hn:null,zt,JSON.stringify([a==="branch"?St:"",a==="pr"?D.revision:0,fn,re])),xn=at?.length??null,N=i.useMemo(()=>{if(a==="commit"||a==="pr")return(D.files??[]).map(l=>({path:l.path,index:"",working_dir:l.status,insertions:l.insertions,deletions:l.deletions,isNew:l.status==="A"}));if(a==="branch")return(at??[]).map(l=>({path:l.path,index:"",working_dir:l.status,insertions:0,deletions:0,isNew:l.status==="A"})).sort((l,p)=>l.path.localeCompare(p.path));if(a==="turn")return rt.map(l=>({path:l.file??"",index:"",working_dir:Ds(l.status),insertions:l.additions??0,deletions:l.deletions??0,isNew:l.status==="added"})).filter(l=>l.path).sort((l,p)=>l.path.localeCompare(p.path));if(!S?.files)return[];const n=S.diffStats??{},r=a==="staged"?_t:a==="working"?Kt:()=>!0;return S.files.filter(r).map(l=>({...l,insertions:n[l.path]?.insertions??0,deletions:n[l.path]?.deletions??0,isNew:Cs(l)})).sort((l,p)=>l.path.localeCompare(p.path))},[a,at,D.files,rt,S]),mt=i.useMemo(()=>N.map(n=>n.path).join("\0"),[N]);i.useEffect(()=>{const n=mt?mt.split("\0"):[],r=new Set(n),l=`${f??""}:${a}:${s?"collapsed":"default"}`,p=ke.current!==l;ke.current=l,q(y=>{if(p){const I=s?0:js(n.length);return new Set(n.slice(0,I))}let B=!1;const k=new Set;for(const I of y){if(!r.has(I)){B=!0;continue}k.add(I)}return B?k:y}),J(y=>{if(p)return new Set;let B=!1;const k=new Set;for(const I of y){if(!r.has(I)){B=!0;continue}k.add(I)}return B?k:y})},[a,mt,f,s]);const Dt=i.useCallback(()=>{if(oe.current=null,!o)return;const n=Ee.current;if(!n)return;const r=n.getBoundingClientRect(),l=r.top-Ot,p=r.bottom+Ot,y={},B=[];for(const[k,I]of Le.current){if(!I)continue;const Z=I.getBoundingClientRect();B.push({path:k,top:Z.top}),O.has(k)&&(Z.bottom<l||Z.top>p||(y[k]=!0))}Ce.current=Bt(r.top,B),J(k=>{let I=!1;const Z=new Set(k);for(const Lt of Object.keys(y))Z.has(Lt)||(Z.add(Lt),I=!0);return I?Z:k})},[O,o]),ae=i.useCallback(()=>{o&&(typeof window>"u"||oe.current===null&&(oe.current=window.requestAnimationFrame(Dt)))},[Dt,o]);i.useEffect(()=>{const n=Ee.current;if(!(!o||!n))return ae(),n.addEventListener("scroll",ae,{passive:!0}),window.addEventListener("resize",ae),()=>{n.removeEventListener("scroll",ae),window.removeEventListener("resize",ae),oe.current!==null&&(window.cancelAnimationFrame(oe.current),oe.current=null)}},[N,O,ae,o]);const pt=i.useCallback(n=>{const r=Ze[n.path];if(r)return r;if(_e==="inline")return"inline";if(_e==="side-by-side")return"side-by-side";const l=Y<ws;return n.isNew||l?"inline":"side-by-side"},[Ze,_e,Y]),At=i.useMemo(()=>N.length===0?null:N.every(n=>pt(n)==="side-by-side")?"side-by-side":"inline",[N,pt]);i.useEffect(()=>{o&&f&&(ne(f),ce(f,w))},[f,ne,ce,w,o]);const lt=JSON.stringify([E,f]),ht=i.useRef({scope:lt,paths:new Set,dirty:!1}),Vt=i.useRef(o);i.useEffect(()=>{const n=o&&!Vt.current;if(Vt.current=o,ht.current.scope!==lt&&(ht.current={scope:lt,paths:new Set,dirty:!1}),!f)return;const r=p=>{p?.length&&(dt.current=wt()??Ce.current,W(f,p),ut(y=>{const B=new Map(y);for(const k of p)B.set(k,(B.get(k)??0)+1);return B})),ue(f,w,{silent:!0})},l=ht.current;return o&&(n||l.dirty)&&(r([...l.paths]),l.paths.clear(),l.dirty=!1),qt.onGitRefreshHint(p=>{if(Ht(p.directory)===Ht(f)){if(!o){l.dirty=!0;for(const y of p.paths??[])l.paths.add(y);return}r(p.paths)}})},[wt,W,f,ue,w,lt,o]),i.useLayoutEffect(()=>{const n=dt.current;if(!n)return;dt.current=null;const r=Ee.current,l=Le.current.get(n.path);if(!r||!l)return;const p=r.getBoundingClientRect().top,y=l.getBoundingClientRect().top-p;r.scrollTop=ys(r.scrollTop,n.topOffset,y,r.scrollHeight-r.clientHeight),Ce.current=n},[ye]),i.useEffect(()=>{!o||a!=="all"&&!Ne||z&&(Ne&&Se(Ne),A(z),K(Ne==="staged"||!Ne&&me),ot(null),R.current=!0,pe.current=z,qe(z),Ae(n=>n+1))},[a,qe,z,Ne,me,ot,o]),i.useEffect(()=>{if(a==="all")return;const n=j?.trim();n&&(A(n),K(a==="staged"),R.current=!0,pe.current=n,qe(n),Ae(r=>r+1))},[a,qe,j]),i.useEffect(()=>{if(!T)return;N.some(r=>r.path===T)||(A(null),K(!1))},[N,T]);const yn=i.useCallback((n,r)=>{const l=Le.current;r?l.set(n,r):l.delete(n),ae()},[ae]),wn=i.useCallback((n,r)=>{$e(),q(l=>{const p=l.has(n);if(r===p)return l;const y=new Set(l);return r?y.add(n):y.delete(n),y}),r||J(l=>{if(!l.has(n))return l;const p=new Set(l);return p.delete(n),p}),ae()},[$e,ae]),bn=i.useCallback(()=>{$e(),q(n=>n.size>0?new Set:new Set(N.map(r=>r.path))),J(new Set),ae()},[$e,N,ae]),jn=i.useCallback(async n=>{if(!be)return;const r=Mt.getState().getDirectoryForSession(be)||d||"";if(!r){Je.error(c("diffView.reviewDialog.toast.noSessionDirectory"));return}we(!0);try{await Qn({originalSessionID:be,directory:r,providerID:n.providerID,modelID:n.modelID,agent:n.agent||void 0,variant:n.variant||void 0,generateHandoff:n.generateHandoff,returnAfterHandoffRequest:n.generateHandoff,autoReview:n.autoReview}),ze(!1)}catch(l){console.error("[review-flow] failed to start review flow",l),Je.error(l instanceof Error?l.message:c("diffView.reviewDialog.toast.startFailed"))}finally{we(!1)}},[be,d,c]),ct=i.useCallback(n=>{const r=Le.current.get(n),l=Ee.current;if(!r||!l)return!1;const p=r.getBoundingClientRect().top-l.getBoundingClientRect().top;return l.scrollTo({top:l.scrollTop+p,behavior:"auto"}),!0},[]);i.useEffect(()=>{const n=pe.current;if(!o||!n)return;let r=0;const l=20;let p=!1;const y=(k=!0)=>{p||(p=!0,pe.current=null,R.current=!1,k&&U(null),H.current!==null&&(window.cancelAnimationFrame(H.current),H.current=null))},B=()=>{if(p){H.current=null;return}const k=pe.current;if(!k){y(),H.current=null;return}if(!ct(k)){r+=1,r<l?H.current=window.requestAnimationFrame(B):(y(),H.current=null);return}if(u&&R.current){U(k),y(!1);return}y()};return H.current=window.requestAnimationFrame(B),()=>{p=!0,H.current!==null&&(window.cancelAnimationFrame(H.current),H.current=null)}},[u,it,ct,o]);const vn=i.useCallback(n=>{},[]),gt=i.useCallback(n=>{$e(),A(n),K(!1),R.current=!0,pe.current=n,qe(n),Ae(r=>r+1),ct(n)},[$e,qe,ct]);i.useEffect(()=>{const n=r=>{if(!o||!r.altKey||r.metaKey||r.ctrlKey||r.shiftKey||r.key!=="ArrowDown"&&r.key!=="ArrowUp")return;const l=r.target;if(l instanceof HTMLElement&&(l.isContentEditable||l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.closest('[role="dialog"]'))||N.length===0)return;const p=r.key==="ArrowDown"?1:-1,y=T?N.findIndex(I=>I.path===T):-1,B=y===-1?p>0?0:N.length-1:y+p,k=N[B];k&&(r.preventDefault(),gt(k.path))};return window.addEventListener("keydown",n),()=>window.removeEventListener("keydown",n)},[N,T,gt,o]);const Sn=i.useCallback(n=>{const r=n==="side-by-side"?"side-by-side":"inline";N.forEach(l=>{et(l.path,r)})},[N,et]),[Nn,Et]=i.useState(null),kn=i.useCallback(async(n,r)=>{if(!f||!n)return;Et(n);const l=De();try{let p=null;if(r?.patch&&!r.isBinary&&!Xe(n)?p=It(r.patch):r&&r.contextMode==="full"&&!r.isBinary&&!Xe(n)&&(p=Gt(r.original,r.modified)),p===null)try{const Z=await w.getGitDiff(f,{path:n,staged:M,contextLines:3});p=It(Z.diff)}catch{p=null}let y=r;if(p===null||!y){const Z=await w.getGitFileDiff(f,{path:n,staged:M});y={original:Z.original??"",modified:Z.modified??"",isBinary:Z.isBinary},M||fe(f,n,y,l)}const B=p??(y.isBinary||Xe(n)?1:Gt(y.original,y.modified)),k=Rs(f,n),I=await ms(v,k,{directory:f});if(!I.ok){Je.error(ps(I.reason));return}nt(f,k,B,1)}finally{Et(p=>p===n?null:p)}},[M,f,v,w,nt,fe]),Cn=()=>{if(!f)return null;const n=r=>g!==null?g:$&&r===T;return t.jsxs("div",{className:je("flex min-w-0 flex-1 min-h-0 h-full",C?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[ft&&t.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[t.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:c("diffView.section.files")}),t.jsx("span",{className:"typography-meta text-muted-foreground",children:N.length})]}),t.jsx(Vs,{changedFiles:N,selectedFile:null,onSelectFile:gt})]}),t.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:t.jsx(Jt,{ref:Ee,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:t.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:N.map(r=>t.jsx(Ts,{visible:o,directory:f,file:r,layout:pt(r),wrapLines:st,isSelected:!1,isExpanded:O.has(r.path),isMounted:ve.has(r.path)||r.path===de,onSelect:vn,onExpandedChange:wn,registerSectionRef:yn,showOpenInEditorAction:h&&a!=="turn",isOpeningInEditor:Nn===r.path,onOpenInEditor:(l,p)=>{kn(l,p)},staged:n(r.path),loadFullFiles:re&&a!=="pr",readOnlyActions:a==="branch"||a==="commit"||a==="pr",hunkActionsEnabled:a==="all"||a==="working"||a==="staged",comparisonDiff:a==="branch"||a==="commit"||a==="pr"?gn.get(r.path)??zt:void 0,onRetryComparisonDiff:()=>dn(l=>l+1),initialDiffData:a==="turn"?en.get(r.path)??null:null},`${De()}:${f}:${r.path}:${ye.get(r.path)??0}`))})})})]})},Rn=()=>{if(!f)return t.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:c("diffView.state.selectSessionDirectory")});if(a!=="turn"&&te&&!S)return t.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[t.jsx(V,{name:"loader-4",className:"size-4 animate-spin"}),c("diffView.state.loadingRepositoryStatus")]});if(a!=="turn"&&L===!1)return t.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:c("diffView.state.notGitRepository")});if(a==="pr"){if(!Me||D.error)return t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:D.error??Te.error??(Te.loading?c("session.githubPrPicker.loading.pullRequests"):c("pullRequestComparison.select"))}),(D.error||Te.error)&&t.jsx(he,{variant:"outline",size:"sm",onClick:()=>{Me?D.refresh():Te.refresh()},children:c("diffView.actions.retry")}),!Me&&!Te.loading&&t.jsx(Tt,{comparison:Te})]});if(!D.files)return t.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 typography-meta text-muted-foreground",children:[t.jsx(V,{name:"loader-4",className:"size-4 animate-spin"}),c("diffView.state.loadingDiff")]})}if(a==="commit"){if(Ct)return t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center",children:[t.jsx("p",{className:"typography-meta text-muted-foreground",children:Ct}),t.jsx(he,{variant:"outline",size:"sm",onClick:()=>{D.refresh()},children:c("diffView.actions.retry")})]});if(!Ie&&!Be.loading)return t.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:Be.error??c("commitComparison.noCommits")});if(!kt)return t.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[t.jsx(V,{name:"loader-4",className:"size-4 animate-spin"}),c("diffView.state.loadingDiff")]})}if(a==="branch"){if(!un)return t.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[t.jsx(V,{name:"loader-4",className:"size-4 animate-spin"}),c("diffView.branch.resolvingBase")]});if(!Re)return t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[t.jsx(V,{name:"git-branch",className:"size-6 text-muted-foreground"}),t.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:c("diffView.branch.noBaseTitle")}),t.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:c("gitView.pr.toast.baseBranchRequired")})]});if(Rt)return t.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[t.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:c("diffView.branch.loadError")}),t.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:Rt}),t.jsx(he,{variant:"outline",size:"sm",onClick:()=>{D.refresh()},children:c("diffView.actions.retry")})]});if(at===null)return t.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[t.jsx(V,{name:"loader-4",className:"size-4 animate-spin"}),c("diffView.branch.loadingFiles")]})}return N.length===0?t.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:a==="turn"?c("diffView.state.noLastTurnChanges"):a==="pr"?c("walkthrough.blocked.emptyDiff.description"):a==="commit"?c("commitComparison.emptyDiff"):a==="branch"&&Re?c("diffView.branch.empty",{base:us(Re)}):c("diffView.state.cleanWorkingTree")}):Cn()};return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[t.jsxs("div",{className:"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[b===!1&&Array.isArray(P)&&P.length>0?t.jsx(cs,{repositories:P,selectedRepository:_??null,onSelectRepository:n=>{d&&se(d,n)},repositoryRoot:d??void 0}):null,!F&&(a!=="all"?t.jsx(As,{scope:a,workingCount:tn,stagedCount:nn,turnCount:sn,branchCount:xn,commitCount:a==="commit"?kt?.length??null:null,prCount:a==="pr"?D.files?.length??null:null,showCommitOption:!Fe(),showBranchOption:jt,onScopeChange:n=>{Se(n),x?.(n)}}):t.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:t.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:te&&!S?c("diffView.state.loadingChanges"):N.length===1?c("diffView.summary.changedFilesSingle",{count:N.length}):c("diffView.summary.changedFilesPlural",{count:N.length})})})),a==="branch"&&t.jsx(En,{branches:We?.all??[],currentBranch:G,base:Re,onSelect:n=>{f&&G&&cn(f,G,n)}},JSON.stringify([f,G])),a==="commit"&&t.jsx(Ln,{commits:Be.commits,selectedHash:Ie,loading:Be.loading,error:Be.error,onSelect:Be.select,onRefresh:()=>{Be.refresh()}},JSON.stringify([f,G])),a==="pr"&&t.jsxs(t.Fragment,{children:[t.jsx(Tt,{comparison:Te},JSON.stringify([E,f,G])),Me&&t.jsx(he,{variant:"ghost",size:"sm",disabled:D.loading,"aria-label":c("session.githubIssuePicker.actions.refresh"),title:c("session.githubIssuePicker.actions.refresh"),onClick:()=>{D.refresh()},children:t.jsx(V,{name:"refresh",className:"size-4"})})]}),N.length>0&&t.jsxs(he,{variant:"ghost",size:"sm",onClick:bn,className:je("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:O.size>0?c("diffView.actions.collapseAll"):c("diffView.actions.expandAll"),children:[t.jsx(V,{name:"expand-up-down",className:"size-4"}),t.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:O.size>0?c("diffView.actions.collapseAll"):c("diffView.actions.expandAll")})]}),N.length>0&&Ge&&t.jsxs(he,{variant:"default",size:"sm",onClick:()=>ze(!0),disabled:Ve,className:"diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2","aria-label":c("diffView.actions.reviewAria"),children:[Ve?t.jsx(V,{name:"loader-4",className:"size-4 animate-spin"}):t.jsx(V,{name:"search-eye",className:"size-4"}),t.jsx("span",{className:"diff-toolbar__review-label typography-ui-label",children:c("diffView.actions.review")})]}),N.length>0&&X&&t.jsxs(he,{variant:"outline",size:"sm",onClick:()=>{const n=f??"";xe(n,a==="pr"&&Me?Me:a==="commit"&&Ie?{kind:"commit",hash:Ie}:a==="branch"&&Re&&G?{kind:"branch",baseRef:Re,headRef:G}:{kind:"working-tree",scope:a==="staged"||a==="working"?a:"all"}),ge(d??n,"walkthrough")},className:je("diff-toolbar__walkthrough-button h-7 flex-shrink-0 gap-1.5 px-2",hs),"aria-label":c("walkthrough.action.open"),children:[t.jsx(V,{name:"route",className:"size-4"}),t.jsx("span",{className:"diff-toolbar__walkthrough-label typography-ui-label",children:c("walkthrough.action.open")})]}),N.length>0&&a!=="pr"&&t.jsxs(Zn,{children:[t.jsx(es,{asChild:!0,children:t.jsx(he,{variant:"ghost",size:"sm",onClick:()=>Qe(n=>!n),"aria-pressed":re,"aria-label":c(re?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles"),className:je("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",re&&"bg-interactive-selection text-interactive-selection-foreground"),children:t.jsx(V,{name:"file-download",className:"size-4"})})}),t.jsx(ts,{children:t.jsx("p",{children:c(re?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles")})})]}),N.length>0&&t.jsx(he,{variant:"ghost",size:"sm",onClick:()=>Ke(!tt),className:je("h-5 w-5 p-0 transition-opacity",st?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:c(st?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:t.jsx(V,{name:"text-wrap",className:"size-4"})}),At&&t.jsx(Wt,{mode:At==="side-by-side"?"side-by-side":"unified",onModeChange:Sn})]}),t.jsx(ns,{open:Oe,onOpenChange:ze,projectDirectory:f??null,submitting:Ve,onConfirm:jn}),Rn()]})};export{Yi as DiffView,Ts as MultiFileDiffEntry};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{R as N,f as oe,j as s}from"./vendor-react-BUCujlKS.js";import{u as ze}from"./vendor-tanstack-react-virtual-g05Cx3z9.js";import{f as J,aw as Ee,a9 as be,aa as ye,I as E,ab as we,h as Z,B as Y,a4 as Te,hn as Ie,bN as fe,bO as ue,bP as pe,bQ as ge,bR as xe,bS as ve,bd as Me,c9 as Re,t as ae}from"./useAppFontEffects-DQXEYu1N.js";import{u as ke}from"./index-zzfsbdBe.js";const Se={"?":{code:"?",color:"var(--status-info)",description:"Untracked file"},A:{code:"A",color:"var(--status-success)",description:"New file"},D:{code:"D",color:"var(--status-error)",description:"Deleted file"},R:{code:"R",color:"var(--status-info)",description:"Renamed file"},C:{code:"C",color:"var(--status-info)",description:"Copied file"},M:{code:"M",color:"var(--status-warning)",description:"Modified file"}},Pe=Se.M;function Fe(p){const e=p.index?.trim(),t=p.working_dir?.trim();return e&&e!=="?"?e.charAt(0):t?t.charAt(0):e?.charAt(0)||t?.charAt(0)||"M"}function He(p){const e=Fe(p);return Se[e]??Pe}const $e=N.memo(function(e){const t=oe.c(58),{file:r,actionLabel:w,actionSymbol:x,onAction:g,onViewDiff:d,onRevert:a,isReverting:h,stats:S,rowPaddingClassName:f,indentPx:b,actionAtStart:V,showRevert:k}=e,v=b===void 0?0:b,o=V===void 0?!1:V,j=k===void 0?!0:k;let c;t[0]!==r?(c=He(r),t[0]=r,t[1]=c):c=t[1];const u=c,{t:I}=J(),H=u.description,P=S?.insertions??0,A=S?.deletions??0;let z;t[2]!==g||t[3]!==d?(z=U=>{U.key===" "?(U.preventDefault(),g()):U.key==="Enter"&&(U.preventDefault(),d())},t[2]=g,t[3]=d,t[4]=z):z=t[4];const T=z;let M;t[5]!==g?(M=U=>{U.preventDefault(),U.stopPropagation(),g()},t[5]=g,t[6]=M):M=t[6];const y=M;let $;t[7]!==a?($=U=>{U.preventDefault(),U.stopPropagation(),a()},t[7]=a,t[8]=$):$=t[8];const W=$;let L;t[9]!==w||t[10]!==x||t[11]!==y?(L=s.jsx("button",{type:"button",onClick:y,className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":w,title:w,children:x}),t[9]=w,t[10]=x,t[11]=y,t[12]=L):L=t[12];const F=L,X=`group flex items-center gap-2 py-1.5 cursor-pointer ${f??"px-3"}`;let R;t[13]!==v?(R=v>0?{paddingLeft:`${v}px`}:void 0,t[13]=v,t[14]=R):R=t[14];const q=o?F:null;let K;t[15]!==u.color?(K={color:u.color},t[15]=u.color,t[16]=K):K=t[16];let O;t[17]!==u.code||t[18]!==H||t[19]!==K?(O=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:K,title:H,"aria-label":H,children:u.code}),t[17]=u.code,t[18]=H,t[19]=K,t[20]=O):O=t[20];let G;t[21]!==r.path?(G=s.jsx(Ee,{filePath:r.path,className:"h-3.5 w-3.5 shrink-0"}),t[21]=r.path,t[22]=G):G=t[22];let _;if(t[23]!==r.path){e:{const U=r.path.lastIndexOf("/");if(U===-1){let ne;t[25]===Symbol.for("react.memo_cache_sentinel")?(ne={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},t[25]=ne):ne=t[25],_=s.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:ne,title:r.path,children:r.path});break e}const Ae=r.path.slice(0,U),De=r.path.slice(U);let te;t[26]===Symbol.for("react.memo_cache_sentinel")?(te={direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},t[26]=te):te=t[26];let se;t[27]===Symbol.for("react.memo_cache_sentinel")?(se=s.jsx("span",{className:"text-muted-foreground",children:"/"}),t[27]=se):se=t[27];const ce=s.jsx("span",{className:"text-foreground",children:De.slice(1)});let ie;t[28]!==ce?(ie=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[se,ce]}),t[28]=ce,t[29]=ie):ie=t[29],_=s.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:r.path,children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:te,children:Ae}),ie]})}t[23]=r.path,t[24]=_}else _=t[24];let Q;t[30]===Symbol.for("react.memo_cache_sentinel")?(Q={color:"var(--status-success)"},t[30]=Q):Q=t[30];let i;t[31]!==P?(i=s.jsxs("span",{style:Q,children:["+",P]}),t[31]=P,t[32]=i):i=t[32];let n,l;t[33]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),l={color:"var(--status-error)"},t[33]=n,t[34]=l):(n=t[33],l=t[34]);let m;t[35]!==A?(m=s.jsxs("span",{style:l,children:["-",A]}),t[35]=A,t[36]=m):m=t[36];let D;t[37]!==i||t[38]!==m?(D=s.jsxs("span",{className:"shrink-0 typography-micro",children:[i,n,m]}),t[37]=i,t[38]=m,t[39]=D):D=t[39];let C;t[40]!==r.path||t[41]!==W||t[42]!==h||t[43]!==j||t[44]!==I?(C=j?s.jsxs(be,{children:[s.jsx(ye,{asChild:!0,children:s.jsx("button",{type:"button",onClick:W,disabled:h,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-50","aria-label":I("gitView.changes.revertFileAria",{path:r.path}),children:h?s.jsx(E,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(E,{name:"arrow-go-back",className:"size-3.5"})})}),s.jsx(we,{sideOffset:8,children:I("gitView.changes.revertFileTooltip")})]}):null,t[40]=r.path,t[41]=W,t[42]=h,t[43]=j,t[44]=I,t[45]=C):C=t[45];const B=o?null:F;let ee;return t[46]!==T||t[47]!==d||t[48]!==R||t[49]!==q||t[50]!==O||t[51]!==G||t[52]!==_||t[53]!==D||t[54]!==C||t[55]!==B||t[56]!==X?(ee=s.jsxs("div",{className:X,role:"button",tabIndex:0,onClick:d,onKeyDown:T,style:R,children:[q,O,G,_,D,C,B]}),t[46]=T,t[47]=d,t[48]=R,t[49]=q,t[50]=O,t[51]=G,t[52]=_,t[53]=D,t[54]=C,t[55]=B,t[56]=X,t[57]=ee):ee=t[57],ee}),je=14,Ve=p=>p.replace(/\\/g,"/").replace(/^\/+/,"").trim(),Ne=(p,e)=>({id:`dir:${p}`,path:p,name:e,children:new Map,directFiles:[],files:[]}),Le=p=>{const e=Ne("","");for(const t of p){const r=Ve(t.path);if(!r)continue;const x=r.split("/").filter(Boolean).slice(0,-1);let g=e;if(g.files.push(t),x.length>0){let d="";for(const a of x){d=d?`${d}/${a}`:a;const h=g.children.get(a);if(h){h.files.push(t),g=h;continue}const S=Ne(d,a);S.files.push(t),g.children.set(a,S),g=S}}g.directFiles.push(t)}return e},Oe=(p,e)=>{const t=[],r=(w,x)=>{const g=Array.from(w.children.values()).sort((a,h)=>a.path.localeCompare(h.path));for(const a of g)t.push({key:a.id,kind:"directory",depth:x,directory:a}),e.has(a.path)&&r(a,x+1);const d=[...w.directFiles].sort((a,h)=>a.path.localeCompare(h.path));for(const a of d)t.push({key:`file:${Ve(a.path)}`,kind:"file",depth:x,file:a})};return r(p,0),t},Ge=1e3,Ce=34,de=30,le="pl-0 pr-2",me=(p,e)=>`${p} ${e}`,Qe=({groups:p,diffStats:e,revertingPaths:t,isRevertingAll:r=!1,headerBackgroundClassName:w="bg-sidebar",onVisiblePathsChange:x,onRevertAll:g,onRevertDirectory:d})=>{const{t:a}=J(),h=N.useRef(null),f=ke(i=>i.gitChangesViewMode)==="tree",b=N.useMemo(()=>p.filter(i=>i.entries.length>0),[p]),[V,k]=N.useState(new Set),[v,o]=N.useState(new Set),[j,c]=N.useState(!1),[u,I]=N.useState(null),H=N.useMemo(()=>b.map(i=>Le(i.entries)),[b]),P=N.useMemo(()=>{const i=[];return b.forEach((n,l)=>{Array.from(H[l]?.children.values()??[]).forEach(m=>{i.push(me(n.id,m.path))})}),i},[H,b]);N.useEffect(()=>{f&&o(i=>{const n=new Set,l=new Set(P);return i.forEach(m=>{(m.slice(m.indexOf(" ")+1).includes("/")||l.has(m))&&n.add(m)}),P.forEach(m=>n.add(m)),n})},[f,P]);const A=N.useMemo(()=>{const i=[];return b.forEach((n,l)=>{if(i.push({type:"header",key:`header:${n.id}`,groupIndex:l}),!V.has(n.id)){if(f){const m=new Set;v.forEach(C=>{C.startsWith(`${n.id} `)&&m.add(C.slice(n.id.length+1))}),Oe(H[l],m).forEach(C=>{C.kind==="file"?i.push({type:"file",key:`${n.id}:${C.key}`,groupIndex:l,file:C.file,depth:C.depth}):i.push({type:"directory",key:`${n.id}:${C.key}`,groupIndex:l,directory:C.directory,depth:C.depth})});return}n.entries.forEach(m=>{i.push({type:"file",key:`${n.id}:file:${m.path}`,groupIndex:l,file:m,depth:0})})}}),g&&b.length>0&&i.push({type:"revert-all",key:"revert-all"}),i},[V,v,f,g,H,b]),z=A.length,T=z>=Ge,M=ze({count:z,enabled:T,getScrollElement:()=>h.current,estimateSize:()=>Ce,overscan:12,getItemKey:i=>A[i]?.key??i}),y=M.getVirtualItems(),$=N.useMemo(()=>{if(!T)return 0;const i=h.current?.scrollTop??0;return y.find(l=>l.end>i)?.index??0},[T,y,h]);N.useEffect(()=>{if(!x)return;const i=n=>n&&n.type==="file"?n.file.path:null;if(z===0){x([]);return}if(!T){const n=[];for(const l of A)if(l.type==="file"&&(n.push(l.file.path),n.length>=de))break;x(n);return}x(A.slice($,$+Math.ceil((h.current?.clientHeight??0)/Ce)+de).map(n=>i(n)).filter(n=>!!n).slice(0,de))},[x,z,A,T,$]);const W=N.useCallback(i=>{k(n=>{const l=new Set(n);return l.has(i)?l.delete(i):l.add(i),l})},[]),L=N.useCallback((i,n)=>{o(l=>{const m=new Set(l),D=me(i,n);return m.has(D)?m.delete(D):m.add(D),m})},[]),F=N.useMemo(()=>{const i=new Set;return b.forEach(n=>n.entries.forEach(l=>i.add(l.path))),Array.from(i)},[b]),X=F.length,R=u?r||u.paths.some(i=>t.has(i)):!1,q=N.useCallback(async()=>{!g||r||F.length===0||(await g(F),c(!1))},[F,r,g]),K=N.useCallback(async()=>{!d||!u||R||(await d(u.paths),I(null))},[R,d,u]),O=N.useCallback((i,n)=>{const l=V.has(i.id),m=i.entries.length;return s.jsxs("div",{className:Z("sticky top-0 z-10 flex items-center gap-2 py-2",w,le,!n&&"mt-1 border-t border-border/40"),children:[s.jsx("button",{type:"button",onClick:()=>i.onActionAll(i.entries.map(D=>D.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":i.actionAllLabel,title:i.actionAllLabel,children:i.actionSymbol}),s.jsxs("button",{type:"button",onClick:()=>W(i.id),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-expanded":!l,children:[s.jsx("h3",{className:"truncate typography-ui-header font-semibold text-foreground",children:i.title}),s.jsx("span",{className:"typography-meta text-muted-foreground",children:m}),s.jsx(E,{name:"arrow-down-s",className:Z("size-3.5 shrink-0 text-muted-foreground transition-transform",l&&"-rotate-90")})]})]})},[V,w,W]),G=N.useCallback((i,n,l)=>{const m=v.has(me(i.id,n.path)),D=n.files.map(B=>B.path),C=r||D.some(B=>t.has(B));return s.jsxs("div",{className:Z("group flex items-center gap-2 py-1.5",le),style:{paddingLeft:`${l*je}px`},children:[s.jsxs("button",{type:"button",onClick:()=>L(i.id,n.path),className:"flex min-w-0 flex-1 items-center gap-2 rounded text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary","aria-label":m?a("gitView.changes.collapseDirectoryAria",{path:n.path}):a("gitView.changes.expandDirectoryAria",{path:n.path}),children:[m?s.jsx(E,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(E,{name:"folder-3-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label text-foreground",title:n.path,children:n.name}),s.jsx("span",{className:"ml-auto shrink-0 typography-micro text-muted-foreground",children:n.files.length})]}),i.showRevertActions!==!1&&d?s.jsx("button",{type:"button",onClick:()=>I({path:n.path,paths:D,count:D.length}),disabled:C,className:"flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)] disabled:cursor-not-allowed disabled:opacity-50","aria-label":a("gitView.changes.revertDirectoryAria",{path:n.path}),title:a("gitView.changes.revertDirectoryTooltip"),children:C?s.jsx(E,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(E,{name:"arrow-go-back",className:"size-3.5"})}):null,s.jsx("button",{type:"button",onClick:()=>i.onActionAll(n.files.map(B=>B.path)),className:"flex size-5 shrink-0 items-center justify-center rounded typography-micro font-semibold text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]","aria-label":a(i.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:n.path}),title:a(i.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:n.path}),children:i.actionSymbol})]})},[v,r,d,t,a,L]),_=N.useCallback((i,n)=>{if(i.type==="revert-all")return s.jsx("div",{className:Z("flex justify-end py-2",le),children:s.jsxs(Y,{variant:"ghost",size:"sm",onClick:()=>c(!0),disabled:r,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[s.jsx(E,{name:"arrow-go-back",className:"size-3.5"}),a("gitView.changes.revertAll")]})});const l=b[i.groupIndex];if(!l)return null;if(i.type==="header")return O(l,n);if(i.type==="directory")return G(l,i.directory,i.depth);const m=i.file;return s.jsx($e,{file:m,actionLabel:l.getActionLabel(m.path),actionSymbol:l.actionSymbol,onAction:()=>l.onActionFile(m.path),stats:e?.[m.path],onViewDiff:()=>l.onViewDiff(m.path),onRevert:()=>l.onRevertFile(m.path),isReverting:t.has(m.path)||r,rowPaddingClassName:le,indentPx:i.depth*je,actionAtStart:!f,showRevert:l.showRevertActions!==!1})},[e,r,f,G,O,t,a,b]),Q=N.useCallback(i=>{const n=A[i],l=A[i-1];return!n||!l||n.type!=="file"&&n.type!=="directory"||l.type!=="file"&&l.type!=="directory"?!1:l.groupIndex===n.groupIndex},[A]);return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"relative flex h-full min-h-0 w-full flex-col overflow-hidden",children:[s.jsx(Te,{ref:h,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:T?s.jsx("div",{style:{height:M.getTotalSize(),position:"relative"},children:y.map(i=>{const n=A[i.index];return n?s.jsx("div",{"data-index":i.index,ref:M.measureElement,style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${i.start}px)`},className:Z(Q(i.index)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:_(n,i.index===0)},n.key):null})}):s.jsx("div",{role:"list","aria-label":a("gitView.changes.changedFilesAria"),children:A.map((i,n)=>s.jsx("div",{className:Z("relative",Q(n)&&"before:pointer-events-none before:absolute before:left-0 before:right-2 before:top-0 before:border-t before:border-border/60"),children:_(i,n===0)},i.key))})}),s.jsx(Ie,{containerRef:h,disableHorizontal:!0})]}),s.jsx(fe,{open:j,onOpenChange:i=>{!r&&!i&&c(!1)},children:s.jsxs(ue,{className:"max-w-md",children:[s.jsxs(pe,{children:[s.jsx(ge,{children:a("gitView.changes.revertAllDialogTitle")}),s.jsx(xe,{children:X===1?a("gitView.changes.revertAllDescriptionSingle",{count:X}):a("gitView.changes.revertAllDescriptionPlural",{count:X})})]}),s.jsxs(ve,{children:[s.jsx(Y,{variant:"outline",size:"sm",onClick:()=>c(!1),disabled:r,children:a("gitView.common.cancel")}),s.jsx(Y,{variant:"destructive",size:"sm",onClick:()=>{q()},disabled:r,children:a(r?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})}),s.jsx(fe,{open:!!u,onOpenChange:i=>{!R&&!i&&I(null)},children:s.jsxs(ue,{className:"max-w-md",children:[s.jsxs(pe,{children:[s.jsx(ge,{children:a("gitView.changes.revertDirectoryDialogTitle")}),s.jsx(xe,{children:u?u.count===1?a("gitView.changes.revertDirectoryDescriptionSingle",{count:u.count,path:u.path}):a("gitView.changes.revertDirectoryDescriptionPlural",{count:u.count,path:u.path}):null})]}),s.jsxs(ve,{children:[s.jsx(Y,{variant:"outline",size:"sm",onClick:()=>I(null),disabled:R,children:a("gitView.common.cancel")}),s.jsx(Y,{variant:"destructive",size:"sm",onClick:()=>{K()},disabled:R||!u,children:a(R?"gitView.changes.reverting":"gitView.changes.revertDirectory")})]})]})})]})},he=38,re=200,Ke=p=>{const e=oe.c(23),{value:t,onChange:r,onSubmit:w,placeholder:x,disabled:g,hasTouchInput:d,isMobile:a}=p,h=g===void 0?!1:g,S=d===void 0?!1:d,f=a===void 0?!1:a,{t:b}=J(),V=N.useRef(null),k=ke(_e);let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=()=>{const y=V.current;if(!y)return;const $=document.activeElement===y,W=()=>{y.style.height=`${he}px`;const F=y.scrollHeight,X=Math.min(Math.max(F,he),re);y.style.height=`${X}px`,y.style.overflowY=F>re?"auto":"hidden",F>re&&!$&&(y.scrollTop=y.scrollHeight)};W();const L=window.requestAnimationFrame(W);return()=>{window.cancelAnimationFrame(L)}},e[0]=v):v=e[0];let o;e[1]!==t?(o=[t],e[1]=t,e[2]=o):o=e[2],N.useLayoutEffect(v,o);let j;e[3]!==r?(j=y=>r(y.target.value),e[3]=r,e[4]=j):j=e[4];let c;e[5]!==w?(c=y=>{y.key==="Enter"&&(y.metaKey||y.ctrlKey)&&!y.shiftKey&&!y.altKey&&(y.preventDefault(),w?.())},e[5]=w,e[6]=c):c=e[6];let u;e[7]!==x||e[8]!==b?(u=x??b("gitView.commit.messagePlaceholder"),e[7]=x,e[8]=b,e[9]=u):u=e[9];const I=S?"on":"off",H=S?"sentences":"off",P=f||k,A=h&&"opacity-50";let z;e[10]!==A?(z=Z("w-full rounded-lg border border-border/60 bg-surface-elevated px-3 py-2 typography-ui-label text-foreground placeholder:text-muted-foreground","resize-none outline-none transition-[border-color,box-shadow] duration-150","focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",A),e[10]=A,e[11]=z):z=e[11];let T;e[12]===Symbol.for("react.memo_cache_sentinel")?(T={minHeight:he,maxHeight:re},e[12]=T):T=e[12];let M;return e[13]!==h||e[14]!==H||e[15]!==P||e[16]!==z||e[17]!==j||e[18]!==c||e[19]!==u||e[20]!==I||e[21]!==t?(M=s.jsx("textarea",{ref:V,value:t,onChange:j,onKeyDown:c,placeholder:u,rows:1,disabled:h,autoCorrect:I,autoCapitalize:H,spellCheck:P,className:z,style:T}),e[13]=h,e[14]=H,e[15]=P,e[16]=z,e[17]=j,e[18]=c,e[19]=u,e[20]=I,e[21]=t,e[22]=M):M=e[22],M};function _e(p){return p.inputSpellcheckEnabled}const Be=p=>{const e=oe.c(30),{highlights:t,onInsert:r}=p,{t:w}=J();if(t.length===0)return null;let x;e[0]!==t||e[1]!==r?(x=()=>{r(t)},e[0]=t,e[1]=r,e[2]=x):x=e[2];const g=x;let d;e[3]!==w?(d=w("gitView.commit.aiHighlights.title"),e[3]=w,e[4]=d):d=e[4];let a;e[5]!==d?(a=s.jsx("p",{className:"typography-micro text-muted-foreground",children:d}),e[5]=d,e[6]=a):a=e[6];let h;e[7]!==w?(h=w("gitView.commit.aiHighlights.insertAria"),e[7]=w,e[8]=h):h=e[8];let S;e[9]===Symbol.for("react.memo_cache_sentinel")?(S=s.jsx(E,{name:"arrow-down",className:"size-4"}),e[9]=S):S=e[9];let f;e[10]!==g||e[11]!==h?(f=s.jsx(ye,{asChild:!0,children:s.jsx(Y,{variant:"ghost",size:"icon",className:"size-6",onClick:g,"aria-label":h,children:S})}),e[10]=g,e[11]=h,e[12]=f):f=e[12];let b;e[13]!==w?(b=w("gitView.commit.aiHighlights.insertTooltip"),e[13]=w,e[14]=b):b=e[14];let V;e[15]!==b?(V=s.jsx(we,{sideOffset:8,children:b}),e[15]=b,e[16]=V):V=e[16];let k;e[17]!==f||e[18]!==V?(k=s.jsxs(be,{children:[f,V]}),e[17]=f,e[18]=V,e[19]=k):k=e[19];let v;e[20]!==a||e[21]!==k?(v=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[a,k]}),e[20]=a,e[21]=k,e[22]=v):v=e[22];let o;e[23]!==t?(o=t.map(Ue),e[23]=t,e[24]=o):o=e[24];let j;e[25]!==o?(j=s.jsx("ul",{className:"space-y-1",children:o}),e[25]=o,e[26]=j):j=e[26];let c;return e[27]!==v||e[28]!==j?(c=s.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[v,j]}),e[27]=v,e[28]=j,e[29]=c):c=e[29],c};function Ue(p,e){return s.jsx("li",{className:"typography-meta text-foreground",children:p},`${p}-${e}`)}const Ze=p=>{const e=oe.c(80),{stagedCount:t,commitMessage:r,onCommitMessageChange:w,generatedHighlights:x,onInsertHighlights:g,onGenerateMessage:d,isGeneratingMessage:a,onCommit:h,onCommitAndPush:S,commitAction:f,hasPendingIndexMutation:b,gitmojiEnabled:V,onOpenGitmojiPicker:k}=p,v=b===void 0?!1:b,{t:o}=J(),j=t>0;let c;e[0]!==f||e[1]!==r||e[2]!==v||e[3]!==j?(c=r.trim()&&j&&f===null&&!v,e[0]=f,e[1]=r,e[2]=v,e[3]=j,e[4]=c):c=e[4];const u=c,{isMobile:I,hasTouchInput:H}=Me();let P;e[5]!==o?(P=o("gitView.commit.title"),e[5]=o,e[6]=P):P=e[6];let A;e[7]!==P?(A=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:P}),e[7]=P,e[8]=A):A=e[8];let z;e[9]!==j||e[10]!==o?(z=j?null:s.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:o("gitView.commit.stageFilesHint")}),e[9]=j,e[10]=o,e[11]=z):z=e[11];let T;e[12]!==A||e[13]!==z?(T=s.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[A,z]}),e[12]=A,e[13]=z,e[14]=T):T=e[14];let M;e[15]!==x||e[16]!==g?(M=s.jsx(Be,{highlights:x,onInsert:g}),e[15]=x,e[16]=g,e[17]=M):M=e[17];let y;e[18]!==u||e[19]!==a||e[20]!==h?(y=()=>{u&&!a&&h()},e[18]=u,e[19]=a,e[20]=h,e[21]=y):y=e[21];let $;e[22]!==o?($=o("gitView.commit.messagePlaceholder"),e[22]=o,e[23]=$):$=e[23];const W=f!==null;let L;e[24]!==r||e[25]!==H||e[26]!==I||e[27]!==w||e[28]!==W||e[29]!==y||e[30]!==$?(L=s.jsx(Ke,{value:r,onChange:w,onSubmit:y,placeholder:$,disabled:W,hasTouchInput:H,isMobile:I}),e[24]=r,e[25]=H,e[26]=I,e[27]=w,e[28]=W,e[29]=y,e[30]=$,e[31]=L):L=e[31];let F;e[32]!==V||e[33]!==k||e[34]!==o?(F=V&&s.jsxs(Y,{variant:"outline",size:"sm",onClick:k,className:"w-fit",type:"button",children:[s.jsx(E,{name:"emotion-happy",className:"size-4"}),o("gitView.commit.addGitmoji")]}),e[32]=V,e[33]=k,e[34]=o,e[35]=F):F=e[35];const X=a||f!==null||v||t===0;let R;e[36]!==o?(R=o("gitView.commit.generateAria"),e[36]=o,e[37]=R):R=e[37];let q;e[38]!==a?(q=a?s.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(E,{name:"ai-generate-2",className:"size-4 text-primary"}),e[38]=a,e[39]=q):q=e[39];let K;e[40]!==o?(K=o("gitView.commit.generate"),e[40]=o,e[41]=K):K=e[41];let O;e[42]!==K?(O=s.jsx("span",{className:"commit-actions__label",children:K}),e[42]=K,e[43]=O):O=e[43];let G;e[44]!==d||e[45]!==X||e[46]!==R||e[47]!==q||e[48]!==O?(G=s.jsxs(Y,{variant:"outline",size:"sm",onClick:d,disabled:X,type:"button","aria-label":R,className:"commit-actions__btn",children:[q,O]}),e[44]=d,e[45]=X,e[46]=R,e[47]=q,e[48]=O,e[49]=G):G=e[49];let _;e[50]===Symbol.for("react.memo_cache_sentinel")?(_=s.jsx("div",{className:"flex-1"}),e[50]=_):_=e[50];const Q=!u||a;let i;e[51]!==o?(i=o("gitView.commit.commitAria"),e[51]=o,e[52]=i):i=e[52];let n;e[53]!==f||e[54]!==o?(n=f==="commit"?s.jsxs(s.Fragment,{children:[s.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:o("gitView.commit.committing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(E,{name:"git-commit",className:"size-4"}),s.jsx("span",{className:"commit-actions__label",children:o("gitView.commit.commit")})]}),e[53]=f,e[54]=o,e[55]=n):n=e[55];let l;e[56]!==h||e[57]!==Q||e[58]!==i||e[59]!==n?(l=s.jsx(Y,{size:"sm",variant:"outline",onClick:h,disabled:Q,className:"commit-actions__btn whitespace-nowrap","aria-label":i,children:n}),e[56]=h,e[57]=Q,e[58]=i,e[59]=n,e[60]=l):l=e[60];let m;e[61]!==u||e[62]!==f||e[63]!==a||e[64]!==I||e[65]!==S||e[66]!==o?(m=I?s.jsxs(be,{children:[s.jsx(ye,{asChild:!0,children:s.jsx(Y,{variant:"default",size:"sm",onClick:()=>S(),disabled:!u||a,className:"h-7 w-7 p-0","aria-label":o("gitView.commit.pushAria"),children:f==="commitAndPush"?s.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(E,{name:"arrow-up",className:"size-3.5"})})}),s.jsx(we,{side:"top",children:s.jsx("p",{children:o("gitView.commit.push")})})]}):s.jsx(Y,{size:"sm",variant:"default",onClick:()=>S(),disabled:!u||a,className:"commit-actions__btn","aria-label":o("gitView.commit.pushAria"),children:f==="commitAndPush"?s.jsxs(s.Fragment,{children:[s.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:o("gitView.commit.pushing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(E,{name:"arrow-up",className:"size-3.5"}),s.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:o("gitView.commit.push")})]})}),e[61]=u,e[62]=f,e[63]=a,e[64]=I,e[65]=S,e[66]=o,e[67]=m):m=e[67];let D;e[68]!==G||e[69]!==l||e[70]!==m?(D=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[G,_,l,m]}),e[68]=G,e[69]=l,e[70]=m,e[71]=D):D=e[71];let C;e[72]!==L||e[73]!==F||e[74]!==D||e[75]!==M?(C=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[M,L,F,D]}),e[72]=L,e[73]=F,e[74]=D,e[75]=M,e[76]=C):C=e[76];let B;return e[77]!==C||e[78]!==T?(B=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[T,C]}),e[77]=C,e[78]=T,e[79]=B):B=e[79],B},Je=({open:p,onOpenChange:e,targetBranch:t,changedFileCount:r,onCommitAndSwitch:w,onGenerateMessage:x,onRevertAndSwitch:g})=>{const{t:d}=J(),[a,h]=N.useState(""),[S,f]=N.useState(null),[b,V]=N.useState(!1),k=S!==null;N.useEffect(()=>{p||(h(""),V(!1))},[p]);const v=async()=>{f("generate");try{const c=await x();c&&h(c)}catch(c){ae.error(c instanceof Error?c.message:d("gitView.dirtySwitch.actionFailed"))}finally{f(null)}},o=async()=>{f("commit");try{let c=a.trim();if(!c){if(c=(await x()).trim(),!c){ae.error(d("gitView.toast.enterCommitMessage"));return}h(c)}await w(c,b)}catch(c){ae.error(c instanceof Error?c.message:d("gitView.dirtySwitch.actionFailed"))}finally{f(null)}},j=async()=>{f("revert");try{await g()}catch(c){ae.error(c instanceof Error?c.message:d("gitView.dirtySwitch.actionFailed"))}finally{f(null)}};return s.jsx(fe,{open:p,onOpenChange:c=>{k||e(c)},children:s.jsx(ue,{className:"max-w-md w-[calc(100vw-2rem)]",children:s.jsxs("div",{className:"flex flex-col gap-4",children:[s.jsxs(pe,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(E,{name:"alert",className:"size-5 shrink-0 text-[var(--status-warning)]"}),s.jsx(ge,{children:d("gitView.dirtySwitch.title")})]}),s.jsx(xe,{children:r===1?d("gitView.dirtySwitch.descriptionSingle",{branch:t}):d("gitView.dirtySwitch.descriptionPlural",{branch:t,count:r})})]}),s.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border/60 px-3 py-2 focus-within:border-border",children:[s.jsx("input",{value:a,onChange:c=>h(c.target.value),placeholder:d("gitView.commit.messagePlaceholder"),disabled:k,onKeyDown:c=>{c.key==="Enter"&&!k&&(c.preventDefault(),o())},className:"min-w-0 flex-1 bg-transparent typography-meta text-foreground outline-none placeholder:text-muted-foreground"}),s.jsx("button",{type:"button",onClick:()=>{v()},disabled:k,"aria-label":d("gitView.commit.generate"),title:d("gitView.commit.generate"),className:"shrink-0 text-muted-foreground hover:text-foreground disabled:opacity-50",children:S==="generate"?s.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(E,{name:"ai-generate-2",className:"size-4 text-primary"})})]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Re,{checked:b,onChange:V,disabled:k,ariaLabel:d("gitView.dirtySwitch.pushAfterCommit")}),s.jsx("span",{className:"typography-ui-label text-foreground cursor-pointer select-none",onClick:()=>!k&&V(!b),children:d("gitView.dirtySwitch.pushAfterCommit")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-2 pt-1",children:[s.jsxs(Y,{variant:"destructive",size:"sm",onClick:()=>{j()},disabled:k,className:"gap-2",children:[S==="revert"?s.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):null,d("gitView.dirtySwitch.revertAndSwitch")]}),s.jsxs(Y,{variant:"default",size:"sm",onClick:()=>{o()},disabled:k,className:"gap-2",children:[S==="commit"?s.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):null,d("gitView.dirtySwitch.commitAndSwitch")]})]})]})})})};export{Qe as C,Je as D,Ze as a};
|