fix: preserve multi-line message body in read_console#1227
fix: preserve multi-line message body in read_console#1227GallopingDino wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughRefactors ReadConsole.cs's stack-trace extraction logic, replacing ChangesConsole message parsing refactor
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
MCPForUnity/Editor/Tools/ReadConsole.cs (1)
519-547: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winThe uppercase+dot fallback can still split legitimate multi-line log bodies (for example
Status.\nDetails: X.Y) as stack traces, so some message content will still be lost. Tightening this heuristic would make the split safer for multi-line logs.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@MCPForUnity/Editor/Tools/ReadConsole.cs` around lines 519 - 547, The fallback in FindStackStartIndex is too permissive and can misclassify normal multi-line log text as a stack trace, causing message content to be split and lost. Tighten the heuristic in ReadConsole.FindStackStartIndex by requiring stronger stack-trace indicators than just an uppercase token with a dot, and prefer the existing explicit patterns like "at ", "UnityEngine.", "UnityEditor.", or "(at " before treating a line as stack start.
🧹 Nitpick comments (1)
MCPForUnity/Editor/Tools/ReadConsole.cs (1)
509-517: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMinor: simplify sentinel check.
FindStackStartIndexcan only return-1or an index>= 1(loop starts ati = 1), sostackStartIndex <= 0is equivalent tostackStartIndex == -1here. Not a bug, just slightly misleading.♻️ Suggested simplification
- int stackStartIndex = FindStackStartIndex(lines); - if (stackStartIndex <= 0) + int stackStartIndex = FindStackStartIndex(lines); + if (stackStartIndex == -1) return (string.Join("\n", lines), null);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@MCPForUnity/Editor/Tools/ReadConsole.cs` around lines 509 - 517, Simplify the sentinel check in ReadConsole’s stack-splitting logic: in the code that calls FindStackStartIndex, replace the broad “<= 0” guard with an explicit “== -1” check since FindStackStartIndex only returns -1 or a valid index starting at 1. Keep the existing tuple return behavior in the same parsing block, just make the condition match the actual return contract of FindStackStartIndex.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@MCPForUnity/Editor/Tools/ReadConsole.cs`:
- Around line 519-547: The fallback in FindStackStartIndex is too permissive and
can misclassify normal multi-line log text as a stack trace, causing message
content to be split and lost. Tighten the heuristic in
ReadConsole.FindStackStartIndex by requiring stronger stack-trace indicators
than just an uppercase token with a dot, and prefer the existing explicit
patterns like "at ", "UnityEngine.", "UnityEditor.", or "(at " before treating a
line as stack start.
---
Nitpick comments:
In `@MCPForUnity/Editor/Tools/ReadConsole.cs`:
- Around line 509-517: Simplify the sentinel check in ReadConsole’s
stack-splitting logic: in the code that calls FindStackStartIndex, replace the
broad “<= 0” guard with an explicit “== -1” check since FindStackStartIndex only
returns -1 or a valid index starting at 1. Keep the existing tuple return
behavior in the same parsing block, just make the condition match the actual
return contract of FindStackStartIndex.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1a7cdd0b-5c23-4f51-8dff-de2f0d64f895
📒 Files selected for processing (2)
MCPForUnity/Editor/Tools/ReadConsole.csTestProjects/UnityMCPTests/Assets/Tests/EditMode/Tools/ReadConsoleTests.cs
Description
read_consoletruncated every log entry'smessageto its first line, so a multi-lineDebug.Log("a\nb\nc")came back as just"a"— linesbandcwere dropped frommessageand never surfaced instackTraceeither, with no parameter or resource to recover them. This preserves the full multi-line message body while still separating the appended stack trace into its own gated field.Type of Change
Changes Made
ExtractStackTracewithSplitMessageAndStackTrace(+ extractedFindStackStartIndex) inMCPForUnity/Editor/Tools/ReadConsole.cs: the log entry is split into body and appended stack trace at the first stack-frame boundary, andmessagenow receives the entire body instead of only the first line.\r\n/\r→\n) and split withoutRemoveEmptyEntries, so internal blank lines in the body are preserved (e.g."a\n\nc"stays"a\n\nc").include_stacktracebehavior is unchanged: it still only gates the separatestackTracefield;messageis returned independently of it.FindStackStartIndex), so severity classification and stack detection carry no regression.HandleCommand_Get_PreservesMultilineMessageBody(multi-line log with an internal blank line; asserts the body is preserved and that the appended stack does not leak intomessage).Compatibility / Package Source
#beta,#main, tag, branch, orfile:): local checkout of CoplayDev/unity-mcp#betaPackages/packages-lock.json(if using a Git package URL): N/A (C#-only change, no package-source change)Testing/Screenshots/Recordings
cd Server && uv run pytest tests/ -v)ReadConsole EditMode tests pass on Unity 2021.3.43f1.
Documentation Updates
tools/UPDATE_DOCS_PROMPT.md(recommended)No tool/resource surface changed — no new tools, resources, or parameters. Only the value of the existing
messagefield changed (now multi-line), and the auto-generated docs are driven by the parameter registry, which is untouched.Related Issues
N/A
Additional Notes
read_consoletool passesmessagethrough unchanged, and no consumer parses theplainoutput line-by-line (verified againstServer/src/services/tools/read_console.pyand the CLI), so a multi-linemessagebreaks nothing downstream.read_consolevia HTTP server on Unity 6000.3.12f1.Summary by CodeRabbit