mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
more robust command parsing logs (#15339)
This commit is contained in:
committed by
GitHub
parent
b828b4754b
commit
db67bb106a
@@ -12,8 +12,9 @@ import {
|
|||||||
type SpawnOptionsWithoutStdio,
|
type SpawnOptionsWithoutStdio,
|
||||||
} from 'node:child_process';
|
} from 'node:child_process';
|
||||||
import type { Node } from 'web-tree-sitter';
|
import type { Node } from 'web-tree-sitter';
|
||||||
import { Language, Parser } from 'web-tree-sitter';
|
import { Language, Parser, Query } from 'web-tree-sitter';
|
||||||
import { loadWasmBinary } from './fileUtils.js';
|
import { loadWasmBinary } from './fileUtils.js';
|
||||||
|
import { debugLogger } from './debugLogger.js';
|
||||||
|
|
||||||
export const SHELL_TOOL_NAMES = ['run_shell_command', 'ShellTool'];
|
export const SHELL_TOOL_NAMES = ['run_shell_command', 'ShellTool'];
|
||||||
|
|
||||||
@@ -305,12 +306,38 @@ function parseBashCommandDetails(command: string): CommandParseResult | null {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const details = collectCommandDetails(tree.rootNode, command);
|
const details = collectCommandDetails(tree.rootNode, command);
|
||||||
|
|
||||||
|
const hasError =
|
||||||
|
tree.rootNode.hasError ||
|
||||||
|
details.length === 0 ||
|
||||||
|
hasPromptCommandTransform(tree.rootNode);
|
||||||
|
|
||||||
|
if (hasError) {
|
||||||
|
let query = null;
|
||||||
|
try {
|
||||||
|
query = new Query(bashLanguage, '(ERROR) @error (MISSING) @missing');
|
||||||
|
const captures = query.captures(tree.rootNode);
|
||||||
|
const syntaxErrors = captures.map((capture) => {
|
||||||
|
const { node, name } = capture;
|
||||||
|
const type = name === 'missing' ? 'Missing' : 'Error';
|
||||||
|
return `${type} node: "${node.text}" at ${node.startPosition.row}:${node.startPosition.column}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
debugLogger.log(
|
||||||
|
'Bash command parsing error detected for command:',
|
||||||
|
command,
|
||||||
|
'Syntax Errors:',
|
||||||
|
syntaxErrors,
|
||||||
|
);
|
||||||
|
} catch (_e) {
|
||||||
|
// Ignore query errors
|
||||||
|
} finally {
|
||||||
|
query?.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
details,
|
details,
|
||||||
hasError:
|
hasError,
|
||||||
tree.rootNode.hasError ||
|
|
||||||
details.length === 0 ||
|
|
||||||
hasPromptCommandTransform(tree.rootNode),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user