( dirPath: string, destination: PermissionUpdateDestination = 'session', )
| 359 | * @returns A PermissionUpdate for a Read rule, or undefined for the root directory |
| 360 | */ |
| 361 | export function createReadRuleSuggestion( |
| 362 | dirPath: string, |
| 363 | destination: PermissionUpdateDestination = 'session', |
| 364 | ): PermissionUpdate | undefined { |
| 365 | // Convert to POSIX format for pattern matching (handles Windows internally) |
| 366 | const pathForPattern = toPosixPath(dirPath) |
| 367 | |
| 368 | // Root directory is too broad to be a reasonable permission target |
| 369 | if (pathForPattern === '/') { |
| 370 | return undefined |
| 371 | } |
| 372 | |
| 373 | // For absolute paths, prepend an extra / to create //path/** pattern |
| 374 | const ruleContent = posix.isAbsolute(pathForPattern) |
| 375 | ? `/${pathForPattern}/**` |
| 376 | : `${pathForPattern}/**` |
| 377 | |
| 378 | return { |
| 379 | type: 'addRules', |
| 380 | rules: [ |
| 381 | { |
| 382 | toolName: 'Read', |
| 383 | ruleContent, |
| 384 | }, |
| 385 | ], |
| 386 | behavior: 'allow', |
| 387 | destination, |
| 388 | } |
| 389 | } |
| 390 |
no test coverage detected