#!/usr/bin/env nu
# Install syntaxis integration to project .claude/

def print_help [] {
    print ""
    print "syntaxis Project Installer"
    print ""
    print "USAGE:"
    print "  install.nu [project-path]"
    print "  install.nu ."
    print "  install.nu help"
    print ""
}

def main [
    project_path?: string
    --verbose
] {
    if ($project_path == null or $project_path == "help") {
        print_help
        return
    }

    let tools_home = $env.TOOLS_HOME? | default "/Users/Akasha/Tools"
    let project = if ($project_path == ".") { pwd } else { $project_path }

    if not ($project | path exists) {
        print ("Error: Project not found: " + $project)
        return
    }

    print ""
    print "Installing syntaxis to project"
    print ("Project: " + $project)
    print ""

    let claude_dir = ([$project, ".claude"] | path join)
    let agents_dir = ([$project, ".claude", "agents"] | path join)
    let skills_dir = ([$project, ".claude", "skills"] | path join)

    mkdir $claude_dir
    mkdir $agents_dir
    mkdir $skills_dir

    print "Created .claude/ structure"

    let tools_dir = ([$project, ".project"] | path join)
    let coder_dir = ([$project, ".coder"] | path join)
    mkdir $tools_dir
    mkdir $coder_dir

    let config_dst = ([$tools_dir, "syntaxis.toml"] | path join)

    if not ($config_dst | path exists) {
        let lines = [
            "[project]",
            "name = \"My Project\"",
            "version = \"0.1.0\"",
            "created_date = \"2025-11-12\"",
            "",
            "[syntaxis]",
            "enabled = true",
            "track_phases = true",
            "validate_checklists = true",
            "",
            "[phases]",
            "active = [\"planning\", \"development\", \"testing\", \"release\"]",
            "",
            "[integration]",
            "session_dir = \".coder/sessions\"",
            "git_tracking = true"
        ]
        try {
            $lines | str join "\n" | save $config_dst
            print "  Config: .project/syntaxis.toml"
        } catch {
            print "  Error creating config"
        }
    }

    print ""
    print "Done!"
    print ""
}
