Skip to content

Conversation

gveres
Copy link
Contributor

@gveres gveres commented Oct 2, 2025

See #109

Summary by CodeRabbit

  • Bug Fixes
    • Improved nREPL port detection by prioritizing explicit server startup messages, reducing false positives when auto-connecting.
    • Continued support for several common log formats to ensure ports are still discovered in typical setups.
    • Narrower matching rules may change behavior for some rare or custom log outputs but increase overall connection reliability.

Copy link

coderabbitai bot commented Oct 2, 2025

Walkthrough

Replaced broad, case-insensitive nREPL port-detection regex with a specific matcher for "nREPL server started on port\s{1,10}(\d+)"; removed other generic patterns while retaining explicit 4–5 digit extraction patterns like :(\d{4,5}), Started.*?(\d{4,5}), and Listening.*?(\d{4,5}). Error/validation unchanged.

Changes

Cohort / File(s) Summary of Changes
nREPL port parsing patterns
src/clojure_mcp/nrepl_launcher.clj
Replaced generic, case-insensitive port-detection regex with a specific nREPL server started on port\s{1,10}(\d+) matcher; removed prior generic patterns; retained additional explicit patterns for 4–5 digit ports: ":(\d{4,5})", "Started.*?(\d{4,5})", "Listening.*?(\d{4,5})". Error handling and port validation preserved.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Launcher as nREPL Launcher
  participant Proc as Clojure Process
  participant Parser as Port Parser

  User->>Launcher: start()
  Launcher->>Proc: spawn nREPL process
  Proc-->>Launcher: stdout/stderr lines
  Launcher->>Parser: parse(line)
  alt matches specific "nREPL server started on port" or explicit 4–5 digit patterns
    Note over Parser: Primary: /nREPL server started on port\s{1,10}(\d+)/\nFallbacks: /:(\d{4,5})/, /Started.*?(\d{4,5})/, /Listening.*?(\d{4,5})/
    Parser-->>Launcher: port number
    Launcher-->>User: return connected client
  else no match (generic pattern removed)
    Parser-->>Launcher: no port
    Launcher-->>Proc: continue reading output
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

I nibble logs where digits play,
"nREPL started" shows the way.
One clear pattern, snug and neat,
Replaced the chase of every beat.
Hooray — the port is found today! 🐇🔌

Pre-merge checks and finishing touches

✅ 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 clearly describes the main change—tightening the port‐parsing pattern—while referencing the related issue, making it a concise, single‐sentence summary of the pull request’s primary purpose.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 31258b8 and 8871321.

📒 Files selected for processing (1)
  • src/clojure_mcp/nrepl_launcher.clj (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/clojure_mcp/nrepl_launcher.clj

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.

❤️ Share

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

@bhauman
Copy link
Owner

bhauman commented Oct 2, 2025

Man all these regexes could be tighter... ^\d+ is pretty lax. I think it should be \s{1, 10}. What do you think?

@hugoduncan

@bhauman bhauman assigned Copilot and unassigned Copilot Oct 2, 2025
@gveres
Copy link
Contributor Author

gveres commented Oct 3, 2025

How about making it configurable and leave it to the user.
{:start-nrepl
{:cmd ["clojure" "whatev"]
:startup-delay 10
:port-file "myproject/.nrepl-port"}}

or

{:start-nrepl
{:cmd ["clojure" "whatev"]
:output-parsing-regex #"whatever" }}

Or something along those lines? A bit less plug'n'play, but gives control to users. Could also combine with existing default parsing behavior...

Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd9a2f5 and 31258b8.

📒 Files selected for processing (1)
  • src/clojure_mcp/nrepl_launcher.clj (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.{clj,cljc}

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.{clj,cljc}: Use :require with ns aliases for imports (e.g., [clojure.string :as string])
Include clear tool :description for LLM guidance
Validate inputs and provide helpful error messages in MCP tools
Return structured data with both result and error status in MCP tools
Maintain atom-based state for consistent service access in MCP tools

Files:

  • src/clojure_mcp/nrepl_launcher.clj
**/*.{clj,cljc}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{clj,cljc}: Use kebab-case for vars/functions; end predicates with ? (e.g., is-top-level-form?)
Use try/catch with specific exception handling; use atom for tracking errors
Use 2-space indentation and maintain whitespace in edited forms
Align namespaces with directory structure (e.g., clojure-mcp.repl-tools)

Files:

  • src/clojure_mcp/nrepl_launcher.clj
🧠 Learnings (1)
📚 Learning: 2025-08-18T00:39:24.837Z
Learnt from: hugoduncan
PR: bhauman/clojure-mcp#86
File: src/clojure_mcp/subprocess.clj:0-0
Timestamp: 2025-08-18T00:39:24.837Z
Learning: In the clojure-mcp project, the user prefers to only parse stdout for nREPL port discovery in the subprocess.clj module, and explicitly does not want to parse stderr for port information.

Applied to files:

  • src/clojure_mcp/nrepl_launcher.clj
🔇 Additional comments (1)
src/clojure_mcp/nrepl_launcher.clj (1)

20-22: Patterns passed initial false-positive tests but still need full verification.

We ran these regexes against common non-port log entries (e.g., “Started batch job 45000”, “Listening to 30000 events”) and observed no matches. However, please validate against your complete logs and consider tightening each pattern with more context (for example, #"Listening on port (\d{4,5})\b") or adopting the configurable parsing approach suggested by @gveres.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@bhauman
Copy link
Owner

bhauman commented Oct 5, 2025

Thanks for starting this work @gveres! I've created PR #113 which builds on your changes with some additional improvements:

  • Added case-insensitive matching to all patterns
  • Used bounded whitespace \s{1,10} for more predictable matching
  • Added a regression test for the FlowStorm output
  • Added you as a co-author

The new patterns pass all existing tests while preventing the FlowStorm false positive. Feel free to review #113 and let me know if you have any feedback!

@bhauman
Copy link
Owner

bhauman commented Oct 5, 2025

Closing this PR in favor of #113 which includes these changes plus additional improvements. Thank you for the initial work on this issue!

@bhauman bhauman closed this Oct 5, 2025
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.

3 participants