Skip to content

feat: @-Mentions — Dateien direkt im Prompt einbetten - #49

Merged
webmatze merged 1 commit into
mainfrom
feat/mentions
Aug 8, 2026
Merged

feat: @-Mentions — Dateien direkt im Prompt einbetten#49
webmatze merged 1 commit into
mainfrom
feat/mentions

Conversation

@webmatze

@webmatze webmatze commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Closes #27.

Was drin ist

@pfad bettet die Datei in den ersten Request ein — der read_file-Roundtrip entfällt. Der @pfad bleibt im Satz stehen, der Inhalt hängt darunter, im selben Format wie ein Skill-Anhang.

Form Wirkung
@src/agent.cr Inhalt wird angehängt
@src/tools/ nur Auflistung, nicht rekursiv
@"my notes.md" Pfade mit Leerzeichen
foo@bar.com nichts — @ zählt nur am Wortanfang

Zusätzlich: ~ wird expandiert, und Satzzeichen am Ende gehören nicht zum Pfad (@src/agent.cr. findet die Datei).

Schutz

Ein Prompt kommt nicht immer vom Nutzer — ein Skill-Body könnte sonst @~/.ssh/id_rsa einziehen:

  • Pfad-Ausbruch wird abgelehnt, außer allow_outside = true. Das Projektverzeichnis wird dabei genauso normalisiert wie die Kandidatenpfade — sonst sähe unter einem symlinkten Projekt (/tmp auf macOS) jede relative Mention wie ein Ausbruch aus. Das ist derselbe Fehler, der bei den Permission-Rules schon einmal aufgetreten ist.
  • Budgets: Dateien über max_lines werden gekürzt und markiert; ist max_total_bytes erschöpft, werden weitere Mentions vermerkt statt eingebettet.
  • Binärdateien werden an Nullbytes im ersten Kilobyte erkannt und nicht eingebettet.

Ein nicht existierender Pfad bleibt unverändert stehen, mit Warnung — kein Abbruch, der Nutzer meinte vielleicht ein echtes @.

Reihenfolge

Erst Skills, dann Mentions — so löst auch ein Skill-Body mit @-Referenzen auf. Genau eine Ebene: was eine Mention einzieht, wird nicht erneut gescannt, eine Datei kann sich also nicht über einen Skill selbst hereinholen. Ist als Spec festgehalten.

Konfiguration

[mentions]
max_lines       = 2000
max_total_bytes = 262144
allow_outside   = false

Sichtbarkeit

FilesMentioned-Event: 📎 src/smith/agent.cr (174 lines) im Human-Renderer, strukturiert unter --json.

Verifikation

  • 518 Specs grün, Format sauber, Build ok — macOS und Linux (Docker); 14 neue Specs in spec/smith/mentions_spec.cr
  • Live gegen claude-sonnet-5: @sample.txt wird ohne Tool-Call korrekt zitiert; foo@bar.com bleibt unberührt, @../../etc/passwd und @missing.cr werden mit Begründung übersprungen

🤖 Generated with Claude Code

Naming a file used to cost a full provider roundtrip: the model read the
name, called read_file, waited. @path puts the file in the first request
instead, and the model stops guessing at paths it was already given.

The @path stays in the sentence so it still reads; content is appended
below it in the same shape as a skill attachment. Directories are listed,
never walked — inlining a tree is how a prompt silently becomes a
megabyte.

@ only counts at the start of a word, which is what keeps foo@bar.com out
of it. Trailing sentence punctuation is not part of the path, so
"@src/agent.cr." finds the file.

Three guards, since a prompt does not always come from the user — a skill
body could otherwise pull in @~/.ssh/id_rsa:

  - a path leaving the project is refused unless allow_outside is set,
    with the project dir normalised the same way candidate paths are so a
    symlinked project does not make every relative mention look like an
    escape
  - files over max_lines are truncated and marked; once max_total_bytes
    is spent, further mentions are reported rather than embedded
  - binary files are detected by a null byte in the first kilobyte

A missing path stays in the text untouched with a warning rather than
failing the turn: the user may have meant a literal @.

Skills expand first, mentions second, so a skill body referencing @files
resolves too — exactly one level, since what a mention pulls in is never
scanned again.

Closes #27.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@webmatze
webmatze merged commit e50c039 into main Aug 8, 2026
2 checks passed
@webmatze
webmatze deleted the feat/mentions branch August 8, 2026 00:14
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.

@-Mentions: Dateien direkt im Prompt einbetten

1 participant