agentleFS
MicrosoftKnown publishermicrosoft/Sysinternals-listent/.github/copilot-instructions.md

Sysinternals-listent

Copilot instructions5 starsChanged 9 months agoMITView on GitHub

Project: listent - macOS entitlement scanning CLI tool Language: Rust Last Updated: September 20, 2025 listent is a fast command-line tool for macOS that scans and monitors code signing entitlements. It provides both one-time scanning and real-time monitoring capabilities for security analysis and compliance verification. Now includes background daemon mode for continuous system monitoring. Usage: listent monitor [OPTIONS] [PATH...]

The file

Show its rules and text

We split this copilot-instructions.md into the rules it gives an agent

22 rules. About 0 are common, 17 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈17

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    No unsafe code without justification

    line 41
  2. Distinctive:

    Test-driven development with cargo test

    line 42
  3. Distinctive:

    Use existing codesign extraction for monitored processes

    line 116
  4. Distinctive:

    No terminal output in daemon mode - ULS logging only

    line 271
  5. Distinctive:

    Use HashMap for O(1) process lookups during comparison

    line 304
  6. Very specific:

    Use rustfmt default formatting

    line 373
  7. Distinctive:

    Prefer explicit types for public APIs

    line 374
  8. Very specific:

    Use ? operator for error propagation

    line 375
  9. Distinctive:

    Document public functions with /// comments

    line 376
  10. Very specific:

    Use #[derive(Debug)] for data structures

    line 377
  11. Distinctive:

    Use clap derive API for argument parsing

    line 380
  12. Distinctive:

    Use structured output (JSON) for programmatic consumption

    line 382
  13. Very specific:

    Use assert_cmd for CLI testing, predicates for output validation

    line 389
  14. Very specific:

    Add field to Args struct in src/cli/mod.rs

    line 394
  15. Distinctive:

    Add validation logic if needed

    line 395
  16. Distinctive:

    Update help text generation

    line 396
  17. Distinctive:

    Add contract tests for new option

    line 397
  18. Distinctive:

    Update JSON serialization if needed

    line 401
  19. Distinctive:

    Add output format contract tests

    line 403
  20. Distinctive:

    Add new error variants to appropriate error enums

    line 406
  21. Distinctive:

    Add error context in calling code

    line 408
  22. Distinctive:

    Test error scenarios with unit tests

    line 409

≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
copilot-instructions.md

GitHub Copilot Instructions

Project: listent - macOS entitlement scanning CLI tool
Language: Rust
Last Updated: September 20, 2025

Project Overview

listent is a fast command-line tool for macOS that scans and monitors code signing entitlements. It provides both one-time scanning and real-time monitoring capabilities for security analysis and compliance verification. Now includes background daemon mode for continuous system monitoring.

Current Architecture

Module Structure

src/
├── main.rs              # Entry point and CLI coordination
├── cli/mod.rs           # Command-line argument parsing (clap)
├── models/mod.rs        # Data structures and configuration
├── scan/mod.rs          # Filesystem scanning and binary discovery  
├── entitlements/mod.rs  # Code signing entitlement extraction
├── output/mod.rs        # Output formatting (human-readable and JSON)
├── monitor/mod.rs       # Real-time process monitoring
└── daemon/mod.rs        # NEW: LaunchD daemon functionality
    ├── config.rs        # Configuration management
    ├── ipc.rs           # Inter-process communication
    ├── launchd.rs       # macOS launchd integration
    └── logging.rs       # Enhanced ULS logging

Key Dependencies

  • clap: Command-line argument parsing with subcommands
  • serde_json: JSON serialization for output
  • sysinfo: Process enumeration for monitoring mode
  • tokio: Async runtime for daemon mode IPC and signal handling
  • toml: Configuration file parsing for daemon settings
  • nix: Unix domain sockets and signal handling

Constitutional Principles

  • Single binary CLI tool targeting macOS
  • Minimal dependencies, prefer std library
  • No unsafe code without justification
  • Test-driven development with cargo test
  • Clear error handling with structured messages

Feature: Real-time Process Monitoring

CLI Structure

// Monitor subcommand structure
#[derive(Subcommand)]
pub enum Commands {
    /// Real-time process monitoring
    Monitor {
        path: Vec<PathBuf>,
        entitlement: Vec<String>,
        interval: f64,
        json: bool,
        quiet: bool,
    },
    // ... other subcommands
}

Usage: listent monitor [OPTIONS] [PATH...]

New Data Model Types

// In src/models/mod.rs - extend existing types
pub struct MonitoredProcess {
    pub pid: u32,
    pub name: String,
    pub executable_path: PathBuf,
    pub entitlements: Vec<String>,
    pub discovery_timestamp: SystemTime,
}

pub struct PollingConfiguration {
    pub interval: Duration,
    pub path_filters: Vec<PathBuf>,
    pub entitlement_filters: Vec<String>,
    pub output_json: bool,
    pub quiet_mode: bool,
}

pub struct ProcessSnapshot {
    pub processes: HashMap<u32, MonitoredProcess>,
    pub timestamp: SystemTime,
    pub scan_duration: Duration,
}

Monitor Module Structure

// src/monitor/mod.rs - NEW module
pub mod process_tracker;   // Process state management
pub mod polling;          // Polling loop implementation  
pub mod unified_logging;  // macOS system logging

pub use process_tracker::ProcessTracker;
pub use polling::start_monitoring;

Integration Points

CLI Integration

  • Extend existing Args struct with monitor and interval fields
  • Reuse existing path (-p) and entitlement (-e) parsing logic
  • Maintain existing help and version functionality

Scan Module Reuse

  • Leverage existing path filtering logic for monitoring scope
  • Reuse directory traversal patterns for initial process discovery
  • Maintain consistent error handling patterns

Entitlements Module Reuse

  • Use existing codesign extraction for monitored processes
  • Apply existing entitlement filtering logic
  • Handle extraction failures gracefully (empty entitlements list)

Output Module Extension

  • Extend existing JSON schema for process detection events
  • Reuse human-readable formatting patterns
  • Maintain existing quiet mode behavior

Coding Patterns

Error Handling

// Use Result types for fallible operations
pub fn extract_process_entitlements(pid: u32) -> Result<Vec<String>, MonitorError> {
    // Implementation
}

// Custom error types for monitoring
#[derive(Debug, thiserror::Error)]
pub enum MonitorError {
    #[error("Invalid polling interval: {0}. Must be between 0.1 and 300.0 seconds")]
    InvalidInterval(f64),
    #[error("Process access denied: {0}")]
    PermissionDenied(String),
    #[error("System resource error: {0}")]
    SystemError(String),
}

Testing Approach

// Unit tests for core logic
#[cfg(test)]
mod tests {
    use super::*;
    
    #[test]
    fn test_process_snapshot_comparison() {
        // Test new process detection logic
    }
    
    #[test]
    fn test_polling_configuration_validation() {
        // Test interval bounds checking
    }
}

// Integration tests in tests/ directory
// Test full monitor workflows with real processes

Feature: LaunchD Daemon Support

CLI Extensions for Daemon Management

// Nested daemon subcommands
#[derive(Subcommand)]
pub enum Commands {
    Monitor { /* ... */ },
    
    /// Daemon management commands
    Daemon {
        #[command(subcommand)]
        action: DaemonCommands,
    },
}

#[derive(Subcommand)]
pub enum DaemonCommands {
    Run { config: Option<PathBuf> },
    Install { config: Option<PathBuf> },
    Uninstall,
    Status,
    Stop,
    Logs { follow: bool, since: Option<String> },
}

Usage:

  • listent daemon run [--config FILE]
  • listent daemon install [--config FILE]
  • listent daemon uninstall
  • listent daemon status
  • listent daemon stop
  • listent daemon logs [--since TIME]

Daemon Configuration Types

// In src/daemon/config.rs
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DaemonConfiguration {
    pub daemon: DaemonSettings,
    pub logging: LoggingSettings,
    pub monitoring: MonitoringSettings,
    pub ipc: IpcSettings,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DaemonSettings {
    pub polling_interval: f64,      // 0.1-300.0 seconds
    pub auto_start: bool,           // launchd RunAtLoad setting
    pub pid_file: PathBuf,          // /var/run/listent/daemon.pid
}

// Configuration file: /etc/listent/daemon.toml

LaunchD Integration

// src/daemon/launchd.rs
pub struct LaunchDPlist {
    pub label: String,              // com.microsoft.sysinternals.listent
    pub program_arguments: Vec<String>,
    pub run_at_load: bool,
    pub keep_alive: bool,
    pub working_directory: Option<PathBuf>,
}

pub fn generate_plist(daemon_path: &Path) -> Result<String>;
pub fn install_plist(plist_content: &str, service_name: &str) -> Result<()>;
pub fn launchctl_load(plist_path: &Path) -> Result<()>;
pub fn launchctl_unload(service_name: &str) -> Result<()>;

IPC Communication

// src/daemon/ipc.rs
#[derive(Debug, Serialize, Deserialize)]
pub enum IpcMessage {
    UpdateConfig { updates: ConfigUpdates },
    ReloadConfig,
    GetStatus,
    GetStats,
    Shutdown,
}

#[derive(Debug, Serialize, Deserialize)]
pub enum IpcResponse {
    Success { data: Option<serde_json::Value> },
    Error { code: u32, message: String },
    ConfigUpdated { new_config: DaemonConfiguration },
}

// Unix domain socket at /var/run/listent/daemon.sock
pub struct IpcServer {
    socket_path: PathBuf,
    listener: UnixListener,
}

Integration Points

Daemon Mode Execution

  • Extend main.rs with daemon execution path
  • No terminal output in daemon mode - ULS logging only
  • Reuse existing monitor::polling logic with async wrapper
  • Signal handling for graceful shutdown and config reload

Configuration Management

  • TOML-based configuration files
  • Atomic configuration updates with validation
  • Backup and rollback functionality
  • Dynamic reload without daemon restart

Testing Approach

// Unit tests for core logic
#[cfg(test)]
mod tests {
    use super::*;
    
    #[test]
    fn test_process_snapshot_comparison() {
        // Test new process detection logic
    }
    
    #[test]
    fn test_polling_configuration_validation() {
        // Test interval bounds checking
    }
}

// Integration tests in tests/ directory
// Test full monitor workflows with real processes

Performance Considerations

  • Use HashMap for O(1) process lookups during comparison
  • Minimize allocations in polling loop (reuse collections)
  • Handle large entitlements lists efficiently
  • Profile memory usage during extended monitoring

Recent Changes

Phase 1: Core CLI Implementation (001-macos-rust-cli)

  • Status: ✅ COMPLETE
  • Key Features: Basic directory scanning, entitlement extraction, JSON/human output, path filtering
  • Architecture: Modular design with scan, entitlements, output, and CLI modules

Phase 2: Monitor Feature Implementation (002-add-monitor-switch)

  • Status: ✅ COMPLETE
  • Key Features Implemented:
    • Real-time process monitoring with monitor subcommand
    • Configurable polling intervals with --interval (0.1-300.0 seconds)
    • Process entitlement extraction and filtering
    • Human-readable and JSON output formats
    • Graceful shutdown with Ctrl+C handling
    • Performance optimized for extended monitoring
  • Performance Optimizations:
    • Pre-allocated collections to reduce memory allocations
    • Lazy entitlement extraction (only for new processes)
    • Efficient process state tracking with HashMap lookups
    • Memory usage <1% of system resources during operation
  • Testing: TDD approach with comprehensive contract tests covering CLI validation, output formats, and edge cases

Phase 3: Performance & UX Optimizations (Multiple Sessions)

  • Status: ✅ COMPLETE
  • Progress Indicator Enhancements:
    • ✅ Fast file counting phase (like find command performance)
    • ✅ Real-time progress with "Processed X/Y files (scanned: A, skipped: B)" format
    • ✅ Directory name display in progress output
    • ✅ Skip tracking for non-executable files
  • Default Path Optimization:
    • ✅ Default scan paths set to /usr/bin and /usr/sbin
    • ✅ Significantly faster default scans with maintained functionality
    • ✅ Updated help text and documentation
  • Interrupt Handling Refinement:
    • ✅ Clean signal handling with signal-hook library
    • ✅ Silent interrupt (no error messages)
    • ✅ Documented macOS terminal workaround (trap - INT)
    • ✅ Cross-terminal compatibility notes in README

Phase 4: Daemon Infrastructure (003-add-launchd-daemon)

  • Status: 🚧 IN PROGRESS
  • Implemented:
    • ✅ CLI subcommands for daemon management
    • ✅ Configuration file structure and parsing
    • ✅ LaunchD plist generation and integration
    • ✅ IPC framework for runtime configuration updates
    • ✅ Unified Logging System integration
  • Remaining:
    • 🔄 End-to-end daemon operation testing
    • 🔄 Configuration update workflows
    • 🔄 Production deployment validation

Files Modified/Added (Cumulative)

  • Core Architecture: Complete modular structure in src/
  • CLI Enhancement: Comprehensive argument parsing with subcommands
  • Performance: Fast counting, optimized progress tracking, efficient file filtering
  • Documentation: Updated README with all features, troubleshooting, examples
  • Testing: Comprehensive contract, integration, and unit test coverage
  • Daemon Support: Full LaunchD integration with configuration management

Code Style Preferences

Rust Conventions

  • Use rustfmt default formatting
  • Prefer explicit types for public APIs
  • Use ? operator for error propagation
  • Document public functions with /// comments
  • Use #[derive(Debug)] for data structures

CLI Patterns

  • Use clap derive API for argument parsing
  • Validate arguments early, fail fast with clear messages
  • Use structured output (JSON) for programmatic consumption
  • Provide human-readable output by default

Testing Patterns

  • Unit tests in module files (#[cfg(test)])
  • Integration tests in tests/ directory
  • Contract tests validate CLI behavior and output formats
  • Use assert_cmd for CLI testing, predicates for output validation

Common Tasks

Adding New CLI Options

  1. Add field to Args struct in src/cli/mod.rs
  2. Add validation logic if needed
  3. Update help text generation
  4. Add contract tests for new option

Extending Output Formats

  1. Modify output structures in src/models/mod.rs
  2. Update JSON serialization if needed
  3. Extend formatting logic in src/output/mod.rs
  4. Add output format contract tests

Error Handling Extensions

  1. Add new error variants to appropriate error enums
  2. Implement Display and Error traits
  3. Add error context in calling code
  4. Test error scenarios with unit tests

This file is automatically updated as new features are implemented.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.