Skip to content
Open
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
258 changes: 258 additions & 0 deletions create-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
#!/bin/bash

# Script to create a branch, commit changes, push to all remotes, and create PRs
# Usage: ./create-pr.sh <branch-name> <commit-message> <pr-title> [pr-description]
#
# Prerequisites:
# - Bitbucket: API key at ~/.bitbucket-api-key (required for BB PRs)
# - GitHub: gh CLI (preferred) or token at ~/.github-token
# - GitLab: glab CLI (required for GL PRs)

# Don't exit on error - we want to continue even if some remotes fail
set +e

# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Check if required arguments are provided
if [ $# -lt 3 ]; then
echo -e "${RED}Error: Missing required arguments${NC}"
echo "Usage: $0 <branch-name> <commit-message> <pr-title> [pr-description]"
echo ""
echo "Example:"
echo " $0 feature/new-ui 'Add new UI components' 'Add New UI Components' 'This PR adds new UI components for better UX'"
exit 1
fi

BRANCH_NAME="$1"
COMMIT_MESSAGE="$2"
PR_TITLE="$3"
PR_DESCRIPTION="${4:-$COMMIT_MESSAGE}"

# Add Claude Code signature to commit message and PR description
COMMIT_MESSAGE_FULL="$COMMIT_MESSAGE

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>"

PR_DESCRIPTION_FULL="$PR_DESCRIPTION

🤖 Generated with [Claude Code](https://claude.com/claude-code)"

echo -e "${GREEN}Starting automated PR creation workflow...${NC}"
echo ""

# Step 1: Create and checkout new branch
echo -e "${YELLOW}Step 1: Creating branch '$BRANCH_NAME'...${NC}"
# Delete branch if it already exists
git branch -D "$BRANCH_NAME" 2>/dev/null
git checkout -b "$BRANCH_NAME"
if [ $? -ne 0 ]; then
echo -e "${RED}✗ Failed to create branch '$BRANCH_NAME'${NC}"
exit 1
fi
Comment on lines +51 to +57
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Branch deletion without confirmation could cause data loss.

git branch -D "$BRANCH_NAME" forcefully deletes the branch if it exists, potentially discarding uncommitted or unpushed work without warning. Consider prompting for confirmation or using -d (safe delete) first.

-# Delete branch if it already exists
-git branch -D "$BRANCH_NAME" 2>/dev/null
+# Check if branch exists and warn user
+if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then
+    echo -e "${YELLOW}Warning: Branch '$BRANCH_NAME' already exists.${NC}"
+    read -p "Delete existing branch and continue? (y/N) " -n 1 -r
+    echo
+    if [[ ! $REPLY =~ ^[Yy]$ ]]; then
+        echo -e "${RED}Aborted.${NC}"
+        exit 1
+    fi
+    git branch -D "$BRANCH_NAME"
+fi
🤖 Prompt for AI Agents
In create-pr.sh around lines 51 to 57, the script currently force-deletes the
branch with git branch -D which can discard unpushed or uncommitted work; change
the flow to first check if the branch exists (git rev-parse --verify
"$BRANCH_NAME" >/dev/null 2>&1), then try a safe delete with git branch -d
"$BRANCH_NAME" and only if that fails prompt the user for confirmation to
force-delete (or accept a --force/CI flag) before running git branch -D
"$BRANCH_NAME"; ensure the prompt is clear and abort if the user declines.

echo -e "${GREEN}✓ Branch created and checked out${NC}"
echo ""

# Step 2: Stage all changes
echo -e "${YELLOW}Step 2: Staging changes...${NC}"
git add .
echo -e "${GREEN}✓ Changes staged${NC}"
echo ""

# Step 3: Commit changes
echo -e "${YELLOW}Step 3: Committing changes...${NC}"
git commit -m "$COMMIT_MESSAGE_FULL"
echo -e "${GREEN}✓ Changes committed${NC}"
echo ""

# Step 4: Push to all remotes
echo -e "${YELLOW}Step 4: Pushing to all remotes...${NC}"

# Get base branch (default to main)
BASE_BRANCH="${BASE_BRANCH:-main}"

# Track successful pushes (bash 3.2 compatible)
PUSHED_BB=0
PUSHED_GH=0
PUSHED_GL=0

# Push to each remote
for remote in bb gh gl; do
echo -e " Pushing to ${YELLOW}$remote${NC}..."
if git push -u "$remote" "$BRANCH_NAME" 2>/dev/null; then
echo -e " ${GREEN}✓ Pushed to $remote${NC}"
case $remote in
bb) PUSHED_BB=1 ;;
gh) PUSHED_GH=1 ;;
gl) PUSHED_GL=1 ;;
esac
else
echo -e " ${RED}✗ Failed to push to $remote (server may be unavailable)${NC}"
fi
done
echo ""

# Step 5: Create PRs
echo -e "${YELLOW}Step 5: Creating pull requests...${NC}"
echo ""

# Load Bitbucket API key
if [ -f ~/.bitbucket-api-key ]; then
BB_API_KEY=$(cat ~/.bitbucket-api-key)
else
echo -e "${RED}Warning: Bitbucket API key not found at ~/.bitbucket-api-key${NC}"
BB_API_KEY=""
fi

# Load GitHub token
if [ -f ~/.github-token ]; then
GH_TOKEN=$(cat ~/.github-token)
else
echo -e "${YELLOW}Info: GitHub token not found at ~/.github-token. Attempting to use gh CLI...${NC}"
GH_TOKEN=""
fi

# Create PR on Bitbucket
if [ "$PUSHED_BB" = "1" ]; then
if [ -n "$BB_API_KEY" ]; then
echo -e " Creating PR on ${YELLOW}Bitbucket${NC}..."
# Escape special characters in description for JSON
PR_DESC_ESCAPED=$(echo "$PR_DESCRIPTION_FULL" | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}' | sed '$ s/\\n$//')
PR_TITLE_ESCAPED=$(echo "$PR_TITLE" | sed 's/"/\\"/g')

BB_RESPONSE=$(curl -s -X POST \
-u "jbingham@coderabbit.ai:$BB_API_KEY" \
-H "Content-Type: application/json" \
https://api.bitbucket.org/2.0/repositories/demo-coderabbit/btop/pullrequests \
-d "{\"title\":\"$PR_TITLE_ESCAPED\",\"source\":{\"branch\":{\"name\":\"$BRANCH_NAME\"}},\"destination\":{\"branch\":{\"name\":\"$BASE_BRANCH\"}},\"description\":\"$PR_DESC_ESCAPED\"}")
Comment on lines +128 to +132
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Hardcoded email address limits script reusability.

The Bitbucket username jbingham@coderabbit.ai is hardcoded. This should be configurable via environment variable or config file to allow other users to use this script.

+# Load Bitbucket username
+BB_USERNAME="${BB_USERNAME:-$(git config user.email)}"
+
 BB_RESPONSE=$(curl -s -X POST \
-  -u "jbingham@coderabbit.ai:$BB_API_KEY" \
+  -u "$BB_USERNAME:$BB_API_KEY" \
📝 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
BB_RESPONSE=$(curl -s -X POST \
-u "jbingham@coderabbit.ai:$BB_API_KEY" \
-H "Content-Type: application/json" \
https://api.bitbucket.org/2.0/repositories/demo-coderabbit/btop/pullrequests \
-d "{\"title\":\"$PR_TITLE_ESCAPED\",\"source\":{\"branch\":{\"name\":\"$BRANCH_NAME\"}},\"destination\":{\"branch\":{\"name\":\"$BASE_BRANCH\"}},\"description\":\"$PR_DESC_ESCAPED\"}")
# Load Bitbucket username
BB_USERNAME="${BB_USERNAME:-$(git config user.email)}"
BB_RESPONSE=$(curl -s -X POST \
-u "$BB_USERNAME:$BB_API_KEY" \
-H "Content-Type: application/json" \
https://api.bitbucket.org/2.0/repositories/demo-coderabbit/btop/pullrequests \
-d "{\"title\":\"$PR_TITLE_ESCAPED\",\"source\":{\"branch\":{\"name\":\"$BRANCH_NAME\"}},\"destination\":{\"branch\":{\"name\":\"$BASE_BRANCH\"}},\"description\":\"$PR_DESC_ESCAPED\"}")
🤖 Prompt for AI Agents
In create-pr.sh around lines 128 to 132 the Bitbucket username is hardcoded as
jbingham@coderabbit.ai which prevents reuse; change the script to read the
username from an environment variable (e.g. BB_USER or BITBUCKET_USER) and use
that in the curl -u authentication string (fallback to a sensible default or
fail with a clear error if not set). Also add a short pre-check to ensure
BB_USER and BB_API_KEY are set before calling curl so the script fails fast with
a helpful message.


BB_PR_URL=$(echo "$BB_RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data.get('links', {}).get('html', {}).get('href', ''))" 2>/dev/null)
if [ -n "$BB_PR_URL" ]; then
echo -e " ${GREEN}✓ Bitbucket PR created: $BB_PR_URL${NC}"
else
echo -e " ${RED}✗ Failed to create Bitbucket PR${NC}"
echo -e " ${RED}Response: $BB_RESPONSE${NC}"
fi
else
echo -e " ${YELLOW}⊘ Skipping Bitbucket PR (no API key)${NC}"
fi
else
echo -e " ${YELLOW}⊘ Skipping Bitbucket PR (push failed)${NC}"
fi

# Create PR on GitHub
if [ "$PUSHED_GH" = "1" ]; then
echo -e " Creating PR on ${YELLOW}GitHub${NC}..."
if command -v gh &> /dev/null; then
GH_PR_URL=$(gh pr create --repo coderabbit-demo/btop \
--title "$PR_TITLE" \
--body "$PR_DESCRIPTION_FULL" \
--base "$BASE_BRANCH" \
--head "$BRANCH_NAME" 2>&1)

if [[ $GH_PR_URL == http* ]]; then
echo -e " ${GREEN}✓ GitHub PR created: $GH_PR_URL${NC}"
else
echo -e " ${RED}✗ Failed to create GitHub PR: $GH_PR_URL${NC}"
fi
elif [ -n "$GH_TOKEN" ]; then
GH_RESPONSE=$(curl -s -X POST \
-H "Authorization: token $GH_TOKEN" \
-H "Content-Type: application/json" \
https://api.github.com/repos/coderabbit-demo/btop/pulls \
-d "{
\"title\": \"$PR_TITLE\",
\"body\": \"$PR_DESCRIPTION_FULL\",
\"head\": \"$BRANCH_NAME\",
\"base\": \"$BASE_BRANCH\"
}")
Comment on lines +164 to +173
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

JSON body not properly escaped for GitHub API.

Unlike the Bitbucket request (lines 125-126), the GitHub API request doesn't escape special characters in PR_TITLE and PR_DESCRIPTION_FULL. Quotes or newlines in these values will break the JSON payload.

+        # Escape for JSON
+        GH_PR_TITLE_ESCAPED=$(echo "$PR_TITLE" | sed 's/"/\\"/g')
+        GH_PR_DESC_ESCAPED=$(echo "$PR_DESCRIPTION_FULL" | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}' | sed '$ s/\\n$//')
+        
         GH_RESPONSE=$(curl -s -X POST \
           -H "Authorization: token $GH_TOKEN" \
           -H "Content-Type: application/json" \
           https://api.github.com/repos/coderabbit-demo/btop/pulls \
           -d "{
-            \"title\": \"$PR_TITLE\",
-            \"body\": \"$PR_DESCRIPTION_FULL\",
+            \"title\": \"$GH_PR_TITLE_ESCAPED\",
+            \"body\": \"$GH_PR_DESC_ESCAPED\",
             \"head\": \"$BRANCH_NAME\",
             \"base\": \"$BASE_BRANCH\"
           }")
🤖 Prompt for AI Agents
In create-pr.sh around lines 164 to 173, the JSON body for the GitHub API POST
is built by interpolating raw shell variables which will break if PR_TITLE or
PR_DESCRIPTION_FULL contain quotes or newlines; replace the inline interpolated
JSON with a properly escaped JSON generator (for example use jq -n with --arg
for each field or generate the payload with printf and jq to escape strings) and
pass the resulting safe JSON to curl (e.g., via --data @- or a temporary file)
so that quotes, newlines and other special characters in PR_TITLE and
PR_DESCRIPTION_FULL are correctly escaped.


GH_PR_URL=$(echo "$GH_RESPONSE" | grep -o '"html_url":"[^"]*"' | head -1 | sed 's/"html_url":"//;s/"$//')
if [ -n "$GH_PR_URL" ]; then
echo -e " ${GREEN}✓ GitHub PR created: $GH_PR_URL${NC}"
else
echo -e " ${RED}✗ Failed to create GitHub PR${NC}"
fi
else
echo -e " ${YELLOW}⊘ Skipping GitHub PR (no gh CLI or token found)${NC}"
fi
else
echo -e " ${YELLOW}⊘ Skipping GitHub PR (push failed)${NC}"
fi

# Create PR on GitLab (gitlab.com)
if [ "$PUSHED_GL" = "1" ]; then
echo -e " Creating PR on ${YELLOW}GitLab (gitlab.com)${NC}..."
if command -v glab &> /dev/null; then
GLAB_PR_URL=$(glab mr create --repo demo-coderabbit/btop \
--title "$PR_TITLE" \
--description "$PR_DESCRIPTION_FULL" \
--source-branch "$BRANCH_NAME" \
--target-branch "$BASE_BRANCH" 2>&1 | grep -o 'https://[^ ]*')

if [ -n "$GLAB_PR_URL" ]; then
echo -e " ${GREEN}✓ GitLab MR created: $GLAB_PR_URL${NC}"
else
echo -e " ${RED}✗ Failed to create GitLab MR${NC}"
fi
else
echo -e " ${YELLOW}⊘ Skipping GitLab MR (glab CLI not found)${NC}"
fi
else
echo -e " ${YELLOW}⊘ Skipping GitLab MR (push failed)${NC}"
fi

echo ""
echo -e "${GREEN}Workflow completed!${NC}"
echo ""

# Build list of successful pushes
SUCCESSFUL_REMOTES=""
for remote in bb gh gl; do
case $remote in
bb) PUSHED=$PUSHED_BB ;;
gh) PUSHED=$PUSHED_GH ;;
gl) PUSHED=$PUSHED_GL ;;
esac

if [ "$PUSHED" = "1" ]; then
if [ -z "$SUCCESSFUL_REMOTES" ]; then
SUCCESSFUL_REMOTES="$remote"
else
SUCCESSFUL_REMOTES="$SUCCESSFUL_REMOTES, $remote"
fi
fi
done

# Build list of failed pushes
FAILED_REMOTES=""
for remote in bb gh gl; do
case $remote in
bb) PUSHED=$PUSHED_BB ;;
gh) PUSHED=$PUSHED_GH ;;
gl) PUSHED=$PUSHED_GL ;;
esac

if [ "$PUSHED" = "0" ]; then
if [ -z "$FAILED_REMOTES" ]; then
FAILED_REMOTES="$remote"
else
FAILED_REMOTES="$FAILED_REMOTES, $remote"
fi
fi
done

echo "Summary:"
echo " Branch: $BRANCH_NAME"
if [ -n "$SUCCESSFUL_REMOTES" ]; then
echo -e " ${GREEN}✓ Pushed to: $SUCCESSFUL_REMOTES${NC}"
fi
if [ -n "$FAILED_REMOTES" ]; then
echo -e " ${RED}✗ Failed to push to: $FAILED_REMOTES${NC}"
fi
echo " PRs created on available platforms"
3 changes: 3 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MemoryGraph } from './components/MemoryGraph';
import { ProcessTable } from './components/ProcessTable';
import { StatusBar } from './components/StatusBar';
import { EnvironmentPanel } from './components/EnvironmentPanel';
import { NetworkPanel } from './components/NetworkPanel';
import { useSystemMetrics } from './hooks/useSystemMetrics';
import './App.css';

Expand Down Expand Up @@ -61,6 +62,8 @@ function App() {
/>
</div>

<NetworkPanel metrics={metrics} />

<div className="process-section compact">
<div className="section-header">
<span className="section-title">Processes</span>
Expand Down
99 changes: 99 additions & 0 deletions src/components/NetworkPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { useState, useEffect } from 'react';
import type { SystemMetrics } from '../types';

interface NetworkPanelProps {
metrics: SystemMetrics;
}

// Magic numbers without constants
export function NetworkPanel({ metrics }: NetworkPanelProps) {
const [downloadSpeed, setDownloadSpeed] = useState(0);
const [uploadSpeed, setUploadSpeed] = useState(0);
const [totalDownloaded, setTotalDownloaded] = useState(0);
const [totalUploaded, setTotalUploaded] = useState(0);
const [previousTimestamp, setPreviousTimestamp] = useState(0); // Inconsistent indentation (spaces vs tabs)
const unusedVariable = "This is not used anywhere"; // Unused variable
let tempCounter = 0; // Unused variable
Comment on lines +14 to +16
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Remove unused variables and fix inconsistent indentation.

Lines 14-16 have mixed indentation (spaces vs tabs) and declare unused variables (unusedVariable, tempCounter). These should be removed.

-        const [previousTimestamp, setPreviousTimestamp] = useState(0); // Inconsistent indentation (spaces vs tabs)
-	const unusedVariable = "This is not used anywhere"; // Unused variable
-  let tempCounter = 0; // Unused variable
+  const [previousTimestamp, setPreviousTimestamp] = useState(Date.now);
📝 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
const [previousTimestamp, setPreviousTimestamp] = useState(0); // Inconsistent indentation (spaces vs tabs)
const unusedVariable = "This is not used anywhere"; // Unused variable
let tempCounter = 0; // Unused variable
const [previousTimestamp, setPreviousTimestamp] = useState(Date.now());
Suggested change
const [previousTimestamp, setPreviousTimestamp] = useState(0); // Inconsistent indentation (spaces vs tabs)
const unusedVariable = "This is not used anywhere"; // Unused variable
let tempCounter = 0; // Unused variable
const [previousTimestamp, setPreviousTimestamp] = useState(0);
🤖 Prompt for AI Agents
In src/components/NetworkPanel.tsx around lines 14 to 16, there is inconsistent
indentation (mix of spaces and tabs) and two unused variables declared
(unusedVariable and tempCounter); remove the unusedVariable and tempCounter
declarations and normalize the remaining line indentation to match the file's
convention (replace tabs with spaces or vice versa as used elsewhere) so the
code has consistent indentation and no unused variables.


useEffect(() => {
// Simulate network metrics calculation
const timestamp = Date.now();
const timeDiff = timestamp - previousTimestamp;

if (timeDiff > 0) // Missing braces
setDownloadSpeed(Math.random() * 1024 * 1024 * 10);

if (timeDiff > 0) // Missing braces
setUploadSpeed(Math.random() * 1024 * 1024 * 5);

// Non-const correctness - should be const
let calculatedDownload = totalDownloaded + (downloadSpeed * timeDiff / 1000);
let calculatedUpload = totalUploaded + (uploadSpeed * timeDiff / 1000);

setTotalDownloaded(calculatedDownload);
setTotalUploaded(calculatedUpload);
setPreviousTimestamp(timestamp);
}, [metrics]);
Comment on lines +18 to +36
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Stale closure bug causes incorrect calculations.

The useEffect reads downloadSpeed, uploadSpeed, totalDownloaded, and totalUploaded from state but doesn't include them in the dependency array. This causes stale values to be used. Additionally, initializing previousTimestamp to 0 means the first timeDiff will be ~1.7 trillion milliseconds, causing totalDownloaded/totalUploaded to explode immediately.

Consider using useRef for values that need to persist across renders without triggering re-renders, or use functional state updates:

+  const previousTimestampRef = useRef(Date.now());
+  const downloadSpeedRef = useRef(0);
+  const uploadSpeedRef = useRef(0);
+
   useEffect(() => {
     const timestamp = Date.now();
-    const timeDiff = timestamp - previousTimestamp;
+    const timeDiff = timestamp - previousTimestampRef.current;
 
-    if (timeDiff > 0)
-      setDownloadSpeed(Math.random() * 1024 * 1024 * 10);
-
-    if (timeDiff > 0)
-      setUploadSpeed(Math.random() * 1024 * 1024 * 5);
-
-    let calculatedDownload = totalDownloaded + (downloadSpeed * timeDiff / 1000);
-    let calculatedUpload = totalUploaded + (uploadSpeed * timeDiff / 1000);
-
-    setTotalDownloaded(calculatedDownload);
-    setTotalUploaded(calculatedUpload);
-    setPreviousTimestamp(timestamp);
+    if (timeDiff > 0 && timeDiff < 10000) { // Guard against first render
+      const newDownloadSpeed = Math.random() * 1024 * 1024 * 10;
+      const newUploadSpeed = Math.random() * 1024 * 1024 * 5;
+      
+      downloadSpeedRef.current = newDownloadSpeed;
+      uploadSpeedRef.current = newUploadSpeed;
+      setDownloadSpeed(newDownloadSpeed);
+      setUploadSpeed(newUploadSpeed);
+      
+      setTotalDownloaded(prev => prev + (newDownloadSpeed * timeDiff / 1000));
+      setTotalUploaded(prev => prev + (newUploadSpeed * timeDiff / 1000));
+    }
+    previousTimestampRef.current = timestamp;
   }, [metrics]);

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In src/components/NetworkPanel.tsx around lines 18 to 36, the effect uses stale
state (downloadSpeed, uploadSpeed, totalDownloaded, totalUploaded) and an
initial previousTimestamp of 0 causing an enormous first timeDiff; also the two
ifs lack braces and calculatedDownload/calculatedUpload should be const. Fix by
initializing previousTimestamp to Date.now() (or guard the first run to skip
accumulation), use functional state updates or refs to avoid reading stale
values inside the effect (e.g., setTotalDownloaded(prev => prev + downloadSpeed
* timeDiff / 1000) and similarly for upload) and include any necessary
dependencies or move mutable counters into useRef so the effect dependencies
remain stable, add braces around the if bodies, and change
calculatedDownload/calculatedUpload to const when keeping local calculations.


// Unnecessary type casting
const formatBytes = (bytes: number) => {
if (bytes < 1024) return bytes + ' B';
if (bytes < 1048576) return (bytes / 1024 as number).toFixed(2) + ' KB';
if (bytes < 1073741824) return ((bytes / 1048576) as number).toFixed(2) + ' MB';
return ((bytes / 1073741824) as number).toFixed(2) + ' GB';
};

// Inconsistent naming convention (should be camelCase)
const Calculate_Speed_Color = (speed: number): string => {
if (speed < 1048576) return '#34d399'; // Magic number
if (speed < 10485760) return '#fbbf24'; // Magic number
if (speed < 104857600) return '#fb923c'; // Magic number
return '#f87171';
};

// Very long line that exceeds typical line length limits
const networkInterfaceStatus = metrics && metrics.cpuUsage && metrics.cpuUsage.length > 0 && metrics.memPercent > 0 ? 'Active' : 'Inactive';
Comment on lines +54 to +55
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Network status logic checks wrong metrics.

networkInterfaceStatus checks cpuUsage and memPercent to determine if the network is "Active", which is semantically incorrect and misleading to users. Consider checking actual network-related data or removing this status indicator until real network metrics are available.

🤖 Prompt for AI Agents
In src/components/NetworkPanel.tsx around lines 54-55, the
networkInterfaceStatus variable is computed using cpuUsage and memPercent which
is semantically incorrect; replace that logic to use real network-related
metrics (e.g., metrics.networkInterfaces, metrics.networkUsage, or a specific
interface.active flag) or remove the status indicator until proper network
metrics are available. Ensure the expression checks for the presence and
non-empty state of the chosen network metric(s) and yields 'Active' or
'Inactive' accordingly, and keep the line length within style limits by
splitting into multiple shorter statements if needed.


// Empty catch block
try {
const data = JSON.parse('{"test": "value"}');
} catch (e) {
// Empty catch - poor error handling
}
Comment on lines +57 to +62
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Remove dead code with empty catch block.

This try/catch block parses a hardcoded valid JSON string, assigns it to an unused variable, and silently swallows any errors. It serves no purpose and should be removed.

-  // Empty catch block
-  try {
-    const data = JSON.parse('{"test": "value"}');
-  } catch (e) {
-    // Empty catch - poor error handling
-  }
📝 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
// Empty catch block
try {
const data = JSON.parse('{"test": "value"}');
} catch (e) {
// Empty catch - poor error handling
}
🤖 Prompt for AI Agents
In src/components/NetworkPanel.tsx around lines 57 to 62, remove the dead
try/catch: the block parses a hardcoded JSON into an unused variable and the
catch is empty; delete the entire try/catch (both JSON.parse and the empty
catch) so no silent error handling or unused parsing remains, and run
lint/format to ensure no leftover unused imports or variables are present.


return (
<div className="network-panel">
<div className="panel-header">
<span className="panel-title">Network Statistics</span>
<span className="panel-status" style={{ color: networkInterfaceStatus === 'Active' ? '#34d399' : '#f87171' }}>
{networkInterfaceStatus}
</span>
</div>
<div className="network-stats">
<div className="stat-row">
<span className="stat-label">Download:</span>
<span className="stat-value" style={{ color: Calculate_Speed_Color(downloadSpeed) }}>
{formatBytes(downloadSpeed)}/s
</span>
</div>
<div className="stat-row">
<span className="stat-label">Upload:</span>
<span className="stat-value" style={{ color: Calculate_Speed_Color(uploadSpeed) }}>
{formatBytes(uploadSpeed)}/s
</span>
</div>
<div className="stat-row">
<span className="stat-label">Total Downloaded:</span>
<span className="stat-value">{formatBytes(totalDownloaded)}</span>
</div>
<div className="stat-row">
<span className="stat-label">Total Uploaded:</span>
<span className="stat-value">{formatBytes(totalUploaded)}</span>
</div>
</div>
<div className="network-graph-placeholder">
<div className="placeholder-text">Network traffic visualization</div>
</div>
</div>
);
}