@siteboon/claude-code-ui 1.11.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.
- package/README.md +19 -16
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/index-Cc6pl7ji.css +32 -0
- package/dist/assets/index-Zq2roSUR.js +1206 -0
- package/dist/assets/{vendor-codemirror-B7BYDWj-.js → vendor-codemirror-CnTQH7Pk.js} +1 -1
- package/dist/assets/{vendor-react-7V_UDHjJ.js → vendor-react-DVSKlM5e.js} +9 -9
- package/dist/assets/{vendor-xterm-jI4BCHEb.js → vendor-xterm-DfaPXD3y.js} +12 -12
- package/dist/icons/codex-white.svg +3 -0
- package/dist/icons/codex.svg +3 -0
- package/dist/icons/cursor-white.svg +12 -0
- package/dist/index.html +6 -6
- package/dist/logo-128.png +0 -0
- package/dist/logo-256.png +0 -0
- package/dist/logo-32.png +0 -0
- package/dist/logo-512.png +0 -0
- package/dist/logo-64.png +0 -0
- package/dist/logo.svg +17 -9
- package/package.json +7 -1
- package/server/claude-sdk.js +20 -19
- package/server/database/auth.db +0 -0
- package/server/database/db.js +73 -0
- package/server/database/init.sql +4 -1
- package/server/index.js +263 -29
- package/server/middleware/auth.js +34 -3
- package/server/openai-codex.js +387 -0
- package/server/projects.js +448 -7
- package/server/routes/agent.js +42 -4
- package/server/routes/cli-auth.js +263 -0
- package/server/routes/codex.js +310 -0
- package/server/routes/git.js +123 -28
- package/server/routes/projects.js +378 -0
- package/server/routes/taskmaster.js +2 -10
- package/server/routes/user.js +106 -0
- package/server/utils/gitConfig.js +24 -0
- package/dist/assets/index-B4_v-YUz.css +0 -32
- package/dist/assets/index-BZX1vtg9.js +0 -932
package/server/routes/git.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
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
|
|
478
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
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 });
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { spawn } from 'child_process';
|
|
5
|
+
import os from 'os';
|
|
6
|
+
import { addProjectManually } from '../projects.js';
|
|
7
|
+
|
|
8
|
+
const router = express.Router();
|
|
9
|
+
|
|
10
|
+
// Configure allowed workspace root (defaults to user's home directory)
|
|
11
|
+
const WORKSPACES_ROOT = process.env.WORKSPACES_ROOT || os.homedir();
|
|
12
|
+
|
|
13
|
+
// System-critical paths that should never be used as workspace directories
|
|
14
|
+
const FORBIDDEN_PATHS = [
|
|
15
|
+
'/',
|
|
16
|
+
'/etc',
|
|
17
|
+
'/bin',
|
|
18
|
+
'/sbin',
|
|
19
|
+
'/usr',
|
|
20
|
+
'/dev',
|
|
21
|
+
'/proc',
|
|
22
|
+
'/sys',
|
|
23
|
+
'/var',
|
|
24
|
+
'/boot',
|
|
25
|
+
'/root',
|
|
26
|
+
'/lib',
|
|
27
|
+
'/lib64',
|
|
28
|
+
'/opt',
|
|
29
|
+
'/tmp',
|
|
30
|
+
'/run'
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Validates that a path is safe for workspace operations
|
|
35
|
+
* @param {string} requestedPath - The path to validate
|
|
36
|
+
* @returns {Promise<{valid: boolean, resolvedPath?: string, error?: string}>}
|
|
37
|
+
*/
|
|
38
|
+
async function validateWorkspacePath(requestedPath) {
|
|
39
|
+
try {
|
|
40
|
+
// Resolve to absolute path
|
|
41
|
+
let absolutePath = path.resolve(requestedPath);
|
|
42
|
+
|
|
43
|
+
// Check if path is a forbidden system directory
|
|
44
|
+
const normalizedPath = path.normalize(absolutePath);
|
|
45
|
+
if (FORBIDDEN_PATHS.includes(normalizedPath) || normalizedPath === '/') {
|
|
46
|
+
return {
|
|
47
|
+
valid: false,
|
|
48
|
+
error: 'Cannot use system-critical directories as workspace locations'
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Additional check for paths starting with forbidden directories
|
|
53
|
+
for (const forbidden of FORBIDDEN_PATHS) {
|
|
54
|
+
if (normalizedPath === forbidden ||
|
|
55
|
+
normalizedPath.startsWith(forbidden + path.sep)) {
|
|
56
|
+
// Exception: /var/tmp and similar user-accessible paths might be allowed
|
|
57
|
+
// but /var itself and most /var subdirectories should be blocked
|
|
58
|
+
if (forbidden === '/var' &&
|
|
59
|
+
(normalizedPath.startsWith('/var/tmp') ||
|
|
60
|
+
normalizedPath.startsWith('/var/folders'))) {
|
|
61
|
+
continue; // Allow these specific cases
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
valid: false,
|
|
66
|
+
error: `Cannot create workspace in system directory: ${forbidden}`
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Try to resolve the real path (following symlinks)
|
|
72
|
+
let realPath;
|
|
73
|
+
try {
|
|
74
|
+
// Check if path exists to resolve real path
|
|
75
|
+
await fs.access(absolutePath);
|
|
76
|
+
realPath = await fs.realpath(absolutePath);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (error.code === 'ENOENT') {
|
|
79
|
+
// Path doesn't exist yet - check parent directory
|
|
80
|
+
let parentPath = path.dirname(absolutePath);
|
|
81
|
+
try {
|
|
82
|
+
const parentRealPath = await fs.realpath(parentPath);
|
|
83
|
+
|
|
84
|
+
// Reconstruct the full path with real parent
|
|
85
|
+
realPath = path.join(parentRealPath, path.basename(absolutePath));
|
|
86
|
+
} catch (parentError) {
|
|
87
|
+
if (parentError.code === 'ENOENT') {
|
|
88
|
+
// Parent doesn't exist either - use the absolute path as-is
|
|
89
|
+
// We'll validate it's within allowed root
|
|
90
|
+
realPath = absolutePath;
|
|
91
|
+
} else {
|
|
92
|
+
throw parentError;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Resolve the workspace root to its real path
|
|
101
|
+
const resolvedWorkspaceRoot = await fs.realpath(WORKSPACES_ROOT);
|
|
102
|
+
|
|
103
|
+
// Ensure the resolved path is contained within the allowed workspace root
|
|
104
|
+
if (!realPath.startsWith(resolvedWorkspaceRoot + path.sep) &&
|
|
105
|
+
realPath !== resolvedWorkspaceRoot) {
|
|
106
|
+
return {
|
|
107
|
+
valid: false,
|
|
108
|
+
error: `Workspace path must be within the allowed workspace root: ${WORKSPACES_ROOT}`
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Additional symlink check for existing paths
|
|
113
|
+
try {
|
|
114
|
+
await fs.access(absolutePath);
|
|
115
|
+
const stats = await fs.lstat(absolutePath);
|
|
116
|
+
|
|
117
|
+
if (stats.isSymbolicLink()) {
|
|
118
|
+
// Verify symlink target is also within allowed root
|
|
119
|
+
const linkTarget = await fs.readlink(absolutePath);
|
|
120
|
+
const resolvedTarget = path.resolve(path.dirname(absolutePath), linkTarget);
|
|
121
|
+
const realTarget = await fs.realpath(resolvedTarget);
|
|
122
|
+
|
|
123
|
+
if (!realTarget.startsWith(resolvedWorkspaceRoot + path.sep) &&
|
|
124
|
+
realTarget !== resolvedWorkspaceRoot) {
|
|
125
|
+
return {
|
|
126
|
+
valid: false,
|
|
127
|
+
error: 'Symlink target is outside the allowed workspace root'
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error.code !== 'ENOENT') {
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
// Path doesn't exist - that's fine for new workspace creation
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
valid: true,
|
|
140
|
+
resolvedPath: realPath
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
} catch (error) {
|
|
144
|
+
return {
|
|
145
|
+
valid: false,
|
|
146
|
+
error: `Path validation failed: ${error.message}`
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Create a new workspace
|
|
153
|
+
* POST /api/projects/create-workspace
|
|
154
|
+
*
|
|
155
|
+
* Body:
|
|
156
|
+
* - workspaceType: 'existing' | 'new'
|
|
157
|
+
* - path: string (workspace path)
|
|
158
|
+
* - githubUrl?: string (optional, for new workspaces)
|
|
159
|
+
* - githubTokenId?: number (optional, ID of stored token)
|
|
160
|
+
* - newGithubToken?: string (optional, one-time token)
|
|
161
|
+
*/
|
|
162
|
+
router.post('/create-workspace', async (req, res) => {
|
|
163
|
+
try {
|
|
164
|
+
const { workspaceType, path: workspacePath, githubUrl, githubTokenId, newGithubToken } = req.body;
|
|
165
|
+
|
|
166
|
+
// Validate required fields
|
|
167
|
+
if (!workspaceType || !workspacePath) {
|
|
168
|
+
return res.status(400).json({ error: 'workspaceType and path are required' });
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (!['existing', 'new'].includes(workspaceType)) {
|
|
172
|
+
return res.status(400).json({ error: 'workspaceType must be "existing" or "new"' });
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Validate path safety before any operations
|
|
176
|
+
const validation = await validateWorkspacePath(workspacePath);
|
|
177
|
+
if (!validation.valid) {
|
|
178
|
+
return res.status(400).json({
|
|
179
|
+
error: 'Invalid workspace path',
|
|
180
|
+
details: validation.error
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const absolutePath = validation.resolvedPath;
|
|
185
|
+
|
|
186
|
+
// Handle existing workspace
|
|
187
|
+
if (workspaceType === 'existing') {
|
|
188
|
+
// Check if the path exists
|
|
189
|
+
try {
|
|
190
|
+
await fs.access(absolutePath);
|
|
191
|
+
const stats = await fs.stat(absolutePath);
|
|
192
|
+
|
|
193
|
+
if (!stats.isDirectory()) {
|
|
194
|
+
return res.status(400).json({ error: 'Path exists but is not a directory' });
|
|
195
|
+
}
|
|
196
|
+
} catch (error) {
|
|
197
|
+
if (error.code === 'ENOENT') {
|
|
198
|
+
return res.status(404).json({ error: 'Workspace path does not exist' });
|
|
199
|
+
}
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Add the existing workspace to the project list
|
|
204
|
+
const project = await addProjectManually(absolutePath);
|
|
205
|
+
|
|
206
|
+
return res.json({
|
|
207
|
+
success: true,
|
|
208
|
+
project,
|
|
209
|
+
message: 'Existing workspace added successfully'
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Handle new workspace creation
|
|
214
|
+
if (workspaceType === 'new') {
|
|
215
|
+
// Check if path already exists
|
|
216
|
+
try {
|
|
217
|
+
await fs.access(absolutePath);
|
|
218
|
+
return res.status(400).json({
|
|
219
|
+
error: 'Path already exists. Please choose a different path or use "existing workspace" option.'
|
|
220
|
+
});
|
|
221
|
+
} catch (error) {
|
|
222
|
+
if (error.code !== 'ENOENT') {
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
// Path doesn't exist - good, we can create it
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Create the directory
|
|
229
|
+
await fs.mkdir(absolutePath, { recursive: true });
|
|
230
|
+
|
|
231
|
+
// If GitHub URL is provided, clone the repository
|
|
232
|
+
if (githubUrl) {
|
|
233
|
+
let githubToken = null;
|
|
234
|
+
|
|
235
|
+
// Get GitHub token if needed
|
|
236
|
+
if (githubTokenId) {
|
|
237
|
+
// Fetch token from database
|
|
238
|
+
const token = await getGithubTokenById(githubTokenId, req.user.id);
|
|
239
|
+
if (!token) {
|
|
240
|
+
// Clean up created directory
|
|
241
|
+
await fs.rm(absolutePath, { recursive: true, force: true });
|
|
242
|
+
return res.status(404).json({ error: 'GitHub token not found' });
|
|
243
|
+
}
|
|
244
|
+
githubToken = token.github_token;
|
|
245
|
+
} else if (newGithubToken) {
|
|
246
|
+
githubToken = newGithubToken;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Clone the repository
|
|
250
|
+
try {
|
|
251
|
+
await cloneGitHubRepository(githubUrl, absolutePath, githubToken);
|
|
252
|
+
} catch (error) {
|
|
253
|
+
// Clean up created directory on failure
|
|
254
|
+
try {
|
|
255
|
+
await fs.rm(absolutePath, { recursive: true, force: true });
|
|
256
|
+
} catch (cleanupError) {
|
|
257
|
+
console.error('Failed to clean up directory after clone failure:', cleanupError);
|
|
258
|
+
// Continue to throw original error
|
|
259
|
+
}
|
|
260
|
+
throw new Error(`Failed to clone repository: ${error.message}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Add the new workspace to the project list
|
|
265
|
+
const project = await addProjectManually(absolutePath);
|
|
266
|
+
|
|
267
|
+
return res.json({
|
|
268
|
+
success: true,
|
|
269
|
+
project,
|
|
270
|
+
message: githubUrl
|
|
271
|
+
? 'New workspace created and repository cloned successfully'
|
|
272
|
+
: 'New workspace created successfully'
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
} catch (error) {
|
|
277
|
+
console.error('Error creating workspace:', error);
|
|
278
|
+
res.status(500).json({
|
|
279
|
+
error: error.message || 'Failed to create workspace',
|
|
280
|
+
details: process.env.NODE_ENV === 'development' ? error.stack : undefined
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Helper function to get GitHub token from database
|
|
287
|
+
*/
|
|
288
|
+
async function getGithubTokenById(tokenId, userId) {
|
|
289
|
+
const { getDatabase } = await import('../database/db.js');
|
|
290
|
+
const db = await getDatabase();
|
|
291
|
+
|
|
292
|
+
const credential = await db.get(
|
|
293
|
+
'SELECT * FROM user_credentials WHERE id = ? AND user_id = ? AND credential_type = ? AND is_active = 1',
|
|
294
|
+
[tokenId, userId, 'github_token']
|
|
295
|
+
);
|
|
296
|
+
|
|
297
|
+
// Return in the expected format (github_token field for compatibility)
|
|
298
|
+
if (credential) {
|
|
299
|
+
return {
|
|
300
|
+
...credential,
|
|
301
|
+
github_token: credential.credential_value
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Helper function to clone a GitHub repository
|
|
310
|
+
*/
|
|
311
|
+
function cloneGitHubRepository(githubUrl, destinationPath, githubToken = null) {
|
|
312
|
+
return new Promise((resolve, reject) => {
|
|
313
|
+
// Parse GitHub URL and inject token if provided
|
|
314
|
+
let cloneUrl = githubUrl;
|
|
315
|
+
|
|
316
|
+
if (githubToken) {
|
|
317
|
+
try {
|
|
318
|
+
const url = new URL(githubUrl);
|
|
319
|
+
// Format: https://TOKEN@github.com/user/repo.git
|
|
320
|
+
url.username = githubToken;
|
|
321
|
+
url.password = '';
|
|
322
|
+
cloneUrl = url.toString();
|
|
323
|
+
} catch (error) {
|
|
324
|
+
return reject(new Error('Invalid GitHub URL format'));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
const gitProcess = spawn('git', ['clone', cloneUrl, destinationPath], {
|
|
329
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
330
|
+
env: {
|
|
331
|
+
...process.env,
|
|
332
|
+
GIT_TERMINAL_PROMPT: '0' // Disable git password prompts
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
let stdout = '';
|
|
337
|
+
let stderr = '';
|
|
338
|
+
|
|
339
|
+
gitProcess.stdout.on('data', (data) => {
|
|
340
|
+
stdout += data.toString();
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
gitProcess.stderr.on('data', (data) => {
|
|
344
|
+
stderr += data.toString();
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
gitProcess.on('close', (code) => {
|
|
348
|
+
if (code === 0) {
|
|
349
|
+
resolve({ stdout, stderr });
|
|
350
|
+
} else {
|
|
351
|
+
// Parse git error messages to provide helpful feedback
|
|
352
|
+
let errorMessage = 'Git clone failed';
|
|
353
|
+
|
|
354
|
+
if (stderr.includes('Authentication failed') || stderr.includes('could not read Username')) {
|
|
355
|
+
errorMessage = 'Authentication failed. Please check your GitHub token.';
|
|
356
|
+
} else if (stderr.includes('Repository not found')) {
|
|
357
|
+
errorMessage = 'Repository not found. Please check the URL and ensure you have access.';
|
|
358
|
+
} else if (stderr.includes('already exists')) {
|
|
359
|
+
errorMessage = 'Directory already exists';
|
|
360
|
+
} else if (stderr) {
|
|
361
|
+
errorMessage = stderr;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
reject(new Error(errorMessage));
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
gitProcess.on('error', (error) => {
|
|
369
|
+
if (error.code === 'ENOENT') {
|
|
370
|
+
reject(new Error('Git is not installed or not in PATH'));
|
|
371
|
+
} else {
|
|
372
|
+
reject(error);
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export default router;
|
|
@@ -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
|
-
|
|
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
|
}
|