fix(mentions): resolve @ mentions followed by punctuation or naming paths with spaces - #6
Merged
Conversation
…aths with spaces A mention ran to the next whitespace, so `@file:notes.md,` looked up `notes.md,` and a path with a space could not be named at all; either way the token reached the agent unresolved. This follows the decision on plmbr/notebook-intelligence#503 to match Claude Code and Codex, and keeps nui's grammar in step with Chatbook's: - `@file:"data/my notes.md"` (also `dir:` and `ext:`) names a value containing whitespace or `@`. It is taken exactly as written, whitespace included, and cannot hold a quote or a line break; a closing quote glued to a word character keeps the old single token. - Sentence punctuation after an unquoted file or dir mention is not part of the path. The name as written is tried first, then with up to five of those characters removed one at a time, and the first name that exists wins, so a real name ending in punctuation still resolves and a shorter name is never reached past it. The trimmed punctuation is written back after the resolved path, so the sentence is unchanged. `ext:` values are never trimmed. - A resolved path containing whitespace is emitted as `@"/abs/path"`, the form Claude Code reads. - The mention menu inserts the quoted form when a value needs it. Tokens are found with a small rune scanner rather than a regexp, because RE2 has no lookaround and its `\s` is ASCII-only while Chatbook's is Unicode. A mention still has to follow whitespace, now checked by rune rather than by byte, which is also what Claude Code requires of the `@path` mentions nui hands it.
pjdoland
force-pushed
the
fix/mention-punctuation-quoting
branch
from
September 28, 2026 17:52
cd16ea3 to
8f38cf8
Compare
mbektas
approved these changes
Sep 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is the nui half of plmbr/notebook-intelligence#503, where we agreed to bring
@mentions in line with Claude Code and Codex and to update nui to match. The Chatbook side is plmbr/notebook-intelligence#505.Before this change, a mention ran to the next whitespace. So
Summarize @file:notes.md, then chart itlooked upnotes.md,, and a path with a space could not be named at all, even though the mention menu offers such paths. Either way the token reached the agent unresolved.What changes
@file:"data/my notes.md"(and@dir:"...",@ext:"...") names a value containing whitespace or@. The value is taken exactly as written, leading or trailing whitespace included, and cannot hold a double quote or a line break. A closing quote glued to a word character (@file:"a"b.csv) keeps the old single-token reading..,;:!?…, closing brackets and quotes, and their full-width forms. The name as written is tried first, then with up to five of those characters removed one at a time, and the first name that exists wins. A real name ending in punctuation (notes.) still resolves, and a shorter name is never reached past one that exists.foo.c++is never trimmed tofoo.c. Paths outside the working directory end the search. The trimmed punctuation is written back after the resolved path, so@file:notes.md,becomes@/abs/notes.md,and the sentence is unchanged.ext:values accept the quoted form but are never trimmed. Provider values are opaque, so trailing characters may belong to them.@"/abs/path", the form Claude Code reads. Other paths are unchanged (@/abs/path).useMentionMenuinserts the quoted form when a value needs it (ui/src/lib/mentionToken.ts).Tokens are found with a small rune scanner (
internal/mentions/tokens.go) rather than a regexp. RE2 has no lookaround, and its\sis ASCII-only, while Chatbook's Python tokenizer is Unicode-aware; the scanner matches Chatbook's behavior. A mention still has to follow whitespace, which is also what Claude Code requires of the@pathmentions nui hands it. That check is now done by rune rather than by byte, so a full-width space before@counts.Testing
internal/mentions/tokens_test.gocovers:@dir:data(2)).resolvesdata(2));foo.c++, an existingdata.folder, too much punctuation);@;"notes.md ");@rule;ext:values quoted but never trimmed.ui/src/lib/mentionToken.test.tscovers the quoting rules.go vet ./internal/mentions/andgo test . ./cmd/... ./internal/...(Go 1.27.1 locally). The UI passesnpm run lint,npm run buildandnpm test: 36 files, 229 tests.mainas well:TestOrchestratorDefinitionAPIHasNoCLIAllowlist. It expects theapi/anthropicharness, which is unavailable in a shell with noANTHROPIC_API_KEYand the Claude CLI installed.main's CI is green, so it only depends on the local environment.Not changed here
@/abs/path, so trimming punctuation from it would change nothing the agent sees.file:,dir:andext:. That was already the case; adding a bare@"..."form is worth a separate decision.