feat: finally made tree just like witr (this unironically took me 3 hours)#6
feat: finally made tree just like witr (this unironically took me 3 hours)#6supervoidcoder merged 7 commits intomainfrom
Conversation
📝 WalkthroughWalkthroughRefactors process-ancestry printing in Changes
Sequence Diagram(s)(omitted — changes are internal to a single program and do not introduce multi-component sequential flows requiring a diagram) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
📜 Recent review detailsConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🔇 Additional comments (10)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In @main.cpp:
- Around line 226-260: The loop repeatedly calls CreateToolhelp32Snapshot and
iterates Process32First/Process32Next for each ancestor, which is inefficient;
instead create a single snapshot once (use CreateToolhelp32Snapshot and iterate
Process32First/Process32Next to build an unordered_map<DWORD, PROCESSENTRY32>
like pidMap keyed by th32ProcessID), CloseHandle the snapshot, then replace the
inner snapshot traversal by looking up pe = pidMap[pid] and using
pe.th32ParentProcessID, WideToString(pe.szExeFile), and
GetProcessCreationTime(parentPid) to traverse parentPid until pid == 0 || 4 or
break; this removes repeated snapshots and uses the existing symbols
(CreateToolhelp32Snapshot, Process32First, Process32Next, PROCESSENTRY32, pe32,
pidMap, GetProcessCreationTime, parentPid, exeNames, exeTimes, parentPids).
- Around line 18-19: Remove the redundant include of <vector> (the duplicate
#include <vector> line) so only the single <vector> header remains; locate the
second occurrence of the <vector> include in main.cpp (the one after the
existing include on line 9) and delete it, then rebuild to ensure no other
duplicate includes exist.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.gitignoremain.cpp
🔇 Additional comments (3)
.gitignore (1)
1-7: LGTM! Standard build artifact patterns.The gitignore patterns appropriately exclude Windows build artifacts (executables, object files, and debugging symbols).
main.cpp (2)
262-286: Nice refactor! The tree traversal and display logic works correctly.The approach of collecting ancestry in vectors, reversing them, and then printing with proper indentation and Unicode box-drawing characters (└─) successfully achieves the witr-style output format. The logic correctly handles the root node (no prefix) and child nodes (with indentation and branch characters).
404-404: LGTM! UTF-8 console setup is essential.Setting the console output code page to UTF-8 ensures that the Unicode box-drawing characters (└─) used in the ancestry tree display correctly on Windows terminals.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @main.cpp:
- Around line 227-260: The snapshot handle hSnapshot is closed inside the while
loop which invalidates it for subsequent Process32First/Process32Next calls and
causes incorrect behavior; move CloseHandle(hSnapshot) so it’s called after the
loop finishes (not per-iteration) and recreate a fresh snapshot each iteration
if you intended repeated snapshots, and also reset the boolean found to false at
the start of each while(pid != 0 && pid != 4) iteration so a previous true value
doesn’t persist; update references in this block (hSnapshot,
CloseHandle(hSnapshot), found, pid, Process32First/Process32Next,
GetProcessCreationTime) accordingly.
🧹 Nitpick comments (1)
main.cpp (1)
233-241: Remove redundantparentPidassignment.
parentPidis assigned on line 233 and then identically reassigned on line 240. The second assignment is unnecessary. Also, line 241 can useparentPiddirectly.🔎 Proposed fix
parentPid = pe32.th32ParentProcessID; // this is the parent process pid ULONGLONG creationTime = GetProcessCreationTime(pid); exeTimes.emplace_back(creationTime); exeName = WideToString(pe32.szExeFile); exeNames.emplace_back(exeName); pidNames.emplace_back(pid); - parentPid = pe32.th32ParentProcessID; // this gets the pid of the PARENT pid (if there hopefully is one) - parentPids.emplace_back(pe32.th32ParentProcessID); // adds above to list + parentPids.emplace_back(parentPid); // adds above to list ULONGLONG parentTime = GetProcessCreationTime(parentPid);
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
main.cpp
🔇 Additional comments (3)
main.cpp (3)
18-18: LGTM!The
<algorithm>include is correctly added to supportstd::reverseusage.
266-300: LGTM!The vector reversal and tree printing logic correctly displays ancestry from root to leaf with proper indentation and Unicode branch characters.
404-404: LGTM!Setting UTF-8 console output is necessary for the Unicode tree characters (
└─) to render correctly.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @main.cpp:
- Around line 277-279: The indentation loop in main that prints two spaces per
iteration uses the condition `for (size_t j = 0; j <= i; j++)`, which causes one
extra iteration; change the loop condition to `j < i` so root (i==0) prints 0
spaces, first child prints 2 spaces, etc., keeping the rest of the loop body
(the std::cout << " "; comment) unchanged.
🧹 Nitpick comments (2)
main.cpp (2)
233-242: Remove redundant assignment ofparentPid.The variable
parentPidis assigned at line 233, then redundantly re-assigned from the same source at line 240. The second assignment and its comment are unnecessary.🔎 Proposed fix
// Without comments, this literally looks like alien gibberish so lemme explain parentPid = pe32.th32ParentProcessID; // this is the parent process pid ULONGLONG creationTime = GetProcessCreationTime(pid); // this stores the creation time of the CURRENT pid (not parent) exeTimes.emplace_back(creationTime); // immediately stores the above to the list exeName = WideToString(pe32.szExeFile); //this stores the NAME of the current pid, converted to something that the terminal won't choke and die on exeNames.emplace_back(exeName); // this adds the above to the name list pidNames.emplace_back(pid); // this adds the current pid (no need to store in var as already passed into if) - parentPid = pe32.th32ParentProcessID; // this gets the pid of the PARENT pid (if there hopefully is one) - parentPids.emplace_back(pe32.th32ParentProcessID); // adds above to list + parentPids.emplace_back(parentPid); // adds above to list ULONGLONG parentTime = GetProcessCreationTime(parentPid); // this gets the creation time of that one
222-225: Optional: Consider using a struct instead of parallel vectors.The parallel vectors approach works fine, but if you'd like to improve maintainability, you could define a struct to group related data:
struct ProcessInfo { std::string exeName; ULONGLONG creationTime; DWORD pid; DWORD parentPid; }; std::vector<ProcessInfo> processChain;This eliminates the need to keep multiple vectors in sync. However, your current approach is perfectly valid for this use case.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
main.cpp
🔇 Additional comments (5)
main.cpp (5)
18-18: LGTM: Include added forstd::reverse.The
<algorithm>header is correctly included to support thestd::reversecalls used later in the refactoredPrintAncestryfunction.
219-220: Excellent fix: Snapshot handle now managed correctly.The critical bugs from previous reviews have been properly addressed:
- Snapshot created once before the loop (line 219)
foundreset at the start of each iteration (line 228)CloseHandlemoved outside the loop (line 261)This ensures the handle remains valid throughout the traversal.
Also applies to: 228-228, 261-261
266-269: LGTM: Vectors correctly reversed for root-to-leaf display.All parallel vectors are properly reversed to achieve the desired ancestry tree ordering from root to child processes.
288-300: LGTM: Parent exit detection logic is sound.The logic correctly identifies orphaned processes by checking creation times and properly indents the "[Parent Process Exited]" indicator to appear at the appropriate tree level.
404-404: LGTM: UTF-8 console output enabled.
SetConsoleOutputCP(CP_UTF8)is correctly placed at the start ofmain()to ensure the Unicode tree characters (└─) render properly in the Windows console.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
@coderabbitai the ratelimit should be over by now can you rereview |
🧩 Analysis chain🏁 Script executed: Length of output: 3990 @supervoidcoder Yes, I can confirm your The key setting is: reviews:
request_changes_workflow: true # Changed: Enable PR approvalsWith I'll start the review now. ✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @main.cpp:
- Around line 233-242: parentPid is assigned twice from pe32.th32ParentProcessID
and pe32.th32ParentProcessID is used directly in parentPids.emplace_back; remove
the redundant assignment (either keep the first or the second) and use the
single parentPid variable for the parentPids.emplace_back and for the subsequent
GetProcessCreationTime call (i.e., replace
parentPids.emplace_back(pe32.th32ParentProcessID) with
parentPids.emplace_back(parentPid) and eliminate the duplicate parentPid =
pe32.th32ParentProcessID).
🧹 Nitpick comments (3)
main.cpp (3)
201-226: Nice refactoring to iterative approach!The function signature change and vector-based data collection is a solid approach. The use of multiple parallel vectors is perfectly reasonable and clear.
Optional: Remove self-deprecating comment
The comment on line 223 is unnecessarily critical of your code. Using separate vectors is a legitimate approach that's often clearer than nested structures. Consider removing or softening the comment:
- std::vector<ULONGLONG> exeTimes; // sorry for the crap code but idk how to make multidimensional arrays yet 😭😭😭 + std::vector<ULONGLONG> exeTimes; // Parallel vectors for ancestry data collection
263-286: Excellent tree rendering logic!The vector reversal and iterative printing with proper indentation correctly produces the tree structure from root to leaf. The indentation logic using
j < iis now correct (past issue resolved).Optional: Clarify comment about Unicode characters
The comment on line 282 mentions "escaped s" which is unclear. Consider:
- std::cout << "\u2514\u2500 "; // it's the little thingy thing └─ unicode from witr but escaped s + std::cout << "\u2514\u2500 "; // Unicode box-drawing characters └─ (matching witr style)
404-404: Good addition for UTF-8 tree character support!Setting the console output code page to UTF-8 is necessary for the Unicode box-drawing characters in
PrintAncestryto render correctly.Optional: Add error handling
If
SetConsoleOutputCPfails (rare but possible on very old systems), the tree characters may not render correctly. You could optionally check the return value:- SetConsoleOutputCP(CP_UTF8); + if (!SetConsoleOutputCP(CP_UTF8)) { + // Fallback: tree will still work but may show garbled characters on old systems + }However, for a tool like this, silent failure is probably acceptable.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
main.cpp
🔇 Additional comments (2)
main.cpp (2)
18-18: LGTM! Necessary include forstd::reverse.The
<algorithm>header is correctly added to support the vector reversal operations inPrintAncestry.
288-300: LGTM! Parent exit detection logic is sound.The validation correctly checks if the parent process has exited by comparing creation times and checking for invalid PIDs. The indentation calculation properly positions the message one level deeper than the last displayed process.
main.cpp
Outdated
| parentPid = pe32.th32ParentProcessID; // this is the parent process pid | ||
| ULONGLONG creationTime = GetProcessCreationTime(pid); // this stores the creation time of the CURRENT pid (not parent) | ||
| exeTimes.emplace_back(creationTime); // immediately stores the above to the list | ||
| exeName = WideToString(pe32.szExeFile); //this stores the NAME of the current pid, converted to something that the terminal won't choke and die on | ||
| exeNames.emplace_back(exeName); // this adds the above to the name list | ||
| pidNames.emplace_back(pid); // this adds the current pid (no need to store in var as already passed into if) | ||
|
|
||
| parentPid = pe32.th32ParentProcessID; // this gets the pid of the PARENT pid (if there hopefully is one) | ||
| parentPids.emplace_back(pe32.th32ParentProcessID); // adds above to list | ||
| ULONGLONG parentTime = GetProcessCreationTime(parentPid); // this gets the creation time of that one |
There was a problem hiding this comment.
Remove redundant assignment of parentPid.
The variable parentPid is assigned on line 233, then redundantly assigned again on line 240 with the same value. Line 241 also directly uses pe32.th32ParentProcessID when it could use the parentPid variable.
🔎 Proposed fix
// Without comments, this literally looks like alien gibberish so lemme explain
parentPid = pe32.th32ParentProcessID; // this is the parent process pid
ULONGLONG creationTime = GetProcessCreationTime(pid); // this stores the creation time of the CURRENT pid (not parent)
exeTimes.emplace_back(creationTime); // immediately stores the above to the list
exeName = WideToString(pe32.szExeFile); //this stores the NAME of the current pid, converted to something that the terminal won't choke and die on
exeNames.emplace_back(exeName); // this adds the above to the name list
pidNames.emplace_back(pid); // this adds the current pid (no need to store in var as already passed into if)
- parentPid = pe32.th32ParentProcessID; // this gets the pid of the PARENT pid (if there hopefully is one)
- parentPids.emplace_back(pe32.th32ParentProcessID); // adds above to list
+ parentPids.emplace_back(parentPid); // adds parent PID to list
ULONGLONG parentTime = GetProcessCreationTime(parentPid); // this gets the creation time of that one🤖 Prompt for AI Agents
In @main.cpp around lines 233 - 242, parentPid is assigned twice from
pe32.th32ParentProcessID and pe32.th32ParentProcessID is used directly in
parentPids.emplace_back; remove the redundant assignment (either keep the first
or the second) and use the single parentPid variable for the
parentPids.emplace_back and for the subsequent GetProcessCreationTime call
(i.e., replace parentPids.emplace_back(pe32.th32ParentProcessID) with
parentPids.emplace_back(parentPid) and eliminate the duplicate parentPid =
pe32.th32ParentProcessID).
|
@coderabbitai ughhhh how long till the new timeout |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@supervoidcoder I can check the exact cooldown that applies here. Do you mean:
I’m fetching your repo’s CodeRabbit config and schema now to confirm any timeout/cooldown values. If you want, I can also trigger a full review once we confirm the cooldown. 🏁 Script executed: Length of output: 2205 🛠 Debug Information Gathered @supervoidcoder Short answer:
If by “timeout” you mean GitHub API rate limits, I can check the live reset time and remaining quota and post it here. Want me to do that and/or force a full review now? Also, heads-up: the active config currently applied shows request_changes_workflow: false (so auto-approval is OFF right now), even though your coderabbit.yaml in the PR sets it to true. That suggests the default-branch config is still the one in effect during reviews. If you want approvals enabled before this PR merges, commit the setting to the default branch (or .github/coderabbit.yaml on main), and I’ll confirm it flips to true. Would you like me to:
Reply “yes” and I’ll do both. |
|
@coderabbitai look at your sticky comment it's ratelmiit |
🧩 Analysis chain🏁 Script executed: Length of output: 0 🏁 Script executed: Length of output: 36121 @supervoidcoder You're absolutely right! I can see my sticky comment clearly shows:
That 17 minutes and 13 seconds countdown was from when the rate limit message was posted. Depending on how much time has passed since then, the cooldown may have expired by now. Let me trigger a review now to see if the rate limit window has cleared: ✅ Actions performedReview triggered.
|
|
@coderabbitai look it changed! |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 2913 🏁 Script executed: Length of output: 1793 @supervoidcoder Yes! 🎉 The rate limit cleared and the review completed successfully! Looking at the PR checks, CodeRabbit now shows: The timeout is over and the review went through. Thanks for your patience while waiting for the rate limit window to expire! Your PR has been reviewed and approved. The build checks are passing too (though clang-tidy has some suggestions, but that's separate). Great work on getting the tree display working like witr! 🌳 If you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
|
@coderabbitai actually clang tidy is completely freaking broken can you fix pls Current runner version: '2.330.0' |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 903 🏁 Script executed: Length of output: 222 @supervoidcoder Found the issue! The clang-tidy workflow is using version The latest version is name: C++ Linting
on: [pull_request]
jobs:
clang-tidy-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: clang-tidy review
uses: ZedThree/clang-tidy-review@v0.23.0
with:
build_dir: .
config_file: ''
continue-on-error: true
- name: Upload review comments
uses: ZedThree/clang-tidy-review/upload@v0.23.0
continue-on-error: trueChanges made:
Replace the content in |
Summary by CodeRabbit
Chores
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.