From 818689b2ee71cb6966cb4dc5a5ebd90fd22b0fcb Mon Sep 17 00:00:00 2001 From: Kevin Codex Date: Sun, 26 Apr 2026 12:45:09 +0800 Subject: [PATCH] fix(query): restore system prompt structure and add missing config import (#907) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- src/query.ts | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/query.ts b/src/query.ts index fe2e84e6..d3304ea5 100644 --- a/src/query.ts +++ b/src/query.ts @@ -99,6 +99,7 @@ import { applyToolResultBudget } from './utils/toolResultStorage.js' import { recordContentReplacement } from './utils/sessionStorage.js' import { handleStopHooks } from './query/stopHooks.js' import { buildQueryConfig } from './query/config.js' +import { getGlobalConfig } from './utils/config.js' import { productionDeps, type QueryDeps } from './query/deps.js' import type { Terminal, Continue } from './query/transitions.js' import { feature } from 'bun:bundle' @@ -476,14 +477,27 @@ async function* queryLoop( messagesForQuery = collapseResult.messages } - 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) + // arcSummary must be a separate array element; concatenating it into a + // template string makes [...systemPrompt] spread chars, shredding the prompt. + let promptWithArc: readonly string[] = systemPrompt + if (feature('CONVERSATION_ARC')) { + 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( - appendSystemContext(`${systemPrompt}\n\n${arcSummary}`, systemContext), + appendSystemContext(asSystemPrompt(promptWithArc), systemContext), ) queryCheckpoint('query_autocompact_start') @@ -1878,9 +1892,11 @@ async function* queryLoop( } queryCheckpoint('query_recursive_call') - - // Persist conversation progress to global project memory - if (getGlobalConfig().knowledgeGraphEnabled) { + + if ( + feature('CONVERSATION_ARC') && + getGlobalConfig().knowledgeGraphEnabled + ) { const { finalizeArcTurn } = await import('./utils/conversationArc.js') finalizeArcTurn() }