Skip to content

Conversation

ugai
Copy link

@ugai ugai commented Sep 6, 2025

Description

Add comprehensive text encoding support to the file_read tool.
This allows proper handling of international text files (Japanese, Chinese, Korean, etc.) across all file reading modes.

  • Added encoding parameter to all file reading functions with utf-8 default
  • Added FILE_READ_ENCODING_DEFAULT environment variable for global configuration

Example issue:
In Japanese Windows environments, the default system encoding is CP932. When Python opens files without an explicit encoding specification, it uses this system default, which can cause UTF-8 text files to fail due to encoding errors.
This enhancement sets UTF-8 as the explicit default, preventing these common encoding failures.
Users can also override the encoding as needed via tool arguments or environment variables.

Note: This change may be slightly breaking for code that relies on the system default encoding.

Thank you!

Related Issues

Documentation PR

None (covered in docstrings).

Type of Change

Bug fix
New Tool
Breaking change
Documentation update
Other (please describe): Feature enhancement to existing tool

Testing

  • I ran hatch fmt --formatter
  • I ran hatch fmt --linter
  • I ran hatch test
  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- Add encoding parameter to all file_read plugin functions
  (default: utf-8)
- Add FILE_READ_ENCODING_DEFAULT environment variable for
  configuration

This fixes file reading errors in environments using regional character
encodings, particularly for non-English text files.
@ugai ugai marked this pull request as ready for review September 6, 2025 13:17
@ugai ugai requested a review from a team as a code owner September 6, 2025 13:17
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.

1 participant