restructure Pi tool formatting into per-method dispatch with generic fallback#1012
restructure Pi tool formatting into per-method dispatch with generic fallback#1012LasmarKhalifa wants to merge 1 commit into
Conversation
2390b15 to
3f04dcc
Compare
3f04dcc to
58fc38b
Compare
mathiusj
left a comment
There was a problem hiding this comment.
Foundation looks clean — per-method dispatch with respond_to?(..., true) and a generic fallback reads well, and the test rewrite is a nice tightening. A few things to consider before the whole stack lands on top of this.
| format_unknown | ||
| end | ||
|
|
||
| # Truncate long formatted tool-call strings to keep terminal output to generally one line, accounting for logger prefixing. |
There was a problem hiding this comment.
Line-length contract vs. what the code enforces. This comment (and its result-side twin) says the goal is to "keep terminal output to generally one line," but TRUNCATE_LIMIT only bounds individual values, not the composed line. format_unknown joins every argument (each truncated to 45) with no cap on the number of args, so N args → up to ~45·N chars. Downstream, format_grep appends an untruncated path + glob + limit. Either truncate the final composed string, or soften the wording to "each value" so the comment doesn't overpromise a bound the code doesn't keep.
| # DEPLOY | ||
| # | ||
| #: () -> String | ||
| def format_unknown |
There was a problem hiding this comment.
Robustness: dispatch trusts arguments is a well-formed Hash. format_unknown calls arguments.empty?/.map, and downstream formatters do arguments.values_at(...) / arguments[:edits].length. If Pi ever sends a non-Hash (or nil) arguments, or a formatter's typed assumption is violated (e.g. :edits as a String), dispatch raises inside the progress logger. Since this is display-only, the highest-leverage fix lives here in the foundation: wrap the send(format_method_name) in a rescue that falls back to format_unknown. That protects all 7 downstream PRs at once and means per-tool reviewers don't have to scrutinize each formatter's arg assumptions. (Normalizing @arguments to {} when non-Hash in initialize is a cheap complement.)
| # READ ERROR ENOENT: no such file or directory | ||
| # | ||
| #: () -> String | ||
| def error_line |
There was a problem hiding this comment.
Minor: the outer .strip here only does anything when content is blank (trimming the trailing space after ERROR). Harmless, just slightly redundant given content.to_s.strip is already stripped. Could special-case blank content instead, but not worth churn.

Closes #1022
Builds the foundation for the stack by replacing the current tool formatter routing to a per-method dispatch.