@@ -54,11 +54,10 @@ export namespace Skill {
5454 type State = {
5555 skills : Record < string , Info >
5656 dirs : Set < string >
57- task ?: Promise < void >
5857 }
5958
6059 type Cache = State & {
61- ensure : ( ) => Promise < void >
60+ load : ( ) => Promise < void >
6261 }
6362
6463 export interface Interface {
@@ -116,7 +115,6 @@ export namespace Skill {
116115 } )
117116 }
118117
119- // TODO: Migrate to Effect
120118 const create = ( discovery : Discovery . Interface , directory : string , worktree : string ) : Cache => {
121119 const state : State = {
122120 skills : { } ,
@@ -166,16 +164,7 @@ export namespace Skill {
166164 log . info ( "init" , { count : Object . keys ( state . skills ) . length } )
167165 }
168166
169- const ensure = ( ) => {
170- if ( state . task ) return state . task
171- state . task = load ( ) . catch ( ( err ) => {
172- state . task = undefined
173- throw err
174- } )
175- return state . task
176- }
177-
178- return { ...state , ensure }
167+ return { ...state , load }
179168 }
180169
181170 export class Service extends ServiceMap . Service < Service , Interface > ( ) ( "@opencode/Skill" ) { }
@@ -188,12 +177,18 @@ export namespace Skill {
188177 Effect . fn ( "Skill.state" ) ( ( ctx ) => Effect . sync ( ( ) => create ( discovery , ctx . directory , ctx . worktree ) ) ) ,
189178 )
190179
191- const ensure = Effect . fn ( "Skill.ensure" ) ( function * ( ) {
180+ const ensureCached = Effect . fnUntraced ( function * ( ) {
192181 const cache = yield * InstanceState . get ( state )
193- yield * Effect . promise ( ( ) => cache . ensure ( ) )
182+ yield * Effect . promise ( ( ) => cache . load ( ) )
194183 return cache
195184 } )
196185
186+ let cachedEnsure = yield * Effect . cached ( ensureCached ( ) )
187+
188+ const ensure = Effect . fn ( "Skill.ensure" ) ( function * ( ) {
189+ return yield * cachedEnsure
190+ } )
191+
197192 const get = Effect . fn ( "Skill.get" ) ( function * ( name : string ) {
198193 const cache = yield * ensure ( )
199194 return cache . skills [ name ]
0 commit comments