feat(core): support MIDSCENE_CUSTOM_SYSTEM_PROMPT env var for custom system prompt injection#2488
Open
will- wants to merge 3 commits into
Open
feat(core): support MIDSCENE_CUSTOM_SYSTEM_PROMPT env var for custom system prompt injection#2488will- wants to merge 3 commits into
will- wants to merge 3 commits into
Conversation
…system prompt injection Allow private/self-hosted models to receive model-specific system prompt instructions via the MIDSCENE_CUSTOM_SYSTEM_PROMPT environment variable. When set, the value is prepended to all system messages across all AI call paths (planning, locate, extract, assert). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mock the OpenAI client and verify that the custom system prompt is actually prepended to system messages in the API call payload, covering the full callAI → OpenAI path with multimodal and multi-intent scenarios. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…EM_PROMPT_EXTRA Rename the env var to better communicate its prepend behavior — "extra" makes it clear that this is additional content prepended to the existing system prompt, not a replacement. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MIDSCENE_CUSTOM_SYSTEM_PROMPTenvironment variable support that prepends a custom system prompt to all AI calls (planning, locate, extract, assert)callAI()entry point, covering all downstream paths including CodexAppServerMotivation
When using private or self-hosted models, some require specific system prompt instructions (e.g., role definitions, output format constraints) that differ from Midscene's built-in prompts. Currently there is no way to inject custom system-level instructions without modifying source code.
This change allows users to simply set an environment variable:
Changes
packages/shared/src/env/types.ts— DeclareMIDSCENE_CUSTOM_SYSTEM_PROMPTconstant and register inSTRING_ENV_KEYSpackages/core/src/ai-model/service-caller/index.ts— AddapplyCustomSystemPrompt()function and call it atcallAI()entry pointpackages/core/tests/unit-test/custom-system-prompt.test.ts— 8 unit tests for the pure functionpackages/core/tests/unit-test/custom-system-prompt-integration.test.ts— 4 integration tests mocking OpenAI client to verify end-to-end behaviorTest plan
pnpm run lint— passes (no new lint errors)vitest --run tests/unit-test/custom-system-prompt.test.ts— 8 passedvitest --run tests/unit-test/custom-system-prompt-integration.test.ts— 4 passed🤖 Generated with Claude Code