Skip to content

feat(prime): add prime.exclude_types for the Key concepts section - #121

Open
weshofmann wants to merge 2 commits into
wandercom:mainfrom
weshofmann:feat/prime-exclude-types
Open

weshofmann wants to merge 2 commits into
wandercom:mainfrom
weshofmann:feat/prime-exclude-types

Conversation

@weshofmann

@weshofmann weshofmann commented Nov 24, 2026 •

Copy link
Copy Markdown

Problem

kin prime --for hook fills "Key concepts" from a search on the topic it detects from the working directory. Auto-captured session nodes are titled after that directory (for example Session: -home-dev-notes), so they match the topic too. Once enough of them accumulate, they take every Key concepts slot with near-identical stubs and crowd out the concepts the section is for. No setting controls this today.

Change

A new prime config section with one key:

prime:
  exclude_types: [session]
  • Filtered inside the search, not after it. The excluded types go to hybrid_search as a node_filter. Text and recall-cue candidates are admitted through it, so excluded types don't take their places and the next matches fill the section. Dropping them from the results afterwards would leave the section short, or empty when every hit is excluded. The vector channel still fetches top_k before filtering, so excluded types can use up its share; filtering vectors earlier would change shared retrieval code for every caller.
  • Neighbor titles follow the same filter. node_filter also applies to the [...] neighbor titles beside each entry, so an excluded type isn't named there either. (Session nodes already never appear there, because their edges aren't semantic.)
  • Caveats are kept. The filter chooses entries, not caveats. hybrid_search also uses node_filter when it attaches an imported Kinbase fact's open Unknowns, which are question nodes. So when question is excluded, the prime re-attaches them without the filter, and excluding question still leaves a fact's "Unknown [open]" line in place.
  • Only Key concepts. Constraints, watches, directives and recent activity are unchanged, so the setting can't hide an operational node.
  • Default []. No filter is passed and the prime is unchanged.
  • Bad values. An unknown type name raises a ValidationError at config load, like other invalid values, instead of silently matching nothing. kin config set prime.* validates before writing, as sim.* does, so a typo is refused rather than saved. A single type can be given as a bare string, as code_ingest.exclude allows, so kin config --global set prime.exclude_types session works. (--global goes before set: after it, Python 3.10 and 3.11 argparse reject the command.)
  • User config only. prime is in _PROJECT_LAYER_UNTRUSTED_KEYS, so a repository's .kin/config can't quietly hide node types from the prime of everyone working in it. Loosening that later is easy; tightening it after a release would be a breaking change.

Docs

  • CHANGELOG.md: an entry under Unreleased / Added.
  • README.md: the key in the configuration example, plus a paragraph after it that says to set it with --global.
  • kin.sample.yaml: a commented example.

Tests

New TestPrimeExcludeTypes in tests/test_hooks.py:

  • With the default config, session nodes appear in Key concepts.
  • With exclude_types: [session] and more matching sessions than slots, no session entry appears and both real concepts fill the freed slots.
  • An excluded type isn't named as a neighbor. The test uses a decision neighbor, which the default config does name.
  • Excluding question keeps an imported fact's open Unknown on its entry.
  • Excluding constraint leaves Active constraints untouched.
  • A bare string is accepted and duplicates are removed.
  • An unknown type is refused, both in Config(...) and through load_config on a kin.yaml.
  • kin config set refuses an unknown type without writing the file, and writes a valid one.

New test in tests/test_clone_config_authority.py: a repository's .kin/config value is ignored and recorded in _ignored_project_keys, and the user's own value still applies.

The refill, neighbor and Unknowns tests fail without the change. The full suite passes: pytest tests/ -n auto --dist loadfile --timeout 300 (4968 passed, 4 skipped), and make lint is clean. The new tests also pass on Python 3.10.

`kin prime` fills "Key concepts" from a search on the topic it detects
from the working directory. Auto-captured session nodes are titled after
that same directory, so they match the topic and can take every slot
with near-identical stubs, crowding out real concepts.

prime.exclude_types names node types to leave out. They are excluded
through hybrid_search's node_filter, so they never take a slot in the
candidate window and the next matches fill the section; filtering the
results afterwards would leave it empty when every hit is excluded. The
same filter keeps excluded types out of the neighbor titles shown
beside each entry. It chooses entries, not caveats: an imported Kinbase
fact's open Unknowns are re-attached unfiltered, so excluding question
never strips them. Constraints, watches, directives and recent activity
are unaffected.

The default is empty and the search runs unfiltered, as before. An
unknown type name is refused at config load, as other invalid values
are, rather than silently matching nothing. The key is user-config
only (added to _PROJECT_LAYER_UNTRUSTED_KEYS): a repository's
.kin/config could otherwise hide node types from the prime of everyone
working in it, without their seeing it.

@adaptcom adaptcom Bot 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.

Confidence Score: 2/5

Summary

Score reconciled from 4/5 because the review includes a blocking finding.

Adds user-only prime.exclude_types that filters Key concepts inside hybrid_search; default is a no-op and tests cover refill, neighbours, Unknowns and authority. Low code risk, but the documented enablement command fails as written.

Important Files Changed

File Overview
src/kindex/config.py New PrimeConfig with type validation; prime added to project-untrusted keys
src/kindex/hooks.py Passes node_filter to hybrid_search; re-attaches Unknowns unfiltered when excluding
README.md Documents the key; quoted kin config set --global invocation errors
kin.sample.yaml Commented example; same broken --global ordering
CHANGELOG.md Unreleased/Added entry
tests/test_hooks.py TestPrimeExcludeTypes covers default, refill, neighbour, Unknowns, validation
tests/test_clone_config_authority.py Repo .kin/config prime value ignored and recorded

Reviewed 528566c...9629512 · ↻ Re-run review · View in Adapt

Comment thread README.md Outdated
shown. Constraints, watches, directives and recent activity are unaffected. An
unknown type name is refused when the config loads. Only your own config sets
it; a repository's `.kin/config` cannot hide node types from your prime, so
set it with `kin config set --global prime.exclude_types session` or in

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified: kin config set --global prime.exclude_types session exits 2 with "unrecognized arguments" (argparse consumes the nargs='?' positionals before --global); document kin config --global set prime.exclude_types session instead.

Comment thread kin.sample.yaml Outdated
# auto-captured session nodes, titled after the working directory, match the
# detected topic and crowd out real concepts. Unknown type names are refused.
# User config only: a repository's .kin/config cannot set it, so use
# `kin config set --global prime.exclude_types session` or set it here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same broken invocation as README; use kin config --global set prime.exclude_types session (or put --global last).

Comment thread src/kindex/config.py
def _known_types(cls, value: list[str]) -> list[str]:
from .schema import STORAGE_NODE_TYPES

unknown = [t for t in value if t not in STORAGE_NODE_TYPES]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kin config set writes the value unvalidated, so a typo like sesion makes every later kin command fail and the prime hook degrade silently; pre-validate prime.* in _config_write as sim.* already is.

Comment thread src/kindex/hooks.py
# Configured types (prime.exclude_types) are left out of the search
# itself, not dropped afterwards, so they never take a slot the next
# match could fill. With none configured the search runs unfiltered.
excluded = frozenset(getattr(getattr(config, "prime", None), "exclude_types", None) or ())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The "never take a slot" claim holds for FTS and cues only: vector_search fetches top_k unfiltered and scoped_ranks drops excluded hits afterwards, so the vector channel can still be crowded out; adjust comment or filter vectors upstream.

Comment thread src/kindex/hooks.py
# imported fact keeps its open Unknowns (question nodes)
# even when questions are excluded as entries.
from .kinbase import attach_unknowns
attach_unknowns(store, r)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unfiltered attach_unknowns re-queries every kinbase result whenever any type is excluded; gate on "question" in excluded and hoist the import out of the loop.

- Document `kin config --global set prime.exclude_types session`. With
  --global after `set`, Python 3.10 and 3.11 argparse exit 2
  ("unrecognized arguments"); the leading form works on 3.10-3.14.
- `kin config set prime.*` validates before writing, as `sim.*` does,
  so a typo is refused instead of saved and failing every later load.
- Correct the refill claim: text and recall-cue candidates are admitted
  through the filter, but the vector channel fetches top_k before
  filtering, so excluded types can still use up its share.
- Re-attach Kinbase Unknowns only when `question` is excluded, with the
  import hoisted out of the loop.
@weshofmann

Copy link
Copy Markdown
Author

Addressed the review in 264685d:

  • --global ordering: confirmed. kin config set --global … exits 2 on Python 3.10 and 3.11 and works on 3.12+. The README and kin.sample.yaml now use kin config --global set prime.exclude_types session, which parses on 3.10 through 3.14.
  • Unvalidated kin config set: prime.* is now validated in _config_write before anything is written, the same way sim.* is. A typo like sesion exits 1 and leaves the file untouched. Added a test.
  • Vector channel: right, vector_search fetches top_k before scoped_ranks filters it. I corrected the comment, the docstring, the README and the CHANGELOG rather than filtering vectors upstream, since that would change shared retrieval code for every caller. Refill comes from the text and recall-cue channels, which the tests cover.
  • attach_unknowns cost: it now runs only when question is excluded, with the import outside the loop.

Full suite: 4968 passed, 4 skipped; the new tests also pass on Python 3.10.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant