@@ -37,6 +37,7 @@ import {
3737 type OrchestrationV2ProviderThread,
3838 OrchestrationV2UserInputQuestion,
3939 ProjectId,
40+ type PromptSuggestion,
4041 ProviderInstanceId,
4142 type ProviderInstanceEnvironment,
4243 ProviderDriverKind,
@@ -110,6 +111,9 @@ const decodeUserInputQuestions = Schema.decodeUnknownSync(
110111);
111112
112113const DEFAULT_CLAUDE_SETTINGS = Schema.decodeSync(ClaudeSettings)({});
114+ const PROMPT_SUGGESTIONS_CLAUDE_SETTINGS = Schema.decodeSync(ClaudeSettings)({
115+ promptSuggestions: true,
116+ });
113117const AUTO_COMPACT_CLAUDE_SETTINGS = Schema.decodeSync(ClaudeSettings)({
114118 autoCompactWindow: "300000",
115119});
@@ -310,6 +314,20 @@ describe("ClaudeAdapterV2 runtime query policy", () => {
310314 assert.deepEqual(options.supportedDialogKinds, ["resume_return"]);
311315 });
312316
317+ it("asks the SDK for prompt suggestions only when the setting is on", () => {
318+ const optionsFor = (settings: ClaudeSettings) =>
319+ ClaudeAdapterV2.makeClaudeQueryOptions({
320+ modelSelection: CLAUDE_TEST_MODEL_SELECTION,
321+ nativeThreadId: "native-thread-prompt-suggestions",
322+ resume: false,
323+ cwd: "/workspace",
324+ settings,
325+ });
326+
327+ assert.isUndefined(optionsFor(DEFAULT_CLAUDE_SETTINGS).promptSuggestions);
328+ assert.isTrue(optionsFor(PROMPT_SUGGESTIONS_CLAUDE_SETTINGS).promptSuggestions);
329+ });
330+
313331 it("projects AskUserQuestion input with question text as the answer key", () => {
314332 assert.deepEqual(
315333 ClaudeAdapterV2.claudeUserInputQuestions({
@@ -2512,6 +2530,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
25122530 readonly nativeSessionId?: string;
25132531 readonly settings?: ClaudeSettings;
25142532 readonly freshQueueOnReopen?: boolean;
2533+ readonly promptSuggestions?: ClaudeAdapterV2.ClaudeAdapterV2Options["promptSuggestions"];
25152534 }) =>
25162535 Effect.gen(function* () {
25172536 const fileSystem = yield* FileSystem.FileSystem;
@@ -2575,6 +2594,9 @@ describe("ClaudeAdapterV2 background wake turns", () => {
25752594 continuationRequests.push(request);
25762595 }).pipe(Effect.andThen(Queue.offer(continuationReceipts, request))),
25772596 },
2597+ ...(options?.promptSuggestions === undefined
2598+ ? {}
2599+ : { promptSuggestions: options.promptSuggestions }),
25782600 queryRunner: {
25792601 allocateSessionId: Effect.succeed(options?.nativeSessionId ?? WAKE_NATIVE_SESSION),
25802602 open: (input) =>
@@ -3669,6 +3691,177 @@ describe("ClaudeAdapterV2 background wake turns", () => {
36693691 ),
36703692 );
36713693
3694+ const promptSuggestionFrame = claudeSdkFrame({
3695+ type: "prompt_suggestion",
3696+ suggestion: " Add a regression test for the sidebar. ",
3697+ uuid: "00000000-0000-4000-8000-000000000701",
3698+ session_id: WAKE_NATIVE_SESSION,
3699+ });
3700+
3701+ const makePromptSuggestionHarness = Effect.gen(function* () {
3702+ const published: Array<readonly [ThreadId, PromptSuggestion | null]> = [];
3703+ const harness = yield* makeWakeHarnessWithOptions({
3704+ close: (sdkMessages) => Queue.shutdown(sdkMessages),
3705+ promptSuggestions: {
3706+ publish: (threadId, suggestion) =>
3707+ Effect.sync(() => {
3708+ published.push([threadId, suggestion]);
3709+ }),
3710+ },
3711+ });
3712+ const now = yield* DateTime.now;
3713+ const startTurn = Effect.fnUntraced(function* (
3714+ ordinal: number,
3715+ threadId: ThreadId = harness.threadId,
3716+ ) {
3717+ const input = makeClaudeTestTurnInput({
3718+ threadId,
3719+ providerThread: harness.providerThread,
3720+ now,
3721+ attemptId: RunAttemptId.make(`attempt-claude-suggestion-${ordinal}`),
3722+ providerTurnOrdinal: ordinal,
3723+ text: "Fix the sidebar.",
3724+ attachments: [],
3725+ });
3726+ yield* harness.runtime.startTurn(input);
3727+ return input;
3728+ });
3729+ const completeTurn = Effect.fnUntraced(function* (
3730+ ordinal: number,
3731+ threadId: ThreadId = harness.threadId,
3732+ ) {
3733+ const input = yield* startTurn(ordinal, threadId);
3734+ yield* Queue.offer(
3735+ harness.sdkMessages,
3736+ makeResultFrame({
3737+ uuid: `00000000-0000-4000-8000-00000000070${ordinal + 1}`,
3738+ result: "Done.",
3739+ }),
3740+ );
3741+ yield* Queue.take(harness.terminalReceipts);
3742+ return input;
3743+ });
3744+ const publishedSuggestions = () => published.filter(([, suggestion]) => suggestion !== null);
3745+ return { harness, published, publishedSuggestions, startTurn, completeTurn };
3746+ });
3747+
3748+ it.effect("publishes Claude's suggestion after a completed turn until the next turn starts", () =>
3749+ Effect.gen(function* () {
3750+ const { harness, published, completeTurn } = yield* makePromptSuggestionHarness;
3751+ const first = yield* completeTurn(1);
3752+ yield* harness.offerAndWait(promptSuggestionFrame);
3753+ assert.deepEqual(published.at(-1), [
3754+ harness.threadId,
3755+ {
3756+ id: "00000000-0000-4000-8000-000000000701",
3757+ runId: first.runId,
3758+ text: "Add a regression test for the sidebar.",
3759+ },
3760+ ]);
3761+ yield* completeTurn(2);
3762+ assert.deepEqual(published.at(-1), [harness.threadId, null]);
3763+ }).pipe(
3764+ Effect.provide(
3765+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
3766+ ),
3767+ ),
3768+ );
3769+
3770+ it.effect("drops a suggestion that arrives once the next turn has started", () =>
3771+ Effect.gen(function* () {
3772+ const { harness, publishedSuggestions, startTurn, completeTurn } =
3773+ yield* makePromptSuggestionHarness;
3774+ yield* completeTurn(1);
3775+ yield* startTurn(2);
3776+ yield* harness.offerAndWait(promptSuggestionFrame);
3777+ assert.lengthOf(publishedSuggestions(), 0);
3778+ }).pipe(
3779+ Effect.provide(
3780+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
3781+ ),
3782+ ),
3783+ );
3784+
3785+ it.effect("clears a suggestion for another app thread of the session on rollback", () =>
3786+ Effect.gen(function* () {
3787+ const { harness, published, completeTurn } = yield* makePromptSuggestionHarness;
3788+ const otherThreadId = ThreadId.make("thread-claude-suggestion-other");
3789+ yield* completeTurn(1, otherThreadId);
3790+ yield* harness.offerAndWait(promptSuggestionFrame);
3791+ assert.equal(published.at(-1)?.[0], otherThreadId);
3792+ yield* harness.runtime.rollbackThread({
3793+ providerThread: harness.providerThread,
3794+ providerThreadTurns: [],
3795+ target: {
3796+ type: "thread_start",
3797+ checkpointId: CheckpointId.make("checkpoint-claude-suggestion-other-rollback"),
3798+ appRunOrdinal: 0,
3799+ },
3800+ });
3801+ assert.deepEqual(published.at(-1), [otherThreadId, null]);
3802+ }).pipe(
3803+ Effect.provide(
3804+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
3805+ ),
3806+ ),
3807+ );
3808+
3809+ it.effect("clears the suggestion when the thread rolls back", () =>
3810+ Effect.gen(function* () {
3811+ const { harness, published, publishedSuggestions, completeTurn } =
3812+ yield* makePromptSuggestionHarness;
3813+ yield* completeTurn(1);
3814+ yield* harness.offerAndWait(promptSuggestionFrame);
3815+ assert.lengthOf(publishedSuggestions(), 1);
3816+ yield* harness.runtime.rollbackThread({
3817+ providerThread: harness.providerThread,
3818+ providerThreadTurns: [],
3819+ target: {
3820+ type: "thread_start",
3821+ checkpointId: CheckpointId.make("checkpoint-claude-suggestion-rollback"),
3822+ appRunOrdinal: 0,
3823+ },
3824+ });
3825+ assert.deepEqual(published.at(-1), [harness.threadId, null]);
3826+ }).pipe(
3827+ Effect.provide(
3828+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
3829+ ),
3830+ ),
3831+ );
3832+
3833+ it.effect("clears the suggestion when a background wake starts and offers none after it", () =>
3834+ Effect.gen(function* () {
3835+ const { harness, published, publishedSuggestions, completeTurn } =
3836+ yield* makePromptSuggestionHarness;
3837+ yield* completeTurn(1);
3838+ yield* harness.offerAndWait(promptSuggestionFrame);
3839+ assert.lengthOf(publishedSuggestions(), 1);
3840+ yield* harness.offerAndWait(wakeTurnInit);
3841+ assert.deepEqual(published.at(-1), [harness.threadId, null]);
3842+ yield* harness.offerAndWait(
3843+ makeAssistantTextFrame({
3844+ uuid: "00000000-0000-4000-8000-000000000711",
3845+ text: "The background task finished.",
3846+ }),
3847+ );
3848+ assert.deepEqual(published.at(-1), [harness.threadId, null]);
3849+ yield* harness.offerAndWait(
3850+ claudeSdkFrame({
3851+ type: "prompt_suggestion",
3852+ suggestion: "Check the test results.",
3853+ uuid: "00000000-0000-4000-8000-000000000712",
3854+ session_id: WAKE_NATIVE_SESSION,
3855+ }),
3856+ );
3857+ assert.lengthOf(publishedSuggestions(), 1);
3858+ }).pipe(
3859+ Effect.provide(
3860+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
3861+ ),
3862+ ),
3863+ );
3864+
36723865 it.effect("keeps usage warnings and provisioned overage silent", () =>
36733866 Effect.gen(function* () {
36743867 const harness = yield* makeWakeHarness;
0 commit comments