feat: add read_discovery_answers, append_followup_answer, and ask-more command

- Add read_discovery_answers() to parse discovery-log.md rows into dicts
  with low_confidence and needs_followup boolean flags.
- Add append_followup_answer() to append follow-up rows linked to original Q-A IDs.
- Add 'ask-more' CLI command that detects Low-confidence and Follow-up-needed
  answers, prompts for additional details, and records them in the log.
- Add 6 tests: read_discovery_answers round-trip, empty-log handling,
  low-confidence detection, follow-up flag detection, and append_followup.
This commit is contained in:
2026-06-02 09:57:02 +01:00
parent 07ee27b03e
commit 39728667a7
3 changed files with 202 additions and 1 deletions
+90
View File
@@ -105,6 +105,96 @@ def test_append_preserves_existing_history(tmp_path: Path) -> None:
assert len(data_rows) == 2
def test_read_discovery_answers_returns_dicts(tmp_path: Path) -> None:
discovery_mod.append_discovery_answer(
tmp_path,
question_id="Q-001",
question="What is this?",
answer="A thing",
confidence="High",
follow_up_needed="No",
)
answers = discovery_mod.read_discovery_answers(tmp_path)
assert len(answers) == 1
assert answers[0]["id"] == "Q-001"
assert answers[0]["question"] == "What is this?"
assert answers[0]["answer"] == "A thing"
assert answers[0]["confidence"] == "High"
assert answers[0]["follow_up_needed"] == "No"
assert answers[0]["needs_followup"] is False
assert answers[0]["low_confidence"] is False
def test_read_discovery_answers_returns_empty_when_no_log(tmp_path: Path) -> None:
log_path = tmp_path / "context" / "discovery-log.md"
assert not log_path.exists()
answers = discovery_mod.read_discovery_answers(tmp_path)
assert answers == []
def test_read_discovery_answers_detects_low_confidence(tmp_path: Path) -> None:
discovery_mod.append_discovery_answer(
tmp_path,
question_id="Q-002",
question="How much?",
answer="About half",
confidence="Low",
follow_up_needed="No",
)
answers = discovery_mod.read_discovery_answers(tmp_path)
low_conf_rows = [a for a in answers if a["low_confidence"]]
assert len(low_conf_rows) == 1
assert low_conf_rows[0]["id"] == "Q-002"
def test_read_discovery_answers_detects_followup_flag(tmp_path: Path) -> None:
discovery_mod.append_discovery_answer(
tmp_path,
question_id="Q-003",
question="What next?",
answer="TBD",
confidence="High",
follow_up_needed="Yes",
)
answers = discovery_mod.read_discovery_answers(tmp_path)
fu_rows = [a for a in answers if a["needs_followup"]]
assert len(fu_rows) == 1
assert fu_rows[0]["id"] == "Q-003"
def test_append_followup_appends_row(tmp_path: Path) -> None:
# First create the log with an existing entry
discovery_mod.append_discovery_answer(
tmp_path,
question_id="Q-010",
question="Original?",
answer="Original answer",
confidence="High",
follow_up_needed="No",
)
original_count = len(discovery_mod.read_discovery_answers(tmp_path))
discovery_mod.append_followup_answer(
tmp_path,
question_id="Q-010",
follow_up_question="Can you elaborate?",
answer="Yes, it's bigger than expected.",
confidence="Medium",
)
answers = discovery_mod.read_discovery_answers(tmp_path)
assert len(answers) == original_count + 1
# The new row should have the original Q-010 id and follow-up data
new_row = [a for a in answers if a["question"] == "Can you elaborate?"][0]
assert new_row["follow_up_needed"] == "Yes"
assert new_row["confidence"] == "Medium"
def test_header_is_written_on_create(tmp_path: Path) -> None:
discovery_mod.append_discovery_answer(
tmp_path,