-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathAgentRegistry.cfc
More file actions
1148 lines (1015 loc) · 32.1 KB
/
Copy pathAgentRegistry.cfc
File metadata and controls
1148 lines (1015 loc) · 32.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Registry for AI agent configurations
* Manages agent-specific files (CLAUDE.md, AGENTS.md, .cursorrules, etc.)
*/
component singleton {
// DI
property name="print" inject="PrintBuffer";
property name="fileSystemUtil" inject="fileSystem";
property name="wirebox" inject="wirebox";
property name="utility" inject="Utility@coldbox-cli";
property name="mcpRegistry" inject="MCPRegistry@coldbox-cli";
static {
SUPPORTED_AGENTS = [
"claude",
"copilot",
"cursor",
"codex",
"gemini",
"opencode"
]
AGENT_FILES = {
"claude" : "CLAUDE.md",
"copilot" : "AGENTS.md",
"cursor" : ".cursorrules",
"codex" : "AGENTS.md",
"gemini" : "GEMINI.md",
"opencode" : "AGENTS.md"
}
// Demarcation markers that wrap the ColdBox CLI-managed section
MANAGED_SECTION_START = "<!-- COLDBOX-CLI:START -->"
MANAGED_SECTION_END = "<!-- COLDBOX-CLI:END -->"
AGENT_OPTIONS = [
{
display : "Claude (Anthropic) - Recommended for general development",
value : "claude"
},
{
display : "GitHub Copilot - Integrated with VS Code",
value : "copilot"
},
{
display : "Cursor AI - AI-first code editor",
value : "cursor"
},
{
display : "Codex (OpenAI) - GPT-powered coding assistant",
value : "codex"
},
{
display : "Gemini (Google) - Google's AI assistant",
value : "gemini"
},
{
display : "OpenCode - Open source AI assistant",
value : "opencode"
}
]
// Compiled once (singleton) — matches any public function declaration
FUNCTION_PATTERN = createObject( "java", "java.util.regex.Pattern" ).compile(
"(?i)(?:^|\s)(?:public\s+)?(?:\w+\s+)?function\s+(\w+)\s*\("
)
}
// Expose them as instance properties for easier access in commands
this.SUPPORTED_AGENTS = static.SUPPORTED_AGENTS
this.AGENT_OPTIONS = static.AGENT_OPTIONS
this.AGENT_FILES = static.AGENT_FILES
this.FUNCTION_PATTERN = static.FUNCTION_PATTERN
/**
* Configure agents for a project
*
* @directory The project directory
* @agents Comma-separated list of agents
* @language Project language mode
*/
function configureAgents(
required string directory,
required string agents,
required string language
){
return listToArray( arguments.agents ).map( ( agent ) => {
configureAgent( directory, agent, language )
return agent
} )
}
/**
* Get the config path mapping for all supported agents or a specific agent if passed
*
* @agentName Optional agent name to get specific path for (claude, copilot, cursor, codex, gemini, opencode)
*
* @return Struct with agent names as keys and config paths as values as per their conventions
*/
function getAgentConfigPaths( string agentName ){
if ( !isNull( arguments.agentName ) ) {
return static.AGENT_FILES[ arguments.agentName ] ?: "AI_INSTRUCTIONS.md"
}
return static.AGENT_FILES
}
/**
* Diagnose agent configuration health
*
* @directory The project directory
* @manifest The manifest struct
*/
function diagnose(
required string directory,
required struct manifest
){
var issues = {
"warnings" : [],
"recommendations" : []
};
// Check each configured agentr
var agents = manifest.agents ?: [];
agents.each( ( agent ) => {
var configFile = getAgentConfigPath( directory, agent )
if ( !fileExists( configFile ) ) {
issues.warnings.append( "Agent config file missing: #agent#" )
issues.recommendations.append( "Run 'coldbox ai refresh' to regenerate agent files" )
}
} )
return issues;
}
// ========================================
// Private Helpers
// ========================================
/**
* Merges newly generated managed content with any user-authored content from an existing file.
*
* The managed section is delimited by COLDBOX-CLI:START and COLDBOX-CLI:END HTML comment
* markers. On refresh, only the content between those markers is replaced; user-authored
* content before the start marker and after the end marker is preserved unchanged.
*
* Behavior:
* - File does not exist → return newContent as-is (first-time write).
* - File exists but has no start/end marker pair → return newContent as-is.
* - File exists with a start/end marker pair → replace managed section, preserve user sections.
*
* @filePath Absolute path to the existing agent config file (may not exist yet).
* @newContent Freshly generated content that includes both START and END markers.
*
* @return Combined content with updated managed section and preserved user section.
*/
private string function mergeUserContent(
required string filePath,
required string newContent
){
var startMarker = static.MANAGED_SECTION_START
var endMarker = static.MANAGED_SECTION_END
// Nothing to preserve — first-time write
if ( !fileExists( filePath ) ) {
return newContent
}
// Read existing content and locate markers
var existingContent = fileRead( filePath ).trim()
var startPos = findNoCase( startMarker, existingContent )
var endPos = findNoCase( endMarker, existingContent )
// If existing content is empty or markers are not properly found, return new content as-is
if ( !len( existingContent ) ) {
return newContent
}
// Old-format file (no marker pair) — write fresh content
if ( !startPos || !endPos || endPos <= startPos ) {
return newContent
}
// Preserve user-authored content around managed section
var userContentBeforeManaged = startPos > 1 ? left( existingContent, startPos - 1 ) : ""
var userStartPos = endPos + len( endMarker )
var userContentAfterManaged = mid(
existingContent,
userStartPos,
len( existingContent ) - userStartPos + 1
)
// Slice managed portion from the newly generated content
var newStartPos = findNoCase( startMarker, newContent )
var newEndPos = findNoCase( endMarker, newContent )
if ( !newStartPos || !newEndPos || newEndPos <= newStartPos ) {
return newContent & userContentAfterManaged
}
var managedContent = mid(
newContent,
newStartPos,
newEndPos + len( endMarker ) - newStartPos
)
return userContentBeforeManaged & managedContent & userContentAfterManaged
}
/**
* Configure a single agent
*
* @directory The project directory
* @agent The agent name (claude, copilot, cursor, etc.)
* @language Project language mode (boxlang, cfml, hybrid)
*/
function configureAgent(
required string directory,
required string agent,
required string language
){
var configPath = getAgentConfigPath( arguments.directory, arguments.agent )
var templateType = variables.utility.detectTemplateType( arguments.directory )
var content = getAgentConfigContent(
arguments.agent,
arguments.language,
templateType,
arguments.directory
)
// Create directories if needed
var configDir = getDirectoryFromPath( configPath )
if ( !directoryExists( configDir ) ) {
directoryCreate( configDir )
}
// For Claude, write the full content to AGENTS.md and make CLAUDE.md point to it
if ( arguments.agent == "claude" ) {
var agentsFilePath = getDirectoryFromPath( configPath ) & "AGENTS.md"
var mergedContent = mergeUserContent( agentsFilePath, content )
fileWrite( agentsFilePath, mergedContent )
fileWrite( configPath, "@AGENTS.md" )
return
}
// Write agent config file, preserving any user-authored content outside the managed section
fileWrite(
configPath,
mergeUserContent( configPath, content )
)
}
/**
* Get agent config file path for a specific agent on a specific project directory
*
* @directory The project directory
* @agent The agent name (claude, copilot, cursor, etc.)
*/
function getAgentConfigPath(
required string directory,
required string agent
){
// Check if directory ends in / or \ and remove it for consistent path building
if ( right( arguments.directory, 1 ) == "/" || right( arguments.directory, 1 ) == "\" ) {
arguments.directory = left(
arguments.directory,
len( arguments.directory ) - 1
)
}
switch ( arguments.agent ) {
case "claude":
return "#arguments.directory#/CLAUDE.md"
case "copilot":
return "#arguments.directory#/AGENTS.md"
case "cursor":
return "#arguments.directory#/.cursorrules"
case "codex":
return "#arguments.directory#/AGENTS.md"
case "gemini":
return "#arguments.directory#/GEMINI.md"
case "opencode":
return "#arguments.directory#/AGENTS.md"
default:
return "#arguments.directory#/AI_INSTRUCTIONS.md"
}
}
/**
* Get agent config content (reads from template)
*
* @agent The agent name (claude, copilot, cursor, etc.)
* @language Project language mode (boxlang, cfml, hybrid)
* @templateType Project template type (flat or modern)
* @directory The project directory
*/
private function getAgentConfigContent(
required string agent,
required string language,
required string templateType,
required string directory
){
var templatesPath = variables.utility.getTemplatesPath()
var templateFile = ""
// Use layout-specific templates for all agents
templateFile = arguments.templateType == "modern"
? "#templatesPath#/ai/agents/agent-modern-instructions.md"
: "#templatesPath#/ai/agents/agent-flat-instructions.md"
if ( !fileExists( templateFile ) ) {
throw(
type = "AgentRegistry.TemplateNotFound",
message = "Agent template not found: #templateFile#"
)
}
var content = fileRead( templateFile )
// Get project information
var boxJson = {}
var boxJsonPath = "#arguments.directory#/box.json"
if ( fileExists( boxJsonPath ) ) {
boxJson = deserializeJSON( fileRead( boxJsonPath ) )
}
var projectName = boxJson.name ?: getFileFromPath( arguments.directory )
var coldboxVersion = boxJson.dependencies.coldbox ?: "8.x"
// Determine language mode display
var languageMode = "BoxLang"
if ( arguments.language == "cfml" ) {
languageMode = "CFML"
} else if ( arguments.language == "hybrid" ) {
languageMode = "BoxLang/CFML Hybrid"
}
// Detect enabled features
var viteEnabled = detectViteEnabled( arguments.directory )
var dockerEnabled = detectDockerEnabled( arguments.directory )
var ormEnabled = detectOrmEnabled( boxJson )
var migrationsEnabled = detectMigrationsEnabled( arguments.directory, boxJson )
// Build features list
var enabledFeatures = []
if ( viteEnabled ) enabledFeatures.append( "Vite" )
if ( dockerEnabled ) enabledFeatures.append( "Docker" )
if ( ormEnabled ) enabledFeatures.append( "ORM" )
if ( migrationsEnabled ) enabledFeatures.append( "Migrations" )
var features = enabledFeatures.len() ? enabledFeatures.toList( ", " ) : "None"
// Replace placeholders
content = replaceNoCase(
content,
"|PROJECT_NAME|",
projectName,
"all"
)
content = replaceNoCase(
content,
"|LANGUAGE_MODE|",
languageMode,
"all"
)
content = replaceNoCase(
content,
"|COLDBOX_VERSION|",
coldboxVersion,
"all"
)
content = replaceNoCase(
content,
"|FEATURES|",
features,
"all"
)
content = replaceNoCase(
content,
"|VITE_ENABLED|",
viteEnabled ? "Yes" : "No",
"all"
)
content = replaceNoCase(
content,
"|DOCKER_ENABLED|",
dockerEnabled ? "Yes" : "No",
"all"
)
content = replaceNoCase(
content,
"|ORM_ENABLED|",
ormEnabled ? "Yes" : "No",
"all"
)
content = replaceNoCase(
content,
"|MIGRATIONS_ENABLED|",
migrationsEnabled ? "Yes" : "No",
"all"
)
// Add guidelines inventory (module and additional guidelines only)
// Language-specific guideline file and description
var languageGuidelineFile = "`.ai/guidelines/core/boxlang.md`"
var languageGuidelineDesc = "BoxLang syntax and patterns"
if ( arguments.language == "cfml" ) {
languageGuidelineFile = "`.ai/guidelines/core/cfml.md`"
languageGuidelineDesc = "CFML syntax and patterns"
} else if ( arguments.language == "hybrid" ) {
languageGuidelineFile = "`.ai/guidelines/core/boxlang.md`"
languageGuidelineDesc = "BoxLang/CFML syntax and patterns (or `cfml.md` for CFML-only)"
}
content = replaceNoCase(
content,
"|LANGUAGE_GUIDELINE_FILE|",
languageGuidelineFile,
"all"
)
content = replaceNoCase(
content,
"|LANGUAGE_GUIDELINE_DESC|",
languageGuidelineDesc,
"all"
)
// Generate installed modules content
var installedModulesContent = generateInstalledModulesContent( arguments.directory, boxJson )
content = replaceNoCase(
content,
"|INSTALLED_MODULES|",
installedModulesContent,
"all"
)
// Generate handlers snapshot
var handlersSnapshotContent = generateHandlersSnapshot(
arguments.directory,
arguments.templateType
)
content = replaceNoCase(
content,
"|HANDLERS_SNAPSHOT|",
handlersSnapshotContent,
"all"
)
// Generate interceptors snapshot
var interceptorsSnapshotContent = generateInterceptorsSnapshot(
arguments.directory,
arguments.templateType
)
content = replaceNoCase(
content,
"|INTERCEPTORS_SNAPSHOT|",
interceptorsSnapshotContent,
"all"
)
// Generate layouts snapshot
var layoutsSnapshotContent = generateLayoutsSnapshot(
arguments.directory,
arguments.templateType
)
content = replaceNoCase(
content,
"|LAYOUTS_SNAPSHOT|",
layoutsSnapshotContent,
"all"
)
// Generate custom modules snapshot
var customModulesContent = generateCustomModulesSnapshot(
arguments.directory,
arguments.templateType
)
content = replaceNoCase(
content,
"|CUSTOM_MODULES_SNAPSHOT|",
customModulesContent,
"all"
)
// Add guidelines inventory (module and additional guidelines only)
var guidelinesContent = generateGuidelinesContent(
arguments.directory,
arguments.language
)
content = replaceNoCase(
content,
"|GUIDELINES_INVENTORY|",
guidelinesContent,
"all"
)
// Add skills inventory
var skillsContent = generateSkillsContent( arguments.directory )
content = replaceNoCase(
content,
"|SKILLS_INVENTORY|",
skillsContent,
"all"
)
// Add MCP servers content
var mcpContent = generateMCPServersContent( arguments.directory )
content = replaceNoCase(
content,
"|MCP_SERVERS|",
mcpContent,
"all"
)
return content
}
/**
* Detect if Vite is enabled in the project
*/
private function detectViteEnabled( required string directory ){
var viteConfig = "#arguments.directory#/vite.config.mjs"
var packageJson = "#arguments.directory#/package.json"
if ( fileExists( viteConfig ) ) return true
if ( fileExists( packageJson ) ) {
var pkgContent = deserializeJSON( fileRead( packageJson ) )
return structKeyExists(
pkgContent.dependencies ?: {},
"vite"
) ||
structKeyExists(
pkgContent.devDependencies ?: {},
"vite"
)
}
return false
}
/**
* Detect if Docker is enabled in the project
*/
private function detectDockerEnabled( required string directory ){
return fileExists( "#arguments.directory#/Dockerfile" ) ||
fileExists( "#arguments.directory#/docker-compose.yml" )
}
/**
* Detect if ORM is enabled (cborm or quick)
*/
private function detectOrmEnabled( required struct boxJson ){
var deps = boxJson.dependencies ?: {}
var devDeps = boxJson.devDependencies ?: {}
return structKeyExists( deps, "cborm" ) ||
structKeyExists( devDeps, "cborm" ) ||
structKeyExists( deps, "quick" ) ||
structKeyExists( devDeps, "quick" )
}
/**
* Detect if migrations are enabled
*/
private function detectMigrationsEnabled(
required string directory,
required struct boxJson
){
// Check for migrations in dependencies
var deps = boxJson.dependencies ?: {}
var devDeps = boxJson.devDependencies ?: {}
if (
structKeyExists( deps, "commandbox-migrations" ) ||
structKeyExists( devDeps, "commandbox-migrations" )
) {
return true
}
// Check for migrations directory
return directoryExists( "#arguments.directory#/resources/database/migrations" )
}
/**
* Generate inline guidelines content (core framework guidelines only)
*
* @directory The project directory
* @language The project language (boxlang, cfml, hybrid)
*
* @return String containing full content of core framework guidelines
*/
private function generateInlineGuidelinesContent(
required string directory,
required string language
){
var content = [];
var guidelineManager = variables.wirebox.getInstance( "GuidelineManager@coldbox-cli" );
var aiService = variables.wirebox.getInstance( "AIService@coldbox-cli" );
var manifest = aiService.loadManifest( arguments.directory );
var coreGuidelines = manifest.guidelines.filter( ( g ) => g.type == "core" );
// Determine which guidelines to inline
var guidelinesToInline = [ "coldbox" ];
if ( arguments.language == "boxlang" || arguments.language == "hybrid" ) {
guidelinesToInline.append( "boxlang" );
}
if ( arguments.language == "cfml" || arguments.language == "hybrid" ) {
guidelinesToInline.append( "cfml" );
}
// Store directory in local variable for closure access
var projectDirectory = arguments.directory;
// Load and inline each guideline
guidelinesToInline.each( ( guidelineName ) => {
// Check if guideline is installed
var installed = coreGuidelines.filter( ( g ) => g.name == guidelineName );
if ( !installed.len() ) {
return;
}
// Get guideline content
var guidelineContent = guidelineManager.getGuidelineContent(
projectDirectory,
guidelineName,
"core"
);
if ( guidelineContent.len() ) {
content.append( "---" );
content.append( "" );
content.append( guidelineContent );
content.append( "" );
}
} );
if ( !content.len() ) {
return "No core guidelines available. Run 'coldbox ai refresh' to initialize.";
}
return content.toList( chr( 10 ) );
}
/**
* Generate guidelines inventory for agent configuration
* Excludes inlined guidelines (core framework guidelines)
*
* @directory The project directory
* @language The project language (boxlang, cfml, hybrid)
*
* @return String containing formatted guidelines inventory
*/
private function generateGuidelinesContent(
required string directory,
required string language
){
// Load manifest to get guidelines
var aiService = variables.wirebox.getInstance( "AIService@coldbox-cli" )
var manifest = aiService.loadManifest( arguments.directory )
if ( !structKeyExists( manifest, "guidelines" ) || !manifest.guidelines.len() ) {
return "No guidelines installed yet. Run 'coldbox ai install' to get started."
}
var content = [];
// Determine which guidelines are inlined (should be excluded from inventory)
var inlinedGuidelines = [ "coldbox" ];
if ( arguments.language == "boxlang" || arguments.language == "hybrid" ) {
inlinedGuidelines.append( "boxlang" );
}
if ( arguments.language == "cfml" || arguments.language == "hybrid" ) {
inlinedGuidelines.append( "cfml" );
}
// Group guidelines by type, excluding inlined ones
var coreGuidelines = manifest.guidelines.filter( ( g ) => {
return g.type == "core" && !inlinedGuidelines.find( g.name )
} );
var customGuidelines = manifest.guidelines.filter( ( g ) => g.type == "custom" );
// Core guidelines (only non-inlined ones)
if ( coreGuidelines.len() ) {
content.append( "**Additional Framework Guidelines (Available on request):**" );
content.append( "" );
coreGuidelines.each( ( guideline ) => {
var desc = structKeyExists( guideline, "description" ) ? guideline.description : "Framework guideline";
content.append( "- **#guideline.name#** - #desc#" );
} );
content.append( "" );
}
// Custom guidelines
if ( customGuidelines.len() ) {
content.append( "**Custom Guidelines:**" )
content.append( "" )
customGuidelines.each( ( guideline ) => {
var desc = structKeyExists( guideline, "description" ) ? guideline.description : "Custom guideline"
content.append( "- **#guideline.name#** - #desc#" )
} )
content.append( "" )
}
if ( !content.len() ) {
return "No additional module guidelines installed."
}
return content.toList( chr( 10 ) )
}
/**
* Generate skills inventory for agent configuration
*
* @directory The project directory
*
* @return String containing formatted skills inventory
*/
private function generateSkillsContent( required string directory ){
// Load manifest to get skills
var aiService = variables.wirebox.getInstance( "AIService@coldbox-cli" )
var manifest = aiService.loadManifest( arguments.directory )
var hasSkills = structKeyExists( manifest, "skills" ) && manifest.skills.len()
var hasCustomSkills = structKeyExists( manifest, "customSkills" ) && manifest.customSkills.len()
if ( !hasSkills && !hasCustomSkills ) {
return "No skills installed yet. Run 'coldbox ai install' to get started."
}
// Prefix-to-category mapping for grouping skill names
var prefixMap = {
"coldbox" : "ColdBox",
"boxlang" : "BoxLang",
"testbox" : "TestBox",
"commandbox" : "CommandBox",
"wirebox" : "WireBox",
"cachebox" : "CacheBox",
"logbox" : "LogBox"
}
var content = []
var coreSkills = hasSkills ? manifest.skills.filter( ( s ) => s.source == "core" ) : []
var moduleSkills = hasSkills ? manifest.skills.filter( ( s ) => s.source != "core" && s.source != "custom" ) : []
var customSkills = manifest.customSkills ?: []
// Helper: group skills by prefix and append formatted output to content
var appendGroupedSkills = ( skills, sectionLabel ) => {
if ( !skills.len() ) {
return;
}
// Build grouped struct keyed by category name
var groups = {}
skills.each( ( skill ) => {
var groupName = "Other"
for ( var prefix in prefixMap ) {
if ( skill.name.startsWith( prefix & "-" ) || skill.name == prefix ) {
groupName = prefixMap[ prefix ]
break
}
}
if ( !structKeyExists( groups, groupName ) ) {
groups[ groupName ] = []
}
groups[ groupName ].append( skill )
} )
content.append( "**#sectionLabel#:**" )
content.append( "" )
// Use for loops instead of .each() closures to avoid Lucee nested-closure scoping issues
var sortedGroupNames = groups.keyArray().sort( "textnocase" )
for ( var groupName in sortedGroupNames ) {
content.append( "_#groupName# (#groups[ groupName ].len()#):_" )
for ( var skill in groups[ groupName ] ) {
var desc = structKeyExists( skill, "description" ) && len( skill.description ) ? skill.description : "Development skill"
if ( len( desc ) > 80 ) desc = left( desc, 80 ) & "..."
content.append( "- **#skill.name#** - #desc#" )
}
content.append( "" )
}
}
appendGroupedSkills( coreSkills, "Core Skills" )
appendGroupedSkills( moduleSkills, "Module Skills" )
appendGroupedSkills( customSkills, "Custom Skills" )
content.append( "**To load a skill:** Use `read_file` on `.agents/skills/{skill-name}/SKILL.md` (e.g., `.agents/skills/coldbox-handler-development/SKILL.md`) for core skills, or `.agents/skills-custom/{skill-name}/SKILL.md` for custom project skills." )
return content.toList( chr( 10 ) )
}
/**
* Generate MCP servers content for agent configuration
*
* @directory The project directory
*
* @return String containing formatted MCP server list
*/
private function generateMCPServersContent( required string directory ){
// Load manifest to get MCP servers
var aiService = variables.wirebox.getInstance( "AIService@coldbox-cli" )
var manifest = aiService.loadManifest( arguments.directory )
if ( !structKeyExists( manifest, "mcpServers" ) ) {
return "No MCP servers configured yet. Run 'coldbox ai refresh' to initialize."
}
var mcpServers = manifest.mcpServers
var content = []
// Core servers
if ( mcpServers.core.len() ) {
content.append( "**Core Documentation Servers:**" )
content.append( "" )
mcpServers.core.each( ( mcpServer ) => {
var serverDef = variables.mcpRegistry.getServerDefinition( mcpServer )
if ( !serverDef.isEmpty() ) {
content.append( "- **#mcpServer#**: #serverDef.description# - #serverDef.url#" )
}
} )
content.append( "" )
}
// Module servers
if ( mcpServers.module.len() ) {
content.append( "**Module Documentation Servers:**" )
content.append( "" )
mcpServers.module.each( ( mcpServer ) => {
var serverDef = variables.mcpRegistry.getServerDefinition( mcpServer )
if ( !serverDef.isEmpty() ) {
content.append( "- **#mcpServer#**: #serverDef.description# - #serverDef.url#" )
}
} )
content.append( "" )
}
// Custom servers
if ( mcpServers.custom.len() ) {
content.append( "**Custom Documentation Servers:**" )
content.append( "" )
mcpServers.custom.each( ( mcpServer ) => {
var desc = mcpServer.description ?: "Custom MCP server"
var details = ""
if ( structKeyExists( mcpServer, "url" ) ) {
details = " - #mcpServer.url#"
} else if ( structKeyExists( mcpServer, "command" ) ) {
details = " - Command: #mcpServer.command#"
}
content.append( "- **#mcpServer.name#**: #desc##details#" )
} )
content.append( "" )
}
content.append( "**Using MCP Servers:** Query these servers when you need current documentation, API references, or code examples. They provide live, up-to-date information directly from official documentation sources." )
return content.toList( chr( 10 ) )
}
/**
* Generate a list of installed project modules (excluding framework packages)
*
* @directory The project directory
* @boxJson The parsed box.json struct
*
* @return Formatted markdown bullet list of installed modules
*/
private function generateInstalledModulesContent(
required string directory,
required struct boxJson
){
// Packages to skip — framework internals that aren't actionable for the AI
var frameworkPackages = [
"coldbox",
"testbox",
"wirebox",
"cachebox",
"logbox"
]
var dependencies = arguments.boxJson.dependencies ?: {}
var lines = []
for ( var pkg in dependencies ) {
// Skip framework packages and commandbox-* infrastructure packages
if ( frameworkPackages.findNoCase( pkg ) || pkg.startsWith( "commandbox-" ) ) {
continue;
}
var version = dependencies[ pkg ]
lines.append( "- **#pkg#** (#version#)" )
}
if ( !lines.len() ) {
return "No additional modules installed yet."
}
lines.sort( "textnocase" )
return lines.toList( chr( 10 ) )
}
/**
* Generate a snapshot of existing handlers and their public actions
*
* @directory The project directory
* @templateType "modern" or "flat"
*
* @return Formatted markdown bullet list of handlers and their actions
*/
private function generateHandlersSnapshot(
required string directory,
required string templateType
){
var handlersRoot = arguments.templateType == "modern"
? "#arguments.directory#/app/handlers"
: "#arguments.directory#/handlers"
if ( !directoryExists( handlersRoot ) ) {
return "No handlers found."
}
// Lifecycle / framework methods to exclude from the action list
var lifecycleMethods = [
"init",
"onmissingaction",
"onerror",
"onrequeststart",
"onrequestend",
"onapplicationstart",
"onsessionstart",
"onsessionend",
"onapplicationend"
]
var handlerFiles = directoryList(
handlersRoot,
false,
"path",
"*.cfc|*.bx"
)
var lines = []
for ( var handlerFile in handlerFiles ) {
var handlerName = listFirst( getFileFromPath( handlerFile ), "." )
var actions = extractFunctionNames(
fileRead( handlerFile ),
lifecycleMethods
)
lines.append(
actions.len()
? "- **#handlerName#**: #actions.toList( ", " )#"
: "- **#handlerName#**: _(no public actions)_"
)
}
if ( !lines.len() ) {
return "No handlers found."
}
lines.sort( "textnocase" )
return lines.toList( chr( 10 ) )
}
/**
* Generate a snapshot of existing interceptors and their interception point methods
*
* @directory The project directory
* @templateType "modern" or "flat"
*
* @return Formatted markdown bullet list of interceptors and their announced points
*/
private function generateInterceptorsSnapshot(
required string directory,
required string templateType
){
var interceptorsRoot = arguments.templateType == "modern"
? "#arguments.directory#/app/interceptors"
: "#arguments.directory#/interceptors"
if ( !directoryExists( interceptorsRoot ) ) {
return "No interceptors found."
}
// Methods to exclude — framework inherited methods, not interception points
var excludedMethods = [
"init",
"configure",
"getproperty",
"setproperty",
"getproperties"
]
var interceptorFiles = directoryList(
interceptorsRoot,
false,
"path",
"*.cfc|*.bx"
)
var lines = []
for ( var interceptorFile in interceptorFiles ) {
var interceptorName = listFirst(
getFileFromPath( interceptorFile ),