Step 657: energy context status model

This commit is contained in:
Bill
2026-02-17 22:11:38 -07:00
parent 295163e298
commit 33e887fd8b
4 changed files with 85 additions and 0 deletions

View File

@@ -4792,4 +4792,13 @@ target_link_libraries(step656_test PRIVATE
tree_sitter_javascript tree_sitter_typescript
tree_sitter_java tree_sitter_rust tree_sitter_go)
add_executable(step657_test tests/step657_test.cpp)
target_include_directories(step657_test PRIVATE src)
target_link_libraries(step657_test PRIVATE
nlohmann_json::nlohmann_json
unofficial::tree-sitter::tree-sitter
tree_sitter_python tree_sitter_cpp tree_sitter_elisp
tree_sitter_javascript tree_sitter_typescript
tree_sitter_java tree_sitter_rust tree_sitter_go)
# Step 12: Dear ImGui shell scaffolding created (main.cpp exists but not built due to dependencies)

View File

@@ -0,0 +1,28 @@
#pragma once
// Step 657: Energy context status bar model
#include <string>
struct EnergyContextState {
std::string mode = "Normal";
int watts = 0;
int batteryPercent = 100;
};
class EnergyContextStatusModel {
public:
static std::string statusLabel(const EnergyContextState& e) {
if (e.mode == "Conservation") {
return "Conservation " + std::to_string(e.batteryPercent) + "%";
}
return e.mode + " " + std::to_string(e.watts) + "W";
}
static bool shouldFlashOrange(const EnergyContextState& e) {
return e.mode == "Conservation" || e.batteryPercent < 30;
}
static std::string promptContextLine(const EnergyContextState& e) {
return "energyState: " + statusLabel(e);
}
};

View File

@@ -0,0 +1,24 @@
// Step 657: Energy context status bar (12 tests)
#include "EnergyContextStatusModel.h"
#include <iostream>
static int p=0,f=0;
#define T(n) { std::cout<<" "<<#n<<"... "; }
#define P() { std::cout<<"PASS\n"; ++p; }
#define F(m) { std::cout<<"FAIL: "<<m<<"\n"; ++f; }
#define C(c,m) if(!(c)){F(m);return;}
void t1(){T(label_for_high_solar_uses_watts);EnergyContextState e{"HighSolar",450,80};C(EnergyContextStatusModel::statusLabel(e)=="HighSolar 450W","label");P();}
void t2(){T(label_for_conservation_uses_percent);EnergyContextState e{"Conservation",120,28};C(EnergyContextStatusModel::statusLabel(e)=="Conservation 28%","label");P();}
void t3(){T(flash_true_for_conservation);EnergyContextState e{"Conservation",120,50};C(EnergyContextStatusModel::shouldFlashOrange(e),"flash");P();}
void t4(){T(flash_true_for_low_battery);EnergyContextState e{"Normal",120,20};C(EnergyContextStatusModel::shouldFlashOrange(e),"flash");P();}
void t5(){T(flash_false_for_normal_high_battery);EnergyContextState e{"Normal",120,80};C(!EnergyContextStatusModel::shouldFlashOrange(e),"no flash");P();}
void t6(){T(prompt_context_line_prefix);EnergyContextState e{"Normal",100,70};C(EnergyContextStatusModel::promptContextLine(e).find("energyState:")==0,"prefix");P();}
void t7(){T(prompt_context_includes_label);EnergyContextState e{"HighSolar",450,80};C(EnergyContextStatusModel::promptContextLine(e).find("HighSolar 450W")!=std::string::npos,"content");P();}
void t8(){T(default_state_label);EnergyContextState e;C(EnergyContextStatusModel::statusLabel(e)=="Normal 0W","default");P();}
void t9(){T(conservation_low_battery_still_percent_label);EnergyContextState e{"Conservation",10,5};C(EnergyContextStatusModel::statusLabel(e)=="Conservation 5%","label");P();}
void t10(){T(battery_threshold_30_not_flashing);EnergyContextState e{"Normal",100,30};C(!EnergyContextStatusModel::shouldFlashOrange(e),"threshold");P();}
void t11(){T(battery_threshold_29_flashing);EnergyContextState e{"Normal",100,29};C(EnergyContextStatusModel::shouldFlashOrange(e),"threshold");P();}
void t12(){T(prompt_context_for_conservation);EnergyContextState e{"Conservation",120,28};C(EnergyContextStatusModel::promptContextLine(e).find("Conservation 28%")!=std::string::npos,"prompt");P();}
int main(){std::cout<<"Step 657: Energy context status model\n";t1();t2();t3();t4();t5();t6();t7();t8();t9();t10();t11();t12();std::cout<<"\nResults: "<<p<<"/"<<(p+f)<<" passed\n";return f?1:0;}

View File

@@ -13528,3 +13528,27 @@ tool title/source metadata presentation.
- `editor/src/ApiaryBrowserPanelModel.h` (`36` <= `600`)
- `editor/tests/step656_test.cpp` within test-file size guidance (`29` lines)
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`
### Step 657: Energy context status bar
**Status:** PASS (12/12 tests)
Adds energy-context status modeling for status-bar label generation, conservation
flash signaling, and agent prompt-context line composition.
**Files added:**
- `editor/src/EnergyContextStatusModel.h` - energy status/prompt model
- `editor/tests/step657_test.cpp` - 12 tests for label/flash/prompt behavior
**Files modified:**
- `editor/CMakeLists.txt` - `step657_test` target
**Verification run:**
- `cmake -S editor -B editor/build-native` - PASS
- `cmake --build editor/build-native --target step657_test step656_test` - PASS
- `./editor/build-native/step657_test` - PASS (12/12)
- `./editor/build-native/step656_test` - PASS (12/12) regression coverage
**Architecture gate check:**
- `editor/src/EnergyContextStatusModel.h` (`28` <= `600`)
- `editor/tests/step657_test.cpp` within test-file size guidance (`24` lines)
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`