11import type { CommandName } from '../commands/command-metadata.ts' ;
2+ import type { CommandExecutionResult } from '../commands/command-surface.ts' ;
23
34export type ToolRefPinStore = {
45 pinInput (
@@ -8,7 +9,7 @@ export type ToolRefPinStore = {
89 ) : Record < string , unknown > ;
910 mergeCommandResult (
1011 name : CommandName ,
11- result : unknown ,
12+ result : CommandExecutionResult ,
1213 stateDir : string | undefined ,
1314 session : unknown ,
1415 ) : void ;
@@ -106,7 +107,7 @@ function mergeDivergenceScreenRefPins(
106107) : void {
107108 const divergence = asOptionalRecord ( details ?. divergence ) ;
108109 const screen = asOptionalRecord ( divergence ?. screen ) ;
109- if ( ! screen || screen . state !== 'available' ) return ;
110+ if ( screen ? .state !== 'available' ) return ;
110111 const refsGeneration = screen . refsGeneration ;
111112 if ( typeof refsGeneration !== 'number' ) return ;
112113 const issuedRefs : string [ ] = [ ] ;
@@ -125,7 +126,7 @@ function mergeIssuedRefPins(
125126 refPinsByScope : Map < string , Map < string , number > > ,
126127 scopeKey : string ,
127128 name : CommandName ,
128- result : unknown ,
129+ result : CommandExecutionResult ,
129130) : void {
130131 if ( SETTLE_REF_ISSUING_TOOLS . has ( name ) ) {
131132 mergeSettleIssuedRefPins ( refPinsByScope , scopeKey , result ) ;
@@ -158,7 +159,7 @@ function mergeIssuedRefPins(
158159function mergeSettleIssuedRefPins (
159160 refPinsByScope : Map < string , Map < string , number > > ,
160161 scopeKey : string ,
161- result : unknown ,
162+ result : CommandExecutionResult ,
162163) : void {
163164 const settle = asOptionalRecord ( asOptionalRecord ( result ) ?. settle ) ;
164165 if ( ! settle ) return ;
@@ -265,7 +266,10 @@ function pinRef(ref: string, pins: Map<string, number>): string {
265266 return generation === undefined ? ref : `${ ref } ~s${ generation } ` ;
266267}
267268
269+ function isRecord ( value : unknown ) : value is Record < string , unknown > {
270+ return typeof value === 'object' && value !== null && ! Array . isArray ( value ) ;
271+ }
272+
268273function asOptionalRecord ( value : unknown ) : Record < string , unknown > | undefined {
269- if ( ! value || typeof value !== 'object' || Array . isArray ( value ) ) return undefined ;
270- return value as Record < string , unknown > ;
274+ return isRecord ( value ) ? value : undefined ;
271275}
0 commit comments