From 09beb648b8378cb592922767045e37e00c071f73 Mon Sep 17 00:00:00 2001 From: Jerop Kipruto Date: Mon, 2 Feb 2026 19:32:13 -0500 Subject: [PATCH] refactor: migrate checks.ts utility to core and deduplicate (#18139) --- packages/cli/src/ui/commands/rewindCommand.tsx | 12 ++++++------ packages/cli/src/ui/components/AskUserDialog.tsx | 2 +- packages/cli/src/ui/components/ChecklistItem.tsx | 2 +- .../src/ui/components/shared/vim-buffer-actions.ts | 2 +- packages/cli/src/ui/hooks/toolMapping.ts | 2 +- packages/cli/src/ui/hooks/useExtensionUpdates.ts | 2 +- packages/cli/src/ui/state/extensions.ts | 2 +- packages/cli/src/utils/sessionUtils.ts | 10 ++++------ packages/core/src/index.ts | 1 + packages/{cli => core}/src/utils/checks.test.ts | 0 packages/{cli => core}/src/utils/checks.ts | 0 11 files changed, 17 insertions(+), 18 deletions(-) rename packages/{cli => core}/src/utils/checks.test.ts (100%) rename packages/{cli => core}/src/utils/checks.ts (100%) diff --git a/packages/cli/src/ui/commands/rewindCommand.tsx b/packages/cli/src/ui/commands/rewindCommand.tsx index c9b0424842..f9bd8f3578 100644 --- a/packages/cli/src/ui/commands/rewindCommand.tsx +++ b/packages/cli/src/ui/commands/rewindCommand.tsx @@ -14,14 +14,14 @@ import { type HistoryItem } from '../types.js'; import { convertSessionToHistoryFormats } from '../hooks/useSessionBrowser.js'; import { revertFileChanges } from '../utils/rewindFileOps.js'; import { RewindOutcome } from '../components/RewindConfirmation.js'; -import { checkExhaustive } from '../../utils/checks.js'; - import type { Content } from '@google/genai'; -import type { - ChatRecordingService, - GeminiClient, +import { + checkExhaustive, + coreEvents, + debugLogger, + type ChatRecordingService, + type GeminiClient, } from '@google/gemini-cli-core'; -import { coreEvents, debugLogger } from '@google/gemini-cli-core'; /** * Helper function to handle the core logic of rewinding a conversation. diff --git a/packages/cli/src/ui/components/AskUserDialog.tsx b/packages/cli/src/ui/components/AskUserDialog.tsx index 4c45b356fc..c579ee8933 100644 --- a/packages/cli/src/ui/components/AskUserDialog.tsx +++ b/packages/cli/src/ui/components/AskUserDialog.tsx @@ -21,7 +21,7 @@ import type { SelectionListItem } from '../hooks/useSelectionList.js'; import { TabHeader, type Tab } from './shared/TabHeader.js'; import { useKeypress, type Key } from '../hooks/useKeypress.js'; import { keyMatchers, Command } from '../keyMatchers.js'; -import { checkExhaustive } from '../../utils/checks.js'; +import { checkExhaustive } from '@google/gemini-cli-core'; import { TextInput } from './shared/TextInput.js'; import { useTextBuffer } from './shared/text-buffer.js'; import { getCachedStringWidth } from '../utils/textUtils.js'; diff --git a/packages/cli/src/ui/components/ChecklistItem.tsx b/packages/cli/src/ui/components/ChecklistItem.tsx index 922cec97e1..6e08e0af6b 100644 --- a/packages/cli/src/ui/components/ChecklistItem.tsx +++ b/packages/cli/src/ui/components/ChecklistItem.tsx @@ -7,7 +7,7 @@ import type React from 'react'; import { Box, Text } from 'ink'; import { theme } from '../semantic-colors.js'; -import { checkExhaustive } from '../../utils/checks.js'; +import { checkExhaustive } from '@google/gemini-cli-core'; export type ChecklistStatus = | 'pending' diff --git a/packages/cli/src/ui/components/shared/vim-buffer-actions.ts b/packages/cli/src/ui/components/shared/vim-buffer-actions.ts index 67aa50faeb..5bec8f033c 100644 --- a/packages/cli/src/ui/components/shared/vim-buffer-actions.ts +++ b/packages/cli/src/ui/components/shared/vim-buffer-actions.ts @@ -19,7 +19,7 @@ import { findWordEndInLine, } from './text-buffer.js'; import { cpLen, toCodePoints } from '../../utils/textUtils.js'; -import { assumeExhaustive } from '../../../utils/checks.js'; +import { assumeExhaustive } from '@google/gemini-cli-core'; // Check if we're at the end of a base word (on the last base character) // Returns true if current position has a base character followed only by combining marks until non-word diff --git a/packages/cli/src/ui/hooks/toolMapping.ts b/packages/cli/src/ui/hooks/toolMapping.ts index 902db1333e..e83fb583bf 100644 --- a/packages/cli/src/ui/hooks/toolMapping.ts +++ b/packages/cli/src/ui/hooks/toolMapping.ts @@ -18,7 +18,7 @@ import { type IndividualToolCallDisplay, } from '../types.js'; -import { checkExhaustive } from '../../utils/checks.js'; +import { checkExhaustive } from '@google/gemini-cli-core'; export function mapCoreStatusToDisplayStatus( coreStatus: CoreStatus, diff --git a/packages/cli/src/ui/hooks/useExtensionUpdates.ts b/packages/cli/src/ui/hooks/useExtensionUpdates.ts index 771b0f2cb3..1c83c26cf6 100644 --- a/packages/cli/src/ui/hooks/useExtensionUpdates.ts +++ b/packages/cli/src/ui/hooks/useExtensionUpdates.ts @@ -19,7 +19,7 @@ import { updateExtension, } from '../../config/extensions/update.js'; import { type ExtensionUpdateInfo } from '../../config/extension.js'; -import { checkExhaustive } from '../../utils/checks.js'; +import { checkExhaustive } from '@google/gemini-cli-core'; import type { ExtensionManager } from '../../config/extension-manager.js'; type ConfirmationRequestWrapper = { diff --git a/packages/cli/src/ui/state/extensions.ts b/packages/cli/src/ui/state/extensions.ts index 7e7cc83c74..c642a333d3 100644 --- a/packages/cli/src/ui/state/extensions.ts +++ b/packages/cli/src/ui/state/extensions.ts @@ -5,7 +5,7 @@ */ import type { ExtensionUpdateInfo } from '../../config/extension.js'; -import { checkExhaustive } from '../../utils/checks.js'; +import { checkExhaustive } from '@google/gemini-cli-core'; export enum ExtensionUpdateState { CHECKING_FOR_UPDATES = 'checking for updates', diff --git a/packages/cli/src/utils/sessionUtils.ts b/packages/cli/src/utils/sessionUtils.ts index 63ccf4d14a..b49a461ce2 100644 --- a/packages/cli/src/utils/sessionUtils.ts +++ b/packages/cli/src/utils/sessionUtils.ts @@ -4,20 +4,18 @@ * SPDX-License-Identifier: Apache-2.0 */ -import type { - Config, - ConversationRecord, - MessageRecord, -} from '@google/gemini-cli-core'; import { + checkExhaustive, partListUnionToString, SESSION_FILE_PREFIX, + type Config, + type ConversationRecord, + type MessageRecord, } from '@google/gemini-cli-core'; import * as fs from 'node:fs/promises'; import path from 'node:path'; import { stripUnsafeCharacters } from '../ui/utils/textUtils.js'; import type { Part } from '@google/genai'; -import { checkExhaustive } from './checks.js'; import { MessageType, ToolCallStatus, diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 219e8151ab..7fa7a5099e 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -56,6 +56,7 @@ export * from './core/apiKeyCredentialStorage.js'; // Export utilities export { homedir, tmpdir } from './utils/paths.js'; export * from './utils/paths.js'; +export * from './utils/checks.js'; export * from './utils/schemaValidator.js'; export * from './utils/errors.js'; export * from './utils/exitCodes.js'; diff --git a/packages/cli/src/utils/checks.test.ts b/packages/core/src/utils/checks.test.ts similarity index 100% rename from packages/cli/src/utils/checks.test.ts rename to packages/core/src/utils/checks.test.ts diff --git a/packages/cli/src/utils/checks.ts b/packages/core/src/utils/checks.ts similarity index 100% rename from packages/cli/src/utils/checks.ts rename to packages/core/src/utils/checks.ts