Skip to content

feat(#88): add valence and intensity metadata#174

Merged
magicpro97 merged 4 commits into
mainfrom
feat/issue-88-valence-intensity
May 12, 2026
Merged

feat(#88): add valence and intensity metadata#174
magicpro97 merged 4 commits into
mainfrom
feat/issue-88-valence-intensity

Conversation

@magicpro97
Copy link
Copy Markdown
Owner

Summary

Closes #88

magicpro97 and others added 2 commits May 12, 2026 23:44
- 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>
Copilot AI review requested due to automatic review settings May 12, 2026 17:11
@magicpro97 magicpro97 added the enhancement New feature or request label May 12, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_entries with valence and intensity (plus an index on intensity).
  • Extend learn.py to accept --valence / --intensity and persist them (including preserving stored intensity on valence-only updates).
  • Update briefing.py ranking 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 thread learn.py Outdated
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 thread tests/test_valence_intensity.py Outdated
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))

magicpro97 and others added 2 commits May 13, 2026 00:32
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>
@magicpro97 magicpro97 merged commit 619ec39 into main May 12, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Valence + Intensity — Metadata mới cho knowledge entries từ Hippocampus

2 participants