Documentation
¶
Index ¶
- Variables
- func CleanAISuggestedPatterns(patterns []string) []string
- func ExecutePlan(plan *InitPlan, w io.Writer, dryRun bool) error
- func ExtractBranchPatterns(branches []string) []string
- func FileActionLabel(a FileAction) string
- func FormatAISuggestedSection(patterns []string) string
- func GenerateConfig(result *AnalysisResult) string
- func GenerateGitignore(result *AnalysisResult) string
- func MergeConfig(existing []byte, generated []byte) (merged []byte, added []string, err error)
- func MergeGitignore(existing string, generated string) (merged string, added []string)
- func ParseGitignore(content string) []string
- func SuggestGitignorePatterns(ctx context.Context, provider AIGitignoreProvider, dir string, ...) []string
- type AIContextFile
- type AIContextOptions
- type AIGitignoreProvider
- type AnalysisResult
- type BuildSystem
- type CommitAnalysis
- type FileAction
- type FilePlan
- type FileResult
- type GarbageDetection
- type GitRunner
- type InitPlan
- type Language
- type PreflightStep
Constants ¶
This section is empty.
Variables ¶
var BuildSystemFileList = []string{
"Makefile", "Dockerfile",
"docker-compose.yml", "docker-compose.yaml",
"Taskfile.yml", "justfile",
}
BuildSystemFileList는 검색 대상 빌드 시스템 파일 목록이다 (테스트에서도 참조).
var CompiledArtifactPatterns = []string{
"__pycache__/",
"*.pyc",
"*.pyo",
"*.pyd",
".pytest_cache/",
".mypy_cache/",
".ruff_cache/",
"*.class",
"*.o",
"*.obj",
"*.so",
"*.dylib",
"*.dll",
"*.a",
"*.lib",
"*.cover",
"*.coverage",
"coverage/",
".tox/",
".cache/",
}
CompiledArtifactPatterns는 언어 감지 결과와 무관하게 항상 ignore할 컴파일 산출물 패턴이다.
왜 이 리스트가 별도로 필요한가:
- langIgnorePatterns는 marker file이 있는 언어만 커버한다. Go 모노레포 에 들어 있는 임시 Python 스크립트가 __pycache__ 를 만들면 Python marker가 없어 빠진다. 그 결과 .pyc 가 working tree로 흘러들어 `gk commit` LLM payload 의 토큰을 잠식한다.
- 멀티 언어 프로젝트에서 language detection이 한 가지만 잡아도 나머지 언어 산출물은 누락될 수 있다.
var DefaultBranchPattern = "^(feat|fix|chore|docs|refactor|test|perf|build|ci|revert|release|hotfix)/[a-z0-9._-]+"
DefaultBranchPattern은 branch 패턴을 추출할 수 없을 때 사용하는 기본 패턴이다.
var DefaultCommitTypes = []string{"feat", "fix", "chore", "docs", "style", "refactor", "perf", "test", "build", "ci", "revert"}
DefaultCommitTypes는 conventional commit 비율이 낮거나 커밋이 없을 때 사용하는 기본 type 목록이다.
var IDEPatterns = []string{
".idea/",
".vscode/",
".cursor/",
".claude/",
".kiro/",
".xm/",
".omc/",
"*.swp",
".DS_Store",
"Thumbs.db",
}
IDEPatterns는 공통 IDE/에디터 ignore 패턴이다.
var MarkerFiles = []string{
"go.mod", "package.json",
"requirements.txt", "pyproject.toml", "setup.py",
"Cargo.toml", "pom.xml", "build.gradle",
"Gemfile", "composer.json",
"Package.swift", "pubspec.yaml", "CMakeLists.txt",
}
MarkerFiles는 검색 대상 marker file 목록이다 (테스트에서도 참조).
var SecurityPatterns = []string{
".env",
".env.*",
"*.pem",
"id_rsa*",
"credentials.json",
"*.pfx",
"*.kdbx",
"*.keystore",
"service-account*.json",
}
SecurityPatterns는 공통 보안 관련 ignore 패턴이다.
Functions ¶
func CleanAISuggestedPatterns ¶
CleanAISuggestedPatterns keeps only conservative, single-line gitignore patterns. AI output is advisory and must not be able to unignore files or add catch-all rules such as "*".
func ExecutePlan ¶
ExecutePlan은 InitPlan에 따라 파일을 생성/수정한다. dryRun이 true이면 stdout에 미리보기만 출력한다.
func ExtractBranchPatterns ¶
ExtractBranchPatterns는 branch 이름에서 공통 prefix 패턴을 추출하여 정규식 목록을 반환한다. 테스트에서 직접 호출할 수 있도록 exported.
func FileActionLabel ¶
func FileActionLabel(a FileAction) string
FileActionLabel returns the stable external label for a FileAction.
func FormatAISuggestedSection ¶
FormatAISuggestedSection은 AI가 제안한 패턴을 gitignore 섹션 문자열로 포맷한다.
func GenerateConfig ¶
func GenerateConfig(result *AnalysisResult) string
GenerateConfig는 분석 결과를 기반으로 .gk.yaml 내용을 생성한다. 개인 설정 필드(ai.provider, ai.lang, ui.color 등)는 포함하지 않는다.
func GenerateGitignore ¶
func GenerateGitignore(result *AnalysisResult) string
GenerateGitignore는 분석 결과를 기반으로 .gitignore 내용을 생성한다. 카테고리별 주석 헤더와 함께 언어별 패턴, 보안 패턴, IDE 패턴을 포함한다.
func MergeConfig ¶
MergeConfig는 기존 .gk.yaml에 빠진 필드만 추가한다. 기존 필드의 값은 변경하지 않는다. force=true 시 generated를 그대로 반환한다 (완전 덮어쓰기).
func MergeGitignore ¶
MergeGitignore는 기존 .gitignore에 새 규칙을 병합한다. 이미 존재하는 패턴은 건너뛰고, 추가된 규칙만 반환한다. 기존 규칙의 삭제/순서 변경은 하지 않는다.
func ParseGitignore ¶
ParseGitignore는 .gitignore 파일을 파싱하여 패턴 목록을 반환한다. 주석과 빈 줄은 제외한다.
func SuggestGitignorePatterns ¶
func SuggestGitignorePatterns(ctx context.Context, provider AIGitignoreProvider, dir string, result *AnalysisResult) []string
SuggestGitignorePatterns는 AI provider를 사용하여 프로젝트에 맞는 추가 gitignore 패턴을 제안한다. provider가 nil이면 빈 목록을 반환한다.
Types ¶
type AIContextFile ¶
AIContextFile은 생성될 AI context 파일 하나를 나타낸다.
func GenerateAIContext ¶
func GenerateAIContext(result *AnalysisResult, opts AIContextOptions) []AIContextFile
GenerateAIContext는 프로젝트 분석 결과를 template에 주입하여 AI context 파일 내용을 생성한다. IncludeKiro=true 시 .kiro/steering/ 파일 3개를 생성한다. CLAUDE.md, AGENTS.md는 AI 코딩 어시스턴트가 자동 생성하므로 포함하지 않는다.
type AIContextOptions ¶
type AIContextOptions struct {
IncludeKiro bool // .kiro/steering/* 파일도 생성할지
}
AIContextOptions는 AI context 생성 옵션이다.
type AIGitignoreProvider ¶
type AIGitignoreProvider interface {
SuggestGitignore(ctx context.Context, projectInfo string) ([]string, error)
}
AIGitignoreProvider는 AI를 통해 gitignore 패턴을 제안하는 인터페이스이다. provider.Summarizer와 유사한 패턴으로, 시스템 프롬프트 + 유저 프롬프트를 받아 free-form text를 반환한다.
type AnalysisResult ¶
type AnalysisResult struct {
Languages []Language
BuildSystems []BuildSystem
BaseBranch string
Protected []string
BranchPats []string
CommitInfo CommitAnalysis
Preflight []PreflightStep
AIProviders []string
// VersionFiles lists repo-root manifests that carry a release version
// gk ship can bump (pyproject.toml, Cargo.toml, package.json, VERSION,
// …). Empty for tag-only projects like Go, where the version lives only
// in the git tag. gk init scaffolds these as ship.version_files.
VersionFiles []string
// Garbage는 working tree에서 발견된 컴파일 산출물(.pyc, *.class 등)이다.
// nil이면 깨끗하다는 뜻; 비어있지 않으면 CLI가 사용자에게 git rm -rf
// --cached 가이드를 출력한다. .gitignore 패턴 추가만으로는 이미
// tracked된 파일을 제거하지 못하기 때문이다.
Garbage []GarbageDetection
}
AnalysisResult는 프로젝트 분석의 전체 결과를 담는다.
func AnalyzeProject ¶
func AnalyzeProject(dir string, gitRunner GitRunner) (*AnalysisResult, error)
AnalyzeProject는 프로젝트 루트를 스캔하여 AnalysisResult를 반환한다. gitRunner가 nil이면 git 관련 분석(커밋, branch)을 건너뛴다.
type BuildSystem ¶
type BuildSystem struct {
Name string // "make", "docker", "docker-compose", "taskfile", "just"
Artifacts []string // 관련 산출물 패턴 (예: "bin/", "dist/")
}
BuildSystem은 프로젝트에서 감지된 빌드 시스템을 나타낸다.
type CommitAnalysis ¶
type CommitAnalysis struct {
ConventionalRatio float64 // conventional commit 사용 비율 (0.0~1.0)
Types []string // 빈도 내림차순 commit type 목록
Lang string // 커밋 메시지 주요 언어 (BCP-47)
SampleSize int // 분석한 커밋 수
}
CommitAnalysis는 커밋 히스토리 분석 결과를 담는다.
type FileAction ¶
type FileAction int
FileAction은 파일에 대해 수행할 동작을 나타낸다.
const ( ActionCreate FileAction = iota // 새 파일 생성 ActionMerge // 기존 파일에 병합 ActionOverwrite // 기존 파일 덮어쓰기 ActionSkip // 건너뛰기 )
type FilePlan ¶
type FilePlan struct {
Path string
Content string
Action FileAction
}
FilePlan은 생성/수정할 파일 하나의 계획이다.
type FileResult ¶
type FileResult struct {
Path string `json:"path"`
Action string `json:"action"`
Status string `json:"status"` // created | updated | skipped | dry-run
}
FileResult is the observable outcome for one FilePlan.
func ExecutePlanDetailed ¶
ExecutePlanDetailed is ExecutePlan plus a structured result for JSON/agent callers. Writes are atomic per file; if a later file fails, earlier writes are rolled back to their pre-run content.
type GarbageDetection ¶
type GarbageDetection struct {
Pattern string // the matching glob from CompiledArtifactPatterns
Sample []string // up to garbageSampleLimit example paths
Count int // total matches (>= len(Sample))
}
GarbageDetection records compiled-artifact files that already exist in the working tree at gk init time. The CLI surfaces these so the user can choose to `git rm -rf --cached` them — adding a .gitignore pattern alone won't unstage already-tracked files.
func DetectExistingGarbage ¶
func DetectExistingGarbage(dir string) []GarbageDetection
DetectExistingGarbage walks dir looking for files matching any CompiledArtifactPatterns entry. Empty result means the working tree is clean.
The walk is bounded (depth-first via filepath.WalkDir, with skip directories + a hard file-count limit) so it stays cheap even on monorepos. Errors during walking degrade gracefully — partial results are returned rather than aborting init entirely.
type GitRunner ¶
type GitRunner interface {
Run(ctx context.Context, args ...string) (stdout, stderr []byte, err error)
}
GitRunner는 git 명령어를 실행하는 인터페이스이다. internal/git.Runner와 동일한 시그니처를 사용하여 호환성을 유지한다.
type InitPlan ¶
type InitPlan struct {
Gitignore *FilePlan // nil이면 건너뜀
Config *FilePlan // nil이면 건너뜀
AIFiles []FilePlan
}
InitPlan은 실제로 생성/수정할 파일 목록과 내용을 담는다.
type Language ¶
type Language struct {
Name string // "go", "node", "python", "rust", "java", "ruby", "php", "swift", "dart", "cpp"
MarkerFile string // 감지 근거 파일 (예: "go.mod")
}
Language는 프로젝트에서 감지된 프로그래밍 언어를 나타낸다.
type PreflightStep ¶
type PreflightStep struct {
Name string // step 이름 (예: "lint", "test")
Command string // 실행 명령어 (예: "make lint")
}
PreflightStep은 preflight 단계 하나를 나타낸다.