-
Notifications
You must be signed in to change notification settings - Fork 69
add grep tool formatters #1019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 07-02/pi-tool-formatter-edit
Are you sure you want to change the base?
add grep tool formatters #1019
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,6 +128,30 @@ def format_edit | |
| ok_line(@input[:path]) | ||
| end | ||
|
|
||
| # Formats a grep tool result. | ||
| # | ||
| # Content: matching lines, and possibly informational notes, one per | ||
| # line. | ||
| # | ||
| # Output: "GREP OK <n> <match|matches>[ · NOTE <notes>]" – <n> counts | ||
| # lines that look like matches (a leading path or line-number prefix); | ||
| # any remaining lines are joined into a truncated NOTE, shown only when | ||
| # there are both matches and notes. | ||
| # | ||
| # Examples: | ||
| # GREP OK 3 matches | ||
| # GREP OK 1 match | ||
| # GREP OK 0 matches | ||
| # | ||
| #: () -> String | ||
| def format_grep | ||
| lines = content.to_s.lines.map(&:strip).reject(&:empty?) | ||
| matches, notes = lines.partition { |line| line.match?(%r{\A\S+/}) || line.match?(/\A(?:\S+:)?\d+:/) } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Match/note heuristic is best-effort and will miscount.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The matching was actually done against logs on the Claude side that spanned over a hundred calls to grep! The current matching got it all right, so I actually expect this to be accurate. My suggestion is to keep this as it is and if we ever notice inaccuracies we can always follow up. What do you think? |
||
| count = matches.length | ||
| note = "NOTE #{truncate(notes.join(" "))}" if matches.any? && notes.any? | ||
| ok_line("#{count} #{"match".pluralize(count)}", note) | ||
| end | ||
|
|
||
| # Formats a result for which Roast has no dedicated formatter. | ||
| # | ||
| # Content: the tool's output text. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.