Data Model: Smarter Feature Merge

This document defines the key entities and their relationships for the enhanced merge command.

Entities

MergeState

Persisted state for resumable multi-WP merges. Stored at .kittify/merge-state.json.

FieldTypeDescription
feature_slugstringFeature identifier (e.g., "017-smarter-merge")
target_branchstringBranch being merged into (e.g., "main")
wp_orderstring[]WP IDs in merge order (topologically sorted)
completed_wpsstring[]WP IDs that have been successfully merged
current_wpstring \null
has_pending_conflictsbooleanTrue if git merge state has unresolved conflicts
strategystringMerge strategy: "merge", "squash", or "rebase"
started_atstringISO 8601 timestamp when merge started
last_updatedstringISO 8601 timestamp of last state change

Example:

{
  "feature_slug": "017-smarter-feature-merge",
  "target_branch": "main",
  "wp_order": ["WP01", "WP02", "WP03", "WP04"],
  "completed_wps": ["WP01", "WP02"],
  "current_wp": "WP03",
  "has_pending_conflicts": true,
  "strategy": "merge",
  "started_at": "2025-01-18T10:30:00Z",
  "last_updated": "2025-01-18T10:45:00Z"
}

Lifecycle: 1. Created when multi-WP merge starts (after pre-flight passes) 2. Updated after each WP merge completes or conflicts 3. Deleted on successful completion or explicit --abort


PreflightResult

Result of pre-merge validation checks. In-memory only (not persisted).

FieldTypeDescription
passedbooleanTrue if all checks pass
wp_statusesWPStatus[]Status of each WP worktree
target_divergedbooleanTrue if target branch has diverged from origin
target_divergence_msgstring \null
errorsstring[]Blocking issues that prevent merge
warningsstring[]Non-blocking issues to display

WPStatus

Status of a single WP worktree during pre-flight.

FieldTypeDescription
wp_idstringWork package ID (e.g., "WP01")
worktree_pathPathAbsolute path to worktree directory
branch_namestringGit branch name
is_cleanbooleanTrue if no uncommitted changes
errorstring \null

ConflictPrediction

Predicted conflict for a file, generated during --dry-run or pre-merge analysis.

FieldTypeDescription
file_pathstringPath relative to repo root
conflicting_wpsstring[]WP IDs that modify this file
is_status_filebooleanTrue if matches status file pattern
confidencestring"certain", "likely", or "possible"

Confidence Levels:

  • certain: git merge-tree detected actual conflict markers
  • likely: Same lines modified in multiple WPs (git diff --stat overlap)
  • possible: Same file modified in multiple WPs (may not conflict)

ResolutionResult

Result of auto-resolving a status file conflict.

FieldTypeDescription
file_pathPathAbsolute path to resolved file
resolvedbooleanTrue if all conflicts in file were resolved
resolution_typestringType of resolution applied
original_conflictsintNumber of conflict regions found
resolved_conflictsintNumber of conflict regions resolved

Resolution Types:

  • lane: Resolved lane: field by "more done" wins
  • checkbox: Resolved checkboxes by preferring [x]
  • history: Resolved history: by chronological merge
  • mixed: Multiple resolution types applied
  • manual_required: Contains non-status conflicts

Relationships

MergeState
    │
    ├── 1:N ─→ WPStatus (via wp_order → find_wp_worktrees)
    │
    └── contains ─→ completed_wps, current_wp (subset of wp_order)

PreflightResult
    │
    └── 1:N ─→ WPStatus (wp_statuses)

ConflictPrediction
    │
    └── N:M ─→ WP IDs (conflicting_wps)

ResolutionResult
    │
    └── 1:1 ─→ File (file_path)

State Transitions

MergeState Lifecycle

[No State] ──(start merge)──→ [Active: current_wp=WP01]
                                        │
                     ┌──────────────────┼──────────────────┐
                     │                  │                  │
                     ▼                  ▼                  ▼
            [WP merged OK]    [Conflict detected]    [Interrupted]
                     │                  │                  │
                     │           ┌──────┴──────┐           │
                     │           ▼             ▼           │
                     │    [Auto-resolved]  [Manual req]    │
                     │           │             │           │
                     ▼           ▼             │           │
              [Next WP]   [Continue]      [--resume]  [--resume]
                     │           │             │           │
                     └─────┬─────┴─────────────┴───────────┘
                           │
                           ▼
                    [All WPs done]
                           │
                           ▼
                      [Cleanup]
                           │
                           ▼
                    [State cleared]

Resolution Flow

[Merge conflict] ──→ [Check file pattern]
                            │
              ┌─────────────┴─────────────┐
              │                           │
              ▼                           ▼
    [Status file match]           [Non-status file]
              │                           │
              ▼                           ▼
    [Parse conflict markers]      [Manual required]
              │
              ▼
    [Apply resolution rules]
              │
              ▼
    [git add resolved file]
              │
              ▼
    [Continue merge]

File Patterns

Status File Detection

Files matching these patterns are candidates for auto-resolution:

kitty-specs/**/tasks/*.md     # WP files (e.g., WP01.md)
kitty-specs/**/tasks.md       # Main tasks checklist

Resolution Rules

Content PatternRuleWinner
lane: <value>"More done" winsdone > for_review > doing > planned
- [x] vs - [ ]Checked wins[x]
history: arrayConcatenateMerge by timestamp, dedupe
Other YAMLNo auto-resolveManual
Non-YAML contentNo auto-resolveManual