diff options
| author | jlove29 <[email protected]> | 2025-04-19 11:07:39 +0100 |
|---|---|---|
| committer | jlove29 <[email protected]> | 2025-04-19 11:07:39 +0100 |
| commit | d2ef83bc60f0dd295fc6150030357bf914d0169f (patch) | |
| tree | 5f84343cdc8c31c33f9601b5229dfc4d745e1893 /packages/cli/src | |
| parent | 24371a39546a7802ce612c76f5a250b35a739acc (diff) | |
Add direct execution of shell commands
Diffstat (limited to 'packages/cli/src')
| -rw-r--r-- | packages/cli/src/ui/hooks/useGeminiStream.ts | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index b4746fe6..37e62d93 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { exec } from 'child_process'; import { useState, useRef, useCallback, useEffect } from 'react'; import { useInput } from 'ink'; import { GeminiClient } from '../../core/gemini-client.js'; @@ -16,6 +17,8 @@ import { import { globalConfig } from '../../config/config.js'; import { getErrorMessage, isNodeError } from '../../utils/errors.js'; +const allowlistedCommands = ['ls']; // TODO: make this configurable + const addHistoryItem = ( setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>, itemData: Omit<HistoryItem, 'id'>, @@ -106,6 +109,21 @@ export const useGeminiStream = ( { type: 'user', text: trimmedQuery }, userMessageTimestamp, ); + + const maybeCommand = trimmedQuery.split(/\s+/)[0]; + if (allowlistedCommands.includes(maybeCommand)) { + exec(trimmedQuery, (error, stdout, stderr) => { + const timestamp = getNextMessageId(userMessageTimestamp); + // TODO: handle stderr, error + addHistoryItem( + setHistory, + { type: 'info', text: stdout }, + timestamp, + ); + }); + return; + } + } else if ( // HACK to detect errored function responses. typeof query === 'object' && |
