@myrialabs/clopen 0.2.16 → 0.2.17

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 (286) hide show
  1. package/.env.example +4 -4
  2. package/backend/utils/env.ts +5 -5
  3. package/bin/clopen.ts +21 -298
  4. package/dist/assets/addon-clipboard-wHJhZAA4.js +1 -0
  5. package/dist/assets/addon-fit-DX4qG4td.js +1 -0
  6. package/dist/assets/addon-ligatures-DpDY8N_X.js +2 -0
  7. package/dist/assets/addon-unicode11-Bt8F3D7-.js +7 -0
  8. package/dist/assets/addon-web-links-DIbG5aQx.js +1 -0
  9. package/dist/assets/index-C-eR9PGW.js +2 -0
  10. package/dist/assets/main-D1IISCsM.js +247 -0
  11. package/dist/assets/main-DzSwlujO.css +1 -0
  12. package/dist/assets/xterm-B-qIQCd3.js +16 -0
  13. package/{index.html → dist/index.html} +2 -1
  14. package/package.json +11 -2
  15. package/scripts/start.ts +3 -3
  16. package/shared/utils/logger.ts +1 -1
  17. package/.dockerignore +0 -5
  18. package/.github/workflows/ci.yml +0 -86
  19. package/CONTRIBUTING.md +0 -188
  20. package/bun.lock +0 -1127
  21. package/docker-compose.yml +0 -31
  22. package/frontend/App.svelte +0 -77
  23. package/frontend/app-environment.ts +0 -10
  24. package/frontend/app.css +0 -313
  25. package/frontend/components/auth/InvitePage.svelte +0 -215
  26. package/frontend/components/auth/LoginPage.svelte +0 -129
  27. package/frontend/components/auth/SetupPage.svelte +0 -1054
  28. package/frontend/components/chat/ChatInterface.svelte +0 -426
  29. package/frontend/components/chat/formatters/ErrorMessage.svelte +0 -57
  30. package/frontend/components/chat/formatters/MessageFormatter.svelte +0 -244
  31. package/frontend/components/chat/formatters/TextMessage.svelte +0 -383
  32. package/frontend/components/chat/formatters/Tools.svelte +0 -79
  33. package/frontend/components/chat/formatters/index.ts +0 -3
  34. package/frontend/components/chat/input/ChatInput.svelte +0 -492
  35. package/frontend/components/chat/input/components/ChatInputActions.svelte +0 -88
  36. package/frontend/components/chat/input/components/DragDropOverlay.svelte +0 -30
  37. package/frontend/components/chat/input/components/EditModeIndicator.svelte +0 -33
  38. package/frontend/components/chat/input/components/EngineModelPicker.svelte +0 -642
  39. package/frontend/components/chat/input/components/FileAttachmentPreview.svelte +0 -48
  40. package/frontend/components/chat/input/components/LoadingIndicator.svelte +0 -43
  41. package/frontend/components/chat/input/composables/use-animations.svelte.ts +0 -217
  42. package/frontend/components/chat/input/composables/use-chat-actions.svelte.ts +0 -152
  43. package/frontend/components/chat/input/composables/use-file-handling.svelte.ts +0 -216
  44. package/frontend/components/chat/input/composables/use-input-state.svelte.ts +0 -357
  45. package/frontend/components/chat/input/composables/use-textarea-resize.svelte.ts +0 -69
  46. package/frontend/components/chat/message/ChatMessage.svelte +0 -509
  47. package/frontend/components/chat/message/ChatMessages.svelte +0 -553
  48. package/frontend/components/chat/message/DateSeparator.svelte +0 -86
  49. package/frontend/components/chat/message/MessageBubble.svelte +0 -114
  50. package/frontend/components/chat/message/MessageHeader.svelte +0 -143
  51. package/frontend/components/chat/modal/DebugModal.svelte +0 -59
  52. package/frontend/components/chat/shared/index.ts +0 -2
  53. package/frontend/components/chat/shared/utils.ts +0 -116
  54. package/frontend/components/chat/tools/AgentTool.svelte +0 -96
  55. package/frontend/components/chat/tools/AskUserQuestionTool.svelte +0 -391
  56. package/frontend/components/chat/tools/BashOutputTool.svelte +0 -35
  57. package/frontend/components/chat/tools/BashTool.svelte +0 -51
  58. package/frontend/components/chat/tools/CustomMcpTool.svelte +0 -141
  59. package/frontend/components/chat/tools/EditTool.svelte +0 -48
  60. package/frontend/components/chat/tools/EnterPlanModeTool.svelte +0 -24
  61. package/frontend/components/chat/tools/ExitPlanModeTool.svelte +0 -29
  62. package/frontend/components/chat/tools/GlobTool.svelte +0 -51
  63. package/frontend/components/chat/tools/GrepTool.svelte +0 -90
  64. package/frontend/components/chat/tools/ListMcpResourcesTool.svelte +0 -31
  65. package/frontend/components/chat/tools/NotebookEditTool.svelte +0 -38
  66. package/frontend/components/chat/tools/ReadMcpResourceTool.svelte +0 -34
  67. package/frontend/components/chat/tools/ReadTool.svelte +0 -41
  68. package/frontend/components/chat/tools/SkillTool.svelte +0 -21
  69. package/frontend/components/chat/tools/TaskStopTool.svelte +0 -26
  70. package/frontend/components/chat/tools/TaskTool.svelte +0 -64
  71. package/frontend/components/chat/tools/TodoWriteTool.svelte +0 -75
  72. package/frontend/components/chat/tools/WebFetchTool.svelte +0 -35
  73. package/frontend/components/chat/tools/WebSearchTool.svelte +0 -84
  74. package/frontend/components/chat/tools/WriteTool.svelte +0 -33
  75. package/frontend/components/chat/tools/components/CodeBlock.svelte +0 -79
  76. package/frontend/components/chat/tools/components/DiffBlock.svelte +0 -408
  77. package/frontend/components/chat/tools/components/FileHeader.svelte +0 -59
  78. package/frontend/components/chat/tools/components/InfoLine.svelte +0 -19
  79. package/frontend/components/chat/tools/components/StatsBadges.svelte +0 -27
  80. package/frontend/components/chat/tools/components/TerminalCommand.svelte +0 -61
  81. package/frontend/components/chat/tools/components/index.ts +0 -7
  82. package/frontend/components/chat/tools/index.ts +0 -30
  83. package/frontend/components/chat/widgets/ContextIndicator.svelte +0 -186
  84. package/frontend/components/chat/widgets/FloatingTodoList.svelte +0 -367
  85. package/frontend/components/checkpoint/ConflictResolutionModal.svelte +0 -189
  86. package/frontend/components/checkpoint/TimelineModal.svelte +0 -447
  87. package/frontend/components/checkpoint/timeline/TimelineEdge.svelte +0 -26
  88. package/frontend/components/checkpoint/timeline/TimelineGraph.svelte +0 -87
  89. package/frontend/components/checkpoint/timeline/TimelineNode.svelte +0 -119
  90. package/frontend/components/checkpoint/timeline/TimelineVersionGroup.svelte +0 -59
  91. package/frontend/components/checkpoint/timeline/animation.ts +0 -168
  92. package/frontend/components/checkpoint/timeline/config.ts +0 -44
  93. package/frontend/components/checkpoint/timeline/graph-builder.ts +0 -304
  94. package/frontend/components/checkpoint/timeline/types.ts +0 -69
  95. package/frontend/components/checkpoint/timeline/utils.ts +0 -53
  96. package/frontend/components/common/display/AvatarBubble.svelte +0 -56
  97. package/frontend/components/common/display/Button.svelte +0 -71
  98. package/frontend/components/common/display/Card.svelte +0 -102
  99. package/frontend/components/common/display/Icon.svelte +0 -58
  100. package/frontend/components/common/display/PageTemplate.svelte +0 -76
  101. package/frontend/components/common/display/ProjectUserAvatars.svelte +0 -79
  102. package/frontend/components/common/display/ThemeToggle.svelte +0 -44
  103. package/frontend/components/common/editor/MonacoEditor.svelte +0 -583
  104. package/frontend/components/common/feedback/Alert.svelte +0 -139
  105. package/frontend/components/common/feedback/ConnectionBanner.svelte +0 -55
  106. package/frontend/components/common/feedback/LoadingScreen.svelte +0 -52
  107. package/frontend/components/common/feedback/LoadingSpinner.svelte +0 -48
  108. package/frontend/components/common/feedback/NotificationToast.svelte +0 -128
  109. package/frontend/components/common/feedback/RestartRequiredModal.svelte +0 -53
  110. package/frontend/components/common/feedback/UpdateBanner.svelte +0 -99
  111. package/frontend/components/common/form/Checkbox.svelte +0 -48
  112. package/frontend/components/common/form/FolderBrowser.svelte +0 -856
  113. package/frontend/components/common/form/Input.svelte +0 -72
  114. package/frontend/components/common/form/ModelSelector.svelte +0 -110
  115. package/frontend/components/common/form/Select.svelte +0 -98
  116. package/frontend/components/common/form/Textarea.svelte +0 -80
  117. package/frontend/components/common/lucide-icons.ts +0 -1642
  118. package/frontend/components/common/material-icons.ts +0 -1082
  119. package/frontend/components/common/media/MediaPreview.svelte +0 -187
  120. package/frontend/components/common/overlay/Dialog.svelte +0 -251
  121. package/frontend/components/common/overlay/Lightbox.svelte +0 -233
  122. package/frontend/components/common/overlay/Modal.svelte +0 -177
  123. package/frontend/components/common/overlay/ModalProvider.svelte +0 -28
  124. package/frontend/components/common/xterm/XTerm.svelte +0 -743
  125. package/frontend/components/common/xterm/index.ts +0 -16
  126. package/frontend/components/common/xterm/terminal-config.ts +0 -68
  127. package/frontend/components/common/xterm/types.ts +0 -32
  128. package/frontend/components/common/xterm/xterm-service.ts +0 -437
  129. package/frontend/components/files/FileNode.svelte +0 -327
  130. package/frontend/components/files/FileTree.svelte +0 -690
  131. package/frontend/components/files/FileViewer.svelte +0 -551
  132. package/frontend/components/files/SearchResults.svelte +0 -303
  133. package/frontend/components/git/BranchManager.svelte +0 -446
  134. package/frontend/components/git/ChangesSection.svelte +0 -196
  135. package/frontend/components/git/CommitForm.svelte +0 -128
  136. package/frontend/components/git/ConflictResolver.svelte +0 -158
  137. package/frontend/components/git/DiffViewer.svelte +0 -298
  138. package/frontend/components/git/FileChangeItem.svelte +0 -119
  139. package/frontend/components/git/GitButton.svelte +0 -33
  140. package/frontend/components/git/GitLog.svelte +0 -401
  141. package/frontend/components/git/GitModal.svelte +0 -80
  142. package/frontend/components/history/HistoryModal.svelte +0 -602
  143. package/frontend/components/history/HistoryView.svelte +0 -561
  144. package/frontend/components/index.ts +0 -34
  145. package/frontend/components/preview/browser/BrowserPreview.svelte +0 -558
  146. package/frontend/components/preview/browser/components/Canvas.svelte +0 -1523
  147. package/frontend/components/preview/browser/components/ConsolePanel.svelte +0 -757
  148. package/frontend/components/preview/browser/components/Container.svelte +0 -507
  149. package/frontend/components/preview/browser/components/ContextMenu.svelte +0 -236
  150. package/frontend/components/preview/browser/components/SelectDropdown.svelte +0 -224
  151. package/frontend/components/preview/browser/components/Toolbar.svelte +0 -358
  152. package/frontend/components/preview/browser/components/VirtualCursor.svelte +0 -36
  153. package/frontend/components/preview/browser/core/cleanup.svelte.ts +0 -155
  154. package/frontend/components/preview/browser/core/coordinator.svelte.ts +0 -885
  155. package/frontend/components/preview/browser/core/interactions.svelte.ts +0 -113
  156. package/frontend/components/preview/browser/core/mcp-handlers.svelte.ts +0 -331
  157. package/frontend/components/preview/browser/core/native-ui-handlers.svelte.ts +0 -391
  158. package/frontend/components/preview/browser/core/stream-handler.svelte.ts +0 -288
  159. package/frontend/components/preview/browser/core/tab-manager.svelte.ts +0 -210
  160. package/frontend/components/preview/browser/core/tab-operations.svelte.ts +0 -241
  161. package/frontend/components/preview/index.ts +0 -2
  162. package/frontend/components/settings/SettingsModal.svelte +0 -268
  163. package/frontend/components/settings/SettingsView.svelte +0 -54
  164. package/frontend/components/settings/account/AccountSettings.svelte +0 -5
  165. package/frontend/components/settings/admin/InviteManagement.svelte +0 -239
  166. package/frontend/components/settings/admin/UserManagement.svelte +0 -127
  167. package/frontend/components/settings/appearance/AppearanceSettings.svelte +0 -104
  168. package/frontend/components/settings/appearance/LayoutPresetSettings.svelte +0 -160
  169. package/frontend/components/settings/appearance/LayoutPreview.svelte +0 -76
  170. package/frontend/components/settings/engines/AIEnginesSettings.svelte +0 -917
  171. package/frontend/components/settings/general/AdvancedSettings.svelte +0 -193
  172. package/frontend/components/settings/general/AuthModeSettings.svelte +0 -229
  173. package/frontend/components/settings/general/DataManagementSettings.svelte +0 -89
  174. package/frontend/components/settings/general/GeneralSettings.svelte +0 -20
  175. package/frontend/components/settings/general/UpdateSettings.svelte +0 -130
  176. package/frontend/components/settings/git/GitSettings.svelte +0 -392
  177. package/frontend/components/settings/model/EngineModelPicker.svelte +0 -284
  178. package/frontend/components/settings/model/ModelSettings.svelte +0 -240
  179. package/frontend/components/settings/notifications/NotificationSettings.svelte +0 -205
  180. package/frontend/components/settings/security/SecuritySettings.svelte +0 -10
  181. package/frontend/components/settings/system/SystemSettings.svelte +0 -10
  182. package/frontend/components/settings/tunnel/TunnelSettings.svelte +0 -1060
  183. package/frontend/components/settings/user/UserSettings.svelte +0 -270
  184. package/frontend/components/terminal/Terminal.svelte +0 -338
  185. package/frontend/components/terminal/TerminalTabs.svelte +0 -88
  186. package/frontend/components/terminal/TerminalView.svelte +0 -55
  187. package/frontend/components/tunnel/TunnelActive.svelte +0 -218
  188. package/frontend/components/tunnel/TunnelButton.svelte +0 -60
  189. package/frontend/components/tunnel/TunnelInactive.svelte +0 -260
  190. package/frontend/components/tunnel/TunnelModal.svelte +0 -101
  191. package/frontend/components/tunnel/TunnelQRCode.svelte +0 -49
  192. package/frontend/components/workspace/DesktopNavigator.svelte +0 -445
  193. package/frontend/components/workspace/MobileNavigator.svelte +0 -427
  194. package/frontend/components/workspace/PanelContainer.svelte +0 -100
  195. package/frontend/components/workspace/PanelHeader.svelte +0 -664
  196. package/frontend/components/workspace/ViewMenu.svelte +0 -146
  197. package/frontend/components/workspace/WorkspaceLayout.svelte +0 -199
  198. package/frontend/components/workspace/layout/DesktopLayout.svelte +0 -15
  199. package/frontend/components/workspace/layout/MobileLayout.svelte +0 -17
  200. package/frontend/components/workspace/layout/split-pane/Container.svelte +0 -42
  201. package/frontend/components/workspace/layout/split-pane/Handle.svelte +0 -85
  202. package/frontend/components/workspace/layout/split-pane/Layout.svelte +0 -62
  203. package/frontend/components/workspace/panels/ChatPanel.svelte +0 -282
  204. package/frontend/components/workspace/panels/FilesPanel.svelte +0 -1376
  205. package/frontend/components/workspace/panels/GitPanel.svelte +0 -1601
  206. package/frontend/components/workspace/panels/PreviewPanel.svelte +0 -153
  207. package/frontend/components/workspace/panels/TerminalPanel.svelte +0 -73
  208. package/frontend/main.ts +0 -17
  209. package/frontend/services/chat/chat.service.ts +0 -975
  210. package/frontend/services/chat/index.ts +0 -7
  211. package/frontend/services/favicon.service.ts +0 -103
  212. package/frontend/services/notification/global-stream-monitor.ts +0 -120
  213. package/frontend/services/notification/index.ts +0 -8
  214. package/frontend/services/notification/push.service.ts +0 -144
  215. package/frontend/services/notification/sound.service.ts +0 -127
  216. package/frontend/services/preview/browser/browser-console.service.ts +0 -61
  217. package/frontend/services/preview/browser/browser-webcodecs.service.ts +0 -1643
  218. package/frontend/services/preview/browser/mcp-integration.svelte.ts +0 -67
  219. package/frontend/services/preview/index.ts +0 -23
  220. package/frontend/services/project/index.ts +0 -8
  221. package/frontend/services/project/status.service.ts +0 -170
  222. package/frontend/services/snapshot/snapshot.service.ts +0 -86
  223. package/frontend/services/terminal/background/index.ts +0 -130
  224. package/frontend/services/terminal/background/session-restore.ts +0 -274
  225. package/frontend/services/terminal/background/stream-manager.ts +0 -286
  226. package/frontend/services/terminal/index.ts +0 -14
  227. package/frontend/services/terminal/persistence.service.ts +0 -260
  228. package/frontend/services/terminal/project.service.ts +0 -1004
  229. package/frontend/services/terminal/session.service.ts +0 -364
  230. package/frontend/services/terminal/terminal.service.ts +0 -379
  231. package/frontend/stores/core/app.svelte.ts +0 -296
  232. package/frontend/stores/core/files.svelte.ts +0 -87
  233. package/frontend/stores/core/presence.svelte.ts +0 -128
  234. package/frontend/stores/core/projects.svelte.ts +0 -325
  235. package/frontend/stores/core/sessions.svelte.ts +0 -452
  236. package/frontend/stores/features/auth.svelte.ts +0 -336
  237. package/frontend/stores/features/claude-accounts.svelte.ts +0 -58
  238. package/frontend/stores/features/models.svelte.ts +0 -89
  239. package/frontend/stores/features/settings.svelte.ts +0 -151
  240. package/frontend/stores/features/terminal.svelte.ts +0 -747
  241. package/frontend/stores/features/tunnel-config.svelte.ts +0 -205
  242. package/frontend/stores/features/tunnel.svelte.ts +0 -277
  243. package/frontend/stores/features/user.svelte.ts +0 -54
  244. package/frontend/stores/ui/chat-input.svelte.ts +0 -57
  245. package/frontend/stores/ui/chat-model.svelte.ts +0 -61
  246. package/frontend/stores/ui/connection.svelte.ts +0 -40
  247. package/frontend/stores/ui/dialog.svelte.ts +0 -59
  248. package/frontend/stores/ui/edit-mode.svelte.ts +0 -214
  249. package/frontend/stores/ui/notification.svelte.ts +0 -169
  250. package/frontend/stores/ui/settings-modal.svelte.ts +0 -116
  251. package/frontend/stores/ui/theme.svelte.ts +0 -179
  252. package/frontend/stores/ui/todo-panel.svelte.ts +0 -39
  253. package/frontend/stores/ui/update.svelte.ts +0 -159
  254. package/frontend/stores/ui/workspace.svelte.ts +0 -798
  255. package/frontend/utils/chat/date-separator.ts +0 -39
  256. package/frontend/utils/chat/message-grouper.ts +0 -329
  257. package/frontend/utils/chat/message-processor.ts +0 -169
  258. package/frontend/utils/chat/tool-handler.ts +0 -287
  259. package/frontend/utils/chat/virtual-scroll.svelte.ts +0 -142
  260. package/frontend/utils/click-outside.ts +0 -20
  261. package/frontend/utils/context-manager.ts +0 -55
  262. package/frontend/utils/file-icon-mappings.ts +0 -769
  263. package/frontend/utils/file-type.ts +0 -68
  264. package/frontend/utils/folder-icon-mappings.ts +0 -1030
  265. package/frontend/utils/git-status.ts +0 -68
  266. package/frontend/utils/native-ui.ts +0 -73
  267. package/frontend/utils/platform.ts +0 -113
  268. package/frontend/utils/port-check.ts +0 -65
  269. package/frontend/utils/preview-constants.ts +0 -45
  270. package/frontend/utils/terminal-formatter.ts +0 -207
  271. package/frontend/utils/theme.ts +0 -6
  272. package/frontend/utils/tree-visualizer.ts +0 -320
  273. package/frontend/utils/ws.ts +0 -90
  274. package/scripts/dev.ts +0 -46
  275. package/scripts/generate-icons.ts +0 -87
  276. package/svelte.config.js +0 -20
  277. package/tsconfig.json +0 -41
  278. package/vite.config.ts +0 -51
  279. /package/{static → dist}/audio/notification.ogg +0 -0
  280. /package/{static → dist}/favicon.svg +0 -0
  281. /package/{static → dist}/fonts/dm-sans/dm-sans-italic-latin-ext.woff2 +0 -0
  282. /package/{static → dist}/fonts/dm-sans/dm-sans-italic-latin.woff2 +0 -0
  283. /package/{static → dist}/fonts/dm-sans/dm-sans-normal-latin-ext.woff2 +0 -0
  284. /package/{static → dist}/fonts/dm-sans/dm-sans-normal-latin.woff2 +0 -0
  285. /package/{static → dist}/fonts/dm-sans.css +0 -0
  286. /package/{static → dist}/manifest.json +0 -0
@@ -1,1601 +0,0 @@
1
- <script lang="ts">
2
- import { onMount, untrack } from 'svelte';
3
- import Icon from '$frontend/components/common/display/Icon.svelte';
4
- import Dialog from '$frontend/components/common/overlay/Dialog.svelte';
5
- import { projectState } from '$frontend/stores/core/projects.svelte';
6
- import { showError, showInfo } from '$frontend/stores/ui/notification.svelte';
7
- import { debug } from '$shared/utils/logger';
8
- import { settings } from '$frontend/stores/features/settings.svelte';
9
- import ws from '$frontend/utils/ws';
10
- import { getFileIcon } from '$frontend/utils/file-icon-mappings';
11
- import { isPreviewableFile, isBinaryFile } from '$frontend/utils/file-type';
12
- import { getGitStatusLabel, getGitStatusColor } from '$frontend/utils/git-status';
13
- import type { IconName } from '$shared/types/ui/icons';
14
- import type {
15
- GitStatus,
16
- GitBranchInfo,
17
- GitFileChange,
18
- GitFileDiff,
19
- GitCommit,
20
- GitConflictFile,
21
- GitStashEntry,
22
- GitTag,
23
- GitRemote
24
- } from '$shared/types/git';
25
-
26
- // Sub-components
27
- import CommitForm from '$frontend/components/git/CommitForm.svelte';
28
- import ChangesSection from '$frontend/components/git/ChangesSection.svelte';
29
- import DiffViewer from '$frontend/components/git/DiffViewer.svelte';
30
- import BranchManager from '$frontend/components/git/BranchManager.svelte';
31
- import GitLog from '$frontend/components/git/GitLog.svelte';
32
- import ConflictResolver from '$frontend/components/git/ConflictResolver.svelte';
33
-
34
- // Derived state
35
- const hasActiveProject = $derived(projectState.currentProject !== null);
36
- const projectId = $derived(projectState.currentProject?.id || '');
37
-
38
- // Git state
39
- let isRepo = $state(false);
40
- let isLoading = $state(false);
41
- let gitStatus = $state<GitStatus>({ staged: [], unstaged: [], untracked: [], conflicted: [] });
42
- let branchInfo = $state<GitBranchInfo | null>(null);
43
- let isCommitting = $state(false);
44
-
45
- // Remote state
46
- let remotes = $state<GitRemote[]>([]);
47
- let selectedRemote = $state('origin');
48
-
49
- // View state
50
- let activeView = $state<'changes' | 'log' | 'stash' | 'tags'>('changes');
51
- let viewMode = $state<'list' | 'diff'>('list');
52
- let showBranchManager = $state(false);
53
- let showConflictResolver = $state(false);
54
-
55
- // Git init state
56
- let isInitializing = $state(false);
57
-
58
- // Stash state
59
- let stashEntries = $state<GitStashEntry[]>([]);
60
- let isStashLoading = $state(false);
61
- let showStashSaveForm = $state(false);
62
- let stashMessage = $state('');
63
-
64
- // Tags state
65
- let tags = $state<GitTag[]>([]);
66
- let isTagsLoading = $state(false);
67
- let showCreateTagForm = $state(false);
68
- let newTagName = $state('');
69
- let newTagMessage = $state('');
70
-
71
- // Tab system (like Files panel)
72
- interface DiffTab {
73
- id: string;
74
- filePath: string;
75
- fileName: string;
76
- section: string;
77
- diff: GitFileDiff | null;
78
- diffs: GitFileDiff[];
79
- isLoading: boolean;
80
- commitHash?: string;
81
- status?: string;
82
- }
83
-
84
- // Per-view tab isolation — each view (Changes, History, Stash, Tags) has its own tabs
85
- const _tabStore: Record<string, DiffTab[]> = { changes: [], log: [], stash: [], tags: [] };
86
- const _activeTabStore: Record<string, string | null> = { changes: null, log: null, stash: null, tags: null };
87
- const _viewModeStore: Record<string, 'list' | 'diff'> = { changes: 'list', log: 'list', stash: 'list', tags: 'list' };
88
-
89
- let openTabs = $state<DiffTab[]>([]);
90
- let activeTabId = $state<string | null>(null);
91
-
92
- const activeTab = $derived(openTabs.find(t => t.id === activeTabId) || null);
93
-
94
- function switchToView(newView: typeof activeView) {
95
- // Save current view's tab state
96
- _tabStore[activeView] = openTabs;
97
- _activeTabStore[activeView] = activeTabId;
98
- _viewModeStore[activeView] = viewMode;
99
- // Restore target view's tab state
100
- openTabs = _tabStore[newView] || [];
101
- activeTabId = _activeTabStore[newView] || null;
102
- viewMode = _viewModeStore[newView] || 'list';
103
- activeView = newView;
104
- }
105
-
106
- function resetAllViewTabs() {
107
- for (const key of Object.keys(_tabStore)) {
108
- _tabStore[key] = [];
109
- _activeTabStore[key] = null;
110
- _viewModeStore[key] = 'list';
111
- }
112
- openTabs = [];
113
- activeTabId = null;
114
- viewMode = 'list';
115
- }
116
-
117
- // Diff state
118
- const isDiffLoading = $state(false);
119
-
120
- // Log state
121
- let commits = $state<GitCommit[]>([]);
122
- let isLogLoading = $state(false);
123
- let logHasMore = $state(false);
124
- let logSkip = $state(0);
125
-
126
- // Conflict state
127
- let conflictFiles = $state<GitConflictFile[]>([]);
128
- let isConflictLoading = $state(false);
129
-
130
- // Container width for responsive layout (same threshold as Files: 800)
131
- let containerRef = $state<HTMLDivElement | null>(null);
132
- let containerWidth = $state(0);
133
- let leftPanelWidth = $state(288); // default w-72
134
- let isResizing = $state(false);
135
- const TWO_COLUMN_THRESHOLD = $derived(Math.round(600 * (settings.fontSize / 13)));
136
- const isTwoColumnMode = $derived(containerWidth >= TWO_COLUMN_THRESHOLD);
137
-
138
- // Track last project for re-fetch
139
- let lastProjectId = $state('');
140
-
141
- // (File watcher subscription managed by $effect with auto-cleanup)
142
-
143
- // Active diff file path (for highlighting in list)
144
- const activeFilePath = $derived(activeTab?.filePath || null);
145
-
146
- // ============================
147
- // Confirm Dialog State
148
- // ============================
149
- let showConfirmDialog = $state(false);
150
- let confirmConfig = $state({
151
- title: '',
152
- message: '',
153
- type: 'warning' as 'info' | 'warning' | 'error' | 'success',
154
- confirmText: 'Confirm',
155
- cancelText: 'Cancel',
156
- onConfirm: () => {}
157
- });
158
-
159
- function requestConfirm(config: {
160
- title: string;
161
- message: string;
162
- type?: 'info' | 'warning' | 'error' | 'success';
163
- confirmText?: string;
164
- cancelText?: string;
165
- onConfirm: () => void;
166
- }) {
167
- confirmConfig = {
168
- title: config.title,
169
- message: config.message,
170
- type: config.type || 'warning',
171
- confirmText: config.confirmText || 'Confirm',
172
- cancelText: config.cancelText || 'Cancel',
173
- onConfirm: config.onConfirm
174
- };
175
- showConfirmDialog = true;
176
- }
177
-
178
- function closeConfirmDialog() {
179
- showConfirmDialog = false;
180
- }
181
-
182
- // ============================
183
- // Git Init
184
- // ============================
185
-
186
- async function handleInit() {
187
- if (!projectId) return;
188
- isInitializing = true;
189
- try {
190
- await ws.http('git:init', { projectId, defaultBranch: 'main' });
191
- await loadAll();
192
- } catch (err) {
193
- debug.error('git', 'Git init failed:', err);
194
- showError('Git Init Failed', err instanceof Error ? err.message : 'Unknown error');
195
- } finally {
196
- isInitializing = false;
197
- }
198
- }
199
-
200
- // ============================
201
- // Data Loading
202
- // ============================
203
-
204
- async function loadAll() {
205
- if (!hasActiveProject || !projectId) return;
206
- isLoading = true;
207
- try {
208
- await Promise.all([loadStatus(), loadBranches(), loadRemotes()]);
209
- } catch (err) {
210
- debug.error('git', 'Failed to load git data:', err);
211
- } finally {
212
- isLoading = false;
213
- }
214
- }
215
-
216
- async function loadStatus() {
217
- if (!projectId) return;
218
- try {
219
- const data = await ws.http('git:status', { projectId });
220
- isRepo = data.isRepo;
221
- if (data.isRepo) {
222
- gitStatus = {
223
- staged: data.staged,
224
- unstaged: data.unstaged,
225
- untracked: data.untracked,
226
- conflicted: data.conflicted
227
- };
228
- }
229
- } catch (err) {
230
- debug.error('git', 'Failed to load status:', err);
231
- }
232
- }
233
-
234
- async function loadBranches() {
235
- if (!projectId) return;
236
- try {
237
- branchInfo = await ws.http('git:branches', { projectId });
238
- } catch (err) {
239
- debug.error('git', 'Failed to load branches:', err);
240
- }
241
- }
242
-
243
- async function loadRemotes() {
244
- if (!projectId) return;
245
- try {
246
- const list = await ws.http('git:remotes', { projectId });
247
- remotes = list;
248
- // Auto-select first remote if current selection doesn't exist
249
- if (list.length > 0 && !list.find(r => r.name === selectedRemote)) {
250
- selectedRemote = list[0].name;
251
- }
252
- } catch (err) {
253
- debug.error('git', 'Failed to load remotes:', err);
254
- }
255
- }
256
-
257
- async function loadLog(reset = false) {
258
- if (!projectId) return;
259
- isLogLoading = true;
260
- try {
261
- if (reset) {
262
- logSkip = 0;
263
- commits = [];
264
- }
265
- const data = await ws.http('git:log', { projectId, limit: 50, skip: logSkip });
266
- if (reset) {
267
- commits = data.commits;
268
- } else {
269
- commits = [...commits, ...data.commits];
270
- }
271
- logHasMore = data.hasMore;
272
- logSkip += data.commits.length;
273
- } catch (err) {
274
- debug.error('git', 'Failed to load log:', err);
275
- } finally {
276
- isLogLoading = false;
277
- }
278
- }
279
-
280
- async function loadConflicts() {
281
- if (!projectId) return;
282
- isConflictLoading = true;
283
- try {
284
- conflictFiles = await ws.http('git:conflict-files', { projectId });
285
- } catch (err) {
286
- debug.error('git', 'Failed to load conflicts:', err);
287
- } finally {
288
- isConflictLoading = false;
289
- }
290
- }
291
-
292
- // ============================
293
- // Staging Actions
294
- // ============================
295
-
296
- async function stageFile(path: string) {
297
- if (!projectId) return;
298
- try {
299
- await ws.http('git:stage', { projectId, filePath: path });
300
- await loadStatus();
301
- } catch (err) {
302
- debug.error('git', 'Failed to stage file:', err);
303
- }
304
- }
305
-
306
- async function stageAll() {
307
- if (!projectId) return;
308
- try {
309
- await ws.http('git:stage-all', { projectId });
310
- await loadStatus();
311
- } catch (err) {
312
- debug.error('git', 'Failed to stage all:', err);
313
- }
314
- }
315
-
316
- async function unstageFile(path: string) {
317
- if (!projectId) return;
318
- try {
319
- await ws.http('git:unstage', { projectId, filePath: path });
320
- await loadStatus();
321
- } catch (err) {
322
- debug.error('git', 'Failed to unstage file:', err);
323
- }
324
- }
325
-
326
- async function unstageAll() {
327
- if (!projectId) return;
328
- try {
329
- await ws.http('git:unstage-all', { projectId });
330
- await loadStatus();
331
- } catch (err) {
332
- debug.error('git', 'Failed to unstage all:', err);
333
- }
334
- }
335
-
336
- async function discardFile(path: string) {
337
- const fileName = path.split(/[\\/]/).pop() || path;
338
- requestConfirm({
339
- title: 'Discard Changes',
340
- message: `Discard changes to "${fileName}"? This cannot be undone.`,
341
- type: 'error',
342
- confirmText: 'Discard',
343
- onConfirm: async () => {
344
- if (!projectId) return;
345
- try {
346
- await ws.http('git:discard', { projectId, filePath: path });
347
- await loadStatus();
348
- } catch (err) {
349
- debug.error('git', 'Failed to discard file:', err);
350
- }
351
- }
352
- });
353
- }
354
-
355
- async function discardAll() {
356
- requestConfirm({
357
- title: 'Discard All Changes',
358
- message: 'Discard ALL changes? This cannot be undone.',
359
- type: 'error',
360
- confirmText: 'Discard All',
361
- onConfirm: async () => {
362
- if (!projectId) return;
363
- try {
364
- await ws.http('git:discard-all', { projectId });
365
- await loadStatus();
366
- } catch (err) {
367
- debug.error('git', 'Failed to discard all:', err);
368
- }
369
- }
370
- });
371
- }
372
-
373
- // ============================
374
- // Commit
375
- // ============================
376
-
377
- async function handleCommit(message: string) {
378
- if (!projectId) return;
379
- isCommitting = true;
380
- try {
381
- await ws.http('git:commit', { projectId, message });
382
- await loadAll();
383
- if (activeView === 'log') {
384
- await loadLog(true);
385
- }
386
- } catch (err) {
387
- debug.error('git', 'Commit failed:', err);
388
- showError('Commit Failed', err instanceof Error ? err.message : 'Unknown error');
389
- } finally {
390
- isCommitting = false;
391
- }
392
- }
393
-
394
- // ============================
395
- // Tab Operations
396
- // ============================
397
-
398
- function selectTab(id: string) {
399
- activeTabId = id;
400
- }
401
-
402
- // ============================
403
- // Diff
404
- // ============================
405
-
406
- // Detect binary files by extension (for fallback when git diff returns empty)
407
- function isBinaryByExtension(filePath: string): boolean {
408
- const fileName = filePath.split(/[\\/]/).pop() || filePath;
409
- return isPreviewableFile(fileName) || isBinaryFile(fileName);
410
- }
411
-
412
- async function viewDiff(file: GitFileChange, section: string) {
413
- if (!projectId) return;
414
- const tabId = `${section}:${file.path}`;
415
- const fileName = file.path.split(/[\\/]/).pop() || file.path;
416
- const status = section === 'staged' ? file.indexStatus : file.workingStatus;
417
-
418
- // Changes view: always replace with single tab
419
- openTabs = [{
420
- id: tabId,
421
- filePath: file.path,
422
- fileName,
423
- section,
424
- diff: null,
425
- diffs: [],
426
- isLoading: true,
427
- status
428
- }];
429
- activeTabId = tabId;
430
- if (!isTwoColumnMode) viewMode = 'diff';
431
-
432
- try {
433
- let diffResult: GitFileDiff | null = null;
434
-
435
- if (status === '?') {
436
- // Untracked files have no git diff — read file content to build a synthetic diff
437
- const isBinary = isBinaryByExtension(file.path);
438
- if (isBinary) {
439
- diffResult = {
440
- oldPath: file.path,
441
- newPath: file.path,
442
- status: '?',
443
- hunks: [],
444
- isBinary: true
445
- };
446
- } else {
447
- const basePath = projectState.currentProject?.path || '';
448
- const separator = basePath.includes('\\') ? '\\' : '/';
449
- const fullPath = `${basePath}${separator}${file.path}`;
450
- const fileData = await ws.http('files:read-file', { file_path: fullPath });
451
-
452
- if (fileData.isBinary) {
453
- // Backend detected binary content — show preview instead of diff
454
- diffResult = {
455
- oldPath: file.path,
456
- newPath: file.path,
457
- status: '?',
458
- hunks: [],
459
- isBinary: true
460
- };
461
- } else {
462
- const lines = (fileData.content || '').split('\n');
463
- diffResult = {
464
- oldPath: file.path,
465
- newPath: file.path,
466
- status: '?',
467
- hunks: [{
468
- oldStart: 0,
469
- oldLines: 0,
470
- newStart: 1,
471
- newLines: lines.length,
472
- header: `@@ -0,0 +1,${lines.length} @@`,
473
- lines: lines.map((line, i) => ({
474
- type: 'add' as const,
475
- content: line,
476
- newLineNumber: i + 1
477
- }))
478
- }],
479
- isBinary: false
480
- };
481
- }
482
- }
483
- } else {
484
- const action = section === 'staged' ? 'git:diff-staged' : 'git:diff-unstaged';
485
- const diffs = await ws.http(action, { projectId, filePath: file.path });
486
- diffResult = diffs.length > 0 ? diffs[0] : null;
487
-
488
- if (!diffResult) {
489
- diffResult = {
490
- oldPath: file.path,
491
- newPath: file.path,
492
- status: status || '?',
493
- hunks: [],
494
- isBinary: isBinaryByExtension(file.path)
495
- };
496
- } else if (status) {
497
- // Override diff parser status with authoritative status from git status
498
- // parseDiff defaults to 'M', but the real status (A, D, R, etc.) comes from git status
499
- diffResult = { ...diffResult, status };
500
- }
501
- }
502
-
503
- openTabs = openTabs.map(t =>
504
- t.id === tabId ? { ...t, diff: diffResult, isLoading: false } : t
505
- );
506
- } catch (err) {
507
- debug.error('git', 'Failed to load diff:', err);
508
- openTabs = openTabs.map(t =>
509
- t.id === tabId ? { ...t, diff: null, isLoading: false } : t
510
- );
511
- }
512
- }
513
-
514
- async function viewCommitDiff(hash: string) {
515
- if (!projectId) return;
516
- const loadingTabId = `commit:${hash}`;
517
-
518
- // History view: show loading placeholder, then replace with per-file tabs
519
- openTabs = [{
520
- id: loadingTabId,
521
- filePath: hash,
522
- fileName: `Commit ${hash.substring(0, 7)}`,
523
- section: 'commit',
524
- diff: null,
525
- diffs: [],
526
- isLoading: true,
527
- commitHash: hash
528
- }];
529
- activeTabId = loadingTabId;
530
- if (!isTwoColumnMode) viewMode = 'diff';
531
-
532
- try {
533
- const diffs = await ws.http('git:diff-commit', { projectId, commitHash: hash });
534
- if (diffs.length === 0) {
535
- openTabs = [{
536
- id: loadingTabId,
537
- filePath: hash,
538
- fileName: `Commit ${hash.substring(0, 7)}`,
539
- section: 'commit',
540
- diff: null,
541
- diffs: [],
542
- isLoading: false,
543
- commitHash: hash
544
- }];
545
- return;
546
- }
547
-
548
- // Create one tab per file in the commit
549
- const fileTabs: DiffTab[] = diffs.map((d: GitFileDiff, i: number) => {
550
- const path = d.newPath || d.oldPath || `file-${i}`;
551
- const name = path.split(/[\\/]/).pop() || path;
552
- return {
553
- id: `commit:${hash}:${path}`,
554
- filePath: path,
555
- fileName: name,
556
- section: 'commit',
557
- diff: d,
558
- diffs: [],
559
- isLoading: false,
560
- commitHash: hash,
561
- status: d.status
562
- };
563
- });
564
- openTabs = fileTabs;
565
- activeTabId = fileTabs[0].id;
566
- } catch (err) {
567
- debug.error('git', 'Failed to load commit diff:', err);
568
- openTabs = [{
569
- id: loadingTabId,
570
- filePath: hash,
571
- fileName: `Commit ${hash.substring(0, 7)}`,
572
- section: 'commit',
573
- diff: null,
574
- diffs: [],
575
- isLoading: false,
576
- commitHash: hash
577
- }];
578
- }
579
- }
580
-
581
- // ============================
582
- // Branch Operations
583
- // ============================
584
-
585
- async function switchBranch(name: string) {
586
- if (!projectId) return;
587
- try {
588
- await ws.http('git:switch-branch', { projectId, name });
589
- showBranchManager = false;
590
- await loadAll();
591
- } catch (err) {
592
- debug.error('git', 'Failed to switch branch:', err);
593
- showError('Switch Branch Failed', err instanceof Error ? err.message : 'Unknown error');
594
- }
595
- }
596
-
597
- async function createBranch(name: string) {
598
- if (!projectId) return;
599
- try {
600
- await ws.http('git:create-branch', { projectId, name });
601
- showBranchManager = false;
602
- await loadAll();
603
- } catch (err) {
604
- debug.error('git', 'Failed to create branch:', err);
605
- showError('Create Branch Failed', err instanceof Error ? err.message : 'Unknown error');
606
- }
607
- }
608
-
609
- async function deleteBranch(name: string) {
610
- requestConfirm({
611
- title: 'Delete Branch',
612
- message: `Delete branch "${name}"?`,
613
- type: 'error',
614
- confirmText: 'Delete',
615
- onConfirm: async () => {
616
- if (!projectId) return;
617
- try {
618
- await ws.http('git:delete-branch', { projectId, name });
619
- await loadBranches();
620
- } catch (err) {
621
- debug.error('git', 'Failed to delete branch:', err);
622
- requestConfirm({
623
- title: 'Force Delete Branch',
624
- message: 'Branch is not fully merged. Force delete?',
625
- type: 'error',
626
- confirmText: 'Force Delete',
627
- onConfirm: async () => {
628
- try {
629
- await ws.http('git:delete-branch', { projectId, name, force: true });
630
- await loadBranches();
631
- } catch (forceErr) {
632
- showError('Force Delete Failed', forceErr instanceof Error ? forceErr.message : 'Unknown error');
633
- }
634
- }
635
- });
636
- }
637
- }
638
- });
639
- }
640
-
641
- async function renameBranch(oldName: string, newName: string) {
642
- if (!projectId) return;
643
- try {
644
- await ws.http('git:rename-branch', { projectId, oldName, newName });
645
- await loadBranches();
646
- } catch (err) {
647
- debug.error('git', 'Failed to rename branch:', err);
648
- }
649
- }
650
-
651
- async function mergeBranch(name: string) {
652
- requestConfirm({
653
- title: 'Merge Branch',
654
- message: `Merge "${name}" into "${branchInfo?.current}"?`,
655
- type: 'info',
656
- confirmText: 'Merge',
657
- onConfirm: async () => {
658
- if (!projectId) return;
659
- try {
660
- const result = await ws.http('git:merge-branch', { projectId, branchName: name });
661
- showBranchManager = false;
662
- if (!result.success) {
663
- await loadAll();
664
- if (gitStatus.conflicted.length > 0) {
665
- await loadConflicts();
666
- showConflictResolver = true;
667
- } else {
668
- showError('Merge Failed', result.message);
669
- }
670
- } else {
671
- await loadAll();
672
- }
673
- } catch (err) {
674
- debug.error('git', 'Failed to merge branch:', err);
675
- }
676
- }
677
- });
678
- }
679
-
680
- // ============================
681
- // Remote Operations
682
- // ============================
683
-
684
- let isFetching = $state(false);
685
- let isPulling = $state(false);
686
- let isPushing = $state(false);
687
-
688
- async function handleFetch() {
689
- if (!projectId || isFetching) return;
690
- isFetching = true;
691
- try {
692
- const prevAhead = branchInfo?.ahead ?? 0;
693
- const prevBehind = branchInfo?.behind ?? 0;
694
- await ws.http('git:fetch', { projectId, remote: selectedRemote });
695
- await loadBranches();
696
- const newAhead = branchInfo?.ahead ?? 0;
697
- const newBehind = branchInfo?.behind ?? 0;
698
- const parts: string[] = [];
699
- if (newAhead > 0) parts.push(`${newAhead} ahead`);
700
- if (newBehind > 0) parts.push(`${newBehind} behind`);
701
- if (parts.length > 0) {
702
- showInfo('Fetch Complete', `Your branch is ${parts.join(', ')} ${selectedRemote}.`);
703
- } else if (prevBehind > 0 || prevAhead > 0) {
704
- showInfo('Fetch Complete', `In sync with ${selectedRemote}.`);
705
- } else {
706
- showInfo('Fetch Complete', `Already up to date with ${selectedRemote}.`);
707
- }
708
- } catch (err) {
709
- debug.error('git', 'Fetch failed:', err);
710
- showError('Fetch Failed', err instanceof Error ? err.message : 'Unknown error');
711
- } finally {
712
- isFetching = false;
713
- }
714
- }
715
-
716
- async function handlePull() {
717
- if (!projectId || isPulling) return;
718
- isPulling = true;
719
- try {
720
- const prevBehind = branchInfo?.behind ?? 0;
721
- const result = await ws.http('git:pull', { projectId, remote: selectedRemote, branch: branchInfo?.current });
722
- if (!result.success) {
723
- if (result.message.includes('conflict')) {
724
- await loadAll();
725
- await loadConflicts();
726
- showConflictResolver = true;
727
- } else {
728
- showError('Pull Failed', result.message);
729
- }
730
- } else {
731
- await loadAll();
732
- if (prevBehind > 0) {
733
- showInfo('Pull Complete', `Pulled ${prevBehind} commit${prevBehind > 1 ? 's' : ''} from ${selectedRemote}.`);
734
- } else {
735
- showInfo('Pull Complete', `Already up to date with ${selectedRemote}.`);
736
- }
737
- }
738
- } catch (err) {
739
- debug.error('git', 'Pull failed:', err);
740
- showError('Pull Failed', err instanceof Error ? err.message : 'Unknown error');
741
- } finally {
742
- isPulling = false;
743
- }
744
- }
745
-
746
- async function handlePush() {
747
- if (!projectId || isPushing) return;
748
- isPushing = true;
749
- try {
750
- const prevAhead = branchInfo?.ahead ?? 0;
751
- const result = await ws.http('git:push', { projectId, remote: selectedRemote, branch: branchInfo?.current });
752
- if (!result.success) {
753
- showError('Push Failed', result.message);
754
- } else {
755
- await loadBranches();
756
- if (prevAhead > 0) {
757
- showInfo('Push Complete', `Pushed ${prevAhead} commit${prevAhead > 1 ? 's' : ''} to ${selectedRemote}.`);
758
- } else {
759
- showInfo('Push Complete', `Branch pushed to ${selectedRemote}.`);
760
- }
761
- }
762
- } catch (err) {
763
- debug.error('git', 'Push failed:', err);
764
- showError('Push Failed', err instanceof Error ? err.message : 'Unknown error');
765
- } finally {
766
- isPushing = false;
767
- }
768
- }
769
-
770
- // ============================
771
- // Conflict Resolution
772
- // ============================
773
-
774
- async function resolveConflict(filePath: string, resolution: 'ours' | 'theirs' | 'custom', customContent?: string) {
775
- if (!projectId) return;
776
- try {
777
- await ws.http('git:resolve-conflict', { projectId, filePath, resolution, customContent });
778
- await loadConflicts();
779
- await loadStatus();
780
- if (conflictFiles.length === 0) {
781
- showConflictResolver = false;
782
- }
783
- } catch (err) {
784
- debug.error('git', 'Failed to resolve conflict:', err);
785
- }
786
- }
787
-
788
- function resolveWithAI(filePath: string) {
789
- showConflictResolver = false;
790
- showInfo('AI Conflict Resolution', `To resolve "${filePath}" with AI, open the Chat panel and describe the conflict. The AI will help you resolve it.`);
791
- }
792
-
793
- async function abortMerge() {
794
- requestConfirm({
795
- title: 'Abort Merge',
796
- message: 'Abort the current merge? All conflict resolutions will be lost.',
797
- type: 'error',
798
- confirmText: 'Abort Merge',
799
- onConfirm: async () => {
800
- if (!projectId) return;
801
- try {
802
- await ws.http('git:abort-merge', { projectId });
803
- showConflictResolver = false;
804
- await loadAll();
805
- } catch (err) {
806
- debug.error('git', 'Failed to abort merge:', err);
807
- }
808
- }
809
- });
810
- }
811
-
812
- function openConflictResolver(path: string) {
813
- loadConflicts().then(() => {
814
- showConflictResolver = true;
815
- });
816
- }
817
-
818
- // ============================
819
- // Stash Operations
820
- // ============================
821
-
822
- async function loadStash() {
823
- if (!projectId) return;
824
- isStashLoading = true;
825
- try {
826
- stashEntries = await ws.http('git:stash-list', { projectId });
827
- } catch (err) {
828
- debug.error('git', 'Failed to load stash list:', err);
829
- } finally {
830
- isStashLoading = false;
831
- }
832
- }
833
-
834
- async function handleStashSave() {
835
- if (!projectId) return;
836
- try {
837
- await ws.http('git:stash-save', { projectId, message: stashMessage.trim() || undefined });
838
- stashMessage = '';
839
- showStashSaveForm = false;
840
- await Promise.all([loadStash(), loadStatus()]);
841
- } catch (err) {
842
- debug.error('git', 'Stash save failed:', err);
843
- showError('Stash Failed', err instanceof Error ? err.message : 'Unknown error');
844
- }
845
- }
846
-
847
- async function handleStashPop(index: number) {
848
- if (!projectId) return;
849
- try {
850
- await ws.http('git:stash-pop', { projectId, index });
851
- await Promise.all([loadStash(), loadStatus()]);
852
- } catch (err) {
853
- debug.error('git', 'Stash pop failed:', err);
854
- showError('Stash Pop Failed', err instanceof Error ? err.message : 'Unknown error');
855
- }
856
- }
857
-
858
- async function handleStashDrop(index: number) {
859
- requestConfirm({
860
- title: 'Drop Stash',
861
- message: `Drop stash@{${index}}? This cannot be undone.`,
862
- type: 'error',
863
- confirmText: 'Drop',
864
- onConfirm: async () => {
865
- if (!projectId) return;
866
- try {
867
- await ws.http('git:stash-drop', { projectId, index });
868
- await loadStash();
869
- } catch (err) {
870
- debug.error('git', 'Stash drop failed:', err);
871
- showError('Stash Drop Failed', err instanceof Error ? err.message : 'Unknown error');
872
- }
873
- }
874
- });
875
- }
876
-
877
- // ============================
878
- // Tag Operations
879
- // ============================
880
-
881
- async function loadTags() {
882
- if (!projectId) return;
883
- isTagsLoading = true;
884
- try {
885
- tags = await ws.http('git:tags', { projectId });
886
- } catch (err) {
887
- debug.error('git', 'Failed to load tags:', err);
888
- } finally {
889
- isTagsLoading = false;
890
- }
891
- }
892
-
893
- async function handleCreateTag() {
894
- if (!projectId || !newTagName.trim()) return;
895
- try {
896
- await ws.http('git:create-tag', {
897
- projectId,
898
- name: newTagName.trim(),
899
- message: newTagMessage.trim() || undefined
900
- });
901
- newTagName = '';
902
- newTagMessage = '';
903
- showCreateTagForm = false;
904
- await loadTags();
905
- } catch (err) {
906
- debug.error('git', 'Create tag failed:', err);
907
- showError('Create Tag Failed', err instanceof Error ? err.message : 'Unknown error');
908
- }
909
- }
910
-
911
- async function handleDeleteTag(name: string) {
912
- requestConfirm({
913
- title: 'Delete Tag',
914
- message: `Delete tag "${name}"?`,
915
- type: 'error',
916
- confirmText: 'Delete',
917
- onConfirm: async () => {
918
- if (!projectId) return;
919
- try {
920
- await ws.http('git:delete-tag', { projectId, name });
921
- await loadTags();
922
- } catch (err) {
923
- debug.error('git', 'Delete tag failed:', err);
924
- showError('Delete Tag Failed', err instanceof Error ? err.message : 'Unknown error');
925
- }
926
- }
927
- });
928
- }
929
-
930
- async function handlePushTag(name: string) {
931
- if (!projectId) return;
932
- try {
933
- const result = await ws.http('git:push-tag', { projectId, name });
934
- if (!result.success) {
935
- showError('Push Tag Failed', result.message);
936
- } else {
937
- showInfo('Tag Pushed', `Tag "${name}" pushed to remote.`);
938
- }
939
- } catch (err) {
940
- debug.error('git', 'Push tag failed:', err);
941
- showError('Push Tag Failed', err instanceof Error ? err.message : 'Unknown error');
942
- }
943
- }
944
-
945
- async function copyTagHash(hash: string, e: MouseEvent) {
946
- e.stopPropagation();
947
- try {
948
- await navigator.clipboard.writeText(hash);
949
- showInfo('Copied', `Hash ${hash.substring(0, 7)} copied to clipboard`);
950
- } catch {
951
- showError('Copy Failed', 'Could not copy to clipboard');
952
- }
953
- }
954
-
955
- // ============================
956
- // Lifecycle
957
- // ============================
958
-
959
- $effect(() => {
960
- if (hasActiveProject && projectId) {
961
- const prevId = untrack(() => lastProjectId);
962
- if (projectId !== prevId) {
963
- lastProjectId = projectId;
964
- activeView = 'changes';
965
- resetAllViewTabs();
966
- commits = [];
967
- logSkip = 0;
968
- loadAll();
969
- }
970
- }
971
- });
972
-
973
- // Load log when switching to log view
974
- $effect(() => {
975
- if (activeView === 'log' && isRepo) {
976
- untrack(() => {
977
- if (commits.length === 0) {
978
- loadLog(true);
979
- }
980
- });
981
- }
982
- });
983
-
984
- // Load stash when switching to stash view
985
- $effect(() => {
986
- if (activeView === 'stash' && isRepo) {
987
- untrack(() => loadStash());
988
- }
989
- });
990
-
991
- // Load tags when switching to tags view
992
- $effect(() => {
993
- if (activeView === 'tags' && isRepo) {
994
- untrack(() => loadTags());
995
- }
996
- });
997
-
998
- // Sync view mode on column mode change
999
- let prevTwoColumnMode = $state<boolean | null>(null);
1000
- $effect(() => {
1001
- if (prevTwoColumnMode !== null && prevTwoColumnMode !== isTwoColumnMode) {
1002
- if (!isTwoColumnMode) {
1003
- if (activeTabId && openTabs.length > 0) {
1004
- viewMode = 'diff';
1005
- } else {
1006
- viewMode = 'list';
1007
- }
1008
- }
1009
- }
1010
- prevTwoColumnMode = isTwoColumnMode;
1011
- });
1012
-
1013
- // Start file watcher for this project (idempotent — won't duplicate if FilesPanel already started it)
1014
- $effect(() => {
1015
- if (hasActiveProject && projectId && projectState.currentProject?.path) {
1016
- ws.emit('files:watch', { projectPath: projectState.currentProject.path });
1017
- }
1018
- });
1019
-
1020
- // Debounce timer for file/git change events
1021
- let changeDebounce: ReturnType<typeof setTimeout> | null = null;
1022
-
1023
- // Shared refresh logic for both file changes and git state changes
1024
- function scheduleGitRefresh() {
1025
- if (changeDebounce) clearTimeout(changeDebounce);
1026
- changeDebounce = setTimeout(async () => {
1027
- changeDebounce = null;
1028
- // Refresh git status and branches (branch switch also modifies working tree)
1029
- const prevBranch = branchInfo?.current;
1030
- await Promise.all([loadStatus(), loadBranches()]);
1031
-
1032
- // If branch changed, also refresh remotes
1033
- if (branchInfo?.current !== prevBranch) {
1034
- loadRemotes();
1035
- }
1036
-
1037
- // Refresh the active diff tab if currently viewing one
1038
- if (activeTab && !activeTab.isLoading && activeTab.section !== 'commit' && activeTab.status !== '?') {
1039
- const tab = activeTab;
1040
- try {
1041
- const action = tab.section === 'staged' ? 'git:diff-staged' : 'git:diff-unstaged';
1042
- const diffs = await ws.http(action, { projectId, filePath: tab.filePath });
1043
- const diffResult = diffs.length > 0 ? diffs[0] : null;
1044
- openTabs = openTabs.map(t =>
1045
- t.id === tab.id ? { ...t, diff: diffResult } : t
1046
- );
1047
- } catch {
1048
- // Silently ignore — file may have been removed from status
1049
- }
1050
- }
1051
- }, 400);
1052
- }
1053
-
1054
- // Subscribe to file change events (working tree changes)
1055
- $effect(() => {
1056
- if (!hasActiveProject || !projectId) return;
1057
-
1058
- const unsub = ws.on('files:changed', (payload: any) => {
1059
- if (payload.projectId !== projectId || !isRepo) return;
1060
- scheduleGitRefresh();
1061
- });
1062
-
1063
- return () => {
1064
- unsub();
1065
- if (changeDebounce) {
1066
- clearTimeout(changeDebounce);
1067
- changeDebounce = null;
1068
- }
1069
- };
1070
- });
1071
-
1072
- // Subscribe to git state change events (external git add, commit, branch switch, etc.)
1073
- $effect(() => {
1074
- if (!hasActiveProject || !projectId) return;
1075
-
1076
- const unsub = ws.on('git:changed', (payload: any) => {
1077
- if (payload.projectId !== projectId || !isRepo) return;
1078
- scheduleGitRefresh();
1079
- // Refresh branches and remotes in case of branch switch/create/delete
1080
- loadBranches();
1081
- loadRemotes();
1082
- // Refresh log if it was already loaded (History tab was visited)
1083
- if (commits.length > 0) {
1084
- loadLog(true);
1085
- }
1086
- });
1087
-
1088
- return () => unsub();
1089
- });
1090
-
1091
- function startColumnResize(e: MouseEvent) {
1092
- isResizing = true;
1093
- const startX = e.clientX;
1094
- const startWidth = leftPanelWidth;
1095
-
1096
- function onMouseMove(e: MouseEvent) {
1097
- const delta = e.clientX - startX;
1098
- leftPanelWidth = Math.max(120, Math.min(startWidth + delta, containerWidth - 120));
1099
- }
1100
-
1101
- function onMouseUp() {
1102
- isResizing = false;
1103
- window.removeEventListener('mousemove', onMouseMove);
1104
- window.removeEventListener('mouseup', onMouseUp);
1105
- }
1106
-
1107
- window.addEventListener('mousemove', onMouseMove);
1108
- window.addEventListener('mouseup', onMouseUp);
1109
- }
1110
-
1111
- // Monitor container width
1112
- onMount(() => {
1113
- let resizeObserver: ResizeObserver | null = null;
1114
- if (containerRef && typeof ResizeObserver !== 'undefined') {
1115
- resizeObserver = new ResizeObserver((entries) => {
1116
- for (const entry of entries) {
1117
- containerWidth = entry.contentRect.width;
1118
- }
1119
- });
1120
- resizeObserver.observe(containerRef);
1121
- }
1122
-
1123
- return () => {
1124
- resizeObserver?.disconnect();
1125
- };
1126
- });
1127
-
1128
- // Combined unstaged + untracked
1129
- const allChanges = $derived([...gitStatus.unstaged, ...gitStatus.untracked]);
1130
-
1131
- // Total changes count
1132
- const totalChanges = $derived(
1133
- gitStatus.staged.length + allChanges.length + gitStatus.conflicted.length
1134
- );
1135
-
1136
- // View tabs config for tab bar
1137
- const viewTabs = $derived([
1138
- { id: 'changes' as const, label: 'Changes', icon: 'lucide:file-pen' as IconName, badge: totalChanges > 0 ? totalChanges : null },
1139
- { id: 'log' as const, label: 'History', icon: 'lucide:history' as IconName, badge: null },
1140
- { id: 'stash' as const, label: 'Stash', icon: 'lucide:archive' as IconName, badge: stashEntries.length > 0 ? stashEntries.length : null },
1141
- { id: 'tags' as const, label: 'Tags', icon: 'lucide:tag' as IconName, badge: tags.length > 0 ? tags.length : null }
1142
- ]);
1143
-
1144
- // Exported panel actions for PanelHeader
1145
- export const panelActions = {
1146
- push: handlePush,
1147
- pull: handlePull,
1148
- fetch: handleFetch,
1149
- init: handleInit,
1150
- openBranchManager: () => { showBranchManager = true; },
1151
- getBranchInfo: () => branchInfo,
1152
- getIsRepo: () => isRepo,
1153
- getIsFetching: () => isFetching,
1154
- getIsPulling: () => isPulling,
1155
- getIsPushing: () => isPushing,
1156
- getRemotes: () => remotes,
1157
- getHasRemotes: () => remotes.length > 0,
1158
- getSelectedRemote: () => selectedRemote,
1159
- setSelectedRemote: (name: string) => { selectedRemote = name; },
1160
- setViewMode: (mode: 'list' | 'diff') => {
1161
- if (!isTwoColumnMode) viewMode = mode;
1162
- },
1163
- getViewMode: () => viewMode,
1164
- canShowDiff: () => openTabs.length > 0,
1165
- isTwoColumnMode: () => isTwoColumnMode
1166
- };
1167
- </script>
1168
-
1169
- <!-- Tab Bar Snippet -->
1170
- {#snippet tabBar()}
1171
- {#if openTabs.length > 0}
1172
- <div class="flex items-center border-b border-slate-200 dark:border-slate-700 bg-slate-50/80 dark:bg-slate-800/50 overflow-x-auto flex-shrink-0">
1173
- {#each openTabs as tab (tab.id)}
1174
- {@const isActive = tab.id === activeTabId}
1175
- <div
1176
- class="flex items-center gap-1.5 pl-3 pr-4 py-2 text-xs border-r border-slate-200/50 dark:border-slate-700/50 whitespace-nowrap transition-colors flex-shrink-0 cursor-pointer {isActive
1177
- ? 'bg-white dark:bg-slate-900 text-slate-900 dark:text-slate-100'
1178
- : 'text-slate-500 dark:text-slate-400 hover:bg-slate-100 dark:hover:bg-slate-800 hover:text-slate-700 dark:hover:text-slate-300'}"
1179
- onclick={() => selectTab(tab.id)}
1180
- >
1181
- <Icon name={getFileIcon(tab.fileName) as IconName} class="w-3.5 h-3.5 flex-shrink-0" />
1182
- <span class="truncate max-w-28">{tab.fileName}</span>
1183
- {#if tab.isLoading}
1184
- <div class="w-2 h-2 border border-slate-400 border-t-transparent rounded-full animate-spin flex-shrink-0"></div>
1185
- {:else if tab.status}
1186
- <span class="text-xs font-bold {getGitStatusColor(tab.status)} flex-shrink-0">{getGitStatusLabel(tab.status)}</span>
1187
- {/if}
1188
- </div>
1189
- {/each}
1190
- </div>
1191
- {/if}
1192
- {/snippet}
1193
-
1194
- <!-- View tabs snippet (always visible, even in single-column diff mode) -->
1195
- {#snippet viewTabBar()}
1196
- <div class="relative flex border-b border-slate-200 dark:border-slate-700">
1197
- {#each viewTabs as tab (tab.id)}
1198
- {@const isActive = activeView === tab.id}
1199
- <button
1200
- type="button"
1201
- class="relative flex-1 flex items-center justify-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors {isActive
1202
- ? 'text-violet-600 dark:text-violet-400'
1203
- : 'text-slate-500 dark:text-slate-400 hover:text-slate-700 dark:hover:text-slate-300'}"
1204
- onclick={() => switchToView(tab.id)}
1205
- >
1206
- {tab.label}
1207
- {#if tab.badge}
1208
- <span class="min-w-4 h-4 px-1 rounded-full bg-violet-500/15 dark:bg-violet-500/25 text-3xs font-semibold flex items-center justify-center">{tab.badge}</span>
1209
- {/if}
1210
- {#if isActive}
1211
- <span class="absolute bottom-0 inset-x-0 h-px bg-violet-600 dark:bg-violet-400"></span>
1212
- {/if}
1213
- </button>
1214
- {/each}
1215
- </div>
1216
- {/snippet}
1217
-
1218
- <!-- Changes list snippet -->
1219
- {#snippet changesList()}
1220
- {#if activeView === 'changes'}
1221
- <!-- Commit form -->
1222
- <CommitForm
1223
- stagedCount={gitStatus.staged.length}
1224
- {isCommitting}
1225
- onCommit={handleCommit}
1226
- />
1227
-
1228
- <!-- Changes sections -->
1229
- <div class="flex-1 overflow-y-auto px-1">
1230
- {#if gitStatus.conflicted.length > 0}
1231
- <ChangesSection
1232
- title="Conflicts"
1233
- icon="lucide:triangle-alert"
1234
- files={gitStatus.conflicted}
1235
- section="conflicted"
1236
- onViewDiff={viewDiff}
1237
- onResolve={openConflictResolver}
1238
- />
1239
- {/if}
1240
-
1241
- <ChangesSection
1242
- title="Staged Changes"
1243
- icon="lucide:circle-check"
1244
- files={gitStatus.staged}
1245
- section="staged"
1246
- onUnstage={unstageFile}
1247
- onUnstageAll={unstageAll}
1248
- onViewDiff={viewDiff}
1249
- />
1250
-
1251
- <ChangesSection
1252
- title="Changes"
1253
- icon="lucide:file-pen"
1254
- files={allChanges}
1255
- section="unstaged"
1256
- onStage={stageFile}
1257
- onStageAll={stageAll}
1258
- onDiscard={discardFile}
1259
- onDiscardAll={discardAll}
1260
- onViewDiff={viewDiff}
1261
- />
1262
-
1263
- {#if totalChanges === 0 && !isLoading}
1264
- <div class="flex flex-col items-center justify-center gap-2 py-8 text-slate-500 text-xs">
1265
- <Icon name="lucide:circle-check" class="w-6 h-6 opacity-30" />
1266
- <span>Working tree clean</span>
1267
- </div>
1268
- {/if}
1269
- </div>
1270
- {:else if activeView === 'log'}
1271
- <GitLog
1272
- {commits}
1273
- isLoading={isLogLoading}
1274
- hasMore={logHasMore}
1275
- onLoadMore={() => loadLog()}
1276
- onViewCommit={viewCommitDiff}
1277
- />
1278
- {:else if activeView === 'stash'}
1279
- <!-- Stash View -->
1280
- <div class="flex-1 overflow-y-auto pt-2">
1281
- <!-- Stash save button/form -->
1282
- <div class="px-2 pb-2">
1283
- {#if showStashSaveForm}
1284
- <div class="p-2.5 bg-slate-50 dark:bg-slate-800/50 border border-slate-200 dark:border-slate-700 rounded-lg space-y-2">
1285
- <input
1286
- type="text"
1287
- bind:value={stashMessage}
1288
- placeholder="Stash message (optional)..."
1289
- class="w-full px-2.5 py-2 text-sm bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 rounded-md text-slate-900 dark:text-slate-100 outline-none focus:border-violet-500/40 focus:ring-1 focus:ring-violet-500/20"
1290
- onkeydown={(e) => e.key === 'Enter' && handleStashSave()}
1291
- />
1292
- <div class="flex gap-1.5">
1293
- <button
1294
- type="button"
1295
- class="flex-1 px-3 py-1.5 text-xs font-medium rounded-md bg-violet-600 text-white hover:bg-violet-700 transition-colors cursor-pointer border-none"
1296
- onclick={handleStashSave}
1297
- >
1298
- Stash Changes
1299
- </button>
1300
- <button
1301
- type="button"
1302
- class="px-3 py-1.5 text-xs font-medium bg-transparent border border-slate-200 dark:border-slate-700 text-slate-600 dark:text-slate-400 rounded-md hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors cursor-pointer"
1303
- onclick={() => { showStashSaveForm = false; stashMessage = ''; }}
1304
- >
1305
- Cancel
1306
- </button>
1307
- </div>
1308
- </div>
1309
- {:else}
1310
- <button
1311
- type="button"
1312
- class="flex items-center justify-center gap-2 w-full py-2 px-3 border border-dashed border-slate-300 dark:border-slate-600 rounded-lg text-xs text-slate-500 hover:text-violet-600 hover:border-violet-400 transition-colors cursor-pointer bg-transparent"
1313
- onclick={() => showStashSaveForm = true}
1314
- >
1315
- <Icon name="lucide:archive" class="w-3.5 h-3.5" />
1316
- <span>Stash Current Changes</span>
1317
- </button>
1318
- {/if}
1319
- </div>
1320
-
1321
- {#if isStashLoading}
1322
- <div class="flex items-center justify-center py-8">
1323
- <div class="w-5 h-5 border-2 border-slate-200 dark:border-slate-700 border-t-violet-600 rounded-full animate-spin"></div>
1324
- </div>
1325
- {:else if stashEntries.length === 0}
1326
- <div class="flex flex-col items-center justify-center gap-2 py-8 text-slate-500 text-xs">
1327
- <Icon name="lucide:archive" class="w-6 h-6 opacity-30" />
1328
- <span>No stashed changes</span>
1329
- </div>
1330
- {:else}
1331
- <div class="space-y-1 px-1">
1332
- {#each stashEntries as entry (entry.index)}
1333
- <div class="group flex items-center gap-2 px-2.5 py-2 rounded-md hover:bg-slate-100 dark:hover:bg-slate-800/60 transition-colors">
1334
- <Icon name="lucide:archive" class="w-4 h-4 text-slate-400 shrink-0" />
1335
- <div class="flex-1 min-w-0">
1336
- <p class="text-sm font-medium text-slate-900 dark:text-slate-100 truncate">{entry.message}</p>
1337
- <p class="text-xs text-slate-400 dark:text-slate-500">stash@&#123;{entry.index}&#125;</p>
1338
- </div>
1339
- <div class="flex items-center gap-0.5 shrink-0">
1340
- <button
1341
- type="button"
1342
- class="flex items-center justify-center w-7 h-7 rounded-md text-slate-400 hover:bg-emerald-500/10 hover:text-emerald-500 transition-colors bg-transparent border-none cursor-pointer"
1343
- onclick={() => handleStashPop(entry.index)}
1344
- title="Pop (apply and remove)"
1345
- >
1346
- <Icon name="lucide:archive-restore" class="w-3.5 h-3.5" />
1347
- </button>
1348
- <button
1349
- type="button"
1350
- class="flex items-center justify-center w-7 h-7 rounded-md text-slate-400 hover:bg-red-500/10 hover:text-red-500 transition-colors bg-transparent border-none cursor-pointer"
1351
- onclick={() => handleStashDrop(entry.index)}
1352
- title="Drop (delete)"
1353
- >
1354
- <Icon name="lucide:trash-2" class="w-3.5 h-3.5" />
1355
- </button>
1356
- </div>
1357
- </div>
1358
- {/each}
1359
- </div>
1360
- {/if}
1361
- </div>
1362
- {:else if activeView === 'tags'}
1363
- <!-- Tags View -->
1364
- <div class="flex-1 overflow-y-auto pt-2">
1365
- <!-- Create tag button/form -->
1366
- <div class="px-2 pb-2">
1367
- {#if showCreateTagForm}
1368
- <div class="p-2.5 bg-slate-50 dark:bg-slate-800/50 border border-slate-200 dark:border-slate-700 rounded-lg space-y-2">
1369
- <input
1370
- type="text"
1371
- bind:value={newTagName}
1372
- placeholder="Tag name (e.g. v1.0.0)..."
1373
- class="w-full px-2.5 py-2 text-sm bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 rounded-md text-slate-900 dark:text-slate-100 outline-none focus:border-violet-500/40 focus:ring-1 focus:ring-violet-500/20"
1374
- onkeydown={(e) => e.key === 'Enter' && !newTagMessage && handleCreateTag()}
1375
- />
1376
- <input
1377
- type="text"
1378
- bind:value={newTagMessage}
1379
- placeholder="Tag message (optional, makes annotated tag)..."
1380
- class="w-full px-2.5 py-2 text-sm bg-white dark:bg-slate-900 border border-slate-200 dark:border-slate-700 rounded-md text-slate-900 dark:text-slate-100 outline-none focus:border-violet-500/40 focus:ring-1 focus:ring-violet-500/20"
1381
- onkeydown={(e) => e.key === 'Enter' && handleCreateTag()}
1382
- />
1383
- <div class="flex gap-1.5">
1384
- <button
1385
- type="button"
1386
- class="flex-1 px-3 py-1.5 text-xs font-medium rounded-md transition-colors cursor-pointer border-none
1387
- {newTagName.trim()
1388
- ? 'bg-violet-600 text-white hover:bg-violet-700'
1389
- : 'bg-slate-200 dark:bg-slate-700 text-slate-400 dark:text-slate-500 cursor-not-allowed'}"
1390
- onclick={handleCreateTag}
1391
- disabled={!newTagName.trim()}
1392
- >
1393
- Create Tag
1394
- </button>
1395
- <button
1396
- type="button"
1397
- class="px-3 py-1.5 text-xs font-medium bg-transparent border border-slate-200 dark:border-slate-700 text-slate-600 dark:text-slate-400 rounded-md hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors cursor-pointer"
1398
- onclick={() => { showCreateTagForm = false; newTagName = ''; newTagMessage = ''; }}
1399
- >
1400
- Cancel
1401
- </button>
1402
- </div>
1403
- </div>
1404
- {:else}
1405
- <button
1406
- type="button"
1407
- class="flex items-center justify-center gap-2 w-full py-2 px-3 border border-dashed border-slate-300 dark:border-slate-600 rounded-lg text-xs text-slate-500 hover:text-violet-600 hover:border-violet-400 transition-colors cursor-pointer bg-transparent"
1408
- onclick={() => showCreateTagForm = true}
1409
- >
1410
- <Icon name="lucide:tag" class="w-3.5 h-3.5" />
1411
- <span>Create New Tag</span>
1412
- </button>
1413
- {/if}
1414
- </div>
1415
-
1416
- {#if isTagsLoading}
1417
- <div class="flex items-center justify-center py-8">
1418
- <div class="w-5 h-5 border-2 border-slate-200 dark:border-slate-700 border-t-violet-600 rounded-full animate-spin"></div>
1419
- </div>
1420
- {:else if tags.length === 0}
1421
- <div class="flex flex-col items-center justify-center gap-2 py-8 text-slate-500 text-xs">
1422
- <Icon name="lucide:tag" class="w-6 h-6 opacity-30" />
1423
- <span>No tags</span>
1424
- </div>
1425
- {:else}
1426
- <div class="space-y-1 px-1">
1427
- {#each tags as tag (tag.name)}
1428
- <div class="group flex items-center gap-2 px-2.5 py-2 rounded-md hover:bg-slate-100 dark:hover:bg-slate-800/60 transition-colors">
1429
- <Icon name="lucide:tag" class="w-4 h-4 text-slate-400 shrink-0" />
1430
- <div class="flex-1 min-w-0">
1431
- <p class="text-sm font-medium text-slate-900 dark:text-slate-100 truncate">{tag.name}</p>
1432
- <div class="flex items-center gap-1.5">
1433
- <button
1434
- type="button"
1435
- class="text-xs font-mono text-slate-400 dark:text-slate-500 hover:text-violet-600 dark:hover:text-violet-400 bg-transparent border-none cursor-pointer p-0 shrink-0 transition-colors"
1436
- onclick={(e) => copyTagHash(tag.hash, e)}
1437
- title="Copy tag hash"
1438
- >{tag.hash.slice(0, 7)}</button>
1439
- {#if tag.message}
1440
- <span class="text-xs text-slate-400 dark:text-slate-500 truncate">{tag.message}</span>
1441
- {/if}
1442
- </div>
1443
- </div>
1444
- <div class="flex items-center gap-0.5 shrink-0">
1445
- <button
1446
- type="button"
1447
- class="flex items-center justify-center w-7 h-7 rounded-md text-slate-400 hover:bg-blue-500/10 hover:text-blue-500 transition-colors bg-transparent border-none cursor-pointer"
1448
- onclick={() => handlePushTag(tag.name)}
1449
- title="Push tag to remote"
1450
- >
1451
- <Icon name="lucide:arrow-up-from-line" class="w-3.5 h-3.5" />
1452
- </button>
1453
- <button
1454
- type="button"
1455
- class="flex items-center justify-center w-7 h-7 rounded-md text-slate-400 hover:bg-red-500/10 hover:text-red-500 transition-colors bg-transparent border-none cursor-pointer"
1456
- onclick={() => handleDeleteTag(tag.name)}
1457
- title="Delete tag"
1458
- >
1459
- <Icon name="lucide:trash-2" class="w-3.5 h-3.5" />
1460
- </button>
1461
- </div>
1462
- </div>
1463
- {/each}
1464
- </div>
1465
- {/if}
1466
- </div>
1467
- {/if}
1468
- {/snippet}
1469
-
1470
- <!-- Diff panel snippet -->
1471
- {#snippet diffPanel()}
1472
- {@render tabBar()}
1473
- <div class="flex-1 overflow-hidden">
1474
- {#if activeTab}
1475
- <DiffViewer
1476
- diff={activeTab.diff}
1477
- isLoading={activeTab.isLoading}
1478
- />
1479
- {:else}
1480
- <div class="h-full flex flex-col items-center justify-center gap-2 text-slate-500 text-xs">
1481
- <Icon name="lucide:file-diff" class="w-8 h-8 opacity-30" />
1482
- <span>Select a file to view diff</span>
1483
- </div>
1484
- {/if}
1485
- </div>
1486
- {/snippet}
1487
-
1488
- <div class="h-full flex flex-col bg-transparent" bind:this={containerRef}>
1489
- {#if !hasActiveProject}
1490
- <div class="flex-1 flex flex-col items-center justify-center gap-3 text-slate-600 dark:text-slate-500 text-sm">
1491
- <Icon name="lucide:git-branch" class="w-10 h-10 opacity-30" />
1492
- <span>No project selected</span>
1493
- </div>
1494
- {:else if isLoading && !isRepo}
1495
- <div class="flex-1 flex flex-col items-center justify-center gap-3 text-slate-600 dark:text-slate-500 text-sm">
1496
- <div class="w-6 h-6 border-2 border-slate-200 dark:border-slate-800 border-t-violet-600 rounded-full animate-spin"></div>
1497
- <span>Loading...</span>
1498
- </div>
1499
- {:else if !isRepo}
1500
- <div class="flex-1 flex flex-col items-center justify-center gap-4 text-slate-600 dark:text-slate-500 text-sm px-6">
1501
- <Icon name="lucide:git-branch" class="w-10 h-10 opacity-30" />
1502
- <span>Not a git repository</span>
1503
- <p class="text-xs text-slate-400 dark:text-slate-500 text-center max-w-60">
1504
- Initialize a git repository to start tracking your changes.
1505
- </p>
1506
- <button
1507
- type="button"
1508
- class="flex items-center gap-2 px-4 py-2 rounded-lg text-sm font-medium transition-all duration-150
1509
- {isInitializing
1510
- ? 'bg-slate-100 dark:bg-slate-800 text-slate-400 cursor-not-allowed'
1511
- : 'bg-violet-600 text-white hover:bg-violet-700 cursor-pointer'}"
1512
- onclick={handleInit}
1513
- disabled={isInitializing}
1514
- >
1515
- {#if isInitializing}
1516
- <div class="w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"></div>
1517
- <span>Initializing...</span>
1518
- {:else}
1519
- <Icon name="lucide:folder-git-2" class="w-4 h-4" />
1520
- <span>Initialize Repository</span>
1521
- {/if}
1522
- </button>
1523
- </div>
1524
- {:else}
1525
- <div class="flex-1 overflow-hidden">
1526
- <!-- Unified layout: always render both panels to preserve state (like Files panel) -->
1527
- <div class="h-full flex" class:select-none={isResizing} class:cursor-col-resize={isResizing}>
1528
- <!-- Left panel: Changes list -->
1529
- <div
1530
- class={isTwoColumnMode
1531
- ? 'flex-shrink-0 h-full overflow-hidden flex flex-col'
1532
- : (viewMode === 'list' ? 'w-full h-full overflow-hidden flex flex-col' : 'hidden')}
1533
- style={isTwoColumnMode ? `width: ${leftPanelWidth}px` : undefined}
1534
- >
1535
- {@render viewTabBar()}
1536
- {@render changesList()}
1537
- </div>
1538
-
1539
- {#if isTwoColumnMode}
1540
- <!-- Column resize handle -->
1541
- <div
1542
- class="relative flex-shrink-0 h-full w-px cursor-col-resize group"
1543
- role="separator"
1544
- aria-orientation="vertical"
1545
- onmousedown={startColumnResize}
1546
- >
1547
- <!-- Invisible extended hit area (6px each side) -->
1548
- <div class="absolute inset-y-0 -left-1.5 -right-1.5 cursor-col-resize z-10"></div>
1549
- <!-- Visual line: 1px default, expands to 4px on hover -->
1550
- <div class="absolute inset-y-0 left-1/2 -translate-x-1/2 w-px group-hover:w-1 bg-slate-200 dark:bg-slate-700 group-hover:bg-blue-400 dark:group-hover:bg-blue-500 transition-all duration-150"></div>
1551
- </div>
1552
- {/if}
1553
-
1554
- <!-- Right panel: Diff viewer -->
1555
- <div
1556
- class={isTwoColumnMode
1557
- ? 'flex-1 h-full overflow-hidden flex flex-col'
1558
- : (viewMode === 'diff' ? 'w-full h-full flex flex-col' : 'hidden')}
1559
- >
1560
- {@render diffPanel()}
1561
- </div>
1562
- </div>
1563
- </div>
1564
- {/if}
1565
-
1566
- <!-- Branch Manager Modal -->
1567
- <BranchManager
1568
- isOpen={showBranchManager}
1569
- {branchInfo}
1570
- onClose={() => showBranchManager = false}
1571
- onSwitch={switchBranch}
1572
- onCreate={createBranch}
1573
- onDelete={deleteBranch}
1574
- onRename={renameBranch}
1575
- onMerge={mergeBranch}
1576
- onRemotesChanged={loadRemotes}
1577
- />
1578
-
1579
- <!-- Conflict Resolver Modal -->
1580
- <ConflictResolver
1581
- isOpen={showConflictResolver}
1582
- {conflictFiles}
1583
- isLoading={isConflictLoading}
1584
- onResolve={resolveConflict}
1585
- onResolveWithAI={resolveWithAI}
1586
- onAbortMerge={abortMerge}
1587
- onClose={() => showConflictResolver = false}
1588
- />
1589
-
1590
- <!-- Confirm Dialog -->
1591
- <Dialog
1592
- bind:isOpen={showConfirmDialog}
1593
- onClose={closeConfirmDialog}
1594
- type={confirmConfig.type}
1595
- title={confirmConfig.title}
1596
- message={confirmConfig.message}
1597
- confirmText={confirmConfig.confirmText}
1598
- cancelText={confirmConfig.cancelText}
1599
- onConfirm={confirmConfig.onConfirm}
1600
- />
1601
- </div>