Skip to content

fix: merge adaptive guidance into existing system prompt - #21

Open
zoomdbz wants to merge 1 commit into
ian-pascoe:mainfrom
zoomdbz:fix/single-system-message
Open

fix: merge adaptive guidance into existing system prompt#21
zoomdbz wants to merge 1 commit into
ian-pascoe:mainfrom
zoomdbz:fix/single-system-message

Conversation

@zoomdbz

@zoomdbz zoomdbz commented Aug 31, 2026

Copy link
Copy Markdown

Summary

Some strict chat templates require the system prompt to appear only at the very beginning of the conversation. The plugin's experimental.chat.system.transform hook appended its adaptive-thinking guidance with system.push(...), which adds a second system message. Against those templates that fails to render before inference even starts. For example, a local llama.cpp provider raises Jinja Exception: System message must be at the beginning.

Fix

Merge the adaptive-thinking guidance into the existing first system entry rather than pushing a new one. When no system prompt exists yet, the guidance is still injected on its own, so behavior is unchanged for templates that allow it.

const existingSystemPrompt = system[0];
if (existingSystemPrompt === undefined) {
  system.push(adaptivePrompt);
} else {
  system[0] = `${existingSystemPrompt}\n\n${adaptivePrompt}`;
}

This is provider- and model-agnostic: it is compatibility with strict chat templates in general, not a workaround for one model.

Automatic reasoning-effort switching (set_reasoning_effort, temporary vs persistent variants, session.idle reset, current-variant reporting) is unchanged.

Tests

Added coverage in src/index.test.ts (19 passing):

  • existing system prompt: guidance appended to the first entry, exactly one entry remains, original content preserved, guidance present
  • empty system prompt: guidance injected, exactly one entry
  • current effort, valid variants, and configured tool name still included

Validation

pnpm format:check, pnpm lint, pnpm typecheck, pnpm test (19/19), pnpm build all pass.

The experimental.chat.system.transform hook appended its guidance with
system.push(...), creating a second system message. Strict chat templates
require exactly one system message at the start of the conversation and fail
to render otherwise (e.g. llama.cpp: "System message must be at the
beginning."), breaking template rendering before inference starts.

Merge the guidance into the first existing system prompt instead, and only
inject a standalone entry when no system prompt exists yet. Automatic
reasoning-effort switching via set_reasoning_effort is unchanged.
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.

1 participant