gemini-cli - 💡(How to fix) Fix [AgentProtocol] Push client-initiated command routing down to the agent session [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
google-gemini/gemini-cli#24998Fetched 2026-04-09 08:16:21
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Assignees
Timeline (top)
labeled ×2assigned ×1parent_issue_added ×1

Currently, in the stable useGeminiStream flow, the UI explicitly parses slash commands (like /skill) and @-mentions, explicitly schedules the resulting tool calls, and manually injects synthetic turns into the LLM history.

To achieve a true "dumb terminal" TUI, the UI should simply send the user's raw text string to the AgentProtocol. The underlying agent implementation (e.g., LegacyAgentSession or its internal prompt router) should be responsible for intercepting command syntax, executing the necessary tools, managing its internal history, and emitting the appropriate tool_request / tool_response events back to the UI.

Note on Autocomplete: For now, the UI will continue to handle tab-completion and autocomplete suggestions for these commands as it does today. In the future, this capability should also be moved to the protocol level.

Root Cause

Currently, in the stable useGeminiStream flow, the UI explicitly parses slash commands (like /skill) and @-mentions, explicitly schedules the resulting tool calls, and manually injects synthetic turns into the LLM history.

To achieve a true "dumb terminal" TUI, the UI should simply send the user's raw text string to the AgentProtocol. The underlying agent implementation (e.g., LegacyAgentSession or its internal prompt router) should be responsible for intercepting command syntax, executing the necessary tools, managing its internal history, and emitting the appropriate tool_request / tool_response events back to the UI.

Note on Autocomplete: For now, the UI will continue to handle tab-completion and autocomplete suggestions for these commands as it does today. In the future, this capability should also be moved to the protocol level.

RAW_BUFFERClick to expand / collapse

Parent tracking issue: #22702

Context

Currently, in the stable useGeminiStream flow, the UI explicitly parses slash commands (like /skill) and @-mentions, explicitly schedules the resulting tool calls, and manually injects synthetic turns into the LLM history.

To achieve a true "dumb terminal" TUI, the UI should simply send the user's raw text string to the AgentProtocol. The underlying agent implementation (e.g., LegacyAgentSession or its internal prompt router) should be responsible for intercepting command syntax, executing the necessary tools, managing its internal history, and emitting the appropriate tool_request / tool_response events back to the UI.

Note on Autocomplete: For now, the UI will continue to handle tab-completion and autocomplete suggestions for these commands as it does today. In the future, this capability should also be moved to the protocol level.

Tasks

  • Refactor command parsing: Move the logic that detects and resolves backend slash commands and @-mentions out of the UI hooks and into the core agent logic (e.g., intercepting the initial text in LegacyAgentProtocol._runLoop).
    • Note: Purely UI-local commands (like /help or /clear) should remain handled by the UI.
  • Implement synthetic tool execution in LegacyAgentSession: When a command string is intercepted, the session should execute the corresponding tool directly via the Scheduler.
  • Emit synthetic events: The session must emit tool_request and tool_response events for these intercepted commands. Ensure these events are flagged (e.g., isClientInitiated: true in the meta payload) so the UI can render them appropriately.
  • Manage history: Ensure the LegacyAgentSession automatically injects the synthetic "model" and "user" turns into the underlying LLM history so subsequent requests have the correct context.
  • Refactor useAgentStream.ts: Remove the explicit execution logic for backend commands, simply passing the raw text to agent.send({ message: ... }).
  • Maintain Backward Compatibility: When migrating existing command processors from packages/cli to packages/core, ensure the existing behavior and interfaces used by the stable useGeminiStream.ts are strictly preserved without regressions.
  • Add a TODO comment in the codebase tracking the future migration of command autocomplete/discovery to the AgentProtocol.

Relevant Files

  • `packages/core/src/agent/legacy-agent-session.ts`: Implement interception, execution, and history injection logic.
  • `packages/cli/src/ui/hooks/useAgentStream.ts`: Simplify input processing to pass raw text.
  • (Various existing command processors in `packages/cli/src/ui/hooks/` may need to be migrated to `packages/core`).

Acceptance Criteria

  • Sending a string like `/skill [name]` via `agent.send()` results in the agent emitting tool lifecycle events for the `activate_skill` tool.
  • The UI properly renders these synthetic events.
  • The LLM context correctly reflects the outcome of the command in subsequent turns.
  • Autocomplete continues to function in the TUI as it does today.
  • The stable `useGeminiStream` flow continues to function without changes to its user-facing behavior.

extent analysis

TL;DR

Refactor the command parsing logic to move it from the UI to the core agent logic, allowing the agent to intercept and execute commands, and emit synthetic events.

Guidance

  • Identify and migrate the command parsing logic from the UI hooks to the LegacyAgentProtocol._runLoop method.
  • Implement synthetic tool execution in LegacyAgentSession using the Scheduler.
  • Ensure the LegacyAgentSession emits tool_request and tool_response events with the correct metadata.
  • Update useAgentStream.ts to pass raw text to agent.send({ message: ... }) without explicit execution logic.
  • Verify that the changes preserve the existing behavior and interfaces used by the stable useGeminiStream.ts flow.

Example

// packages/core/src/agent/legacy-agent-session.ts
interceptCommand(text: string) {
  if (text.startsWith('/')) {
    const command = text.substring(1);
    // Execute the corresponding tool using the Scheduler
    this.scheduler.executeTool(command);
    // Emit synthetic events
    this.emit('tool_request', { command, isClientInitiated: true });
    // ...
  }
}

Notes

The migration of command autocomplete/discovery to the AgentProtocol is not included in this refactor, but a TODO comment should be added to track this future task.

Recommendation

Apply the workaround by refactoring the command parsing logic and implementing synthetic tool execution in LegacyAgentSession, as this approach allows for a more modular and maintainable architecture.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING