claude-wec 1.0.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/LICENSE +675 -0
- package/README.md +371 -0
- package/dist/api-docs.html +879 -0
- 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-cIxJ4RXb.js +1226 -0
- package/dist/assets/index-oyEz69sP.css +32 -0
- package/dist/assets/vendor-codemirror-CJLzwpLB.js +39 -0
- package/dist/assets/vendor-react-DcyRfQm3.js +59 -0
- package/dist/assets/vendor-xterm-DfaPXD3y.js +66 -0
- package/dist/clear-cache.html +85 -0
- package/dist/convert-icons.md +53 -0
- package/dist/favicon.png +0 -0
- package/dist/favicon.svg +9 -0
- package/dist/generate-icons.js +49 -0
- package/dist/icons/claude-ai-icon.svg +1 -0
- 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/icons/cursor.svg +1 -0
- package/dist/icons/generate-icons.md +19 -0
- package/dist/icons/icon-128x128.png +0 -0
- package/dist/icons/icon-128x128.svg +12 -0
- package/dist/icons/icon-144x144.png +0 -0
- package/dist/icons/icon-144x144.svg +12 -0
- package/dist/icons/icon-152x152.png +0 -0
- package/dist/icons/icon-152x152.svg +12 -0
- package/dist/icons/icon-192x192.png +0 -0
- package/dist/icons/icon-192x192.svg +12 -0
- package/dist/icons/icon-384x384.png +0 -0
- package/dist/icons/icon-384x384.svg +12 -0
- package/dist/icons/icon-512x512.png +0 -0
- package/dist/icons/icon-512x512.svg +12 -0
- package/dist/icons/icon-72x72.png +0 -0
- package/dist/icons/icon-72x72.svg +12 -0
- package/dist/icons/icon-96x96.png +0 -0
- package/dist/icons/icon-96x96.svg +12 -0
- package/dist/icons/icon-template.svg +12 -0
- package/dist/index.html +52 -0
- 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 -0
- package/dist/manifest.json +61 -0
- package/dist/screenshots/cli-selection.png +0 -0
- package/dist/screenshots/desktop-main.png +0 -0
- package/dist/screenshots/mobile-chat.png +0 -0
- package/dist/screenshots/tools-modal.png +0 -0
- package/dist/sw.js +49 -0
- package/package.json +109 -0
- package/server/claude-sdk.js +721 -0
- package/server/cli.js +327 -0
- package/server/cursor-cli.js +267 -0
- package/server/database/auth.db +0 -0
- package/server/database/db.js +361 -0
- package/server/database/init.sql +52 -0
- package/server/index.js +1747 -0
- package/server/middleware/auth.js +111 -0
- package/server/openai-codex.js +389 -0
- package/server/projects.js +1604 -0
- package/server/routes/agent.js +1230 -0
- package/server/routes/auth.js +135 -0
- package/server/routes/cli-auth.js +263 -0
- package/server/routes/codex.js +345 -0
- package/server/routes/commands.js +521 -0
- package/server/routes/cursor.js +795 -0
- package/server/routes/git.js +1128 -0
- package/server/routes/mcp-utils.js +48 -0
- package/server/routes/mcp.js +552 -0
- package/server/routes/projects.js +378 -0
- package/server/routes/settings.js +178 -0
- package/server/routes/taskmaster.js +1963 -0
- package/server/routes/user.js +106 -0
- package/server/utils/commandParser.js +303 -0
- package/server/utils/gitConfig.js +24 -0
- package/server/utils/mcp-detector.js +198 -0
- package/server/utils/taskmaster-websocket.js +129 -0
- package/shared/modelConstants.js +65 -0
|
@@ -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,303 @@
|
|
|
1
|
+
import matter from 'gray-matter';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { execFile } from 'child_process';
|
|
5
|
+
import { promisify } from 'util';
|
|
6
|
+
import { parse as parseShellCommand } from 'shell-quote';
|
|
7
|
+
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
9
|
+
|
|
10
|
+
// Configuration
|
|
11
|
+
const MAX_INCLUDE_DEPTH = 3;
|
|
12
|
+
const BASH_TIMEOUT = 30000; // 30 seconds
|
|
13
|
+
const BASH_COMMAND_ALLOWLIST = [
|
|
14
|
+
'echo',
|
|
15
|
+
'ls',
|
|
16
|
+
'pwd',
|
|
17
|
+
'date',
|
|
18
|
+
'whoami',
|
|
19
|
+
'git',
|
|
20
|
+
'npm',
|
|
21
|
+
'node',
|
|
22
|
+
'cat',
|
|
23
|
+
'grep',
|
|
24
|
+
'find',
|
|
25
|
+
'task-master'
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Parse a markdown command file and extract frontmatter and content
|
|
30
|
+
* @param {string} content - Raw markdown content
|
|
31
|
+
* @returns {object} Parsed command with data (frontmatter) and content
|
|
32
|
+
*/
|
|
33
|
+
export function parseCommand(content) {
|
|
34
|
+
try {
|
|
35
|
+
const parsed = matter(content);
|
|
36
|
+
return {
|
|
37
|
+
data: parsed.data || {},
|
|
38
|
+
content: parsed.content || '',
|
|
39
|
+
raw: content
|
|
40
|
+
};
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new Error(`Failed to parse command: ${error.message}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Replace argument placeholders in content
|
|
48
|
+
* @param {string} content - Content with placeholders
|
|
49
|
+
* @param {string|array} args - Arguments to replace (string or array)
|
|
50
|
+
* @returns {string} Content with replaced arguments
|
|
51
|
+
*/
|
|
52
|
+
export function replaceArguments(content, args) {
|
|
53
|
+
if (!content) return content;
|
|
54
|
+
|
|
55
|
+
let result = content;
|
|
56
|
+
|
|
57
|
+
// Convert args to array if it's a string
|
|
58
|
+
const argsArray = Array.isArray(args) ? args : (args ? [args] : []);
|
|
59
|
+
|
|
60
|
+
// Replace $ARGUMENTS with all arguments joined by space
|
|
61
|
+
const allArgs = argsArray.join(' ');
|
|
62
|
+
result = result.replace(/\$ARGUMENTS/g, allArgs);
|
|
63
|
+
|
|
64
|
+
// Replace positional arguments $1-$9
|
|
65
|
+
for (let i = 1; i <= 9; i++) {
|
|
66
|
+
const regex = new RegExp(`\\$${i}`, 'g');
|
|
67
|
+
const value = argsArray[i - 1] || '';
|
|
68
|
+
result = result.replace(regex, value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Validate file path to prevent directory traversal
|
|
76
|
+
* @param {string} filePath - Path to validate
|
|
77
|
+
* @param {string} basePath - Base directory path
|
|
78
|
+
* @returns {boolean} True if path is safe
|
|
79
|
+
*/
|
|
80
|
+
export function isPathSafe(filePath, basePath) {
|
|
81
|
+
const resolvedPath = path.resolve(basePath, filePath);
|
|
82
|
+
const resolvedBase = path.resolve(basePath);
|
|
83
|
+
const relative = path.relative(resolvedBase, resolvedPath);
|
|
84
|
+
return (
|
|
85
|
+
relative !== '' &&
|
|
86
|
+
!relative.startsWith('..') &&
|
|
87
|
+
!path.isAbsolute(relative)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Process file includes in content (@filename syntax)
|
|
93
|
+
* @param {string} content - Content with @filename includes
|
|
94
|
+
* @param {string} basePath - Base directory for resolving file paths
|
|
95
|
+
* @param {number} depth - Current recursion depth
|
|
96
|
+
* @returns {Promise<string>} Content with includes resolved
|
|
97
|
+
*/
|
|
98
|
+
export async function processFileIncludes(content, basePath, depth = 0) {
|
|
99
|
+
if (!content) return content;
|
|
100
|
+
|
|
101
|
+
// Prevent infinite recursion
|
|
102
|
+
if (depth >= MAX_INCLUDE_DEPTH) {
|
|
103
|
+
throw new Error(`Maximum include depth (${MAX_INCLUDE_DEPTH}) exceeded`);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Match @filename patterns (at start of line or after whitespace)
|
|
107
|
+
const includePattern = /(?:^|\s)@([^\s]+)/gm;
|
|
108
|
+
const matches = [...content.matchAll(includePattern)];
|
|
109
|
+
|
|
110
|
+
if (matches.length === 0) {
|
|
111
|
+
return content;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let result = content;
|
|
115
|
+
|
|
116
|
+
for (const match of matches) {
|
|
117
|
+
const fullMatch = match[0];
|
|
118
|
+
const filename = match[1];
|
|
119
|
+
|
|
120
|
+
// Security: prevent directory traversal
|
|
121
|
+
if (!isPathSafe(filename, basePath)) {
|
|
122
|
+
throw new Error(`Invalid file path (directory traversal detected): ${filename}`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
const filePath = path.resolve(basePath, filename);
|
|
127
|
+
const fileContent = await fs.readFile(filePath, 'utf-8');
|
|
128
|
+
|
|
129
|
+
// Recursively process includes in the included file
|
|
130
|
+
const processedContent = await processFileIncludes(fileContent, basePath, depth + 1);
|
|
131
|
+
|
|
132
|
+
// Replace the @filename with the file content
|
|
133
|
+
result = result.replace(fullMatch, fullMatch.startsWith(' ') ? ' ' + processedContent : processedContent);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error.code === 'ENOENT') {
|
|
136
|
+
throw new Error(`File not found: ${filename}`);
|
|
137
|
+
}
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Validate that a command and its arguments are safe
|
|
147
|
+
* @param {string} commandString - Command string to validate
|
|
148
|
+
* @returns {{ allowed: boolean, command: string, args: string[], error?: string }} Validation result
|
|
149
|
+
*/
|
|
150
|
+
export function validateCommand(commandString) {
|
|
151
|
+
const trimmedCommand = commandString.trim();
|
|
152
|
+
if (!trimmedCommand) {
|
|
153
|
+
return { allowed: false, command: '', args: [], error: 'Empty command' };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Parse the command using shell-quote to handle quotes properly
|
|
157
|
+
const parsed = parseShellCommand(trimmedCommand);
|
|
158
|
+
|
|
159
|
+
// Check for shell operators or control structures
|
|
160
|
+
const hasOperators = parsed.some(token =>
|
|
161
|
+
typeof token === 'object' && token.op
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
if (hasOperators) {
|
|
165
|
+
return {
|
|
166
|
+
allowed: false,
|
|
167
|
+
command: '',
|
|
168
|
+
args: [],
|
|
169
|
+
error: 'Shell operators (&&, ||, |, ;, etc.) are not allowed'
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Extract command and args (all should be strings after validation)
|
|
174
|
+
const tokens = parsed.filter(token => typeof token === 'string');
|
|
175
|
+
|
|
176
|
+
if (tokens.length === 0) {
|
|
177
|
+
return { allowed: false, command: '', args: [], error: 'No valid command found' };
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const [command, ...args] = tokens;
|
|
181
|
+
|
|
182
|
+
// Extract just the command name (remove path if present)
|
|
183
|
+
const commandName = path.basename(command);
|
|
184
|
+
|
|
185
|
+
// Check if command exactly matches allowlist (no prefix matching)
|
|
186
|
+
const isAllowed = BASH_COMMAND_ALLOWLIST.includes(commandName);
|
|
187
|
+
|
|
188
|
+
if (!isAllowed) {
|
|
189
|
+
return {
|
|
190
|
+
allowed: false,
|
|
191
|
+
command: commandName,
|
|
192
|
+
args,
|
|
193
|
+
error: `Command '${commandName}' is not in the allowlist`
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Validate arguments don't contain dangerous metacharacters
|
|
198
|
+
const dangerousPattern = /[;&|`$()<>{}[\]\\]/;
|
|
199
|
+
for (const arg of args) {
|
|
200
|
+
if (dangerousPattern.test(arg)) {
|
|
201
|
+
return {
|
|
202
|
+
allowed: false,
|
|
203
|
+
command: commandName,
|
|
204
|
+
args,
|
|
205
|
+
error: `Argument contains dangerous characters: ${arg}`
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return { allowed: true, command: commandName, args };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Backward compatibility: Check if command is allowed (deprecated)
|
|
215
|
+
* @deprecated Use validateCommand() instead for better security
|
|
216
|
+
* @param {string} command - Command to validate
|
|
217
|
+
* @returns {boolean} True if command is allowed
|
|
218
|
+
*/
|
|
219
|
+
export function isBashCommandAllowed(command) {
|
|
220
|
+
const result = validateCommand(command);
|
|
221
|
+
return result.allowed;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Sanitize bash command output
|
|
226
|
+
* @param {string} output - Raw command output
|
|
227
|
+
* @returns {string} Sanitized output
|
|
228
|
+
*/
|
|
229
|
+
export function sanitizeOutput(output) {
|
|
230
|
+
if (!output) return '';
|
|
231
|
+
|
|
232
|
+
// Remove control characters except \t, \n, \r
|
|
233
|
+
return [...output]
|
|
234
|
+
.filter(ch => {
|
|
235
|
+
const code = ch.charCodeAt(0);
|
|
236
|
+
return code === 9 // \t
|
|
237
|
+
|| code === 10 // \n
|
|
238
|
+
|| code === 13 // \r
|
|
239
|
+
|| (code >= 32 && code !== 127);
|
|
240
|
+
})
|
|
241
|
+
.join('');
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Process bash commands in content (!command syntax)
|
|
246
|
+
* @param {string} content - Content with !command syntax
|
|
247
|
+
* @param {object} options - Options for bash execution
|
|
248
|
+
* @returns {Promise<string>} Content with bash commands executed and replaced
|
|
249
|
+
*/
|
|
250
|
+
export async function processBashCommands(content, options = {}) {
|
|
251
|
+
if (!content) return content;
|
|
252
|
+
|
|
253
|
+
const { cwd = process.cwd(), timeout = BASH_TIMEOUT } = options;
|
|
254
|
+
|
|
255
|
+
// Match !command patterns (at start of line or after whitespace)
|
|
256
|
+
const commandPattern = /(?:^|\n)!(.+?)(?=\n|$)/g;
|
|
257
|
+
const matches = [...content.matchAll(commandPattern)];
|
|
258
|
+
|
|
259
|
+
if (matches.length === 0) {
|
|
260
|
+
return content;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
let result = content;
|
|
264
|
+
|
|
265
|
+
for (const match of matches) {
|
|
266
|
+
const fullMatch = match[0];
|
|
267
|
+
const commandString = match[1].trim();
|
|
268
|
+
|
|
269
|
+
// Security: validate command and parse args
|
|
270
|
+
const validation = validateCommand(commandString);
|
|
271
|
+
|
|
272
|
+
if (!validation.allowed) {
|
|
273
|
+
throw new Error(`Command not allowed: ${commandString} - ${validation.error}`);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
try {
|
|
277
|
+
// Execute without shell using execFile with parsed args
|
|
278
|
+
const { stdout, stderr } = await execFileAsync(
|
|
279
|
+
validation.command,
|
|
280
|
+
validation.args,
|
|
281
|
+
{
|
|
282
|
+
cwd,
|
|
283
|
+
timeout,
|
|
284
|
+
maxBuffer: 1024 * 1024, // 1MB max output
|
|
285
|
+
shell: false, // IMPORTANT: No shell interpretation
|
|
286
|
+
env: { ...process.env, PATH: process.env.PATH } // Inherit PATH for finding commands
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const output = sanitizeOutput(stdout || stderr || '');
|
|
291
|
+
|
|
292
|
+
// Replace the !command with the output
|
|
293
|
+
result = result.replace(fullMatch, fullMatch.startsWith('\n') ? '\n' + output : output);
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if (error.killed) {
|
|
296
|
+
throw new Error(`Command timeout: ${commandString}`);
|
|
297
|
+
}
|
|
298
|
+
throw new Error(`Command failed: ${commandString} - ${error.message}`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return result;
|
|
303
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP SERVER DETECTION UTILITY
|
|
3
|
+
* ============================
|
|
4
|
+
*
|
|
5
|
+
* Centralized utility for detecting MCP server configurations.
|
|
6
|
+
* Used across TaskMaster integration and other MCP-dependent features.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { promises as fsPromises } from 'fs';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import os from 'os';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Check if task-master-ai MCP server is configured
|
|
15
|
+
* Reads directly from Claude configuration files like claude-cli.js does
|
|
16
|
+
* @returns {Promise<Object>} MCP detection result
|
|
17
|
+
*/
|
|
18
|
+
export async function detectTaskMasterMCPServer() {
|
|
19
|
+
try {
|
|
20
|
+
// Read Claude configuration files directly (same logic as mcp.js)
|
|
21
|
+
const homeDir = os.homedir();
|
|
22
|
+
const configPaths = [
|
|
23
|
+
path.join(homeDir, '.claude.json'),
|
|
24
|
+
path.join(homeDir, '.claude', 'settings.json')
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
let configData = null;
|
|
28
|
+
let configPath = null;
|
|
29
|
+
|
|
30
|
+
// Try to read from either config file
|
|
31
|
+
for (const filepath of configPaths) {
|
|
32
|
+
try {
|
|
33
|
+
const fileContent = await fsPromises.readFile(filepath, 'utf8');
|
|
34
|
+
configData = JSON.parse(fileContent);
|
|
35
|
+
configPath = filepath;
|
|
36
|
+
break;
|
|
37
|
+
} catch (error) {
|
|
38
|
+
// File doesn't exist or is not valid JSON, try next
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!configData) {
|
|
44
|
+
return {
|
|
45
|
+
hasMCPServer: false,
|
|
46
|
+
reason: 'No Claude configuration file found',
|
|
47
|
+
hasConfig: false
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Look for task-master-ai in user-scoped MCP servers
|
|
52
|
+
let taskMasterServer = null;
|
|
53
|
+
if (configData.mcpServers && typeof configData.mcpServers === 'object') {
|
|
54
|
+
const serverEntry = Object.entries(configData.mcpServers).find(([name, config]) =>
|
|
55
|
+
name === 'task-master-ai' ||
|
|
56
|
+
name.includes('task-master') ||
|
|
57
|
+
(config && config.command && config.command.includes('task-master'))
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
if (serverEntry) {
|
|
61
|
+
const [name, config] = serverEntry;
|
|
62
|
+
taskMasterServer = {
|
|
63
|
+
name,
|
|
64
|
+
scope: 'user',
|
|
65
|
+
config,
|
|
66
|
+
type: config.command ? 'stdio' : (config.url ? 'http' : 'unknown')
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Also check project-specific MCP servers if not found globally
|
|
72
|
+
if (!taskMasterServer && configData.projects) {
|
|
73
|
+
for (const [projectPath, projectConfig] of Object.entries(configData.projects)) {
|
|
74
|
+
if (projectConfig.mcpServers && typeof projectConfig.mcpServers === 'object') {
|
|
75
|
+
const serverEntry = Object.entries(projectConfig.mcpServers).find(([name, config]) =>
|
|
76
|
+
name === 'task-master-ai' ||
|
|
77
|
+
name.includes('task-master') ||
|
|
78
|
+
(config && config.command && config.command.includes('task-master'))
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
if (serverEntry) {
|
|
82
|
+
const [name, config] = serverEntry;
|
|
83
|
+
taskMasterServer = {
|
|
84
|
+
name,
|
|
85
|
+
scope: 'local',
|
|
86
|
+
projectPath,
|
|
87
|
+
config,
|
|
88
|
+
type: config.command ? 'stdio' : (config.url ? 'http' : 'unknown')
|
|
89
|
+
};
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (taskMasterServer) {
|
|
97
|
+
const isValid = !!(taskMasterServer.config &&
|
|
98
|
+
(taskMasterServer.config.command || taskMasterServer.config.url));
|
|
99
|
+
const hasEnvVars = !!(taskMasterServer.config &&
|
|
100
|
+
taskMasterServer.config.env &&
|
|
101
|
+
Object.keys(taskMasterServer.config.env).length > 0);
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
hasMCPServer: true,
|
|
105
|
+
isConfigured: isValid,
|
|
106
|
+
hasApiKeys: hasEnvVars,
|
|
107
|
+
scope: taskMasterServer.scope,
|
|
108
|
+
config: {
|
|
109
|
+
command: taskMasterServer.config?.command,
|
|
110
|
+
args: taskMasterServer.config?.args || [],
|
|
111
|
+
url: taskMasterServer.config?.url,
|
|
112
|
+
envVars: hasEnvVars ? Object.keys(taskMasterServer.config.env) : [],
|
|
113
|
+
type: taskMasterServer.type
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
} else {
|
|
117
|
+
// Get list of available servers for debugging
|
|
118
|
+
const availableServers = [];
|
|
119
|
+
if (configData.mcpServers) {
|
|
120
|
+
availableServers.push(...Object.keys(configData.mcpServers));
|
|
121
|
+
}
|
|
122
|
+
if (configData.projects) {
|
|
123
|
+
for (const projectConfig of Object.values(configData.projects)) {
|
|
124
|
+
if (projectConfig.mcpServers) {
|
|
125
|
+
availableServers.push(...Object.keys(projectConfig.mcpServers).map(name => `local:${name}`));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
hasMCPServer: false,
|
|
132
|
+
reason: 'task-master-ai not found in configured MCP servers',
|
|
133
|
+
hasConfig: true,
|
|
134
|
+
configPath,
|
|
135
|
+
availableServers
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error('Error detecting MCP server config:', error);
|
|
140
|
+
return {
|
|
141
|
+
hasMCPServer: false,
|
|
142
|
+
reason: `Error checking MCP config: ${error.message}`,
|
|
143
|
+
hasConfig: false
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get all configured MCP servers (not just TaskMaster)
|
|
150
|
+
* @returns {Promise<Object>} All MCP servers configuration
|
|
151
|
+
*/
|
|
152
|
+
export async function getAllMCPServers() {
|
|
153
|
+
try {
|
|
154
|
+
const homeDir = os.homedir();
|
|
155
|
+
const configPaths = [
|
|
156
|
+
path.join(homeDir, '.claude.json'),
|
|
157
|
+
path.join(homeDir, '.claude', 'settings.json')
|
|
158
|
+
];
|
|
159
|
+
|
|
160
|
+
let configData = null;
|
|
161
|
+
let configPath = null;
|
|
162
|
+
|
|
163
|
+
// Try to read from either config file
|
|
164
|
+
for (const filepath of configPaths) {
|
|
165
|
+
try {
|
|
166
|
+
const fileContent = await fsPromises.readFile(filepath, 'utf8');
|
|
167
|
+
configData = JSON.parse(fileContent);
|
|
168
|
+
configPath = filepath;
|
|
169
|
+
break;
|
|
170
|
+
} catch (error) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (!configData) {
|
|
176
|
+
return {
|
|
177
|
+
hasConfig: false,
|
|
178
|
+
servers: {},
|
|
179
|
+
projectServers: {}
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
hasConfig: true,
|
|
185
|
+
configPath,
|
|
186
|
+
servers: configData.mcpServers || {},
|
|
187
|
+
projectServers: configData.projects || {}
|
|
188
|
+
};
|
|
189
|
+
} catch (error) {
|
|
190
|
+
console.error('Error getting all MCP servers:', error);
|
|
191
|
+
return {
|
|
192
|
+
hasConfig: false,
|
|
193
|
+
error: error.message,
|
|
194
|
+
servers: {},
|
|
195
|
+
projectServers: {}
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}
|