Skip to content

feat/cmd-parsing#142

Merged
omarluq merged 3 commits into
mainfrom
feat/cmd-parsing
Jun 19, 2026
Merged

feat/cmd-parsing#142
omarluq merged 3 commits into
mainfrom
feat/cmd-parsing

Conversation

@omarluq

@omarluq omarluq commented Jun 19, 2026

Copy link
Copy Markdown
Owner

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3e95a2d3-4900-47a5-a90f-048089e896c9

📥 Commits

Reviewing files that changed from the base of the PR and between 5cb8f9c and 29f631b.

📒 Files selected for processing (2)
  • internal/compaction/file_operations.go
  • internal/compaction/file_operations_internal_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/compaction/file_operations_internal_test.go
  • internal/compaction/file_operations.go

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • Improvements

    • Enhanced shell command parsing to more reliably detect which commands mutate files and to better extract candidate file paths.
    • Refined terminal diff section headers to improve readability.
  • Tests

    • Updated and expanded shell parsing test coverage, including mutation detection and path extraction scenarios.
  • Chores

    • Added a new dependency to support improved shell script parsing capabilities.

Walkthrough

Adds mvdan.cc/sh/v3 as a dependency and rewrites shell command mutation detection and path extraction in internal/compaction/file_operations.go to use AST parsing and expand.Fields instead of regex/token heuristics. Updates compaction tests accordingly. Also parameterizes the diff section header label in internal/terminal/tool_blocks.go.

Changes

Shell AST-Based Compaction Parsing

Layer / File(s) Summary
Dependency and import wiring
go.mod, internal/compaction/file_operations.go
Adds mvdan.cc/sh/v3 v3.13.1 to go.mod, updates imports to include expand and syntax packages, and removes the shellPathTokenPattern regexp global.
AST-based mutation detection
internal/compaction/file_operations.go
Rewrites shellCommandLooksMutating to parse commands and walk the AST via syntax.Walk, adds shellRedirectWrites for redirect classification, and replaces the sed/perl in-place edit heuristic with static field expansion over AST words.
AST-based path extraction
internal/compaction/file_operations.go
Replaces shellCommandPathTokens with an AST-driven implementation, adds parsing and path-collection helpers traversing call expressions and redirects, introduces singleShellStaticField/shellPathFields/shellStaticFields via expand.Fields, and updates looksLikeShellPath with direct string-prefix rules.
Updated compaction tests
internal/compaction/file_operations_internal_test.go
Adds compactFileOperationTestGuidePath constant, adjusts bash-tool mutation assertions in TestCollectCompactionFileOperations, and replaces TestShellCommandLooksMutating with TestShellCommandParsing covering path tokens and mutating classification across diverse shell patterns.

Terminal Section Label Parameterization

Layer / File(s) Summary
Parameterized diff section header and test fix
internal/terminal/tool_blocks.go, internal/terminal/tool_display_internal_test.go
toolDiffLines passes "diff" to styledSectionLines, which now appends ":" dynamically. TestRenderExpandedToolDisplayPrettyPrintsArguments explicitly sets display.Name = testToolBash.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 No more regex tricks for me,
I parse the shell AST with glee!
Each cp, mv, sed -i in line—
The syntax tree makes detection fine.
With expand.Fields and a bash walk,
This bunny's done with tokenized talk! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether meaningful information about the changeset was communicated. Add a detailed description explaining the motivation, approach, and impact of the shell command parsing refactoring.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat/cmd-parsing' is related to the main change in the PR—refactoring shell command parsing logic to use AST parsing instead of regex heuristics.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 feat/cmd-parsing

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

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.80952% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.38%. Comparing base (33893c2) to head (29f631b).

Files with missing lines Patch % Lines
internal/compaction/file_operations.go 83.33% 9 Missing and 8 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #142   +/-   ##
=======================================
  Coverage   80.38%   80.38%           
=======================================
  Files         277      277           
  Lines       21838    21913   +75     
=======================================
+ Hits        17554    17615   +61     
- Misses       3075     3082    +7     
- Partials     1209     1216    +7     
Flag Coverage Δ
unittests 80.38% <83.80%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@internal/compaction/file_operations.go`:
- Around line 285-287: The in-place flag detection in the ContainsFunc closure
is too restrictive. Currently, it checks for `-i` exactly or flags starting with
`-i.`, but this misses valid formats like `-ibak` (without a dot). Broaden the
detection by changing the strings.HasPrefix check from "-i." to "-i" so that it
matches all valid in-place editing flag variations including `-ibak`,
`-ibak.bak`, and similar formats.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fc2b432c-fed6-4e9f-a804-57f7dde1c03b

📥 Commits

Reviewing files that changed from the base of the PR and between 33893c2 and 5cb8f9c.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • go.mod
  • internal/compaction/file_operations.go
  • internal/compaction/file_operations_internal_test.go
  • internal/terminal/tool_blocks.go
  • internal/terminal/tool_display_internal_test.go

Comment thread internal/compaction/file_operations.go
@sonarqubecloud

Copy link
Copy Markdown

@omarluq omarluq merged commit d760571 into main Jun 19, 2026
17 of 20 checks passed
@omarluq omarluq deleted the feat/cmd-parsing branch June 19, 2026 21:40
@sonarqubecloud

Copy link
Copy Markdown

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