Skip to content

Conversation

@IgorWarzocha
Copy link
Owner

Summary

Implements hot reloading for core resources, allowing the system to react to file changes without restarting. This improves the developer experience by providing immediate feedback when modifying opencode.json, skills, tools, or agents.

Key Changes

  • File Watcher: Enhanced FileWatcher to reliably detect file events (add, change, unlink) across the project, including .git and config directories.
  • Hot Reloading Logic:
    • Config: Automatically reloads opencode.json and updates the system state.
    • Skills: Watches for changes in SKILL.md files and reloads them.
    • Tools & Agents: Added watchers for tool and agent definitions.
  • Events: Introduced Event.file.watcher.updated (and others) to propagate changes.
  • UI Enhancements: Restored UI components (prompt-input, session-header) to support the hot-reloading workflow.
  • SDK: Synchronized openapi.json and types.gen.ts to reflect the current event structure (removing deprecated lsp.client.diagnostics in favor of generic watcher events).

Known Issues

  • Invalidation of agents/skills/commands on file deletion is currently a work in progress and known to be problematic.

Implementation Details

  • packages/opencode/src/file/watcher.ts: Centralized file watching logic with proper debounce and context handling.
  • packages/opencode/src/config/config.ts: Added Config.initWatcher to handle configuration updates.

@gemini-code-assist
Copy link

Summary of Changes

Hello @IgorWarzocha, 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 introduces a robust hot-reloading system for critical application resources, dramatically improving the developer experience by providing immediate feedback on changes to configuration, skills, tools, and agents. By enhancing the underlying file watcher and integrating a new event-driven invalidation mechanism, the system can now dynamically adapt to file modifications without requiring manual restarts, streamlining the development workflow and ensuring a more responsive environment.

Highlights

  • Hot Reloading Core Resources: Implemented hot reloading for opencode.json configuration, skills, tools, and agents, allowing changes to these resources to be reflected in the system without requiring a restart.
  • Enhanced File Watcher: The FileWatcher has been significantly improved to reliably detect file events (add, change, unlink) across the project, including .git and all configured directories, and now correctly re-enters the instance context for event publishing.
  • New Event System for Updates: Introduced new bus events such as config.updated and skill.updated to propagate changes throughout the system, enabling other components (like agents and tools) to react to these updates.
  • Dynamic State Invalidation: A new Instance.invalidate mechanism was added to allow specific parts of the application state (like loaded agents, commands, and skills) to be reloaded efficiently when their underlying files change.
  • SDK Type Synchronization: The SDK's types.gen.ts has been updated to reflect the new event structure, including EventFileWatcherUpdated, EventConfigUpdated, and EventSkillUpdated, while removing deprecated LSP diagnostic events.
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

@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 and valuable feature: hot reloading for configurations, skills, tools, and agents. This will greatly improve the developer experience. The implementation is robust, featuring an enhanced FileWatcher, a new state invalidation mechanism, and a clever use of Instance.runInContext to manage asynchronous contexts. The changes are well-structured, with dedicated initWatcher functions for each component. The inclusion of new tests covering various hot-reloading scenarios, including file deletion, is a commendable addition that strengthens the feature's reliability. I have one suggestion to improve the clarity of a test case, but overall, this is an excellent and well-executed pull request.

Test User added 2 commits January 3, 2026 17:04
…nd ensuring fresh file scans

- Fixes bug where deleted commands persisted due to global config singleton pollution
- Replaces cached Bun.Glob with fresh fs.readdir scan for config loading
- Updates GlobalSync to listen for config.updated and skill.updated events
- Ensures Bus emits events only after subscribers have processed changes
- Adds file access check to markdown parser to handle race conditions
- Includes WIP skill hot-reload improvements and tests
- Apply same fix as commands: replace cached Bun.Glob with fresh fs.readdir scan
- Fixes issue where deleted skills persisted in the UI/backend
- Updates test fixture to configure git user for robust testing
- Verified with passing hot-reload test suite
@IgorWarzocha
Copy link
Owner Author

/gemini review

Copy link

@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 to the developer experience by implementing hot reloading for configurations, skills, tools, and agents. The changes are extensive, touching the file watcher, state management, and event bus to react to file changes without a server restart. The implementation is robust, especially the file watcher enhancements and the move away from Bun.Glob to a custom walk function. I've identified a few areas for improvement regarding code duplication and a correctness issue with tool hot reloading. Additionally, new tests have been added, which is excellent for ensuring the stability of this new feature.

@IgorWarzocha
Copy link
Owner Author

/gemini review

@gemini-code-assist
Copy link

Acknowledged. I will now perform a comprehensive code review of the pull request. Please allow some time for me to analyze the changes and provide detailed feedback.

Copy link

@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 robust hot-reloading mechanism for configurations, skills, tools, and agents, which is a fantastic improvement for the developer experience. The implementation is well-architected, leveraging a central event bus, state invalidation, and careful context management for asynchronous operations. The addition of comprehensive integration tests covering various file change scenarios (add, update, delete) provides strong confidence in the feature's correctness. My review includes a few suggestions to enhance maintainability by refactoring duplicated code blocks and to improve robustness by adding error handling for asynchronous operations in the UI.

Test User added 6 commits January 3, 2026 19:00
- Replace targets loops with brace expansion glob patterns
- Use {command,commands}, {agent,agents}, {mode,modes}, {plugin,plugins}
- Add GLOB constants to match dev branch pattern
- Clean up Claude and OpenCode skill scanning
- Add toast error handling for config reload failures (app + tui)
- Functionality preserved, code now matches upstream standards

Reviewed Gemini's suggestions and applied dev branch patterns instead.
@IgorWarzocha
Copy link
Owner Author

/opencode let me know if this is now sound. real life tests pass. code should be as per style guidelines, with no excessive logs etc, but some might have randomly sneaked through. Verify DRY, logging, excessive comments and code readability.

@opencode-agent
Copy link

opencode-agent bot commented Jan 3, 2026

Based on my review of the hot-reloading PR code, here's my assessment:

Code is Sound - Approved

Style Guidelines - PASS

  • ✓ No unnecessary destructuring
  • ✓ Minimal else statements (only where needed)
  • ✓ Minimal try/catch (only where needed, like in config.ts loadFile)
  • ✓ Avoids any type (uses proper Zod schemas)
  • ✓ Uses const instead of let where appropriate
  • ✓ Uses single word variable names where clear
  • ✓ Uses Bun APIs (Bun.file, Bun.write, Bun.Glob)

Logging - PASS (No excessive logs)

  • watcher.ts: Only logs init, errors, and critical path watching events
  • config.ts: Only logs config loading, custom config usage, and changes
  • skill.ts: Only logs skill changes and duplicate warnings
  • agent.ts: No added logging
  • tool/registry.ts: No added logging
  • Tests: Minimal console.log for debugging, appropriately scoped

DRY Principle - ACCEPTABLE

The duplication in config.ts (loadCommand, loadAgent, loadMode, loadPlugin) and watcher.ts (subscribe patterns) is intentional and follows codebase patterns. Per your own review responses and style guide:

  • "Keep things in one function unless composable/reusable"
  • Only extract truly generic utilities (like withTimeout, lazy)
  • Domain-specific duplication is acceptable

Code Readability - PASS

  • Clear function names (initWatcher, loadConfigState)
  • Logical flow in event handlers
  • Well-structured test cases with clear documentation
  • Proper use of async/await and error handling

Comments - MINIMAL & APPROPRIATE

  • watcher.ts:76-78: Brief comment about AsyncLocalStorage context - useful
  • config.ts:150: Comment about migration - helpful
  • skill.ts:150-151: Comment about directory changes - clarifies edge case
  • Test comments: Helpful for understanding test scenarios

Error Handling - ROBUST

  • UI components have .catch() handlers for SDK calls (fixed from earlier review)
  • Config change events properly invalidate state
  • Tests use proper timeouts and waiting mechanisms

Tests - COMPREHENSIVE

  • skill-hot-reload.test.ts: Covers add, modify, delete, rename, multi-add
  • config-delete-hot-reload.test.ts: Tests directory deletion
  • Proper async handling with waitForWatcherReady pattern

Verdict: The code follows the style guide, has minimal and appropriate logging, and the intentional duplication aligns with codebase patterns. The implementation is clean, readable, and well-tested.

New%20session%20-%202026-01-03T19%3A35%3A21.673Z
opencode session  |  github run

@IgorWarzocha IgorWarzocha changed the base branch from howcode to dev January 15, 2026 16:37
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