commandAutoApprover.ts ×17

Frontier kind: Code frontier

unlabeled · c_3b2969a78438

25 tests · 8617 LOC · 40 files · introduces 0 tests · 51 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
17 ranges51 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1425 ranges8617 lines · 40 files · Browse complete extent
All tests (intent)
25 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 51 introduced LOC across 17 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/agentHost/node/commandAutoApprover.ts 51 introduced LOC · 17 ranges

Open complete file

177 return 'approved';
178 }
180 const rules = this._compileRules(options?.autoApproveRules);
181
185 return 'noMatch';
186 }
188 > if (this._matchesRule(trimmed, rules.denyCommandLineRules)) {
189 return 'denied';
190 }
192 > let result = this._matchSubCommands(parsed.subCommands, rules);
193 if (result !== 'denied' && this._matchesRule(trimmed, rules.allowCommandLineRules)) {
194 result = 'approved';
206
207 private _matchSubCommands(subCommands: string[], rules: IAutoApproveRules): CommandApprovalResult {
208 > let allApproved = true; commandAutoApprover.ts
209 > for (const subCommand of subCommands) {
210 > // Deny transient env var assignments
211 > if (transientEnvVarRegex.test(subCommand)) {
212 return 'denied';
213 }
220 allApproved = false;
221 }
223 > return allApproved ? 'approved' : 'noMatch';
224 > }
225
226 private _matchSingleCommand(command: string, rules: IAutoApproveRules): CommandApprovalResult {
239
240 private _matchesRule(command: string, rules: readonly IAutoApproveRule[]): boolean {
241 > for (const rule of rules) { commandAutoApprover.ts
242 if (rule.regex.test(command)) {
243 return true;
244 }
245 }
246 > return false; commandAutoApprover.ts
247 > }
248
249 // ---- Tree-sitter --------------------------------------------------------
250
251 private _extractSubCommands(commandLine: string): { subCommands: string[]; unsafeWriteDests: (string | undefined)[] } | undefined {
252 > if (!this._parser || !this._bashLanguage || !this._queryClass) { commandAutoApprover.ts
253 return undefined;
254 }
256 > try {
257 > this._parser.setLanguage(this._bashLanguage);
258 > const tree = this._parser.parse(commandLine);
259 > if (!tree) {
260 return undefined;
261 }
263 > try {
264 > const query = new this._queryClass(this._bashLanguage, '(command) @command (file_redirect) @file_redirect (heredoc_redirect) @heredoc_redirect (herestring_redirect) @herestring_redirect');
265 > const captures: QueryCapture[] = query.captures(tree.rootNode);
266 > const subCommands: string[] = [];
267 > const unsafeWriteDests: (string | undefined)[] = [];
268 > for (const capture of captures) {
269 > if (capture.name === 'command') {
270 > subCommands.push(capture.node.text);
271 > } else if (capture.name === 'file_redirect') {
272 // Writes to known-safe sinks (e.g. `> /dev/null`) and
273 // file-descriptor duplications (e.g. `2>&1`) are allowed.
280 // files, so they are not treated as write redirects here.
281 }
283 > query.delete();
284 > return subCommands.length > 0 || unsafeWriteDests.length > 0 ? { subCommands, unsafeWriteDests } : undefined;
285 > } finally {
286 > tree.delete();
287 > }
288 > } catch (err) {
289 this._logService.warn('[CommandAutoApprover] Tree-sitter parsing failed', err);
290 return undefined;
291 }
293
294 private async _initTreeSitter(): Promise<void> {
352
353 private _compileRules(ruleConfig: AgentHostTerminalAutoApproveRules | undefined): IAutoApproveRules {
354 > if (!ruleConfig) { commandAutoApprover.ts
355 if (!this._fallbackRules) {
356 this._fallbackRules = this._compileRuleEntries(DEFAULT_TERMINAL_AUTO_APPROVE_RULES);
359 }
360
361 > if (this._cachedRuleConfig === ruleConfig && this._cachedRules) { commandAutoApprover.ts
362 return this._cachedRules;
363 }
366 this._cachedRules = this._compileRuleEntries(ruleConfig);
367 return this._cachedRules;
369
370 private _compileRuleEntries(ruleConfig: Readonly<Record<string, AgentHostTerminalAutoApproveRuleValue>>): IAutoApproveRules {
371 > const allowRules: IAutoApproveRule[] = []; commandAutoApprover.ts
372 > const denyRules: IAutoApproveRule[] = [];
373 > const allowCommandLineRules: IAutoApproveRule[] = [];
374 > const denyCommandLineRules: IAutoApproveRule[] = [];
375 >
376 > for (const [key, value] of Object.entries(ruleConfig)) {
377 const regex = convertAutoApproveEntryToRegex(key);
378 if (value === true) {
396 }
397 }
399 > return { allowRules, denyRules, allowCommandLineRules, denyCommandLineRules };
400 > }
401 }
402