refactor(app): extract agentdir package, split app.go helpers into sibling files#30
Merged
Conversation
…bling files app.go had grown into a mixed composition root holding unrelated helpers. Move openBrowser, seedSoundsDir, and writeStateFile into focused sibling files (browser.go, sounds.go, state_file.go) within package app. Introduce internal/agentdir as the single source of truth for resolving the Pi agent directory. Previously app.piAgentDir (which respects PI_CODING_AGENT_DIR) and a weaker HOME-only fallback in server.New computed the same path two different ways. Both now call agentdir.Path(), and the repeated filepath.Join(agentDir, "pi-web") convention across app and server goes through agentdir.WebDir(). agentdir.Path() documents that it intentionally models only the agent-dir override, mirroring pi's getAgentDir(); the more specific session-dir knobs (--session-dir, PI_CODING_AGENT_SESSION_DIR) are a known, accepted gap. Tests: new agentdir package tests (Path env override + fallback, WebDir); add seedSoundsDir tests (seeds when empty, skips when an mp3 is present); rename pi_agent_dir_test.go -> state_file_migration_test.go to sit with the state-file code now that the piAgentDir tests moved to agentdir.
.booboo/ is a personal scratch-notes folder, not a project artifact, so it belongs in the user's global git ignore (~/.config/git/ignore) rather than the shared repo .gitignore. This reverts the repo file to its original state.
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.
Summary
Cleans up
internal/appand removes a real source of duplication around the Pi agent directory.app.gohelpers into focused sibling files (samepackage app, no API change):openBrowser→browser.go,seedSoundsDir→sounds.go,writeStateFile+ thestateFileglobal →state_file.go.app.gois now a lean composition root (~133 fewer lines).internal/agentdirpackage = single source of truth for the agent dir. Previouslyapp.piAgentDir(respectsPI_CODING_AGENT_DIR) and a weakerHOME-only fallback inserver.Newresolved the same path two different ways. Both now callagentdir.Path(), and the repeatedfilepath.Join(agentDir, "pi-web")convention acrossappandservergoes throughagentdir.WebDir().agentdir.Path()intentionally models only the agent-dir override, mirroring pi'sgetAgentDir(). pi's more specific session-dir knobs (--session-dir,PI_CODING_AGENT_SESSION_DIR) are not honored — called out in a doc comment as accepted, not an oversight.Behavior note
server.New's fallback now respectsPI_CODING_AGENT_DIR(it previously usedHOMEonly). It only fires whenDeps.AgentDir == "", which never happens in the real app or the server tests (all pass an explicit dir), so it's strictly more consistent.Tests
agentdirtests:Path()env override +~/.pi/agentfallback,WebDir().seedSoundsDirtests: seeds defaults when empty, skips when an mp3 is already present.pi_agent_dir_test.go→state_file_migration_test.go(thepiAgentDirtests moved toagentdir; the file now holds only the state-file migration tests).openBrowserleft untested (fire-and-forget OSexec, not worth a DI seam).Also adds
.booboo/to.gitignore(local scratch notes).Test plan
go vet ./internal/...go build ./...go test ./...(all pass)gofmtclean on all new/changed files