{
  "name": "forge-code-safety",
  "language": "rust",
  "version": "0.2.0",
  "description": "Runtime safety primitives for coding agents \u2014 worktree isolation, write scoping, delete prevention, approval gates, and audit logging",
  "manifest": "forge-rs/crates/forge-code-safety/Cargo.toml",
  "manifestSha256": "543c3a46f92b916a032cb2802d19a0291120cd0ab306b30cd0c4eb45160b699e",
  "status": "source-reference",
  "registryPublicationVerified": false,
  "route": "/libraries/rust/forge-code-safety",
  "features": {},
  "files": [
    {
      "path": "forge-rs/crates/forge-code-safety/src/approval.rs",
      "sha256": "a0eb59fe0fcba3cbe2cf6385565358fea5dfad1003a1ea3357c54cd316a7c592",
      "artifactSha256": "c3683edf06296f75457f7598fb6a51197644c98e6fcdbb19389e0f5edfad5cc0",
      "url": "/reference/source/forge-rs/crates/forge-code-safety/src/approval.rs.txt",
      "declarations": [
        {
          "name": "::ApprovalRequest",
          "line": 49,
          "signature": "#[derive(Debug, Clone, Serialize, Deserialize)]\npub struct ApprovalRequest {\n/// The DID of the agent requesting approval.\n\npub agent_did: String,\n/// The operation type (e.g., \"delete\", \"modify_protected\", \"force_push\").\n\npub operation: String,\n/// The file or directory path the operation targets.\n\npub path: PathBuf,\n/// The assessed risk level of the operation.\n\npub risk_level: RiskLevel,\n/// The agent's justification for why the operation is needed.\n\npub justification: String\n}",
          "documentation": "A request for approval of a file operation."
        },
        {
          "name": "::ApprovalResponse",
          "line": 64,
          "signature": "#[derive(Debug, Clone, Serialize, Deserialize)]\npub struct ApprovalResponse {\n/// Unique identifier for this approval decision.\n\npub decision_id: String,\n/// Whether the operation was approved.\n\npub approved: bool,\n/// The entity that made the approval decision.\n\npub reviewer: String,\n/// Why the decision was made.\n\npub reason: String,\n/// When the decision was made.\n\npub decided_at: DateTime<Utc>,\n/// Optional conditions attached to the approval.\n\npub conditions: Vec<String>\n}",
          "documentation": "The response to an approval request."
        },
        {
          "name": "::ApprovalGate",
          "line": 89,
          "signature": "#[async_trait]\npub trait ApprovalGate: Send + Sync {\n    /// Requests approval for a file operation.\n    ///\n    /// # Arguments\n    ///\n    /// * `request` - The approval request with details about the operation.\n    ///\n    /// # Returns\n    ///\n    /// An [`ApprovalResponse`] indicating whether the operation was approved.\n    async fn request_approval(&self, request: &ApprovalRequest) -> ApprovalResponse;\n}",
          "documentation": "Trait for approval gate implementations.\n\nApproval gates are called before executing high-risk file operations.\nImplementations may be synchronous (auto-approve/deny), or asynchronous\n(queue for human review, send notification).\n\n# Thread Safety\n\nImplementations must be `Send + Sync` for use across async agent tasks."
        },
        {
          "name": "::AutoDenyGate",
          "line": 106,
          "signature": "pub struct AutoDenyGate;",
          "documentation": "An approval gate that automatically denies all requests.\n\nThis is the default gate and the safest option. It ensures no destructive\noperations proceed without explicit configuration of a more permissive gate."
        },
        {
          "name": "::AutoApproveGate",
          "line": 130,
          "signature": "pub struct AutoApproveGate;",
          "documentation": "An approval gate for testing that automatically approves all requests.\n\n**WARNING**: This gate should NEVER be used in production. It is provided\nonly for testing purposes. Using it in production bypasses all safety checks."
        },
        {
          "name": "::RiskBasedGate",
          "line": 155,
          "signature": "pub struct RiskBasedGate {\n\n}",
          "documentation": "An approval gate that auto-approves low-risk operations and denies others.\n\nThis gate is suitable for development environments where low-risk operations\n(deleting build artifacts, generated files) should proceed automatically,\nbut higher-risk operations still require escalation."
        },
        {
          "name": "::RiskBasedGate::new",
          "line": 167,
          "signature": "pub fn new(max_auto_approve: RiskLevel) -> Self;",
          "documentation": "Creates a new risk-based gate that auto-approves up to the given risk level.\n\n# Arguments\n\n* `max_auto_approve` - The maximum risk level to auto-approve. Operations\n  with higher risk will be denied."
        }
      ]
    },
    {
      "path": "forge-rs/crates/forge-code-safety/src/audit.rs",
      "sha256": "46a6ccac555e715e99dfb328174cbf05b60b7070099f1cae1e0bb672f9745782",
      "artifactSha256": "61e0afefcf4c980480bc1189965cd8c76b74b948805093a26101e4b4b5080dc7",
      "url": "/reference/source/forge-rs/crates/forge-code-safety/src/audit.rs.txt",
      "declarations": [
        {
          "name": "::FileOperation",
          "line": 45,
          "signature": "#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]\npub enum FileOperation {\n    /// Creating a new file.\n    Create,\n    /// Reading a file's contents.\n    Read,\n    /// Modifying an existing file.\n    Modify,\n    /// Deleting a file.\n    Delete,\n    /// Renaming or moving a file.\n    Rename,\n    /// Changing file permissions.\n    Chmod,\n    /// Creating a directory.\n    CreateDir,\n    /// Removing a directory.\n    RemoveDir,\n}",
          "documentation": "The type of file operation being performed."
        },
        {
          "name": "::OperationResult",
          "line": 81,
          "signature": "#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]\npub enum OperationResult {\n    /// The operation succeeded.\n    Success,\n    /// The operation was denied by policy.\n    Denied {\n        /// Why it was denied.\n        reason: String,\n    },\n    /// The operation failed due to an error.\n    Failed {\n        /// What went wrong.\n        reason: String,\n    },\n}",
          "documentation": "The result of a file operation."
        },
        {
          "name": "::AuditEntry",
          "line": 108,
          "signature": "#[derive(Debug, Clone, Serialize, Deserialize)]\npub struct AuditEntry {\n/// Unique identifier for this entry.\n\npub id: String,\n/// When the operation occurred.\n\npub timestamp: DateTime<Utc>,\n/// The DID of the agent that performed the operation.\n\npub agent_did: String,\n/// The type of operation.\n\npub operation: FileOperation,\n/// The file path targeted by the operation.\n\npub path: PathBuf,\n/// The result of the operation.\n\npub result: OperationResult,\n/// Optional additional context or notes.\n\npub context: Option<String>,\n/// BLAKE3 hash of the previous entry for chain integrity.\n\npub previous_hash: String,\n/// BLAKE3 hash of this entry's content.\n\npub entry_hash: String\n}",
          "documentation": "A single audit log entry recording a file operation."
        },
        {
          "name": "::FileAuditLog",
          "line": 137,
          "signature": "pub struct FileAuditLog {\n\n}",
          "documentation": "An append-only audit log for file operations.\n\nThe log maintains a hash chain where each entry references the hash of\nthe previous entry, enabling tamper detection.\n\n# Thread Safety\n\nUses `RwLock` for safe concurrent access from multiple agent tasks."
        },
        {
          "name": "::FileAuditLog::new",
          "line": 143,
          "signature": "pub fn new() -> Self;",
          "documentation": "Creates a new empty audit log."
        },
        {
          "name": "::FileAuditLog::record",
          "line": 158,
          "signature": "pub async fn record(\n        &self,\n        agent_did: &str,\n        operation: FileOperation,\n        path: PathBuf,\n        result: OperationResult,\n        context: Option<String>,\n    );",
          "documentation": "Records a file operation in the audit log.\n\n# Arguments\n\n* `agent_did` - The DID of the agent performing the operation.\n* `operation` - The type of file operation.\n* `path` - The file path being operated on.\n* `result` - The result of the operation.\n* `context` - Optional additional context."
        },
        {
          "name": "::FileAuditLog::entries",
          "line": 204,
          "signature": "pub async fn entries(&self) -> Vec<AuditEntry>;",
          "documentation": "Returns all entries in the audit log."
        },
        {
          "name": "::FileAuditLog::len",
          "line": 210,
          "signature": "pub async fn len(&self) -> usize;",
          "documentation": "Returns the number of entries in the audit log."
        },
        {
          "name": "::FileAuditLog::is_empty",
          "line": 216,
          "signature": "pub async fn is_empty(&self) -> bool;",
          "documentation": "Returns true if the audit log is empty."
        },
        {
          "name": "::FileAuditLog::entries_by_agent",
          "line": 222,
          "signature": "pub async fn entries_by_agent(&self, agent_did: &str) -> Vec<AuditEntry>;",
          "documentation": "Returns entries filtered by agent DID."
        },
        {
          "name": "::FileAuditLog::entries_by_operation",
          "line": 232,
          "signature": "pub async fn entries_by_operation(&self, operation: FileOperation) -> Vec<AuditEntry>;",
          "documentation": "Returns entries filtered by operation type."
        },
        {
          "name": "::FileAuditLog::verify_chain",
          "line": 245,
          "signature": "pub async fn verify_chain(&self) -> Result<(), String>;",
          "documentation": "Verifies the hash chain integrity of the audit log.\n\nReturns `Ok(())` if the chain is valid, or an error describing where\nthe chain was broken."
        }
      ]
    },
    {
      "path": "forge-rs/crates/forge-code-safety/src/delete_policy.rs",
      "sha256": "87def6eaf052e64c6979fd63beab1330a136c5807ad3e2a5012242b460a24c95",
      "artifactSha256": "f32284908be22611230122091ed78eea7aaf7ecbd12db9f456953a546ad739f5",
      "url": "/reference/source/forge-rs/crates/forge-code-safety/src/delete_policy.rs.txt",
      "declarations": [
        {
          "name": "::DeleteDecision",
          "line": 43,
          "signature": "#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]\npub enum DeleteDecision {\n    /// The delete is denied.\n    Denied {\n        /// The path that was denied.\n        path: PathBuf,\n        /// Why it was denied.\n        reason: String,\n    },\n    /// The delete requires explicit approval before it can proceed.\n    RequiresApproval {\n        /// The path requiring approval.\n        path: PathBuf,\n        /// The risk level of the delete.\n        risk_level: RiskLevel,\n    },\n    /// The delete is allowed (matches an approved pattern).\n    Allowed {\n        /// The path that was allowed.\n        path: PathBuf,\n        /// The pattern that matched.\n        matched_pattern: String,\n    },\n}",
          "documentation": "The result of evaluating a delete operation against the policy."
        },
        {
          "name": "::RiskLevel",
          "line": 69,
          "signature": "#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]\npub enum RiskLevel {\n    /// Low risk: generated files, build artifacts, temporary files.\n    Low,\n    /// Medium risk: test files, documentation, configuration.\n    Medium,\n    /// High risk: source code, production configuration, data.\n    High,\n    /// Critical risk: security files, keys, critical infrastructure.\n    Critical,\n}",
          "documentation": "Risk levels for delete operations."
        },
        {
          "name": "::DeletePolicy",
          "line": 96,
          "signature": "#[derive(Debug, Clone, Serialize, Deserialize)]\npub struct DeletePolicy {\n\n}",
          "documentation": "Policy that governs whether delete operations are allowed.\n\nThe default is to deny all deletes. More permissive policies can be\nconfigured for specific file patterns (e.g., generated files)."
        },
        {
          "name": "::DeletePolicyMode",
          "line": 109,
          "signature": "#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]\npub enum DeletePolicyMode {\n    /// All deletes are denied.\n    DenyAll,\n    /// Deletes require explicit approval.\n    RequireApproval,\n    /// Deletes matching specific patterns are allowed.\n    AllowPattern,\n}",
          "documentation": "The operational mode of the delete policy."
        },
        {
          "name": "::DeletePolicy::deny_all",
          "line": 122,
          "signature": "pub fn deny_all(agent_did: impl Into<String>) -> Self;",
          "documentation": "Creates a deny-all delete policy. This is the default.\n\nNo delete operations will be allowed under this policy."
        },
        {
          "name": "::DeletePolicy::require_approval",
          "line": 135,
          "signature": "pub fn require_approval(agent_did: impl Into<String>) -> Self;",
          "documentation": "Creates a require-approval delete policy.\n\nAll deletes will be blocked with a `RequiresApproval` decision until\nan external approval handler grants permission."
        },
        {
          "name": "::DeletePolicy::with_allowed_patterns",
          "line": 151,
          "signature": "pub fn with_allowed_patterns(agent_did: impl Into<String>, patterns: Vec<String>) -> Self;",
          "documentation": "Creates a delete policy that allows deletes matching specific patterns.\n\n# Arguments\n\n* `agent_did` - The DID of the agent.\n* `patterns` - Suffix or prefix patterns to allow (e.g., \"*.generated.rs\",\n  \"target/\", \".cache/\")."
        },
        {
          "name": "::DeletePolicy::protect_path",
          "line": 161,
          "signature": "pub fn protect_path(mut self, path: impl Into<PathBuf>) -> Self;",
          "documentation": "Adds a path that is always protected from deletion."
        },
        {
          "name": "::DeletePolicy::evaluate",
          "line": 176,
          "signature": "pub fn evaluate(&self, path: &Path) -> DeleteDecision;",
          "documentation": "Evaluates whether a delete operation should be allowed.\n\n# Arguments\n\n* `path` - The file path to evaluate for deletion.\n\n# Returns\n\nA [`DeleteDecision`] indicating whether the delete is denied, requires\napproval, or is allowed."
        },
        {
          "name": "::DeletePolicy::enforce",
          "line": 230,
          "signature": "pub fn enforce(&self, path: &Path) -> CodeSafetyResult<()>;",
          "documentation": "Enforces the delete policy, returning an error if the delete is not allowed.\n\nThis is a convenience method that wraps `evaluate` and converts non-allowed\ndecisions into errors."
        },
        {
          "name": "::DeletePolicy::agent_did",
          "line": 249,
          "signature": "pub fn agent_did(&self) -> &str;",
          "documentation": "Returns the agent DID this policy applies to."
        },
        {
          "name": "::DeletePolicy::mode",
          "line": 254,
          "signature": "pub fn mode(&self) -> &DeletePolicyMode;",
          "documentation": "Returns the policy mode."
        }
      ]
    },
    {
      "path": "forge-rs/crates/forge-code-safety/src/error.rs",
      "sha256": "9a6d7c0f17f960a2ce9d6d6f5972be6c5e7108ce8048e0c73ca9a45fb962d92e",
      "artifactSha256": "824a848060c9eb9ed323313aedcb85a8705cc9da9f669c432a7920ff10e15a44",
      "url": "/reference/source/forge-rs/crates/forge-code-safety/src/error.rs.txt",
      "declarations": [
        {
          "name": "::CodeSafetyError",
          "line": 32,
          "signature": "#[derive(Debug, Error)]\npub enum CodeSafetyError {\n    /// The agent attempted to write to a file outside its assigned write scope.\n    ///\n    /// Every coding agent is assigned an explicit write scope (a set of paths\n    /// and glob patterns). Writes to files outside that scope are denied.\n    #[error(\"write denied: agent '{agent_did}' attempted to write '{path}' which is outside assigned scope '{scope}'\")]\n    WriteOutsideScope {\n        /// The path the agent tried to write to.\n        path: PathBuf,\n        /// The assigned write scope that was violated.\n        scope: PathBuf,\n        /// The DID of the agent that attempted the write.\n        agent_did: String,\n    },\n\n    /// The agent attempted to delete a file, which is forbidden by default.\n    ///\n    /// Delete operations require explicit escalation and approval. The default\n    /// policy is deny-all for deletes.\n    #[error(\"delete denied: agent '{agent_did}' attempted to delete '{path}'; delete operations require explicit escalation (set escalation_policy to allow)\")]\n    DeleteDenied {\n        /// The path the agent tried to delete.\n        path: PathBuf,\n        /// The DID of the agent that attempted the delete.\n        agent_did: String,\n    },\n\n    /// The worktree does not exist or is not accessible.\n    #[error(\n        \"worktree '{worktree_path}' not found or not accessible for agent '{agent_did}': {reason}\"\n    )]\n    WorktreeNotFound {\n        /// The worktree path that was expected.\n        worktree_path: PathBuf,\n        /// The DID of the agent that tried to use the worktree.\n        agent_did: String,\n        /// Why the worktree was not found.\n        reason: String,\n    },\n\n    /// The worktree has already been leased to another agent.\n    #[error(\"worktree '{worktree_path}' is already leased to agent '{existing_lessee}'; agent '{requesting_agent}' cannot acquire a concurrent lease\")]\n    WorktreeAlreadyLeased {\n        /// The path of the contested worktree.\n        worktree_path: PathBuf,\n        /// The DID of the agent that currently holds the lease.\n        existing_lessee: String,\n        /// The DID of the agent that tried to acquire the lease.\n        requesting_agent: String,\n    },\n\n    /// The agent does not hold a valid lease for the requested repo.\n    #[error(\"no active lease: agent '{agent_did}' does not hold a lease for repo '{repo_path}'; acquire a lease with RepoLeaseManager::acquire() first\")]\n    NoActiveLease {\n        /// The DID of the agent missing a lease.\n        agent_did: String,\n        /// The repo path that required a lease.\n        repo_path: PathBuf,\n    },\n\n    /// The lease has expired.\n    #[error(\"lease expired: agent '{agent_did}' lease for worktree '{worktree_path}' expired at {expired_at}; renew or release the lease\")]\n    LeaseExpired {\n        /// The DID of the agent whose lease expired.\n        agent_did: String,\n        /// The worktree path with the expired lease.\n        worktree_path: PathBuf,\n        /// When the lease expired (ISO 8601 string).\n        expired_at: String,\n    },\n\n    /// An approval was required but not granted.\n    #[error(\"approval required: operation '{operation}' on '{path}' by agent '{agent_did}' requires approval (risk_level={risk_level})\")]\n    ApprovalRequired {\n        /// The operation that required approval.\n        operation: String,\n        /// The path the operation targets.\n        path: PathBuf,\n        /// The DID of the agent requesting the operation.\n        agent_did: String,\n        /// The risk level of the operation.\n        risk_level: String,\n    },\n\n    /// An approval was explicitly denied.\n    #[error(\"approval denied: operation '{operation}' on '{path}' by agent '{agent_did}' was denied by reviewer '{reviewer}': {reason}\")]\n    ApprovalDenied {\n        /// The operation that was denied.\n        operation: String,\n        /// The path the operation targets.\n        path: PathBuf,\n        /// The DID of the agent whose request was denied.\n        agent_did: String,\n        /// The reviewer who denied the request.\n        reviewer: String,\n        /// Why the approval was denied.\n        reason: String,\n    },\n\n    /// A file operation was attempted on the main/default branch directly.\n    #[error(\"direct main branch modification denied: agent '{agent_did}' attempted to modify '{path}' on branch '{branch}'; all modifications must be made in worktrees\")]\n    MainBranchModification {\n        /// The DID of the agent that attempted the modification.\n        agent_did: String,\n        /// The path that was targeted.\n        path: PathBuf,\n        /// The protected branch name.\n        branch: String,\n    },\n\n    /// The audit log write failed.\n    #[error(\"audit log write failed for operation '{operation}' by agent '{agent_did}': {reason}\")]\n    AuditLogFailed {\n        /// The operation that was being audited.\n        operation: String,\n        /// The DID of the agent.\n        agent_did: String,\n        /// Why the audit log write failed.\n        reason: String,\n    },\n\n    /// I/O error during file operations.\n    #[error(\"file I/O error at '{path}': {reason}\")]\n    IoError {\n        /// The path where the I/O error occurred.\n        path: PathBuf,\n        /// What went wrong.\n        reason: String,\n    },\n\n    /// Git operation failed.\n    #[error(\"git operation failed in '{repo_path}': {reason}\")]\n    GitError {\n        /// The repository where the git operation failed.\n        repo_path: PathBuf,\n        /// What went wrong.\n        reason: String,\n    },\n}",
          "documentation": "Error type for coding runtime safety operations.\n\nEvery variant includes actionable context: what failed, why, and what the\ndeveloper should check. No generic \"something went wrong\" messages.\n\n# Examples\n\n```\nuse forge_code_safety::error::CodeSafetyError;\nuse std::path::PathBuf;\n\nlet err = CodeSafetyError::WriteOutsideScope {\n    path: PathBuf::from(\"/repo/src/main.rs\"),\n    scope: PathBuf::from(\"/repo/src/module/\"),\n    agent_did: \"did:oas:agent:abc123\".to_string(),\n};\nlet msg = err.to_string();\nassert!(msg.contains(\"main.rs\"));\nassert!(msg.contains(\"module\"));\n```"
        },
        {
          "name": "::CodeSafetyResult",
          "line": 173,
          "signature": "pub type CodeSafetyResult<T> = Result<T, CodeSafetyError>;",
          "documentation": "A specialized `Result` type for `forge-code-safety` operations."
        }
      ]
    },
    {
      "path": "forge-rs/crates/forge-code-safety/src/lease.rs",
      "sha256": "5c16969d1f368e8013fb1aa77630d4155f41f53a8b48145143c15b8546b1b5ee",
      "artifactSha256": "3bc6bb9da731b6b3921f1968f6cc3dc0584e392ac61d45ea3457ea93ef5b8762",
      "url": "/reference/source/forge-rs/crates/forge-code-safety/src/lease.rs.txt",
      "declarations": [
        {
          "name": "::LeaseRequest",
          "line": 58,
          "signature": "#[derive(Debug, Clone)]\npub struct LeaseRequest {\n/// The DID of the agent requesting the lease.\n\npub agent_did: String,\n/// The worktree path to lease.\n\npub worktree_path: PathBuf,\n/// The write scope the agent is granted.\n\npub write_scope: WriteScope,\n/// How long the lease should be valid for.\n\npub duration: Duration\n}",
          "documentation": "A request to acquire a lease on a worktree."
        },
        {
          "name": "::RepoLease",
          "line": 74,
          "signature": "#[derive(Debug, Clone, Serialize, Deserialize)]\npub struct RepoLease {\n/// Unique identifier for this lease.\n\npub id: String,\n/// The DID of the agent holding this lease.\n\npub agent_did: String,\n/// The worktree path this lease covers.\n\npub worktree_path: PathBuf,\n/// The write scope granted by this lease.\n\npub write_scope: WriteScope,\n/// When the lease was acquired.\n\npub acquired_at: DateTime<Utc>,\n/// When the lease expires.\n\npub expires_at: DateTime<Utc>\n}",
          "documentation": "An active lease granting an agent write access to a worktree.\n\nThe lease carries the write scope and expiration. All file write operations\nmust be validated against the lease before execution."
        },
        {
          "name": "::RepoLease::is_expired",
          "line": 91,
          "signature": "pub fn is_expired(&self) -> bool;",
          "documentation": "Returns true if the lease has expired."
        },
        {
          "name": "::RepoLease::remaining",
          "line": 96,
          "signature": "pub fn remaining(&self) -> Duration;",
          "documentation": "Returns the remaining duration of the lease, or zero if expired."
        },
        {
          "name": "::RepoLeaseManager",
          "line": 119,
          "signature": "pub struct RepoLeaseManager {\n\n}",
          "documentation": "Manages repo leases for coding agents.\n\nThe `RepoLeaseManager` ensures exclusive write access to worktrees by\nmaintaining a registry of active leases. Only one agent may hold a lease\nfor a given worktree at any time.\n\n# Thread Safety\n\nUses `RwLock` for safe concurrent access from multiple agent tasks."
        },
        {
          "name": "::RepoLeaseManager::new",
          "line": 128,
          "signature": "pub fn new() -> Self;",
          "documentation": "Creates a new empty `RepoLeaseManager`."
        },
        {
          "name": "::RepoLeaseManager::acquire",
          "line": 145,
          "signature": "pub async fn acquire(&self, request: LeaseRequest) -> CodeSafetyResult<RepoLease>;",
          "documentation": "Acquires a lease for the given agent on the specified worktree.\n\n# Arguments\n\n* `request` - The lease request specifying the agent, worktree, scope, and duration.\n\n# Errors\n\nReturns [`CodeSafetyError::WorktreeAlreadyLeased`] if another agent\nalready holds an active (non-expired) lease for the worktree."
        },
        {
          "name": "::RepoLeaseManager::release",
          "line": 195,
          "signature": "pub async fn release(&self, lease_id: &str) -> CodeSafetyResult<()>;",
          "documentation": "Releases a lease, allowing another agent to acquire the worktree.\n\n# Arguments\n\n* `lease_id` - The ID of the lease to release.\n\n# Errors\n\nReturns [`CodeSafetyError::NoActiveLease`] if the lease does not exist."
        },
        {
          "name": "::RepoLeaseManager::renew",
          "line": 221,
          "signature": "pub async fn renew(\n        &self,\n        lease_id: &str,\n        additional_duration: Duration,\n    ) -> CodeSafetyResult<RepoLease>;",
          "documentation": "Renews an existing lease with a new duration.\n\n# Arguments\n\n* `lease_id` - The ID of the lease to renew.\n* `additional_duration` - The additional time to add to the lease.\n\n# Errors\n\nReturns [`CodeSafetyError::NoActiveLease`] if the lease does not exist."
        },
        {
          "name": "::RepoLeaseManager::is_active",
          "line": 243,
          "signature": "pub async fn is_active(&self, lease_id: &str) -> bool;",
          "documentation": "Returns true if the given lease ID is active and not expired."
        },
        {
          "name": "::RepoLeaseManager::get_by_agent",
          "line": 252,
          "signature": "pub async fn get_by_agent(&self, agent_did: &str) -> Option<RepoLease>;",
          "documentation": "Gets the lease for a specific agent, if any."
        },
        {
          "name": "::RepoLeaseManager::get_by_path",
          "line": 261,
          "signature": "pub async fn get_by_path(&self, worktree_path: &PathBuf) -> Option<RepoLease>;",
          "documentation": "Gets the lease for a specific worktree path, if any."
        },
        {
          "name": "::RepoLeaseManager::list_active",
          "line": 273,
          "signature": "pub async fn list_active(&self) -> Vec<RepoLease>;",
          "documentation": "Returns all active (non-expired) leases."
        },
        {
          "name": "::RepoLeaseManager::cleanup_expired",
          "line": 285,
          "signature": "pub async fn cleanup_expired(&self) -> usize;",
          "documentation": "Removes all expired leases from the manager.\n\nReturns the number of leases that were cleaned up."
        }
      ]
    },
    {
      "path": "forge-rs/crates/forge-code-safety/src/lib.rs",
      "sha256": "6b10fe5becb97c8f713ce67b145975614a6922cc0f43b6ca65e9f1eedf1fb27c",
      "artifactSha256": "eea948f0c80f1a4b9865035f8caf5b925f49bc65b52e0f1ca688fa16bf223c92",
      "url": "/reference/source/forge-rs/crates/forge-code-safety/src/lib.rs.txt",
      "declarations": [
        {
          "name": "approval",
          "line": 106,
          "signature": "#[cfg(not(target_arch = \"wasm32\"))]\npub mod approval;",
          "documentation": ""
        },
        {
          "name": "audit",
          "line": 108,
          "signature": "#[cfg(not(target_arch = \"wasm32\"))]\npub mod audit;",
          "documentation": ""
        },
        {
          "name": "delete_policy",
          "line": 110,
          "signature": "#[cfg(not(target_arch = \"wasm32\"))]\npub mod delete_policy;",
          "documentation": ""
        },
        {
          "name": "error",
          "line": 111,
          "signature": "pub mod error;",
          "documentation": ""
        },
        {
          "name": "lease",
          "line": 113,
          "signature": "#[cfg(not(target_arch = \"wasm32\"))]\npub mod lease;",
          "documentation": ""
        },
        {
          "name": "worktree",
          "line": 115,
          "signature": "#[cfg(not(target_arch = \"wasm32\"))]\npub mod worktree;",
          "documentation": ""
        },
        {
          "name": "write_scope",
          "line": 117,
          "signature": "#[cfg(not(target_arch = \"wasm32\"))]\npub mod write_scope;",
          "documentation": ""
        },
        {
          "name": "prelude",
          "line": 120,
          "signature": "pub mod prelude;",
          "documentation": "Re-exports of the most commonly used types."
        },
        {
          "name": "pub use crate::approval::{ApprovalGate, ApprovalRequest, ApprovalResponse, AutoDenyGate};",
          "line": 122,
          "signature": "#[cfg(not(target_arch = \"wasm32\"))]\npub use crate::approval::{ApprovalGate, ApprovalRequest, ApprovalResponse, AutoDenyGate};",
          "documentation": ""
        },
        {
          "name": "pub use crate::audit::{AuditEntry, FileAuditLog, FileOperation, OperationResult};",
          "line": 124,
          "signature": "#[cfg(not(target_arch = \"wasm32\"))]\npub use crate::audit::{AuditEntry, FileAuditLog, FileOperation, OperationResult};",
          "documentation": ""
        },
        {
          "name": "pub use crate::delete_policy::{DeleteDecision, DeletePolicy, DeletePolicyMode, RiskLevel};",
          "line": 126,
          "signature": "#[cfg(not(target_arch = \"wasm32\"))]\npub use crate::delete_policy::{DeleteDecision, DeletePolicy, DeletePolicyMode, RiskLevel};",
          "documentation": ""
        },
        {
          "name": "pub use crate::error::{CodeSafetyError, CodeSafetyResult};",
          "line": 127,
          "signature": "pub use crate::error::{CodeSafetyError, CodeSafetyResult};",
          "documentation": ""
        },
        {
          "name": "pub use crate::lease::{LeaseRequest, RepoLease, RepoLeaseManager};",
          "line": 129,
          "signature": "#[cfg(not(target_arch = \"wasm32\"))]\npub use crate::lease::{LeaseRequest, RepoLease, RepoLeaseManager};",
          "documentation": ""
        },
        {
          "name": "pub use crate::worktree::{WorktreeGuard, WorktreeInfo, WorktreeManager};",
          "line": 131,
          "signature": "#[cfg(not(target_arch = \"wasm32\"))]\npub use crate::worktree::{WorktreeGuard, WorktreeInfo, WorktreeManager};",
          "documentation": ""
        },
        {
          "name": "pub use crate::write_scope::WriteScope;",
          "line": 133,
          "signature": "#[cfg(not(target_arch = \"wasm32\"))]\npub use crate::write_scope::WriteScope;",
          "documentation": ""
        }
      ]
    },
    {
      "path": "forge-rs/crates/forge-code-safety/src/worktree.rs",
      "sha256": "d2fb48b09bf630fba3d8977a508dbf16947070c255892ad4e608df6805b618bc",
      "artifactSha256": "db9f445ba483697af82985e446a13c5ba9775e062dc525c641bfa39f56ce07b1",
      "url": "/reference/source/forge-rs/crates/forge-code-safety/src/worktree.rs.txt",
      "declarations": [
        {
          "name": "::WorktreeInfo",
          "line": 53,
          "signature": "#[derive(Debug, Clone, Serialize, Deserialize)]\npub struct WorktreeInfo {\n\n}",
          "documentation": "Represents an active git worktree created for an agent.\n\nA `WorktreeInfo` tracks the association between a worktree path, the agent\nthat owns it, and the branch it was created from."
        },
        {
          "name": "::WorktreeInfo::id",
          "line": 70,
          "signature": "pub fn id(&self) -> &str;",
          "documentation": "Returns the unique identifier for this worktree."
        },
        {
          "name": "::WorktreeInfo::path",
          "line": 75,
          "signature": "pub fn path(&self) -> &Path;",
          "documentation": "Returns the filesystem path of the worktree."
        },
        {
          "name": "::WorktreeInfo::branch",
          "line": 80,
          "signature": "pub fn branch(&self) -> &str;",
          "documentation": "Returns the branch name in the worktree."
        },
        {
          "name": "::WorktreeInfo::agent_did",
          "line": 85,
          "signature": "pub fn agent_did(&self) -> &str;",
          "documentation": "Returns the DID of the agent that owns this worktree."
        },
        {
          "name": "::WorktreeInfo::repo_root",
          "line": 90,
          "signature": "pub fn repo_root(&self) -> &Path;",
          "documentation": "Returns the root repository path."
        },
        {
          "name": "::WorktreeInfo::created_at",
          "line": 95,
          "signature": "pub fn created_at(&self) -> DateTime<Utc>;",
          "documentation": "Returns when the worktree was created."
        },
        {
          "name": "::WorktreeManager",
          "line": 109,
          "signature": "pub struct WorktreeManager {\n\n}",
          "documentation": "Manages git worktrees for coding agents.\n\nThe `WorktreeManager` creates isolated worktrees for each agent task,\nensuring that all modifications happen in isolation from the main branch.\n\n# Thread Safety\n\nThe manager uses an internal `RwLock` to safely track worktrees across\nconcurrent agent operations."
        },
        {
          "name": "::WorktreeManager::new",
          "line": 126,
          "signature": "pub fn new(repo_root: &Path) -> Self;",
          "documentation": "Creates a new `WorktreeManager` for the given repository.\n\nWorktrees will be stored under `{repo_root}/.forge-worktrees/`.\n\n# Arguments\n\n* `repo_root` - The root path of the git repository."
        },
        {
          "name": "::WorktreeManager::with_base",
          "line": 141,
          "signature": "pub fn with_base(repo_root: &Path, worktree_base: &Path) -> Self;",
          "documentation": "Creates a new `WorktreeManager` with a custom worktree base directory.\n\n# Arguments\n\n* `repo_root` - The root path of the git repository.\n* `worktree_base` - The directory where worktrees will be stored."
        },
        {
          "name": "::WorktreeManager::create",
          "line": 164,
          "signature": "pub async fn create(\n        &self,\n        agent_did: &str,\n        branch_name: &str,\n    ) -> CodeSafetyResult<WorktreeInfo>;",
          "documentation": "Creates a new worktree for the given agent and branch.\n\nThe worktree is created as a new branch from the current HEAD. The branch\nname will be sanitized to be a valid git branch name.\n\n# Arguments\n\n* `agent_did` - The DID of the agent that will own this worktree.\n* `branch_name` - The desired branch name for the worktree.\n\n# Errors\n\nReturns [`CodeSafetyError::GitError`] if the git worktree creation fails.\nReturns [`CodeSafetyError::MainBranchModification`] if the branch name is\na protected branch."
        },
        {
          "name": "::WorktreeManager::remove",
          "line": 243,
          "signature": "pub async fn remove(&self, worktree: &WorktreeInfo) -> CodeSafetyResult<()>;",
          "documentation": "Removes a worktree and its associated branch.\n\nThe worktree directory is removed from disk and the tracking record is\ndeleted. The git branch is NOT deleted (changes may need review).\n\n# Arguments\n\n* `worktree` - The worktree info to remove.\n\n# Errors\n\nReturns [`CodeSafetyError::GitError`] if the git worktree removal fails."
        },
        {
          "name": "::WorktreeManager::list",
          "line": 273,
          "signature": "pub async fn list(&self) -> Vec<WorktreeInfo>;",
          "documentation": "Lists all active worktrees managed by this manager."
        },
        {
          "name": "::WorktreeManager::find_by_agent",
          "line": 281,
          "signature": "pub async fn find_by_agent(&self, agent_did: &str) -> Option<WorktreeInfo>;",
          "documentation": "Finds a worktree by agent DID.\n\nReturns the first worktree owned by the given agent, if any."
        },
        {
          "name": "::WorktreeManager::worktree_for_path",
          "line": 293,
          "signature": "pub async fn worktree_for_path(&self, path: &Path) -> Option<WorktreeInfo>;",
          "documentation": "Checks if a path is inside any active worktree.\n\nReturns the owning worktree info if the path is within an active worktree,\nor `None` if the path is not inside any worktree."
        },
        {
          "name": "::WorktreeManager::repo_root",
          "line": 302,
          "signature": "pub fn repo_root(&self) -> &Path;",
          "documentation": "Returns the repo root path."
        },
        {
          "name": "::WorktreeGuard",
          "line": 327,
          "signature": "#[derive(Debug, Clone)]\npub struct WorktreeGuard {\n\n}",
          "documentation": "A guard that validates file operations happen within a worktree.\n\nThe `WorktreeGuard` wraps a `WorktreeInfo` and provides methods for\nperforming file operations that are automatically scoped to the worktree.\nIt prevents operations on protected branches.\n\n# Examples\n\n```no_run\nuse forge_code_safety::worktree::{WorktreeGuard, WorktreeInfo};\nuse std::path::Path;\n\n# async fn demo(info: WorktreeInfo) -> Result<(), Box<dyn std::error::Error>> {\nlet guard = WorktreeGuard::new(info);\n// This will verify the path is inside the worktree before allowing the operation.\nguard.validate_path(Path::new(\"/worktree/path/src/lib.rs\"))?;\n# Ok(())\n# }\n```"
        },
        {
          "name": "::WorktreeGuard::new",
          "line": 333,
          "signature": "pub fn new(info: WorktreeInfo) -> Self;",
          "documentation": "Creates a new `WorktreeGuard` for the given worktree."
        },
        {
          "name": "::WorktreeGuard::info",
          "line": 338,
          "signature": "pub fn info(&self) -> &WorktreeInfo;",
          "documentation": "Returns the underlying worktree info."
        },
        {
          "name": "::WorktreeGuard::validate_path",
          "line": 352,
          "signature": "pub fn validate_path(&self, path: &Path) -> CodeSafetyResult<()>;",
          "documentation": "Validates that a path is within this worktree.\n\n# Arguments\n\n* `path` - The path to validate.\n\n# Errors\n\nReturns [`CodeSafetyError::WriteOutsideScope`] if the path is not within\nthe worktree directory."
        },
        {
          "name": "::WorktreeGuard::validate_branch",
          "line": 373,
          "signature": "pub fn validate_branch(&self, branch: &str) -> CodeSafetyResult<()>;",
          "documentation": "Validates that the target branch is not a protected branch.\n\n# Arguments\n\n* `branch` - The branch name to check.\n\n# Errors\n\nReturns [`CodeSafetyError::MainBranchModification`] if the branch is protected."
        },
        {
          "name": "::is_protected_branch",
          "line": 418,
          "signature": "pub fn is_protected_branch(branch: &str) -> bool;",
          "documentation": "Checks whether a branch name is a protected branch.\n\n# Arguments\n\n* `branch` - The branch name to check.\n\n# Returns\n\n`true` if the branch is protected (main, master, develop)."
        }
      ]
    },
    {
      "path": "forge-rs/crates/forge-code-safety/src/write_scope.rs",
      "sha256": "ffa2123452a0da347aa105913ed97b2e653598c50a294031addcb24ecd5ee220",
      "artifactSha256": "15963d41efab5fd11cdba964ab21ff68685aed33ea081f0f4384b9d2ba265cb7",
      "url": "/reference/source/forge-rs/crates/forge-code-safety/src/write_scope.rs.txt",
      "declarations": [
        {
          "name": "::WriteScope",
          "line": 51,
          "signature": "#[derive(Debug, Clone, Serialize, Deserialize)]\npub struct WriteScope {\n\n}",
          "documentation": "Defines the set of files an agent is permitted to write to.\n\nA `WriteScope` is assigned when an agent acquires a repo lease or worktree.\nAll file write operations are checked against the scope before execution.\n\n# Security\n\nThis is a fail-closed system. If a path does not match any allowed rule,\nthe write is denied. Denied paths take precedence over allowed paths."
        },
        {
          "name": "::WriteScope::builder",
          "line": 76,
          "signature": "pub fn builder(agent_did: impl Into<String>) -> WriteScopeBuilder;",
          "documentation": "Creates a new [`WriteScopeBuilder`] for the given agent DID.\n\n# Arguments\n\n* `agent_did` - The OAS DID of the agent this scope will be assigned to.\n\n# Returns\n\nA builder for constructing a `WriteScope`."
        },
        {
          "name": "::WriteScope::agent_did",
          "line": 88,
          "signature": "pub fn agent_did(&self) -> &str;",
          "documentation": "Returns the DID of the agent this scope is assigned to."
        },
        {
          "name": "::WriteScope::is_allowed",
          "line": 108,
          "signature": "pub fn is_allowed(&self, path: &Path) -> CodeSafetyResult<()>;",
          "documentation": "Checks whether the given path is within the write scope.\n\n# Arguments\n\n* `path` - The file path to check.\n\n# Returns\n\n`Ok(())` if the path is within scope, or a [`CodeSafetyError::WriteOutsideScope`]\nif it is not.\n\n# Evaluation Order\n\n1. If the path matches any denied path or denied directory, return error.\n2. If the path matches any allowed directory, allowed file, or allowed extension, return Ok.\n3. Otherwise, return error (fail-closed)."
        },
        {
          "name": "::WriteScope::allowed_directories",
          "line": 169,
          "signature": "pub fn allowed_directories(&self) -> &[PathBuf];",
          "documentation": "Returns all allowed directories in this scope."
        },
        {
          "name": "::WriteScope::denied_paths",
          "line": 174,
          "signature": "pub fn denied_paths(&self) -> &[PathBuf];",
          "documentation": "Returns all denied paths in this scope."
        },
        {
          "name": "::WriteScope::has_any_allowed",
          "line": 179,
          "signature": "pub fn has_any_allowed(&self) -> bool;",
          "documentation": "Returns true if this scope has any allowed rules at all."
        },
        {
          "name": "::WriteScopeBuilder",
          "line": 200,
          "signature": "pub struct WriteScopeBuilder {\n\n}",
          "documentation": "Builder for constructing a [`WriteScope`].\n\n# Examples\n\n```\nuse forge_code_safety::write_scope::WriteScope;\n\nlet scope = WriteScope::builder(\"did:oas:agent:impl-1\")\n    .allow_directory(\"/repo/crates/my-crate/src/\")\n    .allow_directory(\"/repo/crates/my-crate/tests/\")\n    .allow_file(\"/repo/crates/my-crate/Cargo.toml\")\n    .deny_directory(\"/repo/crates/my-crate/src/generated/\")\n    .build();\n```"
        },
        {
          "name": "::WriteScopeBuilder::allow_directory",
          "line": 213,
          "signature": "pub fn allow_directory(mut self, path: impl Into<PathBuf>) -> Self;",
          "documentation": "Adds a directory prefix to the allowed write set.\n\nAll files under this directory (recursively) will be writable."
        },
        {
          "name": "::WriteScopeBuilder::allow_file",
          "line": 219,
          "signature": "pub fn allow_file(mut self, path: impl Into<PathBuf>) -> Self;",
          "documentation": "Adds an exact file path to the allowed write set."
        },
        {
          "name": "::WriteScopeBuilder::allow_extension",
          "line": 228,
          "signature": "pub fn allow_extension(mut self, pattern: impl Into<String>) -> Self;",
          "documentation": "Adds a file extension pattern to the allowed write set.\n\nThe pattern should be an extension like \"rs\", \"*.rs\", or \".rs\" \u2014 all\nforms are normalized internally."
        },
        {
          "name": "::WriteScopeBuilder::deny_path",
          "line": 236,
          "signature": "pub fn deny_path(mut self, path: impl Into<PathBuf>) -> Self;",
          "documentation": "Adds an exact file path to the denied set.\n\nDenied paths override allowed rules."
        },
        {
          "name": "::WriteScopeBuilder::deny_directory",
          "line": 245,
          "signature": "pub fn deny_directory(mut self, path: impl Into<PathBuf>) -> Self;",
          "documentation": "Adds a directory prefix to the denied set.\n\nAll files under this directory (recursively) will be denied, even if\nthey match an allowed rule."
        },
        {
          "name": "::WriteScopeBuilder::build",
          "line": 251,
          "signature": "pub fn build(self) -> WriteScope;",
          "documentation": "Builds the [`WriteScope`]."
        }
      ]
    }
  ]
}
