# Story 3.2: Permission Code Generation System

## Metadata
- **Story ID**: 3.2
- **Title**: Permission Code Generation System
- **Epic**: 3 - Module Framework
- **Status**: Pending
- **Priority**: High
- **Estimated Time**: 4-5 hours
- **Dependencies**: 3.1

## Goal
Create automated permission code generation from module manifests to ensure type-safe permission constants.

## Description
This story implements a code generation system that scans module manifests and generates type-safe permission constants, ensuring permissions are defined in one place and used consistently throughout the codebase.

## Deliverables

### 1. Permission Generation Script (`scripts/generate-permissions.go`)
- Scan all `modules/*/module.yaml` files
- Extract permissions from manifests
- Generate `pkg/perm/generated.go` with Permission constants
- Support for multiple modules
- Error handling and validation
- Format generated code

### 2. Go Generate Integration
- `//go:generate` directive in `pkg/perm/perm.go`
- Automatic generation on build
- Integration with build process

### 3. Makefile Integration
- `make generate` command
- Run permission generation
- Verify generated code

## Implementation Steps

1. **Create Generation Script**
   - Create `scripts/generate-permissions.go`
   - Implement YAML parsing
   - Implement code generation

2. **Add Go Generate Directive**
   - Add directive to `pkg/perm/perm.go`
   - Test generation

3. **Update Makefile**
   - Add `make generate` command
   - Integrate with build process

## Acceptance Criteria
- [ ] Permission constants are generated from `module.yaml`
- [ ] Generated code is type-safe
- [ ] Code generation runs automatically
- [ ] Permissions follow naming convention
- [ ] Multiple modules are supported
- [ ] Generated code is properly formatted

## Files to Create/Modify
- `scripts/generate-permissions.go` - Generation script
- `pkg/perm/perm.go` - Add go:generate directive
- `Makefile` - Add generate command

