@@ -7,7 +7,6 @@ import 'package:path/path.dart' as path;
77import 'package:serinus_cli/src/utils/config.dart' ; // Reuse your Config logic
88
99class AgentsCommand extends Command <int > {
10-
1110 AgentsCommand ({required Logger logger}) : _logger = logger {
1211 argParser.addFlag (
1312 'claude' ,
@@ -19,7 +18,8 @@ class AgentsCommand extends Command<int> {
1918 final String name = 'agents' ;
2019
2120 @override
22- final String description = 'Generates AGENTS.md and CLAUDE.md and downloads local docs for AI context.' ;
21+ final String description =
22+ 'Generates AGENTS.md and CLAUDE.md and downloads local docs for AI context.' ;
2323
2424 final Logger _logger;
2525
@@ -31,17 +31,45 @@ class AgentsCommand extends Command<int> {
3131 // We can reuse getProjectConfiguration logic or read pubspec directly
3232 final config = await getProjectConfiguration (_logger, deps: true );
3333 final serinusVersion = config.dependencies['serinus' ];
34-
34+
3535 // Fallback if version is a path or git dependency, otherwise strict version
36- var versionTag = _parseVersion (serinusVersion);
36+ var versionTag = _parseVersion (serinusVersion);
3737 _logger.detail ('Detected Serinus version: $versionTag ' );
3838
3939 // 2. Define Docs to Download
4040 // You can fetch the file list dynamically from GitHub API or hardcode the structure based on your config.mts sidebar
4141 final docsMap = {
42- 'overview' : ['modules.md' , 'controllers.md' , 'routes.md' , 'hooks.md' , 'middlewares.md' , 'providers.md' , 'pipes.md' , 'metadata.md' , 'exception_filters.md' ],
43- 'techniques' : ['database.md' , 'configuration.md' , 'logging.md' , 'sse.md' , 'task_scheduling.md' , 'file_uploads.md' , 'mvc.md' , 'serve_static.md' , 'versioning.md' , 'global_prefix.md' , 'session.md' , 'model_provider.md' ],
44- 'security' : ['rate_limiting.md' , 'cors.md' , 'body_size.md' , 'authentication.md' ],
42+ 'overview' : [
43+ 'modules.md' ,
44+ 'controllers.md' ,
45+ 'routes.md' ,
46+ 'hooks.md' ,
47+ 'middlewares.md' ,
48+ 'providers.md' ,
49+ 'pipes.md' ,
50+ 'metadata.md' ,
51+ 'exception_filters.md'
52+ ],
53+ 'techniques' : [
54+ 'database.md' ,
55+ 'configuration.md' ,
56+ 'logging.md' ,
57+ 'sse.md' ,
58+ 'task_scheduling.md' ,
59+ 'file_uploads.md' ,
60+ 'mvc.md' ,
61+ 'serve_static.md' ,
62+ 'versioning.md' ,
63+ 'global_prefix.md' ,
64+ 'session.md' ,
65+ 'model_provider.md'
66+ ],
67+ 'security' : [
68+ 'rate_limiting.md' ,
69+ 'cors.md' ,
70+ 'body_size.md' ,
71+ 'authentication.md'
72+ ],
4573 'openapi' : ['index.md' , 'advanced_usage.md' , 'renderer.md' ],
4674 'websockets' : ['gateways.md' , 'exception_filters.md' , 'pipes.md' ],
4775 'comparisons' : ['dart_frog.md' , 'shelf.md' ],
@@ -50,13 +78,15 @@ class AgentsCommand extends Command<int> {
5078 'deployment' : ['docker.md' , 'globe.md' , 'vps.md' , 'cloud_run.md' ],
5179 };
5280
53- final docsDir = Directory (path.join (Directory .current.path, '.serinus-docs' ));
81+ final docsDir =
82+ Directory (path.join (Directory .current.path, '.serinus-docs' ));
5483 if (! docsDir.existsSync ()) {
5584 docsDir.createSync ();
5685 }
5786
5887 // 3. Download Files
59- var baseUrl = 'https://raw.githubusercontent.com/francescovallone/serinus/$versionTag /.website' ;
88+ var baseUrl =
89+ 'https://raw.githubusercontent.com/francescovallone/serinus/$versionTag /.website' ;
6090 if (versionTag == 'any' || versionTag == 'main' || versionTag == 'latest' ) {
6191 versionTag = 'main' ;
6292 }
@@ -66,30 +96,31 @@ class AgentsCommand extends Command<int> {
6696 final checkResponse = await http.get (checkUrl);
6797 print ('Checking URL: $checkUrl - Status: ${checkResponse .statusCode }' );
6898 if (checkResponse.statusCode != 200 ) {
69- _logger.warn ('Version $versionTag not found on GitHub, falling back to main branch for docs.' );
99+ _logger.warn (
100+ 'Version $versionTag not found on GitHub, falling back to main branch for docs.' );
70101 versionTag = 'main' ;
71102 }
72103 }
73- baseUrl = 'https://raw.githubusercontent.com/francescovallone/serinus/$versionTag /.website' ;
104+ baseUrl =
105+ 'https://raw.githubusercontent.com/francescovallone/serinus/$versionTag /.website' ;
74106 final progress = _logger.progress ('Downloading documentation...' );
75107 try {
76108 for (final category in docsMap.keys) {
77109 final categoryDir = Directory (path.join (docsDir.path, category));
78110 if (! categoryDir.existsSync ()) categoryDir.createSync ();
79111
80112 for (final file in docsMap[category]! ) {
81- // Handle the path structure in your repo (some are in root, some in subfolders)
82- // Based on your file list, many are directly in .website or .website/techniques
83- final remotePath = category == 'overview'
84- ? file
85- : '$category /$file ' ;
86-
87- final url = Uri .parse ('$baseUrl /$remotePath ' );
88- final response = await http.get (url);
89-
90- if (response.statusCode == 200 ) {
91- File (path.join (categoryDir.path, file)).writeAsStringSync (response.body);
92- }
113+ // Handle the path structure in your repo (some are in root, some in subfolders)
114+ // Based on your file list, many are directly in .website or .website/techniques
115+ final remotePath = category == 'overview' ? file : '$category /$file ' ;
116+
117+ final url = Uri .parse ('$baseUrl /$remotePath ' );
118+ final response = await http.get (url);
119+
120+ if (response.statusCode == 200 ) {
121+ File (path.join (categoryDir.path, file))
122+ .writeAsStringSync (response.body);
123+ }
93124 }
94125 }
95126 progress.complete ('Documentation downloaded to .serinus-docs/' );
@@ -107,21 +138,23 @@ class AgentsCommand extends Command<int> {
107138 String _parseVersion (dynamic version) {
108139 // Logic to strip caret ^ or handle 'any'. Default to 'main' if unknown.
109140 if (version is String ) {
110- return version.replaceAll ('^' , '' ).replaceAll ('~' , '' );
141+ return version.replaceAll ('^' , '' ).replaceAll ('~' , '' );
111142 }
112- return 'main' ;
143+ return 'main' ;
113144 }
114145
115146 void _generateAgentsMd (Map <String , List <String >> docsMap) {
116147 final buffer = StringBuffer ()
117- ..write ('<!--- SERINUS-AGENTS-MD-START -->' )
118- // Create the compressed index format Vercel recommends
119- ..write ('[Serinus Docs Index]|root: ./.serinus-docs' )
120- ..write ('|IMPORTANT: Prefer retrieval-led reasoning over pre-training-led reasoning for any Serinus related queries.' )
121- ..write ('|If docs missing run `serinus agents` to download the latest version.' );
148+ ..write ('<!--- SERINUS-AGENTS-MD-START -->' )
149+ // Create the compressed index format Vercel recommends
150+ ..write ('[Serinus Docs Index]|root: ./.serinus-docs' )
151+ ..write (
152+ '|IMPORTANT: Prefer retrieval-led reasoning over pre-training-led reasoning for any Serinus related queries.' )
153+ ..write (
154+ '|If docs missing run `serinus agents` to download the latest version.' );
122155 docsMap.forEach ((category, files) {
123- // Format: |category:{file1.md,file2.md}
124- buffer.write ('|$category :{${files .join (',' )}}' );
156+ // Format: |category:{file1.md,file2.md}
157+ buffer.write ('|$category :{${files .join (',' )}}' );
125158 });
126159 buffer.writeln ('<!--- SERINUS-AGENTS-MD-END -->' );
127160 File (path.join (Directory .current.path, 'AGENTS.md' )).writeAsStringSync (
@@ -133,9 +166,9 @@ class AgentsCommand extends Command<int> {
133166 buffer.toString (),
134167 );
135168 }
136-
169+
137170 _logger.success ('Generated AGENTS.md' );
138171 }
139172
140173 bool get claude => argResults? ['claude' ] as bool ? ?? false ;
141- }
174+ }
0 commit comments