Skip to content

fix: 🐛 Fix bare markdown fences and premature code generation stops #6331

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

chezsmithy
Copy link
Contributor

@chezsmithy chezsmithy commented Jun 27, 2025

Description

Claude 4 sonnet is very excited about creating project structure display in readme files. When this was attempted the markdown display was broken and the file output was truncated. This was due file structure being outputted with nested codeblocks without a type attached.

When I orginally implemented a fix to this code I noted that there might be some risky edge cases where the nested code blocks didn't have types. As such this PR should solve for that use case by implementing a look ahead feature to check upcoming code blocks to determine if nesting is starting or we are ending the outer code block nesting early.

Significant hardening has been done on all of the places where markdown is used. I've still noted a few issues in chat where markdown might be returned and fences are not balanced (for example an open fence is included indented, and the closing fence happens to be not indented or enclosed in quotes) that could be further improved in a new PR.

Further, I noted that Bedrock Lower cost nova models we want to use for edit and apply were causing problems with outputting markdown content that wasn't compatible with the current prompts and filtering logic. This has been solved for.

Checklist

  • I've read the contributing guide
  • The relevant docs, if any, have been updated or created
  • The relevant tests, if any, have been updated or created

Screenshots

[ For visual changes, include screenshots. Screen recordings are particularly helpful, and appreciated! ]

Tests

[ What tests were added or updated to ensure the changes work as expected? ]

I've added a new function for the look ahead checking, and added new tests for that. Then I added a specfic test for the nested structure output that was failing.

I've added extensive tests for all the changes included functions that have been modified. During manual testing, I have found additional edge cases where the generation was stopping pre-maturely and I've added tests to attempt to solve for those. My goal has been to allow using AI to manage the lineStream.ts, and lineStream.vitetest.ts themselves which has been a problem traditionally becuase they contained stop blocks and fences that broke code generation. I've validated that its now possible to refactor those files sucessfully.


Summary by cubic

Fixed an issue where project structure markdown with nested bare codeblocks would break display and truncate output.

  • Bug Fixes
    • Added logic to detect and handle nested bare codeblocks without a type.
    • Updated tests to cover these edge cases.

@chezsmithy chezsmithy requested a review from a team as a code owner June 27, 2025 23:04
@chezsmithy chezsmithy requested review from sestinj and removed request for a team June 27, 2025 23:04
Copy link

netlify bot commented Jun 27, 2025

👷 Deploy request for continuedev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 1364466

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 27, 2025
@sestinj
Copy link
Contributor

sestinj commented Jun 30, 2025

@chezsmithy There is a failing test, but I do like the PR. Will merge once tests are fixed

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 1, 2025
@chezsmithy chezsmithy marked this pull request as draft July 1, 2025 00:45
@chezsmithy
Copy link
Contributor Author

chezsmithy commented Jul 1, 2025

TODO Items:

  • Passing tests
  • Review all ``` and STOP checking to make sure it is looking only for leading backticks or STOP keywords and not catching examples inside of code strings. Thus tests won't generate using these keywords or truncation can occur.
  • Optimize lookahead function for ``` / STOP checking to not scan the whole remainder of the file if we can.

@chezsmithy chezsmithy force-pushed the fix-nested-bare-codeblocks branch from 179347d to be47720 Compare July 2, 2025 21:47
@chezsmithy chezsmithy marked this pull request as ready for review July 2, 2025 22:05
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jul 2, 2025
@chezsmithy
Copy link
Contributor Author

@sestinj feeling good about this now. I've added a tone of tests and split out the filterCodeBlockLines function so that it's easier to test in issolation as its such a critical component.

Copy link
Collaborator

@RomneyDa RomneyDa left a comment

Choose a reason for hiding this comment

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

This fix will be great!
See comments, I think there's some double-duplicate code.
If possible, let's move all the markdown-patching-related code to core utils, have it in one place, and import it into GUI

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Jul 3, 2025
@chezsmithy chezsmithy requested a review from RomneyDa July 4, 2025 21:14
@chezsmithy chezsmithy changed the title fix: 🐛 Project structure creation with bare codeblocks is breaking markdown display and creation fix: 🐛 Fix bare markdown fences and premature code generation stops Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants