@openchamber/web 1.21.1 → 1.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-BGj8TJxW.js → CodeMirrorCommentWidgets-BO_2OW4E.js} +1 -1
  2. package/dist/assets/DiffView-CNnDxRmO.js +4 -0
  3. package/dist/assets/DirtyBranchSwitchDialog-jADfXQnR.js +1 -0
  4. package/dist/assets/FilesView-8wdiG2mj.js +17 -0
  5. package/dist/assets/GitView-Cv2xH-S6.js +6 -0
  6. package/dist/assets/{JsonTreeView-CggOsLot.js → JsonTreeView-DUiIpERC.js} +1 -1
  7. package/dist/assets/LinearIssuesView-CoZ7pQN5.js +1 -0
  8. package/dist/assets/MarkdownImageGallery-DffjmciG.js +1 -0
  9. package/dist/assets/MarkdownRendererImpl-DxqdYDAx.js +12 -0
  10. package/dist/assets/OnboardingScreen-CTZe6HZn.js +1 -0
  11. package/dist/assets/{PatchDiff-DJYMUiXA.js → PatchDiff-BymkP9JA.js} +1 -1
  12. package/dist/assets/{PierreDiffViewer-CY2bx_SB.js → PierreDiffViewer-BvwtCxW4.js} +3 -3
  13. package/dist/assets/{PlanView-PkiOY_9H.js → PlanView-C1qvAm7m.js} +3 -3
  14. package/dist/assets/SettingsView-xGONHFGS.js +28 -0
  15. package/dist/assets/{SettingsWindow-oyOm2fHR.js → SettingsWindow-COzgfFxM.js} +1 -1
  16. package/dist/assets/{ToolOutputDialog-lKyeQTPL.js → ToolOutputDialog-Dlhh_-oe.js} +6 -6
  17. package/dist/assets/ToolPartDiffPreview-b9joNtXH.js +8 -0
  18. package/dist/assets/{VirtualizedFileDiff-BP7ebDFF.js → VirtualizedFileDiff-vqW3KKo5.js} +1 -1
  19. package/dist/assets/WalkthroughView-D-HFgdmM.js +4 -0
  20. package/dist/assets/{computeVirtualFileMetrics-CZ0xPeaT.js → computeVirtualFileMetrics-DUnyszhW.js} +1 -1
  21. package/dist/assets/{contextPanelEmbeddedChat-C9abMBTb.js → contextPanelEmbeddedChat-CV-DwAiX.js} +1 -1
  22. package/dist/assets/{de-CEoCz3j6.js → de-Cv_4FoXm.js} +6 -5
  23. package/dist/assets/es-BIWNEbnS.js +16 -0
  24. package/dist/assets/{fr-CS7Csln9.js → fr-SD3OfMHJ.js} +6 -5
  25. package/dist/assets/index-CHUT_bDS.css +1 -0
  26. package/dist/assets/index-DDInLQDd.js +40 -0
  27. package/dist/assets/{index-CaPAjwXQ.js → index-DLiD86ge.js} +1 -1
  28. package/dist/assets/{isDiffPlainText-ZBvDxhVB.js → isDiffPlainText-TNageFjy.js} +1 -1
  29. package/dist/assets/{isFilePlainText-DiLRrkJr.js → isFilePlainText-JPmZOYSp.js} +1 -1
  30. package/dist/assets/{ja-vnwqLcx6.js → ja-D7I9HofF.js} +7 -6
  31. package/dist/assets/{ko-CXuSfZv5.js → ko-BsVJM_PQ.js} +7 -6
  32. package/dist/assets/{main-D5RWr6sJ.js → main-DCB4JgVe.js} +2 -2
  33. package/dist/assets/main-De8Z5w49.js +928 -0
  34. package/dist/assets/markdownCore-BoQVG5-a.js +3 -0
  35. package/dist/assets/{miniChat-CqR3icsk.js → miniChat-BtV7N5OF.js} +2 -2
  36. package/dist/assets/{mobile-RN_UTTlB.js → mobile-DZV_sfX7.js} +2 -2
  37. package/dist/assets/{patchFileDiff-CjRR5ESs.js → patchFileDiff-Chmiz6hq.js} +4 -4
  38. package/dist/assets/{pl-BJxry0Mi.js → pl-XR9Bs8Be.js} +6 -5
  39. package/dist/assets/pt-BR-Due4be8g.js +16 -0
  40. package/dist/assets/{renderElectronMiniChatApp-1wC94fQK.js → renderElectronMiniChatApp-8tXADjfl.js} +2 -2
  41. package/dist/assets/renderMobileApp-Cji7Hma5.js +25 -0
  42. package/dist/assets/runtimeEndpointReset-gWt3Lb5D.js +16 -0
  43. package/dist/assets/scheduledTasksApi-9e-UX6im.js +1 -0
  44. package/dist/assets/{shikiHighlight-fGmFkxAM.js → shikiHighlight-CRpCl7UT.js} +1 -1
  45. package/dist/assets/tr-DBJcAv4y.js +7 -0
  46. package/dist/assets/uk-COYh2BaN.js +16 -0
  47. package/dist/assets/{useAppFontEffects-KP8_yiGW.js → useAppFontEffects-CCgvcQ6u.js} +178 -170
  48. package/dist/assets/useInlineCommentController-BkfXnjNZ.js +2 -0
  49. package/dist/assets/useRootScrollLock-KzOUytpn.js +1 -0
  50. package/dist/assets/{vendor-codemirror-language-data-DrTPkHl4.js → vendor-codemirror-language-data-BxpoC5Fp.js} +2 -2
  51. package/dist/assets/vendor-zod-DVWEh-IS.js +39 -0
  52. package/dist/assets/{web-components-DOXvU-tB.js → web-components-B6QgbmTo.js} +4 -4
  53. package/dist/assets/zh-CN-Cjk6lzhc.js +16 -0
  54. package/dist/assets/{zh-TW-Dv8yyhN1.js → zh-TW-Dk0dOg03.js} +6 -5
  55. package/dist/index.html +5 -5
  56. package/dist/mini-chat.html +4 -4
  57. package/dist/mobile.html +4 -4
  58. package/package.json +2 -2
  59. package/server/index.js +35 -4
  60. package/server/lib/agent-tool/runtime.js +2 -19
  61. package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
  62. package/server/lib/dev-tunnel/runtime.js +4 -4
  63. package/server/lib/dev-tunnel/tunnel.test.js +20 -0
  64. package/server/lib/dictation/DOCUMENTATION.md +19 -6
  65. package/server/lib/dictation/local/model-catalog.js +220 -0
  66. package/server/lib/dictation/local/model-catalog.test.js +42 -0
  67. package/server/lib/dictation/local/sherpa-tts.js +41 -20
  68. package/server/lib/dictation/local/worker-process.js +2 -0
  69. package/server/lib/dictation/runtime.js +4 -0
  70. package/server/lib/dictation/service.js +27 -4
  71. package/server/lib/fs/DOCUMENTATION.md +4 -0
  72. package/server/lib/fs/routes.js +129 -0
  73. package/server/lib/fs/routes.test.js +219 -0
  74. package/server/lib/git/DOCUMENTATION.md +3 -1
  75. package/server/lib/git/routes.js +16 -0
  76. package/server/lib/git/service.js +97 -17
  77. package/server/lib/git/service.test.js +153 -0
  78. package/server/lib/linear/DOCUMENTATION.md +97 -0
  79. package/server/lib/linear/OAUTH-BROKER-HANDOFF.md +91 -0
  80. package/server/lib/linear/auth.js +436 -0
  81. package/server/lib/linear/auth.test.js +242 -0
  82. package/server/lib/linear/client.js +191 -0
  83. package/server/lib/linear/index.js +61 -0
  84. package/server/lib/linear/issues.js +499 -0
  85. package/server/lib/linear/issues.test.js +512 -0
  86. package/server/lib/linear/mapping.js +188 -0
  87. package/server/lib/linear/mapping.test.js +147 -0
  88. package/server/lib/linear/oauth.js +345 -0
  89. package/server/lib/linear/oauth.test.js +166 -0
  90. package/server/lib/linear/parse.js +23 -0
  91. package/server/lib/linear/routes.js +432 -0
  92. package/server/lib/linear/routes.test.js +661 -0
  93. package/server/lib/linear/status-runtime.js +64 -0
  94. package/server/lib/linear/status-runtime.test.js +167 -0
  95. package/server/lib/linear/status.js +280 -0
  96. package/server/lib/linear/status.test.js +271 -0
  97. package/server/lib/linear/teams.js +72 -0
  98. package/server/lib/linear/teams.test.js +94 -0
  99. package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
  100. package/server/lib/mcp-reconnect/runtime.js +122 -0
  101. package/server/lib/mcp-reconnect/runtime.test.js +140 -0
  102. package/server/lib/message-queue/DOCUMENTATION.md +148 -0
  103. package/server/lib/message-queue/runtime.js +818 -0
  104. package/server/lib/message-queue/runtime.test.js +426 -0
  105. package/server/lib/openchamber-sessions/routes.js +102 -0
  106. package/server/lib/openchamber-sessions/routes.test.js +88 -0
  107. package/server/lib/opencode/DOCUMENTATION.md +5 -1
  108. package/server/lib/opencode/core-routes.js +1 -0
  109. package/server/lib/opencode/feature-routes-runtime.js +5 -0
  110. package/server/lib/opencode/managed-plugin-config.js +35 -0
  111. package/server/lib/opencode/settings-runtime.js +2 -2
  112. package/server/lib/opencode/settings-runtime.test.js +29 -0
  113. package/server/lib/opencode/shutdown-runtime.js +2 -0
  114. package/server/lib/opencode/static-routes-runtime.js +3 -3
  115. package/server/lib/projects/project-config.js +33 -5
  116. package/server/lib/projects/project-config.test.js +85 -0
  117. package/server/lib/quota/DOCUMENTATION.md +2 -1
  118. package/server/lib/quota/credentials/providers.js +4 -0
  119. package/server/lib/quota/credentials/store.js +1 -1
  120. package/server/lib/quota/credentials/store.test.js +4 -4
  121. package/server/lib/quota/providers/exe-dev.js +75 -0
  122. package/server/lib/quota/providers/exe-dev.test.js +47 -0
  123. package/server/lib/quota/providers/index.js +7 -0
  124. package/server/lib/quota/providers/opencode-go.js +1 -0
  125. package/server/lib/quota/providers/opencode-go.test.js +5 -1
  126. package/server/lib/quota/routes.js +2 -0
  127. package/server/lib/relay/DOCUMENTATION.md +1 -1
  128. package/server/lib/relay/tunnel-host.js +3 -1
  129. package/server/lib/relay/tunnel-host.test.js +9 -1
  130. package/server/lib/scheduled-tasks/DOCUMENTATION.md +7 -0
  131. package/server/lib/security/request-security.js +21 -6
  132. package/server/lib/security/request-security.test.js +42 -8
  133. package/server/lib/session-assist/runtime.js +1 -0
  134. package/server/lib/session-goal/create.js +3 -1
  135. package/server/lib/session-goal/runtime.js +1 -0
  136. package/server/lib/small-model/DOCUMENTATION.md +4 -0
  137. package/server/lib/small-model/call.js +8 -2
  138. package/server/lib/small-model/call.test.js +23 -0
  139. package/server/lib/small-model/index.js +2 -1
  140. package/server/lib/small-model/routes.js +2 -1
  141. package/server/lib/system-prompt/runtime.js +2 -21
  142. package/server/lib/terminal/runtime.js +30 -7
  143. package/server/lib/tts/DOCUMENTATION.md +1 -0
  144. package/server/lib/tts/language-detect.js +210 -0
  145. package/server/lib/tts/language-detect.test.js +76 -0
  146. package/server/lib/tts/routes.js +23 -1
  147. package/server/lib/tts/routes.test.js +26 -0
  148. package/server/lib/ui-auth/ui-auth.js +4 -1
  149. package/server/lib/ui-auth/ui-auth.test.js +16 -0
  150. package/server/lib/walkthrough/index.js +1 -0
  151. package/dist/assets/CommitSection-DwGiXyjf.js +0 -1
  152. package/dist/assets/DiffView-Db6bjVv1.js +0 -4
  153. package/dist/assets/FilesView-DQOa7Lgz.js +0 -17
  154. package/dist/assets/GitView-CHzJxTi0.js +0 -6
  155. package/dist/assets/MarkdownImageGallery-DoZpaHev.js +0 -1
  156. package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +0 -12
  157. package/dist/assets/OnboardingScreen-C98d69Fp.js +0 -1
  158. package/dist/assets/SettingsView-D-K3ELCM.js +0 -28
  159. package/dist/assets/ToolPartDiffPreview-C7kBQNAA.js +0 -8
  160. package/dist/assets/WalkthroughView-MuJodAHD.js +0 -4
  161. package/dist/assets/es-DwyXCqaL.js +0 -15
  162. package/dist/assets/index-CUKcHnUA.css +0 -1
  163. package/dist/assets/index-DIvDEKE-.js +0 -7
  164. package/dist/assets/main-DLlfDjQ_.js +0 -926
  165. package/dist/assets/markdownCore-CcTcLsQF.js +0 -3
  166. package/dist/assets/pt-BR-DxLmkhdv.js +0 -15
  167. package/dist/assets/renderMobileApp-ltva2Plg.js +0 -25
  168. package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +0 -15
  169. package/dist/assets/scheduledTasksApi-mjMDet_H.js +0 -1
  170. package/dist/assets/tr-5Mk_hQ2Q.js +0 -6
  171. package/dist/assets/uk-ClgQjmlw.js +0 -15
  172. package/dist/assets/useInlineCommentController-HIjtuhxD.js +0 -2
  173. package/dist/assets/useRootScrollLock-BSiQ5F75.js +0 -1
  174. package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
  175. package/dist/assets/zh-CN-Ba6y8H-i.js +0 -15
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Language detection for text-to-speech voice selection.
3
+ *
4
+ * Picks the language a piece of chat text is written in so a TTS provider
5
+ * can choose a matching voice or model. Deliberately small and dependency
6
+ * free: the writing system decides most cases outright, and Latin-script
7
+ * languages are told apart by function words and characteristic letters.
8
+ * The answer is a best effort for voice selection, not a linguistic claim —
9
+ * an unknown language falls back to English rather than failing.
10
+ */
11
+
12
+ const SCRIPT_RANGES = [
13
+ ['hangul', /[가-힯ᄀ-ᇿ㄰-㆏]/g],
14
+ ['kana', /[぀-ヿ]/g],
15
+ ['han', /[一-鿿㐀-䶿]/g],
16
+ ['cyrillic', /[Ѐ-ӿ]/g],
17
+ ['greek', /[Ͱ-Ͽ]/g],
18
+ ['arabic', /[؀-ۿ]/g],
19
+ ['hebrew', /[֐-׿]/g],
20
+ ['thai', /[฀-๿]/g],
21
+ ['devanagari', /[ऀ-ॿ]/g],
22
+ ['latin', /[A-Za-zÀ-ɏ]/g],
23
+ ];
24
+
25
+ const SCRIPT_LANGUAGE = {
26
+ hangul: 'ko',
27
+ greek: 'el',
28
+ arabic: 'ar',
29
+ hebrew: 'he',
30
+ thai: 'th',
31
+ devanagari: 'hi',
32
+ };
33
+
34
+ // Letters that only (or overwhelmingly) occur in one language of a script.
35
+ const LATIN_MARKERS = {
36
+ pl: /[łęąńśźż]/i,
37
+ cs: /[řěůťďň]/i,
38
+ tr: /[ğışİ]/,
39
+ pt: /[ãõ]/i,
40
+ es: /[ñ¿¡]/,
41
+ de: /[ß]/,
42
+ fr: /[œ]/i,
43
+ sv: /[å]/i,
44
+ };
45
+
46
+ // Frequent function words per language. Scored by whole-word hits; every
47
+ // list has the same length so scores stay comparable.
48
+ const STOPWORDS = {
49
+ en: ['the', 'and', 'is', 'to', 'of', 'that', 'you', 'with', 'for', 'this', 'are', 'it', 'not', 'have', 'can', 'will', 'your', 'from', 'which', 'when'],
50
+ de: ['und', 'der', 'die', 'das', 'ist', 'nicht', 'mit', 'ein', 'eine', 'auch', 'sich', 'auf', 'für', 'wird', 'werden', 'oder', 'aber', 'wenn', 'sind', 'kann'],
51
+ fr: ['le', 'la', 'les', 'et', 'est', 'une', 'des', 'pour', 'que', 'qui', 'dans', 'pas', 'vous', 'sur', 'avec', 'sont', 'nous', 'cette', 'mais', 'plus'],
52
+ es: ['el', 'la', 'los', 'las', 'que', 'es', 'una', 'por', 'para', 'con', 'del', 'como', 'pero', 'más', 'este', 'esta', 'son', 'tiene', 'puede', 'también'],
53
+ it: ['il', 'la', 'che', 'di', 'è', 'una', 'per', 'non', 'con', 'del', 'della', 'come', 'sono', 'anche', 'questo', 'questa', 'gli', 'nel', 'più', 'essere'],
54
+ pt: ['o', 'a', 'os', 'as', 'que', 'é', 'uma', 'para', 'com', 'não', 'do', 'da', 'como', 'mas', 'também', 'este', 'esta', 'são', 'você', 'pode'],
55
+ pl: ['i', 'nie', 'jest', 'się', 'na', 'to', 'że', 'jak', 'ale', 'dla', 'oraz', 'przez', 'czy', 'tym', 'jego', 'można', 'jeśli', 'tego', 'które', 'także'],
56
+ nl: ['de', 'het', 'een', 'en', 'van', 'is', 'niet', 'dat', 'met', 'voor', 'ook', 'zijn', 'maar', 'als', 'wordt', 'deze', 'kan', 'naar', 'bij', 'dan'],
57
+ cs: ['a', 'je', 'se', 'na', 'to', 'že', 'jak', 'ale', 'pro', 'nebo', 'jsou', 'může', 'také', 'tento', 'když', 'jeho', 'které', 'být', 'aby', 'ještě'],
58
+ tr: ['ve', 'bir', 'bu', 'için', 'ile', 'de', 'da', 'ama', 'gibi', 'daha', 'var', 'olarak', 'çok', 'ne', 'her', 'kadar', 'sonra', 'değil', 'olan', 'ise'],
59
+ sv: ['och', 'att', 'det', 'är', 'en', 'som', 'för', 'inte', 'med', 'till', 'den', 'kan', 'har', 'ett', 'men', 'också', 'eller', 'från', 'när', 'vara'],
60
+ uk: ['і', 'та', 'що', 'це', 'не', 'як', 'для', 'він', 'вона', 'але', 'або', 'також', 'тільки', 'вже', 'якщо', 'його', 'цей', 'ця', 'бути', 'коли'],
61
+ ru: ['и', 'что', 'это', 'не', 'как', 'для', 'он', 'она', 'но', 'или', 'также', 'только', 'уже', 'если', 'его', 'этот', 'эта', 'быть', 'когда', 'чтобы'],
62
+ };
63
+
64
+ const LATIN_LANGUAGES = ['en', 'de', 'fr', 'es', 'it', 'pt', 'pl', 'nl', 'cs', 'tr', 'sv'];
65
+ const CYRILLIC_LANGUAGES = ['uk', 'ru'];
66
+
67
+ const countMatches = (text, pattern) => {
68
+ const matches = text.match(pattern);
69
+ return matches ? matches.length : 0;
70
+ };
71
+
72
+ const scoreStopwords = (words, languages) => {
73
+ const scores = {};
74
+ for (const language of languages) {
75
+ const list = new Set(STOPWORDS[language]);
76
+ let hits = 0;
77
+ for (const word of words) {
78
+ if (list.has(word)) hits += 1;
79
+ }
80
+ scores[language] = hits;
81
+ }
82
+ return scores;
83
+ };
84
+
85
+ const bestOf = (scores, fallback) => {
86
+ let best = fallback;
87
+ let bestScore = 0;
88
+ for (const [language, score] of Object.entries(scores)) {
89
+ if (score > bestScore) {
90
+ best = language;
91
+ bestScore = score;
92
+ }
93
+ }
94
+ return best;
95
+ };
96
+
97
+ const pickByMarkers = (text, markers) => {
98
+ for (const [language, pattern] of Object.entries(markers)) {
99
+ if (pattern.test(text)) return language;
100
+ }
101
+ return null;
102
+ };
103
+
104
+ /**
105
+ * @param {string} text
106
+ * @returns {{ language: string, script: string }} BCP-47 primary language subtag and the dominant script.
107
+ */
108
+ export function detectTextLanguage(text) {
109
+ const source = typeof text === 'string' ? text : '';
110
+ const counts = SCRIPT_RANGES.map(([script, pattern]) => [script, countMatches(source, pattern)]);
111
+ const letters = counts.reduce((sum, [, count]) => sum + count, 0);
112
+ if (letters === 0) return { language: 'en', script: 'latin' };
113
+
114
+ // Kana settles Japanese even when Han dominates the character count.
115
+ const kana = counts.find(([script]) => script === 'kana')?.[1] ?? 0;
116
+ const han = counts.find(([script]) => script === 'han')?.[1] ?? 0;
117
+ if (kana > 0 && kana + han >= letters * 0.3) return { language: 'ja', script: 'kana' };
118
+ if (han > 0 && han >= letters * 0.3) return { language: 'zh', script: 'han' };
119
+
120
+ const [script] = counts.reduce((best, entry) => (entry[1] > best[1] ? entry : best));
121
+
122
+ if (script in SCRIPT_LANGUAGE) return { language: SCRIPT_LANGUAGE[script], script };
123
+
124
+ const words = source.toLowerCase().split(/[^\p{L}\p{M}']+/u).filter(Boolean);
125
+
126
+ if (script === 'cyrillic') {
127
+ const scores = scoreStopwords(words, CYRILLIC_LANGUAGES);
128
+ const ukMarkers = countMatches(source, /[іїєґ]/gi);
129
+ const ruMarkers = countMatches(source, /[ыэъё]/gi);
130
+ // Letters decide: the two alphabets differ in letters that occur in
131
+ // nearly every sentence. Function words only settle a text that shows
132
+ // neither set, and a text with no Russian-only letters is far more
133
+ // likely Ukrainian than the reverse, so that tie goes to Ukrainian.
134
+ if (ukMarkers !== ruMarkers) return { language: ukMarkers > ruMarkers ? 'uk' : 'ru', script };
135
+ if (scores.uk !== scores.ru) return { language: scores.uk > scores.ru ? 'uk' : 'ru', script };
136
+ return { language: ruMarkers > 0 ? 'ru' : 'uk', script };
137
+ }
138
+
139
+ const scores = scoreStopwords(words, LATIN_LANGUAGES);
140
+ const marked = pickByMarkers(source, LATIN_MARKERS);
141
+ // A characteristic letter outranks stopword counts unless another language
142
+ // clearly dominates the function words (a German text quoting "façade").
143
+ if (marked && scores[marked] * 2 >= scores[bestOf(scores, marked)]) {
144
+ return { language: marked, script };
145
+ }
146
+ return { language: bestOf(scores, 'en'), script };
147
+ }
148
+
149
+ /**
150
+ * Map a detected language onto the locales a voice list uses (`uk_UA`,
151
+ * `en_US`...). Returns the preferred locale prefixes in order.
152
+ * @param {string} language
153
+ * @returns {string[]}
154
+ */
155
+ function localePrefixesForLanguage(language) {
156
+ const table = {
157
+ en: ['en_US', 'en_GB', 'en'],
158
+ uk: ['uk_UA', 'uk'],
159
+ ru: ['ru_RU', 'ru'],
160
+ de: ['de_DE', 'de'],
161
+ fr: ['fr_FR', 'fr_CA', 'fr'],
162
+ es: ['es_ES', 'es_MX', 'es'],
163
+ it: ['it_IT', 'it'],
164
+ pt: ['pt_BR', 'pt_PT', 'pt'],
165
+ pl: ['pl_PL', 'pl'],
166
+ nl: ['nl_NL', 'nl_BE', 'nl'],
167
+ cs: ['cs_CZ', 'cs'],
168
+ tr: ['tr_TR', 'tr'],
169
+ sv: ['sv_SE', 'sv'],
170
+ zh: ['zh_CN', 'zh_TW', 'zh_HK', 'zh'],
171
+ ja: ['ja_JP', 'ja'],
172
+ ko: ['ko_KR', 'ko'],
173
+ el: ['el_GR', 'el'],
174
+ ar: ['ar_001', 'ar_SA', 'ar'],
175
+ he: ['he_IL', 'he'],
176
+ th: ['th_TH', 'th'],
177
+ hi: ['hi_IN', 'hi'],
178
+ };
179
+ return table[language] ?? [language];
180
+ }
181
+
182
+ /**
183
+ * Choose a voice for a language from a `say`-style voice list.
184
+ * Prefers an enhanced/premium variant of a matching voice, then any voice of
185
+ * the exact locale, then any voice of the language. Returns null when the
186
+ * list has no voice for that language.
187
+ * @param {string} language
188
+ * @param {ReadonlyArray<{ name: string, locale: string }>} voices
189
+ * @returns {string | null}
190
+ */
191
+ export function pickVoiceForLanguage(language, voices) {
192
+ const prefixes = localePrefixesForLanguage(language);
193
+ for (const prefix of prefixes) {
194
+ const matching = voices.filter((voice) => voice.locale === prefix || voice.locale.startsWith(`${prefix}_`) || (prefix === language && voice.locale.startsWith(`${language}_`)));
195
+ if (matching.length === 0) continue;
196
+ const enhanced = matching.find((voice) => /\((Enhanced|Premium)\)/i.test(voice.name));
197
+ return (enhanced ?? matching[0]).name;
198
+ }
199
+ return null;
200
+ }
201
+
202
+ /**
203
+ * Language of a voice, from its locale (`uk_UA` → `uk`).
204
+ * @param {string | null | undefined} locale
205
+ * @returns {string | null}
206
+ */
207
+ export function languageOfLocale(locale) {
208
+ if (typeof locale !== 'string' || !locale) return null;
209
+ return locale.split(/[_-]/)[0].toLowerCase();
210
+ }
@@ -0,0 +1,76 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { detectTextLanguage, languageOfLocale, pickVoiceForLanguage } from './language-detect.js';
3
+
4
+ describe('detectTextLanguage', () => {
5
+ it.each([
6
+ ['en', 'The build is green and the tests pass, so you can merge this now.'],
7
+ ['uk', 'Привіт! Це тестове повідомлення, і воно написане українською мовою.'],
8
+ ['ru', 'Привет! Это тестовое сообщение, и оно написано на русском языке.'],
9
+ ['de', 'Die Änderung ist fertig und die Tests laufen ohne Fehler durch.'],
10
+ ['fr', 'La modification est prête et les tests passent sans erreur.'],
11
+ ['es', 'El cambio está listo y las pruebas pasan sin errores.'],
12
+ ['it', 'La modifica è pronta e i test passano senza errori.'],
13
+ ['pt', 'A alteração está pronta e os testes passam sem erros, você pode continuar.'],
14
+ ['pl', 'Zmiana jest gotowa i testy przechodzą bez błędów.'],
15
+ ['nl', 'De wijziging is klaar en de tests slagen zonder fouten.'],
16
+ ['cs', 'Změna je hotová a testy procházejí bez chyb.'],
17
+ ['tr', 'Değişiklik hazır ve testler hatasız geçiyor.'],
18
+ ['sv', 'Ändringen är klar och testerna går igenom utan fel.'],
19
+ ['zh', '修改已经完成,所有测试都通过了。'],
20
+ ['ja', '変更が完了し、すべてのテストに合格しました。'],
21
+ ['ko', '변경이 완료되었고 모든 테스트를 통과했습니다.'],
22
+ ])('detects %s', (language, text) => {
23
+ expect(detectTextLanguage(text).language).toBe(language);
24
+ });
25
+
26
+ it.each([
27
+ ['uk', 'Готово. Запушено.'],
28
+ ['uk', 'Все ок'],
29
+ ['uk', 'Добре, давай так зробимо'],
30
+ ['ru', 'Хорошо, давай так и сделаем'],
31
+ ['ru', 'Готово, всё запушено.'],
32
+ ])('tells short %s phrases apart by letters', (language, text) => {
33
+ expect(detectTextLanguage(text).language).toBe(language);
34
+ });
35
+
36
+ it('falls back to English for text without letters', () => {
37
+ expect(detectTextLanguage('1234 ... !!!').language).toBe('en');
38
+ expect(detectTextLanguage('').language).toBe('en');
39
+ });
40
+
41
+ it('does not let a single quoted foreign word flip an English paragraph', () => {
42
+ const text = 'The façade of the building is the part that you see from the street, and it is not the same as the interior.';
43
+ expect(detectTextLanguage(text).language).toBe('en');
44
+ });
45
+ });
46
+
47
+ describe('pickVoiceForLanguage', () => {
48
+ const voices = [
49
+ { name: 'Samantha', locale: 'en_US' },
50
+ { name: 'Daniel', locale: 'en_GB' },
51
+ { name: 'Lesya', locale: 'uk_UA' },
52
+ { name: 'Lesya (Enhanced)', locale: 'uk_UA' },
53
+ { name: 'Milena', locale: 'ru_RU' },
54
+ { name: 'Anna', locale: 'de_DE' },
55
+ ];
56
+
57
+ it('prefers the enhanced variant of a matching voice', () => {
58
+ expect(pickVoiceForLanguage('uk', voices)).toBe('Lesya (Enhanced)');
59
+ });
60
+
61
+ it('prefers the primary locale of a language', () => {
62
+ expect(pickVoiceForLanguage('en', voices)).toBe('Samantha');
63
+ });
64
+
65
+ it('returns null when no voice speaks the language', () => {
66
+ expect(pickVoiceForLanguage('ja', voices)).toBeNull();
67
+ });
68
+ });
69
+
70
+ describe('languageOfLocale', () => {
71
+ it('reads the language subtag', () => {
72
+ expect(languageOfLocale('uk_UA')).toBe('uk');
73
+ expect(languageOfLocale('en-GB')).toBe('en');
74
+ expect(languageOfLocale(null)).toBeNull();
75
+ });
76
+ });
@@ -2,6 +2,8 @@ import express from 'express';
2
2
  import { normalizeCustomOpenAIBaseURL } from './base-url.js';
3
3
  import { summarizeText, sanitizeForTTS, sanitizeForNote } from '../text/summarization.js';
4
4
 
5
+ import { detectTextLanguage, languageOfLocale, pickVoiceForLanguage } from './language-detect.js';
6
+
5
7
  export function registerTtsRoutes(app, { sayTTSCapability }) {
6
8
  let ttsModulePromise = null;
7
9
  const getTtsModule = async () => {
@@ -154,7 +156,8 @@ export function registerTtsRoutes(app, { sayTTSCapability }) {
154
156
  // macOS 'say' command TTS speak endpoint
155
157
  app.post('/api/tts/say/speak', async (req, res) => {
156
158
  try {
157
- const { text, voice = 'Samantha', rate = 200 } = req.body || {};
159
+ const { text, rate = 200, language, languageSample } = req.body || {};
160
+ let voice = typeof req.body?.voice === 'string' && req.body.voice.trim() ? req.body.voice.trim() : 'Samantha';
158
161
 
159
162
  if (!text || typeof text !== 'string' || !text.trim()) {
160
163
  return res.status(400).json({ error: 'Text is required' });
@@ -164,6 +167,23 @@ export function registerTtsRoutes(app, { sayTTSCapability }) {
164
167
  if (process.platform !== 'darwin') {
165
168
  return res.status(503).json({ error: 'macOS say command not available on this platform' });
166
169
  }
170
+
171
+ // `language: 'auto'`: keep the chosen voice while it speaks the text's
172
+ // language, otherwise switch to an installed voice that does. A
173
+ // language with no installed voice keeps the chosen voice — say still
174
+ // reads the text, just with an accent — rather than failing.
175
+ let resolvedLanguage = null;
176
+ if (language === 'auto') {
177
+ const capability = await sayTTSCapability;
178
+ const voices = Array.isArray(capability?.voices) ? capability.voices : [];
179
+ const sample = typeof languageSample === 'string' && languageSample.trim() ? languageSample.slice(0, 4000) : text;
180
+ resolvedLanguage = detectTextLanguage(sample).language;
181
+ const chosen = voices.find((entry) => entry.name === voice);
182
+ if (languageOfLocale(chosen?.locale) !== resolvedLanguage) {
183
+ const match = pickVoiceForLanguage(resolvedLanguage, voices);
184
+ if (match) voice = match;
185
+ }
186
+ }
167
187
 
168
188
  const { exec } = await import('child_process');
169
189
  const { promisify } = await import('util');
@@ -195,6 +215,8 @@ export function registerTtsRoutes(app, { sayTTSCapability }) {
195
215
 
196
216
  // Send audio response
197
217
  res.setHeader('Content-Type', 'audio/mp4');
218
+ res.setHeader('X-Speech-Voice', voice);
219
+ if (resolvedLanguage) res.setHeader('X-Speech-Language', resolvedLanguage);
198
220
  res.setHeader('Content-Length', audioBuffer.length);
199
221
  res.send(audioBuffer);
200
222
 
@@ -33,6 +33,32 @@ describe('tts routes', () => {
33
33
  });
34
34
  });
35
35
 
36
+ it('switches the say voice to the language of the text when asked to', async () => {
37
+ const capability = Promise.resolve({
38
+ available: true,
39
+ voices: [
40
+ { name: 'Samantha', locale: 'en_US' },
41
+ { name: 'Lesya', locale: 'uk_UA' },
42
+ { name: 'Lesya (Enhanced)', locale: 'uk_UA' },
43
+ ],
44
+ });
45
+ const app = createApp(capability);
46
+ const response = await request(app)
47
+ .post('/api/tts/say/speak')
48
+ .send({ text: 'Привіт! Це відповідь українською мовою, і вона досить довга.', voice: 'Samantha', language: 'auto' });
49
+
50
+ // On macOS the route synthesizes; elsewhere it refuses before running say.
51
+ // Either way the chosen voice must be the Ukrainian one when the platform
52
+ // allows the request to proceed.
53
+ if (process.platform === 'darwin') {
54
+ expect(response.status).toBe(200);
55
+ expect(response.headers['x-speech-voice']).toBe('Lesya (Enhanced)');
56
+ expect(response.headers['x-speech-language']).toBe('uk');
57
+ } else {
58
+ expect(response.status).toBe(503);
59
+ }
60
+ });
61
+
36
62
  it('returns local note fallback while model summarization is retired', async () => {
37
63
  const response = await request(createApp())
38
64
  .post('/api/text/summarize')
@@ -310,6 +310,7 @@ const isUrlAuthWebSocketPath = (pathname) => {
310
310
  || pathname === '/api/openchamber/realtime-proxy/ws'
311
311
  || pathname === '/api/terminal/ws'
312
312
  || pathname === '/api/dictation/ws'
313
+ || pathname === '/api/dev-tunnel'
313
314
  || pathname.startsWith('/api/preview/proxy/');
314
315
  };
315
316
 
@@ -984,7 +985,9 @@ export const createUiAuth = ({
984
985
  handlePasskeyList,
985
986
  handlePasskeyRevoke,
986
987
  handleResetAuth,
987
- ensureSessionToken: async (req, _res) => {
988
+ ensureSessionToken: (req, _res) => {
989
+ const urlAuth = authenticateUrlAuthToken(req);
990
+ if (urlAuth) return clientSessionToken(urlAuth);
988
991
  return resolveAuthenticatedSessionToken(req);
989
992
  },
990
993
  dispose,
@@ -221,6 +221,22 @@ describe('ui auth client credential seam', () => {
221
221
  };
222
222
  expect(await auth.ensureSessionToken(dictationWsReq, null)).toBe('client:device-1');
223
223
 
224
+ const devTunnelWsReq = {
225
+ method: 'GET',
226
+ path: '/api/dev-tunnel',
227
+ url: `/api/dev-tunnel?port=4322&oc_url_token=${encodeURIComponent(urlToken)}`,
228
+ headers: { upgrade: 'websocket' },
229
+ };
230
+ expect(await auth.ensureSessionToken(devTunnelWsReq, null)).toBe('client:device-1');
231
+
232
+ const devTunnelSubpathWsReq = {
233
+ method: 'GET',
234
+ path: '/api/dev-tunnel/private',
235
+ url: `/api/dev-tunnel/private?port=4322&oc_url_token=${encodeURIComponent(urlToken)}`,
236
+ headers: { upgrade: 'websocket' },
237
+ };
238
+ expect(await auth.ensureSessionToken(devTunnelSubpathWsReq, null)).toBe(null);
239
+
224
240
  const dictationHttpReq = {
225
241
  method: 'GET',
226
242
  path: '/api/dictation/ws',
@@ -474,6 +474,7 @@ async function runGeneration({ directory, source, repoRoot, key, force, explicit
474
474
  prompt: options.prompt,
475
475
  system: options.system,
476
476
  directory,
477
+ sessionID: `openchamber-walkthrough-${cacheKey}`,
477
478
  model: `${model.providerID}/${model.modelID}`,
478
479
  responseSchema: options.responseSchema,
479
480
  onOverflow: 'error',
@@ -1 +0,0 @@
1
- import{R as S,f as oe,j as s}from"./vendor-react-BUCujlKS.js";import{u as Ae}from"./vendor-tanstack-react-virtual-g05Cx3z9.js";import{f as Q,ao as Ee,a6 as fe,a7 as me,I as R,a8 as ue,h as Z,B as J,a1 as ze,gV as Ie,bE as pe,bF as ge,bG as xe,bH as be,bI as ye,bJ as ve,bo as Te}from"./useAppFontEffects-KP8_yiGW.js";import{u as Ce}from"./index-DIvDEKE-.js";const ke={"?":{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"}},Me=ke.M;function He(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 Re(p){const e=He(p);return ke[e]??Me}const Fe=S.memo(function(e){const t=oe.c(58),{file:o,actionLabel:x,actionSymbol:b,onAction:m,onViewDiff:f,onRevert:l,isReverting:d,stats:E,rowPaddingClassName:g,indentPx:y,actionAtStart:A,showRevert:F}=e,j=y===void 0?0:y,r=A===void 0?!1:A,w=F===void 0?!0:F;let N;t[0]!==o?(N=Re(o),t[0]=o,t[1]=N):N=t[1];const h=N,{t:z}=Q(),$=h.description,M=E?.insertions??0,C=E?.deletions??0;let D;t[2]!==m||t[3]!==f?(D=U=>{U.key===" "?(U.preventDefault(),m()):U.key==="Enter"&&(U.preventDefault(),f())},t[2]=m,t[3]=f,t[4]=D):D=t[4];const V=D;let I;t[5]!==m?(I=U=>{U.preventDefault(),U.stopPropagation(),m()},t[5]=m,t[6]=I):I=t[6];const u=I;let P;t[7]!==l?(P=U=>{U.preventDefault(),U.stopPropagation(),l()},t[7]=l,t[8]=P):P=t[8];const W=P;let L;t[9]!==x||t[10]!==b||t[11]!==u?(L=s.jsx("button",{type:"button",onClick:u,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":x,title:x,children:b}),t[9]=x,t[10]=b,t[11]=u,t[12]=L):L=t[12];const H=L,X=`group flex items-center gap-2 py-1.5 cursor-pointer ${g??"px-3"}`;let T;t[13]!==j?(T=j>0?{paddingLeft:`${j}px`}:void 0,t[13]=j,t[14]=T):T=t[14];const Y=r?H:null;let K;t[15]!==h.color?(K={color:h.color},t[15]=h.color,t[16]=K):K=t[16];let G;t[17]!==h.code||t[18]!==$||t[19]!==K?(G=s.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:K,title:$,"aria-label":$,children:h.code}),t[17]=h.code,t[18]=$,t[19]=K,t[20]=G):G=t[20];let O;t[21]!==o.path?(O=s.jsx(Ee,{filePath:o.path,className:"h-3.5 w-3.5 shrink-0"}),t[21]=o.path,t[22]=O):O=t[22];let B;if(t[23]!==o.path){e:{const U=o.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],B=s.jsx("span",{className:"flex-1 min-w-0 truncate typography-ui-label text-foreground",style:ne,title:o.path,children:o.path});break e}const De=o.path.slice(0,U),Ve=o.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 re=s.jsx("span",{className:"text-foreground",children:Ve.slice(1)});let ie;t[28]!==re?(ie=s.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[se,re]}),t[28]=re,t[29]=ie):ie=t[29],B=s.jsxs("span",{className:"flex-1 min-w-0 flex items-baseline overflow-hidden",title:o.path,children:[s.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:te,children:De}),ie]})}t[23]=o.path,t[24]=B}else B=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]!==M?(i=s.jsxs("span",{style:q,children:["+",M]}),t[31]=M,t[32]=i):i=t[32];let n,a;t[33]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx("span",{className:"text-muted-foreground mx-0.5",children:"/"}),a={color:"var(--status-error)"},t[33]=n,t[34]=a):(n=t[33],a=t[34]);let c;t[35]!==C?(c=s.jsxs("span",{style:a,children:["-",C]}),t[35]=C,t[36]=c):c=t[36];let k;t[37]!==i||t[38]!==c?(k=s.jsxs("span",{className:"shrink-0 typography-micro",children:[i,n,c]}),t[37]=i,t[38]=c,t[39]=k):k=t[39];let v;t[40]!==o.path||t[41]!==W||t[42]!==d||t[43]!==w||t[44]!==z?(v=w?s.jsxs(fe,{children:[s.jsx(me,{asChild:!0,children:s.jsx("button",{type:"button",onClick:W,disabled:d,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":z("gitView.changes.revertFileAria",{path:o.path}),children:d?s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(R,{name:"arrow-go-back",className:"size-3.5"})})}),s.jsx(ue,{sideOffset:8,children:z("gitView.changes.revertFileTooltip")})]}):null,t[40]=o.path,t[41]=W,t[42]=d,t[43]=w,t[44]=z,t[45]=v):v=t[45];const _=r?null:H;let ee;return t[46]!==V||t[47]!==f||t[48]!==T||t[49]!==Y||t[50]!==G||t[51]!==O||t[52]!==B||t[53]!==k||t[54]!==v||t[55]!==_||t[56]!==X?(ee=s.jsxs("div",{className:X,role:"button",tabIndex:0,onClick:f,onKeyDown:V,style:T,children:[Y,G,O,B,k,v,_]}),t[46]=V,t[47]=f,t[48]=T,t[49]=Y,t[50]=G,t[51]=O,t[52]=B,t[53]=k,t[54]=v,t[55]=_,t[56]=X,t[57]=ee):ee=t[57],ee}),je=14,Se=p=>p.replace(/\\/g,"/").replace(/^\/+/,"").trim(),we=(p,e)=>({id:`dir:${p}`,path:p,name:e,children:new Map,directFiles:[],files:[]}),$e=p=>{const e=we("","");for(const t of p){const o=Se(t.path);if(!o)continue;const b=o.split("/").filter(Boolean).slice(0,-1);let m=e;if(m.files.push(t),b.length>0){let f="";for(const l of b){f=f?`${f}/${l}`:l;const d=m.children.get(l);if(d){d.files.push(t),m=d;continue}const E=we(f,l);E.files.push(t),m.children.set(l,E),m=E}}m.directFiles.push(t)}return e},Pe=(p,e)=>{const t=[],o=(x,b)=>{const m=Array.from(x.children.values()).sort((l,d)=>l.path.localeCompare(d.path));for(const l of m)t.push({key:l.id,kind:"directory",depth:b,directory:l}),e.has(l.path)&&o(l,b+1);const f=[...x.directFiles].sort((l,d)=>l.path.localeCompare(d.path));for(const l of f)t.push({key:`file:${Se(l.path)}`,kind:"file",depth:b,file:l})};return o(p,0),t},Le=1e3,Ne=34,ce=30,le="pl-0 pr-2",de=(p,e)=>`${p} ${e}`,Ye=({groups:p,diffStats:e,revertingPaths:t,isRevertingAll:o=!1,headerBackgroundClassName:x="bg-sidebar",onVisiblePathsChange:b,onRevertAll:m,onRevertDirectory:f})=>{const{t:l}=Q(),d=S.useRef(null),g=Ce(i=>i.gitChangesViewMode)==="tree",y=S.useMemo(()=>p.filter(i=>i.entries.length>0),[p]),[A,F]=S.useState(new Set),[j,r]=S.useState(new Set),[w,N]=S.useState(!1),[h,z]=S.useState(null),$=S.useMemo(()=>y.map(i=>$e(i.entries)),[y]),M=S.useMemo(()=>{const i=[];return y.forEach((n,a)=>{Array.from($[a]?.children.values()??[]).forEach(c=>{i.push(de(n.id,c.path))})}),i},[$,y]);S.useEffect(()=>{g&&r(i=>{const n=new Set,a=new Set(M);return i.forEach(c=>{(c.slice(c.indexOf(" ")+1).includes("/")||a.has(c))&&n.add(c)}),M.forEach(c=>n.add(c)),n})},[g,M]);const C=S.useMemo(()=>{const i=[];return y.forEach((n,a)=>{if(i.push({type:"header",key:`header:${n.id}`,groupIndex:a}),!A.has(n.id)){if(g){const c=new Set;j.forEach(v=>{v.startsWith(`${n.id} `)&&c.add(v.slice(n.id.length+1))}),Pe($[a],c).forEach(v=>{v.kind==="file"?i.push({type:"file",key:`${n.id}:${v.key}`,groupIndex:a,file:v.file,depth:v.depth}):i.push({type:"directory",key:`${n.id}:${v.key}`,groupIndex:a,directory:v.directory,depth:v.depth})});return}n.entries.forEach(c=>{i.push({type:"file",key:`${n.id}:file:${c.path}`,groupIndex:a,file:c,depth:0})})}}),m&&y.length>0&&i.push({type:"revert-all",key:"revert-all"}),i},[A,j,g,m,$,y]),D=C.length,V=D>=Le,I=Ae({count:D,enabled:V,getScrollElement:()=>d.current,estimateSize:()=>Ne,overscan:12,getItemKey:i=>C[i]?.key??i}),u=I.getVirtualItems(),P=S.useMemo(()=>{if(!V)return 0;const i=d.current?.scrollTop??0;return u.find(a=>a.end>i)?.index??0},[V,u,d]);S.useEffect(()=>{if(!b)return;const i=n=>n&&n.type==="file"?n.file.path:null;if(D===0){b([]);return}if(!V){const n=[];for(const a of C)if(a.type==="file"&&(n.push(a.file.path),n.length>=ce))break;b(n);return}b(C.slice(P,P+Math.ceil((d.current?.clientHeight??0)/Ne)+ce).map(n=>i(n)).filter(n=>!!n).slice(0,ce))},[b,D,C,V,P]);const W=S.useCallback(i=>{F(n=>{const a=new Set(n);return a.has(i)?a.delete(i):a.add(i),a})},[]),L=S.useCallback((i,n)=>{r(a=>{const c=new Set(a),k=de(i,n);return c.has(k)?c.delete(k):c.add(k),c})},[]),H=S.useMemo(()=>{const i=new Set;return y.forEach(n=>n.entries.forEach(a=>i.add(a.path))),Array.from(i)},[y]),X=H.length,T=h?o||h.paths.some(i=>t.has(i)):!1,Y=S.useCallback(async()=>{!m||o||H.length===0||(await m(H),N(!1))},[H,o,m]),K=S.useCallback(async()=>{!f||!h||T||(await f(h.paths),z(null))},[T,f,h]),G=S.useCallback((i,n)=>{const a=A.has(i.id),c=i.entries.length;return s.jsxs("div",{className:Z("sticky top-0 z-10 flex items-center gap-2 py-2",x,le,!n&&"mt-1 border-t border-border/40"),children:[s.jsx("button",{type:"button",onClick:()=>i.onActionAll(i.entries.map(k=>k.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":!a,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:c}),s.jsx(R,{name:"arrow-down-s",className:Z("size-3.5 shrink-0 text-muted-foreground transition-transform",a&&"-rotate-90")})]})]})},[A,x,W]),O=S.useCallback((i,n,a)=>{const c=j.has(de(i.id,n.path)),k=n.files.map(_=>_.path),v=o||k.some(_=>t.has(_));return s.jsxs("div",{className:Z("group flex items-center gap-2 py-1.5",le),style:{paddingLeft:`${a*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":c?l("gitView.changes.collapseDirectoryAria",{path:n.path}):l("gitView.changes.expandDirectoryAria",{path:n.path}),children:[c?s.jsx(R,{name:"folder-open-fill",className:"h-4 w-4 flex-shrink-0 text-primary/60"}):s.jsx(R,{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&&f?s.jsx("button",{type:"button",onClick:()=>z({path:n.path,paths:k,count:k.length}),disabled:v,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":l("gitView.changes.revertDirectoryAria",{path:n.path}),title:l("gitView.changes.revertDirectoryTooltip"),children:v?s.jsx(R,{name:"loader-4",className:"size-3.5 animate-spin"}):s.jsx(R,{name:"arrow-go-back",className:"size-3.5"})}):null,s.jsx("button",{type:"button",onClick:()=>i.onActionAll(n.files.map(_=>_.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":l(i.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:n.path}),title:l(i.actionSymbol==="+"?"gitView.changes.stageDirectoryAria":"gitView.changes.unstageDirectoryAria",{path:n.path}),children:i.actionSymbol})]})},[j,o,f,t,l,L]),B=S.useCallback((i,n)=>{if(i.type==="revert-all")return s.jsx("div",{className:Z("flex justify-end py-2",le),children:s.jsxs(J,{variant:"ghost",size:"sm",onClick:()=>N(!0),disabled:o,className:"gap-1.5 text-[var(--status-error)] hover:bg-[var(--status-error)]/10 hover:text-[var(--status-error)]",children:[s.jsx(R,{name:"arrow-go-back",className:"size-3.5"}),l("gitView.changes.revertAll")]})});const a=y[i.groupIndex];if(!a)return null;if(i.type==="header")return G(a,n);if(i.type==="directory")return O(a,i.directory,i.depth);const c=i.file;return s.jsx(Fe,{file:c,actionLabel:a.getActionLabel(c.path),actionSymbol:a.actionSymbol,onAction:()=>a.onActionFile(c.path),stats:e?.[c.path],onViewDiff:()=>a.onViewDiff(c.path),onRevert:()=>a.onRevertFile(c.path),isReverting:t.has(c.path)||o,rowPaddingClassName:le,indentPx:i.depth*je,actionAtStart:!g,showRevert:a.showRevertActions!==!1})},[e,o,g,O,G,t,l,y]),q=S.useCallback(i=>{const n=C[i],a=C[i-1];return!n||!a||n.type!=="file"&&n.type!=="directory"||a.type!=="file"&&a.type!=="directory"?!1:a.groupIndex===n.groupIndex},[C]);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(ze,{ref:d,className:"overlay-scrollbar-target overlay-scrollbar-container min-h-0 w-full flex-1 overflow-x-hidden overflow-y-auto",children:V?s.jsx("div",{style:{height:I.getTotalSize(),position:"relative"},children:u.map(i=>{const n=C[i.index];return n?s.jsx("div",{"data-index":i.index,ref:I.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:B(n,i.index===0)},n.key):null})}):s.jsx("div",{role:"list","aria-label":l("gitView.changes.changedFilesAria"),children:C.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:B(i,n===0)},i.key))})}),s.jsx(Ie,{containerRef:d,disableHorizontal:!0})]}),s.jsx(pe,{open:w,onOpenChange:i=>{!o&&!i&&N(!1)},children:s.jsxs(ge,{className:"max-w-md",children:[s.jsxs(xe,{children:[s.jsx(be,{children:l("gitView.changes.revertAllDialogTitle")}),s.jsx(ye,{children:X===1?l("gitView.changes.revertAllDescriptionSingle",{count:X}):l("gitView.changes.revertAllDescriptionPlural",{count:X})})]}),s.jsxs(ve,{children:[s.jsx(J,{variant:"outline",size:"sm",onClick:()=>N(!1),disabled:o,children:l("gitView.common.cancel")}),s.jsx(J,{variant:"destructive",size:"sm",onClick:()=>{Y()},disabled:o,children:l(o?"gitView.changes.reverting":"gitView.changes.revertAll")})]})]})}),s.jsx(pe,{open:!!h,onOpenChange:i=>{!T&&!i&&z(null)},children:s.jsxs(ge,{className:"max-w-md",children:[s.jsxs(xe,{children:[s.jsx(be,{children:l("gitView.changes.revertDirectoryDialogTitle")}),s.jsx(ye,{children:h?h.count===1?l("gitView.changes.revertDirectoryDescriptionSingle",{count:h.count,path:h.path}):l("gitView.changes.revertDirectoryDescriptionPlural",{count:h.count,path:h.path}):null})]}),s.jsxs(ve,{children:[s.jsx(J,{variant:"outline",size:"sm",onClick:()=>z(null),disabled:T,children:l("gitView.common.cancel")}),s.jsx(J,{variant:"destructive",size:"sm",onClick:()=>{K()},disabled:T||!h,children:l(T?"gitView.changes.reverting":"gitView.changes.revertDirectory")})]})]})})]})},he=38,ae=200,Ge=p=>{const e=oe.c(23),{value:t,onChange:o,onSubmit:x,placeholder:b,disabled:m,hasTouchInput:f,isMobile:l}=p,d=m===void 0?!1:m,E=f===void 0?!1:f,g=l===void 0?!1:l,{t:y}=Q(),A=S.useRef(null),F=Ce(Oe);let j;e[0]===Symbol.for("react.memo_cache_sentinel")?(j=()=>{const u=A.current;if(!u)return;const P=document.activeElement===u,W=()=>{u.style.height=`${he}px`;const H=u.scrollHeight,X=Math.min(Math.max(H,he),ae);u.style.height=`${X}px`,u.style.overflowY=H>ae?"auto":"hidden",H>ae&&!P&&(u.scrollTop=u.scrollHeight)};W();const L=window.requestAnimationFrame(W);return()=>{window.cancelAnimationFrame(L)}},e[0]=j):j=e[0];let r;e[1]!==t?(r=[t],e[1]=t,e[2]=r):r=e[2],S.useLayoutEffect(j,r);let w;e[3]!==o?(w=u=>o(u.target.value),e[3]=o,e[4]=w):w=e[4];let N;e[5]!==x?(N=u=>{u.key==="Enter"&&(u.metaKey||u.ctrlKey)&&!u.shiftKey&&!u.altKey&&(u.preventDefault(),x?.())},e[5]=x,e[6]=N):N=e[6];let h;e[7]!==b||e[8]!==y?(h=b??y("gitView.commit.messagePlaceholder"),e[7]=b,e[8]=y,e[9]=h):h=e[9];const z=E?"on":"off",$=E?"sentences":"off",M=g||F,C=d&&"opacity-50";let D;e[10]!==C?(D=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)]",C),e[10]=C,e[11]=D):D=e[11];let V;e[12]===Symbol.for("react.memo_cache_sentinel")?(V={minHeight:he,maxHeight:ae},e[12]=V):V=e[12];let I;return e[13]!==d||e[14]!==$||e[15]!==M||e[16]!==D||e[17]!==w||e[18]!==N||e[19]!==h||e[20]!==z||e[21]!==t?(I=s.jsx("textarea",{ref:A,value:t,onChange:w,onKeyDown:N,placeholder:h,rows:1,disabled:d,autoCorrect:z,autoCapitalize:$,spellCheck:M,className:D,style:V}),e[13]=d,e[14]=$,e[15]=M,e[16]=D,e[17]=w,e[18]=N,e[19]=h,e[20]=z,e[21]=t,e[22]=I):I=e[22],I};function Oe(p){return p.inputSpellcheckEnabled}const Ke=p=>{const e=oe.c(30),{highlights:t,onInsert:o}=p,{t:x}=Q();if(t.length===0)return null;let b;e[0]!==t||e[1]!==o?(b=()=>{o(t)},e[0]=t,e[1]=o,e[2]=b):b=e[2];const m=b;let f;e[3]!==x?(f=x("gitView.commit.aiHighlights.title"),e[3]=x,e[4]=f):f=e[4];let l;e[5]!==f?(l=s.jsx("p",{className:"typography-micro text-muted-foreground",children:f}),e[5]=f,e[6]=l):l=e[6];let d;e[7]!==x?(d=x("gitView.commit.aiHighlights.insertAria"),e[7]=x,e[8]=d):d=e[8];let E;e[9]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(R,{name:"arrow-down",className:"size-4"}),e[9]=E):E=e[9];let g;e[10]!==m||e[11]!==d?(g=s.jsx(me,{asChild:!0,children:s.jsx(J,{variant:"ghost",size:"icon",className:"size-6",onClick:m,"aria-label":d,children:E})}),e[10]=m,e[11]=d,e[12]=g):g=e[12];let y;e[13]!==x?(y=x("gitView.commit.aiHighlights.insertTooltip"),e[13]=x,e[14]=y):y=e[14];let A;e[15]!==y?(A=s.jsx(ue,{sideOffset:8,children:y}),e[15]=y,e[16]=A):A=e[16];let F;e[17]!==g||e[18]!==A?(F=s.jsxs(fe,{children:[g,A]}),e[17]=g,e[18]=A,e[19]=F):F=e[19];let j;e[20]!==l||e[21]!==F?(j=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l,F]}),e[20]=l,e[21]=F,e[22]=j):j=e[22];let r;e[23]!==t?(r=t.map(Be),e[23]=t,e[24]=r):r=e[24];let w;e[25]!==r?(w=s.jsx("ul",{className:"space-y-1",children:r}),e[25]=r,e[26]=w):w=e[26];let N;return e[27]!==j||e[28]!==w?(N=s.jsxs("div",{className:"space-y-2 rounded-xl border border-border/60 bg-transparent px-3 py-2",children:[j,w]}),e[27]=j,e[28]=w,e[29]=N):N=e[29],N};function Be(p,e){return s.jsx("li",{className:"typography-meta text-foreground",children:p},`${p}-${e}`)}const qe=p=>{const e=oe.c(80),{stagedCount:t,commitMessage:o,onCommitMessageChange:x,generatedHighlights:b,onInsertHighlights:m,onGenerateMessage:f,isGeneratingMessage:l,onCommit:d,onCommitAndPush:E,commitAction:g,hasPendingIndexMutation:y,gitmojiEnabled:A,onOpenGitmojiPicker:F}=p,j=y===void 0?!1:y,{t:r}=Q(),w=t>0;let N;e[0]!==g||e[1]!==o||e[2]!==j||e[3]!==w?(N=o.trim()&&w&&g===null&&!j,e[0]=g,e[1]=o,e[2]=j,e[3]=w,e[4]=N):N=e[4];const h=N,{isMobile:z,hasTouchInput:$}=Te();let M;e[5]!==r?(M=r("gitView.commit.title"),e[5]=r,e[6]=M):M=e[6];let C;e[7]!==M?(C=s.jsx("h3",{className:"typography-ui-header font-semibold text-foreground",children:M}),e[7]=M,e[8]=C):C=e[8];let D;e[9]!==w||e[10]!==r?(D=w?null:s.jsx("span",{className:"min-w-0 truncate typography-meta text-muted-foreground",children:r("gitView.commit.stageFilesHint")}),e[9]=w,e[10]=r,e[11]=D):D=e[11];let V;e[12]!==C||e[13]!==D?(V=s.jsxs("div",{className:"flex w-full items-baseline gap-2 px-0 pt-2 pb-1",children:[C,D]}),e[12]=C,e[13]=D,e[14]=V):V=e[14];let I;e[15]!==b||e[16]!==m?(I=s.jsx(Ke,{highlights:b,onInsert:m}),e[15]=b,e[16]=m,e[17]=I):I=e[17];let u;e[18]!==h||e[19]!==l||e[20]!==d?(u=()=>{h&&!l&&d()},e[18]=h,e[19]=l,e[20]=d,e[21]=u):u=e[21];let P;e[22]!==r?(P=r("gitView.commit.messagePlaceholder"),e[22]=r,e[23]=P):P=e[23];const W=g!==null;let L;e[24]!==o||e[25]!==$||e[26]!==z||e[27]!==x||e[28]!==W||e[29]!==u||e[30]!==P?(L=s.jsx(Ge,{value:o,onChange:x,onSubmit:u,placeholder:P,disabled:W,hasTouchInput:$,isMobile:z}),e[24]=o,e[25]=$,e[26]=z,e[27]=x,e[28]=W,e[29]=u,e[30]=P,e[31]=L):L=e[31];let H;e[32]!==A||e[33]!==F||e[34]!==r?(H=A&&s.jsxs(J,{variant:"outline",size:"sm",onClick:F,className:"w-fit",type:"button",children:[s.jsx(R,{name:"emotion-happy",className:"size-4"}),r("gitView.commit.addGitmoji")]}),e[32]=A,e[33]=F,e[34]=r,e[35]=H):H=e[35];const X=l||g!==null||j||t===0;let T;e[36]!==r?(T=r("gitView.commit.generateAria"),e[36]=r,e[37]=T):T=e[37];let Y;e[38]!==l?(Y=l?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"ai-generate-2",className:"size-4 text-primary"}),e[38]=l,e[39]=Y):Y=e[39];let K;e[40]!==r?(K=r("gitView.commit.generate"),e[40]=r,e[41]=K):K=e[41];let G;e[42]!==K?(G=s.jsx("span",{className:"commit-actions__label",children:K}),e[42]=K,e[43]=G):G=e[43];let O;e[44]!==f||e[45]!==X||e[46]!==T||e[47]!==Y||e[48]!==G?(O=s.jsxs(J,{variant:"outline",size:"sm",onClick:f,disabled:X,type:"button","aria-label":T,className:"commit-actions__btn",children:[Y,G]}),e[44]=f,e[45]=X,e[46]=T,e[47]=Y,e[48]=G,e[49]=O):O=e[49];let B;e[50]===Symbol.for("react.memo_cache_sentinel")?(B=s.jsx("div",{className:"flex-1"}),e[50]=B):B=e[50];const q=!h||l;let i;e[51]!==r?(i=r("gitView.commit.commitAria"),e[51]=r,e[52]=i):i=e[52];let n;e[53]!==g||e[54]!==r?(n=g==="commit"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label",children:r("gitView.commit.committing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"git-commit",className:"size-4"}),s.jsx("span",{className:"commit-actions__label",children:r("gitView.commit.commit")})]}),e[53]=g,e[54]=r,e[55]=n):n=e[55];let a;e[56]!==d||e[57]!==q||e[58]!==i||e[59]!==n?(a=s.jsx(J,{size:"sm",variant:"outline",onClick:d,disabled:q,className:"commit-actions__btn whitespace-nowrap","aria-label":i,children:n}),e[56]=d,e[57]=q,e[58]=i,e[59]=n,e[60]=a):a=e[60];let c;e[61]!==h||e[62]!==g||e[63]!==l||e[64]!==z||e[65]!==E||e[66]!==r?(c=z?s.jsxs(fe,{children:[s.jsx(me,{asChild:!0,children:s.jsx(J,{variant:"default",size:"sm",onClick:()=>E(),disabled:!h||l,className:"h-7 w-7 p-0","aria-label":r("gitView.commit.pushAria"),children:g==="commitAndPush"?s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}):s.jsx(R,{name:"arrow-up",className:"size-3.5"})})}),s.jsx(ue,{side:"top",children:s.jsx("p",{children:r("gitView.commit.push")})})]}):s.jsx(J,{size:"sm",variant:"default",onClick:()=>E(),disabled:!h||l,className:"commit-actions__btn","aria-label":r("gitView.commit.pushAria"),children:g==="commitAndPush"?s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"loader-4",className:"size-4 animate-spin"}),s.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:r("gitView.commit.pushing")})]}):s.jsxs(s.Fragment,{children:[s.jsx(R,{name:"arrow-up",className:"size-3.5"}),s.jsx("span",{className:"commit-actions__label commit-actions__label--push",children:r("gitView.commit.push")})]})}),e[61]=h,e[62]=g,e[63]=l,e[64]=z,e[65]=E,e[66]=r,e[67]=c):c=e[67];let k;e[68]!==O||e[69]!==a||e[70]!==c?(k=s.jsxs("div",{className:"@container/commit-actions flex items-center gap-2 min-w-0",children:[O,B,a,c]}),e[68]=O,e[69]=a,e[70]=c,e[71]=k):k=e[71];let v;e[72]!==L||e[73]!==H||e[74]!==k||e[75]!==I?(v=s.jsxs("div",{className:"flex flex-col gap-3 px-0 pt-1 pb-3",children:[I,L,H,k]}),e[72]=L,e[73]=H,e[74]=k,e[75]=I,e[76]=v):v=e[76];let _;return e[77]!==v||e[78]!==V?(_=s.jsxs("section",{className:"border-0 bg-transparent rounded-none",children:[V,v]}),e[77]=v,e[78]=V,e[79]=_):_=e[79],_};export{Ye as C,qe as a};
@@ -1,4 +0,0 @@
1
- import{R as o,j as n,f as be}from"./vendor-react-BUCujlKS.js";import{W as pn,a as at,u as te,F as Ge}from"./index-DIvDEKE-.js";import{f as we,V as Et,ab as hn,bo as gn,ad as xn,ac as bn,ae as wn,af as ae,y as vt,k as yn,hF as vn,hG as jn,hH as Sn,cB as Nn,t as Ke,hI as Fn,am as Be,B as me,I as A,h as le,a6 as kn,a7 as Cn,a8 as Dn,hs as Bt,hJ as Rn,fs as An,fx as $e,a0 as En,c0 as it,ao as Vt,al as Bn,a$ as Vn,b1 as Ln,fy as Tn,b2 as Mn}from"./useAppFontEffects-KP8_yiGW.js";import{c as _n,p as In}from"./vendor-zustand-BAGL70zf.js";import{P as On}from"./PierreDiffViewer-CY2bx_SB.js";import{u as zn,v as Pn,g as Gn,W as $n}from"./main-DLlfDjQ_.js";import{f as Kn}from"./patchFileDiff-CjRR5ESs.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zod-BLfBSgBh.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.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"./contextPanelEmbeddedChat-C9abMBTb.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"./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-DrTPkHl4.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-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./web-components-DOXvU-tB.js";import"./computeVirtualFileMetrics-CZ0xPeaT.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"./VirtualizedFileDiff-BP7ebDFF.js";import"./isDiffPlainText-ZBvDxhVB.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";import"./useInlineCommentController-HIjtuhxD.js";import"./runtimeEndpointReset-D6SmNZaP.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";import"./useRootScrollLock-BSiQ5F75.js";import"./scheduledTasksApi-mjMDet_H.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";const Hn="openchamber.git-base-branch",Wn=100,He=(s,e)=>JSON.stringify([at(),s,e]),jt=_n()(In((s,e)=>({overrides:{},getOverride:(i,a)=>!i||!a?null:e().overrides[He(i,a)]??null,setOverride:(i,a,d)=>{!i||!a||!d||s(u=>{const p=He(i,a),g=Object.entries({...u.overrides,[p]:d});for(;g.length>Wn;)g.shift();return{overrides:Object.fromEntries(g)}})},clearOverride:(i,a)=>{!i||!a||s(d=>{const u=He(i,a);if(!(u in d.overrides))return d;const p={...d.overrides};return delete p[u],{overrides:p}})}}),{name:Hn,storage:pn(),partialize:s=>({overrides:s.overrides})})),Un=(s,e)=>!!s&&e!==null&&s!==e,qn=(s,e,i,a)=>i?s===null||a&&e===null?!0:e!==null&&s===e:!1,Xn=(s,e)=>s==="branch"&&!e?"working":s,Jn=(s,e,i)=>JSON.stringify([s,e,i]),Yn=(s,e,i,a,d,u)=>{const p=o.useRef({directory:"",attempts:0}),[g,f]=o.useState(()=>({directory:"",exhausted:!1})),m=o.useRef(d);m.current=d;const x=!!s&&g.directory===s&&g.exhausted;return o.useEffect(()=>{if(!s||!e||a||i)return;const c=p.current.directory===s?p.current.attempts:0;if(c>=u){g.directory===s&&g.exhausted||f({directory:s,exhausted:!0});return}p.current={directory:s,attempts:c+1},m.current()},[s,g,a,e,i,u]),x},Qn=(s,e,i,a)=>{const[d,u]=o.useState(()=>new Map),p=o.useRef(d);p.current=d;const g=o.useRef(i);g.current=i;const f=o.useCallback((m,x)=>{const c=new Map(p.current);if(x===null){if(!c.delete(m))return}else c.set(m,x);p.current=c,u(c)},[]);return o.useEffect(()=>{s&&(p.current=new Map,u(p.current))},[s]),o.useEffect(()=>{const m=g.current;if(!s||!m||!e)return;let x=!1;const c=new Set;for(const v of e.split("\0"))p.current.has(v)||(c.add(v),f(v,a),m(v).then(S=>{x||(c.delete(v),f(v,S))}).catch(()=>{x||(c.delete(v),f(v,null))}));return()=>{x=!0;for(const v of c)f(v,null)}},[e,a,s,f]),d},St=(s,e)=>{if(e.length===0)return null;let i=null,a=null;for(const u of e)u.top<=s?(!i||u.top>i.top)&&(i=u):(!a||u.top<a.top)&&(a=u);const d=i??a;return d?{path:d.path,topOffset:d.top-s}:null},Zn=(s,e,i,a)=>Math.min(Math.max(0,a),Math.max(0,s+i-e)),Nt=s=>{if(!s)return null;const e=s.split(`
2
- `);let i=null;for(const a of e){const d=a.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(d){const u=Number.parseInt(d[1]??"",10);i=Number.isFinite(u)&&u>=1?u:null;continue}if(i!==null){if(a.startsWith(" ")){i+=1;continue}if(a.startsWith("+"))return i;if(a.startsWith("-"))return Math.max(1,i)}}return null},es=1100,ts=15e3,Ft=500,kt=300,ns=1e6,ss=3,rs=s=>s<=6?s:s<=12?6:s<=25?4:2,is={original:"",modified:"",isBinary:!1,contextMode:"patch"},os=3,as=o.memo(()=>{const s=be.c(4),{t:e}=we();let i;s[0]!==e?(i=e("diffView.binary.unavailable"),s[0]=e,s[1]=i):i=s[1];let a;return s[2]!==i?(a=n.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:n.jsx("div",{className:"typography-meta text-muted-foreground",children:i})}),s[2]=i,s[3]=a):a=s[3],a}),Lt={"?":{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"}},ls=Lt.M,cs=s=>{const e=s.index?.trim(),i=s.working_dir?.trim();return e&&e!=="?"?e.charAt(0):i?i.charAt(0):e?.charAt(0)||i?.charAt(0)||"M"},Tt=s=>{const e=cs(s);return Lt[e]??ls},fs=s=>{const{index:e,working_dir:i}=s;return e==="A"||i==="A"||e==="?"||i==="?"},Ct=s=>{const e=s.index?.trim();return!!(e&&e!=="?")},Dt=s=>!!s.working_dir?.trim()||s.index==="?",us=(s,e)=>An(s,e),Rt=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/,""),At=(s,e)=>{const i=s.split(`
3
- `),a=e.split(`
4
- `),d=Math.min(i.length,a.length);for(let u=0;u<d;u+=1)if(i[u]!==a[u])return u+1;return a.length>i.length?i.length+1:i.length>a.length?Math.max(1,a.length):1},ds=s=>/^Binary files .+ differ$/m.test(s)||/^GIT binary patch$/m.test(s),ms=s=>Array.isArray(s)?s.filter(e=>!e||typeof e!="object"?!1:typeof e.file=="string"):[],ps=s=>s==="added"?"A":s==="deleted"?"D":"M",ot=(s,e,i)=>ds(e)?{original:"",modified:"",isBinary:!0,patch:e,contextMode:i}:{original:"",modified:"",patch:e,fileDiff:Kn(s,e),contextMode:i},Mt=(s,e,i)=>{const a=s??0,d=e??0;return!a&&!d?null:n.jsxs("span",{className:le("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",i?.className),children:[a?n.jsxs("span",{style:{color:"var(--status-success)"},children:["+",a]}):null,d?n.jsxs("span",{style:{color:"var(--status-error)"},children:["-",d]}):null]})},hs=o.memo(s=>{const e=be.c(58),{scope:i,workingCount:a,stagedCount:d,turnCount:u,branchCount:p,showBranchOption:g,onScopeChange:f}=s,{t:m}=we(),[x,c]=o.useState(!1),v=i==="staged"?d:i==="turn"?u:i==="branch"?p??0:a;let S;e[0]!==i||e[1]!==m?(S=m(i==="staged"?"diffView.scope.staged":i==="turn"?"diffView.scope.lastTurn":i==="branch"?"diffView.scope.branch":"diffView.scope.changed"),e[0]=i,e[1]=m,e[2]=S):S=e[2];const O=S;let T;e[3]!==m?(T=m("diffView.scope.selectorAria"),e[3]=m,e[4]=T):T=e[4];let ne;e[5]!==v?(ne=n.jsxs("span",{className:"diff-toolbar__scope-count",children:[": ",v]}),e[5]=v,e[6]=ne):ne=e[6];let y;e[7]!==O||e[8]!==ne?(y=n.jsxs("span",{className:"whitespace-nowrap",children:[O,ne]}),e[7]=O,e[8]=ne,e[9]=y):y=e[9];let V;e[10]===Symbol.for("react.memo_cache_sentinel")?(V=n.jsx(A,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"}),e[10]=V):V=e[10];let M;e[11]!==T||e[12]!==y?(M=n.jsx(Vn,{asChild:!0,children:n.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":T,children:[y,V]})}),e[11]=T,e[12]=y,e[13]=M):M=e[13];let q;e[14]!==f?(q=ie=>{(ie==="working"||ie==="staged"||ie==="turn"||ie==="branch")&&(f?.(ie),c(!1))},e[14]=f,e[15]=q):q=e[15];let X;e[16]!==m?(X=m("diffView.scope.changed"),e[16]=m,e[17]=X):X=e[17];let se;e[18]!==X?(se=n.jsx("span",{children:X}),e[18]=X,e[19]=se):se=e[19];let J;e[20]!==a?(J=n.jsx("span",{className:"typography-meta text-muted-foreground",children:a}),e[20]=a,e[21]=J):J=e[21];let Y;e[22]!==J||e[23]!==se?(Y=n.jsx($e,{value:"working",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[se,J]})}),e[22]=J,e[23]=se,e[24]=Y):Y=e[24];let C;e[25]!==m?(C=m("diffView.scope.staged"),e[25]=m,e[26]=C):C=e[26];let _;e[27]!==C?(_=n.jsx("span",{children:C}),e[27]=C,e[28]=_):_=e[28];let re;e[29]!==d?(re=n.jsx("span",{className:"typography-meta text-muted-foreground",children:d}),e[29]=d,e[30]=re):re=e[30];let L;e[31]!==_||e[32]!==re?(L=n.jsx($e,{value:"staged",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[_,re]})}),e[31]=_,e[32]=re,e[33]=L):L=e[33];let G;e[34]!==m?(G=m("diffView.scope.lastTurn"),e[34]=m,e[35]=G):G=e[35];let $;e[36]!==G?($=n.jsx("span",{children:G}),e[36]=G,e[37]=$):$=e[37];let E;e[38]!==u?(E=n.jsx("span",{className:"typography-meta text-muted-foreground",children:u}),e[38]=u,e[39]=E):E=e[39];let K;e[40]!==$||e[41]!==E?(K=n.jsx($e,{value:"turn",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[$,E]})}),e[40]=$,e[41]=E,e[42]=K):K=e[42];let Q;e[43]!==p||e[44]!==g||e[45]!==m?(Q=g?n.jsx($e,{value:"branch",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[n.jsx("span",{children:m("diffView.scope.branch")}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:p??"…"})]})}):null,e[43]=p,e[44]=g,e[45]=m,e[46]=Q):Q=e[46];let z;e[47]!==i||e[48]!==Y||e[49]!==L||e[50]!==K||e[51]!==Q||e[52]!==q?(z=n.jsx(Ln,{align:"start",className:"w-40",children:n.jsxs(Tn,{value:i,onValueChange:q,children:[Y,L,K,Q]})}),e[47]=i,e[48]=Y,e[49]=L,e[50]=K,e[51]=Q,e[52]=q,e[53]=z):z=e[53];let H;return e[54]!==x||e[55]!==z||e[56]!==M?(H=n.jsxs(Mn,{open:x,onOpenChange:c,children:[M,z]}),e[54]=x,e[55]=z,e[56]=M,e[57]=H):H=e[57],H}),gs=o.memo(s=>{const e=be.c(11),{changedFiles:i,selectedFile:a,onSelectFile:d}=s,{t:u}=we();if(i.length===0)return null;let p;if(e[0]!==i||e[1]!==d||e[2]!==a||e[3]!==u){let f;e[5]!==d||e[6]!==a||e[7]!==u?(f=m=>{const x=Tt(m),c=a===m.path;return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>d(m.path),className:le("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",c?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[n.jsx(Vt,{filePath:m.path,className:"h-3.5 w-3.5 flex-shrink-0"}),n.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:x.color},title:u(x.descriptionKey),"aria-label":u(x.descriptionKey),children:x.code}),n.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:m.path,children:m.path}),Mt(m.insertions,m.deletions)]})},m.path)},e[5]=d,e[6]=a,e[7]=u,e[8]=f):f=e[8],p=i.map(f),e[0]=i,e[1]=d,e[2]=a,e[3]=u,e[4]=p}else p=e[4];let g;return e[9]!==p?(g=n.jsx(it,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:n.jsx("ul",{className:"flex flex-col gap-1",children:p})}),e[9]=p,e[10]=g):g=e[10],g}),xs=o.memo(s=>{const e=be.c(20),{filePath:i,diff:a,renderSideBySide:d}=s,{t:u}=we(),p=a.original.length>0,g=a.modified.length>0,f=d?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",m=d?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x={contain:"layout"},e[0]=x):x=e[0];let c;e[1]!==a.original||e[2]!==i||e[3]!==p||e[4]!==m||e[5]!==d||e[6]!==u?(c=p&&n.jsxs("div",{className:m,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:u("diffView.image.original")}),n.jsx("img",{src:a.original,alt:u("diffView.image.originalAlt",{path:i}),className:d?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=a.original,e[2]=i,e[3]=p,e[4]=m,e[5]=d,e[6]=u,e[7]=c):c=e[7];let v;e[8]!==a.modified||e[9]!==i||e[10]!==g||e[11]!==p||e[12]!==m||e[13]!==d||e[14]!==u?(v=g&&n.jsxs("div",{className:m,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:u(p?"diffView.image.modified":"diffView.image.new")}),n.jsx("img",{src:a.modified,alt:u("diffView.image.modifiedAlt",{path:i}),className:d?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=a.modified,e[9]=i,e[10]=g,e[11]=p,e[12]=m,e[13]=d,e[14]=u,e[15]=v):v=e[15];let S;return e[16]!==f||e[17]!==c||e[18]!==v?(S=n.jsx("div",{className:"w-full overflow-auto p-4",style:x,children:n.jsxs("div",{className:f,children:[c,v]})}),e[16]=f,e[17]=c,e[18]=v,e[19]=S):S=e[19],S}),bs=o.memo(s=>{const e=be.c(16),{filePath:i,diff:a,renderSideBySide:d,wrapLines:u}=s;let p;e[0]!==i?(p=Bn(i)||"text",e[0]=i,e[1]=p):p=e[1];const g=p;if(a.isBinary){let x;return e[2]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx(as,{}),e[2]=x):x=e[2],x}if(Be(i)){let x;return e[3]!==a||e[4]!==i||e[5]!==d?(x=n.jsx(xs,{filePath:i,diff:a,renderSideBySide:d}),e[3]=a,e[4]=i,e[5]=d,e[6]=x):x=e[6],x}let f;e[7]===Symbol.for("react.memo_cache_sentinel")?(f={contain:"layout"},e[7]=f):f=e[7];let m;return e[8]!==a.fileDiff||e[9]!==a.modified||e[10]!==a.original||e[11]!==i||e[12]!==g||e[13]!==d||e[14]!==u?(m=n.jsx("div",{className:"w-full",style:f,children:n.jsx(On,{original:a.original,modified:a.modified,fileDiff:a.fileDiff,language:g,fileName:i,renderSideBySide:d,wrapLines:u,layout:"inline"})}),e[8]=a.fileDiff,e[9]=a.modified,e[10]=a.original,e[11]=i,e[12]=g,e[13]=d,e[14]=u,e[15]=m):m=e[15],m}),ws=o.memo(s=>{const e=be.c(7),{filePath:i,staged:a,busyAction:d,disabled:u,onAction:p}=s,{t:g}=we();let f;return e[0]!==d||e[1]!==u||e[2]!==i||e[3]!==p||e[4]!==a||e[5]!==g?(f=n.jsx("div",{className:"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:a?n.jsx(rt,{label:g("gitView.changes.unstageFileAria",{path:i}),icon:"arrow-go-back",loading:d==="unstage",disabled:u,onClick:()=>p("unstage")}):n.jsxs(n.Fragment,{children:[n.jsx(rt,{label:g("gitView.changes.revertFileAria",{path:i}),icon:"arrow-go-back",loading:d==="discard",disabled:u,tone:"failure",onClick:()=>p("discard")}),n.jsx(rt,{label:g("gitView.changes.stageFileAria",{path:i}),icon:"add",loading:d==="stage",disabled:u,tone:"success",onClick:()=>p("stage")})]})}),e[0]=d,e[1]=u,e[2]=i,e[3]=p,e[4]=a,e[5]=g,e[6]=f):f=e[6],f}),rt=s=>{const e=be.c(14),{label:i,icon:a,loading:d,disabled:u,tone:p,onClick:g}=s,f=p==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",m=p==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]";let x;e[0]!==f||e[1]!==m?(x=le("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",f,m),e[0]=f,e[1]=m,e[2]=x):x=e[2];let c;e[3]!==g?(c=O=>{O.stopPropagation(),g()},e[3]=g,e[4]=c):c=e[4];let v;e[5]!==a||e[6]!==d?(v=d?n.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(A,{name:a,className:a==="add"?"size-4":"size-3.5"}),e[5]=a,e[6]=d,e[7]=v):v=e[7];let S;return e[8]!==u||e[9]!==i||e[10]!==x||e[11]!==c||e[12]!==v?(S=n.jsx(me,{variant:"ghost",size:"sm",className:x,disabled:u,title:i,"aria-label":i,onClick:c,children:v}),e[8]=u,e[9]=i,e[10]=x,e[11]=c,e[12]=v,e[13]=S):S=e[13],S},ys=o.memo(({directory:s,file:e,layout:i,wrapLines:a,isSelected:d,isExpanded:u,isMounted:p,onSelect:g,onExpandedChange:f,registerSectionRef:m,showOpenInEditorAction:x=!1,isOpeningInEditor:c=!1,onOpenInEditor:v,staged:S=!1,loadFullFiles:O=!1,initialDiffData:T=null,readOnlyActions:ne=!1})=>{const{t:y}=we(),{git:V}=Et(),M=ae(o.useCallback(w=>w.directories.get(s)?.diffCache.get(e.path)??null,[s,e.path])),q=ae(w=>w.setDiff),X=ae(w=>w.fetchStatus),se=te(w=>w.setDiffFileLayout),[J,Y]=o.useState(0),[C,_]=o.useState(null),[re,L]=o.useState(!1),[G,$]=o.useState(null),[E,K]=o.useState(!1),[Q,z]=o.useState(null),[H,ie]=o.useState(null),ce=o.useRef(null),Ce=o.useRef(null),pe=o.useMemo(()=>Tt(e),[e]),Ve=i==="side-by-side",ye=O?"full":"patch",he=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,Z=o.useMemo(()=>T||(S?H:Q||(M?{original:M.original,modified:M.modified,isBinary:M.isBinary,contextMode:"full"}:null)),[M,T,Q,S,H]),De=Z?.contextMode===ye,b=o.useCallback(w=>{Ce.current=w,m(e.path,w)},[e.path,m]),ge=o.useCallback(w=>{f(e.path,w)},[e.path,f]),fe=o.useCallback(()=>{g(e.path)},[e.path,g]);o.useEffect(()=>{S?ie(null):z(null),_(null),ce.current=null},[he,S]),o.useEffect(()=>{if(!u||!p)return;if(!s||T||Z&&De){ce.current=null,L(!1);return}const w=`${s}::${e.path}::${S?"staged":"unstaged"}::${he}::${ye}::${J}`;if(ce.current===w)return;ce.current=w,_(null),L(!0);let D=!1;const de=at(),Le=O?ns:ss,Te=Be(e.path)?V.getGitFileDiff(s,{path:e.path,staged:S}):V.getGitDiff(s,{path:e.path,staged:S,contextLines:Le}),Me=ts,_e=new Promise((B,W)=>{setTimeout(()=>W(new Error(`Timed out after ${Me}ms`)),Me)});return Promise.race([Te,_e]).then(B=>{if(!D){if("diff"in B){const W=ot(e.path,B.diff,ye);S?ie(W):z(W)}else{const W={original:B.original??"",modified:B.modified??"",isBinary:B.isBinary,contextMode:"full"};S?ie(W):q(s,e.path,W,de)}L(!1)}}).catch(B=>{if(D)return;const W=B instanceof Error?B.message:String(B);_(W),L(!1)}),()=>{D=!0,ce.current===w&&(ce.current=null)}},[ye,Z,De,J,s,e.path,he,V,T,u,p,O,q,S]);const Re=o.useCallback(()=>{ge(!u),fe()},[ge,fe,u]),ue=o.useCallback(async w=>{if(!(!s||G!==null)){$(w);try{w==="stage"?await V.stageGitFile(s,e.path):w==="unstage"?await V.unstageGitFile(s,e.path):await V.revertGitFile(s,e.path,{scope:"working"}),Y(D=>D+1),await X(s,V)}catch(D){const de=w==="unstage"?"gitView.toast.unstageFileFailed":w==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.revertFailed";Ke.error(D instanceof Error?D.message:y(de))}finally{$(D=>D===w?null:D)}}},[s,X,e.path,G,V,y]);return n.jsxs("div",{ref:b,className:"scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0",children:[n.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:n.jsxs("div",{role:"button",tabIndex:0,onClick:Re,onKeyDown:w=>{w.target===w.currentTarget&&(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),Re())},className:le("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",d?"bg-[var(--interactive-selection)]/35":null),children:[n.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),n.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[n.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:u?n.jsx(A,{name:"arrow-down-s",className:"size-4"}):n.jsx(A,{name:"arrow-right-s",className:"size-4"})}),n.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:pe.color},title:y(pe.descriptionKey),"aria-label":y(pe.descriptionKey),children:pe.code}),n.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:e.path,children:n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(Vt,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const w=e.path.lastIndexOf("/");if(w===-1)return n.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:e.path});const D=e.path.slice(0,w),de=e.path.slice(w+1);return n.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[n.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:D}),n.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[n.jsx("span",{className:"text-muted-foreground",children:"/"}),n.jsx("span",{className:"text-foreground",children:de})]})]})})()]})})]}),n.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[Mt(e.insertions,e.deletions),x&&v?n.jsx(me,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:y("diffView.actions.openFileInEditorAtChange"),onClick:w=>{w.stopPropagation(),v(e.path,Z)},disabled:c,children:c?n.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(A,{name:"edit",className:"size-3.5"})}):null,n.jsx(Bt,{mode:Ve?"side-by-side":"unified",onModeChange:w=>{const D=w==="side-by-side"?"side-by-side":"inline";se(e.path,D)},className:"opacity-70"})]})]})}),u&&n.jsxs("div",{className:"relative bg-background overflow-hidden",children:[!p&&!C?n.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,C?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:y("diffView.state.failedToLoadDiff")}),n.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:C}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>Y(w=>w+1),children:y("diffView.actions.retry")})]}):null,p&&re&&!Z&&!C?n.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),y("diffView.state.loadingDiff")]}):null,p&&Z&&!E&&e.insertions+e.deletions>Ft?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:y("diffView.state.largeDiff",{count:e.insertions+e.deletions})}),n.jsx("div",{className:"typography-meta text-muted-foreground",children:y("diffView.state.largeDiffDescription")}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>K(!0),children:y("diffView.actions.renderAnyway")})]}):null,p&&Z&&(E||e.insertions+e.deletions<=Ft)?n.jsxs(n.Fragment,{children:[n.jsx(bs,{filePath:e.path,diff:Z,renderSideBySide:Ve,wrapLines:a}),n.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:n.jsx("div",{className:"pointer-events-auto",children:ne?null:n.jsx(ws,{filePath:e.path,staged:S,busyAction:G,disabled:G!==null,onAction:ue})})})]}):null]})]})}),Mi=({hideStackedFileSidebar:s=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:i=!1,showOpenInEditorAction:a=!1,diffScope:d="all",onDiffScopeChange:u,targetFilePath:p=null,flushContent:g=!1})=>{const{t:f}=we(),{git:m,files:x}=Et(),c=hn(),v=te(t=>t.openContextSurface),S=zn(t=>t.requestSource),{screenWidth:O,isMobile:T}=gn(),ne=xn(c??null),y=bn(c??null),V=wn(c??null),M=ae(t=>t.setActiveDirectory),q=ae(t=>t.ensureStatus),X=ae(t=>t.fetchStatus),se=ae(t=>t.fetchBranches),J=ae(t=>t.clearDiffCache),Y=ae(t=>t.setDiff),[C,_]=o.useState(null),[re,L]=o.useState(!1),[G,$]=o.useState(null),[E,K]=o.useState(()=>new Set),[Q,z]=o.useState(()=>new Set),[H,ie]=o.useState(!1),[ce,Ce]=o.useState(0),[pe,Ve]=o.useState(()=>new Map),[ye,he]=o.useState(!1),[Z,De]=o.useState(!1),[b,ge]=o.useState(d);o.useEffect(()=>{ge(d)},[d]);const fe=te(t=>t.pendingDiffFile),Re=te(t=>t.pendingDiffStaged),ue=te(t=>t.pendingDiffScope),w=te(t=>t.setPendingDiffFile),D=te(t=>t.diffLayoutPreference),de=te(t=>t.diffFileLayout),Le=te(t=>t.setDiffFileLayout),Te=te(t=>t.diffWrapLines),Me=te(t=>t.setDiffWrapLines),_e=te(t=>t.openContextFileAtLine),B=vt(t=>t.currentSessionId),W=yn(B??"",c??void 0),We=Te,Ue=b==="staged"?!0:b==="working"?!1:null,Ie=Ue??re,qe=T||O<=768,_t=!!B&&b!=="turn"&&!qe&&!Ge(),It=b!=="turn"&&!qe&&!Ge(),Ot=!s&&!qe&&O>=1024,ve=o.useRef(null),Ae=o.useRef(new Map),xe=o.useRef(null),P=o.useRef(null),je=o.useRef(!1),Se=o.useRef(null),lt=o.useRef(null),Xe=o.useRef(null),Je=o.useRef(null),ct=o.useCallback(()=>{const t=ve.current;if(!t)return null;const r=t.getBoundingClientRect().top,l=[];for(const[h,j]of Ae.current)j&&l.push({path:h,top:j.getBoundingClientRect().top});return St(r,l)},[]),Ne=o.useCallback(()=>{xe.current=null,je.current=!1,$(null),P.current!==null&&(window.cancelAnimationFrame(P.current),P.current=null)},[]),Fe=o.useCallback(t=>{K(r=>{if(r.has(t))return r;const l=new Set(r);return l.add(t),l})},[]),Ee=o.useMemo(()=>{for(let t=W.length-1;t>=0;t-=1){const r=W[t];if(r.role==="user")return ms(r.summary?.diffs)}return[]},[W]),zt=o.useMemo(()=>{const t=new Map;for(const r of Ee)if(r.file){if(typeof r.patch=="string"){t.set(r.file,ot(r.file,r.patch,"patch"));continue}t.set(r.file,{original:r.before??"",modified:r.after??"",contextMode:"full"})}return t},[Ee]),Pt=o.useMemo(()=>y?.files?y.files.filter(Dt).length:0,[y]),Gt=o.useMemo(()=>y?.files?y.files.filter(Ct).length:0,[y]),$t=Ee.length,k=y?.current??null,ke=ae(t=>c?t.directories.get(c)?.branches??null:null),Kt=ae(t=>c?t.directories.get(c)?.isLoadingBranches??!1:!1),Ht=o.useCallback(()=>{c&&se(c,m)},[c,se,m]),Wt=Yn(c??null,ne!==!1,Kt,!!ke,Ht,os),ft=o.useMemo(()=>{const t=y?.tracking?.trim().split("/")[0];return(t&&ke?.defaultBranches?.[t])??ke?.defaultBranches?.origin??null},[ke,y?.tracking]),Ye=!Ge()&&Un(k,ft),Ut=y!==null,ut=Ge()||Wt||qn(k,ft,Ut,ke!==null),qt=jt(t=>t.setOverride),Xt=jt(o.useCallback(t=>c&&k?t.overrides[He(c,k)]??null:null,[k,c])),[Jt,Qe]=o.useState(null),[Yt,Ze]=o.useState(!1),[dt,Qt]=o.useState("");o.useEffect(()=>{const t=Xn(b,!ut);t!==b&&(ge(t),t==="working"&&u?.("working"))},[b,ut,u]),o.useEffect(()=>{if(!Ye||!c||!k){Qe(null),Ze(!1);return}let t=!1;return Ze(!1),vn(c,k).then(r=>{t||Qe(r.base)}).catch(()=>{t||Qe(null)}).finally(()=>{t||Ze(!0)}),()=>{t=!0}},[k,c,Ye]);const oe=Xt??Jt,[Oe,mt]=o.useState(null),[pt,ht]=o.useState(null),ze=o.useRef(0),et=o.useCallback(()=>{if(!c||!k||!oe)return;const t=ze.current+1;ze.current=t,mt(null),ht(null),jn(c,{base:oe,head:k}).then(r=>{ze.current===t&&mt(r)}).catch(r=>{ze.current===t&&ht(r instanceof Error?r.message:f("diffView.branch.loadError"))})},[oe,k,c,f]);o.useEffect(()=>{b==="branch"&&et()},[b,et]);const gt=b==="branch"&&c&&k&&oe?Jn(c,oe,k):null,Zt=o.useMemo(()=>b==="branch"?Array.from(E).sort().join("\0"):"",[b,E]),en=o.useCallback(t=>!c||!oe||!k?Promise.reject(new Error("branch range is unavailable")):Sn(c,{base:oe,head:k,path:t}).then(r=>ot(t,r.diff,"patch")),[oe,k,c]),tn=Qn(gt,Zt,gt?en:null,is),nn=Oe?.length??null,N=o.useMemo(()=>{if(b==="branch")return(Oe??[]).map(l=>({path:l.path,index:"",working_dir:l.status,insertions:0,deletions:0,isNew:l.status==="A"})).sort((l,h)=>l.path.localeCompare(h.path));if(b==="turn")return Ee.map(l=>({path:l.file??"",index:"",working_dir:ps(l.status),insertions:l.additions??0,deletions:l.deletions??0,isNew:l.status==="added"})).filter(l=>l.path).sort((l,h)=>l.path.localeCompare(h.path));if(!y?.files)return[];const t=y.diffStats??{},r=b==="staged"?Ct:b==="working"?Dt:()=>!0;return y.files.filter(r).map(l=>({...l,insertions:t[l.path]?.insertions??0,deletions:t[l.path]?.deletions??0,isNew:fs(l)})).sort((l,h)=>l.path.localeCompare(h.path))},[b,Oe,Ee,y]),tt=o.useMemo(()=>N.map(t=>t.path).join("\0"),[N]);o.useEffect(()=>{const t=tt?tt.split("\0"):[],r=new Set(t),l=`${c??""}:${b}:${e?"collapsed":"default"}`,h=lt.current!==l;lt.current=l,K(j=>{if(h){const R=e?0:rs(t.length);return new Set(t.slice(0,R))}let I=!1;const F=new Set;for(const R of j){if(!r.has(R)){I=!0;continue}F.add(R)}return I?F:j}),z(j=>{if(h)return new Set;let I=!1;const F=new Set;for(const R of j){if(!r.has(R)){I=!0;continue}F.add(R)}return I?F:j})},[b,tt,c,e]);const xt=o.useCallback(()=>{Se.current=null;const t=ve.current;if(!t)return;const r=t.getBoundingClientRect(),l=r.top-kt,h=r.bottom+kt,j={},I=[];for(const[F,R]of Ae.current){if(!R)continue;const U=R.getBoundingClientRect();I.push({path:F,top:U.top}),E.has(F)&&(U.bottom<l||U.top>h||(j[F]=!0))}Xe.current=St(r.top,I),z(F=>{let R=!1;const U=new Set(F);for(const yt of Object.keys(j))U.has(yt)||(U.add(yt),R=!0);return R?U:F})},[E]),ee=o.useCallback(()=>{typeof window>"u"||Se.current===null&&(Se.current=window.requestAnimationFrame(xt))},[xt]);o.useEffect(()=>{const t=ve.current;if(t)return ee(),t.addEventListener("scroll",ee,{passive:!0}),window.addEventListener("resize",ee),()=>{t.removeEventListener("scroll",ee),window.removeEventListener("resize",ee),Se.current!==null&&(window.cancelAnimationFrame(Se.current),Se.current=null)}},[N,E,ee]);const nt=o.useCallback(t=>{const r=de[t.path];if(r)return r;if(D==="inline")return"inline";if(D==="side-by-side")return"side-by-side";const l=O<es;return t.isNew||l?"inline":"side-by-side"},[de,D,O]),bt=o.useMemo(()=>N.length===0?null:N.every(t=>nt(t)==="side-by-side")?"side-by-side":"inline",[N,nt]);o.useEffect(()=>{c&&(M(c),q(c,m))},[c,M,q,m]),o.useEffect(()=>{if(c)return Nn.onGitRefreshHint(t=>{Rt(t.directory)===Rt(c)&&(t.paths?.length&&(Je.current=ct()??Xe.current,J(c,t.paths),Ve(r=>{const l=new Map(r);for(const h of t.paths??[])l.set(h,(l.get(h)??0)+1);return l})),X(c,m,{silent:!0}))})},[ct,J,c,X,m]),o.useLayoutEffect(()=>{const t=Je.current;if(!t)return;Je.current=null;const r=ve.current,l=Ae.current.get(t.path);if(!r||!l)return;const h=r.getBoundingClientRect().top,j=l.getBoundingClientRect().top-h;r.scrollTop=Zn(r.scrollTop,t.topOffset,j,r.scrollHeight-r.clientHeight),Xe.current=t},[pe]),o.useEffect(()=>{b!=="all"&&!ue||fe&&(ue&&ge(ue),_(fe),L(ue==="staged"||!ue&&Re),w(null),je.current=!0,xe.current=fe,Fe(fe),Ce(t=>t+1))},[b,Fe,fe,ue,Re,w]),o.useEffect(()=>{if(b==="all")return;const t=p?.trim();t&&(_(t),L(b==="staged"),je.current=!0,xe.current=t,Fe(t),Ce(r=>r+1))},[b,Fe,p]),o.useEffect(()=>{if(!C)return;N.some(r=>r.path===C)||(_(null),L(!1))},[N,C]);const sn=o.useCallback((t,r)=>{const l=Ae.current;r?l.set(t,r):l.delete(t),ee()},[ee]),rn=o.useCallback((t,r)=>{Ne(),K(l=>{const h=l.has(t);if(r===h)return l;const j=new Set(l);return r?j.add(t):j.delete(t),j}),r||z(l=>{if(!l.has(t))return l;const h=new Set(l);return h.delete(t),h}),ee()},[Ne,ee]),on=o.useCallback(()=>{Ne(),K(t=>t.size>0?new Set:new Set(N.map(r=>r.path))),z(new Set),ee()},[Ne,N,ee]),an=o.useCallback(async t=>{if(!B)return;const r=vt.getState().getDirectoryForSession(B)||c||"";if(!r){Ke.error(f("diffView.reviewDialog.toast.noSessionDirectory"));return}De(!0);try{await Fn({originalSessionID:B,directory:r,providerID:t.providerID,modelID:t.modelID,agent:t.agent||void 0,variant:t.variant||void 0,generateHandoff:t.generateHandoff,returnAfterHandoffRequest:t.generateHandoff,autoReview:t.autoReview}),he(!1)}catch(l){console.error("[review-flow] failed to start review flow",l),Ke.error(l instanceof Error?l.message:f("diffView.reviewDialog.toast.startFailed"))}finally{De(!1)}},[B,c,f]),Pe=o.useCallback(t=>{const r=Ae.current.get(t),l=ve.current;if(!r||!l)return!1;const h=r.getBoundingClientRect().top-l.getBoundingClientRect().top;return l.scrollTo({top:l.scrollTop+h,behavior:"auto"}),!0},[]);o.useEffect(()=>{if(!xe.current)return;let r=0;const l=20;let h=!1;const j=(F=!0)=>{h||(h=!0,xe.current=null,je.current=!1,F&&$(null),P.current!==null&&(window.cancelAnimationFrame(P.current),P.current=null))},I=()=>{if(h){P.current=null;return}const F=xe.current;if(!F){j(),P.current=null;return}if(!Pe(F)){r+=1,r<l?P.current=window.requestAnimationFrame(I):(j(),P.current=null);return}if(i&&je.current){$(F),j(!1);return}j()};return P.current=window.requestAnimationFrame(I),()=>{h=!0,P.current!==null&&(window.cancelAnimationFrame(P.current),P.current=null)}},[i,ce,Pe]);const ln=o.useCallback(t=>{},[]),st=o.useCallback(t=>{Ne(),_(t),L(!1),je.current=!0,xe.current=t,Fe(t),Ce(r=>r+1),Pe(t)},[Ne,Fe,Pe]);o.useEffect(()=>{const t=r=>{if(!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 h=r.key==="ArrowDown"?1:-1,j=C?N.findIndex(R=>R.path===C):-1,I=j===-1?h>0?0:N.length-1:j+h,F=N[I];F&&(r.preventDefault(),st(F.path))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[N,C,st]);const cn=o.useCallback(t=>{const r=t==="side-by-side"?"side-by-side":"inline";N.forEach(l=>{Le(l.path,r)})},[N,Le]),[fn,wt]=o.useState(null),un=o.useCallback(async(t,r)=>{if(!c||!t)return;wt(t);const l=at();try{let h=null;if(r?.patch&&!r.isBinary&&!Be(t)?h=Nt(r.patch):r&&r.contextMode==="full"&&!r.isBinary&&!Be(t)&&(h=At(r.original,r.modified)),h===null)try{const U=await m.getGitDiff(c,{path:t,staged:Ie,contextLines:3});h=Nt(U.diff)}catch{h=null}let j=r;if(h===null||!j){const U=await m.getGitFileDiff(c,{path:t,staged:Ie});j={original:U.original??"",modified:U.modified??"",isBinary:U.isBinary},Ie||Y(c,t,j,l)}const I=h??(j.isBinary||Be(t)?1:At(j.original,j.modified)),F=us(c,t),R=await Pn(x,F,{directory:c});if(!R.ok){Ke.error(Gn(R.reason));return}_e(c,F,I,1)}finally{wt(h=>h===t?null:h)}},[Ie,c,x,m,_e,Y]),dn=()=>{if(!c)return null;const t=r=>Ue!==null?Ue:re&&r===C;return n.jsxs("div",{className:le("flex min-w-0 flex-1 min-h-0 h-full",g?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[Ot&&n.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[n.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:f("diffView.section.files")}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:N.length})]}),n.jsx(gs,{changedFiles:N,selectedFile:null,onSelectFile:st})]}),n.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:n.jsx(it,{ref:ve,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:n.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:N.map(r=>n.jsx(ys,{directory:c,file:r,layout:nt(r),wrapLines:We,isSelected:!1,isExpanded:E.has(r.path),isMounted:Q.has(r.path)||r.path===G,onSelect:ln,onExpandedChange:rn,registerSectionRef:sn,showOpenInEditorAction:a&&b!=="turn",isOpeningInEditor:fn===r.path,onOpenInEditor:(l,h)=>{un(l,h)},staged:t(r.path),loadFullFiles:H,readOnlyActions:b==="branch",initialDiffData:b==="turn"?zt.get(r.path)??null:b==="branch"?tn.get(r.path)??null:null},`${r.path}:${pe.get(r.path)??0}`))})})})]})},mn=()=>{if(!c)return n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:f("diffView.state.selectSessionDirectory")});if(b!=="turn"&&V&&!y)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),f("diffView.state.loadingRepositoryStatus")]});if(b!=="turn"&&ne===!1)return n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:f("diffView.state.notGitRepository")});if(b==="branch"){if(!Yt)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),f("diffView.branch.resolvingBase")]});if(!oe){const t=(ke?.all??[]).map(l=>l.replace(/^remotes\//,"")).filter(l=>l!==k&&!l.endsWith(`/${k}`)).sort(),r=En(t,dt,l=>[l]);return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[n.jsx(A,{name:"git-branch",className:"size-6 text-muted-foreground"}),n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:f("diffView.branch.noBaseTitle")}),n.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:f("diffView.branch.noBaseDescription")}),n.jsx("input",{type:"text",value:dt,onChange:l=>Qt(l.target.value),placeholder:f("gitView.branch.searchPlaceholder"),"aria-label":f("gitView.branch.searchPlaceholder"),className:"w-full max-w-sm rounded-md border border-border/60 bg-[var(--surface-elevated)] px-2.5 py-1.5 typography-meta text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]"}),n.jsx(it,{outerClassName:"max-h-48 w-full max-w-sm min-h-0",className:"px-1 py-1",children:r.length===0?n.jsx("div",{className:"px-2 py-3 typography-meta text-muted-foreground",children:f("gitView.branch.empty")}):n.jsx("div",{className:"flex flex-col gap-0.5",children:r.map(l=>n.jsxs("button",{type:"button",onClick:()=>c&&k&&qt(c,k,l),className:"flex items-center gap-2 rounded-md px-2 py-1.5 text-left hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[n.jsx(A,{name:"git-branch",className:"size-3.5 text-primary"}),n.jsx("span",{className:"truncate typography-ui-label text-foreground",title:l,children:l})]},l))})})]})}if(pt)return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:f("diffView.branch.loadError")}),n.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:pt}),n.jsx(me,{variant:"outline",size:"sm",onClick:()=>et(),children:f("diffView.actions.retry")})]});if(Oe===null)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),f("diffView.branch.loadingFiles")]})}return N.length===0?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:b==="turn"?f("diffView.state.noLastTurnChanges"):b==="branch"&&oe?f("diffView.branch.empty",{base:oe}):f("diffView.state.cleanWorkingTree")}):dn()};return n.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[n.jsxs("div",{className:"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[!T&&(b==="working"||b==="staged"||b==="turn"||b==="branch"?n.jsx(hs,{scope:b,workingCount:Pt,stagedCount:Gt,turnCount:$t,branchCount:nn,showBranchOption:Ye,onScopeChange:t=>{ge(t),u?.(t)}}):n.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:n.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:V&&!y?f("diffView.state.loadingChanges"):N.length===1?f("diffView.summary.changedFilesSingle",{count:N.length}):f("diffView.summary.changedFilesPlural",{count:N.length})})})),N.length>0&&n.jsxs(me,{variant:"ghost",size:"sm",onClick:on,className:le("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:E.size>0?f("diffView.actions.collapseAll"):f("diffView.actions.expandAll"),children:[n.jsx(A,{name:"expand-up-down",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:E.size>0?f("diffView.actions.collapseAll"):f("diffView.actions.expandAll")})]}),N.length>0&&_t&&n.jsxs(me,{variant:"default",size:"sm",onClick:()=>he(!0),disabled:Z,className:"diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2","aria-label":f("diffView.actions.reviewAria"),children:[Z?n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):n.jsx(A,{name:"search-eye",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__review-label typography-ui-label",children:f("diffView.actions.review")})]}),N.length>0&&It&&n.jsxs(me,{variant:"outline",size:"sm",onClick:()=>{const t=c??"";S(t,{kind:"working-tree",scope:b==="staged"||b==="working"?b:"all"}),v(t,"walkthrough")},className:le("diff-toolbar__walkthrough-button h-7 flex-shrink-0 gap-1.5 px-2",$n),"aria-label":f("walkthrough.action.open"),children:[n.jsx(A,{name:"route",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__walkthrough-label typography-ui-label",children:f("walkthrough.action.open")})]}),N.length>0&&n.jsxs(kn,{children:[n.jsx(Cn,{asChild:!0,children:n.jsx(me,{variant:"ghost",size:"sm",onClick:()=>ie(t=>!t),"aria-pressed":H,"aria-label":f(H?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles"),className:le("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",H&&"bg-interactive-selection text-interactive-selection-foreground"),children:n.jsx(A,{name:"file-download",className:"size-4"})})}),n.jsx(Dn,{children:n.jsx("p",{children:f(H?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles")})})]}),N.length>0&&n.jsx(me,{variant:"ghost",size:"sm",onClick:()=>Me(!Te),className:le("h-5 w-5 p-0 transition-opacity",We?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:f(We?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:n.jsx(A,{name:"text-wrap",className:"size-4"})}),bt&&n.jsx(Bt,{mode:bt==="side-by-side"?"side-by-side":"unified",onModeChange:cn})]}),n.jsx(Rn,{open:ye,onOpenChange:he,projectDirectory:c??null,submitting:Z,onConfirm:an}),mn()]})};export{Mi as DiffView};