Skip to content

Run pre-av-sync hook with tty#601

Merged
aviator-app[bot] merged 1 commit intomasterfrom
git_exec_interactive
Sep 30, 2025
Merged

Run pre-av-sync hook with tty#601
aviator-app[bot] merged 1 commit intomasterfrom
git_exec_interactive

Conversation

@draftcode
Copy link
Copy Markdown
Collaborator

@draftcode draftcode commented Sep 25, 2025

Previously the hook was executed while av having a control on tty. This
means that the hook cannot be interactive. This commit changes the hook
execution to be done with bubbletea's ExecProcess, which allows the
hook to take over the underlying tty. This allows users to create
interactive hook, which was not possible before.

There was a try-and-error on the visual of the hook execution. Details
are written in the comment of preAvSyncHookModel.View(). This will not
change anything if there is no pre-av-sync hook. If there is a hook, it
will show a pre-av-sync hook status shown in the sync view.

@draftcode draftcode requested a review from a team as a code owner September 25, 2025 10:14
@aviator-app
Copy link
Copy Markdown
Contributor

aviator-app bot commented Sep 25, 2025

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This PR was merged using Aviator.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

@aviator-app
Copy link
Copy Markdown
Contributor

aviator-app bot commented Sep 25, 2025

✅ FlexReview Status

Common Owner: aviator-co/engineering (expert-load-balance assignment)
Owner and Assignment:

  • aviator-co/engineering (expert-load-balance assignment)
    Owned Files
    • cmd/av/sync.go
    • internal/git/git.go
    CODEOWNERS Required Files
    • cmd/av/sync.go
    • internal/git/git.go

Review SLO: 7 business hours if PR size is <= 200 LOC for the first response.

@aviator-app aviator-app bot requested a review from simsinght September 25, 2025 10:14
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @draftcode, 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 significantly enhances the av sync command by enabling interactive pre-av-sync hooks. Previously, these hooks were limited to non-interactive operations. By leveraging bubbletea's ExecProcess, the system now allows pre-av-sync hooks to take full control of the terminal, opening up possibilities for more dynamic and user-engaging pre-sync actions. The changes also include a dedicated UI component to display the hook's status and a refactoring of the underlying Git command execution logic to support this new interactive capability.

Highlights

  • Interactive pre-av-sync Hooks: The av sync command now supports interactive pre-av-sync hooks by allowing them to take over the terminal's TTY, enabling more dynamic user interactions.
  • Bubbletea Integration: Interactive hook execution is facilitated by using bubbletea's ExecProcess function, which grants the hook control over the underlying TTY.
  • Dedicated Hook UI Model: A new preAvSyncHookModel has been introduced to manage the lifecycle and display the status of the pre-av-sync hook within the av sync UI.
  • Refactored Git Command Execution: The git.Run method was refactored to separate command creation (git.Cmd) from execution, allowing for more flexible command handling, specifically for tea.ExecProcess.
  • Improved UI Handling: The syncViewModel now dynamically adds and manages sub-models, and its View method filters out empty views for a cleaner display.
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.

Copy link
Copy Markdown

@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 introduces a significant improvement by allowing pre-av-sync hooks to be interactive. The use of bubbletea.ExecProcess to give the hook TTY control is a solid approach. The implementation is well-structured, with a new preAvSyncHookModel to manage the hook's lifecycle, and the code includes excellent comments explaining the design choices. The refactoring in internal/git/git.go to extract a Cmd function is a good enhancement for code reuse. I have one high-severity suggestion regarding context propagation to prevent orphaned processes, which is particularly important for interactive commands like this.

return uiutils.ErrCmd(err)
}
m.hasHook = true
cmd := m.repo.Cmd(context.Background(), []string{"hook", "run", "--ignore-missing", "pre-av-sync"}, nil)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using context.Background() here can lead to the interactive hook process being orphaned if the user cancels the av sync command (e.g., with Ctrl+C). This could leave the user's terminal in an inconsistent state.

To fix this, you should propagate the context from the cobra command all the way down to here. This will ensure that if the main process is cancelled, the hook process is also terminated.

Here are the suggested steps:

  1. Add a ctx context.Context field to the syncViewModel struct.
  2. In the syncCmd.RunE function, pass cmd.Context() when creating the syncViewModel.
  3. Add a ctx context.Context field to preAvSyncHookModel and accept it as an argument in newPreAvSyncHookModel.
  4. In initSync, pass vm.ctx when calling newPreAvSyncHookModel.
  5. Finally, use m.ctx here instead of context.Background().

This change would also allow you to replace other instances of context.Background() in syncViewModel methods, improving the robustness of the command.

Base automatically changed from package_as_model to master September 29, 2025 01:37
@aviator-app
Copy link
Copy Markdown
Contributor

aviator-app bot commented Sep 29, 2025

This PR is stacked on top of #600 which was merged. This PR (and its dependents) need to be synchronized on the commit that was merged into master. From your repository, run the following commands:

# Switch to this branch
git checkout git_exec_interactive
# Sync this branch (and its children) on top of the merge commit
av sync

Previously the hook was executed while av having a control on tty. This
means that the hook cannot be interactive. This commit changes the hook
execution to be done with bubbletea's ExecProcess, which allows the
hook to take over the underlying tty. This allows users to create
interactive hook, which was not possible before.

There was a try-and-error on the visual of the hook execution. Details
are written in the comment of preAvSyncHookModel.View(). This will not
change anything if there is no pre-av-sync hook. If there is a hook, it
will show a pre-av-sync hook status shown in the sync view.
@aviator-app aviator-app bot merged commit ea50a0b into master Sep 30, 2025
5 checks passed
@aviator-app aviator-app bot deleted the git_exec_interactive branch September 30, 2025 03:07
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