(policyRule: string)
| 38 | * Adds a policy rule to the permissions.yaml file |
| 39 | */ |
| 40 | export async function addPolicyToYaml(policyRule: string): Promise<void> { |
| 41 | try { |
| 42 | // Load existing config or create empty one |
| 43 | const config: PermissionsYamlConfig = loadPermissionsYaml() || {}; |
| 44 | |
| 45 | // Ensure allow array exists |
| 46 | if (!config.allow) { |
| 47 | config.allow = []; |
| 48 | } |
| 49 | |
| 50 | // Add the policy if it doesn't already exist |
| 51 | if (config.allow.includes(policyRule)) { |
| 52 | logger.debug(`Policy rule already exists: ${policyRule}`); |
| 53 | } else { |
| 54 | config.allow.push(policyRule); |
| 55 | |
| 56 | // Write the updated config back to the file |
| 57 | const yamlContent = YAML.stringify(config); |
| 58 | |
| 59 | // Add header comment |
| 60 | const finalContent = `# Continue CLI Permissions Configuration |
| 61 | # This file is managed by the Continue CLI and should not be edited manually. |
| 62 | # Use the TUI to modify permissions interactively. |
| 63 | |
| 64 | ${yamlContent}`; |
| 65 | |
| 66 | await fs.promises.writeFile(PERMISSIONS_YAML_PATH, finalContent, "utf-8"); |
| 67 | logger.info(`Added policy rule to permissions.yaml: ${policyRule}`); |
| 68 | } |
| 69 | } catch (error) { |
| 70 | logger.error("Failed to add policy to permissions.yaml", { |
| 71 | error, |
| 72 | policyRule, |
| 73 | }); |
| 74 | throw error; |
| 75 | } |
| 76 | } |
no test coverage detected