Skip to content

fix(integrations): cline hook note collapses onto instruction at EOF#3263

Merged
mnriem merged 1 commit into
github:mainfrom
jawwad-ali:fix/cline-hook-note-eol
Jun 30, 2026
Merged

fix(integrations): cline hook note collapses onto instruction at EOF#3263
mnriem merged 1 commit into
github:mainfrom
jawwad-ali:fix/cline-hook-note-eol

Conversation

@jawwad-ali

Copy link
Copy Markdown
Contributor

Description

ClineIntegration._inject_hook_command_note() inserts a dot-to-hyphen note before the hook-output instruction. Its regex matches the line terminator with an alternation that includes $:

r"(?m)^(\s*)(- For each executable hook, output the following[^\r\n]*)(\r\n|\n|$)"

When the instruction is the final line of a file with no trailing newline, the third group (eol) captures the empty string. The integration then emits:

eol = m.group(3)          # ""  on a trailing-newline-less last line
return indent + NOTE.rstrip("\n") + eol + indent + instruction + eol

so the note text and the instruction are concatenated onto a single line (e.g. ...replace dots with hyphens.- For each executable hook...).

The sibling agy integration already guards this exact case with eol = m.group(3) or "\n" and an explanatory comment — cline is the lone outlier.

Fix

Default eol to "\n" when empty, mirroring the agy twin verbatim (same one-line guard + comment).

Testing

  • New test_cline_hook_instruction_injection_no_trailing_newline: feeds the instruction with no trailing newline and asserts the instruction stays on its own line ("\n- For each executable hook..."). Fails before (note mashed onto the instruction), passes after.
  • uvx ruff check clean; the two cline hook-injection tests pass.

AI Disclosure

  • I did use AI assistance (describe below)

Found and fixed with Claude Code (Claude Opus 4.8) under my direction. AI spotted the agy-vs-cline parity gap; I confirmed the empty-eol collapse, verified the fail-before/pass-after test, and reviewed the diff before submitting.

The hook-note injection regex matches the line terminator via
(\r\n|\n|$), so the captured eol group is empty when the instruction
is the final line of a file with no trailing newline. The cline
integration emitted the note with that empty eol, mashing the note text
and the instruction onto a single line. Default eol to '\n', matching
the agy integration twin which already guards this case.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an edge case in the Cline integration’s hook-note injection where, if the hook instruction is the final line of a file with no trailing newline, the injected note text could collapse onto the instruction line. The change mirrors the existing behavior used in sibling integrations by defaulting the captured end-of-line to "\n" when the regex match occurs via $.

Changes:

  • Update ClineIntegration._inject_hook_command_note() to use eol = m.group(3) or "\n" so injected content never concatenates onto the instruction line at EOF.
  • Add a regression test covering injection when the input content has no trailing newline.
Show a summary per file
File Description
src/specify_cli/integrations/cline/__init__.py Defaults the matched EOL to "\n" when empty to prevent note/instruction line collapse at EOF.
tests/integrations/test_integration_cline.py Adds a regression test ensuring the instruction remains on its own line when the file has no trailing newline.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Low

@mnriem mnriem merged commit 2d56dfd into github:main Jun 30, 2026
12 checks passed
@mnriem

mnriem commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

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.

3 participants