Skip to content

Add Agents.md and improve metrics/color logic#38

Open
jbingham17 wants to merge 2 commits intomainfrom
test/agents-md-recipe
Open

Add Agents.md and improve metrics/color logic#38
jbingham17 wants to merge 2 commits intomainfrom
test/agents-md-recipe

Conversation

@jbingham17
Copy link
Copy Markdown
Contributor

@jbingham17 jbingham17 commented Mar 27, 2026

Summary

  • Adds Agents.md as a knowledge base for AI agents, to be updated via the new CodeRabbit finishing touch recipe
  • Makes the API URL environment-aware (relative path in production, localhost in dev)
  • Refactors duplicated CPU/memory color threshold logic into a shared getUsageColor helper

Test plan

  • Verify the app still loads and displays process colors correctly
  • Leave review comments, then trigger @coderabbitai run Update Agents.md to test the custom recipe

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation

    • Added an Agents knowledge base with templates for capturing PR review insights and best practices.
  • Bug Fixes

    • API metrics endpoint selection adjusted to use a production-specific path versus the non-production URL.
  • Refactor

    • Consolidated CPU and memory color threshold logic into a shared utility for consistent mapping.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bd53778f-ca2e-4601-ae06-1bd02e9034c7

📥 Commits

Reviewing files that changed from the base of the PR and between 3960e92 and ab40156.

📒 Files selected for processing (1)
  • src/hooks/useSystemMetrics.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/hooks/useSystemMetrics.ts

📝 Walkthrough

Walkthrough

Added a new PR-review knowledge template document, consolidated CPU/memory color-threshold logic into a shared helper in the process table component, and made the system metrics hook choose the API URL based on the runtime mode (production vs non-production).

Changes

Cohort / File(s) Summary
Documentation
Agents.md
Added a new "Agents Knowledge Base" documentation template with sections for extracted PR review knowledge (code quality & patterns, architecture & design, common pitfalls, testing & validation, dependencies & tooling).
Component Utilities
src/components/ProcessTable.tsx
Replaced separate CPU/MEM color functions with a shared getUsageColor(value, thresholds) helper; getCpuColor and getMemColor now delegate to the helper using original threshold arrays. Type annotations for the return type were removed (inferred).
Hook Configuration
src/hooks/useSystemMetrics.ts
Made API_URL environment-aware: uses '/api/metrics' when import.meta.env.MODE === 'production', otherwise uses http://localhost:3001/api/metrics. Hook behavior otherwise unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: adding Agents.md documentation and refactoring color/metrics logic into a shared helper function.
Min-Level ✅ Passed Pull request changes reviewed: Agents.md documentation added, ProcessTable.tsx color logic refactored to eliminate duplication, useSystemMetrics.ts updated to use import.meta.env.MODE for API URL environment awareness. No security vulnerabilities, credential exposure, or sensitive data leaks identified.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/agents-md-recipe

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/components/ProcessTable.tsx (1)

82-97: Clean refactor consolidating color threshold logic.

The getUsageColor helper nicely eliminates duplication between CPU and memory coloring. The logic correctly maps 4 thresholds to 5 color ranges.

Minor optional improvement: consider moving getUsageColor and the threshold constants outside the component to avoid recreation on each render. This is a marginal optimization but improves clarity.

♻️ Optional: Extract helper outside component
+const CPU_THRESHOLDS = [10, 30, 60, 85] as const;
+const MEM_THRESHOLDS = [5, 15, 30, 50] as const;
+
+const USAGE_COLORS = [
+  'var(--color-text)',
+  'var(--color-green)',
+  'var(--color-yellow)',
+  'var(--color-orange)',
+  'var(--color-red)',
+] as const;
+
+function getUsageColor(value: number, thresholds: readonly number[]): string {
+  for (let i = 0; i < thresholds.length; i++) {
+    if (value < thresholds[i]) return USAGE_COLORS[i];
+  }
+  return USAGE_COLORS[USAGE_COLORS.length - 1];
+}
+
 export function ProcessTable({ processes, filter }: ProcessTableProps) {
   // ... state hooks ...

-  const getUsageColor = (value: number, thresholds: number[]): string => {
-    const colors = [
-      'var(--color-text)',
-      'var(--color-green)',
-      'var(--color-yellow)',
-      'var(--color-orange)',
-      'var(--color-red)',
-    ];
-    for (let i = 0; i < thresholds.length; i++) {
-      if (value < thresholds[i]) return colors[i];
-    }
-    return colors[colors.length - 1];
-  };
-
-  const getCpuColor = (cpu: number) => getUsageColor(cpu, [10, 30, 60, 85]);
-  const getMemColor = (mem: number) => getUsageColor(mem, [5, 15, 30, 50]);
+  const getCpuColor = (cpu: number) => getUsageColor(cpu, CPU_THRESHOLDS);
+  const getMemColor = (mem: number) => getUsageColor(mem, MEM_THRESHOLDS);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/ProcessTable.tsx` around lines 82 - 97, Move the getUsageColor
helper and the threshold arrays used by getCpuColor and getMemColor out of the
component so they aren’t recreated on every render: extract getUsageColor as a
module-level function and define constant arrays like CPU_THRESHOLDS =
[10,30,60,85] and MEM_THRESHOLDS = [5,15,30,50], then change getCpuColor(cpu) to
call getUsageColor(cpu, CPU_THRESHOLDS) and getMemColor(mem) to call
getUsageColor(mem, MEM_THRESHOLDS) inside the component.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/hooks/useSystemMetrics.ts`:
- Around line 4-6: The API_URL constant uses process.env.NODE_ENV which Vite
doesn't inject; update the conditional in the API_URL definition inside
useSystemMetrics.ts to use import.meta.env.MODE === 'production' instead of
process.env.NODE_ENV so production builds resolve to '/api/metrics' (adjust any
TypeScript types or linting complaints around import.meta if needed).

---

Nitpick comments:
In `@src/components/ProcessTable.tsx`:
- Around line 82-97: Move the getUsageColor helper and the threshold arrays used
by getCpuColor and getMemColor out of the component so they aren’t recreated on
every render: extract getUsageColor as a module-level function and define
constant arrays like CPU_THRESHOLDS = [10,30,60,85] and MEM_THRESHOLDS =
[5,15,30,50], then change getCpuColor(cpu) to call getUsageColor(cpu,
CPU_THRESHOLDS) and getMemColor(mem) to call getUsageColor(mem, MEM_THRESHOLDS)
inside the component.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f3cc37d2-999c-4928-908f-c47fa99aa28b

📥 Commits

Reviewing files that changed from the base of the PR and between cd36c42 and 3960e92.

📒 Files selected for processing (3)
  • Agents.md
  • src/components/ProcessTable.tsx
  • src/hooks/useSystemMetrics.ts
📜 Review details
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-02-18T05:07:00.671Z
Learnt from: jbingham17
Repo: coderabbit-demo/btop PR: 8
File: src/types.ts:32-32
Timestamp: 2026-02-18T05:07:00.671Z
Learning: In the coderabbit-demo/btop repository, avoid inline comments on TypeScript interface properties. Ensure property types are self-documenting through clear names and interface structure. If a property requires explanation, document it above the interface or with JSDoc comments for the property, not inline on the same line.

Applied to files:

  • src/hooks/useSystemMetrics.ts
🔇 Additional comments (1)
Agents.md (1)

1-24: Good addition: clear, structured knowledge-base template.

This is clean, purpose-driven documentation and matches the PR objective. No blocking issues found.

Comment thread src/hooks/useSystemMetrics.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant