Skip to content

Conversation

@PiotrCzapla
Copy link

While using solveit, I noticed create("~/memo.md") was creating a file literally named ~ rather than expanding to the home directory. view already had expanduser().resolve(), but the other tools (create, insert, str_replace, replace_lines, move_lines) didn't.
Rather than adding expanduser().resolve() to each function individually, I've added a helper and wrapped replace_lines/move_lines in try/except for consistent error handling. Also switched from if not ... return to assert.

Let me know what you think.

@PiotrCzapla
Copy link
Author

@jph00 could you have a look?

Copy link
Contributor

@jph00 jph00 left a comment

Choose a reason for hiding this comment

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

Looks great. Just some minor suggestions.

lines[dest_line-1:dest_line-1] = chunk
p.write_text('\n'.join(lines) + '\n')
return f"Moved lines {start_line}-{end_line} to line {dest_line}"
except Exception as e: return f'Error: {str(e)}'
Copy link
Contributor

Choose a reason for hiding this comment

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

The assertion errors have sufficient info in their descriptions, but other errors perhaps need to type info too?

Suggested change
except Exception as e: return f'Error: {str(e)}'
except AssertionError as e: return f'Error: {str(e)}'
except Exception as e: return f'Error: {repr(e)}'

content[start_line-1:end_line] = [new_content]
p.write_text(''.join(content))
return f"Replaced lines {start_line} to {end_line}."
except Exception as e: return f'Error replacing lines: {str(e)}'
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't match the pattern "Error: " any more, which will break API clients relying on it. (Which I assume would be most clients - IIRC that's the pattern we use for indicating an error.)

Suggested change
except Exception as e: return f'Error replacing lines: {str(e)}'
except Exception as e: return f'Error: {repr(e)}'

Copy link
Author

Choose a reason for hiding this comment

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

Which downstream API are you referring to? Are we expecting these tools to be composed or used in places other than the LLM? I’d love to understand more about how you see the error strings being accessed?

@jph00
Copy link
Contributor

jph00 commented Jan 14, 2026

I'm gonna make those minor changes at my end, since I need this PR for what I'm doing now. :D

@jph00 jph00 merged commit 2c84c09 into AnswerDotAI:main Jan 14, 2026
18 of 28 checks passed
@PiotrCzapla
Copy link
Author

@jph00 Thank you for the megre and comments. I'm going to find a better way of getting notified about GitHub.

I've noticed you haven't applied the changes yet so here is a new PR#745 that applies your suggestion partially.

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.

2 participants