Skip to content

refactor(app): extract agentdir package, split app.go helpers into sibling files#30

Merged
setkyar merged 2 commits into
mainfrom
refactor/agentdir-package
Jun 2, 2026
Merged

refactor(app): extract agentdir package, split app.go helpers into sibling files#30
setkyar merged 2 commits into
mainfrom
refactor/agentdir-package

Conversation

@setkyar
Copy link
Copy Markdown
Contributor

@setkyar setkyar commented Jun 2, 2026

Summary

Cleans up internal/app and removes a real source of duplication around the Pi agent directory.

  • Split app.go helpers into focused sibling files (same package app, no API change): openBrowserbrowser.go, seedSoundsDirsounds.go, writeStateFile + the stateFile global → state_file.go. app.go is now a lean composition root (~133 fewer lines).
  • New internal/agentdir package = single source of truth for the agent dir. Previously app.piAgentDir (respects PI_CODING_AGENT_DIR) and a weaker HOME-only fallback in server.New resolved 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().
  • Documented a known gap. agentdir.Path() intentionally models only the agent-dir override, mirroring pi's getAgentDir(). 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 respects PI_CODING_AGENT_DIR (it previously used HOME only). It only fires when Deps.AgentDir == "", which never happens in the real app or the server tests (all pass an explicit dir), so it's strictly more consistent.

Tests

  • New agentdir tests: Path() env override + ~/.pi/agent fallback, WebDir().
  • New seedSoundsDir tests: seeds defaults when empty, skips when an mp3 is already present.
  • Renamed pi_agent_dir_test.gostate_file_migration_test.go (the piAgentDir tests moved to agentdir; the file now holds only the state-file migration tests).
  • openBrowser left untested (fire-and-forget OS exec, not worth a DI seam).

Also adds .booboo/ to .gitignore (local scratch notes).

Test plan

  • go vet ./internal/...
  • go build ./...
  • go test ./... (all pass)
  • gofmt clean on all new/changed files

setkyar added 2 commits June 2, 2026 21:53
…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.
@setkyar setkyar merged commit b396a99 into main Jun 2, 2026
1 check passed
@setkyar setkyar deleted the refactor/agentdir-package branch June 2, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant