🐛 Misc bugfixes and add AGENTS.me

This commit is contained in:
Mentor
2025-11-19 17:13:24 +01:00
parent 863b3dbd98
commit eb08fefaa3
2 changed files with 29 additions and 6 deletions

22
AGENTS.md Normal file
View File

@@ -0,0 +1,22 @@
This repository contains software that limits the battery charging level of apple silicon macbooks.
## Project structure
- `./battery.sh` is the main CLI binary used under the hood
- `./setup.sh` is the setup script for the binary
- `./update.sh` is the script used to update the binary
- `./app/` contains an electron codebase for a GUI that wraps around the CLI
- `./dist` contains precompiled binaries that are shipped with the CLI
## Development flow
- any changes made to `battery.sh` must also increment the version number at the top of `battery.sh` as this is what the update command relies on
- any changes to `smc` commands must update the `visudoconfig` variable in `battery.sh` as this updates the visudo entry on the client device to make sure smc may run commands without sudo
- any changes to the `visudoconfig` file must add a corresponding line to the `smc_commands` variable in `app/modules/battery.js` as this makes sure the GUI continues working when the visudo commands are changed
## Mantatory checks
Before finishing any task, make sure that you:
- do a sanity check for bugs
- check that comments still reflect the changed code

View File

@@ -4,7 +4,7 @@
## Update management ## Update management
## variables are used by this binary as well at the update script ## variables are used by this binary as well at the update script
## ############### ## ###############
BATTERY_CLI_VERSION="v1.3.0" BATTERY_CLI_VERSION="v1.3.1"
# Path fixes for unexpected environments # Path fixes for unexpected environments
PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
@@ -439,7 +439,7 @@ if [[ "$action" == "visudo" ]]; then
# Write the visudo file to a tempfile # Write the visudo file to a tempfile
visudo_tmpfile="$configfolder/visudo.tmp" visudo_tmpfile="$configfolder/visudo.tmp"
sudo rm visudo_tmpfile 2>/dev/null sudo rm $visudo_tmpfile 2>/dev/null
echo -e "$visudoconfig" >$visudo_tmpfile echo -e "$visudoconfig" >$visudo_tmpfile
# If the visudo file is the same (no error, exit code 0), set the permissions just # If the visudo file is the same (no error, exit code 0), set the permissions just
@@ -646,7 +646,7 @@ if [[ "$action" == "maintain_synchronous" ]]; then
# Checking if the calibration process is running # Checking if the calibration process is running
if test -f "$calibrate_pidfile"; then if test -f "$calibrate_pidfile"; then
pid=$(cat "$calibrate_pidfile" 2>/dev/null) pid=$(cat "$calibrate_pidfile" 2>/dev/null)
kill $calibrate_pidfile &>/dev/null kill $pid &>/dev/null
log "🚨 Calibration process have been stopped" log "🚨 Calibration process have been stopped"
fi fi
@@ -801,7 +801,7 @@ if [[ "$action" == "maintain" ]]; then
if test -f "$calibrate_pidfile"; then if test -f "$calibrate_pidfile"; then
pid=$(cat "$calibrate_pidfile" 2>/dev/null) pid=$(cat "$calibrate_pidfile" 2>/dev/null)
kill $calibrate_pidfile &>/dev/null kill $pid &>/dev/null
log "🚨 Calibration process have been stopped" log "🚨 Calibration process have been stopped"
fi fi
@@ -829,7 +829,7 @@ if [[ "$action" == "maintain" ]]; then
log "Error: ${setting}V is not a valid setting. Please use a value between ${voltage_min}V and ${voltage_max}V" log "Error: ${setting}V is not a valid setting. Please use a value between ${voltage_min}V and ${voltage_max}V"
exit 1 exit 1
fi fi
if (($(echo "$subsetting < $voltage_hyst_min" | bc -l) || $(echo "$subsetting > $voltage_max" | bc -l))); then if (($(echo "$subsetting < $voltage_hyst_min" | bc -l) || $(echo "$subsetting > $voltage_hyst_max" | bc -l))); then
log "Error: ${subsetting}V is not a valid setting. Please use a value between ${voltage_hyst_min}V and ${voltage_hyst_max}V" log "Error: ${subsetting}V is not a valid setting. Please use a value between ${voltage_hyst_min}V and ${voltage_hyst_max}V"
exit 1 exit 1
fi fi
@@ -935,7 +935,8 @@ if [[ "$action" == "calibrate" ]]; then
if [[ "$setting" == "stop" ]]; then if [[ "$setting" == "stop" ]]; then
log "Killing running calibration daemon" log "Killing running calibration daemon"
kill $calibrate_pidfile &>/dev/null pid=$(cat "$calibrate_pidfile" 2>/dev/null)
kill $pid &>/dev/null
rm $calibrate_pidfile 2>/dev/null rm $calibrate_pidfile 2>/dev/null
exit 0 exit 0