Skip to content

Comments

refactor(core): extract streamio and decoder sub-packages, eliminate util.go#504

Merged
apstndb merged 2 commits intomainfrom
refactor/extract-streamio-decoder-eliminate-util
Feb 22, 2026
Merged

refactor(core): extract streamio and decoder sub-packages, eliminate util.go#504
apstndb merged 2 commits intomainfrom
refactor/extract-streamio-decoder-eliminate-util

Conversation

@apstndb
Copy link
Owner

@apstndb apstndb commented Feb 22, 2026

Summary

  • Eliminate util.go: Move path helpers to system_variables.go, inline instanceOf, replace ToSortFunc with cmp.Compare, move toRow/sliceOf to statement_processing.go
  • Extract streamio/ sub-package: Move StreamManager and its tests to internal/mycli/streamio/ as a zero-dependency I/O multiplexer (stdlib + golang.org/x/term only)
  • Extract decoder/ sub-package: Move proto/spanner value formatting to internal/mycli/decoder/ with exported FormatConfigWithProto, FormatTypeSimple, FormatTypeVerbose

Based on go-filedeps analysis: reduces file count and intra-package edges in internal/mycli/.

Test plan

  • make check passes (test + lint + fmt-check)
  • New streamio and decoder sub-packages have their own passing tests
  • No behavioral changes — purely structural refactoring

🤖 Generated with Claude Code

…util.go

- Eliminate util.go: move path helpers to system_variables.go, inline
  instanceOf, replace ToSortFunc with cmp.Compare, move toRow/sliceOf
  to statement_processing.go
- Extract streamio/ sub-package: move StreamManager and its tests to
  internal/mycli/streamio/ as a zero-dependency I/O multiplexer
- Extract decoder/ sub-package: move proto/spanner value formatting to
  internal/mycli/decoder/ with exported FormatConfigWithProto,
  FormatTypeSimple, FormatTypeVerbose

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @apstndb, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request undertakes a significant refactoring of the core internal/mycli package, primarily by extracting two new, focused sub-packages: streamio for I/O management and decoder for Spanner value formatting. This reorganization aims to reduce the overall file count and decrease intra-package dependencies within internal/mycli, leading to a cleaner, more maintainable, and less coupled codebase. Additionally, a general utility file (util.go) has been eliminated by relocating its functions to more appropriate contexts or replacing them with standard library alternatives.

Highlights

  • Stream I/O Sub-package Extraction: The StreamManager and its related test files have been moved into a new internal/mycli/streamio sub-package, enhancing modularity for I/O multiplexing.
  • Decoder Sub-package Extraction: Proto and Spanner value formatting logic, including FormatConfigWithProto, FormatTypeSimple, and FormatTypeVerbose, has been extracted into a new internal/mycli/decoder sub-package.
  • Elimination of util.go: The util.go file has been removed, with its functionalities redistributed: path helpers moved to system_variables.go, instanceOf inlined, ToSortFunc replaced with cmp.Compare, and toRow/sliceOf moved to statement_processing.go.
Changelog
  • internal/mycli/app.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/cli_current_width_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/cli_output.go
    • Imported the new decoder package.
    • Updated calls to formatTypeSimple to use decoder.FormatTypeSimple.
  • internal/mycli/cli_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/decoder/decoder.go
    • Renamed from internal/mycli/decoder.go.
    • Updated package declaration to decoder.
    • Exported formatConfigWithProto as FormatConfigWithProto.
    • Exported formatTypeSimple as FormatTypeSimple.
    • Exported formatTypeVerbose as FormatTypeVerbose.
  • internal/mycli/decoder/decoder_test.go
    • Renamed from internal/mycli/decoder_test.go.
    • Updated package declaration to decoder.
    • Updated calls to use the newly exported functions FormatConfigWithProto and FormatTypeVerbose.
  • internal/mycli/execute_sql.go
    • Imported the new decoder package.
    • Updated calls to formatConfigWithProto to use decoder.FormatConfigWithProto.
  • internal/mycli/integration_dump_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/integration_mcp_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/integration_meta_command_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/integration_source_echo_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/integration_sql_export_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/integration_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/meta_commands_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/screen_width_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/screen_width_vty_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/session.go
    • Imported the new decoder package.
    • Updated calls to formatConfigWithProto to use decoder.FormatConfigWithProto.
  • internal/mycli/statement_processing.go
    • Moved toRow and sliceOf functions from util.go.
    • Replaced instanceOf with a direct type assertion for *ast.CreateDatabase.
  • internal/mycli/statements_explain_describe.go
    • Imported the new decoder package.
    • Updated calls to formatTypeVerbose to use decoder.FormatTypeVerbose.
  • internal/mycli/statements_params.go
    • Imported the cmp package.
    • Replaced ToSortFunc with an anonymous function utilizing cmp.Compare.
  • internal/mycli/statements_schema.go
    • Imported the new decoder package.
    • Updated calls to formatConfigWithProto to use decoder.FormatConfigWithProto.
  • internal/mycli/statements_system_variable.go
    • Imported the cmp package.
    • Replaced ToSortFunc with an anonymous function utilizing cmp.Compare.
  • internal/mycli/streamio/stream_manager.go
    • Renamed from internal/mycli/stream_manager.go.
    • Updated package declaration to streamio.
  • internal/mycli/streamio/stream_manager_edge_test.go
    • Renamed from internal/mycli/stream_manager_edge_test.go.
    • Updated package declaration to streamio.
  • internal/mycli/streamio/stream_manager_fifo_test.go
    • Renamed from internal/mycli/stream_manager_fifo_test.go.
    • Updated package declaration to streamio.
  • internal/mycli/streamio/stream_manager_terminal_test.go
    • Renamed from internal/mycli/stream_manager_terminal_test.go.
    • Updated package declaration to streamio.
  • internal/mycli/streamio/stream_manager_test.go
    • Renamed from internal/mycli/stream_manager_test.go.
    • Updated package declaration to streamio.
  • internal/mycli/system_variables.go
    • Imported the new streamio package.
    • Updated the type of StreamManager field to *streamio.StreamManager.
    • Moved projectPath, instancePath, and databasePath functions from util.go.
  • internal/mycli/util.go
    • Removed the file.
Activity
  • The pull request was created by apstndb.
  • The author has confirmed that make check passes, new sub-packages have their own passing tests, and no behavioral changes were introduced, indicating a successful structural refactoring.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link

github-actions bot commented Feb 22, 2026

Code Metrics Report

📊 View detailed coverage report (available for 7 days)

main (d333001) #504 (9a013d2) +/-
Coverage 69.9% 69.9% -0.1%
Code to Test Ratio 1:1.2 1:1.2 +0.0
Test Execution Time 1m18s 1m21s +3s
Details
  |                     | main (d333001) | #504 (9a013d2) |  +/-  |
  |---------------------|----------------|----------------|-------|
- | Coverage            |          69.9% |          69.9% | -0.1% |
  |   Files             |             55 |             54 |    -1 |
  |   Lines             |           5712 |           5704 |    -8 |
- |   Covered           |           3997 |           3990 |    -7 |
+ | Code to Test Ratio  |          1:1.2 |          1:1.2 |  +0.0 |
  |   Code              |          13131 |          13118 |   -13 |
+ |   Test              |          16499 |          16510 |   +11 |
- | Test Execution Time |          1m18s |          1m21s |   +3s |

Code coverage of files in pull request scope (73.9% → 73.9%)

Files Coverage +/- Status
internal/mycli/app.go 65.4% 0.0% modified
internal/mycli/cli_output.go 82.0% 0.0% modified
internal/mycli/decoder.go 0.0% -82.5% affected
internal/mycli/decoder/decoder.go 82.5% +82.5% renamed
internal/mycli/execute_sql.go 73.1% 0.0% modified
internal/mycli/session.go 73.2% 0.0% modified
internal/mycli/statement_processing.go 84.3% +0.2% modified
internal/mycli/statements_explain_describe.go 61.6% 0.0% modified
internal/mycli/statements_params.go 80.0% 0.0% modified
internal/mycli/statements_schema.go 78.0% 0.0% modified
internal/mycli/statements_system_variable.go 84.3% 0.0% modified
internal/mycli/stream_manager.go 0.0% -86.5% affected
internal/mycli/streamio/stream_manager.go 86.4% +86.4% renamed
internal/mycli/system_variables.go 95.0% +0.1% modified
internal/mycli/util.go 0.0% -92.4% removed

Reported by octocov

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request is a significant structural refactoring that extracts streamio and decoder logic into their own sub-packages and eliminates the util.go file. The changes are well-organized and improve the project's modularity by creating clearer boundaries for I/O management and data decoding. The inlining of utility functions and replacement of custom helpers with standard library features (like cmp.Compare) are good simplifications. My review focuses on ensuring the newly created public APIs are well-documented as per the repository's style guide.

Address review feedback: add documentation comment to the newly
exported FormatConfigWithProto function in the decoder package.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@apstndb
Copy link
Owner Author

apstndb commented Feb 22, 2026

/gemini summary

@apstndb
Copy link
Owner Author

apstndb commented Feb 22, 2026

/gemini review

@gemini-code-assist
Copy link
Contributor

Summary of Changes

This pull request significantly refactors the core internal/mycli package by extracting specialized functionalities into new, independent sub-packages for stream I/O management and Spanner value decoding. This structural reorganization aims to enhance modularity, reduce inter-package dependencies, and streamline the codebase by eliminating a general utility file and relocating its functions to more appropriate contexts.

Highlights

  • Elimination of util.go: The util.go file has been removed, with its path helpers moved to system_variables.go, instanceOf inlined, ToSortFunc replaced with cmp.Compare, and toRow/sliceOf moved to statement_processing.go.
  • Extraction of streamio/ sub-package: The StreamManager and its associated tests have been relocated to a new internal/mycli/streamio/ sub-package, serving as a zero-dependency I/O multiplexer.
  • Extraction of decoder/ sub-package: Proto and Spanner value formatting logic, including FormatConfigWithProto, FormatTypeSimple, and FormatTypeVerbose, has been moved to a new internal/mycli/decoder/ sub-package.
Changelog
  • internal/mycli/app.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/cli_current_width_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/cli_output.go
    • Imported the new decoder package.
    • Updated calls to formatTypeSimple to use decoder.FormatTypeSimple.
  • internal/mycli/cli_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/decoder/decoder.go
    • Renamed from internal/mycli/decoder.go.
    • Updated package declaration to decoder.
    • Exported formatConfigWithProto as FormatConfigWithProto.
    • Exported formatTypeSimple as FormatTypeSimple.
    • Exported formatTypeVerbose as FormatTypeVerbose.
  • internal/mycli/decoder/decoder_test.go
    • Renamed from internal/mycli/decoder_test.go.
    • Updated package declaration to decoder.
    • Updated calls to use the newly exported functions FormatConfigWithProto and FormatTypeVerbose.
  • internal/mycli/execute_sql.go
    • Imported the new decoder package.
    • Updated calls to formatConfigWithProto to use decoder.FormatConfigWithProto.
  • internal/mycli/integration_dump_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/integration_mcp_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/integration_meta_command_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/integration_source_echo_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/integration_sql_export_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/integration_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/meta_commands_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/screen_width_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/screen_width_vty_test.go
    • Imported the new streamio package.
    • Updated calls to NewStreamManager to use streamio.NewStreamManager.
  • internal/mycli/session.go
    • Imported the new decoder package.
    • Updated calls to formatConfigWithProto to use decoder.FormatConfigWithProto.
  • internal/mycli/statement_processing.go
    • Moved toRow and sliceOf functions from util.go.
    • Replaced instanceOf with a direct type assertion for *ast.CreateDatabase.
  • internal/mycli/statements_explain_describe.go
    • Imported the new decoder package.
    • Updated calls to formatTypeVerbose to use decoder.FormatTypeVerbose.
  • internal/mycli/statements_params.go
    • Imported the cmp package.
    • Replaced ToSortFunc with an anonymous function utilizing cmp.Compare.
  • internal/mycli/statements_schema.go
    • Imported the new decoder package.
    • Updated calls to formatConfigWithProto to use decoder.FormatConfigWithProto.
  • internal/mycli/statements_system_variable.go
    • Imported the cmp package.
    • Replaced ToSortFunc with an anonymous function utilizing cmp.Compare.
  • internal/mycli/streamio/stream_manager.go
    • Renamed from internal/mycli/stream_manager.go.
    • Updated package declaration to streamio.
  • internal/mycli/streamio/stream_manager_edge_test.go
    • Renamed from internal/mycli/stream_manager_edge_test.go.
    • Updated package declaration to streamio.
  • internal/mycli/streamio/stream_manager_fifo_test.go
    • Renamed from internal/mycli/stream_manager_fifo_test.go.
    • Updated package declaration to streamio.
  • internal/mycli/streamio/stream_manager_terminal_test.go
    • Renamed from internal/mycli/stream_manager_terminal_test.go.
    • Updated package declaration to streamio.
  • internal/mycli/streamio/stream_manager_test.go
    • Renamed from internal/mycli/stream_manager_test.go.
    • Updated package declaration to streamio.
  • internal/mycli/system_variables.go
    • Imported the new streamio package.
    • Updated the type of StreamManager field to *streamio.StreamManager.
    • Moved projectPath, instancePath, and databasePath functions from util.go.
  • internal/mycli/util.go
    • Removed the file.
Activity
  • Gemini Code Assist provided an initial summary of the changes, highlighting the extraction of streamio and decoder sub-packages and the elimination of util.go.
  • A Code Metrics Report was posted by github-actions[bot], showing minor changes in coverage and test execution time, with a reduction in files and lines of code.
  • The author, apstndb, requested a summary and then a review from Gemini.
  • Gemini Code Assist provided a review comment suggesting documentation for the newly exported FormatConfigWithProto function in internal/mycli/decoder/decoder.go, citing the repository's style guide.
  • The author, apstndb, acknowledged Gemini's feedback and confirmed the fix in commit 251abd3.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request performs a significant structural refactoring by extracting streamio and decoder sub-packages and eliminating util.go. The changes generally improve modularity and reduce intra-package dependencies. I have identified one critical issue in the decoder package where an unknown enum value could cause a nil pointer dereference and panic during result formatting. While addressing critical behavioral issues in a structural refactoring PR can sometimes conflict with our guideline to separate such changes, the proposed fix correctly uses a guard condition to prevent the panic, aligning with our error handling practices. Other changes, including the new StreamManager implementation and the migration of utility functions, appear correct and follow the project's Go 1.25 standards and concurrency guidelines.

@apstndb apstndb merged commit 0c76571 into main Feb 22, 2026
2 checks passed
@apstndb apstndb deleted the refactor/extract-streamio-decoder-eliminate-util branch February 22, 2026 06:19
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