@@ -23,6 +23,10 @@ import * as Schema from "effect/Schema";
2323import * as Stream from "effect/Stream" ;
2424
2525import { layerTestProviderHost } from "@t3tools/provider-testing/host" ;
26+ import {
27+ DEFAULT_HANDOFF_TOKEN_CAP ,
28+ handoffBudget ,
29+ } from "@t3tools/provider-core/server/handoffBudget" ;
2630import * as McpProviderSession from "@t3tools/provider-core/server/mcpSession" ;
2731import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator" ;
2832import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter" ;
@@ -771,6 +775,78 @@ describe("CursorAdapterV2", () => {
771775 ) ;
772776 } ) ;
773777
778+ it . effect ( "reports the selected context window so long threads keep a handoff allowance" , ( ) =>
779+ Effect . gen ( function * ( ) {
780+ const fileSystem = yield * FileSystem . FileSystem ;
781+ const workspace = yield * fileSystem . makeTempDirectoryScoped ( { prefix : "cursor-v2-window-" } ) ;
782+ const instanceId = ProviderInstanceId . make ( "cursor" ) ;
783+ const threadId = ThreadId . make ( "cursor-window-thread" ) ;
784+ const selection = ( contextWindow ?: string ) => ( {
785+ instanceId,
786+ model : "claude-opus-5-5" ,
787+ ...( contextWindow === undefined
788+ ? { }
789+ : { options : [ { id : "contextWindow" , value : contextWindow } ] } ) ,
790+ } ) ;
791+ const runtimePolicy = ProviderAdapter . ProviderAdapterV2RuntimePolicy . make ( {
792+ runtimeMode : "full-access" ,
793+ interactionMode : "default" ,
794+ cwd : workspace ,
795+ } ) ;
796+ const adapter = yield * makeCursorAdapterV2 ( {
797+ instanceId,
798+ settings : yield * decodeCursorSettings ( { } ) ,
799+ environment : { HOME : workspace } ,
800+ } ) . pipe (
801+ Effect . provideService ( CursorAgentSdk . CursorAgentSdkRunner , {
802+ assertComplete : Effect . void ,
803+ open : ( ) =>
804+ Effect . succeed ( {
805+ agentId : "native-cursor-window" ,
806+ listMessages : Effect . succeed ( [ ] ) ,
807+ close : Effect . void ,
808+ send : ( ) => Effect . die ( "Cursor turns are not started in this test." ) ,
809+ } ) ,
810+ } ) ,
811+ Effect . provide ( layerTestProviderHost ( { cwd : workspace } ) ) ,
812+ ) ;
813+ const runtime = yield * adapter . openSession ( {
814+ threadId,
815+ providerSessionId : ProviderSessionId . make ( "cursor-window-session" ) ,
816+ modelSelection : selection ( "1m" ) ,
817+ runtimePolicy,
818+ } ) ;
819+ const providerThread = yield * runtime . ensureThread ( {
820+ threadId,
821+ modelSelection : selection ( "1m" ) ,
822+ runtimePolicy,
823+ } ) ;
824+
825+ assert . equal ( runtime . getModelContextWindow ?.( selection ( "1m" ) ) , 1_000_000 ) ;
826+ assert . equal ( runtime . getModelContextWindow ?.( selection ( "272k" ) ) , 272_000 ) ;
827+ assert . equal ( runtime . getModelContextWindow ?.( selection ( "300K" ) ) , 300_000 ) ;
828+ assert . isUndefined ( runtime . getModelContextWindow ?.( selection ( ) ) ) ;
829+ assert . isUndefined ( runtime . getModelContextWindow ?.( selection ( "max" ) ) ) ;
830+
831+ // Cursor reports no context usage, so the budget falls back to a byte
832+ // estimate of the native transcript, here a thread with long shell output.
833+ const budget = ( modelContextWindow : number | undefined ) =>
834+ handoffBudget ( {
835+ tokenCap : DEFAULT_HANDOFF_TOKEN_CAP ,
836+ userText : "Continue." ,
837+ attachments : [ ] ,
838+ providerThread,
839+ nativeContextEstimate : 224_379 ,
840+ modelContextWindow,
841+ } ) ;
842+ assert . equal ( budget ( undefined ) , 0 ) ;
843+ assert . equal (
844+ budget ( runtime . getModelContextWindow ?.( selection ( "1m" ) ) ) ,
845+ DEFAULT_HANDOFF_TOKEN_CAP ,
846+ ) ;
847+ } ) . pipe ( Effect . scoped , Effect . provide ( Layer . merge ( NodeServices . layer , IdAllocator . layer ) ) ) ,
848+ ) ;
849+
774850 it ( "maps runtime modes to the SDK sandbox and auto-review controls" , ( ) => {
775851 const base = {
776852 interactionMode : "default" as const ,
0 commit comments