Skip to content

feat(themes): cross-session pattern detection via entity co-occurrence#332

Merged
plind-junior merged 2 commits into
vouchdev:testfrom
dripsmvcp:feat/cross-session-themes
Jul 1, 2026
Merged

feat(themes): cross-session pattern detection via entity co-occurrence#332
plind-junior merged 2 commits into
vouchdev:testfrom
dripsmvcp:feat/cross-session-themes

Conversation

@dripsmvcp

Copy link
Copy Markdown
Contributor

summary

  • adds kb.detect_themes — read-only detector that finds recurring entity clusters across completed sessions using deterministic co-occurrence scoring (no LLM)
  • adds kb.propose_theme — routes detected clusters through the review gate as "theme" synthesis pages, visible in kb.list_pending
  • registered on all four surfaces: mcp tool, jsonl handler, cli command (vouch detect-themes), and capabilities list
  • adds THEME to the PageType enum; deduplicates against existing/pending theme pages

design

scoring: session_count * log(1 + claim_count) over entity-pair co-occurrence. pairs sharing entities are merged via union-find into larger clusters. archived, superseded, redacted, and unapproved claims are excluded.

config (defensive defaults):

themes:
  enabled: true
  min_sessions: 2
  min_claims: 3
  top_k: 10

cli:

vouch detect-themes [--min-sessions N] [--min-claims N] [--top-k K] [--json]
vouch detect-themes --propose --agent <name>

test plan

  • 11 tests in tests/test_themes.py covering detection, thresholds, read-only invariant, archived exclusion, config disable, proposal gating, deduplication, determinism, and top-k
  • test_capabilities passes (method list parity)
  • mypy clean, ruff clean
  • full test suite passes (1 pre-existing failure in test_volunteer_context unrelated to this change)

closes #311

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d9940760-c805-4cd7-9ff6-36f716c06053

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added cli command line interface mcp mcp, jsonl, and http surfaces storage kb storage, migrations, schemas, and proposals tests tests and fixtures size: L 500-999 changed non-doc lines labels Jul 1, 2026
@plind-junior
plind-junior requested a review from Copilot July 1, 2026 15:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR implements cross-session pattern detection (issue #311). It adds a new src/vouch/themes.py module with a read-only detect_themes() detector that scores recurring entity co-occurrence clusters across completed sessions (deterministic session_count * log(1 + claim_count) scoring, union-find pair merging, exclusion of archived/superseded/redacted/unapproved claims), plus a propose_theme() path that routes detected clusters through the existing propose_page() review gate as "theme" pages. The feature is wired onto all four surfaces (MCP tool, JSONL handler, CLI vouch detect-themes, capabilities list), adds PageType.THEME, and dedups against existing/pending theme pages.

Changes:

  • New themes.py module: detect_themes (read-only detection) and propose_theme (gated proposal), with deterministic co-occurrence scoring and dedup.
  • Registers kb.detect_themes / kb.propose_theme across MCP server, JSONL server, CLI, and capabilities; adds THEME to PageType.
  • Adds tests/test_themes.py covering detection, thresholds, read-only invariant, archived exclusion, config disable, proposal gating, dedup, determinism, and top-k.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/vouch/themes.py New detector + gated proposal logic; config read is not fully defensive, and dedup can miss when entities are dropped at propose time.
src/vouch/server.py Adds kb_detect_themes / kb_propose_theme MCP tools mirroring the module API.
src/vouch/jsonl_server.py Adds matching JSONL handlers and HANDLERS map entries.
src/vouch/cli.py Adds vouch detect-themes command; --propose --json interleaves human text with JSON on stdout.
src/vouch/capabilities.py Registers the two new methods in METHODS for parity.
src/vouch/models.py Adds THEME = "theme" to PageType.
tests/test_themes.py Comprehensive tests for detection and proposal behavior.

Note: CHANGELOG.md under [Unreleased] was not updated for this user-visible feature, which the repository's contribution rules require.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/vouch/cli.py
Comment on lines +1872 to +1875
click.echo(
f"proposed: {p['theme_page_id']} "
f"({p['claim_count']} claims, {p['session_count']} sessions)"
)
Comment thread src/vouch/themes.py Outdated
Comment on lines +60 to +66
themes = cfg.get("themes", {})
return {
"enabled": bool(themes.get("enabled", True)),
"min_sessions": int(themes.get("min_sessions", 2)),
"min_claims": int(themes.get("min_claims", 3)),
"top_k": int(themes.get("top_k", 10)),
}
Comment thread src/vouch/cli.py
# --- cross-session themes -------------------------------------------------


@cli.command(name="detect-themes")
Comment thread src/vouch/themes.py
Comment on lines +267 to +275
valid_entities: list[str] = []
for eid in cluster.entities:
try:
store.get_entity(eid)
valid_entities.append(eid)
except Exception:
pass
if not valid_entities:
raise ProposalError("no valid entities in cluster")
@github-actions github-actions Bot added the docs documentation, specs, examples, and repo guidance label Jul 1, 2026
dripsmvcp added 2 commits July 2, 2026 02:01
adds kb.detect_themes (read-only cluster detector) and kb.propose_theme
(routes synthesis pages through the review gate). scoring is deterministic
— entity pair co-occurrence across sessions, weighted by log(1 + claim_count).

registered on all four surfaces (mcp, jsonl, cli, capabilities). the cli
exposes `vouch detect-themes` with --propose for one-shot propose-all.

adds THEME to the PageType enum so theme pages pass the page-kind gate.
deduplication prevents re-proposing clusters that already have pending or
approved theme pages.

closes vouchdev#311
…utput

- config reader now type-checks every value and falls back to defaults
  on malformed input (mirrors salience.reflex_cfg pattern)
- dedup in detect_themes now compares on the resolvable entity subset
  so it stays consistent with what propose_theme actually stores
- --propose --json no longer interleaves human-readable lines on stdout
- adds changelog entry under [unreleased]
@dripsmvcp
dripsmvcp force-pushed the feat/cross-session-themes branch from 23557ee to 7e495fc Compare July 1, 2026 17:02
@plind-junior
plind-junior merged commit c6e69eb into vouchdev:test Jul 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli command line interface docs documentation, specs, examples, and repo guidance mcp mcp, jsonl, and http surfaces size: L 500-999 changed non-doc lines storage kb storage, migrations, schemas, and proposals tests tests and fixtures

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants