progit-plugin-sdk 0.2.1

Plugin SDK for ProGit — sandboxed LuaJIT runtime with capability-based security. LSL-1.0 (file-level copyleft, proprietary plugins allowed via the commercial bridge).
Documentation
// SPDX-License-Identifier: LSL-1.0
// Copyright (c) 2025 Markus Maiwald

//! Example Lua plugin: Hello World
//!
//! This example demonstrates how to load and execute a simple Lua plugin.

use progit_plugin_sdk::prelude::*;

fn main() -> anyhow::Result<()> {
    env_logger::init();

    let script = r#"
        plugin = {
            name = "hello-world",
            version = "1.0.0",
            author = "Markus Maiwald",
            description = "A simple hello world plugin",
            hooks = {
                on_issue_created = true,
                on_issue_updated = true,
            }
        }
        
        function init()
            print("Hello World plugin initialized!")
            print("Repository: " .. context.repo_path)
        end
        
        function on_issue_created(issue)
            print("🎉 New issue created: " .. issue.title)
            print("   ID: " .. issue.id)
            print("   Status: " .. issue.status)
            
            -- Return success
            return { success = true, message = "Issue logged" }
        end
        
        function on_issue_updated(issue)
            print("✏️  Issue updated: " .. issue.title)
            print("   New status: " .. issue.status)
            
            return { success = true }
        end
    "#;

    // Load the plugin
    let mut plugin = LuaPlugin::from_string(script, "hello-world")?;
    
    println!("Loaded plugin: {}", plugin.metadata().name);
    println!("Version: {}", plugin.metadata().version);
    println!("Author: {}", plugin.metadata().author);
    println!();

    // Initialize with context
    let context = PluginContext {
        repo_path: "/home/user/my-project".to_string(),
        user: Some("markus".to_string()),
        env: std::env::vars().collect(),
        config: Default::default(),
    };
    
    plugin.init(&context)?;
    println!();

    // Create a test issue
    let issue = Issue {
        id: "abc123".to_string(),
        title: "Implement fuzzy command palette".to_string(),
        description: "Add Ctrl+P fuzzy search for issues, files, and commits".to_string(),
        status: "in-progress".to_string(),
        tags: vec!["feature".to_string(), "tui".to_string()],
        assignee: Some("markus".to_string()),
        effort: Some(5),
        blocked: false,
        created: "2025-12-11T00:00:00Z".to_string(),
        updated: "2025-12-11T00:00:00Z".to_string(),
        due: Some("2025-12-13T23:59:59Z".to_string()),
        metadata: Default::default(),
    };

    // Trigger on_issue_created hook
    plugin.on_issue_created(&issue)?;
    println!();

    // Update the issue
    let mut updated_issue = issue.clone();
    updated_issue.status = "done".to_string();
    
    plugin.on_issue_updated(&updated_issue)?;

    Ok(())
}