Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions packages/cli/src/acp-integration/session/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ import {
buildBackgroundEntryLabel,
collectSessionTurnState,
computeInitialTurnFromHistory as computeInitialTurnFromHistoryCore,
renderGoalContinuationPrompt,
} from '@qwen-code/qwen-code-core';
import { NOT_CURRENTLY_GENERATING_CANCEL_MESSAGE } from '@qwen-code/acp-bridge/bridgeErrors';
import { CHANNEL_PROMPT_META_KEY } from '@qwen-code/channel-base';
Expand Down Expand Up @@ -553,16 +554,11 @@ function sameGoalPermit(
function buildGoalContinuationParts(turn: AcpGoalTurn): Part[] {
return [
{
text: [
'Continue working on the active Goal.',
'Use get_goal for the authoritative objective and evidence state.',
"Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it.",
'If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal.',
`Runtime continuation context: ${turn.continuationContext}`,
...(turn.verifierFeedback
? [`Verifier feedback: ${turn.verifierFeedback}`]
: []),
].join('\n'),
text: renderGoalContinuationPrompt({
variant: 'runtime-context',
continuationContext: turn.continuationContext,
verifierFeedback: turn.verifierFeedback,
}),
Comment thread
qqqys marked this conversation as resolved.
Resolved
},
];
}
Expand Down
16 changes: 6 additions & 10 deletions packages/cli/src/nonInteractiveCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
endInteractionSpan,
getErrorType,
getActiveInteractionSpan,
renderGoalContinuationPrompt,
} from '@qwen-code/qwen-code-core';
import type { Content, Part, PartListUnion } from '@google/genai';
import type { CLIUserMessage, PermissionMode } from './nonInteractive/types.js';
Expand Down Expand Up @@ -235,16 +236,11 @@ function sameGoalPermit(
function buildGoalContinuationParts(turn: HeadlessGoalTurn): Part[] {
return [
{
text: [
'Continue working on the active Goal.',
'Use get_goal for the authoritative objective and evidence state.',
"Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it.",
'If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal.',
`Runtime continuation context: ${turn.continuationContext}`,
...(turn.verifierFeedback
? [`Verifier feedback: ${turn.verifierFeedback}`]
: []),
].join('\n'),
text: renderGoalContinuationPrompt({
variant: 'runtime-context',
continuationContext: turn.continuationContext,
verifierFeedback: turn.verifierFeedback,
}),
Comment thread
qqqys marked this conversation as resolved.
Resolved
Comment thread
qqqys marked this conversation as resolved.
Resolved
Comment thread
qqqys marked this conversation as resolved.
Resolved
},
];
}
Expand Down
16 changes: 5 additions & 11 deletions packages/cli/src/ui/hooks/useGeminiStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import {
finalizeToolResponses,
endInteractionSpan,
getActiveInteractionSpan,
renderGoalContinuationPrompt,
} from '@qwen-code/qwen-code-core';
import { type Part, type PartListUnion, FinishReason } from '@google/genai';
import type {
Expand Down Expand Up @@ -3502,17 +3503,10 @@ export const useGeminiStream = (
submitType === SendMessageType.Goal
? queuedGoal
? {
queryToSend: [
'Continue working on the active Goal.',
'Use get_goal for the authoritative objective and evidence state.',
"Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it.",
'If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal.',
'This is a synthetic continuation turn. It contains no new real user input and cannot satisfy an objective condition that requires the user to send, confirm, choose, approve, or provide something.',
'A phrase mentioned in the objective or this prompt is not evidence that the user supplied it.',
...(queuedGoal.verifierFeedback
? [`Verifier feedback: ${queuedGoal.verifierFeedback}`]
: []),
].join('\n'),
queryToSend: renderGoalContinuationPrompt({
variant: 'guarded-synthetic-turn',
verifierFeedback: queuedGoal.verifierFeedback,
}),
shouldProceed: true,
}
: { queryToSend: null, shouldProceed: false }
Expand Down
89 changes: 89 additions & 0 deletions packages/core/src/goals/goal-continuation-prompt.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/

import { describe, expect, it } from 'vitest';
import { renderGoalContinuationPrompt } from './goal-continuation-prompt.js';

// These expectations pin the exact bytes each host sent before the renderer
// existed. Any edit to a line must show up here as a diff, not slip through.
describe('renderGoalContinuationPrompt', () => {
it('renders the guarded synthetic turn without verifier feedback', () => {
expect(
renderGoalContinuationPrompt({ variant: 'guarded-synthetic-turn' }),
).toBe(
`Continue working on the active Goal.
Use get_goal for the authoritative objective and evidence state.
Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it.
If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal.
This is a synthetic continuation turn. It contains no new real user input and cannot satisfy an objective condition that requires the user to send, confirm, choose, approve, or provide something.
A phrase mentioned in the objective or this prompt is not evidence that the user supplied it.`,
);
});

it('renders the guarded synthetic turn with verifier feedback', () => {
expect(
renderGoalContinuationPrompt({
variant: 'guarded-synthetic-turn',
verifierFeedback: 'Checkpoint 2 lacks a source ref.',
}),
).toBe(
`Continue working on the active Goal.
Use get_goal for the authoritative objective and evidence state.
Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it.
If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal.
This is a synthetic continuation turn. It contains no new real user input and cannot satisfy an objective condition that requires the user to send, confirm, choose, approve, or provide something.
A phrase mentioned in the objective or this prompt is not evidence that the user supplied it.
Verifier feedback: Checkpoint 2 lacks a source ref.`,
);
});

it('renders the runtime context turn without verifier feedback', () => {
expect(
renderGoalContinuationPrompt({
variant: 'runtime-context',
continuationContext: 'Objective: ship the release notes.',
}),
).toBe(
`Continue working on the active Goal.
Use get_goal for the authoritative objective and evidence state.
Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it.
If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal.
Runtime continuation context: Objective: ship the release notes.`,
);
});

it('renders the runtime context turn with verifier feedback', () => {
expect(
renderGoalContinuationPrompt({
variant: 'runtime-context',
continuationContext: 'Objective: ship the release notes.',
verifierFeedback: 'Checkpoint 2 lacks a source ref.',
}),
).toBe(
`Continue working on the active Goal.
Use get_goal for the authoritative objective and evidence state.
Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it.
If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal.
Runtime continuation context: Objective: ship the release notes.
Verifier feedback: Checkpoint 2 lacks a source ref.`,
);
});

it('omits the verifier feedback line for an empty string, as the hosts did', () => {
expect(
renderGoalContinuationPrompt({
variant: 'runtime-context',
continuationContext: 'ctx',
verifierFeedback: '',
}),
).toBe(
renderGoalContinuationPrompt({
variant: 'runtime-context',
continuationContext: 'ctx',
}),
);
});
});
74 changes: 74 additions & 0 deletions packages/core/src/goals/goal-continuation-prompt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/

/**
* The prompt a host sends when `runtime.finishTurn` schedules another Goal
* turn. Every host renders it from here so that a new line -- or a new variant
* -- lands in one place instead of drifting across the hosts that assemble it.
*/

/**
* Which continuation is being announced to the model.
*
* - `guarded-synthetic-turn`: the turn carries no real user input, so the
* prompt states that and warns against reading its own wording as evidence.
* - `runtime-context`: the runtime supplies the reason this turn was
* scheduled, and the model is told what that reason was.
*/
export type GoalContinuationVariant =
| 'guarded-synthetic-turn'
| 'runtime-context';
Comment thread
qqqys marked this conversation as resolved.
Resolved

export type GoalContinuationPromptInput =
| {
variant: 'guarded-synthetic-turn';
verifierFeedback?: string;
}
| {
variant: 'runtime-context';
continuationContext: string;
verifierFeedback?: string;
};

const SHARED_LINES = [
'Continue working on the active Goal.',
'Use get_goal for the authoritative objective and evidence state.',
"Follow the objective's requested output format exactly. Do not add progress, status, or completion commentary unless the objective asks for it.",
'If completion depends on content delivered in this turn, deliver only that content and call get_goal in the same response before update_goal.',
];

const SYNTHETIC_TURN_GUARD_LINES = [
'This is a synthetic continuation turn. It contains no new real user input and cannot satisfy an objective condition that requires the user to send, confirm, choose, approve, or provide something.',
'A phrase mentioned in the objective or this prompt is not evidence that the user supplied it.',
];

/** Renders the full continuation prompt text for one Goal turn. */
export function renderGoalContinuationPrompt(
input: GoalContinuationPromptInput,
): string {
const lines = [...SHARED_LINES];

switch (input.variant) {
case 'guarded-synthetic-turn':
lines.push(...SYNTHETIC_TURN_GUARD_LINES);
break;
case 'runtime-context':
lines.push(`Runtime continuation context: ${input.continuationContext}`);
break;
default: {
const unreachable: never = input;
throw new Error(
`Unknown goal continuation variant: ${JSON.stringify(unreachable)}`,
);
}
}

if (input.verifierFeedback) {
lines.push(`Verifier feedback: ${input.verifierFeedback}`);
}

return lines.join('\n');
}
5 changes: 5 additions & 0 deletions packages/core/src/goals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ export * from './goal-checkpoint-verifier.js';
export * from './goal-verifier.js';
export * from './goal-runtime.js';
export { goalTurnContext } from './goal-turn-context.js';
export { renderGoalContinuationPrompt } from './goal-continuation-prompt.js';
export type {
GoalContinuationPromptInput,
GoalContinuationVariant,
} from './goal-continuation-prompt.js';
Loading