17 KiB
Configurable Output Directory Implementation Plan
Status: Complete.
Purpose And Authority
This plan implements the accepted Configurable Output Directory Roadmap. The feature roadmap is authoritative for user intent, scope, policy choices, non-goals, and the desired end state. This document owns implementation order, concrete changes, verification, and exit gates.
The target is one optional output.directory configuration value that selects
the ordinary publication directory for both single reports and batches while
preserving explicit CLI overrides, current defaults, stateless execution,
atomic publication, and notification ordering.
This plan follows the repository's architecture, documentation, and testing policies.
Implementation Rules
- Implement the stages in numeric order. Keep the repository buildable and the default suite passing at every stage.
- Use
GOWORK=offfor all Go validation so the sibling workspace cannot supply unpublished dependency changes. - Keep this change within the configurable-output-directory scope. Do not implement any part of the accepted LLM profile comparison roadmap.
- Preserve one operator-owned Markdown output per generated report. Do not add a workspace, manifest, history, cache, retention policy, directory scan, or managed cleanup behavior.
- Preserve current report filenames, report periods, batch membership, Promptkit inspection and execution, generated-text validation, rendering, cancellation, atomic file publication, action summaries, and Distributor notification ordering.
- Keep CLI flag parsing and current-working-directory capture in
internal/cli, configuration loading and validation ininternal/config, and effective destination resolution and publication ininternal/app. - Keep tests deterministic, offline, credential-free, and independent of
process-wide
os.Chdiror machine-specific directories. Uset.TempDir()and injected working directories. - Update current-state documentation only when the corresponding behavior is implemented. Do not create release notes, select a release version, tag, or publish a release in these stages.
- Run
gofmton changed Go files andgit diff --checkbefore completing every stage. Do not weaken unrelated tests or rewrite historical release notes.
Locked Product And Path Decisions
Implement exactly this optional configuration shape:
output:
directory: /var/lib/weatherreporter/reports
The following decisions are fixed:
- Add
config.OutputConfigwith oneDirectory stringfield and addConfig.Outputwith YAML keyoutput. Do not add other output settings. - The built-in default is the empty string. Omitted and explicitly empty values preserve current-directory behavior.
- A whitespace-only configured value is invalid. Preserve a nonblank value as supplied during configuration loading; do not trim it into a different filesystem path.
- Configuration loading performs no filesystem lookup and creates no directory. Runtime output preflight owns path cleaning and filesystem inspection.
- A relative configured directory resolves against the absolute working directory captured for the invocation, never against the configuration-file directory. There is no environment-variable or home-directory expansion.
- A nonexistent configured directory is valid and is created only as needed by ordinary atomic report publication.
- An existing configured path that is not a directory, or cannot be inspected, fails through the existing output-preflight boundary before prompt inspection, weather collection, model execution, or output replacement.
- Single-report precedence is explicit
--outpath, thenoutput.directoryplus the report's existing default filename, then the working directory plus that filename. - Batch precedence is explicit
--out-dir, thenoutput.directory, then the working directory. - An explicit
--outis the complete file destination. A relative--outremains relative to the invocation working directory and is never rebased beneathoutput.directory. - Configuration must still pass strict validation before any command runs. After a valid configuration loads, explicit output flags completely ignore the configured directory for runtime resolution and filesystem inspection. They retain their current absolute and relative semantics.
- Successful result and summary paths remain cleaned absolute paths. Default filenames and all output, cancellation, and notification safety guarantees remain unchanged.
Stage 1: Add The Configuration Contract
Goal
Make output.directory a strict, validated configuration value without
changing runtime destination behavior or current-state documentation yet.
Work
- In
internal/config/config.go, add:Output OutputConfigtoConfigwith YAML keyoutput; andOutputConfigcontaining onlyDirectory stringwith YAML keydirectory.
- In
internal/config/defaults.go, initializeOutput.Directoryto the empty string explicitly so the public default is visible beside the other configuration defaults. - In
internal/config/validate.go, rejectOutput.Directoryonly when it is nonempty andstrings.TrimSpacefinds no non-whitespace character. Use an actionable error that identifiesoutput.directory. Do not clean, make absolute, stat, create, or otherwise mutate the path during validation. - Rely on the existing
yaml.Decoder.KnownFields(true)boundary for strict nested decoding. Do not introduce custom YAML unmarshalling or a second unknown-field mechanism forOutputConfig. - Add focused configuration tests that prove:
- the exact empty default;
- omission and explicit
directory: ""are accepted; - representative absolute and relative values load without mutation;
- a whitespace-only value fails with
output.directorycontext; - an unknown field beneath
outputfails strict loading; and - constructed and YAML-loaded configurations receive the same validation result.
- Keep the maintained example and current-state documentation unchanged in this stage; they are updated after runtime behavior lands.
Tests
Run:
GOWORK=off go test -count=1 ./internal/config
GOWORK=off go test -count=1 ./...
git diff --check
Exit Gate
The configuration package exposes and validates the additive field, strict loading rejects malformed output configuration, existing configurations remain valid, and runtime output behavior is still unchanged.
Stage 2: Centralize And Apply Effective Destination Resolution
Goal
Apply the locked precedence to single-report and batch orchestration through one coherent app-owned output-resolution boundary.
Work
- Create
internal/app/output.goand move the existing app-owned output helpers out ofapp.gowithout changing their established safety behavior:prepareBatchOutputs,plannedBatchOutputPath,resolveReportOutputPath,resolveOutputDir,resolveOutputPath,validateWorkingDir, andvalidateOutputPath. Clean up imports inapp.go; do not export these helpers or introduce a new package. - Add one narrow directory-precedence helper in
output.go. It must select a nonempty explicit directory first, otherwise the configured directory, and then pass that selected value to the existing directory resolver, whose empty case returns the validated working directory. Do not inspect the lower-precedence configured path when an explicit directory is present. - Extend the single-report resolver to accept the configured directory and
implement this exact branch:
- obtain the existing default output name from
report.Resolved; - when
GenerateRequest.OutputPathis nonempty, resolve and validate that complete explicit path againstWorkingDirand ignore the configured directory; - otherwise resolve the configured directory, falling back to
WorkingDir, and place the existing default filename beneath it; and - validate and return one cleaned absolute final file path.
- obtain the existing default output name from
- Change
GenerateDetailedto passreq.Config.Output.Directoryinto that resolver before debug-writer construction, prompt inspection, weather collection, or model execution. Preserve its current partial-result and destination-preservation behavior on resolution failure. - Change
RunBatchDetailedto resolve its base directory fromreq.OutputDir,req.Config.Output.Directory, andreq.WorkingDirin that order before debug-writer construction, prompt inspection, or collection. Preserve data-dependent batch planning and the later preflight of every final report file. - Do not add output-directory fields to
GenerateRequestorBatchRequest. Their existing explicit override fields remain CLI/action inputs, while the configured fallback remains inConfig. - Add focused
internal/apptests, using existing real filesystem behavior and project-owned fakes, that prove:- omitted configuration retains current-directory destinations for a representative single report and batch;
- absolute and relative configured directories produce the expected cleaned absolute destinations;
- single-report
OutputPathand batchOutputDiroverrides win and do not inspect or use a lower-precedence configured path; - a configured existing non-directory fails before prompt inspection, collection, model execution, publication, or notification;
- a missing configured directory is created through successful ordinary publication;
- existing atomic replacement and cancellation tests continue to pass; and
- result paths and Distributor source paths still identify only the final selected Markdown files.
- Prefer a compact resolver table plus representative assembled workflows. Do not duplicate every path case at configuration, CLI, and app layers.
Tests
Run:
GOWORK=off go test -count=1 ./internal/app ./internal/fileutil
GOWORK=off go test -count=1 ./...
git diff --check
Exit Gate
Direct app callers, ordinary generate, and batches use the locked
CLI/configuration/working-directory precedence; paths are validated before
expensive work; and output, cancellation, and notification invariants remain
intact.
Stage 3: Complete CLI Coverage And Current-State Documentation
Goal
Protect the assembled CLI-to-app contract and make every canonical document and maintained example describe the now-implemented behavior exactly once.
Work
-
Keep
internal/cli.resolveOutputOverridelimited to explicit--outand--out-dirvalues. It must continue resolving relative flag values against the captured working directory. Do not resolveoutput.directoryin the CLI or replace the raw configured value inConfig; the app owns final precedence and runtime path validation. -
Add or update focused
internal/clirequest-construction tests to prove:- a configured relative or absolute directory survives configuration loading and reaches the app request while the absent CLI override remains empty;
- relative and absolute
--outand--out-dirvalues retain their current resolution; and - an explicit flag coexists with the loaded configured value so app-owned precedence can ignore the latter. Keep these tests narrow; app tests own final path and publication outcomes.
-
Add this illustrative stanza to
examples/config.yml:output: directory: /var/lib/weatherreporter/reportsKeep
examples/minimal-config.ymlunchanged so it continues to demonstrate the empty-default path. ExtendTestLoadExampleConfigto assert the exact maintained example value. -
Update canonical current-state documentation according to
docs/policy/documentation.md:docs/config.mdowns the field, empty default, whitespace validation, absolute and relative semantics, lack of expansion, and configuration versus flag precedence;docs/cli.mdowns the unchanged flag syntax and the effective flag/configuration/working-directory selection visible to users;docs/operations.mdowns normal operation with a configured publication directory, explicit one-command overrides, missing-directory creation, atomic replacement, and failure handling;README.mdupdates only its short quickstart destination summary and links to the canonical configuration/CLI references;docs/policy/architecture.mdstates that configuration or explicit CLI input selects the operator-owned output destination without changing the stateless boundary;docs/internal/cli.mddescribes capture and transport of the configured fallback plus explicit overrides without duplicating the field reference; anddocs/internal/app-orchestration.mddescribes app-owned effective destination precedence and the unchanged single and batch preflight ordering.
-
Do not change historical release notes. Do not duplicate the complete field contract outside
docs/config.md, complete flag syntax outsidedocs/cli.md, or operational procedures outsidedocs/operations.md. -
Review all changed commands, values, paths, and examples against executable code. Follow every added or changed repository-relative link and confirm its target exists.
Tests
Run:
GOWORK=off go test -count=1 ./internal/config ./internal/cli ./internal/app
GOWORK=off go run ./cmd/weatherreporter --help
GOWORK=off go test -count=1 ./...
git diff --check
Confirm the maintained full and minimal examples both load through the configuration test suite and no current-state document still claims that the working directory is always the no-flag destination.
Exit Gate
The CLI-to-app boundary is protected without duplicating app behavior tests, the maintained example is executable configuration, and all canonical current-state documentation agrees with the implemented contract.
Stage 4: Reconcile Roadmaps And Run The Final Gate
Goal
Verify the complete feature in the same module-isolated environment used for release preparation and leave roadmap status accurate for post-implementation review.
Work
- Review the complete diff against the feature roadmap, this plan, and all
documents under
docs/policy/. Remove incidental refactors, redundant tests, duplicate documentation, and any behavior outside the accepted scope. - Confirm repository hygiene:
- no tracked
go.workorgo.work.sum; - no
vendordirectory orgo.modreplacement; - no generated binaries, test output, credentials, private paths, or temporary filesystem artifacts; and
- no unintended changes to the profile-comparison feature.
- no tracked
- After every implementation and documentation gate passes, update
docs/roadmap/output-directory.mdfromAccepted; unimplementedtoImplemented; retained temporarily for post-implementation review. Preserve its target-state purpose and policy content until roadmap cleanup is separately authorized. - Update the prerequisite section in
docs/roadmap/profile-comparison.mdto state that configurable output directories are implemented. Link its current behavior summary todocs/config.mdanddocs/operations.mdrather than duplicating their contracts. Do not otherwise advance or implement profile comparison. - Mark this plan
Status: Completeonly after the final gate succeeds. Do not delete either roadmap or this plan in this stage; repository roadmap cleanup follows post-implementation review.
Tests
Run from the repository root:
set -eu
test -z "$(git ls-files go.work go.work.sum)"
test ! -e vendor
if grep -Eq '^[[:space:]]*replace([[:space:]]|\()' go.mod; then
printf '%s\n' 'go.mod contains a replacement' >&2
exit 1
fi
GOWORK=off go test -count=1 ./...
GOWORK=off go test -race -count=1 ./...
GOWORK=off go vet ./...
GOWORK=off go build ./...
GOWORK=off go mod tidy -diff
unformatted="$(git ls-files '*.go' | while IFS= read -r file; do gofmt -l "$file"; done)"
test -z "$unformatted"
GOWORK=off go run ./cmd/weatherreporter --help >/dev/null
git diff --check
git diff --cached --check
Follow every added or changed local documentation link and verify the full and minimal maintained configuration examples through their tests.
Exit Gate
The complete repository passes normal, race-enabled, vet, build, module,
formatting, help, documentation, and hygiene checks with GOWORK=off; roadmap
status accurately distinguishes the implemented output-directory prerequisite
from the still-unimplemented profile-comparison feature; and no required work
remains.
Open Questions
None. The feature roadmap and this plan define every product, architecture, precedence, path, compatibility, testing, documentation, and completion choice required for implementation.