Skip to content

feat(prime): wire IDE selection into loci context recall trigger#12

Merged
senna-lang merged 2 commits into
mainfrom
ide-selection-context-tri
Jun 13, 2026
Merged

feat(prime): wire IDE selection into loci context recall trigger#12
senna-lang merged 2 commits into
mainfrom
ide-selection-context-tri

Conversation

@senna-lang

@senna-lang senna-lang commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Summary

Add a trigger to loci prime's instruction text (PRIME_TEXT) so the agent treats an active IDE editor selection as a deictic anchor — the referent of "this / これ / この〜" — for past-conversation recall.

Mechanism facts (researched):

  • The IDE selection is not available to hooks (no selection field in UserPromptSubmit etc.) and is not queryable via MCP.
  • However, the selected text + active file path are injected into the agent's own context at prompt-submit time (⧉ Selected N lines from <file>).
  • → The right implementation is a prime instruction, not hook detection.

Trigger design (conjunction)

A selection only resolves which symbol is meant; it is not itself a recall request. Recall fires on the AND of:

  1. a selection is active, AND
  2. either (a) the user asks about the past, or (b) the agent's own next action (edit / refactor / debug) on the selected code needs prior decisions.

It must NOT fire when the selection is present only because the user is about to edit it (over-fire guard).

Selection → query mapping

Selection shape Action
Named function/class loci context --symbol "<name>"
Mid-function fragment Resolve the enclosing symbol via LSP/read, then loci context --symbol
Spans multiple symbols / non-symbol / lookups return nothing Fall back to loci search "<question>"

Scope is staged: phase 1 ships the prime instruction only. A loci context --file filter to disambiguate common symbol names is deferred until noise is actually observed.

Changes

  • src/codeatrium/cli/prime_cmd.py — add the "IDE selection as a deictic anchor" section to PRIME_TEXT.
  • tests/test_prime_cmd.py — add 5 contract tests (TDD: Red → Green).
  • Makefile — resolve ruff to the venv binary when present, otherwise uvx ruff, for lint/fmt (fixes the pre-commit hook failing in worktrees without a provisioned venv).

Verification

  • ruff lint passes
  • 251 passed

🤖 Generated with Claude Code

senna-lang and others added 2 commits June 13, 2026 12:39
Teach the agent to treat an active IDE editor selection as a deictic
anchor ("this / これ") for memory recall. The selection resolves *which*
symbol to look up; it does not by itself request a recall.

Recall fires only on the conjunction: a selection is active AND either
the user asks about the past or the agent's next action on the selected
code needs prior decisions. Guards against over-firing on edit-only
selections.

Selection -> query mapping: named symbol -> `loci context --symbol`;
mid-function fragment -> resolve enclosing symbol (LSP/read) first;
multi-symbol / non-symbol / empty result -> fall back to `loci search`.

Adds PRIME_TEXT contract tests for the new section.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The pre-commit hook (make check -> lint) hard-coded .venv/bin/ruff and
failed in worktrees without a provisioned venv. Resolve ruff to the venv
binary when present, otherwise `uvx ruff`, so lint/fmt work everywhere.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@senna-lang senna-lang changed the title feat(prime): IDE 選択を loci context recall の trigger に組み込む feat(prime): wire IDE selection into loci context recall trigger Jun 13, 2026
@claude

claude Bot commented Jun 13, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@senna-lang senna-lang merged commit a81aa85 into main Jun 13, 2026
3 checks passed
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