Mega refactor: package layout, typed events, tests, docs, tooling#2
Merged
Conversation
added 3 commits
May 21, 2026 08:23
Split the 283-line main() into four small packages:
internal/event typed Envelope/AssistantMessageEvent/ToolCall/Result
structs replacing map[string]any assertions
internal/render Renderer state machine with named ANSI constants,
small printf helper, and 15 unit tests covering all
section transitions and edge cases
internal/pi subprocess lifecycle (Start/Events/Close/Kill) wired
to a context.Context for cancellation; BuildArgs is
exposed and tested separately
internal/cli flag parsing + event-loop orchestration with
structured exit codes (0/1/2/130) and --version
main.go is now a thin entrypoint that installs a SIGINT/SIGTERM
NotifyContext and delegates to cli.Run.
Tooling lifted from decodo-coding-tools:
- .golangci.yml v2 config (govet, staticcheck, unused, ineffassign,
errcheck, dupl + gofmt formatter)
- Makefile targets: fmt, vet, staticcheck, lint, lint-fix, tidy, check
- CI split into separate lint/fmt-check/govet/staticcheck/tidy/test
jobs; test job covers ubuntu + macOS; build is gated on all of them
and embeds the commit SHA via -ldflags
Other senior touches:
- LICENSE (MIT)
- README with usage, flags table, exit codes, layout, dev commands
- graceful shutdown via signal.NotifyContext (no orphaned pi child)
- removed dead State.String, dead start-event handlers, magic numbers
pulled into named constants, all interface{} replaced with any
Tests: 34 passing, race detector clean. golangci-lint, staticcheck,
go vet, gofmt -l, go test -race all clean locally.
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
Senior-pass refactor of the whole project. The 283-line
main()is gone; the program is now split into 4 small packages with full test coverage and matching tooling.Package layout
internal/eventEnvelope/AssistantMessageEvent/ToolCall/Resultstructs replacing everymap[string]anyassertion.internal/renderRendererstate machine with named ANSI constants and a tinyprintfhelper.internal/piStart/Events/Close/Kill) wired tocontext.Context.BuildArgsextracted for testing.internal/cli--version.main.gois now a ~10-line entrypoint: installssignal.NotifyContext(SIGINT, SIGTERM)and delegates tocli.Run.Tooling aligned with decodo-coding-tools
.golangci.ymlv2 — govet, staticcheck, unused, ineffassign, errcheck, dupl + gofmtMakefile—fmt,vet,staticcheck,lint,lint-fix,tidy,check,build,install,clean,testlint,fmt-check,govet,staticcheck,tidy,test(ubuntu + macOS matrix),build(gated on the above, embeds short SHA via-ldflags)Other senior touches
signal.NotifyContext— no orphanedpichild on Ctrl+CState.String, dead start-event handlers, magic numbers pulled into named constantsinterface{}replaced withanyTests
34 tests across 4 packages, all passing under
-race. Coverage:Result.SummaryTextnil/empty casesBuildArgsdefaults, with session, full options, omits empty fieldsTest plan
go test -race -count=1 ./...— 34 passinggofmt -l .— cleango vet ./...— cleanstaticcheck ./...— cleangolangci-lint run— cleango build -ldflags '...' -o pi-stream .— produces working binary./pi-stream --versionprints version./pi-stream --model "GLM 5.1" -t bash "..."renders correctly