Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ CloudCLI has a plugin system that lets you add custom tabs with their own fronte
| Plugin | Description |
|---|---|
| **[Project Stats](https://github.com/cloudcli-ai/cloudcli-plugin-starter)** | Shows file counts, lines of code, file-type breakdown, largest files, and recently modified files for your current project |
| **[Web Terminal](https://github.com/cloudcli-ai/cloudcli-plugin-terminal)** | Full xterm.js terminal with multi-tab support|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify the Web Terminal plugin repository exists and is accessible

# Check if the repository exists
gh repo view cloudcli-ai/cloudcli-plugin-terminal --json name,description,url

# Check the README for feature description
gh repo view cloudcli-ai/cloudcli-plugin-terminal --web

Repository: siteboon/claudecodeui

Length of output: 262


🌐 Web query:

cloudcli-ai cloudcli-plugin-terminal GitHub repository

💡 Result:

The GitHub repository for cloudcli-ai / cloudcli-plugin-terminal is:

  • cloudcli-ai/cloudcli-plugin-terminal (CloudCLI Plugin — Web Terminal) [1]

CloudCLI GitHub org (shows the repo in its repository list): [2]

References:
[1] https://github.com/cloudcli-ai/cloudcli-plugin-terminal
[2] https://github.com/cloudcli-ai


🏁 Script executed:

#!/bin/bash
# Try to access the repository URL via HTTP to verify it exists
curl -s -o /dev/null -w "HTTP Status: %{http_code}\n" "https://github.com/cloudcli-ai/cloudcli-plugin-terminal"

# Also check the organization page
curl -s -o /dev/null -w "HTTP Status: %{http_code}\n" "https://github.com/cloudcli-ai"

Repository: siteboon/claudecodeui

Length of output: 98


Add space before the closing pipe for consistent table formatting.

The plugin entry follows the existing format correctly, and the repository is publicly accessible. However, there's a minor spacing inconsistency: add a space before the closing pipe to match the formatting of other rows in the table.

Formatting fix
-| **[Web Terminal](https://github.com/cloudcli-ai/cloudcli-plugin-terminal)** | Full xterm.js terminal with multi-tab support|
+| **[Web Terminal](https://github.com/cloudcli-ai/cloudcli-plugin-terminal)** | Full xterm.js terminal with multi-tab support |
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| **[Web Terminal](https://github.com/cloudcli-ai/cloudcli-plugin-terminal)** | Full xterm.js terminal with multi-tab support|
| **[Web Terminal](https://github.com/cloudcli-ai/cloudcli-plugin-terminal)** | Full xterm.js terminal with multi-tab support |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` at line 156, The table row for "Web Terminal" is missing a space
before the closing pipe causing inconsistent table alignment; edit the Markdown
table row containing the text "**[Web
Terminal](https://github.com/cloudcli-ai/cloudcli-plugin-terminal)** | Full
xterm.js terminal with multi-tab support|" and add a single space before the
final pipe so it matches other rows (i.e., change the trailing "...support|" to
"...support |").


### Build Your Own

Expand Down
2 changes: 0 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 47 additions & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import userRoutes from './routes/user.js';
import codexRoutes from './routes/codex.js';
import geminiRoutes from './routes/gemini.js';
import pluginsRoutes from './routes/plugins.js';
import { startEnabledPluginServers, stopAllPlugins } from './utils/plugin-process-manager.js';
import { startEnabledPluginServers, stopAllPlugins, getPluginPort } from './utils/plugin-process-manager.js';
import { initializeDatabase, sessionNamesDb, applyCustomSessionNames } from './database/db.js';
import { configureWebPush } from './services/vapid-keys.js';
import { validateApiKey, authenticateToken, authenticateWebSocket } from './middleware/auth.js';
Expand Down Expand Up @@ -1396,6 +1396,50 @@ const uploadFilesHandler = async (req, res) => {

app.post('/api/projects/:projectName/files/upload', authenticateToken, uploadFilesHandler);

/**
* Proxy an authenticated client WebSocket to a plugin's internal WS server.
* Auth is enforced by verifyClient before this function is reached.
*/
function handlePluginWsProxy(clientWs, pathname) {
const pluginName = pathname.replace('/plugin-ws/', '');
if (!pluginName || /[^a-zA-Z0-9_-]/.test(pluginName)) {
clientWs.close(4400, 'Invalid plugin name');
return;
}

const port = getPluginPort(pluginName);
if (!port) {
clientWs.close(4404, 'Plugin not running');
return;
}

const upstream = new WebSocket(`ws://127.0.0.1:${port}/ws`);

upstream.on('open', () => {
console.log(`[Plugins] WS proxy connected to "${pluginName}" on port ${port}`);
});

// Relay messages bidirectionally
upstream.on('message', (data) => {
if (clientWs.readyState === WebSocket.OPEN) clientWs.send(data);
});
clientWs.on('message', (data) => {
if (upstream.readyState === WebSocket.OPEN) upstream.send(data);
});
Comment on lines +1416 to +1428
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Potential message loss during upstream connection phase.

Messages sent by the client before the upstream WebSocket reaches the OPEN state will be silently dropped due to the readyState check on line 1427. This could cause issues if the client immediately sends messages after connecting.

Consider buffering client messages until the upstream connection is established:

🔧 Proposed fix to buffer messages until upstream is ready
 function handlePluginWsProxy(clientWs, pathname) {
     const pluginName = pathname.replace('/plugin-ws/', '');
     if (!pluginName || /[^a-zA-Z0-9_-]/.test(pluginName)) {
         clientWs.close(4400, 'Invalid plugin name');
         return;
     }

     const port = getPluginPort(pluginName);
     if (!port) {
         clientWs.close(4404, 'Plugin not running');
         return;
     }

     const upstream = new WebSocket(`ws://127.0.0.1:${port}/ws`);
+    const pendingMessages = [];

     upstream.on('open', () => {
         console.log(`[Plugins] WS proxy connected to "${pluginName}" on port ${port}`);
+        // Flush any messages that arrived before upstream was ready
+        for (const msg of pendingMessages) {
+            upstream.send(msg);
+        }
+        pendingMessages.length = 0;
     });

     // Relay messages bidirectionally
     upstream.on('message', (data) => {
         if (clientWs.readyState === WebSocket.OPEN) clientWs.send(data);
     });
     clientWs.on('message', (data) => {
-        if (upstream.readyState === WebSocket.OPEN) upstream.send(data);
+        if (upstream.readyState === WebSocket.OPEN) {
+            upstream.send(data);
+        } else if (upstream.readyState === WebSocket.CONNECTING) {
+            pendingMessages.push(data);
+        }
+        // If upstream is CLOSING or CLOSED, drop the message (connection is terminating)
     });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/index.js` around lines 1416 - 1428, The client messages can be dropped
while the upstream WebSocket (upstream) is still connecting; implement a small
buffer/queue to store messages received in clientWs.on('message') until upstream
emits 'open', then flush the queue by sending each buffered message via
upstream.send; ensure you still check upstream.readyState before sending and
clear the buffer on upstream 'close'/'error' (or forward an error to clientWs)
to avoid memory leaks; reference the upstream and clientWs event handlers and
the pluginName/port logging when adding the buffer and flush logic.


// Propagate close in both directions
upstream.on('close', () => { if (clientWs.readyState === WebSocket.OPEN) clientWs.close(); });
clientWs.on('close', () => { if (upstream.readyState === WebSocket.OPEN) upstream.close(); });

upstream.on('error', (err) => {
console.error(`[Plugins] WS proxy error for "${pluginName}":`, err.message);
if (clientWs.readyState === WebSocket.OPEN) clientWs.close(4502, 'Upstream error');
});
clientWs.on('error', () => {
if (upstream.readyState === WebSocket.OPEN) upstream.close();
});
}

// WebSocket connection handler that routes based on URL path
wss.on('connection', (ws, request) => {
const url = request.url;
Expand All @@ -1409,6 +1453,8 @@ wss.on('connection', (ws, request) => {
handleShellConnection(ws);
} else if (pathname === '/ws') {
handleChatConnection(ws, request);
} else if (pathname.startsWith('/plugin-ws/')) {
handlePluginWsProxy(ws, pathname);
} else {
console.log('[WARN] Unknown WebSocket path:', pathname);
ws.close();
Expand Down
6 changes: 5 additions & 1 deletion server/routes/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ router.get('/:name/assets/*', (req, res) => {

const contentType = mime.lookup(resolvedPath) || 'application/octet-stream';
res.setHeader('Content-Type', contentType);
// Prevent CDN/proxy caching of plugin assets so updates take effect immediately
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
res.setHeader('Pragma', 'no-cache');
res.setHeader('Expires', '0');
const stream = fs.createReadStream(resolvedPath);
stream.on('error', () => {
if (!res.headersSent) {
Expand Down Expand Up @@ -236,7 +240,7 @@ router.all('/:name/rpc/*', async (req, res) => {
'content-type': req.headers['content-type'] || 'application/json',
};

// Add per-plugin secrets as X-Plugin-Secret-* headers
// Add per-plugin user-configured secrets as X-Plugin-Secret-* headers
for (const [key, value] of Object.entries(secrets)) {
headers[`x-plugin-secret-${key.toLowerCase()}`] = String(value);
}
Expand Down
Loading