Step 586: add capability discovery panels
This commit is contained in:
@@ -4153,4 +4153,13 @@ target_link_libraries(step585_test PRIVATE
|
||||
tree_sitter_javascript tree_sitter_typescript
|
||||
tree_sitter_java tree_sitter_rust tree_sitter_go)
|
||||
|
||||
add_executable(step586_test tests/step586_test.cpp)
|
||||
target_include_directories(step586_test PRIVATE src)
|
||||
target_link_libraries(step586_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)
|
||||
|
||||
86
editor/src/CapabilityDiscoveryPanels.h
Normal file
86
editor/src/CapabilityDiscoveryPanels.h
Normal file
@@ -0,0 +1,86 @@
|
||||
#pragma once
|
||||
// Step 586: Capability Discovery Panels
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct CapabilityCategory {
|
||||
std::string categoryId;
|
||||
std::string title;
|
||||
int operationCount = 0;
|
||||
std::vector<std::string> recommendations;
|
||||
};
|
||||
|
||||
class CapabilityDiscoveryPanels {
|
||||
public:
|
||||
bool registerCategory(const std::string& categoryId,
|
||||
const std::string& title,
|
||||
std::string* error) {
|
||||
if (!error) return false;
|
||||
error->clear();
|
||||
if (categoryId.empty()) return fail(error, "category_id_missing");
|
||||
if (title.empty()) return fail(error, "category_title_missing");
|
||||
if (categories_.count(categoryId) != 0) return fail(error, "category_duplicate");
|
||||
CapabilityCategory c;
|
||||
c.categoryId = categoryId;
|
||||
c.title = title;
|
||||
categories_[categoryId] = c;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool recordOperation(const std::string& categoryId, std::string* error) {
|
||||
if (!error) return false;
|
||||
error->clear();
|
||||
auto it = categories_.find(categoryId);
|
||||
if (it == categories_.end()) return fail(error, "category_missing");
|
||||
++it->second.operationCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool addRecommendation(const std::string& categoryId,
|
||||
const std::string& recommendation,
|
||||
std::string* error) {
|
||||
if (!error) return false;
|
||||
error->clear();
|
||||
auto it = categories_.find(categoryId);
|
||||
if (it == categories_.end()) return fail(error, "category_missing");
|
||||
if (recommendation.empty()) return fail(error, "recommendation_missing");
|
||||
for (const auto& r : it->second.recommendations) {
|
||||
if (r == recommendation) return fail(error, "recommendation_duplicate");
|
||||
}
|
||||
it->second.recommendations.push_back(recommendation);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<CapabilityCategory> sortedByOperationCountDesc() const {
|
||||
std::vector<CapabilityCategory> out;
|
||||
for (const auto& kv : categories_) out.push_back(kv.second);
|
||||
std::stable_sort(out.begin(), out.end(), [](const CapabilityCategory& a, const CapabilityCategory& b) {
|
||||
if (a.operationCount != b.operationCount) return a.operationCount > b.operationCount;
|
||||
return a.categoryId < b.categoryId;
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
std::vector<std::string> recommendationsFor(const std::string& categoryId) const {
|
||||
auto it = categories_.find(categoryId);
|
||||
if (it == categories_.end()) return {};
|
||||
return it->second.recommendations;
|
||||
}
|
||||
|
||||
int operationCountFor(const std::string& categoryId) const {
|
||||
auto it = categories_.find(categoryId);
|
||||
if (it == categories_.end()) return 0;
|
||||
return it->second.operationCount;
|
||||
}
|
||||
|
||||
private:
|
||||
std::map<std::string, CapabilityCategory> categories_;
|
||||
|
||||
static bool fail(std::string* error, const char* code) {
|
||||
*error = code;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
150
editor/tests/step586_test.cpp
Normal file
150
editor/tests/step586_test.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
// Step 586: Capability Discovery Panels (12 tests)
|
||||
|
||||
#include "CapabilityDiscoveryPanels.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static int passed = 0, failed = 0;
|
||||
#define TEST(name) { std::cout << " " << #name << "... "; }
|
||||
#define PASS() { std::cout << "PASS\n"; ++passed; }
|
||||
#define FAIL(msg) { std::cout << "FAIL: " << msg << "\n"; ++failed; }
|
||||
#define CHECK(cond, msg) if (!(cond)) { FAIL(msg); return; } else {}
|
||||
|
||||
void test_register_category_success() {
|
||||
TEST(register_category_success);
|
||||
CapabilityDiscoveryPanels p;
|
||||
std::string error;
|
||||
CHECK(p.registerCategory("mcp", "MCP Tools", &error), "register should succeed");
|
||||
CHECK(p.operationCountFor("mcp") == 0, "initial count should be zero");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_register_category_rejects_missing_id() {
|
||||
TEST(register_category_rejects_missing_id);
|
||||
CapabilityDiscoveryPanels p;
|
||||
std::string error;
|
||||
CHECK(!p.registerCategory("", "MCP Tools", &error), "register should fail");
|
||||
CHECK(error == "category_id_missing", "wrong error");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_register_category_rejects_duplicate() {
|
||||
TEST(register_category_rejects_duplicate);
|
||||
CapabilityDiscoveryPanels p;
|
||||
std::string error;
|
||||
CHECK(p.registerCategory("mcp", "MCP Tools", &error), "first register failed");
|
||||
CHECK(!p.registerCategory("mcp", "Dup", &error), "duplicate should fail");
|
||||
CHECK(error == "category_duplicate", "wrong error");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_record_operation_increments_count() {
|
||||
TEST(record_operation_increments_count);
|
||||
CapabilityDiscoveryPanels p;
|
||||
std::string error;
|
||||
CHECK(p.registerCategory("mcp", "MCP Tools", &error), "register failed");
|
||||
CHECK(p.recordOperation("mcp", &error), "record failed");
|
||||
CHECK(p.recordOperation("mcp", &error), "record failed");
|
||||
CHECK(p.operationCountFor("mcp") == 2, "count mismatch");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_record_operation_fails_for_unknown_category() {
|
||||
TEST(record_operation_fails_for_unknown_category);
|
||||
CapabilityDiscoveryPanels p;
|
||||
std::string error;
|
||||
CHECK(!p.recordOperation("missing", &error), "record should fail");
|
||||
CHECK(error == "category_missing", "wrong error");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_add_recommendation_success() {
|
||||
TEST(add_recommendation_success);
|
||||
CapabilityDiscoveryPanels p;
|
||||
std::string error;
|
||||
CHECK(p.registerCategory("mcp", "MCP Tools", &error), "register failed");
|
||||
CHECK(p.addRecommendation("mcp", "Try tree-sitter panel", &error), "recommendation add failed");
|
||||
CHECK(p.recommendationsFor("mcp").size() == 1, "recommendation count mismatch");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_add_recommendation_rejects_duplicate() {
|
||||
TEST(add_recommendation_rejects_duplicate);
|
||||
CapabilityDiscoveryPanels p;
|
||||
std::string error;
|
||||
CHECK(p.registerCategory("mcp", "MCP Tools", &error), "register failed");
|
||||
CHECK(p.addRecommendation("mcp", "Try tree-sitter panel", &error), "add failed");
|
||||
CHECK(!p.addRecommendation("mcp", "Try tree-sitter panel", &error), "duplicate should fail");
|
||||
CHECK(error == "recommendation_duplicate", "wrong error");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_add_recommendation_rejects_missing_text() {
|
||||
TEST(add_recommendation_rejects_missing_text);
|
||||
CapabilityDiscoveryPanels p;
|
||||
std::string error;
|
||||
CHECK(p.registerCategory("mcp", "MCP Tools", &error), "register failed");
|
||||
CHECK(!p.addRecommendation("mcp", "", &error), "add should fail");
|
||||
CHECK(error == "recommendation_missing", "wrong error");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_sorted_by_operation_count_desc() {
|
||||
TEST(sorted_by_operation_count_desc);
|
||||
CapabilityDiscoveryPanels p;
|
||||
std::string error;
|
||||
CHECK(p.registerCategory("mcp", "MCP Tools", &error), "register mcp failed");
|
||||
CHECK(p.registerCategory("verify", "Verification", &error), "register verify failed");
|
||||
CHECK(p.recordOperation("verify", &error), "record verify failed");
|
||||
CHECK(p.recordOperation("verify", &error), "record verify failed");
|
||||
CHECK(p.recordOperation("mcp", &error), "record mcp failed");
|
||||
const auto sorted = p.sortedByOperationCountDesc();
|
||||
CHECK(sorted[0].categoryId == "verify", "verify should rank first");
|
||||
CHECK(sorted[1].categoryId == "mcp", "mcp should rank second");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_sorted_tie_breaks_by_category_id() {
|
||||
TEST(sorted_tie_breaks_by_category_id);
|
||||
CapabilityDiscoveryPanels p;
|
||||
std::string error;
|
||||
CHECK(p.registerCategory("a", "A", &error), "register a failed");
|
||||
CHECK(p.registerCategory("b", "B", &error), "register b failed");
|
||||
const auto sorted = p.sortedByOperationCountDesc();
|
||||
CHECK(sorted[0].categoryId == "a", "a should come first on tie");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_recommendations_for_unknown_category_empty() {
|
||||
TEST(recommendations_for_unknown_category_empty);
|
||||
CapabilityDiscoveryPanels p;
|
||||
CHECK(p.recommendationsFor("missing").empty(), "unknown category should return empty recommendations");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_operation_count_for_unknown_category_zero() {
|
||||
TEST(operation_count_for_unknown_category_zero);
|
||||
CapabilityDiscoveryPanels p;
|
||||
CHECK(p.operationCountFor("missing") == 0, "unknown category count should be zero");
|
||||
PASS();
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "Step 586: Capability Discovery Panels\n";
|
||||
|
||||
test_register_category_success(); // 1
|
||||
test_register_category_rejects_missing_id(); // 2
|
||||
test_register_category_rejects_duplicate(); // 3
|
||||
test_record_operation_increments_count(); // 4
|
||||
test_record_operation_fails_for_unknown_category();// 5
|
||||
test_add_recommendation_success(); // 6
|
||||
test_add_recommendation_rejects_duplicate(); // 7
|
||||
test_add_recommendation_rejects_missing_text(); // 8
|
||||
test_sorted_by_operation_count_desc(); // 9
|
||||
test_sorted_tie_breaks_by_category_id(); // 10
|
||||
test_recommendations_for_unknown_category_empty();// 11
|
||||
test_operation_count_for_unknown_category_zero(); // 12
|
||||
|
||||
std::cout << "\nResults: " << passed << "/" << (passed + failed) << " passed\n";
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
34
progress.md
34
progress.md
@@ -11020,3 +11020,37 @@ plain-language routing/review explanations, with electric-blue visual defaults.
|
||||
- `editor/src/WorkflowVisualizationV2.h` within header-size limit (`118` <= `600`)
|
||||
- `editor/tests/step585_test.cpp` within test-file size guidance (`177` lines)
|
||||
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`
|
||||
|
||||
### Step 586: Capability Discovery Panels
|
||||
**Status:** PASS (12/12 tests)
|
||||
|
||||
Implements capability discovery panel state for surfacing tool categories,
|
||||
operation counts, and contextual recommendations.
|
||||
|
||||
**Files added:**
|
||||
- `editor/src/CapabilityDiscoveryPanels.h` - capability panel module:
|
||||
- category registration with validation/duplicate guards
|
||||
- operation count tracking per category
|
||||
- recommendation registration with dedupe guards
|
||||
- category ranking by operation activity
|
||||
- category-level recommendation/count query helpers
|
||||
- `editor/tests/step586_test.cpp` - 12 tests covering:
|
||||
- registration success/failure behavior
|
||||
- operation count tracking behavior
|
||||
- recommendation add/dedupe behavior
|
||||
- ranked sorting behavior
|
||||
- unknown-category query fallback behavior
|
||||
|
||||
**Files modified:**
|
||||
- `editor/CMakeLists.txt` - `step586_test` target
|
||||
|
||||
**Verification run:**
|
||||
- `cmake -S editor -B editor/build-native` - PASS
|
||||
- `cmake --build editor/build-native --target step586_test step585_test` - PASS
|
||||
- `./editor/build-native/step586_test` - PASS (12/12)
|
||||
- `./editor/build-native/step585_test` - PASS (12/12) regression coverage
|
||||
|
||||
**Architecture gate check:**
|
||||
- `editor/src/CapabilityDiscoveryPanels.h` within header-size limit (`86` <= `600`)
|
||||
- `editor/tests/step586_test.cpp` within test-file size guidance (`150` lines)
|
||||
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`
|
||||
|
||||
Reference in New Issue
Block a user