mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-17 16:51:15 -07:00
fix(core): enhance sandbox usability and fix build error (#24460)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -179,6 +179,7 @@ export interface ParsedCommandDetail {
|
||||
name: string;
|
||||
text: string;
|
||||
startIndex: number;
|
||||
args?: string[];
|
||||
}
|
||||
|
||||
interface CommandParseResult {
|
||||
@@ -218,9 +219,16 @@ foreach ($commandAst in $commandAsts) {
|
||||
if ([string]::IsNullOrWhiteSpace($name)) {
|
||||
continue
|
||||
}
|
||||
$args = @()
|
||||
if ($commandAst.CommandElements.Count -gt 1) {
|
||||
for ($i = 1; $i -lt $commandAst.CommandElements.Count; $i++) {
|
||||
$args += $commandAst.CommandElements[$i].Extent.Text.Trim()
|
||||
}
|
||||
}
|
||||
$commandObjects += [PSCustomObject]@{
|
||||
name = $name
|
||||
text = $commandAst.Extent.Text.Trim()
|
||||
args = $args
|
||||
}
|
||||
}
|
||||
[PSCustomObject]@{
|
||||
@@ -355,11 +363,31 @@ function collectCommandDetails(
|
||||
|
||||
const name = extractNameFromNode(current);
|
||||
if (name) {
|
||||
details.push({
|
||||
const detail: ParsedCommandDetail = {
|
||||
name,
|
||||
text: source.slice(current.startIndex, current.endIndex).trim(),
|
||||
startIndex: current.startIndex,
|
||||
});
|
||||
};
|
||||
|
||||
if (current.type === 'command') {
|
||||
const args: string[] = [];
|
||||
const nameNode = current.childForFieldName('name');
|
||||
for (let i = 0; i < current.childCount; i += 1) {
|
||||
const child = current.child(i);
|
||||
if (
|
||||
child &&
|
||||
child.type === 'word' &&
|
||||
child.startIndex !== nameNode?.startIndex
|
||||
) {
|
||||
args.push(child.text);
|
||||
}
|
||||
}
|
||||
if (args.length > 0) {
|
||||
detail.args = args;
|
||||
}
|
||||
}
|
||||
|
||||
details.push(detail);
|
||||
}
|
||||
|
||||
// Traverse all children to find all sub-components (commands, redirections, etc.)
|
||||
@@ -509,7 +537,7 @@ function parsePowerShellCommandDetails(
|
||||
|
||||
let parsed: {
|
||||
success?: boolean;
|
||||
commands?: Array<{ name?: string; text?: string }>;
|
||||
commands?: Array<{ name?: string; text?: string; args?: string[] }>;
|
||||
hasRedirection?: boolean;
|
||||
} | null = null;
|
||||
try {
|
||||
@@ -524,7 +552,7 @@ function parsePowerShellCommandDetails(
|
||||
}
|
||||
|
||||
const details = (parsed.commands ?? [])
|
||||
.map((commandDetail) => {
|
||||
.map((commandDetail): ParsedCommandDetail | null => {
|
||||
if (!commandDetail || typeof commandDetail.name !== 'string') {
|
||||
return null;
|
||||
}
|
||||
@@ -539,6 +567,9 @@ function parsePowerShellCommandDetails(
|
||||
name,
|
||||
text,
|
||||
startIndex: 0,
|
||||
args: Array.isArray(commandDetail.args)
|
||||
? commandDetail.args
|
||||
: undefined,
|
||||
};
|
||||
})
|
||||
.filter((detail): detail is ParsedCommandDetail => detail !== null);
|
||||
|
||||
Reference in New Issue
Block a user