@siteboon/claude-code-ui 1.12.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -80,34 +80,47 @@ async function validateGitRepository(projectPath) {
80
80
  // Get git status for a project
81
81
  router.get('/status', async (req, res) => {
82
82
  const { project } = req.query;
83
-
83
+
84
84
  if (!project) {
85
85
  return res.status(400).json({ error: 'Project name is required' });
86
86
  }
87
87
 
88
88
  try {
89
89
  const projectPath = await getActualProjectPath(project);
90
-
90
+
91
91
  // Validate git repository
92
92
  await validateGitRepository(projectPath);
93
93
 
94
- // Get current branch
95
- const { stdout: branch } = await execAsync('git rev-parse --abbrev-ref HEAD', { cwd: projectPath });
96
-
94
+ // Get current branch - handle case where there are no commits yet
95
+ let branch = 'main';
96
+ let hasCommits = true;
97
+ try {
98
+ const { stdout: branchOutput } = await execAsync('git rev-parse --abbrev-ref HEAD', { cwd: projectPath });
99
+ branch = branchOutput.trim();
100
+ } catch (error) {
101
+ // No HEAD exists - repository has no commits yet
102
+ if (error.message.includes('unknown revision') || error.message.includes('ambiguous argument')) {
103
+ hasCommits = false;
104
+ branch = 'main';
105
+ } else {
106
+ throw error;
107
+ }
108
+ }
109
+
97
110
  // Get git status
98
111
  const { stdout: statusOutput } = await execAsync('git status --porcelain', { cwd: projectPath });
99
-
112
+
100
113
  const modified = [];
101
114
  const added = [];
102
115
  const deleted = [];
103
116
  const untracked = [];
104
-
117
+
105
118
  statusOutput.split('\n').forEach(line => {
106
119
  if (!line.trim()) return;
107
-
120
+
108
121
  const status = line.substring(0, 2);
109
122
  const file = line.substring(3);
110
-
123
+
111
124
  if (status === 'M ' || status === ' M' || status === 'MM') {
112
125
  modified.push(file);
113
126
  } else if (status === 'A ' || status === 'AM') {
@@ -118,9 +131,10 @@ router.get('/status', async (req, res) => {
118
131
  untracked.push(file);
119
132
  }
120
133
  });
121
-
134
+
122
135
  res.json({
123
- branch: branch.trim(),
136
+ branch,
137
+ hasCommits,
124
138
  modified,
125
139
  added,
126
140
  deleted,
@@ -128,9 +142,9 @@ router.get('/status', async (req, res) => {
128
142
  });
129
143
  } catch (error) {
130
144
  console.error('Git status error:', error);
131
- res.json({
132
- error: error.message.includes('not a git repository') || error.message.includes('Project directory is not a git repository')
133
- ? error.message
145
+ res.json({
146
+ error: error.message.includes('not a git repository') || error.message.includes('Project directory is not a git repository')
147
+ ? error.message
134
148
  : 'Git operation failed',
135
149
  details: error.message.includes('not a git repository') || error.message.includes('Project directory is not a git repository')
136
150
  ? error.message
@@ -161,10 +175,18 @@ router.get('/diff', async (req, res) => {
161
175
  let diff;
162
176
  if (isUntracked) {
163
177
  // For untracked files, show the entire file content as additions
164
- const fileContent = await fs.readFile(path.join(projectPath, file), 'utf-8');
165
- const lines = fileContent.split('\n');
166
- diff = `--- /dev/null\n+++ b/${file}\n@@ -0,0 +1,${lines.length} @@\n` +
167
- lines.map(line => `+${line}`).join('\n');
178
+ const filePath = path.join(projectPath, file);
179
+ const stats = await fs.stat(filePath);
180
+
181
+ if (stats.isDirectory()) {
182
+ // For directories, show a simple message
183
+ diff = `Directory: ${file}\n(Cannot show diff for directories)`;
184
+ } else {
185
+ const fileContent = await fs.readFile(filePath, 'utf-8');
186
+ const lines = fileContent.split('\n');
187
+ diff = `--- /dev/null\n+++ b/${file}\n@@ -0,0 +1,${lines.length} @@\n` +
188
+ lines.map(line => `+${line}`).join('\n');
189
+ }
168
190
  } else if (isDeleted) {
169
191
  // For deleted files, show the entire file content from HEAD as deletions
170
192
  const { stdout: fileContent } = await execAsync(`git show HEAD:"${file}"`, { cwd: projectPath });
@@ -222,7 +244,15 @@ router.get('/file-with-diff', async (req, res) => {
222
244
  currentContent = headContent; // Show the deleted content in editor
223
245
  } else {
224
246
  // Get current file content
225
- currentContent = await fs.readFile(path.join(projectPath, file), 'utf-8');
247
+ const filePath = path.join(projectPath, file);
248
+ const stats = await fs.stat(filePath);
249
+
250
+ if (stats.isDirectory()) {
251
+ // Cannot show content for directories
252
+ return res.status(400).json({ error: 'Cannot show diff for directories' });
253
+ }
254
+
255
+ currentContent = await fs.readFile(filePath, 'utf-8');
226
256
 
227
257
  if (!isUntracked) {
228
258
  // Get the old content from HEAD for tracked files
@@ -248,6 +278,50 @@ router.get('/file-with-diff', async (req, res) => {
248
278
  }
249
279
  });
250
280
 
281
+ // Create initial commit
282
+ router.post('/initial-commit', async (req, res) => {
283
+ const { project } = req.body;
284
+
285
+ if (!project) {
286
+ return res.status(400).json({ error: 'Project name is required' });
287
+ }
288
+
289
+ try {
290
+ const projectPath = await getActualProjectPath(project);
291
+
292
+ // Validate git repository
293
+ await validateGitRepository(projectPath);
294
+
295
+ // Check if there are already commits
296
+ try {
297
+ await execAsync('git rev-parse HEAD', { cwd: projectPath });
298
+ return res.status(400).json({ error: 'Repository already has commits. Use regular commit instead.' });
299
+ } catch (error) {
300
+ // No HEAD - this is good, we can create initial commit
301
+ }
302
+
303
+ // Add all files
304
+ await execAsync('git add .', { cwd: projectPath });
305
+
306
+ // Create initial commit
307
+ const { stdout } = await execAsync('git commit -m "Initial commit"', { cwd: projectPath });
308
+
309
+ res.json({ success: true, output: stdout, message: 'Initial commit created successfully' });
310
+ } catch (error) {
311
+ console.error('Git initial commit error:', error);
312
+
313
+ // Handle the case where there's nothing to commit
314
+ if (error.message.includes('nothing to commit')) {
315
+ return res.status(400).json({
316
+ error: 'Nothing to commit',
317
+ details: 'No files found in the repository. Add some files first.'
318
+ });
319
+ }
320
+
321
+ res.status(500).json({ error: error.message });
322
+ }
323
+ });
324
+
251
325
  // Commit changes
252
326
  router.post('/commit', async (req, res) => {
253
327
  const { project, message, files } = req.body;
@@ -474,8 +548,14 @@ router.post('/generate-commit-message', async (req, res) => {
474
548
  for (const file of files) {
475
549
  try {
476
550
  const filePath = path.join(projectPath, file);
477
- const content = await fs.readFile(filePath, 'utf-8');
478
- diffContext += `\n--- ${file} (new file) ---\n${content.substring(0, 1000)}\n`;
551
+ const stats = await fs.stat(filePath);
552
+
553
+ if (!stats.isDirectory()) {
554
+ const content = await fs.readFile(filePath, 'utf-8');
555
+ diffContext += `\n--- ${file} (new file) ---\n${content.substring(0, 1000)}\n`;
556
+ } else {
557
+ diffContext += `\n--- ${file} (new directory) ---\n`;
558
+ }
479
559
  } catch (error) {
480
560
  console.error(`Error reading file ${file}:`, error);
481
561
  }
@@ -976,10 +1056,17 @@ router.post('/discard', async (req, res) => {
976
1056
  }
977
1057
 
978
1058
  const status = statusOutput.substring(0, 2);
979
-
1059
+
980
1060
  if (status === '??') {
981
- // Untracked file - delete it
982
- await fs.unlink(path.join(projectPath, file));
1061
+ // Untracked file or directory - delete it
1062
+ const filePath = path.join(projectPath, file);
1063
+ const stats = await fs.stat(filePath);
1064
+
1065
+ if (stats.isDirectory()) {
1066
+ await fs.rm(filePath, { recursive: true, force: true });
1067
+ } else {
1068
+ await fs.unlink(filePath);
1069
+ }
983
1070
  } else if (status.includes('M') || status.includes('D')) {
984
1071
  // Modified or deleted file - restore from HEAD
985
1072
  await execAsync(`git restore "${file}"`, { cwd: projectPath });
@@ -1020,10 +1107,18 @@ router.post('/delete-untracked', async (req, res) => {
1020
1107
  return res.status(400).json({ error: 'File is not untracked. Use discard for tracked files.' });
1021
1108
  }
1022
1109
 
1023
- // Delete the untracked file
1024
- await fs.unlink(path.join(projectPath, file));
1025
-
1026
- res.json({ success: true, message: `Untracked file ${file} deleted successfully` });
1110
+ // Delete the untracked file or directory
1111
+ const filePath = path.join(projectPath, file);
1112
+ const stats = await fs.stat(filePath);
1113
+
1114
+ if (stats.isDirectory()) {
1115
+ // Use rm with recursive option for directories
1116
+ await fs.rm(filePath, { recursive: true, force: true });
1117
+ res.json({ success: true, message: `Untracked directory ${file} deleted successfully` });
1118
+ } else {
1119
+ await fs.unlink(filePath);
1120
+ res.json({ success: true, message: `Untracked file ${file} deleted successfully` });
1121
+ }
1027
1122
  } catch (error) {
1028
1123
  console.error('Git delete untracked error:', error);
1029
1124
  res.status(500).json({ error: error.message });
@@ -331,15 +331,6 @@ router.get('/detect/:projectName', async (req, res) => {
331
331
  timestamp: new Date().toISOString()
332
332
  };
333
333
 
334
- // Broadcast TaskMaster project update via WebSocket
335
- if (req.app.locals.wss) {
336
- broadcastTaskMasterProjectUpdate(
337
- req.app.locals.wss,
338
- projectName,
339
- taskMasterResult
340
- );
341
- }
342
-
343
334
  res.json(responseData);
344
335
 
345
336
  } catch (error) {
@@ -537,7 +528,8 @@ router.get('/next/:projectName', async (req, res) => {
537
528
  console.warn('Failed to execute task-master CLI:', cliError.message);
538
529
 
539
530
  // Fallback to loading tasks and finding next one locally
540
- const tasksResponse = await fetch(`${req.protocol}://${req.get('host')}/api/taskmaster/tasks/${encodeURIComponent(projectName)}`, {
531
+ // Use localhost to bypass proxy for internal server-to-server calls
532
+ const tasksResponse = await fetch(`http://localhost:${process.env.PORT || 3001}/api/taskmaster/tasks/${encodeURIComponent(projectName)}`, {
541
533
  headers: {
542
534
  'Authorization': req.headers.authorization
543
535
  }
@@ -0,0 +1,106 @@
1
+ import express from 'express';
2
+ import { userDb } from '../database/db.js';
3
+ import { authenticateToken } from '../middleware/auth.js';
4
+ import { getSystemGitConfig } from '../utils/gitConfig.js';
5
+ import { exec } from 'child_process';
6
+ import { promisify } from 'util';
7
+
8
+ const execAsync = promisify(exec);
9
+ const router = express.Router();
10
+
11
+ router.get('/git-config', authenticateToken, async (req, res) => {
12
+ try {
13
+ const userId = req.user.id;
14
+ let gitConfig = userDb.getGitConfig(userId);
15
+
16
+ // If database is empty, try to get from system git config
17
+ if (!gitConfig || (!gitConfig.git_name && !gitConfig.git_email)) {
18
+ const systemConfig = await getSystemGitConfig();
19
+
20
+ // If system has values, save them to database for this user
21
+ if (systemConfig.git_name || systemConfig.git_email) {
22
+ userDb.updateGitConfig(userId, systemConfig.git_name, systemConfig.git_email);
23
+ gitConfig = systemConfig;
24
+ console.log(`Auto-populated git config from system for user ${userId}: ${systemConfig.git_name} <${systemConfig.git_email}>`);
25
+ }
26
+ }
27
+
28
+ res.json({
29
+ success: true,
30
+ gitName: gitConfig?.git_name || null,
31
+ gitEmail: gitConfig?.git_email || null
32
+ });
33
+ } catch (error) {
34
+ console.error('Error getting git config:', error);
35
+ res.status(500).json({ error: 'Failed to get git configuration' });
36
+ }
37
+ });
38
+
39
+ // Apply git config globally via git config --global
40
+ router.post('/git-config', authenticateToken, async (req, res) => {
41
+ try {
42
+ const userId = req.user.id;
43
+ const { gitName, gitEmail } = req.body;
44
+
45
+ if (!gitName || !gitEmail) {
46
+ return res.status(400).json({ error: 'Git name and email are required' });
47
+ }
48
+
49
+ // Validate email format
50
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
51
+ if (!emailRegex.test(gitEmail)) {
52
+ return res.status(400).json({ error: 'Invalid email format' });
53
+ }
54
+
55
+ userDb.updateGitConfig(userId, gitName, gitEmail);
56
+
57
+ try {
58
+ await execAsync(`git config --global user.name "${gitName.replace(/"/g, '\\"')}"`);
59
+ await execAsync(`git config --global user.email "${gitEmail.replace(/"/g, '\\"')}"`);
60
+ console.log(`Applied git config globally: ${gitName} <${gitEmail}>`);
61
+ } catch (gitError) {
62
+ console.error('Error applying git config:', gitError);
63
+ }
64
+
65
+ res.json({
66
+ success: true,
67
+ gitName,
68
+ gitEmail
69
+ });
70
+ } catch (error) {
71
+ console.error('Error updating git config:', error);
72
+ res.status(500).json({ error: 'Failed to update git configuration' });
73
+ }
74
+ });
75
+
76
+ router.post('/complete-onboarding', authenticateToken, async (req, res) => {
77
+ try {
78
+ const userId = req.user.id;
79
+ userDb.completeOnboarding(userId);
80
+
81
+ res.json({
82
+ success: true,
83
+ message: 'Onboarding completed successfully'
84
+ });
85
+ } catch (error) {
86
+ console.error('Error completing onboarding:', error);
87
+ res.status(500).json({ error: 'Failed to complete onboarding' });
88
+ }
89
+ });
90
+
91
+ router.get('/onboarding-status', authenticateToken, async (req, res) => {
92
+ try {
93
+ const userId = req.user.id;
94
+ const hasCompleted = userDb.hasCompletedOnboarding(userId);
95
+
96
+ res.json({
97
+ success: true,
98
+ hasCompletedOnboarding: hasCompleted
99
+ });
100
+ } catch (error) {
101
+ console.error('Error checking onboarding status:', error);
102
+ res.status(500).json({ error: 'Failed to check onboarding status' });
103
+ }
104
+ });
105
+
106
+ export default router;
@@ -0,0 +1,24 @@
1
+ import { exec } from 'child_process';
2
+ import { promisify } from 'util';
3
+
4
+ const execAsync = promisify(exec);
5
+
6
+ /**
7
+ * Read git configuration from system's global git config
8
+ * @returns {Promise<{git_name: string|null, git_email: string|null}>}
9
+ */
10
+ export async function getSystemGitConfig() {
11
+ try {
12
+ const [nameResult, emailResult] = await Promise.all([
13
+ execAsync('git config --global user.name').catch(() => ({ stdout: '' })),
14
+ execAsync('git config --global user.email').catch(() => ({ stdout: '' }))
15
+ ]);
16
+
17
+ return {
18
+ git_name: nameResult.stdout.trim() || null,
19
+ git_email: emailResult.stdout.trim() || null
20
+ };
21
+ } catch (error) {
22
+ return { git_name: null, git_email: null };
23
+ }
24
+ }