@google/gemini-cli-core 0.70.0-preview.0 → 0.71.0-nightly.20261120.gd4cb1713f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/docs/changelogs/index.md +46 -0
  2. package/dist/docs/changelogs/latest.md +82 -100
  3. package/dist/docs/changelogs/preview.md +82 -115
  4. package/dist/google-gemini-cli-core-0.71.0-nightly.20261118.g615d6bc8c.tgz +0 -0
  5. package/dist/src/confirmation-bus/types.d.ts +1 -0
  6. package/dist/src/confirmation-bus/types.js.map +1 -1
  7. package/dist/src/generated/git-commit.d.ts +2 -2
  8. package/dist/src/generated/git-commit.js +2 -2
  9. package/dist/src/generated/git-commit.js.map +1 -1
  10. package/dist/src/policy/policy-engine.d.ts +1 -0
  11. package/dist/src/policy/policy-engine.js +15 -6
  12. package/dist/src/policy/policy-engine.js.map +1 -1
  13. package/dist/src/sandbox/utils/commandUtils.js +35 -25
  14. package/dist/src/sandbox/utils/commandUtils.js.map +1 -1
  15. package/dist/src/sandbox/windows/WindowsSandboxManager.d.ts +1 -0
  16. package/dist/src/sandbox/windows/WindowsSandboxManager.js +9 -2
  17. package/dist/src/sandbox/windows/WindowsSandboxManager.js.map +1 -1
  18. package/dist/src/sandbox/windows/commandSafety.js +4 -2
  19. package/dist/src/sandbox/windows/commandSafety.js.map +1 -1
  20. package/dist/src/scheduler/policy.js +6 -0
  21. package/dist/src/scheduler/policy.js.map +1 -1
  22. package/dist/src/scheduler/scheduler.js +79 -59
  23. package/dist/src/scheduler/scheduler.js.map +1 -1
  24. package/dist/src/services/fileDiscoveryService.test.js +15 -0
  25. package/dist/src/services/fileDiscoveryService.test.js.map +1 -1
  26. package/dist/src/tools/shell-powershell-parsing.integration.test.d.ts +6 -0
  27. package/dist/src/tools/shell-powershell-parsing.integration.test.js +576 -0
  28. package/dist/src/tools/shell-powershell-parsing.integration.test.js.map +1 -0
  29. package/dist/src/tools/shell.d.ts +6 -1
  30. package/dist/src/tools/shell.js +281 -189
  31. package/dist/src/tools/shell.js.map +1 -1
  32. package/dist/src/tools/tools.d.ts +1 -0
  33. package/dist/src/tools/tools.js.map +1 -1
  34. package/dist/src/utils/gitIgnoreParser.js +33 -1
  35. package/dist/src/utils/gitIgnoreParser.js.map +1 -1
  36. package/dist/src/utils/gitIgnoreParser.test.js +32 -0
  37. package/dist/src/utils/gitIgnoreParser.test.js.map +1 -1
  38. package/dist/src/utils/ignorePathUtils.d.ts +1 -1
  39. package/dist/src/utils/ignorePathUtils.js +3 -2
  40. package/dist/src/utils/ignorePathUtils.js.map +1 -1
  41. package/dist/src/utils/ignorePathUtils.test.js +8 -0
  42. package/dist/src/utils/ignorePathUtils.test.js.map +1 -1
  43. package/dist/src/utils/shell-parse-cache.d.ts +37 -0
  44. package/dist/src/utils/shell-parse-cache.js +55 -0
  45. package/dist/src/utils/shell-parse-cache.js.map +1 -0
  46. package/dist/src/utils/shell-parse-cache.test.d.ts +6 -0
  47. package/dist/src/utils/shell-parse-cache.test.js +478 -0
  48. package/dist/src/utils/shell-parse-cache.test.js.map +1 -0
  49. package/dist/src/utils/shell-utils.d.ts +27 -29
  50. package/dist/src/utils/shell-utils.js +385 -89
  51. package/dist/src/utils/shell-utils.js.map +1 -1
  52. package/dist/src/utils/untrustedContextTracker.d.ts +2 -6
  53. package/dist/src/utils/untrustedContextTracker.js +65 -27
  54. package/dist/src/utils/untrustedContextTracker.js.map +1 -1
  55. package/dist/tsconfig.tsbuildinfo +1 -1
  56. package/package.json +1 -1
@@ -8,6 +8,8 @@ import fs from 'node:fs';
8
8
  import path from 'node:path';
9
9
  import { quote, parse } from 'shell-quote';
10
10
  import { spawn, spawnSync, } from 'node:child_process';
11
+ import { CommandParseCache, getActiveCommandParseCache, runWithCommandParseCache, } from './shell-parse-cache.js';
12
+ export { CommandParseCache, getActiveCommandParseCache, runWithCommandParseCache, };
11
13
  /**
12
14
  * Extracts the primary command name from a potentially wrapped shell command.
13
15
  * Strips shell wrappers and handles shopt/set/etc.
@@ -20,7 +22,7 @@ export async function getCommandName(command, args) {
20
22
  await initializeShellParsers();
21
23
  const fullCmd = [command, ...args].join(' ');
22
24
  const stripped = stripShellWrapper(fullCmd);
23
- const roots = getCommandRoots(stripped).filter((r) => r !== 'shopt' && r !== 'set');
25
+ const roots = (await getCommandRootsAsync(stripped)).filter((r) => r !== 'shopt' && r !== 'set');
24
26
  if (roots.length > 0) {
25
27
  return roots[0];
26
28
  }
@@ -449,7 +451,74 @@ export function parseBashCommandDetails(command) {
449
451
  hasError,
450
452
  };
451
453
  }
452
- function parsePowerShellCommandDetails(command, executable) {
454
+ function isRawPowerShellCommand(value) {
455
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
456
+ }
457
+ function isRawPowerShellParsePayload(value) {
458
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
459
+ }
460
+ function parsePowerShellParserOutput(rawStdout, originalCommand) {
461
+ const output = rawStdout.trim();
462
+ if (!output) {
463
+ return { details: [], hasError: true };
464
+ }
465
+ let parsedUnknown;
466
+ try {
467
+ parsedUnknown = JSON.parse(output);
468
+ }
469
+ catch {
470
+ return { details: [], hasError: true };
471
+ }
472
+ if (!isRawPowerShellParsePayload(parsedUnknown) ||
473
+ parsedUnknown.success !== true) {
474
+ return { details: [], hasError: true };
475
+ }
476
+ const rawCommandsField = parsedUnknown.commands;
477
+ const rawCommands = Array.isArray(rawCommandsField)
478
+ ? rawCommandsField
479
+ : isRawPowerShellCommand(rawCommandsField)
480
+ ? [rawCommandsField]
481
+ : [];
482
+ const details = rawCommands
483
+ .map((commandDetail) => {
484
+ if (!isRawPowerShellCommand(commandDetail) ||
485
+ typeof commandDetail.name !== 'string') {
486
+ return null;
487
+ }
488
+ const name = normalizeCommandName(commandDetail.name);
489
+ const text = typeof commandDetail.text === 'string'
490
+ ? commandDetail.text.trim()
491
+ : originalCommand;
492
+ const rawArgs = commandDetail.args;
493
+ return {
494
+ name,
495
+ text,
496
+ startIndex: typeof commandDetail.startIndex === 'number'
497
+ ? commandDetail.startIndex
498
+ : 0,
499
+ args: Array.isArray(rawArgs)
500
+ ? rawArgs.filter((arg) => typeof arg === 'string')
501
+ : undefined,
502
+ };
503
+ })
504
+ .filter((detail) => detail !== null)
505
+ .sort((a, b) => a.startIndex - b.startIndex);
506
+ return {
507
+ details,
508
+ hasError: details.length === 0,
509
+ hasRedirection: typeof parsedUnknown.hasRedirection === 'boolean'
510
+ ? parsedUnknown.hasRedirection
511
+ : undefined,
512
+ hasCommandSubstitution: typeof parsedUnknown.hasCommandSubstitution === 'boolean'
513
+ ? parsedUnknown.hasCommandSubstitution
514
+ : false,
515
+ };
516
+ }
517
+ // Coalesces strictly concurrent in-flight async PowerShell AST parses across
518
+ // callers (e.g. Scheduler validation and UI turn-activity hooks) and removes
519
+ // entries immediately on completion so no process-wide parse state is retained.
520
+ const globalInFlightPowerShellParses = new Map();
521
+ function parsePowerShellCommandDetails(command, executable, cache) {
453
522
  const trimmed = command.trim();
454
523
  if (!trimmed) {
455
524
  return {
@@ -457,6 +526,10 @@ function parsePowerShellCommandDetails(command, executable) {
457
526
  hasError: true,
458
527
  };
459
528
  }
529
+ const activeCache = cache ?? getActiveCommandParseCache();
530
+ if (activeCache?.hasCompleted(executable, command)) {
531
+ return activeCache.getCompleted(executable, command) ?? null;
532
+ }
460
533
  try {
461
534
  const result = spawnSync(executable, [
462
535
  '-NoLogo',
@@ -472,65 +545,129 @@ function parsePowerShellCommandDetails(command, executable) {
472
545
  encoding: 'utf-8',
473
546
  });
474
547
  if (result.error || result.status !== 0) {
548
+ activeCache?.setCompleted(executable, command, null);
475
549
  return null;
476
550
  }
477
- const output = (result.stdout ?? '').toString().trim();
478
- if (!output) {
479
- return { details: [], hasError: true };
551
+ const parsed = parsePowerShellParserOutput((result.stdout ?? '').toString(), command);
552
+ activeCache?.setCompleted(executable, command, parsed);
553
+ return parsed;
554
+ }
555
+ catch {
556
+ activeCache?.setCompleted(executable, command, null);
557
+ return null;
558
+ }
559
+ }
560
+ async function parsePowerShellCommandDetailsAsync(command, executable, cache, signal) {
561
+ const trimmed = command.trim();
562
+ if (!trimmed) {
563
+ return {
564
+ details: [],
565
+ hasError: true,
566
+ };
567
+ }
568
+ if (signal?.aborted) {
569
+ return null;
570
+ }
571
+ const activeCache = cache ?? getActiveCommandParseCache();
572
+ if (activeCache?.hasCompleted(executable, command)) {
573
+ return activeCache.getCompleted(executable, command) ?? null;
574
+ }
575
+ const existingInFlight = activeCache?.getInFlight(executable, command);
576
+ if (existingInFlight) {
577
+ return existingInFlight;
578
+ }
579
+ const globalKey = `${executable}\0${command}`;
580
+ if (!signal) {
581
+ const existingGlobalInFlight = globalInFlightPowerShellParses.get(globalKey);
582
+ if (existingGlobalInFlight) {
583
+ const joinedPromise = existingGlobalInFlight.then((result) => {
584
+ activeCache?.setCompleted(executable, command, result);
585
+ return result;
586
+ });
587
+ if (activeCache) {
588
+ return activeCache.trackInFlight(executable, command, joinedPromise);
589
+ }
590
+ return joinedPromise;
480
591
  }
481
- let parsed = null;
592
+ }
593
+ const parsePromise = new Promise((resolve) => {
594
+ let settled = false;
595
+ const finish = (value, cacheResult = true) => {
596
+ if (!settled) {
597
+ settled = true;
598
+ if (cacheResult && !signal?.aborted) {
599
+ activeCache?.setCompleted(executable, command, value);
600
+ }
601
+ resolve(value);
602
+ }
603
+ };
604
+ let child;
482
605
  try {
483
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
484
- parsed = JSON.parse(output);
606
+ child = spawn(executable, [
607
+ '-NoLogo',
608
+ '-NoProfile',
609
+ '-NonInteractive',
610
+ '-EncodedCommand',
611
+ POWERSHELL_PARSER_SCRIPT,
612
+ ], {
613
+ env: {
614
+ ...process.env,
615
+ [POWERSHELL_COMMAND_ENV]: command,
616
+ },
617
+ stdio: ['ignore', 'pipe', 'pipe'],
618
+ windowsHide: true,
619
+ ...(signal ? { signal } : {}),
620
+ });
485
621
  }
486
622
  catch {
487
- return { details: [], hasError: true };
488
- }
489
- if (!parsed?.success) {
490
- return { details: [], hasError: true };
491
- }
492
- const rawCommands = Array.isArray(parsed.commands)
493
- ? parsed.commands
494
- : parsed.commands
495
- ? [parsed.commands]
496
- : [];
497
- const details = rawCommands
498
- .map((commandDetail) => {
499
- if (!commandDetail || typeof commandDetail.name !== 'string') {
500
- return null;
623
+ finish(null, !signal?.aborted);
624
+ return;
625
+ }
626
+ let stdout = '';
627
+ child.stdout?.setEncoding('utf-8');
628
+ child.stdout?.on('data', (chunk) => {
629
+ stdout += chunk.toString();
630
+ });
631
+ child.stderr?.on('data', () => {
632
+ // Drain stderr to avoid blocking child exit if diagnostics are written.
633
+ });
634
+ child.on('error', (err) => {
635
+ if (err.name === 'AbortError' || signal?.aborted) {
636
+ finish(null, false);
637
+ return;
501
638
  }
502
- const name = normalizeCommandName(commandDetail.name);
503
- const text = typeof commandDetail.text === 'string'
504
- ? commandDetail.text.trim()
505
- : command;
506
- return {
507
- name,
508
- text,
509
- startIndex: typeof commandDetail.startIndex === 'number'
510
- ? commandDetail.startIndex
511
- : 0,
512
- args: Array.isArray(commandDetail.args)
513
- ? commandDetail.args
514
- : undefined,
515
- };
516
- })
517
- .filter((detail) => detail !== null)
518
- .sort((a, b) => a.startIndex - b.startIndex);
519
- return {
520
- details,
521
- hasError: details.length === 0,
522
- hasRedirection: parsed.hasRedirection,
523
- hasCommandSubstitution: parsed.hasCommandSubstitution ?? false,
524
- };
639
+ finish(null);
640
+ });
641
+ child.on('close', (code) => {
642
+ if (signal?.aborted) {
643
+ finish(null, false);
644
+ return;
645
+ }
646
+ if (code !== 0) {
647
+ finish(null);
648
+ return;
649
+ }
650
+ const parsed = parsePowerShellParserOutput(stdout, command);
651
+ finish(parsed);
652
+ });
653
+ });
654
+ if (!signal) {
655
+ globalInFlightPowerShellParses.set(globalKey, parsePromise);
656
+ void parsePromise.finally(() => {
657
+ if (globalInFlightPowerShellParses.get(globalKey) === parsePromise) {
658
+ globalInFlightPowerShellParses.delete(globalKey);
659
+ }
660
+ });
525
661
  }
526
- catch {
527
- return null;
662
+ if (activeCache) {
663
+ return activeCache.trackInFlight(executable, command, parsePromise);
528
664
  }
665
+ return parsePromise;
529
666
  }
530
- export function parseCommandDetails(command) {
667
+ export function parseCommandDetails(command, cache) {
531
668
  const configuration = getShellConfiguration();
532
669
  if (configuration.shell === 'powershell') {
533
- const result = parsePowerShellCommandDetails(command, configuration.executable);
670
+ const result = parsePowerShellCommandDetails(command, configuration.executable, cache);
534
671
  if (!result || result.hasError) {
535
672
  // Never fall back to the Bash parser when PowerShell command substitution
536
673
  // is detected, because Bash and PowerShell have incompatible quoting,
@@ -553,6 +690,38 @@ export function parseCommandDetails(command) {
553
690
  }
554
691
  return null;
555
692
  }
693
+ export async function parseCommandDetailsAsync(command, cache, signal) {
694
+ if (signal?.aborted) {
695
+ return null;
696
+ }
697
+ const configuration = getShellConfiguration();
698
+ if (configuration.shell === 'powershell') {
699
+ const result = await parsePowerShellCommandDetailsAsync(command, configuration.executable, cache, signal);
700
+ if (signal?.aborted) {
701
+ return null;
702
+ }
703
+ if (!result || result.hasError) {
704
+ if (detectPowerShellSubstitution(command)) {
705
+ return result ?? { details: [], hasError: true };
706
+ }
707
+ await initializeShellParsers();
708
+ const bashResult = parseBashCommandDetails(command);
709
+ if (bashResult && !bashResult.hasError) {
710
+ return bashResult;
711
+ }
712
+ }
713
+ return result;
714
+ }
715
+ if (configuration.shell === 'bash') {
716
+ await initializeShellParsers();
717
+ return parseBashCommandDetails(command);
718
+ }
719
+ return null;
720
+ }
721
+ const defaultParseCommandDetailsRef = parseCommandDetails;
722
+ export function isDefaultParseCommandDetails(fn) {
723
+ return fn === defaultParseCommandDetailsRef;
724
+ }
556
725
  /**
557
726
  * Determines the appropriate shell configuration for the current platform.
558
727
  *
@@ -653,7 +822,28 @@ export function escapeShellArg(arg, shell) {
653
822
  * Checks if a command contains redirection operators.
654
823
  * Uses shell-specific parsers where possible, falling back to a broad regex check.
655
824
  */
656
- export function hasRedirection(command) {
825
+ function hasBashTreeRedirection(command, fallbackCheck) {
826
+ const tree = parseCommandTree(command);
827
+ if (!tree)
828
+ return fallbackCheck();
829
+ const stack = [tree.rootNode];
830
+ while (stack.length > 0) {
831
+ const current = stack.pop();
832
+ if (current.type === 'redirected_statement' ||
833
+ current.type === 'file_redirect' ||
834
+ current.type === 'heredoc_redirect' ||
835
+ current.type === 'herestring_redirect') {
836
+ return true;
837
+ }
838
+ for (let i = current.childCount - 1; i >= 0; i -= 1) {
839
+ const child = current.child(i);
840
+ if (child)
841
+ stack.push(child);
842
+ }
843
+ }
844
+ return false;
845
+ }
846
+ export function hasRedirection(command, cache) {
657
847
  const fallbackCheck = () => /[><]/.test(command);
658
848
  // If there are no redirection characters at all, we can skip parsing.
659
849
  if (!fallbackCheck()) {
@@ -661,32 +851,40 @@ export function hasRedirection(command) {
661
851
  }
662
852
  const configuration = getShellConfiguration();
663
853
  if (configuration.shell === 'powershell') {
664
- const parsed = parsePowerShellCommandDetails(command, configuration.executable);
854
+ const parsed = parsePowerShellCommandDetails(command, configuration.executable, cache);
665
855
  return parsed && !parsed.hasError
666
856
  ? !!parsed.hasRedirection
667
857
  : fallbackCheck();
668
858
  }
669
859
  if (configuration.shell === 'bash' && bashLanguage) {
670
- const tree = parseCommandTree(command);
671
- if (!tree)
672
- return fallbackCheck();
673
- const stack = [tree.rootNode];
674
- while (stack.length > 0) {
675
- const current = stack.pop();
676
- if (current.type === 'redirected_statement' ||
677
- current.type === 'file_redirect' ||
678
- current.type === 'heredoc_redirect' ||
679
- current.type === 'herestring_redirect') {
680
- return true;
681
- }
682
- for (let i = current.childCount - 1; i >= 0; i -= 1) {
683
- const child = current.child(i);
684
- if (child)
685
- stack.push(child);
686
- }
687
- }
860
+ return hasBashTreeRedirection(command, fallbackCheck);
861
+ }
862
+ return fallbackCheck();
863
+ }
864
+ export async function hasRedirectionAsync(command, cache, signal) {
865
+ if (signal?.aborted) {
688
866
  return false;
689
867
  }
868
+ const fallbackCheck = () => /[><]/.test(command);
869
+ if (!fallbackCheck()) {
870
+ return false;
871
+ }
872
+ const configuration = getShellConfiguration();
873
+ if (configuration.shell === 'powershell') {
874
+ const parsed = await parsePowerShellCommandDetailsAsync(command, configuration.executable, cache, signal);
875
+ if (signal?.aborted) {
876
+ return false;
877
+ }
878
+ return parsed && !parsed.hasError
879
+ ? !!parsed.hasRedirection
880
+ : fallbackCheck();
881
+ }
882
+ if (configuration.shell === 'bash') {
883
+ await initializeShellParsers();
884
+ if (bashLanguage) {
885
+ return hasBashTreeRedirection(command, fallbackCheck);
886
+ }
887
+ }
690
888
  return fallbackCheck();
691
889
  }
692
890
  /**
@@ -881,8 +1079,18 @@ export function hasUnresolvedShellExpansion(command) {
881
1079
  tree.delete();
882
1080
  }
883
1081
  }
884
- export function splitCommands(command) {
885
- const parsed = parseCommandDetails(command);
1082
+ export function splitCommands(command, cache) {
1083
+ const parsed = parseCommandDetails(command, cache);
1084
+ if (!parsed || parsed.hasError) {
1085
+ return [];
1086
+ }
1087
+ return parsed.details
1088
+ .filter((detail) => !REDIRECTION_NAMES.has(detail.name))
1089
+ .map((detail) => detail.text)
1090
+ .filter(Boolean);
1091
+ }
1092
+ export async function splitCommandsAsync(command, cache, signal) {
1093
+ const parsed = await parseCommandDetailsAsync(command, cache, signal);
886
1094
  if (!parsed || parsed.hasError) {
887
1095
  return [];
888
1096
  }
@@ -899,18 +1107,38 @@ export function splitCommands(command) {
899
1107
  * @example getCommandRoot("ls -la /tmp") returns "ls"
900
1108
  * @example getCommandRoot("git status && npm test") returns "git"
901
1109
  */
902
- export function getCommandRoot(command) {
903
- const parsed = parseCommandDetails(command);
1110
+ export function getCommandRoot(command, cache) {
1111
+ const parsed = parseCommandDetails(command, cache);
904
1112
  if (!parsed || parsed.hasError || parsed.details.length === 0) {
905
1113
  return undefined;
906
1114
  }
907
1115
  return parsed.details[0]?.name;
908
1116
  }
909
- export function getCommandRoots(command) {
1117
+ export async function getCommandRootAsync(command, cache, signal) {
1118
+ const parsed = await parseCommandDetailsAsync(command, cache, signal);
1119
+ if (!parsed || parsed.hasError || parsed.details.length === 0) {
1120
+ return undefined;
1121
+ }
1122
+ return parsed.details[0]?.name;
1123
+ }
1124
+ export function getCommandRoots(command, cache) {
1125
+ if (!command) {
1126
+ return [];
1127
+ }
1128
+ const parsed = parseCommandDetails(command, cache);
1129
+ if (!parsed || parsed.hasError) {
1130
+ return [];
1131
+ }
1132
+ return parsed.details
1133
+ .map((detail) => detail.name)
1134
+ .filter((name) => !REDIRECTION_NAMES.has(name))
1135
+ .filter(Boolean);
1136
+ }
1137
+ export async function getCommandRootsAsync(command, cache, signal) {
910
1138
  if (!command) {
911
1139
  return [];
912
1140
  }
913
- const parsed = parseCommandDetails(command);
1141
+ const parsed = await parseCommandDetailsAsync(command, cache, signal);
914
1142
  if (!parsed || parsed.hasError) {
915
1143
  return [];
916
1144
  }
@@ -919,6 +1147,18 @@ export function getCommandRoots(command) {
919
1147
  .filter((name) => !REDIRECTION_NAMES.has(name))
920
1148
  .filter(Boolean);
921
1149
  }
1150
+ const defaultHasRedirectionRef = hasRedirection;
1151
+ const defaultSplitCommandsRef = splitCommands;
1152
+ const defaultGetCommandRootsRef = getCommandRoots;
1153
+ export function isDefaultHasRedirection(fn) {
1154
+ return fn === defaultHasRedirectionRef;
1155
+ }
1156
+ export function isDefaultSplitCommands(fn) {
1157
+ return fn === defaultSplitCommandsRef;
1158
+ }
1159
+ export function isDefaultGetCommandRoots(fn) {
1160
+ return fn === defaultGetCommandRootsRef;
1161
+ }
922
1162
  const PS_WRAPPER_FLAGS = new Set([
923
1163
  '-nologo',
924
1164
  '-noprofile',
@@ -2341,15 +2581,7 @@ function isInteractiveGeminiSegment(segment) {
2341
2581
  }
2342
2582
  return true;
2343
2583
  }
2344
- /**
2345
- * Checks whether a shell command string attempts to invoke an interactive
2346
- * `gemini` CLI session or an invalid management subcommand such as
2347
- * `gemini config ...`.
2348
- */
2349
- export function isInteractiveGeminiCommand(command) {
2350
- if (!command || !command.trim()) {
2351
- return false;
2352
- }
2584
+ function unwrapCommandForGeminiCheck(command) {
2353
2585
  let unwrapped = command.trim();
2354
2586
  for (let depth = 0; depth < 3; depth++) {
2355
2587
  const next = stripShellWrapper(unwrapped);
@@ -2358,11 +2590,75 @@ export function isInteractiveGeminiCommand(command) {
2358
2590
  }
2359
2591
  unwrapped = next;
2360
2592
  }
2361
- const parsedSegments = splitCommands(unwrapped);
2593
+ return unwrapped;
2594
+ }
2595
+ const GEMINI_SUBSEQUENCE = 'gemini';
2596
+ /**
2597
+ * Checks in O(n) time whether `input` contains the characters `g`, `e`, `m`,
2598
+ * `i`, `n`, `i` in order (case-insensitively, including across newlines)
2599
+ * without regex backtracking.
2600
+ */
2601
+ function containsGeminiSubsequence(input) {
2602
+ const lower = input.toLowerCase();
2603
+ let pos = 0;
2604
+ for (const ch of GEMINI_SUBSEQUENCE) {
2605
+ const found = lower.indexOf(ch, pos);
2606
+ if (found === -1) {
2607
+ return false;
2608
+ }
2609
+ pos = found + 1;
2610
+ }
2611
+ return true;
2612
+ }
2613
+ /**
2614
+ * Performs purely in-process checks for interactive `gemini` commands without
2615
+ * spawning any external shell parser. Returns `false` when the command cannot
2616
+ * invoke `gemini`, `true` when synchronous segment tokenization already detects
2617
+ * an interactive `gemini` invocation, or `undefined` when AST command splitting
2618
+ * is still required to disambiguate.
2619
+ */
2620
+ export function isKnownInteractiveGeminiCommandSync(command) {
2621
+ if (!command || !command.trim()) {
2622
+ return false;
2623
+ }
2624
+ const unwrapped = unwrapCommandForGeminiCheck(command);
2625
+ if (!containsGeminiSubsequence(unwrapped)) {
2626
+ return false;
2627
+ }
2362
2628
  const fallbackSegments = splitShellCommandSegments(unwrapped);
2363
- const allSegments = parsedSegments.length > 0
2364
- ? [...parsedSegments, ...fallbackSegments]
2365
- : fallbackSegments;
2366
- return allSegments.some((segment) => isInteractiveGeminiSegment(segment));
2629
+ if (fallbackSegments.some((segment) => isInteractiveGeminiSegment(segment))) {
2630
+ return true;
2631
+ }
2632
+ return undefined;
2633
+ }
2634
+ /**
2635
+ * Checks whether a shell command string attempts to invoke an interactive
2636
+ * `gemini` CLI session or an invalid management subcommand such as
2637
+ * `gemini config ...`.
2638
+ */
2639
+ export function isInteractiveGeminiCommand(command, cache) {
2640
+ const fastResult = isKnownInteractiveGeminiCommandSync(command);
2641
+ if (fastResult !== undefined) {
2642
+ return fastResult;
2643
+ }
2644
+ const unwrapped = unwrapCommandForGeminiCheck(command);
2645
+ const parsedSegments = splitCommands(unwrapped, cache);
2646
+ return parsedSegments.some((segment) => isInteractiveGeminiSegment(segment));
2647
+ }
2648
+ export async function isInteractiveGeminiCommandAsync(command, cache, signal) {
2649
+ if (signal?.aborted) {
2650
+ return false;
2651
+ }
2652
+ const fastResult = isKnownInteractiveGeminiCommandSync(command);
2653
+ if (fastResult !== undefined) {
2654
+ return fastResult;
2655
+ }
2656
+ const unwrapped = unwrapCommandForGeminiCheck(command);
2657
+ const parsedSegments = await splitCommandsAsync(unwrapped, cache, signal);
2658
+ return parsedSegments.some((segment) => isInteractiveGeminiSegment(segment));
2659
+ }
2660
+ const defaultIsInteractiveGeminiCommandRef = isInteractiveGeminiCommand;
2661
+ export function isDefaultIsInteractiveGeminiCommand(fn) {
2662
+ return fn === defaultIsInteractiveGeminiCommandRef;
2367
2663
  }
2368
2664
  //# sourceMappingURL=shell-utils.js.map