Skip to content

feat(tui): @ mentions attach workspace files client-side with ranges, dirs, globs, @diff/@sha, and completion (T12) - #45

Merged
lg2m merged 3 commits into
mainfrom
feat/tool-layer-t12-mentions
Sep 15, 2026
Merged

lg2m merged 3 commits into
mainfrom
feat/tool-layer-t12-mentions

Conversation

@lg2m

@lg2m lg2m commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

T12: @ mentions — attach workspace files client-side, with ranges, directories, globs, @diff/@sha, and completion

Spec: docs/plans/tool-layer.md § D8 Linear: ENG-778 Follows: v0.1.0

What changed

User-visible

compare @notes.md:2-3 with @src/**/*.rs; see @diff and @skill:review
  • @path attaches a workspace file to the prompt as InputPart::WorkspaceFile with expected_hash filled at compose time — so a stale attachment fails the run before the model sees it, exactly as the protocol always promised but no client did.
  • @path:12-40 attaches only those lines (rendered <attached-file path=… lines="12-40/230">); the runtime still hashes and records the whole file, so edit_file on it needs no re-read.
  • @dir/ and @glob expand through the same ignore-aware walk the tools use to ≤ 8 attachments; more refuses with "narrow the directory". Generated dirs, hidden files, binaries, and > 256 KiB files are skipped.
  • @diff, @diff:REF, @sha:REF attach bounded git output (64 / 16 KiB) as text — the user's own tree, no policy hop.
  • @web:URL becomes text asking the model to fetch (network authority stays with server policy). @skill:name at message start rewrites to /name.
  • Unresolvable paths, emails, @decorators, @@, and anything inside code fences are left literal and noted; the grammar never eats a word.
  • Completion: typing on an @ token opens a files box (same chrome as the slash menu) ranked by prefix, substring, subsequence, shorter-path, with the session's recently edited files first. Tab/Enter accept; a directory keeps completing one level down; Esc closes.
  • Works in qq run too: mentions in the prompt resolve, notes go to stderr.

Design

  • Grammar is a pure module in qq-protocol (parse_mentions), so the browser client can share it; wasm build verified.
  • Resolution and completion live in qq-core::mentions (new pub module) reusing Workspace containment, IgnoreStack, list_children, and PathFilter from the search walker. qq-tui gains a qq-core dependency for this — the plan's "reuses the search machinery" is not satisfiable from the TUI otherwise, and xtask already has the edge.
  • Two new Effects keep App pure: ResolveMentions(PendingSubmit) and CompleteMention { query, recent } run in spawn_blocking from the loop and call back into App. Stale completion replies are dropped by query. Plain prompts never pay the hop (a cheap parse decides).
  • TuiOptions.workspace_root: Option<PathBuf> — qq passes its canonical cwd; a remote client without the tree leaves @ literal.
  • Protocol: InputPart::WorkspaceFile.range: Option<LineRange { start, end }> additive with skip_serializing_if; InputError::InvalidRange. No PROTOCOL_VERSION bump — a v20 server ignores nothing (the field is default) and a v20 client never sends it unless the user types a range; I'd bump at the next release boundary as with T6.

How verified

  • cargo test --workspace: 1416 passed / 0 failed; fmt, clippy -D warnings clean; cargo build -p qq-client --target wasm32-unknown-unknown --features wasm ok.
  • 15 tests: grammar (4), resolver incl. a real git init for @diff/@sha (5), runtime range slicing (1), TUI composer/popup/submit/no-root (4), headless end-to-end asserting the sliced attachment, stderr note, and transcript placeholder (1).

Measurements

Gate Result
TUI render sessions_200_with_sidebar_frame 35.6 → 35.3 µs
keystroke_to_frame 28.6 µs (the @ token check is one rfind)

Evidence: target/qq-perf/t12-2026-09-14/.

Docs

  • docs/design/tools.md § File References In Prompts rewritten (grammar, resolution, completion); docs/design/protocol.md workspace_file row; ledger receipt.

Compatibility

  • Additive protocol field; no version bump (see above). Store unchanged. No prompt change.
  • Pre-existing gap noted, not fixed here: the server still renders WorkspaceFile parts as @path placeholders on SteerRun and direct qq ask (it resolves them only on SubmitPrompt). The TUI now emits file parts on steer, so a steered @file reaches the model as a placeholder until the server side is extended — recorded as open in the ledger.

Follow-ups

  • Server-side resolution on steer/ask. T13 measures completion usage.

… dirs, globs, @diff/@sha, and completion (T12)

The grammar (qq_protocol::parse_mentions) is pure and shared by the TUI
and qq run: @path[:line[-line]], @web:URL, @diff[:REF], @sha:REF,
@skill:name; recognised at message start or after whitespace/(/[, ended
by whitespace/)/]/,/;, trailing .:?! excluded, @@ literal, code fences
skipped, unresolvable paths left literal so emails and decorators are
never eaten.

qq_core::mentions resolves a parsed prompt off the executor through the
same cap-std containment and ignore-aware walk the tools use: a file
becomes InputPart::WorkspaceFile with expected_hash filled at compose
time (SHA-256 of the current bytes) and an optional range; a directory
or glob expands to <= 8 attachments or refuses with "narrow the
directory"; @diff/@sha attach bounded git output (64 / 16 KiB) as text
from the user's own tree; @web becomes text asking the model to fetch
so network authority passes server policy; @skill:name at the start
becomes /name. complete_paths ranks an ignore-aware walk by prefix,
substring, subsequence, and recency of the session's edits, under a
150 ms deadline.

Protocol: InputPart::WorkspaceFile gains range: Option<LineRange>
(additive; the runtime attaches only those lines but hashes and records
the whole file, so an edit needs no re-read); InputError::InvalidRange.
The attachment renders <attached-file path=… lines="a-b/total">.

TUI: the composer exposes the @ token at the cursor; typing on one
requests candidates (Effect::CompleteMention, spawn_blocking) shown in
the slash-menu box; Tab/Enter accept (a directory keeps completing),
Esc closes. A prompt with mentions submits through
Effect::ResolveMentions and comes back as parts; a failure returns the
text to the composer. Steering goes through the same path. qq run
resolves mentions in the prompt and reports notes on stderr. A client
without a workspace tree (TuiOptions.workspace_root None) leaves @
literal. qq-tui now depends on qq-core for the walk.
@lg2m
lg2m force-pushed the feat/tool-layer-t12-mentions branch from 198990a to 1dbff75 Compare September 15, 2026 21:45
@lg2m
lg2m merged commit 896ea93 into main Sep 15, 2026
4 checks passed
@lg2m
lg2m deleted the feat/tool-layer-t12-mentions branch September 15, 2026 21:49
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