Repository navigation
fix(app): only attach comment @mentions that exist - #62242
Conversation
There was a problem hiding this comment.
Looks good. The bot's #50393 reproduction fails on dev (@here, @channel and @everyone are attached as file:///repo/<word>) and passes with this change. Path-like mentions (@src/shared.ts, @~/x, @foo#L3) are still attached. request.test.ts passes, and tsc -b in packages/app passes. I tested at the unit level; the change is in the app's prompt builder, so the TUI is unaffected.
Public API: unchanged. The files field of the prompt request just stops listing bare @words from comment text.
The same parser handles quote comments, so this also stops the 400 "Unable to read attachment" failure in #62197, where an unpicked @prototype blocked sending. As the description says, a root-level dotless file like Makefile or Dockerfile picked from the comment editor's @ menu is now inserted as @Makefile and no longer attached. If that matters later, the menu could insert @./Makefile for such paths.
Fixes #62197
There was a problem hiding this comment.
The new commit only merges dev; the fix itself is unchanged. I re-ran the #50393 reproduction: bare @here, @channel and @everyone are still attached as files on dev and are dropped with this branch, while path-like mentions are still attached. request.test.ts and tsc -b in packages/app pass. Public API: unchanged. Nothing new to raise.
There was a problem hiding this comment.
The existence check fixes the bare-@word case: an unpicked @here is no longer attached, and @Makefile attaches again, which addresses the trade-off I raised earlier. I checked it through the submitQuote path in submit.test.ts with an @here comment. request.test.ts, submit.test.ts and machine.test.ts pass, and tsc -b in packages/app passes. Public API: unchanged (existingMentions and commentMentions are internal to the app).
One regression, see the inline comment: directory mentions in comments are now always dropped, although dev attaches them and the server accepts them.
|
|
||
| await Promise.all( | ||
| [...new Set(mentions)].map(async (path) => { | ||
| const parent = /[\\/]/.test(path) ? getDirectory(path) : undefined |
There was a problem hiding this comment.
This drops directory mentions. The comment autocomplete offers folders (searchFilesAndDirectories), and the server accepts a directory file:// attachment (it sends the listing, see readAttachment in core/src/session/prompt.ts). On dev, @src/components/ in a comment is attached; here it is always treated as missing.
entry.type === "file"excludes directories.fs.listreturns directory entries with a trailing separator (src/components/), sogetFilenamedoesn't matchsrc/componentseither.- For
@src/,getDirectory("src/")is/, so this lists the filesystem root.
Checking against a mock file.list shaped like the server's output: src/api.ts and Makefile are found, while src/components/, src/components and src/ are not. Accepting directory entries and comparing paths with any trailing separator removed would keep folder mentions working.
There was a problem hiding this comment.
The new commit fixes the directory-mention problem I raised: @src/components/, @src/components and @src/ are attached again, and @src/ now checks the project root rather than the filesystem root. I checked this against a mock file.list shaped like the server's output; bare @here is still not attached. request.test.ts, submit.test.ts and machine.test.ts pass, and tsc -b in packages/app passes. Public API: unchanged. Nothing new to raise.
There was a problem hiding this comment.
The new commit only adds a blank line for lint; behaviour is unchanged. The folder-mention fix from the previous push still applies, and request.test.ts, submit.test.ts, machine.test.ts and tsc -b in packages/app pass. Public API: unchanged. Nothing new to raise.
There was a problem hiding this comment.
The new commit only touches tests and narrows the file.list result type; the existence check is unchanged. The updated quote test in submit.test.ts fails on dev (an extra file:///C:/repo/here attachment) and passes here. request.test.ts, submit.test.ts, machine.test.ts and tsc -b in packages/app pass. Public API: unchanged. Nothing new to raise.
Issue for this PR
Closes #50393
Type of change
What does this PR do?
The app attaches every
@wordin a line comment as a file. A comment likeCheck @here and @src/app.tsattaches a file calledhere. The server can't read it, so it rejects the whole prompt with a 400 and the send fails.Now the app checks which comment mentions exist before sending and only attaches those. It lists each mention's parent folder, the same check the files model uses. Mentions that don't exist stay as plain text in the comment.
#50526 and #52877 only attached mentions that looked like paths. This checks the file itself, so
@Makefileand folders like@src/still attach.How did you verify your code works?
Check @here, @Makefile and @src/app.ts please. Ondevthe send fails with a 400. With this PR it sends, attachingMakefileandsrc/app.tsand skippinghere.submit.test.tsnow includes@here. It fails without the fix.packages/appcomposer tests,bun typecheckandbun run checkpass.Visual
Checklist
Added by the opencode bot (AI-generated).
Fixes #62197