Add direct execution of shell commands
This commit is contained in:
parent
24371a3954
commit
d2ef83bc60
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { exec } from 'child_process';
|
||||||
import { useState, useRef, useCallback, useEffect } from 'react';
|
import { useState, useRef, useCallback, useEffect } from 'react';
|
||||||
import { useInput } from 'ink';
|
import { useInput } from 'ink';
|
||||||
import { GeminiClient } from '../../core/gemini-client.js';
|
import { GeminiClient } from '../../core/gemini-client.js';
|
||||||
|
@ -16,6 +17,8 @@ import {
|
||||||
import { globalConfig } from '../../config/config.js';
|
import { globalConfig } from '../../config/config.js';
|
||||||
import { getErrorMessage, isNodeError } from '../../utils/errors.js';
|
import { getErrorMessage, isNodeError } from '../../utils/errors.js';
|
||||||
|
|
||||||
|
const allowlistedCommands = ['ls']; // TODO: make this configurable
|
||||||
|
|
||||||
const addHistoryItem = (
|
const addHistoryItem = (
|
||||||
setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>,
|
setHistory: React.Dispatch<React.SetStateAction<HistoryItem[]>>,
|
||||||
itemData: Omit<HistoryItem, 'id'>,
|
itemData: Omit<HistoryItem, 'id'>,
|
||||||
|
@ -106,6 +109,21 @@ export const useGeminiStream = (
|
||||||
{ type: 'user', text: trimmedQuery },
|
{ type: 'user', text: trimmedQuery },
|
||||||
userMessageTimestamp,
|
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 (
|
} else if (
|
||||||
// HACK to detect errored function responses.
|
// HACK to detect errored function responses.
|
||||||
typeof query === 'object' &&
|
typeof query === 'object' &&
|
||||||
|
|
Loading…
Reference in New Issue