//! Composes selected permission text and prepared runtime facts into a stored fragment body. //! Remote paths use executor context; the local adapter retains host filesystem resolution. //! Displayed paths share a byte budget and are omitted only at whole-entry boundaries. //! Catalog text uses literal substitution; bundled sandbox templates are parsed and cached here. use crate::ResolvedMessage; use crate::ResolvedModelMessages; use crate::model_messages::permissions::DANGER_FULL_ACCESS_TEMPLATE; use crate::model_messages::permissions::READ_ONLY_TEMPLATE; use crate::model_messages::permissions::ResolvedApprovalMessages; use crate::model_messages::permissions::ResolvedPermissionMessages; use crate::model_messages::permissions::WORKSPACE_WRITE_TEMPLATE; use akode_context_fragments::ContextualUserFragment; use akode_execpolicy::Policy; use akode_protocol::config_types::ApprovalsReviewer; use akode_protocol::config_types::SandboxMode; use akode_protocol::models::ContentItem; use akode_protocol::models::ContentItemKind; use akode_protocol::models::PermissionProfile; use akode_protocol::models::format_allow_prefixes; use akode_protocol::models::input_text; use akode_protocol::permissions::FileSystemSandboxPolicyContext; use akode_protocol::protocol::AskForApproval; use akode_protocol::protocol::GranularApprovalConfig; use akode_protocol::protocol::NetworkAccess; use akode_utils_template::Template; use approval_instructions::ApprovalInstructions; use path_warnings::OMITTED_PERMISSION_PATHS; use path_warnings::denied_reads_text; use path_warnings::omitted_paths_text; use std::collections::HashSet; use std::path::Path; use std::sync::LazyLock; use writable_roots::writable_roots_text; mod approval_instructions; mod path_warnings; mod writable_roots; const REQUEST_PERMISSION_RULE: &str = include_str!("../templates/permissions/approval_policy/on_request_rule_request_permission.md"); const REQUEST_PERMISSIONS_TOOL: &str = "# request_permissions Tool\n\nThe built-in `request_permissions` tool is available in this session. Invoke it when you need to request additional `network` or `file_system` permissions before later shell-like commands need them. Request only the specific permissions required for the task."; const AUTO_REVIEW_SUFFIX: &str = "`approvals_reviewer` is `auto_review`: Sandbox escalations with require_escalated will be reviewed for compliance with the policy. If a rejection happens, you should proceed only with a materially safer alternative, or inform the user of the risk and send a final message to ask for approval."; const GRANULAR_INTRO: &str = "# Approval Requests\n\nApproval policy is `granular`. Categories set to `false` are automatically rejected instead of prompting the user."; const GRANULAR_PROMPTED_CATEGORIES: &str = "These approval categories may still prompt the user when needed:"; const GRANULAR_REJECTED_CATEGORIES: &str = "These approval categories are automatically rejected instead of prompting the user:"; const MAX_PERMISSION_PATH_BYTES: usize = 32 * 1024; static DANGER_FULL_ACCESS: LazyLock