fix(query): restore system prompt structure and add missing config import (#907)

- import getGlobalConfig — six call sites referenced it without an import;
  five short-circuited via feature() gates, but src/query.ts:1896 always
  ran and crashed every queryLoop iteration with "getGlobalConfig is not
  defined" (e.g. Explore subagent: "Agent failed: getGlobalConfig is not
  defined").
- stop coercing SystemPrompt (string[]) into a template-string before
  appendSystemContext — that made [...systemPrompt] spread the string
  character-by-character, replacing the structured prompt with thousands
  of one-char system blocks. Append arcSummary as its own array element
  instead.
- gate the finalizeArcTurn call behind feature('CONVERSATION_ARC') so it
  matches the rest of the memory-PR call sites and gets dead-code-
  eliminated for users without the flag.

Co-authored-by: OpenClaude <openclaude@gitlawb.com>
This commit is contained in:
Kevin Codex
2026-04-26 12:45:09 +08:00
committed by GitHub
parent d9ae56bc58
commit 818689b2ee

View File

@@ -99,6 +99,7 @@ import { applyToolResultBudget } from './utils/toolResultStorage.js'
import { recordContentReplacement } from './utils/sessionStorage.js' import { recordContentReplacement } from './utils/sessionStorage.js'
import { handleStopHooks } from './query/stopHooks.js' import { handleStopHooks } from './query/stopHooks.js'
import { buildQueryConfig } from './query/config.js' import { buildQueryConfig } from './query/config.js'
import { getGlobalConfig } from './utils/config.js'
import { productionDeps, type QueryDeps } from './query/deps.js' import { productionDeps, type QueryDeps } from './query/deps.js'
import type { Terminal, Continue } from './query/transitions.js' import type { Terminal, Continue } from './query/transitions.js'
import { feature } from 'bun:bundle' import { feature } from 'bun:bundle'
@@ -476,14 +477,27 @@ async function* queryLoop(
messagesForQuery = collapseResult.messages messagesForQuery = collapseResult.messages
} }
const lastMessage = messagesForQuery[messagesForQuery.length - 1] // arcSummary must be a separate array element; concatenating it into a
const userQueryText = lastMessage?.type === 'user' ? (typeof lastMessage.message.content === 'string' ? lastMessage.message.content : '') : '' // template string makes [...systemPrompt] spread chars, shredding the prompt.
let promptWithArc: readonly string[] = systemPrompt
const { getArcSummary } = await import('./utils/conversationArc.js') if (feature('CONVERSATION_ARC')) {
const arcSummary = getArcSummary(userQueryText) if (getGlobalConfig().knowledgeGraphEnabled) {
const lastMessage = messagesForQuery[messagesForQuery.length - 1]
const userQueryText =
lastMessage?.type === 'user' &&
typeof lastMessage.message.content === 'string'
? lastMessage.message.content
: ''
const { getArcSummary } = await import('./utils/conversationArc.js')
const arcSummary = getArcSummary(userQueryText)
if (arcSummary) {
promptWithArc = [...systemPrompt, arcSummary]
}
}
}
const fullSystemPrompt = asSystemPrompt( const fullSystemPrompt = asSystemPrompt(
appendSystemContext(`${systemPrompt}\n\n${arcSummary}`, systemContext), appendSystemContext(asSystemPrompt(promptWithArc), systemContext),
) )
queryCheckpoint('query_autocompact_start') queryCheckpoint('query_autocompact_start')
@@ -1878,9 +1892,11 @@ async function* queryLoop(
} }
queryCheckpoint('query_recursive_call') queryCheckpoint('query_recursive_call')
// Persist conversation progress to global project memory if (
if (getGlobalConfig().knowledgeGraphEnabled) { feature('CONVERSATION_ARC') &&
getGlobalConfig().knowledgeGraphEnabled
) {
const { finalizeArcTurn } = await import('./utils/conversationArc.js') const { finalizeArcTurn } = await import('./utils/conversationArc.js')
finalizeArcTurn() finalizeArcTurn()
} }