feat(cli): add /restart slash command#25657
feat(cli): add /restart slash command#25657martin-hsu-test wants to merge 1 commit intogoogle-gemini:mainfrom
Conversation
Adds a new /restart slash command that gracefully restarts the gemini
CLI process and resumes the current chat session in the new process.
Motivation: when the CLI auto-updates itself in-place, users currently
have to manually quit, re-launch, and run /chat resume to continue
their conversation. /restart performs all three steps automatically.
Implementation
--------------
1. New restartCommand returns {type: 'restart', resumeSessionId, ...}
from its action, capturing the current session ID via
context.services.agentContext.config.getSessionId().
2. slashCommandProcessor dispatches the new return type to a new
actions.restart() handler.
3. AppContainer.restart() sends an IPC message to the parent watchdog
({type: 'restart-with-resume', sessionId}), then calls the existing
relaunchApp() helper which exits with RELAUNCH_EXIT_CODE (199).
4. The parent watchdog in packages/cli/index.ts records the sessionId
in pendingExtraScriptArgs and injects ['--resume', sessionId] into
the next spawn's argv, then clears the buffer.
Design rationale
----------------
* IPC over env vars / marker files: env vars only flow parent->child,
and marker files add a disk race + cleanup burden. The parent
watchdog already has an IPC channel for admin-settings-update, so we
extend it.
* Explicit sessionId vs --resume (latest): the user intent of
/restart is 'continue THIS session', not 'continue the most recent
session'. With multiple gemini instances running concurrently,
'latest' could resolve to a different instance's session, which
would feel like data loss.
* IPC failure is non-fatal: if process.send is unavailable (e.g.
GEMINI_CLI_NO_RELAUNCH=true) the restart still happens, just without
resume. Users get a working restart over a stuck process.
Tests
-----
* New restartCommand.test.ts: 2 unit tests covering presence and
absence of agentContext.config.
* slashCommandProcessor.test.tsx: existing 35 tests still pass after
adding restart to the actions mock.
* BuiltinCommandLoader.test.ts: existing 17 tests still pass after
registering restartCommand.
* End-to-end IPC contract verified out-of-band by spawning a child
that sends restart-with-resume + exits 199, and asserting the next
spawn's argv contains ['--resume', sessionId].
Closes google-gemini#16124
Summary of ChangesHello, 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 improves the developer experience by adding a /restart command to the Gemini CLI. This feature streamlines the process of restarting the application after updates or configuration changes by automating the session resumption, effectively replacing a multi-step manual workflow with a single command. Highlights
Using Gemini Code AssistThe 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
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 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new /restart slash command that allows users to relaunch the CLI process while automatically resuming the current session. The implementation involves adding IPC message handling in the main entry point to capture session IDs and inject them as --resume arguments into the next process spawn. The review feedback correctly identifies a property access error in the restartCommand implementation and its associated tests, where agentContext was being treated as a wrapper rather than the configuration object itself.
|
Hi, I’d like to work on the Proposed approach:
Please let me know if this aligns or if there are any specific guidelines I should follow. |
|
/assign |
Summary
Adds a new
/restartslash command that gracefully restarts the gemini CLI process and automatically resumes the current chat session in the new process.Closes #16124.
Motivation
Today, when the CLI auto-updates itself in-place, users see:
…and have to manually:
/quit(or Ctrl+C)gemini/chat resumeorgemini --resume <id>/restartcollapses all three into one command.How it works
restartCommandreads the current session ID viacontext.services.agentContext.config.getSessionId()and returns{type: 'restart', resumeSessionId, messages}.slashCommandProcessordispatches the new return type toactions.restart().AppContainer.restart()sends an IPC message{type: 'restart-with-resume', sessionId}to the parent watchdog, then calls the existingrelaunchApp()helper (which exits withRELAUNCH_EXIT_CODE = 199).pendingExtraScriptArgsand prepends['--resume', sessionId]to the next spawn's argv. The buffer is cleared after one use.Design rationale
IPC over env vars / marker files — Env vars only flow parent→child, and a disk marker file would add a race condition + cleanup burden. The parent watchdog already has an IPC channel for
admin-settings-update, so we extend it with one more message type.Explicit
sessionIdover--resume(latest) — The semantic intent of/restartis "continue this session", not "continue the most recent session". With multiple gemini instances running concurrently, "latest" could resolve to a different instance's session — that would feel like data loss. Passing the explicit ID makes the behavior deterministic.Graceful degradation on IPC failure — If
process.sendis unavailable (e.g. when launched withGEMINI_CLI_NO_RELAUNCH=truefor development), the restart still happens; only the resume is skipped. Users get a working restart over a stuck process.Tests
restartCommand.test.ts: 2 new unit tests covering presence/absence ofagentContext.config.slashCommandProcessor.test.tsx: 35/35 existing tests still pass after addingrestartto the actions mock.BuiltinCommandLoader.test.ts: 17/17 existing tests still pass after registeringrestartCommand.restart-with-resume+ exits 199, and asserting the next spawn's argv contains['--resume', sessionId]./restartand AI retains session-specific context.Files changed (8)
packages/cli/src/ui/commands/restartCommand.tspackages/cli/src/ui/commands/restartCommand.test.tspackages/cli/src/ui/commands/types.tsRestartActionReturnto the unionpackages/cli/src/ui/hooks/slashCommandProcessor.ts'restart'actionpackages/cli/src/ui/hooks/slashCommandProcessor.test.tsxpackages/cli/src/ui/AppContainer.tsxrestartaction handlerpackages/cli/src/services/BuiltinCommandLoader.tsrestartCommandpackages/cli/index.tsNet: +194 / −6 lines.