@@ -67,6 +67,7 @@ func OciRefToFilename(ociRef string) string {
6767}
6868
6969// Resolve resolves an agent file reference (local file or OCI image) to a local file path
70+ // For OCI references, always checks remote for updates but falls back to local cache if offline
7071func Resolve (ctx context.Context , out * cli.Printer , agentFilename string ) (string , error ) {
7172 originalOCIRef := agentFilename // Store the original for OCI ref tracking
7273
@@ -101,20 +102,42 @@ func Resolve(ctx context.Context, out *cli.Printer, agentFilename string) (strin
101102 return agentFilename , nil
102103 }
103104
104- // Treat as an OCI image reference. Try local store first, otherwise pull then load.
105- a , err := FromStore (agentFilename )
105+ // Treat as an OCI image reference
106+ // Check if we have a local copy (without loading content)
107+ store , err := content .NewStore ()
106108 if err != nil {
107- out .Println ("Pulling agent" , agentFilename )
108- if _ , pullErr := remote .Pull (ctx , agentFilename , false ); pullErr != nil {
109+ return "" , fmt .Errorf ("failed to create content store: %w" , err )
110+ }
111+
112+ _ , metaErr := store .GetArtifactMetadata (agentFilename )
113+ hasLocal := metaErr == nil
114+
115+ if out != nil {
116+ if hasLocal {
117+ out .Printf ("Checking for updates to OCI reference %s...\n " , agentFilename )
118+ } else {
119+ out .Printf ("Pulling OCI reference %s...\n " , agentFilename )
120+ }
121+ }
122+
123+ // Try to pull from remote (only pulls if digest changed)
124+ if _ , pullErr := remote .Pull (ctx , agentFilename , false ); pullErr != nil {
125+ if ! hasLocal {
126+ // No local copy and can't pull, error out
109127 return "" , fmt .Errorf ("failed to pull OCI image %s: %w" , agentFilename , pullErr )
110128 }
111- // Retry after pull
112- a , err = FromStore (agentFilename )
113- if err != nil {
114- return "" , fmt .Errorf ("failed to load agent from store after pull: %w" , err )
129+ slog .Debug ("Failed to check for OCI reference updates, using cached version" , "ref" , agentFilename , "error" , pullErr )
130+ if out != nil {
131+ out .Println ("Using cached version of" , agentFilename )
115132 }
116133 }
117134
135+ // Load the agent contents from the store
136+ a , err := FromStore (agentFilename )
137+ if err != nil {
138+ return "" , fmt .Errorf ("failed to load agent from store: %w" , err )
139+ }
140+
118141 filename := OciRefToFilename (originalOCIRef )
119142 tmpFilename := filepath .Join (os .TempDir (), filename )
120143
0 commit comments