Skip to content

refactor(haru): use hooks, loading spinner, dotenv manage#28

Merged
kwaa merged 3 commits intomainfrom
refactor/haru
Feb 21, 2026
Merged

refactor(haru): use hooks, loading spinner, dotenv manage#28
kwaa merged 3 commits intomainfrom
refactor/haru

Conversation

@kwaa
Copy link
Copy Markdown
Member

@kwaa kwaa commented Feb 21, 2026

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @kwaa, 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 refactors the haru chat application to improve its maintainability and user experience. By migrating the chat's operational logic into a dedicated React hook, the codebase becomes cleaner and more modular. The introduction of a loading spinner provides immediate visual feedback during AI processing, enhancing interactivity. Furthermore, the change in conversation ID persistence to environment variables offers a more robust and configurable setup for deployment.

Highlights

  • Refactored Chat Logic with Hooks: The core chat application logic in chat.tsx has been extracted and encapsulated into a new custom React hook, useHaru, centralizing state management and simplifying the main component.
  • Introduced Loading Spinner: A visual loading spinner (ink-spinner) has been integrated into the chat interface to provide better user feedback while AI responses are being generated.
  • Updated Conversation ID Management: The method for storing and retrieving the persistent conversation ID has been changed from a local config file (~/.config/haru/id) to using the HARU_CONVERSATION_ID environment variable, enhancing flexibility.
  • Dependency Updates: Several new dependencies were added, including @xsai/tool, ink-spinner, swr (for data fetching), temporal-polyfill (for modern date/time API), and zod (for schema validation), to support the new architecture and features.
Changelog
  • cspell.config.yaml
    • Added 'sonarjs' to the list of allowed words.
  • examples/haru/README.md
    • Updated the description of Haru's memory characteristic from 'Memory-fragile' to 'Memory-honest'.
    • Modified the explanation of persistent identity storage to reference the HARU_CONVERSATION_ID environment variable instead of a local config file.
  • examples/haru/package.json
    • Added new dependencies: @xsai/tool, ink-spinner, swr, temporal-polyfill, and zod.
  • examples/haru/src/chat.tsx
    • Refactored chat handling logic into the useHaru hook.
    • Removed direct state management for messages and loading status, delegating to useHaru.
    • Integrated ink-spinner component to display loading state.
    • Simplified command handling by calling methods from the useHaru hook.
  • examples/haru/src/docs/PROMPT.md
    • Updated the placeholder for recent memory in the prompt template from {recentMemory()} to {recent_memory}.
  • examples/haru/src/hooks/use-haru.ts
    • Added a new React hook useHaru to encapsulate all chat-related logic, including message state, API interactions, and tool execution.
    • Implemented useSWR and useSWRMutation for efficient data fetching and mutation.
    • Utilized temporal-polyfill for precise time and duration calculations in system prompts.
  • examples/haru/src/vite-env.d.ts
    • Added comprehensive type definitions for Intl.DurationFormat to support temporal duration formatting.
  • pnpm-lock.yaml
    • Updated the lockfile to reflect the addition of new dependencies and their transitive dependencies.
Activity
  • The pull request was opened by kwaa, introducing a significant refactor to the haru application.
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
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 solid refactoring of the Haru example application. It effectively introduces the useHaru custom hook to encapsulate chat logic, leverages swr for cleaner data fetching, and improves the user experience with a new loading spinner. The code is now more modular and maintainable. My review includes a few suggestions to enhance robustness by handling missing environment variables and preventing user input during loading states, along with a minor documentation formatting fix.

Comment thread examples/haru/src/hooks/use-haru.ts
Comment thread examples/haru/README.md
Comment thread examples/haru/src/hooks/use-haru.ts
@kwaa kwaa merged commit ed3701f into main Feb 21, 2026
@kwaa kwaa deleted the refactor/haru branch February 21, 2026 09:22
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