---
name: gitflow
description: GitFlow workflow — routes to colocated CLI commands (skills/gitflow/cli/) for deterministic execution
argument-hint: "[-f|-r|-h] <action> [name]"
cli: cli/
allowed-tools: [Read, Glob, Grep, Bash]  # Bash: CLI invocation
---

## Current state (auto-injected)
- Branch: !`git branch --show-current 2>/dev/null || echo "UNAVAILABLE"`
- Status: !`git status --short 2>/dev/null | head -10`
- Config: !`cat .claude/gitflow/config.json 2>/dev/null || echo "no config found"`

<objective>
Route GitFlow operations to colocated CLI commands in `skills/gitflow/cli/`.
Each CLI is self-contained (Zod types, validate, execute, orchestrate).
You interpret the JSON results for the user.
</objective>

<routing>

| User input            | CLI command                                                                  |
|-----------------------|------------------------------------------------------------------------------|
| `init [url]`          | `npx tsx skills/gitflow/cli/init/index.ts --spec '{"url":"<url>"}' --json`       |
| `-f <name>`           | `npx tsx skills/gitflow/cli/start/index.ts --spec '{"type":"feature","name":"<name>"}' --json` |
| `-r <version>`        | `npx tsx skills/gitflow/cli/start/index.ts --spec '{"type":"release","name":"<version>"}' --json` |
| `-h <name>`           | `npx tsx skills/gitflow/cli/start/index.ts --spec '{"type":"hotfix","name":"<name>"}' --json` |
| `commit [msg]`        | `npx tsx skills/gitflow/cli/commit/index.ts --spec '{"message":"<msg>"}' --json`  |
| `sync`                | `npx tsx skills/gitflow/cli/sync/index.ts --spec '{}' --json`                    |
| `pr`                  | `npx tsx skills/gitflow/cli/pr/index.ts --spec '{}' --json`                      |
| `merge`               | `npx tsx skills/gitflow/cli/merge/index.ts --spec '{}' --json`                   |
| `finish`              | `npx tsx skills/gitflow/cli/finish/index.ts --spec '{}' --json`                  |
| `status` or `-s`      | `npx tsx skills/gitflow/cli/status/index.ts --spec '{}' --json`                  |
| `cleanup`             | `npx tsx skills/gitflow/cli/cleanup/index.ts --spec '{}' --json`                 |
| `abort`               | `npx tsx skills/gitflow/cli/abort/index.ts --spec '{"git":true}' --json`         |
| `generate-msg`        | `npx tsx skills/gitflow/cli/generate-msg/index.ts --spec '{}' --json`            |

</routing>

<generate_msg_flow>

`generate-msg` is a two-phase process: YOU analyze, then the CLI formalizes.

**Phase 1 — Analysis (you do this):**

1. Run `git status --porcelain -uall` to get the list of changed files
2. Run `git diff --stat` to get an overview of changes
3. For each changed file, use the **Read** tool to understand the content
4. For modified files, run `git diff -- <file>` to see what changed precisely
5. Group changes by theme/module and identify the main intent
6. Determine:
   - `scope`: the primary module or component affected
   - `summary`: one-line description of what changed and WHY (max 72 chars, English)
   - Per-file: status (added/modified/deleted/renamed) + one-line summary

**Phase 2 — Formalization (CLI does this):**

Call the CLI with your analysis as structured JSON:

```bash
npx tsx skills/gitflow/cli/generate-msg/index.ts --spec '{
  "branch": "<current branch>",
  "branchType": "<feature|release|hotfix|develop|main|other>",
  "scope": "<main module>",
  "summary": "<one-line summary>",
  "files": [
    {"path": "src/main/router.ts", "status": "modified", "summary": "add 7 new git operation routes"},
    {"path": "src/client/pages/BranchPage.tsx", "status": "added", "summary": "full-page branch management UI"}
  ]
}' --json
```

The CLI returns a formatted conventional commit message in Markdown.

**Output:** The CLI result JSON has a `message` field. Output that message on the last line prefixed with:
```
COMMIT_MSG: <the message field from CLI result>
```

</generate_msg_flow>

<interpretation>

When the CLI returns JSON:
1. Check `success` field
2. If `false`: show `error` to user, suggest fix
3. If `true`: summarize key fields in readable format
4. If `needsInput: true` (init only): ask user the required questions
5. Always show the **next step** suggestion

</interpretation>

<init_flow>

`init` is special — the CLI is non-interactive. When it returns `needsInput: true`:

1. Show `detected` values to user
2. Ask: Repository URL (default: detected value)
3. Ask: Root folder (default: detected value)
4. Ask: Project name (default: detected value)
5. Ask: Worktree mode — organized/simple/disabled (default: organized)
6. Re-run with complete spec: `npx tsx skills/gitflow/cli/init/index.ts --spec '{"url":"<url>","root":"<path>","name":"<name>","mode":"<mode>"}' --json`

</init_flow>

<workflows>

```
FEATURE:  start -f → commit* → sync → pr → (review) → merge → finish
RELEASE:  start -r → commit* → sync → pr → (review) → merge → finish (+ tag + merge-back)
HOTFIX:   start -h → commit* → sync → pr → (review) → merge → finish (+ tag + merge-back)
```

</workflows>

<cli_structure>

Each CLI follows the Skill+CLI 4-file pattern:
```
cli/<command>/
├── types.ts      ← Zod schemas (input spec + output result)
├── validate.ts   ← Pure validation (no I/O, no git)
├── execute.ts    ← Execution (uses ../lib/, no validation)
└── index.ts      ← Orchestration: parse args → validate → execute → JSON
```

Shared utilities in `cli/lib/` (git, branch, config, worktree, provider, version, efcore, output, platform, paths).

</cli_structure>

<flags>

| Flag | Description |
|------|-------------|
| `--json` | All commands support JSON output |
| `--spec` | JSON input spec (required for all commands) |
| `--workdir` | Override working directory |

</flags>
