Skip to content

restructure Pi tool formatting into per-method dispatch with generic fallback#1012

Open
LasmarKhalifa wants to merge 1 commit into
mainfrom
06-30/pi-tool-formatter-foundation
Open

restructure Pi tool formatting into per-method dispatch with generic fallback#1012
LasmarKhalifa wants to merge 1 commit into
mainfrom
06-30/pi-tool-formatter-foundation

Conversation

@LasmarKhalifa

@LasmarKhalifa LasmarKhalifa commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Closes #1022

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

LasmarKhalifa commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

@LasmarKhalifa LasmarKhalifa force-pushed the 06-30/pi-tool-formatter-foundation branch from 3f04dcc to 58fc38b Compare July 3, 2026 14:50
@LasmarKhalifa LasmarKhalifa marked this pull request as ready for review July 3, 2026 16:29
Comment thread lib/roast/cogs/agent/providers/pi/messages/tool_call_message.rb

@mathiusj mathiusj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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.

Restructure Pi tool formatting into per-method dispatch with generic fallback

2 participants