GeezerVison is showing github.com — feat: Labs option to suggest your next prompt after Claude and Codex … · adampeterhiggins/t3code@b24959d
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/auth/RpcAuthorization.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,6 +61,7 @@ export const RPC_REQUIRED_SCOPES = { | 61 | 61 | [ORCHESTRATION_V2_WS_METHODS.subscribeShell]: AuthOrchestrationReadScope, | 62 | 62 | [ORCHESTRATION_V2_WS_METHODS.subscribeThread]: AuthOrchestrationReadScope, | 63 | 63 | [ORCHESTRATION_V2_WS_METHODS.subscribeCommandOutput]: AuthOrchestrationReadScope, | | 64 | + [ORCHESTRATION_V2_WS_METHODS.subscribePromptSuggestion]: AuthOrchestrationReadScope, | 64 | 65 | [WS_METHODS.projectsMutate]: AuthOrchestrationOperateScope, | 65 | 66 | [WS_METHODS.serverProbe]: AuthOrchestrationReadScope, | 66 | 67 | [WS_METHODS.serverGetConfig]: AuthOrchestrationReadScope, | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/observability/RpcInstrumentation.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,6 +33,7 @@ const RPC_AGGREGATES = { | 33 | 33 | [ORCHESTRATION_V2_WS_METHODS.subscribeShell]: "orchestrationV2", | 34 | 34 | [ORCHESTRATION_V2_WS_METHODS.subscribeThread]: "orchestrationV2", | 35 | 35 | [ORCHESTRATION_V2_WS_METHODS.subscribeCommandOutput]: "orchestrationV2", | | 36 | + [ORCHESTRATION_V2_WS_METHODS.subscribePromptSuggestion]: "orchestrationV2", | 36 | 37 | [WS_METHODS.projectsMutate]: "orchestration", | 37 | 38 | [WS_METHODS.serverProbe]: "server", | 38 | 39 | [WS_METHODS.serverGetConfig]: "server", | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +140Lines changed: 140 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3159,6 +3159,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { | 3159 | 3159 | readonly freshQueueOnReopen?: boolean; | 3160 | 3160 | readonly forkSession?: ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerShape["forkSession"]; | 3161 | 3161 | readonly allocateSessionId?: Effect.Effect<string>; | | 3162 | + readonly promptSuggestions?: boolean; | 3162 | 3163 | }) => | 3163 | 3164 | Effect.gen(function* () { | 3164 | 3165 | const fileSystem = yield* FileSystem.FileSystem; | @@ -3329,6 +3330,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { | 3329 | 3330 | providerSessionId: ProviderSessionId.make("provider-session-claude-wake"), | 3330 | 3331 | modelSelection: CLAUDE_TEST_MODEL_SELECTION, | 3331 | 3332 | runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY, | | 3333 | + promptSuggestions: Effect.succeed(options?.promptSuggestions === true), | 3332 | 3334 | }); | 3333 | 3335 | const providerThread = yield* runtime.ensureThread({ | 3334 | 3336 | threadId, | @@ -7864,6 +7866,101 @@ describe("ClaudeAdapterV2 background wake turns", () => { | 7864 | 7866 | ), | 7865 | 7867 | ); | 7866 | 7868 |
| | 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 | + | 7867 | 7964 | it.effect("merges cumulative stream usage into the message_start counts", () => | 7868 | 7965 | Effect.gen(function* () { | 7869 | 7966 | const harness = yield* makeWakeHarnessWithOptions({ | @@ -12452,6 +12549,49 @@ describe("ClaudeAdapterV2 background wake turns", () => { | 12452 | 12549 | ), | 12453 | 12550 | ); | 12454 | 12551 | 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 | + ); | 12455 | 12595 | }).pipe( | 12456 | 12596 | Effect.provide( | 12457 | 12597 | Layer.mergeAll( | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -128,6 +128,7 @@ import { | 128 | 128 | type RunId, | 129 | 129 | type ThreadId, | 130 | 130 | resolveIdleCompaction, | | 131 | + isDelegatedAppThread, | 131 | 132 | } from "@t3tools/contracts"; | 132 | 133 |
| 133 | 134 | import { FILE_HEADERS_ONLY, formatPatch, structuredPatch } from "diff"; | @@ -1758,6 +1759,7 @@ export function makeClaudeQueryOptions(input: { | 1758 | 1759 | readonly cwd: string | null; | 1759 | 1760 | readonly attachmentsDir?: string; | 1760 | 1761 | readonly settings?: ClaudeSettings; | | 1762 | + readonly promptSuggestions?: boolean; | 1761 | 1763 | readonly sdkSettings?: string | ClaudeSdkSettings; | 1762 | 1764 | readonly environment?: NodeJS.ProcessEnv; | 1763 | 1765 | readonly mcpServers?: ClaudeQueryOptions["mcpServers"]; | @@ -1842,6 +1844,7 @@ export function makeClaudeQueryOptions(input: { | 1842 | 1844 | ? "bypassPermissions" | 1843 | 1845 | : (input.permissionMode ?? "default")), | 1844 | 1846 | includePartialMessages: true, | | 1847 | + promptSuggestions: input.promptSuggestions === true, | 1845 | 1848 | ...(compiledSelection.effort === undefined | 1846 | 1849 | ? {} | 1847 | 1850 | : { | @@ -5102,6 +5105,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( | 5102 | 5105 | }), | 5103 | 5106 | openSession: Effect.fn("ClaudeAdapterV2.openSession")( | 5104 | 5107 | function* (input: ProviderAdapter.ProviderAdapterV2OpenSessionInput) { | | 5108 | + const promptSuggestionsEnabled = input.promptSuggestions ?? Effect.succeed(false); | 5105 | 5109 | const sessionScope = yield* Effect.scope; | 5106 | 5110 | const now = yield* DateTime.now; | 5107 | 5111 | const session = providerSession({ | @@ -8821,6 +8825,27 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( | 8821 | 8825 | } | 8822 | 8826 |
| 8823 | 8827 | 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 | + } | 8824 | 8849 | // Track before routing: idle-wake Monitors report tasks before replaying their tool calls. | 8825 | 8850 | yield* trackClaudeMonitorCalls(message); | 8826 | 8851 | // Update before routing because the idle wake gate reads this. | @@ -10924,6 +10949,9 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( | 10924 | 10949 | cwd: turnInput.runtimePolicy.cwd, | 10925 | 10950 | attachmentsDir, | 10926 | 10951 | settings: adapterOptions.settings, | | 10952 | + // Delegated threads have no one typing, so they never ask for suggestions. | | 10953 | + promptSuggestions: | | 10954 | + !isDelegatedAppThread(turnInput.appThread) && (yield* promptSuggestionsEnabled), | 10927 | 10955 | ...(launchArgSettings === undefined | 10928 | 10956 | ? {} | 10929 | 10957 | : { sdkSettings: claudeSdkLaunchArgSettings(launchArgSettings) }), | |
|