Skip to content

Take the suggested name from the line after a lead-in, without its label [patch] - #242

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/237-skip-lead-in-line
Nov 4, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/237-skip-lead-in-line

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #237

What changed

SanitizeFileName kept the first non-empty line of the model's answer. When a chat-tuned model wrote a lead-in first, such as "Here is a suggested filename:", the lead-in was stored as the suggestion, and suggestions are never re-requested for a hash. A label on the same line as the name ("Filename: sunset-beach") stayed in the result too.

The line choice now lives in a new helper, Scan.SelectNameLine:

  • It skips a line ending in : when another content line follows. Emphasis around the colon counts, as in **Here is the filename:**. If the lead-in is the only line, it is still used.
  • On the chosen line, it strips a leading heading, bullet or numbered-list marker (# , - , * , 1. ).
  • It strips a leading label: prefix when text follows it. The label may be wrapped in */_. A label is only letters, spaces and apostrophes followed by whitespace, so a name like sunset-at-5:30pm is left alone.

The rest of the sanitizing (quotes, extension, portable characters, length cap, device names) is unchanged. I left the default prompt alone, because it already asks for "only the filename … without … explanation".

Tests

  • SanitizeFileNameSkipsALeadInAndStripsALabelOrMarkdownMarker covers every row of the issue's table, plus an emphasised lead-in, a lead-in followed by a fenced name, _Filename_:, - and 1. .
  • SanitizeFileNameKeepsANameThatOnlyLooksLikeALabelOrLeadIn covers sunset-at-5:30pm, a lone Filename:, and **sunset-beach**.
  • With Scan.cs reverted, 9 of the new cases fail. With the fix, the full suite passes: 158 passed, 1 skipped because it runs as root.

Note on #232

Open PR #232 (for #225) rewrites the lines right after the line-selection statement, so whichever PR lands second gets a small conflict in SanitizeFileName. To resolve it, take #232's version of the function and replace its opening string name = rawSuggestion.Split('\n')…FirstOrDefault(…) statement with string name = SelectNameLine(rawSuggestion);.


Generated by Claude Code

…bel [patch]

Chat-tuned models often answer "Here is a suggested filename:" and put the
name on the next line, or write "**Filename:** `sunset-beach`". The first
line was kept, so the lead-in or the label became the stored suggestion.
SanitizeFileName now skips a line ending in a colon when another line
follows, and strips a leading label and a heading, bullet or list marker.

Fixes #237

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW55AnQ5psSyMDKg84G
Resolve the SanitizeFileName conflict with #232 by keeping its formatting
and extension handling and taking the line from SelectNameLine. The #232
test row for "Suggested filename: **sunset-beach.png**" pinned the label
surviving, which #237 fixes, so it now expects sunset-beach.png.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW55AnQ5psSyMDKg84G
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit b10aa98 into main Nov 4, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/237-skip-lead-in-line branch November 4, 2026 02:01
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.

Suggested name becomes the model's intro sentence ("Here is a suggested filename.jpg") when the model writes a lead-in line before the name

2 participants