Skip to content

hook: inject an orient briefing for plain-English tasks#462

Closed
rs545837 wants to merge 3 commits into
mainfrom
feat/hook-plainword-inject
Closed

hook: inject an orient briefing for plain-English tasks#462
rs545837 wants to merge 3 commits into
mainfrom
feat/hook-plainword-inject

Conversation

@rs545837

@rs545837 rs545837 commented Jul 5, 2026

Copy link
Copy Markdown
Member

The sem hook prompt-submit UserPromptSubmit hook resolved only identifier-shaped tokens from the prompt by exact name — so it fired only when the user literally typed a function_name, and stayed silent on ordinary tasks like "fix the bug where empty blueprint names don't raise an error", which is exactly when injecting the code would help most.

Fix: when no entity is named, fall back to an orient --pack briefing (tight, 3 entities) over the whole prompt, so the agent starts with the relevant code in context and skips the search. This is the 0-turn understanding path — measured at 9.4s vs 13.2s (−29%) when the code is pre-injected, vs the agent calling a tool (a turn) which was net slower.

Verified locally:

  • Coding/navigation prompts inject a briefing (fix the bug where empty blueprint names…, where is the code that builds the graph).
  • Chat/meta injects nothing (explain the philosophy…, are we faster, …the fundraise — whole-word match so 'fundraise' doesn't trip 'raise').
  • Fast: ~0.05s on a cached repo, hard-capped at 2.5s so a cold/huge repo can't stall a prompt.

This is the 'last mile' that makes auto-injection actually fire on real tasks, built on the ranking fixes in #460/#461.

The prompt-submit hook only fired when the prompt literally named an
entity (snake_case/CamelCase/backtick) and resolved it by exact name — so
it stayed silent on ordinary tasks like 'fix the empty blueprint name
bug', which is exactly when injection would help most. Add a fallback:
when no entity is named, run orient --pack (tight, 3 entities) on the
whole prompt and inject that briefing. Fast on a cached repo (~0.05s,
2.5s hard cap), gated to coding/navigation intent (whole-word match so
'fundraise' doesn't trip 'raise'), silent on chat/meta.

@inspect-review inspect-review 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.

inspect review

Triage: 3 entities analyzed | 0 critical, 0 high, 1 medium, 2 low
Verdict: standard_review

Findings (0)


Reviewed by inspect | Entity-level triage found 0 high-risk changes

Full bodies stay limited to the top few so an injected agent isn't
distracted, but the briefing now ends with a compact 'also relevant'
index — the ranker's next ~12 candidates as name/type/file one-liners.
When the top bodies miss the exact fix location, the index points at the
right neighborhood so the agent jumps there instead of grepping blind,
without paying full-body tokens for the tail. This is what lets the
prompt-submit hook stay focused (3 bodies) yet still lead the agent to
the fix on harder tasks where ranking alone doesn't nail it.

@inspect-review inspect-review 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.

inspect review

Triage: 4 entities analyzed | 0 critical, 0 high, 2 medium, 2 low
Verdict: standard_review

Findings (0)


Reviewed by inspect | Entity-level triage found 0 high-risk changes

Lead the briefing with the resolved structure, not just bodies. Before
the code, print the ranked entities as a map annotated with each one's
deterministic blast radius (dependent count, marked when high) and the
intra-set call edges. This gives the model an attention prior — where a
change ripples and how the entities connect — so it reasons WITH the
graph instead of reconstructing it from linear text. Targets accuracy
(edit knowing the blast radius, don't break unseen callers) as much as
speed. Composes with the recall index: map -> focused bodies -> leads.

@inspect-review inspect-review 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.

inspect review

Triage: 4 entities analyzed | 0 critical, 0 high, 2 medium, 2 low
Verdict: standard_review

Findings (0)


Reviewed by inspect | Entity-level triage found 0 high-risk changes

@rs545837

rs545837 commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

Superseded by the orient removal (#463). That PR added the fuzzy hook fallback; we're removing all fuzzy retrieval instead.

@rs545837 rs545837 closed this Jul 5, 2026
rs545837 added a commit that referenced this pull request Jul 5, 2026
sem becomes **purely deterministic**. Removed: the `orient` command and
its `--pack` briefing, the sem-core ranking (lexical scoring, IDF,
recall net, structural priming), the `sem_entities query=` intent-search
mode, and the resident server's `orient` socket op.

**Why:** a 45-task validation (requests/flask/sphinx) showed orient's
~47% hit-rate could not be lifted by heuristics without causing
regressions (0 gains, 5+ regressions on a graph-expansion + path-penalty
attempt). Fuzzy ranking was the only non-deterministic thing in sem, and
it was where all the complexity accreted. The deterministic commands
never needed it.

**Remaining surface:** `context` (entity + callers/callees), `impact`
(blast radius), `diff`, `entities` (list by path, or `text=` for
exact-substring search), `blame`, `log`. To find code whose name you
don't know: text-search for a candidate, then `sem context` for the
structure grep can't give. The prompt-submit hook keeps its
deterministic exact-name prefetch.

745 lines deleted. Build clean, tests green (2 pre-existing `sem diff`
cwd-resolution failures unrelated).

Supersedes #462 (which added the fuzzy hook fallback this removes).

Note: sem-cloud has a `repo_orient` endpoint that pins a published
sem-core; it'll need the same removal when it bumps.
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