Step 580: add taskitem confidence ambiguity annotation
This commit is contained in:
@@ -4099,4 +4099,13 @@ target_link_libraries(step579_test PRIVATE
|
||||
tree_sitter_javascript tree_sitter_typescript
|
||||
tree_sitter_java tree_sitter_rust tree_sitter_go)
|
||||
|
||||
add_executable(step580_test tests/step580_test.cpp)
|
||||
target_include_directories(step580_test PRIVATE src)
|
||||
target_link_libraries(step580_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)
|
||||
|
||||
85
editor/src/TaskitemConfidenceAmbiguity.h
Normal file
85
editor/src/TaskitemConfidenceAmbiguity.h
Normal file
@@ -0,0 +1,85 @@
|
||||
#pragma once
|
||||
// Step 580: Taskitem Confidence + Ambiguity Annotation
|
||||
|
||||
#include "RequirementNormalizationConflictDetector.h"
|
||||
#include "TaskitemGeneratorV2.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct AnnotatedTaskitem {
|
||||
GeneratedTaskitem base;
|
||||
int confidence = 0; // 0..100
|
||||
int ambiguityCount = 0;
|
||||
bool escalate = false;
|
||||
std::vector<std::string> reasons;
|
||||
};
|
||||
|
||||
class TaskitemConfidenceAmbiguity {
|
||||
public:
|
||||
static bool annotate(const std::vector<GeneratedTaskitem>& tasks,
|
||||
const RequirementNormalizationResult& normalized,
|
||||
std::vector<AnnotatedTaskitem>* out,
|
||||
std::string* error) {
|
||||
if (!out || !error) return false;
|
||||
error->clear();
|
||||
out->clear();
|
||||
if (tasks.empty()) {
|
||||
*error = "tasks_empty";
|
||||
return false;
|
||||
}
|
||||
|
||||
const int ambiguousRequirements = countAmbiguous(normalized.requirements);
|
||||
const int conflictCount = static_cast<int>(normalized.conflicts.size());
|
||||
|
||||
for (const auto& task : tasks) {
|
||||
AnnotatedTaskitem item;
|
||||
item.base = task;
|
||||
item.ambiguityCount = ambiguousRequirements;
|
||||
item.confidence = computeConfidence(task, ambiguousRequirements, conflictCount);
|
||||
item.reasons = deriveReasons(task, ambiguousRequirements, conflictCount, item.confidence);
|
||||
item.escalate = shouldEscalate(item);
|
||||
out->push_back(item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
static int countAmbiguous(const std::vector<NormalizedRequirement>& requirements) {
|
||||
int count = 0;
|
||||
for (const auto& req : requirements) if (req.ambiguous) ++count;
|
||||
return count;
|
||||
}
|
||||
|
||||
static int computeConfidence(const GeneratedTaskitem& task,
|
||||
int ambiguityCount,
|
||||
int conflictCount) {
|
||||
int confidence = 85;
|
||||
if (!task.queueReady) confidence -= 25;
|
||||
confidence -= ambiguityCount * 10;
|
||||
confidence -= conflictCount * 8;
|
||||
if (task.prerequisiteOps.size() > 2) confidence -= 5;
|
||||
if (!task.dependencyTaskIds.empty()) confidence -= 4;
|
||||
return std::max(0, std::min(100, confidence));
|
||||
}
|
||||
|
||||
static std::vector<std::string> deriveReasons(const GeneratedTaskitem& task,
|
||||
int ambiguityCount,
|
||||
int conflictCount,
|
||||
int confidence) {
|
||||
std::vector<std::string> reasons;
|
||||
if (!task.queueReady) reasons.push_back("queue_not_ready");
|
||||
if (ambiguityCount > 0) reasons.push_back("ambiguous_requirements:" + std::to_string(ambiguityCount));
|
||||
if (conflictCount > 0) reasons.push_back("conflicts_detected:" + std::to_string(conflictCount));
|
||||
if (!task.dependencyTaskIds.empty()) reasons.push_back("depends_on_prior_tasks");
|
||||
if (confidence < 60) reasons.push_back("low_confidence");
|
||||
if (reasons.empty()) reasons.push_back("high_confidence_clear_path");
|
||||
return reasons;
|
||||
}
|
||||
|
||||
static bool shouldEscalate(const AnnotatedTaskitem& item) {
|
||||
return item.confidence < 60 || item.ambiguityCount > 0 || !item.base.queueReady;
|
||||
}
|
||||
};
|
||||
189
editor/tests/step580_test.cpp
Normal file
189
editor/tests/step580_test.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
// Step 580: Taskitem Confidence + Ambiguity Annotation (12 tests)
|
||||
|
||||
#include "TaskitemConfidenceAmbiguity.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 {}
|
||||
|
||||
static GeneratedTaskitem task(const std::string& id, bool queueReady) {
|
||||
GeneratedTaskitem t;
|
||||
t.taskId = id;
|
||||
t.title = "title";
|
||||
t.milestoneId = "m1";
|
||||
t.queueReady = queueReady;
|
||||
t.prerequisiteOps = {"validate-intake"};
|
||||
return t;
|
||||
}
|
||||
|
||||
static NormalizedRequirement req(const std::string& id, bool ambiguous) {
|
||||
NormalizedRequirement r;
|
||||
r.requirementId = id;
|
||||
r.kind = NormalizedRequirementKind::Constraint;
|
||||
r.normalizedText = "text";
|
||||
r.anchor = "constraints";
|
||||
r.sourceLine = 1;
|
||||
r.ambiguous = ambiguous;
|
||||
return r;
|
||||
}
|
||||
|
||||
void test_annotate_success() {
|
||||
TEST(annotate_success);
|
||||
std::vector<AnnotatedTaskitem> out;
|
||||
RequirementNormalizationResult normalized;
|
||||
std::string error;
|
||||
CHECK(TaskitemConfidenceAmbiguity::annotate({task("task-1", true)}, normalized, &out, &error), "annotate should succeed");
|
||||
CHECK(out.size() == 1, "annotated task count mismatch");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_annotate_fails_for_empty_tasks() {
|
||||
TEST(annotate_fails_for_empty_tasks);
|
||||
std::vector<AnnotatedTaskitem> out;
|
||||
RequirementNormalizationResult normalized;
|
||||
std::string error;
|
||||
CHECK(!TaskitemConfidenceAmbiguity::annotate({}, normalized, &out, &error), "annotate should fail");
|
||||
CHECK(error == "tasks_empty", "wrong error");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_queue_not_ready_reduces_confidence() {
|
||||
TEST(queue_not_ready_reduces_confidence);
|
||||
std::vector<AnnotatedTaskitem> out;
|
||||
RequirementNormalizationResult normalized;
|
||||
std::string error;
|
||||
CHECK(TaskitemConfidenceAmbiguity::annotate({task("task-1", false)}, normalized, &out, &error), "annotate should succeed");
|
||||
CHECK(out[0].confidence < 80, "confidence should be reduced");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_ambiguous_requirements_reduce_confidence() {
|
||||
TEST(ambiguous_requirements_reduce_confidence);
|
||||
std::vector<AnnotatedTaskitem> out;
|
||||
RequirementNormalizationResult normalized;
|
||||
normalized.requirements.push_back(req("r1", true));
|
||||
std::string error;
|
||||
CHECK(TaskitemConfidenceAmbiguity::annotate({task("task-1", true)}, normalized, &out, &error), "annotate should succeed");
|
||||
CHECK(out[0].ambiguityCount == 1, "ambiguity count mismatch");
|
||||
CHECK(out[0].confidence <= 75, "confidence should be reduced by ambiguity");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_conflicts_reduce_confidence() {
|
||||
TEST(conflicts_reduce_confidence);
|
||||
std::vector<AnnotatedTaskitem> out;
|
||||
RequirementNormalizationResult normalized;
|
||||
normalized.conflicts.push_back({"a", "b", "constraint_contradiction", "detail"});
|
||||
std::string error;
|
||||
CHECK(TaskitemConfidenceAmbiguity::annotate({task("task-1", true)}, normalized, &out, &error), "annotate should succeed");
|
||||
CHECK(out[0].confidence <= 77, "confidence should be reduced by conflicts");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_dependency_presence_adds_reason() {
|
||||
TEST(dependency_presence_adds_reason);
|
||||
std::vector<AnnotatedTaskitem> out;
|
||||
RequirementNormalizationResult normalized;
|
||||
auto t = task("task-1", true);
|
||||
t.dependencyTaskIds.push_back("task-0");
|
||||
std::string error;
|
||||
CHECK(TaskitemConfidenceAmbiguity::annotate({t}, normalized, &out, &error), "annotate should succeed");
|
||||
bool found = false;
|
||||
for (const auto& r : out[0].reasons) if (r == "depends_on_prior_tasks") found = true;
|
||||
CHECK(found, "dependency reason expected");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_low_confidence_adds_reason() {
|
||||
TEST(low_confidence_adds_reason);
|
||||
std::vector<AnnotatedTaskitem> out;
|
||||
RequirementNormalizationResult normalized;
|
||||
normalized.requirements.push_back(req("r1", true));
|
||||
normalized.requirements.push_back(req("r2", true));
|
||||
normalized.requirements.push_back(req("r3", true));
|
||||
normalized.conflicts.push_back({"a", "b", "constraint_contradiction", "detail"});
|
||||
auto t = task("task-1", false);
|
||||
std::string error;
|
||||
CHECK(TaskitemConfidenceAmbiguity::annotate({t}, normalized, &out, &error), "annotate should succeed");
|
||||
bool found = false;
|
||||
for (const auto& r : out[0].reasons) if (r == "low_confidence") found = true;
|
||||
CHECK(found, "low confidence reason expected");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_high_confidence_adds_clear_path_reason() {
|
||||
TEST(high_confidence_adds_clear_path_reason);
|
||||
std::vector<AnnotatedTaskitem> out;
|
||||
RequirementNormalizationResult normalized;
|
||||
auto t = task("task-1", true);
|
||||
std::string error;
|
||||
CHECK(TaskitemConfidenceAmbiguity::annotate({t}, normalized, &out, &error), "annotate should succeed");
|
||||
CHECK(out[0].reasons[0] == "high_confidence_clear_path", "clear-path reason expected");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_escalate_when_queue_not_ready() {
|
||||
TEST(escalate_when_queue_not_ready);
|
||||
std::vector<AnnotatedTaskitem> out;
|
||||
RequirementNormalizationResult normalized;
|
||||
std::string error;
|
||||
CHECK(TaskitemConfidenceAmbiguity::annotate({task("task-1", false)}, normalized, &out, &error), "annotate should succeed");
|
||||
CHECK(out[0].escalate, "should escalate when queue not ready");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_escalate_when_ambiguous() {
|
||||
TEST(escalate_when_ambiguous);
|
||||
std::vector<AnnotatedTaskitem> out;
|
||||
RequirementNormalizationResult normalized;
|
||||
normalized.requirements.push_back(req("r1", true));
|
||||
std::string error;
|
||||
CHECK(TaskitemConfidenceAmbiguity::annotate({task("task-1", true)}, normalized, &out, &error), "annotate should succeed");
|
||||
CHECK(out[0].escalate, "should escalate when ambiguous");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_no_escalation_for_high_confidence_clear_item() {
|
||||
TEST(no_escalation_for_high_confidence_clear_item);
|
||||
std::vector<AnnotatedTaskitem> out;
|
||||
RequirementNormalizationResult normalized;
|
||||
std::string error;
|
||||
CHECK(TaskitemConfidenceAmbiguity::annotate({task("task-1", true)}, normalized, &out, &error), "annotate should succeed");
|
||||
CHECK(!out[0].escalate, "should not escalate");
|
||||
PASS();
|
||||
}
|
||||
|
||||
void test_multiple_tasks_all_annotated() {
|
||||
TEST(multiple_tasks_all_annotated);
|
||||
std::vector<AnnotatedTaskitem> out;
|
||||
RequirementNormalizationResult normalized;
|
||||
std::string error;
|
||||
CHECK(TaskitemConfidenceAmbiguity::annotate({task("task-1", true), task("task-2", false)}, normalized, &out, &error), "annotate should succeed");
|
||||
CHECK(out.size() == 2, "two annotations expected");
|
||||
CHECK(out[1].escalate, "second should escalate");
|
||||
PASS();
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "Step 580: Taskitem Confidence + Ambiguity Annotation\n";
|
||||
|
||||
test_annotate_success(); // 1
|
||||
test_annotate_fails_for_empty_tasks(); // 2
|
||||
test_queue_not_ready_reduces_confidence(); // 3
|
||||
test_ambiguous_requirements_reduce_confidence();// 4
|
||||
test_conflicts_reduce_confidence(); // 5
|
||||
test_dependency_presence_adds_reason(); // 6
|
||||
test_low_confidence_adds_reason(); // 7
|
||||
test_high_confidence_adds_clear_path_reason(); // 8
|
||||
test_escalate_when_queue_not_ready(); // 9
|
||||
test_escalate_when_ambiguous(); // 10
|
||||
test_no_escalation_for_high_confidence_clear_item(); // 11
|
||||
test_multiple_tasks_all_annotated(); // 12
|
||||
|
||||
std::cout << "\nResults: " << passed << "/" << (passed + failed) << " passed\n";
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
33
progress.md
33
progress.md
@@ -10768,3 +10768,36 @@ queue-readiness metadata, prerequisite operations, and dependency hints.
|
||||
- `editor/src/TaskitemGeneratorV2.h` within header-size limit (`65` <= `600`)
|
||||
- `editor/tests/step579_test.cpp` within test-file size guidance (`225` lines)
|
||||
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`
|
||||
|
||||
### Step 580: Taskitem Confidence + Ambiguity Annotation
|
||||
**Status:** PASS (12/12 tests)
|
||||
|
||||
Implements confidence and ambiguity annotation for generated taskitems to drive
|
||||
routing/escalation behavior in constrained execution pipelines.
|
||||
|
||||
**Files added:**
|
||||
- `editor/src/TaskitemConfidenceAmbiguity.h` - annotation module:
|
||||
- per-task confidence scoring from queue-readiness, ambiguity, conflicts, dependencies
|
||||
- ambiguity/conflict reason synthesis for operator visibility
|
||||
- escalation flag computation for low-confidence or ambiguous tasks
|
||||
- stable bounded confidence outputs (`0..100`)
|
||||
- `editor/tests/step580_test.cpp` - 12 tests covering:
|
||||
- annotation success/failure behavior
|
||||
- confidence reductions from queue/ambiguity/conflict signals
|
||||
- reason generation behavior
|
||||
- escalation/no-escalation behavior
|
||||
- multi-task annotation behavior
|
||||
|
||||
**Files modified:**
|
||||
- `editor/CMakeLists.txt` - `step580_test` target
|
||||
|
||||
**Verification run:**
|
||||
- `cmake -S editor -B editor/build-native` - PASS
|
||||
- `cmake --build editor/build-native --target step580_test step579_test` - PASS
|
||||
- `./editor/build-native/step580_test` - PASS (12/12)
|
||||
- `./editor/build-native/step579_test` - PASS (12/12) regression coverage
|
||||
|
||||
**Architecture gate check:**
|
||||
- `editor/src/TaskitemConfidenceAmbiguity.h` within header-size limit (`85` <= `600`)
|
||||
- `editor/tests/step580_test.cpp` within test-file size guidance (`189` lines)
|
||||
- Header-only architecture and naming conventions remain aligned with `ARCHITECTURE.md`
|
||||
|
||||
Reference in New Issue
Block a user