ADR-029: AI-Powered Plan Mode (Vibe Mode)

Status

Proposed

Date

2025-12-07

Deciders

Context and Problem Statement

iDempiere consultants spend significant time analyzing client requirements, designing Application Dictionary structures, and manually creating AD elements in the correct order. This process is:

  1. Time-consuming (days for complex modules)
  2. Error-prone (missing dependencies, wrong order)
  3. Undocumented (no ADRs, no implementation guides)
  4. Hard to estimate (no structured breakdown)

We need a CLI mode that lets consultants describe what they need in natural language and get a production-ready, executable implementation plan with documentation.

Reference: Inspired by Claude Code's plan mode and "vibe coding" approach.

Decision Drivers

Considered Options

  1. Wizard-based - Interactive step-by-step prompts
  2. Template-based - Pre-defined plugin templates
  3. AI Plan Mode - Natural language to executable plan

Decision Outcome

Chosen option: "AI Plan Mode", because it combines the flexibility of natural language input with the rigor of structured, validated execution plans. It follows clig.dev guidelines by being fully scriptable while optionally interactive.

Confirmation

The Vibe Mode Workflow

┌─────────────────────────────────────────────────────────────────┐
│                         VIBE MODE                               │
│                                                                  │
│   INPUT (natural language)                                      │
│   "equipment maintenance with work orders and parts tracking"   │
│                                                                  │
│         ↓ AI Analysis (LangChain4j)                             │
│                                                                  │
│   UNDERSTAND                                                    │
│   ├── Domain: Maintenance Management                            │
│   ├── Entities: Equipment, WorkOrder, Part, Technician          │
│   ├── Patterns: Document (WorkOrder), Master (Equipment, Part)  │
│   └── Relationships: Equipment→WorkOrder→WorkOrderLine→Part     │
│                                                                  │
│         ↓ Plan Generation                                       │
│                                                                  │
│   GENERATE                                                      │
│   ├── docs/adr/XXX-maintenance-module.md                        │
│   ├── docs/FUNCTIONAL_SPEC.md                                   │
│   ├── docs/IMPLEMENTATION_PLAN.md                               │
│   ├── plan/plan.json (executable steps)                         │
│   └── plan/todo.md (human checklist)                            │
│                                                                  │
│         ↓ Execution                                             │
│                                                                  │
│   EXECUTE (step-by-step)                                        │
│   [1/47] Creating AD_Element: XX_Equipment_ID    ✔              │
│   [2/47] Creating AD_Element: XX_WorkOrder_ID    ✔              │
│   [3/47] Creating AD_Table: XX_Equipment         ✔              │
│   [4/47] Creating AD_Table: XX_WorkOrder         ✘ Pre-flight   │
│          → Skip / Retry / Abort / Force                         │
│                                                                  │
│         ↓ Output                                                │
│                                                                  │
│   DISTRIBUTE                                                    │
│   ├── 2pack/Maintenance_1.0.0.zip                               │
│   └── migration/maintenance_001.sql                             │
└─────────────────────────────────────────────────────────────────┘

Command Interface

Create Plan (non-interactive, scriptable)

# From text
idempiere-cli plan "equipment maintenance with work orders"

# From file
idempiere-cli plan --input requirements.txt

# With options
idempiere-cli plan "sales order module" \
  --prefix XX \
  --entity-type com.example \
  --output ./my-project

Review Plan

# Show plan summary
idempiere-cli plan --show maintenance-module

# Show full plan
idempiere-cli plan --show maintenance-module --verbose

# Export plan
idempiere-cli plan --export maintenance-module --format json

Execute Plan

# Execute all steps
idempiere-cli plan --execute maintenance-module

# Dry-run (preview without changes)
idempiere-cli plan --execute maintenance-module --dry-run

# Execute with auto-skip existing
idempiere-cli plan --execute maintenance-module --skip-existing

# Resume from checkpoint
idempiere-cli plan --resume maintenance-module

Full Scriptable Flow (CI/CD)

# One-liner for automation
idempiere-cli plan "sales order" \
  --output ./plan \
  --execute \
  --skip-existing \
  --format pack \
  --json

Generated Artifacts

.idempiere/plans/maintenance-module/
├── plan.json              # Executable steps with dependencies
├── state.json             # Execution checkpoint (resume support)
├── todo.md                # Human-readable checklist
├── estimate.md            # Effort breakdown
│
├── docs/
│   ├── adr.md             # Architecture decision record
│   ├── functional-spec.md # Client-facing: what it does
│   └── implementation.md  # Technical: how to build
│
└── output/
    ├── 2pack/             # Ready-to-deploy package
    └── migration/         # SQL scripts

Plan.json Structure

{
  "name": "maintenance-module",
  "description": "Equipment maintenance with work orders",
  "created": "2025-12-07T10:30:00Z",
  "prefix": "XX",
  "entityType": "D",

  "analysis": {
    "domain": "Maintenance Management",
    "patterns": ["document", "master-data", "transaction-line"],
    "entities": ["Equipment", "WorkOrder", "WorkOrderLine", "Part"]
  },

  "steps": [
    {
      "id": 1,
      "type": "element",
      "action": "create",
      "name": "XX_Equipment_ID",
      "description": "Equipment unique identifier",
      "status": "pending",
      "depends": [],
      "command": "dict element add --column-name XX_Equipment_ID --name Equipment --type ID",
      "validation": {
        "pre": "SELECT COUNT(*) = 0 FROM AD_Element WHERE ColumnName = 'XX_Equipment_ID'",
        "post": "SELECT AD_Element_ID FROM AD_Element WHERE ColumnName = 'XX_Equipment_ID'"
      }
    },
    {
      "id": 2,
      "type": "table",
      "action": "create",
      "name": "XX_Equipment",
      "description": "Equipment master data",
      "status": "pending",
      "depends": [1],
      "command": "dict table add --name XX_Equipment --type master --columns standard,uuid",
      "validation": {
        "pre": "SELECT COUNT(*) = 0 FROM AD_Table WHERE TableName = 'XX_Equipment'",
        "post": "SELECT AD_Table_ID FROM AD_Table WHERE TableName = 'XX_Equipment'"
      }
    },
    {
      "id": 3,
      "type": "column",
      "action": "create",
      "name": "XX_Equipment.Name",
      "status": "pending",
      "depends": [2],
      "command": "dict column add --table XX_Equipment --column Name --type String --mandatory"
    }
  ],

  "summary": {
    "totalSteps": 47,
    "elements": 8,
    "tables": 4,
    "columns": 28,
    "windows": 2,
    "processes": 1
  }
}

AI Analysis Patterns

The AI recognizes iDempiere patterns from natural language:

Input Phrase Detected Pattern Generated Structure
"work order" Document Table + DocType + Workflow
"equipment", "product" Master Data Table + Window + standard columns
"order line", "detail" Transaction Line Child table with parent FK
"approval" Workflow DocAction, DocStatus columns
"tracking", "history" Audit IsActive, Created, Updated columns
"inventory", "stock" Material Management Locator, Warehouse references

Integration with Existing ADRs

ADR Integration
ADR-004 Table/column creation commands
ADR-005 Migration script generation
ADR-008 AD Registry queries for validation
ADR-013 LangChain4j for AI analysis
ADR-028 Pre-flight checks, error handling

Implementation Architecture

src/main/java/org/idempiere/cli/
├── commands/
│   └── PlanCommand.java           # Main plan command
├── plan/
│   ├── PlanService.java           # Orchestration
│   ├── PlanAnalyzer.java          # AI analysis (LangChain4j)
│   ├── PlanGenerator.java         # Generate plan.json
│   ├── PlanExecutor.java          # Step-by-step execution
│   ├── PlanCheckpoint.java        # State management
│   └── model/
│       ├── Plan.java              # Plan record
│       ├── PlanStep.java          # Step record
│       └── PlanAnalysis.java      # AI analysis result
├── docs/
│   └── DocumentGenerator.java     # Generate ADR, specs, guides
└── ai/
    └── PlanAnalyzerAgent.java     # LangChain4j agent for analysis

Pros and Cons of the Options

Option 1: Wizard-based

Interactive step-by-step prompts.

Option 2: Template-based

Pre-defined plugin templates.

Option 3: AI Plan Mode (Chosen)

Natural language to executable plan.

More Information

Target Users

Persona Use Case
Consultant Quick analysis, client proposals, effort estimates
Implementer Execute plans, customize, deploy
Developer Extend with custom steps, integrate in CI/CD

Effort Estimation

Plan includes step count which maps to effort:

Step Type Typical Time Notes
Element 2 min Simple creation
Table 5 min Includes sync
Column 2 min Per column
Window 10 min With tabs
Process 15 min Includes Java class

Formula: estimated_hours = (elements * 0.03) + (tables * 0.08) + (columns * 0.03) + (windows * 0.17) + (processes * 0.25)

References

Path: /docs/developers/architecture/idempiere-hub/029-ai-plan-mode