@@ -3,8 +3,11 @@ package cli
33import (
44 "embed"
55 "fmt"
6+ "io"
7+ "net/http"
68 "os"
79 "path"
10+ "time"
811
912 "github.com/spf13/cobra"
1013
@@ -114,9 +117,28 @@ func processTemplateFile(fs embed.FS, templateDir, filename, cwd string) error {
114117 return fmt .Errorf ("Error creating directory %s: %w" , dirPath , err )
115118 }
116119
117- content , err := fs .ReadFile (path .Join (templateDir , filename ))
118- if err != nil {
119- return fmt .Errorf ("Error reading %s: %w" , filename , err )
120+ var content []byte
121+
122+ // Special handling for AGENTS.md - try to download from Replicate docs
123+ if filename == "AGENTS.md" {
124+ downloadedContent , err := downloadAgentsFile ()
125+ if err != nil {
126+ console .Infof ("Failed to download AGENTS.md: %v" , err )
127+ console .Infof ("Using template version instead..." )
128+ // Fall back to template version
129+ content , err = fs .ReadFile (path .Join (templateDir , filename ))
130+ if err != nil {
131+ return fmt .Errorf ("Error reading template %s: %w" , filename , err )
132+ }
133+ } else {
134+ content = downloadedContent
135+ }
136+ } else {
137+ // Regular template file processing
138+ content , err = fs .ReadFile (path .Join (templateDir , filename ))
139+ if err != nil {
140+ return fmt .Errorf ("Error reading %s: %w" , filename , err )
141+ }
120142 }
121143
122144 if err := os .WriteFile (filePath , content , 0o644 ); err != nil {
@@ -127,6 +149,31 @@ func processTemplateFile(fs embed.FS, templateDir, filename, cwd string) error {
127149 return nil
128150}
129151
152+ func downloadAgentsFile () ([]byte , error ) {
153+ const agentsURL = "https://replicate.com/docs/reference/pipelines/llms.txt"
154+
155+ client := & http.Client {
156+ Timeout : 10 * time .Second ,
157+ }
158+
159+ resp , err := client .Get (agentsURL )
160+ if err != nil {
161+ return nil , fmt .Errorf ("%w" , err )
162+ }
163+ defer resp .Body .Close ()
164+
165+ if resp .StatusCode != http .StatusOK {
166+ return nil , fmt .Errorf ("HTTP %d" , resp .StatusCode )
167+ }
168+
169+ content , err := io .ReadAll (resp .Body )
170+ if err != nil {
171+ return nil , fmt .Errorf ("failed to read response body: %w" , err )
172+ }
173+
174+ return content , nil
175+ }
176+
130177func addPipelineInit (cmd * cobra.Command ) {
131178 const pipeline = "x-pipeline"
132179 cmd .Flags ().BoolVar (& pipelineTemplate , pipeline , false , "Initialize a pipeline template" )
0 commit comments