Skip to content

feat(0.5.0): auto-load task-relevant KG entities in intake (BRO-1295)#6

Merged
broomva merged 2 commits into
mainfrom
feature/bro-1295-task-entity-autoload
Jun 1, 2026
Merged

feat(0.5.0): auto-load task-relevant KG entities in intake (BRO-1295)#6
broomva merged 2 commits into
mainfrom
feature/bro-1295-task-entity-autoload

Conversation

@broomva
Copy link
Copy Markdown
Owner

@broomva broomva commented Jun 1, 2026

Problem

Per-task knowledge contextualization was manual. The role-x intake hook auto-surfaced only persona constraints every prompt; task-specific entities loaded only when a domain lens scored ≥2. For off-lens prompts (most), no topic knowledge auto-loaded — the agent was contextualized on who the user is, not what we already know about the task. The kg skill was the manual fallback.

This was surfaced by an audit (BRO-1288 arc): capture + catalog-index are automated (Stop hooks), substrate is healthy (355 entities, 0 lint errors), retrieval is decent (R@5 0.86 via bookkeeping bench) — but the read path wasn't wired into every turn.

Change

After lens selection, intake scans the dense knowledge catalog (docs/knowledge-index.md, schema dense-catalog-v2), scores each entity's slug/tags/claim against the prompt tokens, and surfaces the top-5 under a new block:

Task-relevant knowledge (auto-loaded by relevance — read full bodies via `/kg load <slug>` or Read before relying on them):
  - <core_claim>  ·  [research/entities/<type>/<slug>.md]
  ...

Self-contained — no cross-skill import of the kg loader, so the hook degrades gracefully (empty list, exit 0) when the catalog or kg is absent. Reuses the existing _tokenize_prompt + _confined_entity_path + _safe_inline helpers.

Guards (each found + fixed by P11 validation against the live 318-entity catalog)

Guard Why
Curated-match gate — surface only on slug/tag overlap, never body-text claim alone precision over a 300+ entity graph; a body-excerpt "claim" that happens to contain the prompt word is noise
Body-excerpt suppression — weak-core_claim entities render path-only the catalog stores a truncated body excerpt for entities with no clean claim; rendering it = markdown noise. Heuristic: ends-with- (a real ≤140-char claim is stored whole) or structural markers
Robust header parse — tolerates trailing · score N/9 that suffix broke the \]$ anchor and made the parser drift, mis-attributing an adjacent block's text (caught a real entity surfacing the wrong claim)
Weighted slug(3)/tag(2)/claim(1), min 3, dedup vs persona/lens, persona-type skipped ranking + no duplication of already-surfaced constraints

Validation (P11)

  • Ran intake against the real workspace catalog on knowledge-topic and RCS-topic prompts → surfaces the right entity cluster for each (the screenshots of that are what exposed the 3 guards above).
  • Full suite 51/51 green (47 existing + 4 new: surface-relevant · body-excerpt→path-only · curated-gate-rejects-body-only · no-catalog→no-block).

Dep-chain (P14)

  • Upstream: _format_intake_context, _tokenize_prompt, _confined_entity_path, _safe_inline; the dense-catalog-v2 format emitted by bookkeeping index.
  • Downstream: the UserPromptSubmit intake hook (every prompt, all workspaces). Merge to main = published; .agents/ + global snapshots refreshed via npx skills update role-x.

Closes BRO-1295 · follows BRO-1288/BRO-1292.

🤖 Generated with Claude Code

Closes the "contextualized on who, not on what" gap. Until now intake surfaced
only persona constraints every prompt; task-specific entities loaded only when a
domain lens scored >=2. For off-lens prompts (most), no topic knowledge was
auto-loaded. Now every turn carries the top-5 relevant entities from the graph.

Mechanism (self-contained — no cross-skill import of the kg loader):
- After lens selection, scan docs/knowledge-index.md (dense-catalog-v2), score
  each entity's slug/tags/claim vs prompt tokens, surface top-5 in a new
  "Task-relevant knowledge (auto-loaded by relevance ...)" block.

Guards (found + fixed via P11 validation against the live catalog):
- Curated-match gate: surface only on slug/tag overlap, never body-text alone.
- Body-excerpt suppression: weak-core_claim entities render path-only, not
  markdown noise (ellipsis + structural-marker heuristic).
- Robust header parse: tolerates trailing " · score N/9" that drifted the parser.
- Weighted slug(3)/tag(2)/claim(1), min 3, dedup vs persona/lens, persona skipped.
- Never blocks the turn: any absence/parse error -> empty list, exit 0.

4 new tests; full suite 51/51 green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@linear
Copy link
Copy Markdown

linear Bot commented Jun 1, 2026

BRO-1295

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Warning

Review limit reached

@broomva, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 26 minutes and 35 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 20e6e9d5-e83b-4247-a555-b067e4189110

📥 Commits

Reviewing files that changed from the base of the PR and between 4bcf078 and c48515e.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • scripts/role-x.py
  • tests/test_role_x.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/bro-1295-task-entity-autoload

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 and usage tips.

…uppression (BRO-1295)

P20 cross-review (FAIL 6/10) found two real, verified, untested defects:

1. BLOCKING — `except OSError` does not catch `UnicodeDecodeError` (a ValueError),
   so a single non-UTF-8 byte in any scraped catalog claim crashed the every-prompt
   hook (exit 1). Siblings already use `except Exception`; my narrow catch was a
   regression. Fix: broaden to `except Exception` + read with errors="replace"
   + an 8 MiB size cap (keeps the hook inside its time budget at any graph size).

2. BLOCKING — `_clean_claim_or_none` matched interior " > " as a markdown
   blockquote, false-suppressing legit math claims. On the live catalog this
   stripped the claim off `stability-budget` itself (the flagship RCS entity:
   "lambda_i must stay > 0 …"). Fix: detect only a *leading* "> "; the ellipsis
   check still catches the real body excerpts.

Non-blocking (also applied): type whitelist (drop discovery/question noise),
dedup by type/slug (not bare stem), catalog size cap.

Tests: +2 regression tests (math-inequality claim survives; non-UTF-8 catalog
exits 0). Suite 53/53. Verified on the live 318-entity catalog: stability-budget
now renders its full claim inline; 0 discovery/question noise on generic prompts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@broomva
Copy link
Copy Markdown
Owner Author

broomva commented Jun 1, 2026

P20 Cross-Review — verdict: PASS (after one fix round)

Round 1 (FAIL 6/10) — fresh-context adversarial review found two real, verified, untested blocking defects:

  1. except OSError didn't catch UnicodeDecodeError → a non-UTF-8 byte in any scraped catalog claim crashed the every-prompt hook (exit 1).
  2. _clean_claim_or_none matched interior " > " as a blockquote → false-suppressed legit math claims, stripping the claim off stability-budget itself on the live catalog.

Fixes (c48515e): broaden to except Exception + errors="replace" + 8 MiB size cap; detect only a leading > (ellipsis check still catches real excerpts). Non-blocking also applied: type whitelist (drop discovery/question noise), type/slug dedup, size cap. Added 2 regression tests.

Round 2 (PASS) — re-verification confirmed: both resolved; no new regressions; suite 53/53; and the 2 new tests genuinely gate the fixes (reverting B1 → UnicodeDecodeError traceback; reverting B2 → must stay > 0 absent). Verified empirically on the live 318-entity catalog — stability-budget now renders its full claim inline; 0 discovery/question noise on generic prompts.

@broomva broomva merged commit d8455a4 into main Jun 1, 2026
3 checks passed
@broomva broomva deleted the feature/bro-1295-task-entity-autoload branch June 1, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant