refactor(hooks/builtins): inline GetEnvironmentInfo + simplify package#2529
Merged
dgageot merged 4 commits intodocker:mainfrom Apr 27, 2026
Merged
Conversation
session.GetEnvironmentInfo and session.isGitRepo had a single production caller (the add_environment_info builtin) and no callers elsewhere. Move both — along with their helpers (boolToYesNo, getOperatingSystem, getArchitecture) — into pkg/hooks/builtins where they're used, dropping the cross-package import. The function is privatized in the process; tests move with it as internal-package tests so they can keep exercising the helpers. Assisted-By: docker-agent
- Drop the boolToYesNo helper: it had a single call site, replace with the idiomatic two-line ternary that yields it inline. - Replace the three-case getArchitecture switch (only amd64 was non-identity) with a one-line if. - Rename getEnvironmentInfo/getOperatingSystem/getArchitecture to environmentInfo/displayOS/displayArch so the names read as nouns/labels rather than getter calls. - Drop the now-redundant TestBoolToYesNo (the helper is gone) and TestGetEnvironmentInfoIntegration (it duplicated the table-driven test, only differing by using os.Getwd as the cwd, which is not a meaningfully distinct code path). Behavior is preserved: the env block format, the public AddEnvironmentInfo registered name, and the addEnvironmentInfo session_start contract are all unchanged. Assisted-By: docker-agent
…able Four single-case tests collapsed into one table-driven TestIsGitRepo with six cases. Coverage is identical (positive parent-dir, .git-is-a-file, missing/empty paths, etc.) and the table layout makes the contract — what counts as 'a git repo' — visible at a glance. Assisted-By: docker-agent
- AgentDefaults.IsZero() had no production callers; the empty-config contract it documented is already enforced (and tested) directly via ApplyAgentDefaults returning nil. Remove the method and the matching test assertion. - turnStartContext was a one-line wrapper used by exactly two callers, while addEnvironmentInfo was already calling hooks.NewAdditionalContextOutput directly. Inline it in add_date and add_prompt_files so every builtin makes its target event (turn_start vs session_start) visible at the call site rather than hiding it behind a same-package helper. - Tighten the package doc accordingly. Assisted-By: docker-agent
gtardif
approved these changes
Apr 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Move
session.GetEnvironmentInfo(and its only filesystem helper,isGitRepo) out ofpkg/sessionand intopkg/hooks/builtins, where the lone production caller lives. Then take a small simplification pass over the builtins package now that everything is colocated.The function had a single production caller —
add_environment_info.goinpkg/hooks/builtins— and a handful of unexported helpers (boolToYesNo,getOperatingSystem,getArchitecture,isGitRepo) that nothing else inpkg/sessionreferenced. Inlining the whole graph drops a cross-package import and lets the builtin testsuite exercise the helpers directly as internal-package tests.Commits
refactor(hooks/builtins): inline GetEnvironmentInfo and isGitRepoMove the function + its helpers + the related tests from
pkg/sessiontopkg/hooks/builtins. Privatize on the way in (no external callers). Tests move with the code as internal-package tests so they can keep exercising the helpers.refactor(hooks/builtins): simplify add_environment_infoDrop the
boolToYesNohelper (one call site → inline ternary). Collapse the three-armgetArchitectureswitch (onlyamd64was non-identity) into a one-lineif. Rename helpers to read as nouns (environmentInfo/displayOS/displayArch). DropTestBoolToYesNo(helper gone) andTestGetEnvironmentInfoIntegration(duplicated the table-driven test, only differing by usingos.Getwdas the cwd, which isn't a meaningfully distinct code path). Env-block format andaddEnvironmentInfosession_start contract are byte-identical.refactor(hooks/builtins): consolidate isGitRepo tests into a single tableFour single-case tests (
TestIsGitRepo,TestIsGitRepoParent,TestInvalidGitFile,TestIsNotGitRepo) collapse into one table-drivenTestIsGitRepowith six explicit cases (positive, parent-dir walkup,.git-is-a-file, missing/empty paths, etc.). Coverage is identical; the table makes the contract — what counts as "a git repo" — visible at a glance.refactor(hooks/builtins): drop dead IsZero and inline turnStartContextAgentDefaults.IsZero()had no production callers; the empty-config contract it documented is already enforced (and tested) directly viaApplyAgentDefaultsreturningnil.turnStartContextwas a one-line wrapper used by exactly two callers, whileaddEnvironmentInfowas already callinghooks.NewAdditionalContextOutputdirectly — inlining surfaces every builtin's target event (turn_startvssession_start) at the call site rather than hiding it behind a same-package helper. Tighten the package doc accordingly.Validation
go build ./...✅mise test✅ (97 packages OK, 0 failures)mise lint✅ (golangci-lint: 0 issues, custom lint: no offenses,go mod tidyclean)Behavior preservation
IsZerowas removed, and it had no production callers.<env>block format injected at session_start is byte-identical (verified by the table-drivenTestEnvironmentInfo).AddDate/AddEnvironmentInfo/AddPromptFiles) is unchanged.Assisted-By: docker-agent