WeaveDocs
Agentfs

Agents and Permissions

Agents and permissions in AgentFS — per-agent permission modes, capability bindings, and policy callbacks at write time.

Purpose

Local agent filesystem with contexts, registry, permissions, metadata hooks, sync, watchers, and atomic writes.

This page follows the real source shape for Agentfs and explains the workflow a developer is likely to use first.

Trust contract

Document which keys authorize the operation, what is signed, what is encrypted, what is deliberately public, and which policy hook can deny the call. Security examples should use deterministic test vectors where possible.

Primary types to know

  • AgentContext — local/agentfs/src/agent.rs
  • AgentContext — local/agentfs/src/agent_refactored.rs
  • AgentFS — local/agentfs/src/fs.rs
  • AgentFS — local/agentfs/src/fs_refactored.rs
  • AgentFSConfig — local/agentfs/src/config.rs
  • AgentPermission — local/agentfs/src/permissions.rs
  • AgentPermission — local/agentfs/src/permissions_refactored.rs
  • AgentRegistry — local/agentfs/src/agent.rs
  • AgentRegistry — local/agentfs/src/agent_refactored.rs
  • ConflictInfo — local/agentfs/src/sync_refactored.rs
  • FsckReport — local/agentfs/src/fs.rs
  • FsMetrics — local/agentfs/src/fs.rs

Example shape

use agentfs::{AgentContext, AgentRegistry, AgentPermission, Permission, PermissionChecker};
use std::sync::Arc;
use weave_identity::{Ed25519Adapter, Identity};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let adapter: Arc<dyn weave_identity::WeaveIdentityAdapter> = Arc::new(Ed25519Adapter::new());

    // Build agent and organization identities, then bind them in an AgentContext.
    let agent = Identity::agent_from_public_key(vec![0u8; 32], Some("ops-bot"))?;
    let org = Identity::ao_from_public_key(vec![1u8; 32], "demo-org")?;
    let mut ctx = AgentContext::new(agent.clone(), org);
    ctx.add_capability("write:file".to_string());

    // The registry tracks active agent contexts on a node.
    let mut registry = AgentRegistry::new();
    registry.register(ctx);

    // PermissionChecker holds path-scoped grants and validates them through
    // the identity adapter; defaults apply when no explicit grant matches.
    let mut checker = PermissionChecker::new(adapter);
    checker.set_default_permissions(vec![Permission::Read]);
    checker.grant(&agent, "/inbox", Permission::Write);
    checker.grant(&agent, "/inbox", Permission::Delete);

    println!(
        "registered_agents={} write_action={}",
        registry.list_agents().len(),
        Permission::Write.to_action(),
    );
    Ok(())
}