( context: ToolPermissionContext, )
| 482 | * user allow/deny/environment values from settings.autoMode. |
| 483 | */ |
| 484 | export async function buildYoloSystemPrompt( |
| 485 | context: ToolPermissionContext, |
| 486 | ): Promise<string> { |
| 487 | const usingExternal = isUsingExternalPermissions() |
| 488 | const systemPrompt = BASE_PROMPT.replace('<permissions_template>', () => |
| 489 | usingExternal |
| 490 | ? EXTERNAL_PERMISSIONS_TEMPLATE |
| 491 | : ANTHROPIC_PERMISSIONS_TEMPLATE, |
| 492 | ) |
| 493 | |
| 494 | const autoMode = getAutoModeConfig() |
| 495 | const includeBashPromptRules = feature('BASH_CLASSIFIER') |
| 496 | ? !usingExternal |
| 497 | : false |
| 498 | const includePowerShellGuidance = feature('POWERSHELL_AUTO_MODE') |
| 499 | ? !usingExternal |
| 500 | : false |
| 501 | const allowDescriptions = [ |
| 502 | ...(includeBashPromptRules ? getBashPromptAllowDescriptions(context) : []), |
| 503 | ...(autoMode?.allow ?? []), |
| 504 | ] |
| 505 | const denyDescriptions = [ |
| 506 | ...(includeBashPromptRules ? getBashPromptDenyDescriptions(context) : []), |
| 507 | ...(includePowerShellGuidance ? POWERSHELL_DENY_GUIDANCE : []), |
| 508 | ...(autoMode?.soft_deny ?? []), |
| 509 | ] |
| 510 | |
| 511 | // All three sections use the same <foo_to_replace>...</foo_to_replace> |
| 512 | // delimiter pattern. The external template wraps its defaults inside the |
| 513 | // tags, so user-provided values REPLACE the defaults entirely. The |
| 514 | // anthropic template keeps its defaults outside the tags and uses an empty |
| 515 | // tag pair at the end of each section, so user-provided values are |
| 516 | // strictly ADDITIVE. |
| 517 | const userAllow = allowDescriptions.length |
| 518 | ? allowDescriptions.map(d => `- ${d}`).join('\n') |
| 519 | : undefined |
| 520 | const userDeny = denyDescriptions.length |
| 521 | ? denyDescriptions.map(d => `- ${d}`).join('\n') |
| 522 | : undefined |
| 523 | const userEnvironment = autoMode?.environment?.length |
| 524 | ? autoMode.environment.map(e => `- ${e}`).join('\n') |
| 525 | : undefined |
| 526 | |
| 527 | return systemPrompt |
| 528 | .replace( |
| 529 | /<user_allow_rules_to_replace>([\s\S]*?)<\/user_allow_rules_to_replace>/, |
| 530 | (_m, defaults: string) => userAllow ?? defaults, |
| 531 | ) |
| 532 | .replace( |
| 533 | /<user_deny_rules_to_replace>([\s\S]*?)<\/user_deny_rules_to_replace>/, |
| 534 | (_m, defaults: string) => userDeny ?? defaults, |
| 535 | ) |
| 536 | .replace( |
| 537 | /<user_environment_to_replace>([\s\S]*?)<\/user_environment_to_replace>/, |
| 538 | (_m, defaults: string) => userEnvironment ?? defaults, |
| 539 | ) |
| 540 | } |
| 541 | // ============================================================================ |
no test coverage detected