Skip to content

Bug: Inconsistent code extraction (-w:code) during auto-continue sequences #22

@albatrosary

Description

@albatrosary

Problem Description

The -w:code flag is designed to extract raw source code by instructing the AI to omit Markdown fences (```). However, when a response is long enough to trigger the auto-continue mechanism, the extraction often fails in subsequent chunks.

Root Causes

  1. Instruction Loss: While the initial prompt contains the CODE_ONLY_SUFFIX, the subsequent "continue" prompts (generated by _make_continue_prompt) do not carry the same strict "no-fence" constraints. The AI often reverts to its default Markdown behavior for the second or third chunk.
  2. Markdown Triggering: The current "continue" prompt uses triple backticks to wrap the "tail" of the previous message for alignment. This inadvertently signals the AI to continue using Markdown formatting in its reply.

Proposed Solution

  1. Enhance CODE_ONLY_SUFFIX
    Update the suffix to explicitly define the scope as the "entire request," including all continuation chunks.

  2. Mode-Aware Continuation Prompts
    Update _make_continue_prompt to accept a mode argument. When mode="code", the function will inject strict formatting rules into every continuation request:

  • Force "Code Only" output.
  • Explicitly forbid Markdown fences (``` or ~~~).
  • Prevent any explanatory text or greetings in the middle of the code stream.
  1. Replace Context Delimiters
    Avoid using backticks to present the "tail" to the AI. Instead, use custom delimiters (e.g., <<<TAIL_START) to prevent the model from entering "Markdown mode."

Implementation Plan

  • Modify CODE_ONLY_SUFFIX constant.
  • Update _make_continue_prompt(tail, mode="raw") signature and logic.
  • Update all AIEngine.ask implementations to pass the current mode to the continuation helper.
  • Verify that multi-chunk code generation results in a single, seamless, fence-less file.

Expected Outcome

Files saved with -w:code will contain pure source code even if the generation requires multiple API rounds, eliminating the need for manual cleanup of Markdown tags in the middle of files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions