-
Notifications
You must be signed in to change notification settings - Fork 475
[yamllint-fixer] Trim trailing whitespace and cap blank runs in inlined prompt content #46123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c3f543e
33f19cf
75c338e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -457,6 +457,16 @@ func (c *Compiler) generateUnifiedPromptCreationStep(yaml *strings.Builder, buil | |
| // 2. Write user prompt chunks (appended after built-in sections). | ||
| // All chunks are written into the same heredoc block (opened above or here) | ||
| // to minimise the number of delimiter lines in the compiled lock file. | ||
| // | ||
| // The heredoc payload is a YAML block scalar, so normalizeBlankLines preserves | ||
| // it verbatim (it must, since arbitrary block scalars can carry semantically | ||
| // significant trailing whitespace and blank runs). Prompt content is markdown | ||
| // text the compiler owns, where trailing whitespace is never meaningful and | ||
| // long blank runs are noise, so it is cleaned here instead: trailing whitespace | ||
| // is trimmed from every line and consecutive blank lines are capped at | ||
| // maxConsecutiveBlankLines. userBlankRun is tracked across chunks so a run that | ||
| // straddles a chunk boundary is still collapsed. | ||
| userBlankRun := 0 | ||
| for chunkIdx, chunk := range userPromptChunks { | ||
| unifiedPromptLog.Printf("Writing user prompt chunk %d/%d", chunkIdx+1, len(userPromptChunks)) | ||
|
|
||
|
|
@@ -472,6 +482,7 @@ func (c *Compiler) generateUnifiedPromptCreationStep(yaml *strings.Builder, buil | |
| inHeredoc = true | ||
| } | ||
| yaml.WriteString(" " + chunk + "\n") | ||
| userBlankRun = 0 | ||
| continue | ||
| } | ||
|
|
||
|
|
@@ -483,8 +494,20 @@ func (c *Compiler) generateUnifiedPromptCreationStep(yaml *strings.Builder, buil | |
|
|
||
| lines := strings.SplitSeq(chunk, "\n") | ||
| for line := range lines { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No dedicated unit tests for the new trim-and-blank-run logic: regressions will only surface through golden-file diffs that are easy to misread. 💡 Suggested additionsAdd a test case to
The golden-file test only validates two specific trailing-space removals from the smoke fixture and does not cover any of these edge cases. A future refactor of the chunk loop could silently break the trimming logic or over-aggressively collapse blanks inside user prompts.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 75c338e — |
||
| trimmed := strings.TrimRight(line, " \t") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These prompts are consumed by LLMs as plaintext strings, not rendered as HTML/Markdown. In that consumption context, two trailing spaces have no semantic effect — the agent receives raw text and acts on it directly, not via a Markdown renderer. Trimming is therefore safe for all user-prompt content, including imported workflow Markdown. The PR description explicitly scopes this to prompt content (the heredoc payload of the |
||
| if trimmed == "" { | ||
| // Collapse over-long blank runs; emit truly empty lines (no | ||
| // indentation) so they carry no trailing whitespace. | ||
| if userBlankRun >= maxConsecutiveBlankLines { | ||
| continue | ||
| } | ||
| userBlankRun++ | ||
|
Comment on lines
+501
to
+504
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 75c338e —
|
||
| yaml.WriteByte('\n') | ||
| continue | ||
| } | ||
| userBlankRun = 0 | ||
| yaml.WriteString(" ") | ||
| yaml.WriteString(line) | ||
| yaml.WriteString(trimmed) | ||
| yaml.WriteByte('\n') | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/tdd] No test covers the new trimming and blank-line-capping behaviour — a future refactor could silently regress both properties.
💡 Suggested test skeleton
Without this, the behaviour is only validated indirectly by the golden fixture update.
@copilot please address this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 75c338e — see the four new tests in
pkg/workflow/unified_prompt_step_test.gocovering trailing-whitespace trimming, within-chunk blank-run capping, cross-chunk blank-run capping, and the runtime-import macro adjacency case.