@ian2018cs/agenthub 0.1.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.
Files changed (136) hide show
  1. package/LICENSE +675 -0
  2. package/README.md +330 -0
  3. package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  4. package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  5. package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  6. package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  7. package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  8. package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  9. package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  10. package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  11. package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  12. package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  13. package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  14. package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  15. package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  16. package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  17. package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  18. package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  19. package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  20. package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  21. package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  22. package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  23. package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  24. package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  25. package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  26. package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  27. package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  28. package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  29. package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  30. package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  31. package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  32. package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  33. package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  34. package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  35. package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  36. package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  37. package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  38. package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  39. package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  40. package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  41. package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  42. package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  43. package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  44. package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  45. package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  46. package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  47. package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  48. package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  49. package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  50. package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  51. package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  52. package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  53. package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  54. package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  55. package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  56. package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  57. package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  58. package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  59. package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  60. package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  61. package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  62. package/dist/assets/index-B4ru3EJb.css +32 -0
  63. package/dist/assets/index-DDFuyrpY.js +154 -0
  64. package/dist/assets/vendor-codemirror-C_VWDoZS.js +39 -0
  65. package/dist/assets/vendor-icons-CJV4dnDL.js +326 -0
  66. package/dist/assets/vendor-katex-DK8hFnhL.js +261 -0
  67. package/dist/assets/vendor-markdown-VwNYkg_0.js +35 -0
  68. package/dist/assets/vendor-react-BeVl62c0.js +59 -0
  69. package/dist/assets/vendor-syntax-CdGaPJRS.js +16 -0
  70. package/dist/assets/vendor-utils-00TdZexr.js +1 -0
  71. package/dist/assets/vendor-xterm-CvdiG4-n.js +66 -0
  72. package/dist/clear-cache.html +85 -0
  73. package/dist/convert-icons.md +53 -0
  74. package/dist/favicon.png +0 -0
  75. package/dist/favicon.svg +9 -0
  76. package/dist/generate-icons.js +49 -0
  77. package/dist/icons/claude-ai-icon.svg +1 -0
  78. package/dist/icons/codex-white.svg +3 -0
  79. package/dist/icons/codex.svg +3 -0
  80. package/dist/icons/cursor-white.svg +12 -0
  81. package/dist/icons/cursor.svg +1 -0
  82. package/dist/icons/generate-icons.md +19 -0
  83. package/dist/icons/icon-128x128.png +0 -0
  84. package/dist/icons/icon-128x128.svg +12 -0
  85. package/dist/icons/icon-144x144.png +0 -0
  86. package/dist/icons/icon-144x144.svg +12 -0
  87. package/dist/icons/icon-152x152.png +0 -0
  88. package/dist/icons/icon-152x152.svg +12 -0
  89. package/dist/icons/icon-192x192.png +0 -0
  90. package/dist/icons/icon-192x192.svg +12 -0
  91. package/dist/icons/icon-384x384.png +0 -0
  92. package/dist/icons/icon-384x384.svg +12 -0
  93. package/dist/icons/icon-512x512.png +0 -0
  94. package/dist/icons/icon-512x512.svg +12 -0
  95. package/dist/icons/icon-72x72.png +0 -0
  96. package/dist/icons/icon-72x72.svg +12 -0
  97. package/dist/icons/icon-96x96.png +0 -0
  98. package/dist/icons/icon-96x96.svg +12 -0
  99. package/dist/icons/icon-template.svg +12 -0
  100. package/dist/index.html +57 -0
  101. package/dist/logo-128.png +0 -0
  102. package/dist/logo-256.png +0 -0
  103. package/dist/logo-32.png +0 -0
  104. package/dist/logo-512.png +0 -0
  105. package/dist/logo-64.png +0 -0
  106. package/dist/logo.svg +17 -0
  107. package/dist/manifest.json +61 -0
  108. package/dist/screenshots/cli-selection.png +0 -0
  109. package/dist/screenshots/desktop-main.png +0 -0
  110. package/dist/screenshots/mobile-chat.png +0 -0
  111. package/dist/screenshots/tools-modal.png +0 -0
  112. package/dist/sw.js +49 -0
  113. package/package.json +113 -0
  114. package/server/claude-sdk.js +791 -0
  115. package/server/cli.js +330 -0
  116. package/server/database/auth.db +0 -0
  117. package/server/database/db.js +523 -0
  118. package/server/database/init.sql +23 -0
  119. package/server/index.js +1678 -0
  120. package/server/load-env.js +27 -0
  121. package/server/middleware/auth.js +118 -0
  122. package/server/projects.js +899 -0
  123. package/server/routes/admin.js +89 -0
  124. package/server/routes/auth.js +144 -0
  125. package/server/routes/commands.js +570 -0
  126. package/server/routes/mcp-utils.js +37 -0
  127. package/server/routes/mcp.js +593 -0
  128. package/server/routes/projects.js +216 -0
  129. package/server/routes/skills.js +891 -0
  130. package/server/routes/usage.js +206 -0
  131. package/server/services/pricing.js +196 -0
  132. package/server/services/usage-scanner.js +283 -0
  133. package/server/services/user-directories.js +123 -0
  134. package/server/utils/commandParser.js +303 -0
  135. package/server/utils/mcp-detector.js +73 -0
  136. package/shared/modelConstants.js +23 -0
@@ -0,0 +1,123 @@
1
+ import { promises as fs } from 'fs';
2
+ import path from 'path';
3
+
4
+ // Base data directory (configurable via env)
5
+ const DATA_DIR = process.env.DATA_DIR || path.join(process.cwd(), 'data');
6
+
7
+ // UUID validation regex to prevent path traversal attacks
8
+ const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
9
+
10
+ function validateUuid(userUuid) {
11
+ if (!userUuid || !UUID_REGEX.test(userUuid)) {
12
+ throw new Error('Invalid user UUID format');
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Get paths for a user
18
+ */
19
+ export function getUserPaths(userUuid) {
20
+ validateUuid(userUuid);
21
+ return {
22
+ configDir: path.join(DATA_DIR, 'user-data', userUuid),
23
+ claudeDir: path.join(DATA_DIR, 'user-data', userUuid, '.claude'),
24
+ projectsDir: path.join(DATA_DIR, 'user-projects', userUuid),
25
+ skillsDir: path.join(DATA_DIR, 'user-data', userUuid, '.claude', 'skills'),
26
+ skillsImportDir: path.join(DATA_DIR, 'user-data', userUuid, 'skills-import'),
27
+ skillsRepoDir: path.join(DATA_DIR, 'user-data', userUuid, 'skills-repo'),
28
+ };
29
+ }
30
+
31
+ /**
32
+ * Get public paths (shared across all users)
33
+ */
34
+ export function getPublicPaths() {
35
+ return {
36
+ skillsRepoDir: path.join(DATA_DIR, 'skills-repo'),
37
+ };
38
+ }
39
+
40
+ /**
41
+ * Initialize directories for a new user
42
+ */
43
+ export async function initUserDirectories(userUuid) {
44
+ validateUuid(userUuid);
45
+ const paths = getUserPaths(userUuid);
46
+
47
+ // Create directories
48
+ await fs.mkdir(paths.claudeDir, { recursive: true });
49
+ await fs.mkdir(paths.projectsDir, { recursive: true });
50
+
51
+ // Create projects directory for Claude session files
52
+ const projectsDir = path.join(paths.claudeDir, 'projects');
53
+ await fs.mkdir(projectsDir, { recursive: true });
54
+
55
+ // Create skills directories
56
+ await fs.mkdir(paths.skillsDir, { recursive: true });
57
+ await fs.mkdir(paths.skillsImportDir, { recursive: true });
58
+ await fs.mkdir(paths.skillsRepoDir, { recursive: true });
59
+
60
+ // Create .claude.json with hasCompletedOnboarding=true
61
+ const claudeJsonPath = path.join(paths.claudeDir, '.claude.json');
62
+ const claudeConfig = {
63
+ hasCompletedOnboarding: true
64
+ };
65
+ await fs.writeFile(claudeJsonPath, JSON.stringify(claudeConfig, null, 2));
66
+ console.log(`Created .claude.json for user ${userUuid}`);
67
+
68
+ // Create settings.json with proxy configuration
69
+ const destSettings = path.join(paths.claudeDir, 'settings.json');
70
+ const settingsConfig = {
71
+ env: {
72
+ ANTHROPIC_AUTH_TOKEN: process.env.ANTHROPIC_AUTH_TOKEN || '',
73
+ ANTHROPIC_BASE_URL: process.env.ANTHROPIC_BASE_URL || ''
74
+ }
75
+ };
76
+ await fs.writeFile(destSettings, JSON.stringify(settingsConfig, null, 2));
77
+ console.log(`Created settings.json for user ${userUuid}`);
78
+
79
+ // Create usage scan state file (tracks last scanned position)
80
+ const usageScanStatePath = path.join(paths.claudeDir, '.usage-scan-state.json');
81
+ const scanState = {
82
+ lastScanTime: null,
83
+ scannedSessions: {}
84
+ };
85
+ await fs.writeFile(usageScanStatePath, JSON.stringify(scanState, null, 2));
86
+ console.log(`Created .usage-scan-state.json for user ${userUuid}`);
87
+
88
+ return paths;
89
+ }
90
+
91
+ /**
92
+ * Delete all directories for a user
93
+ */
94
+ export async function deleteUserDirectories(userUuid) {
95
+ validateUuid(userUuid);
96
+ const paths = getUserPaths(userUuid);
97
+
98
+ try {
99
+ await fs.rm(paths.configDir, { recursive: true, force: true });
100
+ await fs.rm(paths.projectsDir, { recursive: true, force: true });
101
+ console.log(`Deleted directories for user ${userUuid}`);
102
+ } catch (error) {
103
+ console.error(`Error deleting directories for user ${userUuid}:`, error);
104
+ throw error;
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Check if user directories exist
110
+ */
111
+ export async function userDirectoriesExist(userUuid) {
112
+ validateUuid(userUuid);
113
+ const paths = getUserPaths(userUuid);
114
+ try {
115
+ await fs.access(paths.configDir);
116
+ await fs.access(paths.projectsDir);
117
+ return true;
118
+ } catch {
119
+ return false;
120
+ }
121
+ }
122
+
123
+ export { DATA_DIR };
@@ -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,73 @@
1
+ /**
2
+ * MCP SERVER DETECTION UTILITY
3
+ * ============================
4
+ *
5
+ * Centralized utility for detecting MCP server configurations.
6
+ * Used across MCP-dependent features.
7
+ */
8
+
9
+ import { promises as fsPromises } from 'fs';
10
+ import path from 'path';
11
+ import { getUserPaths } from '../services/user-directories.js';
12
+
13
+ /**
14
+ * Get all configured MCP servers for a specific user
15
+ * @param {string} userUuid - User UUID (required)
16
+ * @returns {Promise<Object>} All MCP servers configuration
17
+ */
18
+ export async function getAllMCPServers(userUuid) {
19
+ if (!userUuid) {
20
+ return {
21
+ hasConfig: false,
22
+ error: 'userUuid is required',
23
+ servers: {},
24
+ projectServers: {}
25
+ };
26
+ }
27
+
28
+ try {
29
+ const userPaths = getUserPaths(userUuid);
30
+ const configPaths = [
31
+ userPaths.claudeJson,
32
+ path.join(userPaths.claudeDir, 'settings.json')
33
+ ];
34
+
35
+ let configData = null;
36
+ let configPath = null;
37
+
38
+ // Try to read from either config file
39
+ for (const filepath of configPaths) {
40
+ try {
41
+ const fileContent = await fsPromises.readFile(filepath, 'utf8');
42
+ configData = JSON.parse(fileContent);
43
+ configPath = filepath;
44
+ break;
45
+ } catch (error) {
46
+ continue;
47
+ }
48
+ }
49
+
50
+ if (!configData) {
51
+ return {
52
+ hasConfig: false,
53
+ servers: {},
54
+ projectServers: {}
55
+ };
56
+ }
57
+
58
+ return {
59
+ hasConfig: true,
60
+ configPath,
61
+ servers: configData.mcpServers || {},
62
+ projectServers: configData.projects || {}
63
+ };
64
+ } catch (error) {
65
+ console.error('Error getting all MCP servers:', error);
66
+ return {
67
+ hasConfig: false,
68
+ error: error.message,
69
+ servers: {},
70
+ projectServers: {}
71
+ };
72
+ }
73
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Centralized Model Definitions
3
+ * Single source of truth for all supported AI models
4
+ */
5
+
6
+ /**
7
+ * Claude (Anthropic) Models
8
+ *
9
+ * Note: Claude uses two different formats:
10
+ * - SDK format ('sonnet', 'opus') - used by the UI and claude-sdk.js
11
+ * - API format ('claude-sonnet-4.5') - used by slash commands for display
12
+ */
13
+ export const CLAUDE_MODELS = {
14
+ // Models in SDK format (what the actual SDK accepts)
15
+ OPTIONS: [
16
+ { value: 'sonnet', label: 'Sonnet' },
17
+ { value: 'opus', label: 'Opus' },
18
+ { value: 'haiku', label: 'Haiku' }
19
+ ],
20
+
21
+ DEFAULT: 'sonnet'
22
+ };
23
+