@@ -18,6 +18,7 @@ import { isModelModeAllowedForFlavor, isPermissionModeAllowedForFlavor } from '@
1818import { ModelModeSchema , PermissionModeSchema } from '@hapi/protocol/schemas' ;
1919import { formatMessageWithAttachments } from '@/utils/attachmentFormatter' ;
2020import { findClaudeThinkEffortFromArgs , type ClaudeThinkEffort , resolveClaudeModelSelection } from './modelMode' ;
21+ import { isPureContextModeEnabled } from '@/agent/utils/haqiAgentInstructions' ;
2122
2223export interface StartOptions {
2324 model ?: string
@@ -427,11 +428,15 @@ export async function runClaude(options: StartOptions = {}): Promise<void> {
427428 }
428429 const messagePermissionMode = currentPermissionMode ;
429430 const messageModel = currentModel ;
431+ const pureContextMode = isPureContextModeEnabled ( ) ;
430432 logger . debug ( `[loop] User message received with permission mode: ${ currentPermissionMode } , modelMode: ${ currentModelMode } , model: ${ currentModel ?? 'default' } ` ) ;
431433
432434 // Resolve custom system prompt - use message.meta.customSystemPrompt if provided, otherwise use current
433435 let messageCustomSystemPrompt = currentCustomSystemPrompt ;
434- if ( message . meta ?. hasOwnProperty ( 'customSystemPrompt' ) ) {
436+ if ( pureContextMode ) {
437+ messageCustomSystemPrompt = undefined ;
438+ currentCustomSystemPrompt = undefined ;
439+ } else if ( message . meta ?. hasOwnProperty ( 'customSystemPrompt' ) ) {
435440 messageCustomSystemPrompt = message . meta . customSystemPrompt || undefined ; // null becomes undefined
436441 currentCustomSystemPrompt = messageCustomSystemPrompt ;
437442 logger . debug ( `[loop] Custom system prompt updated from user message: ${ messageCustomSystemPrompt ? 'set' : 'reset to none' } ` ) ;
@@ -451,7 +456,10 @@ export async function runClaude(options: StartOptions = {}): Promise<void> {
451456
452457 // Resolve append system prompt - use message.meta.appendSystemPrompt if provided, otherwise use current
453458 let messageAppendSystemPrompt = currentAppendSystemPrompt ;
454- if ( message . meta ?. hasOwnProperty ( 'appendSystemPrompt' ) ) {
459+ if ( pureContextMode ) {
460+ messageAppendSystemPrompt = undefined ;
461+ currentAppendSystemPrompt = undefined ;
462+ } else if ( message . meta ?. hasOwnProperty ( 'appendSystemPrompt' ) ) {
455463 messageAppendSystemPrompt = message . meta . appendSystemPrompt || undefined ; // null becomes undefined
456464 currentAppendSystemPrompt = messageAppendSystemPrompt ;
457465 logger . debug ( `[loop] Append system prompt updated from user message: ${ messageAppendSystemPrompt ? 'set' : 'reset to none' } ` ) ;
@@ -632,13 +640,14 @@ export async function runClaude(options: StartOptions = {}): Promise<void> {
632640 try {
633641 const parsed = resolveEnqueuePayload ( payload ) ;
634642 const formattedText = formatMessageWithAttachments ( parsed . text , parsed . attachments ) ;
643+ const pureContextMode = isPureContextModeEnabled ( ) ;
635644 const enhancedMode : EnhancedMode = {
636645 permissionMode : currentPermissionMode ?? 'default' ,
637646 model : currentModel ,
638647 thinkEffort : currentThinkEffort ,
639648 fallbackModel : currentFallbackModel ,
640- customSystemPrompt : currentCustomSystemPrompt ,
641- appendSystemPrompt : currentAppendSystemPrompt ,
649+ customSystemPrompt : pureContextMode ? undefined : currentCustomSystemPrompt ,
650+ appendSystemPrompt : pureContextMode ? undefined : currentAppendSystemPrompt ,
642651 allowedTools : currentAllowedTools ,
643652 disallowedTools : currentDisallowedTools ,
644653 routeContext : parsed . routeContext
@@ -727,12 +736,13 @@ export async function runClaude(options: StartOptions = {}): Promise<void> {
727736 try {
728737 const parsed = resolveEnqueuePayload ( payload ) ;
729738 const formattedText = formatMessageWithAttachments ( parsed . text , parsed . attachments ) ;
739+ const pureContextMode = isPureContextModeEnabled ( ) ;
730740 const enhancedMode : EnhancedMode = {
731741 permissionMode : currentPermissionMode ?? 'default' ,
732742 model : currentModelMode === 'default' ? undefined : currentModelMode ,
733743 fallbackModel : currentFallbackModel ,
734- customSystemPrompt : currentCustomSystemPrompt ,
735- appendSystemPrompt : currentAppendSystemPrompt ,
744+ customSystemPrompt : pureContextMode ? undefined : currentCustomSystemPrompt ,
745+ appendSystemPrompt : pureContextMode ? undefined : currentAppendSystemPrompt ,
736746 allowedTools : currentAllowedTools ,
737747 disallowedTools : currentDisallowedTools ,
738748 routeContext : parsed . routeContext
0 commit comments