Skip to content

Refactor Phase 1: shared leaf packages + mechanical boilerplate (fsatomic, cobra Args, view/progress helpers) #448

Description

@rianjs

Part of the refactoring roadmap (see parent issue and docs/refactoring/roadmap.md). Phase 1.

Shared helpers created before the structural moves, so the new packages are written in the deduplicated idiom instead of inheriting today's copies.

Tasks

  • internal/fsatomic leaf package: WriteFileAtomic, WriteJSON, ReadJSON (one canonical atomic JSON codec, 0o600 perms). Migrate the three divergent writeJSONFile copies (pipeline.go:4401, benchmark/metrics.go:456, benchmarkcmd/run.go:829) package-by-package. Note: pipeline currently writes workbench metadata atomically on one path and non-atomically on another — unifying is a small deliberate behavior improvement; verify Windows rename semantics with a test.
  • ShortSHA standardized at 12 chars in an existing leaf package (three drifted copies: pipeline.go:3444 and reviewplan.go:1065 use 12, agents.go:990 uses 7). The agents 7→12 change is user-visible — ship last with golden-test updates.
  • Cobra Args constructors in exitcode: NoArgs(msg), ExactArgs(n, msg), NonEmptyArg(msg) — replaces 41 identical 6-line closures across 13 files (two sites need a dynamic-message variant).
  • configPath dedup — delete the five byte-identical private copies (agentscmd, mecmd, configcmd, benchmarkcmd, credentialcmd) in favor of cmdruntime.ConfigPath; fold configcmd's six RunE load-inline blocks into loadConfig.
  • view.RenderJSON(w, v) / view.Render(w, asJSON, v, textFn) / root.AddJSONFlag(cmd, target) — kills 21+ identical encoder bodies, 18 json/text branch sites, 22 --json flag registrations.
  • Hoist newProgressLogger/endProgressSpan (byte-identical in 5 cmd packages); give (*progress.Span).End(err) error a return value so return span.End(err) replaces every wrapper.
  • ledger.OpenLedger helper for the duplicated layout→migrate→stat→open sequence (sessionscmd, datacmd).

Details: docs/refactoring/tactical-simplifications-report.md (Tier 1 items 3–7) and docs/refactoring/architecture-report.md proposal 4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:foundationFoundation, skeleton, config, state-path, credential setup

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions