actualised-core 0.1.1

Autonomous multi-agent orchestration engine for AI teams and game studios
use crate::state::{Agent, CompanyState, Project};
use crate::inference::Tool;

/// Creates the starter company used by new Actualised.ai workspaces: "Pawsome",
/// led by a Project Manager coordinating Product, Engineering, and Growth.
pub async fn seed_default_company(state: &mut CompanyState) -> Result<(), String> {
    state.set_company_name("Pawsome".to_string()).await?;

    let tools = [
        Tool {
            name: "create_sub_project".to_string(),
            company_id: None,
            description: "Create a sub project/epic".to_string(),
            parameters: serde_json::json!({
                "type": "object",
                "properties": {
                    "title": { "type": "string" },
                    "description": { "type": "string" }
                },
                "required": ["title", "description"]
            }),
        },
        Tool {
            name: "read_memory".to_string(),
            company_id: None,
            description: "Read content from your own memory footprint. Use this to remember rules, past decisions, or user preferences.".to_string(),
            parameters: serde_json::json!({
                "type": "object",
                "properties": {
                    "file_name": { "type": "string" }
                },
                "required": ["file_name"]
            }),
        },
        Tool {
            name: "telegram_notify".to_string(),
            company_id: None,
            description: "Send a notification directly to the user's Telegram. Use sparingly for significant updates or when explicit user input is required.".to_string(),
            parameters: serde_json::json!({
                "type": "object",
                "properties": {
                    "message": { "type": "string" }
                },
                "required": ["message"]
            }),
        },
        Tool {
            name: "write_memory".to_string(),
            company_id: None,
            description: "Write content to your own memory footprint. Use '/' in file_name to organise files into folders (e.g. 'research/competitors.md').".to_string(),
            parameters: serde_json::json!({
                "type": "object",
                "properties": {
                    "file_name": { "type": "string" },
                    "content": { "type": "string" }
                },
                "required": ["file_name", "content"]
            }),
        },
        Tool {
            name: "github_read_file".to_string(),
            company_id: None,
            description: "Read a file from the configured GitHub repository.".to_string(),
            parameters: serde_json::json!({
                "type": "object",
                "properties": {
                    "path": { "type": "string" }
                },
                "required": ["path"]
            }),
        },
        Tool {
            name: "github_write_file".to_string(),
            company_id: None,
            description: "Write content to a file in the configured GitHub repository and create a commit.".to_string(),
            parameters: serde_json::json!({
                "type": "object",
                "properties": {
                    "path": { "type": "string" },
                    "content": { "type": "string" },
                    "message": { "type": "string", "description": "Commit message" }
                },
                "required": ["path", "content", "message"]
            }),
        },
        Tool {
            name: "github_comment_issue".to_string(),
            company_id: None,
            description: "Add a comment to a GitHub issue.".to_string(),
            parameters: serde_json::json!({
                "type": "object",
                "properties": {
                    "issue_id": { "type": "string" },
                    "comment": { "type": "string" }
                },
                "required": ["issue_id", "comment"]
            }),
        }
    ];

    for t in tools {
        state.add_tool(t).await?;
    }

    let agents = [
        Agent {
            id: "node_project_manager".to_string(),
            name: "Project Manager".to_string(),
            role: "Company Orchestrator".to_string(),
            parent_id: None,
            system_prompt: "You are the Project Manager at Pawsome. Coordinate the Engineering, Product, and Growth leads, turn operator messages into clear priorities, and keep the three teams aligned around the MVP. Use create_sub_project to break down cross-team work and write_shared_file to publish company-wide decisions.".to_string(),
            tools: vec!["telegram_notify".to_string(), "create_sub_project".to_string(), "assign_task".to_string(), "github_read_file".to_string(), "github_write_file".to_string(), "github_comment_issue".to_string()],
            model: None,
            provider: None,
            temperature: None,
            telemetry: None,
            scheduled_tasks: None,
            pending_messages: None, issue_triggers: None, company_id: None,
        },
        Agent {
            id: "node_eng_lead".to_string(),
            name: "Engineering Lead".to_string(),
            role: "Lead Engineer".to_string(),
            parent_id: Some("node_project_manager".to_string()),
            system_prompt: "You are the Engineering Lead at Pawsome, an online pet store and adoption marketplace. Break down the platform (product catalog, checkout, adoption listings) into epics for your reports, Frontend Engineer and Backend Engineer, using create_sub_project. Publish the technical roadmap to the shared team directory with write_shared_file at 'engineering/roadmap.md' so Product and Growth can see it.".to_string(),
            tools: vec!["create_sub_project".to_string(), "assign_task".to_string(), "github_read_file".to_string(), "github_write_file".to_string(), "github_comment_issue".to_string()],
            model: None,
            provider: None,
            temperature: None,
            telemetry: None,
            scheduled_tasks: None,
            pending_messages: None, issue_triggers: None, company_id: None,
        },
        Agent {
            id: "node_eng_frontend".to_string(),
            name: "Frontend Engineer".to_string(),
            role: "React/UI Developer".to_string(),
            parent_id: Some("node_eng_lead".to_string()),
            system_prompt: "You are the Frontend Engineer at Pawsome. Build the storefront: product listing pages, pet profile cards, and the checkout flow. Keep your own working notes and drafts organised in folders with write_memory (e.g. 'components/product-card.tsx', 'components/checkout-form.tsx'). When a component is ready to hand off, also publish it to the shared team directory with write_shared_file under 'engineering/frontend/'.".to_string(),
            tools: vec!["read_memory".to_string(), "write_memory".to_string(), "github_read_file".to_string(), "github_write_file".to_string(), "github_comment_issue".to_string()],
            model: None,
            provider: None,
            temperature: None,
            telemetry: None,
            scheduled_tasks: None,
            pending_messages: None, issue_triggers: None, company_id: None,
        },
        Agent {
            id: "node_eng_backend".to_string(),
            name: "Backend Engineer".to_string(),
            role: "Rust API Developer".to_string(),
            parent_id: Some("node_eng_lead".to_string()),
            system_prompt: "You are the Backend Engineer at Pawsome. Build the Rust APIs for the product catalog, inventory, orders, and pet adoption applications. Organise your work with write_memory using folders (e.g. 'api/catalog.rs', 'api/orders.rs'). Publish finished API contracts to the shared team directory with write_shared_file under 'engineering/backend/' so the Frontend Engineer can integrate against them.".to_string(),
            tools: vec!["read_memory".to_string(), "write_memory".to_string(), "github_read_file".to_string(), "github_write_file".to_string(), "github_comment_issue".to_string()],
            model: None,
            provider: None,
            temperature: None,
            telemetry: None,
            scheduled_tasks: None,
            pending_messages: None, issue_triggers: None, company_id: None,
        },
        Agent {
            id: "node_product_lead".to_string(),
            name: "Product Lead".to_string(),
            role: "Product Manager".to_string(),
            parent_id: Some("node_project_manager".to_string()),
            system_prompt: "You are the Product Lead at Pawsome. Define the MVP requirements: browsing the pet/product catalog, checkout, and the adoption application flow. Assign design work to the Designer with create_sub_project, and publish the product spec to the shared team directory with write_shared_file at 'product/mvp-spec.md'.".to_string(),
            tools: vec!["create_sub_project".to_string(), "assign_task".to_string(), "github_read_file".to_string(), "github_write_file".to_string(), "github_comment_issue".to_string()],
            model: None,
            provider: None,
            temperature: None,
            telemetry: None,
            scheduled_tasks: None,
            pending_messages: None, issue_triggers: None, company_id: None,
        },
        Agent {
            id: "node_product_designer".to_string(),
            name: "Product Designer".to_string(),
            role: "UI/UX Designer".to_string(),
            parent_id: Some("node_product_lead".to_string()),
            system_prompt: "You are the Designer at Pawsome. Create wireframes and style guides for the storefront and adoption flow. Keep drafts organised with write_memory (e.g. 'wireframes/homepage.md', 'style/palette.css'). Publish finalised wireframes to the shared team directory with write_shared_file under 'product/wireframes/' for engineering to build from.".to_string(),
            tools: vec!["read_memory".to_string(), "write_memory".to_string(), "github_read_file".to_string(), "github_write_file".to_string(), "github_comment_issue".to_string()],
            model: None,
            provider: None,
            temperature: None,
            telemetry: None,
            scheduled_tasks: None,
            pending_messages: None, issue_triggers: None, company_id: None,
        },
        Agent {
            id: "node_growth_lead".to_string(),
            name: "Growth Lead".to_string(),
            role: "Marketing Director".to_string(),
            parent_id: Some("node_project_manager".to_string()),
            system_prompt: "You are the Growth Lead at Pawsome. Plan the launch campaign for the pet store and adoption marketplace. Use create_sub_project to document campaigns, and publish the go-to-market plan to the shared team directory with write_shared_file at 'growth/launch-plan.md'.".to_string(),
            tools: vec!["create_sub_project".to_string(), "assign_task".to_string(), "github_read_file".to_string(), "github_write_file".to_string(), "github_comment_issue".to_string()],
            model: None,
            provider: None,
            temperature: None,
            telemetry: None,
            scheduled_tasks: None,
            pending_messages: None, issue_triggers: None, company_id: None,
        },
        Agent {
            id: "node_growth_exec".to_string(),
            name: "Marketing Exec".to_string(),
            role: "Marketing Execution".to_string(),
            parent_id: Some("node_growth_lead".to_string()),
            system_prompt: "You are the Marketing Exec at Pawsome. Write launch campaign copy: emails, social posts, and adoption-drive promotions. Keep drafts organised with write_memory (e.g. 'campaigns/launch-email.txt', 'campaigns/social-posts.md'). Publish approved copy to the shared team directory with write_shared_file under 'growth/campaigns/'.".to_string(),
            tools: vec!["read_memory".to_string(), "write_memory".to_string(), "github_read_file".to_string(), "github_write_file".to_string(), "github_comment_issue".to_string()],
            model: None,
            provider: None,
            temperature: None,
            telemetry: None,
            scheduled_tasks: None,
            pending_messages: None, issue_triggers: None, company_id: None,
        },
    ];

    for agent in agents {
        state.add_agent(agent).await?;
    }

    for project in [
        Project {
            id: "proj_root_1".to_string(),
            title: "Pawsome MVP: Storefront & Checkout".to_string(),
            description: "Assigned to Eng Lead: build the product catalog, cart, and checkout for the online pet store.".to_string(),
            company_id: None,
        },
        Project {
            id: "proj_root_2".to_string(),
            title: "Pawsome MVP: Adoption Flow".to_string(),
            description: "Assigned to Product Lead: define the pet adoption application journey, from listing to approval.".to_string(),
            company_id: None,
        },
    ] {
        state.add_project(project).await?;
    }

    Ok(())
}