bash-context.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Shared context type for bash permission helpers. Lives in its own
  3. * file to avoid runtime cyclic imports between `bash-permission.ts`,
  4. * `bash-write-target.ts`, and `bash-fast-allow.ts` — every consumer
  5. * pulls the type from here without depending on each other.
  6. */
  7. import type { PermissionRule } from '../types.js';
  8. /**
  9. * Optional context passed from {@link BashToolPermissionChecker} to
  10. * fine-tune the SOFT remote-execution pre-scan, the IO-redirect /
  11. * write-target gates, and the fast-allow shortcut. Without it, the
  12. * pre-scan still works but always trips on `<sep> bash <script>`
  13. * (the original conservative behaviour). With it, locally-produced
  14. * scripts can pass through.
  15. */
  16. export type BashCheckContext = {
  17. /** Host platform; required before platform-specific delete transforms are enabled. */
  18. platform?: NodeJS.Platform;
  19. /** Actual shell family used for the command; unknown keeps Windows delete fail-closed. */
  20. shellFamily?: 'posix' | 'cmd' | 'powershell' | 'unknown';
  21. /** Number of top-level command segments in the original shell input. */
  22. topLevelSegmentCount?: number;
  23. sessionId?: string;
  24. workingDirectory?: string;
  25. allowedWorkingPaths?: readonly string[];
  26. /** User home directory. Lets the write-target gate statically expand `~/` so a leading tilde is not a dynamic-shape bail and can match `writeAllowRules`. */
  27. homeDir?: string;
  28. /** Host-owned file probe for local-script relaxation. Missing probe keeps the check conservative. */
  29. isFile?: (filePath: string) => boolean;
  30. /** User-granted `write` tool allow rules. The bash gate cross-references them so shell forms (`cp` / `mv` / `tee` / `cat > <dst>`) and direct tool writes stay symmetric on user-approved destinations (e.g. `write(/Users/adao/Downloads/**)`). */
  31. writeAllowRules?: readonly PermissionRule[];
  32. };