ide

package
v0.5.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IDECursor     = "cursor"
	IDEVSCode     = "vscode"
	IDECopilot    = "copilot" // vscode + copilot
	IDEClaudeCode = "claude-code"
	IDEWindsurf   = "windsurf"
	IDECline      = "cline"
	IDEZed        = "zed"
	IDENeovim     = "neovim"
	IDEJetBrains  = "jetbrains"
	IDEUnknown    = "unknown"
	IDEBoth       = "both" // legacy: cursor + copilot
)

IDE type constants

View Source
const GitflowInstructionsCompact = `## Gitflow Enforcement

**Before modifying ANY code, run the gitflow pre-flight check.**

` + "```bash" + `
gitflow --json status
` + "```" + `

### Pre-flight sequence

1. Check ` + "`git_flow_initialized`" + ` → if false, run ` + "`gitflow --json init`" + `
2. Check ` + "`merge.in_merge`" + ` → if true, STOP and report to user
3. Check ` + "`main_ahead_of_develop`" + ` → if > 0, run ` + "`gitflow --json backmerge`" + `
4. Ensure you are on the correct branch for the task type
5. NEVER modify code on main or develop directly — use flow branches
6. When done: ` + "`gitflow --json finish`" + `

### Branch routing

| Task type    | Start command                                |
|-------------|----------------------------------------------|
| Feature     | ` + "`gitflow --json start feature <name>`" + `      |
| Bugfix      | ` + "`gitflow --json start bugfix <name>`" + `       |
| Hotfix      | ` + "`gitflow --json start hotfix <version>`" + `    |
| Release     | ` + "`gitflow --json start release <version>`" + `   |

### Full CLI

` + "```" + `
gitflow --json status|pull|init|sync|switch|backmerge|cleanup|health|doctor|log|undo|releasenotes|finish
gitflow --json start feature|bugfix|release|hotfix <name>
` + "```" + `

Exit codes: 0=success, 1=error, 2=conflict-needs-human
`

GitflowInstructionsCompact is a shorter version for IDEs with limited instruction space (e.g. appended sections in existing files).

View Source
const GitflowInstructionsFull = `## Gitflow Pre-flight Check

**MANDATORY: Before modifying ANY code, run the pre-flight check.**

### Step 1 — Run status (EVERY TIME before code changes)

` + "```bash" + `
gitflow --json status
` + "```" + `

Evaluate the JSON response in order:

#### 1a. Is git-flow initialized?
If ` + "`git_flow_initialized`" + ` is false:
` + "```bash" + `
gitflow --json init
` + "```" + `

#### 1b. Is there a merge conflict?
If ` + "`merge.in_merge`" + ` is true → **STOP.** Report to user.

#### 1c. Is there branch divergence?
If ` + "`main_ahead_of_develop > 0`" + ` → **STOP.** Fix immediately:
` + "```bash" + `
gitflow --json backmerge
` + "```" + `

#### 1d. Are we on the right branch?

| User wants to...          | Correct branch           | If wrong, run                              |
|---------------------------|-------------------------|--------------------------------------------|
| Add a new feature         | feature/* or develop     | ` + "`gitflow --json switch develop`" + `, then ` + "`gitflow --json start feature <name>`" + ` |
| Fix a bug (non-urgent)    | bugfix/* or develop      | ` + "`gitflow --json switch develop`" + `, then ` + "`gitflow --json start bugfix <name>`" + `  |
| Fix a production bug      | hotfix/* or main         | ` + "`gitflow --json switch main`" + `, then ` + "`gitflow --json start hotfix <ver>`" + `     |
| Prepare a release         | release/* or develop     | ` + "`gitflow --json switch develop`" + `, then ` + "`gitflow --json start release <ver>`" + `  |

**NEVER modify code on main. NEVER commit directly to develop.**

#### 1e. Ask user intent
If no flow branch exists, ask the user:
1. Feature — new functionality
2. Bugfix — fix a non-urgent bug
3. Hotfix — urgent fix for production
4. Continue — already on the right branch

#### 1f. Only NOW proceed with code changes

### Step 2 — During Development
` + "```bash" + `
gitflow --json sync    # sync with parent
gitflow --json pull    # pull before pushing
` + "```" + `

### Step 3 — Finishing Work
` + "```bash" + `
gitflow --json finish
` + "```" + `

### CLI Reference
` + "```" + `
gitflow --json status|pull|init|sync|switch|backmerge|cleanup|health|doctor|log|undo|releasenotes|finish
gitflow --json start feature|bugfix|release|hotfix <name>
gitflow setup [--ide cursor|copilot|both]
` + "```" + `

Exit codes: 0=success, 1=error, 2=conflict-needs-human
`

GitflowInstructionsFull is the complete gitflow preflight instruction set, reusable across all IDE rule generators. It uses pure markdown (no IDE-specific frontmatter) so each generator can wrap it as needed.

Variables

View Source
var MCPSupportedIDEs = map[string]bool{
	IDECursor:     true,
	IDECopilot:    true,
	IDEVSCode:     true,
	IDEClaudeCode: true,
	IDEWindsurf:   true,
	IDECline:      true,
	IDEZed:        true,
	IDENeovim:     true,
	IDEJetBrains:  true,
}

MCPSupportedIDEs lists IDE IDs that support MCP server configuration.

View Source
var UserHomeDirFunc = os.UserHomeDir

Functions

func EnsureMCPConfig

func EnsureMCPConfig(projectRoot, ideID string) (string, error)

EnsureMCPConfig creates or updates the MCP config file for the given IDE, adding a gitflow server entry if not already present. Returns the file path if created/updated, or empty string if already present or IDE unsupported.

func EnsureRulesForIDE

func EnsureRulesForIDE(projectRoot string, detected DetectedIDE) ([]string, error)

EnsureRulesForIDE checks if rules exist for the detected IDE. If missing, it creates them. Also ensures the embedded gitflow skill is installed, AGENTS.md is present as a universal fallback, and MCP config for IDEs that support it. Returns list of newly created files (empty if all exist).

func EnsureRulesWithAIConsent

func EnsureRulesWithAIConsent(projectRoot string, detected DetectedIDE, interactive bool, appVersion string) ([]string, error)

EnsureRulesWithAIConsent installs IDE-specific instructions and embedded skill only when user consent for AI integration is enabled.

Consent is persisted at {projectRoot}/.gitflow/ai-integration.json (per project). In non-interactive mode (agents / --json) this function does NOT auto-enable; it skips provisioning when no prior consent exists, preserving explicit user opt-in.

When consent exists and the stored version matches appVersion, provisioning is skipped entirely (zero file I/O). On version mismatch, rules are re-provisioned idempotently and the stored version is updated.

func Generate

func Generate(projectRoot, ideType string) ([]string, error)

Generate dispatches to the appropriate rule/instruction file generators. For explicit setup: always generates for the specified IDE, installs the embedded skill, ensures AGENTS.md, and writes MCP config when supported.

func MCPConfigExists

func MCPConfigExists(projectRoot, ideID string) bool

MCPConfigExists checks whether an MCP config with a gitflow entry already exists.

Types

type DetectedIDE

type DetectedIDE struct {
	ID          string `json:"id"`
	DisplayName string `json:"display_name"`
}

DetectedIDE holds the result of IDE detection with display-friendly name.

func DetectAll

func DetectAll(projectRoot string) []DetectedIDE

DetectAll returns all detected IDEs (there may be multiple signals).

func DetectPrimary

func DetectPrimary(projectRoot string) DetectedIDE

DetectPrimary returns the most specific IDE detected, or "unknown".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL