Documentation
¶
Overview ¶
Package easy implements the Easy Mode engine for gk CLI.
Easy Mode translates technical git output into beginner-friendly language with emoji, term translations, and contextual hints. The engine coordinates activation logic, message catalog access, and graceful fallback when any component fails.
Index ¶
- type EmojiMapper
- type Engine
- func (e *Engine) Emoji() *EmojiMapper
- func (e *Engine) Format(key string, args ...interface{}) (result string)
- func (e *Engine) FormatHint(hintKey string, args ...interface{}) string
- func (e *Engine) Hints() *HintGenerator
- func (e *Engine) IsEnabled() bool
- func (e *Engine) Lang() string
- func (e *Engine) MergeIntoNextHint(receiver string, sourceFullyMerged bool, source string) []string
- func (e *Engine) PushSummaryHint(n int, remote, branch, short string) string
- func (e *Engine) SetDebugFn(fn func(string, ...interface{}))
- func (e *Engine) StatusCrossWorktreeHint(items []WorktreeWorkItem, total int) string
- func (e *Engine) StatusHint(hasStaged, hasUnstaged, hasUntracked, hasConflict bool) string
- func (e *Engine) SyncHint(ahead, behind int, hasUpstream bool) string
- func (e *Engine) TranslateTerms(s string) string
- type HintGenerator
- func (g *HintGenerator) Generate(key string, args ...interface{}) string
- func (g *HintGenerator) Level() HintLevel
- func (g *HintGenerator) MergeIntoNextHint(receiver string, sourceFullyMerged bool, source string) []string
- func (g *HintGenerator) PushSummaryHint(n int, remote, branch, short string) string
- func (g *HintGenerator) StatusCrossWorktreeHint(items []WorktreeWorkItem, total int) string
- func (g *HintGenerator) StatusHint(hasStaged, hasUnstaged, hasUntracked, hasConflict bool) string
- func (g *HintGenerator) SyncHint(ahead, behind int, hasUpstream bool) string
- type HintLevel
- type TermMapper
- type WorktreeWorkItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EmojiMapper ¶
type EmojiMapper struct {
// contains filtered or unexported fields
}
EmojiMapper manages status-to-emoji mappings. When disabled, all methods return empty strings so callers don't need conditional logic.
func NewEmojiMapper ¶
func NewEmojiMapper(enabled bool) *EmojiMapper
NewEmojiMapper creates an EmojiMapper pre-loaded with the default emoji set. When enabled is false, Get and Prefix always return "".
func (*EmojiMapper) Get ¶
func (m *EmojiMapper) Get(key string) string
Get returns the emoji for the given status key. Returns "" if the mapper is disabled or the key is unknown.
func (*EmojiMapper) Prefix ¶
func (m *EmojiMapper) Prefix(key string) string
Prefix returns the emoji followed by a space for the given key. Returns "" if the mapper is disabled or the key is unknown.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine coordinates Easy Mode activation, message formatting, term translation, and hint generation. All formatting methods are safe to call regardless of whether Easy Mode is enabled — when disabled they return the key or input string unchanged.
func NewEngine ¶
func NewEngine(cfg config.OutputConfig, flagEasy, flagNoEasy bool) *Engine
NewEngine creates an Engine based on the resolved OutputConfig and CLI flags. Activation priority: CLI flags > env vars > config file.
The cfg parameter already reflects env-var and config-file values (viper merges them before unmarshalling into OutputConfig). The flagEasy / flagNoEasy parameters represent the --easy / --no-easy CLI flags which take highest precedence.
If catalog loading fails the engine falls back to disabled mode with a warning on stderr.
func (*Engine) Emoji ¶
func (e *Engine) Emoji() *EmojiMapper
Emoji returns the underlying EmojiMapper so callers can wire it into out-of-package formatters (e.g. ui.NewEasyFormatter). Returns nil when the engine is disabled, uninitialised, or emoji is turned off.
func (*Engine) Format ¶
Format looks up a message key from the catalog and applies fmt.Sprintf-style arguments. When Easy Mode is disabled or the catalog is nil, the key itself is returned (with args applied if present).
Any panic inside the formatting pipeline is recovered and the function falls back to returning the raw key — satisfying the fallback safety requirement (Property 10).
func (*Engine) FormatHint ¶
FormatHint generates a contextual hint for the given hint key. Delegates to the HintGenerator when available; falls back to catalog lookup when the generator is nil.
func (*Engine) Hints ¶
func (e *Engine) Hints() *HintGenerator
Hints returns the underlying HintGenerator, or nil when the engine is disabled or not initialised.
func (*Engine) MergeIntoNextHint ¶
MergeIntoNextHint generates next-step hints right after `gk merge --into` completes. Runs in both Easy Mode (uses configured hints) and normal mode (synthesizes a normal-mode generator) so users always see the next-step nudge.
func (*Engine) PushSummaryHint ¶
PushSummaryHint generates the one-line summary for a successful push. Runs in both Easy Mode and normal mode (see effectiveHints).
func (*Engine) SetDebugFn ¶
SetDebugFn installs a debug logging function (typically cli.Dbg). This is called after engine construction because the debug flag state may not be fully resolved at NewEngine time.
func (*Engine) StatusCrossWorktreeHint ¶
func (e *Engine) StatusCrossWorktreeHint(items []WorktreeWorkItem, total int) string
StatusCrossWorktreeHint generates a one-line summary of pending work across worktrees for the in-sync clean status path. Runs in both Easy Mode and normal mode (see effectiveHints).
func (*Engine) StatusHint ¶
StatusHint generates a contextual next-step hint based on the current git working tree state. Delegates to HintGenerator.StatusHint.
func (*Engine) SyncHint ¶
SyncHint generates a contextual hint based on upstream divergence when the working tree is clean. Delegates to HintGenerator.SyncHint.
func (*Engine) TranslateTerms ¶
TranslateTerms replaces git terminology in s with beginner-friendly translations. When disabled or the TermMapper is nil, the input string is returned unchanged.
type HintGenerator ¶
type HintGenerator struct {
// contains filtered or unexported fields
}
HintGenerator produces contextual next-action hints based on the current hint level, message catalog, and emoji mapper.
func NewHintGenerator ¶
func NewHintGenerator(level HintLevel, catalog *i18n.Catalog, emoji *EmojiMapper) *HintGenerator
NewHintGenerator creates a HintGenerator with the given verbosity level, message catalog, and emoji mapper.
func (*HintGenerator) Generate ¶
func (g *HintGenerator) Generate(key string, args ...interface{}) string
Generate looks up a hint key from the catalog and formats it with the supplied arguments. Returns "" when the level is HintOff or the generator/catalog is nil.
func (*HintGenerator) Level ¶
func (g *HintGenerator) Level() HintLevel
Level returns the current hint verbosity level.
func (*HintGenerator) MergeIntoNextHint ¶
func (g *HintGenerator) MergeIntoNextHint(receiver string, sourceFullyMerged bool, source string) []string
MergeIntoNextHint produces the next-step hints emitted right after a successful `gk merge --into <receiver>`. Always returns a push hint; when the source branch is fully merged into receiver, also returns a cleanup hint nudging the user to delete the source branch. Result is returned as a slice so callers can decide whether to print one per line or join them.
Returns nil when the level is HintOff or the generator is nil.
func (*HintGenerator) PushSummaryHint ¶
func (g *HintGenerator) PushSummaryHint(n int, remote, branch, short string) string
PushSummaryHint returns a one-line summary for a successful `gk push`. When n > 0 it reports how many commits were uploaded; n == 0 falls back to the up-to-date message (same wording as a no-op push).
Returns "" when the level is HintOff or the generator is nil.
func (*HintGenerator) StatusCrossWorktreeHint ¶
func (g *HintGenerator) StatusCrossWorktreeHint(items []WorktreeWorkItem, total int) string
StatusCrossWorktreeHint produces a one-line summary of pending work across other worktrees for `gk st` when the current worktree is clean and in sync. Items with empty Detail are filtered out. When more than 3 items have work, only the first 3 are listed and an extra "+N more" suffix is appended.
total is the total number of worktrees inspected (used for the "all clean" message when items is empty).
Returns "" when the level is HintOff or the generator is nil.
func (*HintGenerator) StatusHint ¶
func (g *HintGenerator) StatusHint(hasStaged, hasUnstaged, hasUntracked, hasConflict bool) string
StatusHint generates a contextual next-step hint based on the current git working tree state. Priority order: conflict > staged > unstaged > untracked.
Returns "" when the level is HintOff, no flags are true, or the generator is nil.
func (*HintGenerator) SyncHint ¶
func (g *HintGenerator) SyncHint(ahead, behind int, hasUpstream bool) string
SyncHint generates a contextual hint when the working tree is otherwise clean, based purely on upstream divergence. Priority order: diverged (both ahead and behind) > behind > ahead > in sync.
hasUpstream reports whether the current branch tracks an upstream; without one we cannot speak to "in sync" so the function returns "".
Returns "" when the level is HintOff or the generator is nil.
type TermMapper ¶
type TermMapper struct {
// contains filtered or unexported fields
}
TermMapper translates git terminology into beginner-friendly language for a given locale. It replaces known terms in strings while preserving the original English term in parentheses.
func NewTermMapper ¶
func NewTermMapper(lang string) *TermMapper
NewTermMapper creates a TermMapper for the given language. If the language has no registered term mappings, the mapper is created with an empty map — TranslateTerm and Translate will return inputs unchanged.
func (*TermMapper) Translate ¶
func (m *TermMapper) Translate(s string) string
Translate replaces all known git terms in the string s with their beginner-friendly translations, appending the original English term in parentheses. Terms are matched using word boundaries to avoid partial replacements (e.g., "committed" does not match "commit").
Longer terms are replaced first to prevent shorter terms from interfering with multi-word terms like "cherry-pick".
func (*TermMapper) TranslateTerm ¶
func (m *TermMapper) TranslateTerm(term string) string
TranslateTerm translates a single git term. If a mapping exists, it returns "번역 (term)". If no mapping exists, the original term is returned unchanged.
type WorktreeWorkItem ¶
WorktreeWorkItem describes a single worktree's pending work for the cross-worktree status hint. Branch is the short branch name (e.g. "feat/x"); Detail is a free-form short label like "↑3", "↓2", "↑1 ↓4", "dirty", or "stale". Empty Detail means "nothing to flag".