feat(core): implement Windows sandbox dynamic expansion Phase 1 and 2.1 (#23691)

This commit is contained in:
Tommaso Sciortino
2026-03-25 17:54:45 +00:00
committed by GitHub
parent f11bd3d079
commit 1b052df52f
18 changed files with 1168 additions and 528 deletions

View File

@@ -7,12 +7,47 @@
import os from 'node:os';
import fs from 'node:fs';
import path from 'node:path';
import { quote } from 'shell-quote';
import { quote, type ParseEntry } from 'shell-quote';
import {
spawn,
spawnSync,
type SpawnOptionsWithoutStdio,
} from 'node:child_process';
/**
* Extracts the primary command name from a potentially wrapped shell command.
* Strips shell wrappers and handles shopt/set/etc.
*
* @param command - The full command string.
* @param args - The arguments for the command.
* @returns The primary command name.
*/
export async function getCommandName(
command: string,
args: string[],
): Promise<string> {
await initializeShellParsers();
const fullCmd = [command, ...args].join(' ');
const stripped = stripShellWrapper(fullCmd);
const roots = getCommandRoots(stripped).filter(
(r) => r !== 'shopt' && r !== 'set',
);
if (roots.length > 0) {
return roots[0];
}
return path.basename(command);
}
/**
* Extracts a string representation from a shell-quote ParseEntry.
*/
export function extractStringFromParseEntry(entry: ParseEntry): string {
if (typeof entry === 'string') return entry;
if ('pattern' in entry) return entry.pattern;
if ('op' in entry) return entry.op;
if ('comment' in entry) return ''; // We can typically ignore comments for safety checks
return '';
}
import * as readline from 'node:readline';
import { Language, Parser, Query, type Node, type Tree } from 'web-tree-sitter';
import { loadWasmBinary } from './fileUtils.js';