feat(#88): add valence and intensity metadata#174
Merged
Conversation
- migrate.py: v21 migration adds valence TEXT and intensity REAL columns with DEFAULT '' / DEFAULT 0.5, plus idx_ke_intensity index - learn.py: --valence (reward/neutral/penalty/trauma) and --intensity (0.0-1.0) CLI flags; post-INSERT UPDATE pattern matching existing error_lifecycle_columns convention; json_mode output includes fields - briefing.py: _ke_has_intensity() and _intensity_order_expr() helpers; search_knowledge_entries() uses (COALESCE(intensity,0.5)*confidence) DESC ranking for all query paths including the documents-table fallback; wakeup TOP-MISTAKES query uses same intensity-weighted scoring - tests/test_valence_intensity.py: 34 regression tests covering migration, learn CLI flags, validation, briefing helpers, and ranking order Closes #88 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep briefing ranking intensity-first and preserve stored intensity on valence-only updates. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds valence/intensity metadata support for knowledge entries (issue #88), including DB migration, learn-time writing, and briefing-time ranking so higher-intensity warnings surface first.
Changes:
- Add migration v21 to extend
knowledge_entrieswithvalenceandintensity(plus an index on intensity). - Extend
learn.pyto accept--valence/--intensityand persist them (including preserving stored intensity on valence-only updates). - Update
briefing.pyranking to sort intensity-first when the DB supports it; add regression tests.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
tests/test_valence_intensity.py |
Adds regression tests for migration, learn write paths, and briefing ranking behavior. |
migrate.py |
Introduces v21 migration adding valence/intensity columns and an index. |
learn.py |
Adds CLI flags + DB write support for valence/intensity and includes these fields in --json output. |
briefing.py |
Adds schema detection + intensity-first ORDER BY for FTS results; updates wakeup “top mistakes” ordering with fallback. |
Comment on lines
+1564
to
+1568
| row = db.execute( | ||
| """ | ||
| SELECT id, category, title, confidence, session_id, task_id, | ||
| affected_files, facts, occurrence_count, last_seen | ||
| affected_files, facts, occurrence_count, last_seen, | ||
| COALESCE(valence, '') AS valence, |
Comment on lines
+275
to
+288
| # 4. learn.py -- CLI validation constants | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| print("\n[4] learn.py - valence/intensity validation constants") | ||
|
|
||
| valid_valences = ("reward", "neutral", "penalty", "trauma", "") | ||
| for v in valid_valences: | ||
| test("valence '%s' is valid" % v, v in valid_valences) | ||
|
|
||
| for good_i in (0.0, 0.5, 1.0, 0.99): | ||
| test("intensity %.2f in [0,1]" % good_i, 0.0 <= good_i <= 1.0) | ||
| for bad_i in (-0.1, 1.1, 2.0): | ||
| test("intensity %.1f outside [0,1]" % bad_i, not (0.0 <= bad_i <= 1.0)) | ||
|
|
Guard learn.py --json against missing valence/intensity columns and replace tautological validation coverage with real regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Apply the CI-required Ruff formatting change to learn.py without altering the pre-v21 compatibility logic or valence/intensity behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #88