@@ -42,6 +42,7 @@ import {
4242 type OrchestrationV2PendingBackgroundTask,
4343 OrchestrationV2ProviderThread,
4444 ProjectId,
45+ type PromptSuggestion,
4546 ProviderInstanceId,
4647 type ResolvedProviderInstanceEnvironment,
4748 ProviderDriverKind,
@@ -124,6 +125,9 @@ beforeEach(() => {
124125});
125126
126127const DEFAULT_CLAUDE_SETTINGS = Schema.decodeSync(ClaudeSettings)({});
128+ const PROMPT_SUGGESTIONS_CLAUDE_SETTINGS = Schema.decodeSync(ClaudeSettings)({
129+ promptSuggestions: true,
130+ });
127131const AUTO_COMPACT_CLAUDE_SETTINGS = Schema.decodeSync(ClaudeSettings)({
128132 autoCompactWindow: "300000",
129133});
@@ -349,6 +353,20 @@ describe("ClaudeAdapterV2 runtime query policy", () => {
349353 });
350354 });
351355
356+ it("asks the SDK for prompt suggestions only when the setting is on", () => {
357+ const optionsFor = (settings: ClaudeSettings) =>
358+ ClaudeAdapterV2.makeClaudeQueryOptions({
359+ modelSelection: CLAUDE_TEST_MODEL_SELECTION,
360+ nativeThreadId: "native-thread-prompt-suggestions",
361+ resume: false,
362+ cwd: "/workspace",
363+ settings,
364+ });
365+
366+ assert.isUndefined(optionsFor(DEFAULT_CLAUDE_SETTINGS).promptSuggestions);
367+ assert.isTrue(optionsFor(PROMPT_SUGGESTIONS_CLAUDE_SETTINGS).promptSuggestions);
368+ });
369+
352370 it("projects AskUserQuestion input with question text as the answer key", () => {
353371 const preview = "\n **Proposed change**\n\n```ts\n\tconst enabled = true;\n```\n ";
354372 assert.deepEqual(
@@ -3100,6 +3118,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
31003118 readonly freshQueueOnReopen?: boolean;
31013119 readonly forkSession?: ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerShape["forkSession"];
31023120 readonly allocateSessionId?: Effect.Effect<string>;
3121+ readonly promptSuggestions?: ClaudeAdapterV2.ClaudeAdapterV2Options["promptSuggestions"];
31033122 }) =>
31043123 Effect.gen(function* () {
31053124 const fileSystem = yield* FileSystem.FileSystem;
@@ -3171,6 +3190,9 @@ describe("ClaudeAdapterV2 background wake turns", () => {
31713190 Effect.andThen(changes.notify),
31723191 ),
31733192 },
3193+ ...(options?.promptSuggestions === undefined
3194+ ? {}
3195+ : { promptSuggestions: options.promptSuggestions }),
31743196 queryRunner: {
31753197 allocateSessionId:
31763198 options?.allocateSessionId ??
@@ -5846,6 +5868,202 @@ describe("ClaudeAdapterV2 background wake turns", () => {
58465868 ),
58475869 );
58485870
5871+ const promptSuggestionFrame = claudeSdkFrame({
5872+ type: "prompt_suggestion",
5873+ suggestion: " Add a regression test for the sidebar. ",
5874+ uuid: "00000000-0000-4000-8000-000000000701",
5875+ session_id: WAKE_NATIVE_SESSION,
5876+ });
5877+
5878+ const makePromptSuggestionHarness = Effect.gen(function* () {
5879+ const published: Array<readonly [ThreadId, PromptSuggestion | null]> = [];
5880+ const harness = yield* makeWakeHarnessWithOptions({
5881+ close: (sdkMessages) => Queue.shutdown(sdkMessages),
5882+ promptSuggestions: {
5883+ publish: (threadId, suggestion) =>
5884+ Effect.sync(() => {
5885+ published.push([threadId, suggestion]);
5886+ }),
5887+ },
5888+ });
5889+ const now = yield* DateTime.now;
5890+ const startTurn = Effect.fnUntraced(function* (
5891+ ordinal: number,
5892+ threadId: ThreadId = harness.threadId,
5893+ ) {
5894+ const input = makeClaudeTestTurnInput({
5895+ threadId,
5896+ providerThread: harness.providerThread,
5897+ now,
5898+ attemptId: RunAttemptId.make(`attempt-claude-suggestion-${ordinal}`),
5899+ providerTurnOrdinal: ordinal,
5900+ text: "Fix the sidebar.",
5901+ attachments: [],
5902+ });
5903+ yield* harness.runtime.startTurn(input);
5904+ return input;
5905+ });
5906+ const completeTurn = Effect.fnUntraced(function* (
5907+ ordinal: number,
5908+ threadId: ThreadId = harness.threadId,
5909+ ) {
5910+ const input = yield* startTurn(ordinal, threadId);
5911+ yield* Queue.offer(
5912+ harness.sdkMessages,
5913+ makeResultFrame({
5914+ uuid: `00000000-0000-4000-8000-00000000070${ordinal + 1}`,
5915+ result: "Done.",
5916+ }),
5917+ );
5918+ yield* Queue.take(harness.terminalReceipts);
5919+ return input;
5920+ });
5921+ const publishedSuggestions = () => published.filter(([, suggestion]) => suggestion !== null);
5922+ return { harness, published, publishedSuggestions, startTurn, completeTurn };
5923+ });
5924+
5925+ it.effect("publishes Claude's suggestion after a completed turn until the next turn starts", () =>
5926+ Effect.gen(function* () {
5927+ const { harness, published, completeTurn } = yield* makePromptSuggestionHarness;
5928+ const first = yield* completeTurn(1);
5929+ yield* harness.offerAndWait(promptSuggestionFrame);
5930+ assert.deepEqual(published.at(-1), [
5931+ harness.threadId,
5932+ {
5933+ id: "00000000-0000-4000-8000-000000000701",
5934+ runId: first.runId,
5935+ text: "Add a regression test for the sidebar.",
5936+ },
5937+ ]);
5938+ yield* completeTurn(2);
5939+ assert.deepEqual(published.at(-1), [harness.threadId, null]);
5940+ }).pipe(
5941+ Effect.provide(
5942+ Layer.mergeAll(
5943+ IdAllocator.layer,
5944+ McpProviderSessions.layer,
5945+ NodeServices.layer,
5946+ NodeCrypto.layer,
5947+ ),
5948+ ),
5949+ ),
5950+ );
5951+
5952+ it.effect("drops a suggestion that arrives once the next turn has started", () =>
5953+ Effect.gen(function* () {
5954+ const { harness, publishedSuggestions, startTurn, completeTurn } =
5955+ yield* makePromptSuggestionHarness;
5956+ yield* completeTurn(1);
5957+ yield* startTurn(2);
5958+ yield* harness.offerAndWait(promptSuggestionFrame);
5959+ assert.lengthOf(publishedSuggestions(), 0);
5960+ }).pipe(
5961+ Effect.provide(
5962+ Layer.mergeAll(
5963+ IdAllocator.layer,
5964+ McpProviderSessions.layer,
5965+ NodeServices.layer,
5966+ NodeCrypto.layer,
5967+ ),
5968+ ),
5969+ ),
5970+ );
5971+
5972+ it.effect("clears a suggestion for another app thread of the session on rollback", () =>
5973+ Effect.gen(function* () {
5974+ const { harness, published, completeTurn } = yield* makePromptSuggestionHarness;
5975+ const otherThreadId = ThreadId.make("thread-claude-suggestion-other");
5976+ yield* completeTurn(1, otherThreadId);
5977+ yield* harness.offerAndWait(promptSuggestionFrame);
5978+ assert.equal(published.at(-1)?.[0], otherThreadId);
5979+ yield* harness.runtime.rollbackThread({
5980+ providerThread: harness.providerThread,
5981+ providerThreadTurns: [],
5982+ target: {
5983+ type: "thread_start",
5984+ checkpointId: CheckpointId.make("checkpoint-claude-suggestion-other-rollback"),
5985+ appRunOrdinal: 0,
5986+ },
5987+ });
5988+ assert.deepEqual(published.at(-1), [otherThreadId, null]);
5989+ }).pipe(
5990+ Effect.provide(
5991+ Layer.mergeAll(
5992+ IdAllocator.layer,
5993+ McpProviderSessions.layer,
5994+ NodeServices.layer,
5995+ NodeCrypto.layer,
5996+ ),
5997+ ),
5998+ ),
5999+ );
6000+
6001+ it.effect("clears the suggestion when the thread rolls back", () =>
6002+ Effect.gen(function* () {
6003+ const { harness, published, publishedSuggestions, completeTurn } =
6004+ yield* makePromptSuggestionHarness;
6005+ yield* completeTurn(1);
6006+ yield* harness.offerAndWait(promptSuggestionFrame);
6007+ assert.lengthOf(publishedSuggestions(), 1);
6008+ yield* harness.runtime.rollbackThread({
6009+ providerThread: harness.providerThread,
6010+ providerThreadTurns: [],
6011+ target: {
6012+ type: "thread_start",
6013+ checkpointId: CheckpointId.make("checkpoint-claude-suggestion-rollback"),
6014+ appRunOrdinal: 0,
6015+ },
6016+ });
6017+ assert.deepEqual(published.at(-1), [harness.threadId, null]);
6018+ }).pipe(
6019+ Effect.provide(
6020+ Layer.mergeAll(
6021+ IdAllocator.layer,
6022+ McpProviderSessions.layer,
6023+ NodeServices.layer,
6024+ NodeCrypto.layer,
6025+ ),
6026+ ),
6027+ ),
6028+ );
6029+
6030+ it.effect("clears the suggestion when a background wake starts and offers none after it", () =>
6031+ Effect.gen(function* () {
6032+ const { harness, published, publishedSuggestions, completeTurn } =
6033+ yield* makePromptSuggestionHarness;
6034+ yield* completeTurn(1);
6035+ yield* harness.offerAndWait(promptSuggestionFrame);
6036+ assert.lengthOf(publishedSuggestions(), 1);
6037+ yield* harness.offerAndWait(wakeTurnInit);
6038+ assert.deepEqual(published.at(-1), [harness.threadId, null]);
6039+ yield* harness.offerAndWait(
6040+ makeAssistantTextFrame({
6041+ uuid: "00000000-0000-4000-8000-000000000711",
6042+ text: "The background task finished.",
6043+ }),
6044+ );
6045+ assert.deepEqual(published.at(-1), [harness.threadId, null]);
6046+ yield* harness.offerAndWait(
6047+ claudeSdkFrame({
6048+ type: "prompt_suggestion",
6049+ suggestion: "Check the test results.",
6050+ uuid: "00000000-0000-4000-8000-000000000712",
6051+ session_id: WAKE_NATIVE_SESSION,
6052+ }),
6053+ );
6054+ assert.lengthOf(publishedSuggestions(), 1);
6055+ }).pipe(
6056+ Effect.provide(
6057+ Layer.mergeAll(
6058+ IdAllocator.layer,
6059+ McpProviderSessions.layer,
6060+ NodeServices.layer,
6061+ NodeCrypto.layer,
6062+ ),
6063+ ),
6064+ ),
6065+ );
6066+
58496067 it.effect.each([
58506068 {
58516069 name: "an unflagged result with surrounding whitespace",
0 commit comments