Skip to content

feat: add comfy code-search (alias comfy cs) subcommand#386

Open
snomiao wants to merge 6 commits intomainfrom
feat/code-search
Open

feat: add comfy code-search (alias comfy cs) subcommand#386
snomiao wants to merge 6 commits intomainfrom
feat/code-search

Conversation

@snomiao
Copy link
Member

@snomiao snomiao commented Mar 25, 2026

Summary

  • Add new comfy code-search subcommand (alias comfy cs) that searches code across ComfyUI repositories via the comfy-codesearch Vercel API (Sourcegraph-backed)
  • Supports --repo / -r to filter by repository, --count / -n to limit results, and --json / -j for machine-readable output
  • Includes 33 unit tests covering query building, response parsing, error handling, and CLI integration

Usage

comfy code-search "LoadImage" # basic search comfy code-search --repo ComfyUI "LoadImage" # filter by repo comfy code-search --count 50 "class_type" # more results comfy cs --json "SaveImage" # JSON output via alias

Demo

$ comfy code-search --repo ComfyUI "SaveImage" Comfy-Org/ComfyUI / nodes.py L 1627 class SaveImage: https://github.com/Comfy-Org/ComfyUI/blob/b53b10ea.../nodes.py#L1627 L 1684 class PreviewImage(SaveImage): https://github.com/Comfy-Org/ComfyUI/blob/b53b10ea.../nodes.py#L1684 L 2055 "SaveImage": SaveImage, https://github.com/Comfy-Org/ComfyUI/blob/b53b10ea.../nodes.py#L2055 Comfy-Org/ComfyUI_frontend / src/constants/essentialsNodes.ts L 12 SaveImage: 'icon-s1.3-[lucide--image-down]', https://github.com/Comfy-Org/ComfyUI_frontend/blob/a44fa1fd.../essentialsNodes.ts#L12 Comfy-Org/ComfyUI / comfy_extras/nodes_dataset.py L 204 class SaveImageDataSetToFolderNode(io.ComfyNode): https://github.com/Comfy-Org/ComfyUI/blob/b53b10ea.../nodes_dataset.py#L204 Comfy-Org/ComfyUI / custom_nodes/websocket_image_save.py L 13 class SaveImageWebsocket: https://github.com/Comfy-Org/ComfyUI/blob/b53b10ea.../websocket_image_save.py#L13 ... 30+ approximate results, 30 matches returned (limit hit — use --count to fetch more) 

Test plan

  • All 33 new tests pass (pytest tests/comfy_cli/command/test_code_search.py)
  • Manual test: comfy code-search "LoadImage" returns results
  • Manual test: comfy cs "LoadImage" alias works
  • Manual test: comfy code-search --json "LoadImage" outputs valid JSON
  • Manual test: comfy code-search --repo ComfyUI "SaveImage" filters correctly

🤖 Generated with Claude Code

Integrate with the comfy-codesearch Vercel API to search code across ComfyUI repositories powered by Sourcegraph. Supports repo filtering, result count limits, and JSON output. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 25, 2026 04:53
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. enhancement New feature or request labels Mar 25, 2026
@codecov
Copy link

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@ Coverage Diff @@ ## main #386 +/- ## ========================================== + Coverage 67.04% 67.87% +0.83%  ========================================== Files 33 34 +1 Lines 3711 3807 +96 ========================================== + Hits 2488 2584 +96  Misses 1223 1223 
Files with missing lines Coverage Δ
comfy_cli/cmdline.py 58.33% <100.00%> (+0.33%) ⬆️
comfy_cli/command/code_search.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new comfy code-search CLI subcommand (with hidden alias comfy cs) that queries the comfy-codesearch (Sourcegraph-backed) API and prints either human-friendly Rich output or JSON for machine consumption.

Changes:

  • Introduce comfy_cli/command/code_search.py implementing query building, API fetch, result normalization, stats extraction, and output rendering.
  • Register the new code-search and cs commands in the main CLI app.
  • Add a comprehensive new unit test module covering query building, parsing, error handling, and Typer CLI invocation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
comfy_cli/command/code_search.py New Typer subcommand for code search; includes API interaction, formatting, and error handling.
comfy_cli/cmdline.py Wires the new subcommand into the top-level CLI (plus hidden alias).
tests/comfy_cli/command/test_code_search.py New test suite validating query construction, formatting/stats parsing, error handling, and CLI behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

snomiao and others added 2 commits March 25, 2026 13:57
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Address Copilot review: e.response can be None for some HTTPError cases. Fall back to "unknown" status instead of raising AttributeError. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Move `import json` to top-level (no reason to lazy-import stdlib) - Rename `json` parameter to `json_output` to avoid shadowing builtin - Hoist URL base string outside inner match loop - Remove redundant docstrings on self-explanatory private functions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +104 to +108

if not results:
console.print("[yellow]No results found.[/yellow]")
return

Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

In --json mode, using Rich console.print() to emit the JSON string can break machine-readable output (Rich may wrap long lines based on terminal width, and any inserted line breaks inside long string values like URLs will produce invalid JSON). Prefer writing directly to stdout without Rich rendering (e.g., typer.echo(...) / print(...)), or explicitly disable wrapping/markup/highlighting when printing the JSON payload.

Copilot uses AI. Check for mistakes.
…alue Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:XL This PR changes 500-999 lines, ignoring generated files.

2 participants