<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**

- [Packs System - Quick Fix Guide](#packs-system---quick-fix-guide)
  - [🎯 Goal: Get System Compiling in 2-4 Hours](#-goal-get-system-compiling-in-2-4-hours)
  - [Fix 1: Add async-trait Dependency (5 minutes)](#fix-1-add-async-trait-dependency-5-minutes)
  - [Fix 2: Make PackRepository Dyn-Compatible (30 minutes)](#fix-2-make-packrepository-dyn-compatible-30-minutes)
  - [Fix 3: Fix Ownership in install.rs (15 minutes)](#fix-3-fix-ownership-in-installrs-15-minutes)
  - [Fix 4: Fix String Type in installer.rs (15 minutes)](#fix-4-fix-string-type-in-installerrs-15-minutes)
  - [Fix 5: Fix InstallInput Type (30 minutes)](#fix-5-fix-installinput-type-30-minutes)
  - [Fix 6: Remove Unused Imports (10 minutes)](#fix-6-remove-unused-imports-10-minutes)
  - [Verification Checklist](#verification-checklist)
  - [Post-Fix Validation](#post-fix-validation)
    - [Workflow 1: List Packs](#workflow-1-list-packs)
    - [Workflow 2: Show Pack Details](#workflow-2-show-pack-details)
    - [Workflow 3: Dry-Run Install](#workflow-3-dry-run-install)
    - [Workflow 4: Generate Project](#workflow-4-generate-project)
    - [Workflow 5: Compose Multi-Pack](#workflow-5-compose-multi-pack)
    - [Workflow 6: Execute SPARQL](#workflow-6-execute-sparql)
  - [Troubleshooting](#troubleshooting)
    - [Issue: Still getting async trait errors after adding dependency](#issue-still-getting-async-trait-errors-after-adding-dependency)
    - [Issue: Type conversion errors persist](#issue-type-conversion-errors-persist)
    - [Issue: Tests fail after compilation succeeds](#issue-tests-fail-after-compilation-succeeds)
    - [Issue: Workflows return "pack not found"](#issue-workflows-return-pack-not-found)
  - [Timeline Estimate](#timeline-estimate)
  - [Next Steps After Fixes](#next-steps-after-fixes)
  - [Success Criteria](#success-criteria)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

# Packs System - Quick Fix Guide

## 🎯 Goal: Get System Compiling in 2-4 Hours

This guide provides step-by-step instructions to resolve all critical compilation errors and get the packs system to a testable state.

---

## Fix 1: Add async-trait Dependency (5 minutes)

**File**: `crates/ggen-domain/Cargo.toml`

**Add this to dependencies section**:
```toml
[dependencies]
# ... existing dependencies ...
async-trait = "0.1"
```

**Verify**:
```bash
cargo build --package ggen-domain
# Should see: Compiling async-trait v0.1.x
```

---

## Fix 2: Make PackRepository Dyn-Compatible (30 minutes)

**File**: `crates/ggen-domain/src/packs/repository.rs`

**Add import at top**:
```rust
use async_trait::async_trait;
```

**Add macro to trait**:
```rust
#[async_trait]
pub trait PackRepository: Send + Sync {
    async fn load(&self, pack_id: &str) -> Result<Pack>;
    async fn list(&self, category: Option<&str>) -> Result<Vec<Pack>>;
    async fn save(&self, pack: &Pack) -> Result<()>;
    async fn exists(&self, pack_id: &str) -> Result<bool>;
    async fn delete(&self, pack_id: &str) -> Result<()>;
}
```

**Add macro to implementation**:
```rust
#[async_trait]
impl PackRepository for FileSystemRepository {
    async fn load(&self, pack_id: &str) -> Result<Pack> {
        // ... existing implementation ...
    }
    // ... rest of methods ...
}
```

**Verify**:
```bash
cargo build --package ggen-domain --lib
# Should compile without async trait errors
```

---

## Fix 3: Fix Ownership in install.rs (15 minutes)

**File**: `crates/ggen-domain/src/packs/install.rs`

**Change lines 53-56 from**:
```rust
InstallReport {
    pack: pack.clone(),
    packages_installed: report.packages_installed,
    packages_skipped: report.packages_skipped,
    total_packages: report.packages_installed.len(),  // ❌ Use after move!
    // ...
}
```

**To**:
```rust
let packages_count = report.packages_installed.len();  // ✅ Calculate before move
InstallReport {
    pack: pack.clone(),
    packages_installed: report.packages_installed,
    packages_skipped: report.packages_skipped,
    total_packages: packages_count,  // ✅ Use calculated value
    // ...
}
```

**Verify**:
```bash
cargo build --package ggen-domain --lib
# Should not see E0382 error
```

---

## Fix 4: Fix String Type in installer.rs (15 minutes)

**File**: `crates/ggen-domain/src/packs/installer.rs`

**Change line 139 from**:
```rust
packages_installed.push(package_name.clone());  // ❌ Pushes &str
```

**To**:
```rust
packages_installed.push(package_name.to_string());  // ✅ Converts to String
```

**Verify**:
```bash
cargo build --package ggen-domain --lib
# Should not see Vec<&str> vs Vec<String> error
```

---

## Fix 5: Fix InstallInput Type (30 minutes)

**File**: `crates/ggen-domain/src/packs/installer.rs`

**Change line 277 from**:
```rust
marketplace::execute_install(&marketplace_options).await?;
```

**To**:
```rust
let install_input = InstallInput {
    package_name: marketplace_options.package_name.clone(),
    version: marketplace_options.version.clone(),
    target_dir: marketplace_options.target_dir.clone(),
    dry_run: marketplace_options.dry_run,
    force: marketplace_options.force,
    verbose: marketplace_options.verbose,
};
marketplace::execute_install(install_input).await?;
```

**Note**: Adjust field names based on actual `InstallInput` and `InstallOptions` struct definitions.

**Verify**:
```bash
cargo build --package ggen-domain --lib
# Should not see type mismatch error
```

---

## Fix 6: Remove Unused Imports (10 minutes)

**File**: `crates/ggen-domain/src/packs/compose.rs` (line 206)
```rust
// Remove PackTemplate if unused
use crate::packs::types::{PackDependency, PackMetadata};
```

**File**: `crates/ggen-domain/src/packs/composer.rs` (line 393)
```rust
// Remove PackDependency if unused
use crate::packs::types::{PackMetadata, PackTemplate};
```

**File**: `crates/ggen-domain/src/packs/dependency_graph.rs` (line 222)
```rust
// Remove PackTemplate if unused
use crate::packs::types::{PackDependency, PackMetadata};
```

**File**: `crates/ggen-domain/src/packs/installer.rs` (lines 393-394)
```rust
// Remove all if unused in tests
// use crate::packs::types::{PackDependency, PackMetadata, PackTemplate};
// use std::collections::HashMap;
```

**File**: `crates/ggen-domain/src/packs/repository.rs` (line 9)
```rust
// Remove Path if unused
use std::path::PathBuf;
```

**Verify**:
```bash
cargo build --package ggen-domain --lib
# Should not see unused_imports warnings
```

---

## Verification Checklist

After applying all fixes, run these commands:

```bash
# 1. Check compilation (should succeed with 0 errors)
cargo build --package ggen-domain --lib

# 2. Run clippy (should have 0 errors in packs module)
cargo clippy --package ggen-domain --lib -- -D warnings 2>&1 | grep packs

# 3. Build release binary (should succeed)
cargo build --release

# 4. Run packs tests (should compile and run)
cargo test --package ggen-domain --lib packs::

# 5. Run integration tests (if any)
cargo test --package ggen-domain --lib packs::integration::
```

**Expected Results**:
- ✅ All commands succeed
- ✅ 0 compilation errors
- ✅ 0 clippy warnings in packs module
- ✅ Tests compile and execute

---

## Post-Fix Validation

Once compilation succeeds, execute these user workflows:

### Workflow 1: List Packs
```bash
./target/release/ggen packs list --category "web"
```
**Expected**: List of web-related packs (or empty if none configured)

### Workflow 2: Show Pack Details
```bash
./target/release/ggen packs show --pack_id web-api-pack
```
**Expected**: Pack metadata displayed

### Workflow 3: Dry-Run Install
```bash
./target/release/ggen packs install --pack_id web-api-pack --dry-run
```
**Expected**: Installation plan shown, no actual changes

### Workflow 4: Generate Project
```bash
./target/release/ggen packs generate --pack_id web-api-pack --project-name test-api
```
**Expected**: Project structure created in `test-api/`

### Workflow 5: Compose Multi-Pack
```bash
./target/release/ggen packs compose --pack_ids web-api-pack,devops-pack --project-name test-compose
```
**Expected**: Merged project structure created

### Workflow 6: Execute SPARQL
```bash
./target/release/ggen packs query --pack_id web-api-pack --query "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 10"
```
**Expected**: SPARQL query results

---

## Troubleshooting

### Issue: Still getting async trait errors after adding dependency
**Solution**: Run `cargo clean && cargo build` to force rebuild

### Issue: Type conversion errors persist
**Solution**: Check actual struct definitions in `marketplace/install.rs` for correct field names

### Issue: Tests fail after compilation succeeds
**Solution**: Check test setup - may need test data or mock repository configuration

### Issue: Workflows return "pack not found"
**Solution**: Check if pack repository is initialized. May need to run `ggen packs sync` first.

---

## Timeline Estimate

| Task | Time | Cumulative |
|------|------|------------|
| Add async-trait dependency | 5 min | 5 min |
| Fix PackRepository trait | 30 min | 35 min |
| Fix install.rs ownership | 15 min | 50 min |
| Fix installer.rs String type | 15 min | 65 min |
| Fix InstallInput type | 30 min | 95 min |
| Remove unused imports | 10 min | 105 min |
| Verification & testing | 30 min | 135 min |
| **Total** | **~2.5 hours** | - |

**Contingency**: +1 hour for unexpected issues
**Total with contingency**: **3-4 hours**

---

## Next Steps After Fixes

1. **Run Full Test Suite** (1-2 hours)
   - All unit tests should pass
   - Document any test failures
   - Fix failing tests

2. **Execute User Workflows** (2-4 hours)
   - Test all 6 workflows end-to-end
   - Document actual vs expected behavior
   - Fix any workflow issues

3. **Performance Validation** (2-4 hours)
   - Benchmark pack loading
   - Benchmark composition
   - Ensure <2s single pack, <10s complex

4. **Re-Run Production Validation** (1 hour)
   - Run full validation protocol
   - Generate updated scorecard
   - Target: 95+ score

**Total Timeline to Production Ready**: 2-3 days with dedicated effort

---

## Success Criteria

- [ ] Compiles without errors or warnings
- [ ] All tests pass (100%)
- [ ] All 6 user workflows execute successfully
- [ ] Performance meets targets
- [ ] Production readiness score ≥ 95/100

**Good luck! The fixes are straightforward - just methodical application of each change.**
