@@ -47,7 +47,9 @@ const personalSkill = {
4747} ;
4848
4949// Respond through the real stdio transport, with a distinct command catalog for each cwd.
50- const makePiSpawner = Effect . gen ( function * ( ) {
50+ const makePiSpawner = Effect . fnUntraced ( function * (
51+ discovery : { readonly state ?: unknown ; readonly models ?: ReadonlyArray < unknown > } = { } ,
52+ ) {
5153 const pendingCommand = yield * Deferred . make < void > ( ) ;
5254 const launches : Array < ChildProcess . StandardCommand > = [ ] ;
5355 const spawner = ChildProcessSpawner . make ( ( command ) =>
@@ -92,8 +94,10 @@ const makePiSpawner = Effect.gen(function* () {
9294 ] ,
9395 }
9496 : request . type === "get_available_models"
95- ? { models : [ { provider : "test" , id : "model" } ] }
96- : { } ;
97+ ? { models : discovery . models ?? [ { provider : "test" , id : "model" } ] }
98+ : request . type === "get_state"
99+ ? ( discovery . state ?? { } )
100+ : { } ;
97101 return Queue . offer (
98102 stdout ,
99103 encoder . encode (
@@ -125,7 +129,7 @@ const create = (config: Partial<PiSettings> = {}, enabled = true) =>
125129it . layer ( layerTest ) ( "PiDriver workspace discovery" , ( it ) => {
126130 it . effect ( "keeps each workspace's skills and commands separate from the machine catalog" , ( ) =>
127131 Effect . gen ( function * ( ) {
128- const { spawner, launches } = yield * makePiSpawner ;
132+ const { spawner, launches } = yield * makePiSpawner ( ) ;
129133 const instance = yield * create ( { launchArgs : '--approve --skill "extra skill"' } ) . pipe (
130134 Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
131135 ) ;
@@ -186,11 +190,50 @@ it.layer(layerTest)("PiDriver workspace discovery", (it) => {
186190 } ) . pipe ( Effect . scoped ) ,
187191 ) ;
188192
193+ it . effect . each ( [ true , false ] ) (
194+ "limits discovered thinking defaults to the known active model, known=%s" ,
195+ ( known ) =>
196+ Effect . gen ( function * ( ) {
197+ const { spawner } = yield * makePiSpawner ( {
198+ state : {
199+ thinkingLevel : "high" ,
200+ ...( known ? { model : { provider : "test" , id : "model" } } : { } ) ,
201+ } ,
202+ models : [
203+ { provider : "test" , id : "model" , reasoning : true } ,
204+ { provider : "other" , id : "model" , reasoning : true } ,
205+ { provider : "test" , id : "other" , reasoning : true } ,
206+ ] ,
207+ } ) ;
208+ const instance = yield * create ( ) . pipe (
209+ Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
210+ ) ;
211+ yield * instance . snapshot . refresh ;
212+ const snapshot = yield * instance . snapshot . getSnapshot ;
213+ assert . deepEqual (
214+ snapshot . models . map ( ( model ) => [
215+ model . slug ,
216+ ( model . capabilities ?. optionDescriptors ?? [ ] ) . flatMap ( ( descriptor ) =>
217+ descriptor . type === "select"
218+ ? descriptor . options . filter ( ( option ) => option . isDefault ) . map ( ( option ) => option . id )
219+ : [ ] ,
220+ ) ,
221+ ] ) ,
222+ [
223+ [ "default" , [ ] ] ,
224+ [ "test/model" , known ? [ "high" ] : [ ] ] ,
225+ [ "other/model" , [ ] ] ,
226+ [ "test/other" , [ ] ] ,
227+ ] ,
228+ ) ;
229+ } ) . pipe ( Effect . scoped ) ,
230+ ) ;
231+
189232 it . effect (
190233 "fails command discovery instead of returning an empty successful workspace catalog" ,
191234 ( ) =>
192235 Effect . gen ( function * ( ) {
193- const { spawner } = yield * makePiSpawner ;
236+ const { spawner } = yield * makePiSpawner ( ) ;
194237 const instance = yield * create ( ) . pipe (
195238 Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
196239 ) ;
@@ -208,7 +251,7 @@ it.layer(layerTest)("PiDriver workspace discovery", (it) => {
208251
209252 it . effect ( "times out workspace discovery that needs interactive input" , ( ) =>
210253 Effect . gen ( function * ( ) {
211- const { spawner, pendingCommand } = yield * makePiSpawner ;
254+ const { spawner, pendingCommand } = yield * makePiSpawner ( ) ;
212255 const instance = yield * create ( ) . pipe (
213256 Effect . provideService ( ChildProcessSpawner . ChildProcessSpawner , spawner ) ,
214257 ) ;
0 commit comments