Skip to content

Commit b24959d

Browse files
t3dotggclaude
andauthored
feat: Labs option to suggest your next prompt after Claude and Codex turns (#28047)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 521ac7c commit b24959d

27 files changed

Lines changed: 783 additions & 7 deletions

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const RPC_REQUIRED_SCOPES = {
6161
[ORCHESTRATION_V2_WS_METHODS.subscribeShell]: AuthOrchestrationReadScope,
6262
[ORCHESTRATION_V2_WS_METHODS.subscribeThread]: AuthOrchestrationReadScope,
6363
[ORCHESTRATION_V2_WS_METHODS.subscribeCommandOutput]: AuthOrchestrationReadScope,
64+
[ORCHESTRATION_V2_WS_METHODS.subscribePromptSuggestion]: AuthOrchestrationReadScope,
6465
[WS_METHODS.projectsMutate]: AuthOrchestrationOperateScope,
6566
[WS_METHODS.serverProbe]: AuthOrchestrationReadScope,
6667
[WS_METHODS.serverGetConfig]: AuthOrchestrationReadScope,

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const RPC_AGGREGATES = {
3333
[ORCHESTRATION_V2_WS_METHODS.subscribeShell]: "orchestrationV2",
3434
[ORCHESTRATION_V2_WS_METHODS.subscribeThread]: "orchestrationV2",
3535
[ORCHESTRATION_V2_WS_METHODS.subscribeCommandOutput]: "orchestrationV2",
36+
[ORCHESTRATION_V2_WS_METHODS.subscribePromptSuggestion]: "orchestrationV2",
3637
[WS_METHODS.projectsMutate]: "orchestration",
3738
[WS_METHODS.serverProbe]: "server",
3839
[WS_METHODS.serverGetConfig]: "server",

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,6 +3159,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
31593159
readonly freshQueueOnReopen?: boolean;
31603160
readonly forkSession?: ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerShape["forkSession"];
31613161
readonly allocateSessionId?: Effect.Effect<string>;
3162+
readonly promptSuggestions?: boolean;
31623163
}) =>
31633164
Effect.gen(function* () {
31643165
const fileSystem = yield* FileSystem.FileSystem;
@@ -3329,6 +3330,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
33293330
providerSessionId: ProviderSessionId.make("provider-session-claude-wake"),
33303331
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
33313332
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
3333+
promptSuggestions: Effect.succeed(options?.promptSuggestions === true),
33323334
});
33333335
const providerThread = yield* runtime.ensureThread({
33343336
threadId,
@@ -7864,6 +7866,101 @@ describe("ClaudeAdapterV2 background wake turns", () => {
78647866
),
78657867
);
78667868

7869+
it.effect.each(["root", "mcp", "subagent", "remote"] as const)(
7870+
"asks Claude for suggestions only on threads a person drives (%s)",
7871+
(lineage) =>
7872+
Effect.gen(function* () {
7873+
const harness = yield* makeWakeHarnessWithOptions({ promptSuggestions: true });
7874+
const base = makeClaudeTestTurnInput({
7875+
threadId: harness.threadId,
7876+
providerThread: harness.providerThread,
7877+
now: yield* DateTime.now,
7878+
attemptId: RunAttemptId.make("attempt-prompt-suggestion"),
7879+
text: "Add a subtract function.",
7880+
attachments: [],
7881+
});
7882+
const parentThreadId = ThreadId.make("thread-claude-suggestion-parent");
7883+
// MCP-launched root threads carry `delegatedFrom: null` at runtime.
7884+
const offered = lineage === "root" || lineage === "mcp";
7885+
const input =
7886+
lineage === "root"
7887+
? base
7888+
: lineage === "mcp"
7889+
? {
7890+
...base,
7891+
appThread: {
7892+
...base.appThread,
7893+
delegatedFrom: null as unknown as undefined,
7894+
},
7895+
}
7896+
: lineage === "subagent"
7897+
? {
7898+
...base,
7899+
appThread: {
7900+
...base.appThread,
7901+
lineage: {
7902+
parentThreadId,
7903+
relationshipToParent: "subagent" as const,
7904+
rootThreadId: parentThreadId,
7905+
},
7906+
},
7907+
}
7908+
: {
7909+
...base,
7910+
appThread: {
7911+
...base.appThread,
7912+
delegatedFrom: {
7913+
environmentId: EnvironmentId.make("environment-claude-suggestion-parent"),
7914+
threadId: parentThreadId,
7915+
title: "Parent",
7916+
},
7917+
},
7918+
};
7919+
yield* harness.runtime.startTurn(input);
7920+
yield* Queue.offer(
7921+
harness.sdkMessages,
7922+
makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000690", result: "Done." }),
7923+
);
7924+
yield* Queue.take(harness.terminalReceipts);
7925+
// Delegated threads have no one typing, so the SDK is never asked for suggestions.
7926+
assert.equal(harness.getOpenedOptions()?.promptSuggestions, offered);
7927+
if (!offered) return;
7928+
yield* Queue.offer(
7929+
harness.sdkMessages,
7930+
claudeSdkFrame({
7931+
type: "prompt_suggestion",
7932+
suggestion: " add tests for subtract\n",
7933+
uuid: "00000000-0000-4000-8000-000000000691",
7934+
session_id: WAKE_NATIVE_SESSION,
7935+
}),
7936+
);
7937+
yield* harness.until(() =>
7938+
harness.events.some((event) => event.type === "prompt_suggestion.updated"),
7939+
);
7940+
assert.deepEqual(
7941+
harness.events.filter((event) => event.type === "prompt_suggestion.updated"),
7942+
[
7943+
{
7944+
type: "prompt_suggestion.updated",
7945+
driver: ClaudeAdapterV2.CLAUDE_PROVIDER,
7946+
threadId: harness.threadId,
7947+
runId: input.runId,
7948+
text: "add tests for subtract",
7949+
},
7950+
],
7951+
);
7952+
}).pipe(
7953+
Effect.provide(
7954+
Layer.mergeAll(
7955+
IdAllocator.layer,
7956+
McpProviderSessions.layer,
7957+
NodeServices.layer,
7958+
NodeCrypto.layer,
7959+
),
7960+
),
7961+
),
7962+
);
7963+
78677964
it.effect("merges cumulative stream usage into the message_start counts", () =>
78687965
Effect.gen(function* () {
78697966
const harness = yield* makeWakeHarnessWithOptions({
@@ -12452,6 +12549,49 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1245212549
),
1245312550
);
1245412551
assert.isFalse(yield* harness.hasPendingBackgroundWork);
12552+
12553+
// The continuation settled with no result of its own, so a late suggestion belongs to B.
12554+
yield* harness.offerAndWait(
12555+
claudeSdkFrame({
12556+
type: "prompt_suggestion",
12557+
suggestion: "Check the build logs",
12558+
uuid: "00000000-0000-4000-8000-000000000692",
12559+
session_id: WAKE_NATIVE_SESSION,
12560+
}),
12561+
);
12562+
const userTurn = makeClaudeTestTurnInput({
12563+
threadId: harness.threadId,
12564+
providerThread: harness.providerThread,
12565+
now,
12566+
attemptId: RunAttemptId.make("attempt-claude-wake-4d"),
12567+
text: "Ship it.",
12568+
attachments: [],
12569+
providerTurnOrdinal: 4,
12570+
});
12571+
yield* harness.runtime.startTurn(userTurn);
12572+
yield* Queue.offer(
12573+
harness.sdkMessages,
12574+
makeResultFrame({ uuid: "00000000-0000-4000-8000-000000000693", result: "Shipped." }),
12575+
);
12576+
yield* harness.awaitTerminal(4);
12577+
yield* Queue.offer(
12578+
harness.sdkMessages,
12579+
claudeSdkFrame({
12580+
type: "prompt_suggestion",
12581+
suggestion: "Open the release notes",
12582+
uuid: "00000000-0000-4000-8000-000000000694",
12583+
session_id: WAKE_NATIVE_SESSION,
12584+
}),
12585+
);
12586+
yield* harness.until(() =>
12587+
harness.events.some((event) => event.type === "prompt_suggestion.updated"),
12588+
);
12589+
assert.deepEqual(
12590+
harness.events.flatMap((event) =>
12591+
event.type === "prompt_suggestion.updated" ? [[event.runId, event.text]] : [],
12592+
),
12593+
[[userTurn.runId, "Open the release notes"]],
12594+
);
1245512595
}).pipe(
1245612596
Effect.provide(
1245712597
Layer.mergeAll(

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ import {
128128
type RunId,
129129
type ThreadId,
130130
resolveIdleCompaction,
131+
isDelegatedAppThread,
131132
} from "@t3tools/contracts";
132133

133134
import { FILE_HEADERS_ONLY, formatPatch, structuredPatch } from "diff";
@@ -1758,6 +1759,7 @@ export function makeClaudeQueryOptions(input: {
17581759
readonly cwd: string | null;
17591760
readonly attachmentsDir?: string;
17601761
readonly settings?: ClaudeSettings;
1762+
readonly promptSuggestions?: boolean;
17611763
readonly sdkSettings?: string | ClaudeSdkSettings;
17621764
readonly environment?: NodeJS.ProcessEnv;
17631765
readonly mcpServers?: ClaudeQueryOptions["mcpServers"];
@@ -1842,6 +1844,7 @@ export function makeClaudeQueryOptions(input: {
18421844
? "bypassPermissions"
18431845
: (input.permissionMode ?? "default")),
18441846
includePartialMessages: true,
1847+
promptSuggestions: input.promptSuggestions === true,
18451848
...(compiledSelection.effort === undefined
18461849
? {}
18471850
: {
@@ -5102,6 +5105,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
51025105
}),
51035106
openSession: Effect.fn("ClaudeAdapterV2.openSession")(
51045107
function* (input: ProviderAdapter.ProviderAdapterV2OpenSessionInput) {
5108+
const promptSuggestionsEnabled = input.promptSuggestions ?? Effect.succeed(false);
51055109
const sessionScope = yield* Effect.scope;
51065110
const now = yield* DateTime.now;
51075111
const session = providerSession({
@@ -8821,6 +8825,27 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
88218825
}
88228826

88238827
const message = input.message;
8828+
if (message.type === "prompt_suggestion") {
8829+
// Arrives after `result`; offer it only while the completed turn is still the latest.
8830+
// A continuation can settle from buffered frames first, so its suggestion may be a user turn's.
8831+
const settled = settledTurnByNativeThread.get(liveQuery.nativeThreadId);
8832+
const text = message.suggestion.trim();
8833+
if (
8834+
settled !== undefined &&
8835+
!isClaudeProviderContinuationTurn(settled.input) &&
8836+
text.length > 0 &&
8837+
(yield* Ref.get(activeTurn)) === null
8838+
) {
8839+
yield* emitProviderEvent({
8840+
type: "prompt_suggestion.updated",
8841+
driver: CLAUDE_PROVIDER,
8842+
threadId: settled.input.threadId,
8843+
runId: settled.input.runId,
8844+
text,
8845+
});
8846+
}
8847+
return;
8848+
}
88248849
// Track before routing: idle-wake Monitors report tasks before replaying their tool calls.
88258850
yield* trackClaudeMonitorCalls(message);
88268851
// Update before routing because the idle wake gate reads this.
@@ -10924,6 +10949,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1092410949
cwd: turnInput.runtimePolicy.cwd,
1092510950
attachmentsDir,
1092610951
settings: adapterOptions.settings,
10952+
// Delegated threads have no one typing, so they never ask for suggestions.
10953+
promptSuggestions:
10954+
!isDelegatedAppThread(turnInput.appThread) && (yield* promptSuggestionsEnabled),
1092710955
...(launchArgSettings === undefined
1092810956
? {}
1092910957
: { sdkSettings: claudeSdkLaunchArgSettings(launchArgSettings) }),

0 commit comments

Comments
 (0)