Skip to content

Feat: agent loop, context window manager, and refreshed CLI activity UI#161

Merged
lvndry merged 6 commits intomainfrom
feat/agent-loop-context-window-and-cli-ui
Feb 7, 2026
Merged

Feat: agent loop, context window manager, and refreshed CLI activity UI#161
lvndry merged 6 commits intomainfrom
feat/agent-loop-context-window-and-cli-ui

Conversation

@lvndry
Copy link
Owner

@lvndry lvndry commented Feb 7, 2026

Summary

This PR evolves the agent execution pipeline and CLI experience by introducing an explicit agent loop, a context window manager, and a refreshed activity UI, along with LLM plumbing and dependency cleanup.

Highlights

  • Add agent loop abstraction and tests to orchestrate tool usage and streaming output
  • Introduce a context window manager and tests for safer long-running conversations
  • Refactor batch, streaming and tool executors around the new execution model
  • Refresh CLI activity view, renderer and output theme for clearer reasoning and logs
  • Update tool registry and fs tools (find/grep) and tighten error handling
  • Move models-dev client into core utils and update LLM services and tests
  • Trim unused dev dependencies from package.json and bun.lock

Testing

  • bun test
  • bun lint (or equivalent)
  • Manual CLI run for a typical agent flow to confirm UI and streaming behavior

lvndry and others added 2 commits February 7, 2026 17:33
…ervice

Move the 11 module-level mutable variables from App.tsx into a UIStore
class in store.ts for encapsulation and test isolation. Delete the
unused AppStateService Effect-based state system (~700 lines of dead
code across 6 files).

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

Summary of Changes

Hello @lvndry, 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 agent's execution capabilities and refines the command-line interface (CLI) experience. Key changes include the introduction of a unified agent loop for more robust and maintainable execution, a dedicated context window manager to optimize long-running conversations, and a complete refresh of the CLI's activity display for improved clarity. Additionally, it streamlines dependencies, upgrades file system tools for better performance, and integrates prompt caching into LLM services.

Highlights

  • Agent Execution Pipeline Refactor: Introduced a new agent-loop abstraction to orchestrate tool usage and streaming output, centralizing core agent execution logic previously duplicated across batch and streaming executors.
  • Context Window Management: Implemented a ContextWindowManager and associated tests to ensure safer and more efficient long-running conversations by proactively compacting context and managing token limits.
  • Refreshed CLI Activity UI: Overhauled the CLI activity view, renderer, and output theme for clearer reasoning and logs, including new icons and improved presentation of agent thought processes and tool executions. This also involved a significant refactoring of the CLI's internal state management, replacing a service-based approach with a new UIStore class.
  • Enhanced File System Tools: Updated the find tool to use fast-glob for improved performance and cross-platform compatibility, and the grep tool to prioritize ripgrep (rg) with fallback to grep, offering new output modes and better error handling.
  • Dependency Cleanup: Trimmed numerous unused development dependencies from package.json and bun.lock, reducing the project's footprint and improving build times.
  • LLM Service Improvements: Moved the models-dev-client utility to core/utils and updated LLM services to include prompt caching for system messages, which can lead to cost reduction and latency improvements.
  • Agent Prompt Enhancements: Modified system prompts for coder, default, and researcher agents to include explicit instructions for parallel tool execution and delegating complex exploration tasks to sub-agents.
Changelog
  • bun.lock
    • Removed numerous unused dependencies, including @ai-sdk/react, @inquirer/prompts and its sub-dependencies, pastel, react-devtools-core, and various utility libraries.
  • package.json
    • Removed @ai-sdk/react, @inquirer/prompts, pastel, and react-devtools-core from project dependencies.
  • src/cli/commands/config-wizard.ts
    • Updated import path for store to reflect the new UI store location.
  • src/cli/commands/edit-agent.ts
    • Moved getModelsDevMetadata import to src/core/utils/models-dev-client.
    • Removed an emoji from the wizard heading for a cleaner look.
  • src/cli/commands/wizard.ts
    • Updated import path for store to reflect the new UI store location.
  • src/cli/commands/workflow.ts
    • Updated import path for store to reflect the new UI store location.
  • src/cli/presentation/activity-reducer.ts
    • Added MAX_LIVE_TEXT_LENGTH constant to cap live text output at 200,000 characters.
    • Changed reasoning and tool execution icons from emojis to '▸' for consistency.
    • Introduced a separator and '▸ Response' label before agent responses in the activity log.
  • src/cli/presentation/cli-renderer.ts
    • Updated tool execution icon from '⚙️' to '▸'.
  • src/cli/presentation/ink-presentation-service.test.ts
    • Updated import path for store to reflect the new UI store location.
  • src/cli/presentation/ink-presentation-service.ts
    • Moved getModelsDevMetadata import to src/core/utils/models-dev-client.
    • Updated import path for store to reflect the new UI store location.
    • Added clearAllToolTimeouts calls on stop and flush for proper resource cleanup.
    • Modified error handling to catchAllDefect and log warnings to the UI store.
  • src/cli/presentation/output-theme.ts
    • Updated icons for thinking, tool, warning, and info to simpler characters ('▸', '!', 'i').
  • src/cli/services/app-state-service.test.ts
    • Removed file as part of the UI state management refactor.
  • src/cli/services/app-state-service.ts
    • Removed file as part of the UI state management refactor.
  • src/cli/services/index.ts
    • Removed exports related to the deprecated AppStateService.
  • src/cli/services/terminal-service.ts
    • Added a listener for terminal resize events to dynamically update cached terminal dimensions.
  • src/cli/ui/ActivityView.tsx
    • Updated the reasoning section UI, changing the icon and adding a 'Response' label with a separator.
  • src/cli/ui/App.tsx
    • Updated import for store to ../ui/store.
    • Refactored UI components (ActivityIsland, PromptIsland, LogIsland) to integrate with the new UIStore class, using its registration and snapshot methods.
    • Added useEffect cleanup for unregistering UI setters on component unmount.
  • src/cli/ui/contexts/AppStateContext.tsx
    • Removed file as part of the UI state management refactor.
  • src/cli/ui/contexts/index.ts
    • Removed exports related to the deprecated AppStateContext.
  • src/cli/ui/hooks/index.ts
    • Removed exports related to the deprecated use-app-state hooks.
  • src/cli/ui/hooks/use-app-state.ts
    • Removed file as part of the UI state management refactor.
  • src/cli/ui/store.ts
    • Added new UIStore class for centralized UI state management, including methods for logs, prompts, activity, working directory, custom views, and interrupt handlers.
    • Implemented registration methods for React components to connect their state setters to the store, along with snapshot accessors for hydration.
  • src/core/agent/context/context-window-manager.test.ts
    • Added new test file for ContextWindowManager, covering token estimation, trimming logic, and message preservation.
  • src/core/agent/context/summarizer.ts
    • Moved getMetadataFromMap and getModelsDevMap imports to src/core/utils/models-dev-client.
  • src/core/agent/execution/agent-loop.test.ts
    • Added new test file for the executeAgentLoop function, verifying its core logic for completions, tool calls, and error handling.
  • src/core/agent/execution/agent-loop.ts
    • Added new executeAgentLoop function, encapsulating the main agent execution logic and defining a CompletionStrategy interface for flexible completion handling.
  • src/core/agent/execution/batch-executor.ts
    • Refactored to utilize the new executeAgentLoop function, removing duplicated agent loop logic.
  • src/core/agent/execution/streaming-executor.ts
    • Refactored to utilize the new executeAgentLoop function, removing duplicated agent loop logic and streamlining stream event processing.
  • src/core/agent/execution/tool-executor.test.ts
    • Added new test file for ToolExecutor, covering tool execution, argument parsing, and handling of multiple tool calls.
  • src/core/agent/execution/tool-executor.ts
    • Updated executeTool to explicitly handle ToolNotFoundError.
  • src/core/agent/prompts/coder/system.ts
    • Added new instructions to the system prompt regarding parallel tool calls and delegating exploration to sub-agents.
  • src/core/agent/prompts/default/system.ts
    • Added new sections to the system prompt on parallel tool execution and delegating exploration to sub-agents.
  • src/core/agent/prompts/researcher/system.ts
    • Added instructions to the system prompt to run multiple web searches and tool calls in parallel.
  • src/core/agent/tools/fs/find.ts
    • Updated tool description to highlight fast-glob usage for speed.
    • Replaced child_process.spawn with fast-glob for file searching, improving performance and reliability.
    • Added sorting of results by modification time (most recent first).
  • src/core/agent/tools/fs/grep.ts
    • Updated tool description to mention ripgrep preference with grep fallback.
    • Added a new outputMode parameter (content, files, count) for flexible search results.
    • Refactored the execution logic to first attempt ripgrep and adjust arguments based on the chosen output mode.
  • src/core/agent/tools/tool-registry.ts
    • Modified getTool to return Effect.fail(new ToolNotFoundError(...)) instead of throwing a generic error.
    • Updated executeTool's error handling to catch ToolNotFoundError.
  • src/core/interfaces/tool-registry.ts
    • Updated the return type of getTool to include ToolNotFoundError.
  • src/core/types/errors.ts
    • Added new ToolNotFoundError class for specific tool-related errors.
    • Introduced ExecutorError type alias for common executor-related errors.
  • src/services/chat-service.ts
    • Updated updateWorkingDirectoryInStore calls to pass store.setWorkingDirectory as a callback, aligning with the new UI store architecture.
  • src/services/chat/commands/handler.ts
    • Removed direct store.printOutput calls, replacing them with terminal.info for command output.
    • Moved getModelsDevMetadata import to src/core/utils/models-dev-client.
  • src/services/chat/session/manager.ts
    • Modified updateWorkingDirectoryInStore to accept an optional setWorkingDirectory callback for UI updates.
  • src/services/llm/ai-sdk-service.ts
    • Moved getMetadataFromMap and getModelsDevMap imports to src/core/utils/models-dev-client.
    • Modified toCoreMessages to enable prompt caching for system messages in Anthropic and OpenAI providers.
  • src/services/llm/model-fetcher.test.ts
    • Updated mock path for models-dev-client to reflect its new location.
  • src/services/llm/model-fetcher.ts
    • Moved getMetadataFromMap and getModelsDevMap imports to src/core/utils/models-dev-client.
  • src/services/llm/models-dev-client.ts
    • Renamed to src/core/utils/models-dev-client.ts, moving the utility to a more central location.
  • src/services/terminal.ts
    • Updated store import to src/cli/ui/store.
Activity
  • New core logic for agent execution is introduced with agent-loop.ts, accompanied by dedicated test files for context-window-manager.test.ts and tool-executor.test.ts.
  • The CLI's state management system has been completely refactored, leading to the removal of app-state-service.test.ts, app-state-service.ts, AppStateContext.tsx, and use-app-state.ts.
  • A new store.ts file centralizes UI state management, providing a more robust and maintainable architecture for the CLI.
  • Existing CLI UI components and services are updated to integrate seamlessly with the new UI store and reflect the refreshed activity UI, including new icons and improved log presentation.
  • A significant dependency cleanup has been performed, removing numerous unused packages from bun.lock and package.json to streamline the project.
  • Tool definitions for find and grep are enhanced for better performance and functionality, leveraging modern tools like fast-glob and ripgrep.
  • The LLM service integration now includes prompt caching for system messages, aiming to optimize performance and reduce costs.
  • Agent system prompts are updated to guide agents towards more efficient strategies, such as parallel tool execution and delegating complex tasks to sub-agents.
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 is an excellent pull request that introduces significant architectural improvements. The new agent loop abstraction is a major win for code clarity and maintainability, centralizing the core execution logic. The refactoring of the CLI's state management to a simpler global store is a pragmatic and well-executed change for this type of application. I'm also impressed with the performance enhancements to the find and grep tools by using fast-glob and ripgrep. Overall, these changes greatly enhance the robustness and structure of the codebase. I have one suggestion for refactoring to reduce some code duplication.

@lvndry lvndry merged commit 80b97b4 into main Feb 7, 2026
4 checks passed
@lvndry lvndry deleted the feat/agent-loop-context-window-and-cli-ui branch February 7, 2026 23:51
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