powermonitor Improvement Plan¶
Goal¶
Make powermonitor easier to configure, inspect, and operate without changing the existing data collection behavior.
The first completed outcome is a tested powermonitor config command group plus updated user documentation.
Context¶
The application already has a TOML configuration loader in src/powermonitor/config_loader.py, a validated
PowerMonitorConfig dataclass in src/powermonitor/config.py, and Typer CLI commands in src/powermonitor/cli.py.
The missing piece is a user-facing way to create, inspect, and validate ~/.powermonitor/config.toml without launching
the TUI.
Non-Goals¶
- Do not change IOKit, SMC, or
ioregcollection semantics in this plan. - Do not migrate the SQLite schema or historical readings.
- Do not add dynamic TUI config reload or multiple config profiles in the first implementation slice.
- Do not add dependencies unless stdlib and existing Typer/Rich APIs cannot support the accepted behavior.
Assumptions¶
powermonitorshould continue to launch the TUI when invoked without a subcommand.- CLI arguments should continue to override config file values for the TUI.
- Config file creation should be conservative and should not overwrite an existing file unless an explicit flag is added.
Resolved Decisions¶
powermonitor config initrefuses to overwrite an existing file. No--forceflag is included in this slice.powermonitor config showuses human-readable Rich output only. Machine-readable JSON is not included in this slice.powermonitor config editis deferred because$EDITORlaunching is not required for the first tested config slice.
Plan¶
- [x] Capture the current quality baseline before implementation; verify with
just alland record any pre-existing failures before changing code. - [x] Add a
configTyper command group insrc/powermonitor/cli.pythat does not interfere with default TUI launch; verify withuv run powermonitor --helpand existing CLI tests. - [x] Add
powermonitor config showto display the effective configuration and config file path; verify with a CLI test that uses the existingtemp_configfixture and asserts database path, interval, limits, and log level are shown. - [x] Add
powermonitor config initto create a commented default config atget_config_path()when no file exists; verify with a CLI test usingmonkeypatchandtmp_paththat the file is created and valid TOML. - [x] Define and test existing-file behavior for
config init; verify that the command refuses to overwrite by default or that--forcebehavior is explicitly covered by CLI tests. - [x] Add
powermonitor config validateto parse and validate the configured TOML without starting the TUI; verify with tests for valid TOML, invalid TOML syntax, invalid field values, unknown sections, and unknown keys. - [x] Reuse
PowerMonitorConfigandconfig_loadervalidation paths instead of adding a second config schema; verify with focused tests intests/test_config_loader.pyortests/test_cli.py. - [x] Update
README.mdwith the newpowermonitor configcommands and examples; verify the documented commands matchuv run powermonitor config --help. - [x] Decide whether
powermonitor config editbelongs in this release slice; if accepted, implement it with a mocked editor invocation test, otherwise leave it as a later candidate in this file. - [x] Run the final quality gate; verify with
just allanduv build --no-sources.
Later Candidates¶
- [ ] Add data analysis documentation with CSV and JSON examples; verify by adding a README or docs section that uses
fields produced by
powermonitor export. - [ ] Add
powermonitor config edit; verify with a mocked editor invocation test and platform-neutral editor failure handling. - [ ] Add a battery health interpretation guide; verify that thresholds match the
healthcommand behavior insrc/powermonitor/cli.py. - [ ] Investigate dynamic TUI config reload; verify feasibility with a small design note covering file watching, validation failures, and live widget update behavior before writing code.
- [ ] Investigate multiple config profiles; verify the design with examples for profile selection, default fallback, and
backwards compatibility with
~/.powermonitor/config.toml.
Risks¶
- A
configcommand group can accidentally break the no-argument TUI entry path if Typer wiring changes are not covered by tests. - Config validation can diverge from runtime behavior if it duplicates schema logic instead of reusing
PowerMonitorConfigandload_configinternals. config initcan destroy user settings if overwrite behavior is not explicit and tested.config editcan be brittle across shells and editors unless it is small, optional, and covered with mocks.
Rollback / Recovery¶
- Revert the config command group and README changes if default
powermonitorlaunch behavior regresses. - If a release is already published with broken config commands, ship a patch release that disables the affected command path while keeping existing TUI, database, and collector behavior unchanged.
Completion Checklist¶
- [x]
powermonitor config show,powermonitor config init, andpowermonitor config validateare implemented and verified by CLI tests. - [x] Default
powermonitorinvocation still launches the TUI path, verified by existing or new CLI/TUI tests. - [x] Runtime config loading and config validation share the same schema behavior, verified by tests that cover invalid values and unknown keys.
- [x] README usage examples match command help, verified with
uv run powermonitor config --help. - [x] Repository quality gates pass, verified with
just allanduv build --no-sources.