Repository navigation
Description
Analysis
Current codebase: 363 Go files, 81,822 lines (73,935 hand-written, 7,887 generated).
Several patterns of duplicated boilerplate have been identified across the codebase. Below are the consolidation opportunities ranked by impact.
1. File I/O Helpers (HIGH IMPACT)
16+ instances of the same read-file-unmarshal / marshal-write-file pattern scattered across internal/config, internal/credentials, internal/cli, internal/manifest, internal/lorepackage, internal/signing, internal/execution. The pattern is always:
data, err := os.ReadFile(path)
if err != nil { return ..., fmt.Errorf("reading X: %w", err) }
if err := yaml.Unmarshal(data, &v); err != nil { return ..., fmt.Errorf("parsing X: %w", err) }Opportunity: A small internal/fileio package (or similar) with:
ReadYAML(path, &v)/ReadJSON(path, &v)/ReadYAMLOrJSON(path, &v)WriteYAML(path, v, perm)/WriteJSON(path, v, indent, perm)- Handles
MkdirAll, format detection by extension, consistent error wrapping,0o600default permissions
Eliminates ~200 lines of boilerplate across 10+ files.
2. Shell Command Runner (MEDIUM IMPACT)
~35 exec.Command call sites across 15 files. Three distinct clusters:
| Cluster | Files | Pattern |
|---|---|---|
| Git operations | snapshot/snapshot.go, lorepackage/git.go, provider/git/provider.go |
git -C <dir> <args> → capture stdout, parse, trim |
| Credential helpers | credentials/helper.go |
platform keychain CLI → capture stdout, trim |
| General shell | platform_helpers.go, provider/shell, provider/pkg |
run command → structured result with exit code |
Opportunity: Not one helper, but two:
internal/shellrun.Run(ctx, name, args...) -> (stdout string, error)— the simple "capture stdout, trim, wrap error" case (~20 call sites)- The platform-specific
PlatformResultstruct inplatform_helpers.goalready handles the structured-result case well; other call sites could adopt it
3. Star* Provider Composition (MEDIUM IMPACT — design smell)
staranalysis manually instantiates starstats.Provider, starcomplexity.Provider, and starindex.Provider, bypassing the ReceiverFactory system entirely. This is a composition anti-pattern — if any of those providers gain state or lifecycle dependencies, it'll break silently.
Opportunity: Make staranalysis accept its dependencies via the factory system rather than direct construction. Not a merge — each provider keeps its own Starlark receiver name — but proper dependency injection.
Summary
| Opportunity | Est. Lines Eliminated | Files Touched | Risk |
|---|---|---|---|
| File I/O helpers | ~200 | 10-12 | Low |
| Shell command runner | ~150 | 8-10 | Low |
| Star composition fix* | ~0 (design fix) | 1-2 | Low |
Plan and design documents
| Kind | Document |
|---|---|
| Plan | docs/plans/structured-document-io.md |
Activity
refactor: Extract internal/document package, simplify manifest format
refactor: Extract internal/document package, simplify manifest format
refactor: Extract internal/document package, simplify manifest format (…
fix(file): Replace Read with ReadText/ReadBytes, fix Link param name (#…
fix(file): Replace Read with ReadText/ReadBytes, fix Link param name (#…
fix(ci): the PowerShell gate arrives with its sweep, 51 findings to z…