---
name: bonita-generate
description: Generate all Bonita artifacts (BOM, Organization, Process, Profile) from analysis document. Use when the user wants to generate, create, or build all Bonita artifacts at once from an analysis document.
disable-model-invocation: true
argument-hint: "[--input <analysis-file>] [--skip-readme]"
allowed-tools: Read, Bash, Glob, Grep
---

**Orchestrator skill** that generates all Bonita technical artifacts (XML and .proc files) from analysis documents by coordinating specialized generation skills.

## Description

This skill orchestrates the complete artifact generation workflow by calling specialized sub-skills:
- `/bonita-generate-bom` - Business Data Model (bom.xml)
- `/bonita-generate-organization` - Organization structure (organization.xml)
- `/bonita-generate-process` - Process diagram (.proc)
- `/bonita-generate-profile` - Application profiles (profile.xml)
- `/bonita-validate-artifacts` - Comprehensive XSD validation

All generated artifacts are validated and placed in `docs/artifacts/`, ready to import into Bonita Studio.

## Usage

```bash
# Generate all artifacts from most recent analysis document
/bonita-generate

# Generate from specific analysis document
/bonita-generate --input docs/out/analyse-validation-recrutement-2026-01-23.adoc

# Skip README generation
/bonita-generate --skip-readme

# Skip final validation
/bonita-generate --skip-validation

# Combine options
/bonita-generate --input docs/out/analyse-project.adoc --skip-readme
```

## Parameters

- `--input <path>` - Path to analysis document (default: most recent .adoc in `docs/out/`)
- `--skip-readme` - Skip README-ARTIFACTS.md generation (optional)
- `--skip-validation` - Skip final validation step (optional)

## Prerequisites

- Analysis document must exist in `docs/out/` (generated by `/bonita-analyze-docs`)
- Docker must be available for XML validation and UUID generation
- All sub-skills must be available:
  - `/bonita-generate-bom`
  - `/bonita-generate-organization`
  - `/bonita-generate-process`
  - `/bonita-generate-profile`
  - `/bonita-validate-artifacts`

## Global Directives

**IMPORTANT GLOBAL DIRECTIVE**: If you need any tooling (python3, xmllint, jq, etc.), use a Docker version to run the tool instead of relying on local installation. Example: `docker run --rm python:3 python3 -c "import uuid; print(uuid.uuid4())"` or `docker run --rm alpine:latest sh -c "apk add --no-cache libxml2-utils >/dev/null 2&1 && xmllint xmllint --version`.

## Execution Steps

Follow these steps in order:

> **Arguments**: Apply user-provided options from `$ARGUMENTS` (e.g., `--input`, `--skip-readme`, `--skip-validation`) before starting.

### Step 0: Prepare and Read Analysis
[Read detailed instructions](steps/00-prepare.md)
- Create `docs/artifacts/` directory if it doesn't exist
- Find and select analysis document
- Read the analysis document to understand requirements
- Store document path for sub-skills

### Step 1: Generate BOM XML
[Read detailed instructions](steps/01-bom-generation.md)
- **Call `/bonita-generate-bom` sub-skill**
- Pass analysis document path from Step 0
- BOM will be generated at `docs/artifacts/bom.xml`
- Includes automatic XSD validation

### Step 2: Generate Organization XML
[Read detailed instructions](steps/02-organization-generation.md)
- **Call `/bonita-generate-organization` sub-skill**
- Pass analysis document path from Step 0
- Organization will be generated at `docs/artifacts/organization.xml`
- Includes automatic XSD validation

### Step 3: Generate Process Diagram
[Read detailed instructions](steps/03-process-generation.md)
- **Call `/bonita-generate-process` sub-skill**
- Pass analysis document path from Step 0
- Process diagram will be generated at `docs/artifacts/ProcessName-1.0.proc`
- Includes automatic XSD validation

### Step 4: Generate Profile XML
[Read detailed instructions](steps/04-profile-generation.md)
- **Call `/bonita-generate-profile` sub-skill**
- Pass analysis document path from Step 0
- Profile will be generated at `docs/artifacts/profile.xml`
- Includes automatic XSD validation

### Step 5: Generate README
[Read detailed instructions](steps/05-readme-generation.md)
- Create comprehensive README-ARTIFACTS.md
- Include file descriptions, statistics, implementation guide
- Save to `docs/artifacts/README-ARTIFACTS.md`
- Skip if `--skip-readme` parameter provided

### Step 6: Validate All Artifacts
[Read detailed instructions](steps/06-validate.md)
- **Call `/bonita-validate-artifacts` sub-skill**
- Comprehensive validation of all generated artifacts
- Generate validation report
- Skip if `--skip-validation` parameter provided

### Step 7: Summary
[Read detailed instructions](steps/07-summary.md)
- Provide comprehensive summary of generated artifacts
- List all files with sizes and validation status
- Provide next steps for import into Bonita Studio
- Report any errors or warnings

## Orchestration Flow

```
Start
  ↓
Step 0: Prepare
  ├─ Create docs/artifacts/
  ├─ Select analysis document
  └─ Store document path
  ↓
Step 1: Call /bonita-generate-bom --input <doc> --output docs/artifacts/bom.xml
  ↓
Step 2: Call /bonita-generate-organization --input <doc> --output docs/artifacts/organization.xml
  ↓
Step 3: Call /bonita-generate-process --input <doc> --output docs/artifacts/
  ↓
Step 4: Call /bonita-generate-profile --input <doc> --output docs/artifacts/profile.xml
  ↓
Step 5: Generate README-ARTIFACTS.md (unless --skip-readme)
  ↓
Step 6: Call /bonita-validate-artifacts --directory docs/artifacts/ (unless --skip-validation)
  ↓
Step 7: Provide Summary
  ↓
End
```

## Output Structure

```
docs/artifacts/
├── bom.xml                          # Business Object Model
├── organization.xml                 # Users, roles, groups
├── ProcessName-1.0.proc            # BPMN process diagram
├── profile.xml                      # Application profiles
└── README-ARTIFACTS.md             # Complete documentation
```

## Sub-Skills

This orchestrator delegates to these specialized skills:

### /bonita-generate-bom
Generates Business Data Model (BDM) XML from analysis document:
- Extracts entity definitions
- Generates Bonita 10.x compatible BOM
- Uses LONG foreign keys (no AGGREGATION/COMPOSITION)
- Validates against bom.xsd
- Output: `docs/artifacts/bom.xml`

### /bonita-generate-organization
Generates Organization XML from analysis document:
- Extracts users, roles, groups, memberships
- Creates test users with password "bpm"
- Validates against organization.xsd
- Output: `docs/artifacts/organization.xml`

### /bonita-generate-process
Generates Process Diagram (.proc) from analysis document:
- Extracts workflow structure
- Generates UUIDs using Docker
- Creates BPMN 2.0 diagram (bonitaModelVersion="9")
- Validates against ProcessDefinition.xsd
- Output: `docs/artifacts/ProcessName-1.0.proc`

### /bonita-generate-profile
Generates Profile XML from analysis document:
- Extracts profiles and mappings
- Includes standard Bonita profiles (User, Administrator)
- Validates against profiles.xsd
- Output: `docs/artifacts/profile.xml`

### /bonita-validate-artifacts
Validates all generated artifacts:
- Validates each XML/proc file against XSD
- Generates validation report
- Reports file statistics
- Exit code indicates success/failure

## Benefits of Orchestration

### Modularity
- Each artifact can be regenerated independently
- Use sub-skills directly: `/bonita-generate-bom --input doc.adoc`
- No need to regenerate all artifacts if only one changes

### Testability
- Each sub-skill tested in isolation
- Clear separation of concerns
- Easier to debug individual artifact generation

### Reusability
- Sub-skills usable outside orchestrator
- Validation skill useful for manual editing workflows
- Process can be extended with new artifact types

### Maintainability
- Changes to artifact generation isolated to sub-skills
- Orchestrator remains simple and focused
- Clear documentation per artifact type

## Error Handling

If any sub-skill fails:
1. Report the specific sub-skill that failed
2. Show error details from sub-skill
3. Continue with remaining steps (best effort)
4. Report all errors in final summary
5. Exit with error code if any failures occurred

## Backward Compatibility

The orchestrator maintains full backward compatibility:
- Same usage: `/bonita-generate`
- Same parameters: `--input`
- Same output directory: `docs/artifacts/`
- Same file names and structure
- New optional parameters: `--skip-readme`, `--skip-validation`

## Performance

Orchestration overhead:
- Sub-skill invocation adds minimal overhead
- Each sub-skill performs its own validation
- Total time similar to monolithic approach
- Benefits: better error messages, modular regeneration

## Examples

### Generate All Artifacts
```bash
/bonita-generate
```

### Regenerate Only BOM
```bash
/bonita-generate-bom --input docs/out/analyse-project.adoc
```

### Regenerate Organization and Validate
```bash
/bonita-generate-organization --input docs/out/analyse-project.adoc
/bonita-validate-artifacts
```

### Generate Without README
```bash
/bonita-generate --skip-readme
```

### Generate and Skip Final Validation
```bash
/bonita-generate --skip-validation
```

## Notes

- All artifacts are Bonita 10.x compatible
- BOM uses Long foreign keys (no AGGREGATION/COMPOSITION)
- Organization includes test users with password "bpm"
- Process diagrams use bonitaModelVersion="9"
- All XML files validated against XSD schemas
- Sub-skills can be used independently for granular regeneration
