specialist-agent 2.8.1 → 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cli/index.mjs CHANGED
@@ -6,6 +6,10 @@ import { execFileSync } from 'child_process'
6
6
  import { join, dirname, resolve } from 'path'
7
7
  import { fileURLToPath } from 'url'
8
8
  import { homedir } from 'os'
9
+ import { ARCHITECTURE_PATTERNS, MIGRATION_MAP } from './architectures.mjs'
10
+ import { detectProjectArchitecture, generateDetectionReport } from './detect-architecture.mjs'
11
+ import { getRecommendations } from './recommend-architecture.mjs'
12
+ import { generateArchitectureGuide } from './generate-architecture.mjs'
9
13
 
10
14
  const __filename = fileURLToPath(import.meta.url)
11
15
  const __dirname = dirname(__filename)
@@ -201,12 +205,21 @@ function detectFramework(pkgPath, availablePacks) {
201
205
 
202
206
  // ── Guidance texts ───────────────────────────────────
203
207
 
204
- function buildGettingStarted(agentNames, installedSkills) {
208
+ function buildGettingStarted(agentNames, installedSkills, archInstalled) {
205
209
  const lines = []
206
210
 
207
- lines.push('Agents enforce the architecture defined in docs/ARCHITECTURE.md.')
208
- lines.push('They ensure consistency across modules \u2014 the more you use them,')
209
- lines.push('the more value they deliver.')
211
+ if (archInstalled) {
212
+ lines.push('Agents enforce the architecture defined in docs/ARCHITECTURE.md.')
213
+ lines.push('They ensure consistency across modules \u2014 the more you use them,')
214
+ lines.push('the more value they deliver.')
215
+ lines.push('')
216
+ lines.push('To migrate your project to the new architecture:')
217
+ lines.push(' > "Use /migrate-architecture to restructure my project"')
218
+ lines.push(' > "Use @architect to assess my current architecture"')
219
+ } else {
220
+ lines.push('Agents use generic best practices for your framework.')
221
+ lines.push('To customize patterns, run: specialist-agent detect')
222
+ }
210
223
  lines.push('')
211
224
  lines.push('Examples:')
212
225
  lines.push('')
@@ -244,7 +257,7 @@ function buildGettingStarted(agentNames, installedSkills) {
244
257
 
245
258
  const args = process.argv.slice(2)
246
259
 
247
- const validCommands = ['init', 'create-agent', 'list', 'profiles', 'community']
260
+ const validCommands = ['init', 'create-agent', 'list', 'profiles', 'community', 'detect']
248
261
  const command = args.find(a => !a.startsWith('-'))
249
262
  if (command && !validCommands.includes(command)) {
250
263
  console.error(` ${YELLOW}Unknown command: ${command}${NC}`)
@@ -261,6 +274,7 @@ if (args.includes('--help') || args.includes('-h')) {
261
274
  console.log()
262
275
  console.log(' Commands:')
263
276
  console.log(` init ${DIM}Install agents and skills in your project${NC}`)
277
+ console.log(` detect ${DIM}Detect project architecture, monorepo, and suggest migrations${NC}`)
264
278
  console.log(` create-agent <name> ${DIM}Create a custom agent from template${NC}`)
265
279
  console.log(` list ${DIM}List installed agents and skills${NC}`)
266
280
  console.log(` profiles ${DIM}Manage AI team profiles${NC}`)
@@ -748,9 +762,175 @@ async function manageCommunity() {
748
762
  }
749
763
  }
750
764
 
765
+ // ── Detect Command ──────────────────────────────────
766
+
767
+ async function detectArchitecture() {
768
+ const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf-8'))
769
+ clack.intro(`Architecture Detection ${DIM}v${pkg.version}${NC}`)
770
+
771
+ const cwd = process.cwd()
772
+ const isJson = args.includes('--json')
773
+
774
+ // Detect framework
775
+ const packs = readdirSync(join(ROOT, 'packs'), { withFileTypes: true })
776
+ .filter(d => d.isDirectory())
777
+ .map(d => d.name)
778
+ const framework = detectFramework(join(cwd, 'package.json'), packs)
779
+
780
+ // Run detection
781
+ const s = clack.spinner()
782
+ s.start('Scanning project structure...')
783
+
784
+ const result = detectProjectArchitecture(cwd, { framework })
785
+
786
+ s.stop('Detection complete')
787
+
788
+ if (isJson) {
789
+ console.log(JSON.stringify(result, null, 2))
790
+ return
791
+ }
792
+
793
+ // Display report
794
+ const report = generateDetectionReport(result)
795
+ clack.note(report, 'Architecture Detection')
796
+
797
+ // Get recommendations
798
+ const teamSize = await clack.select({
799
+ message: 'Team size (for recommendations)?',
800
+ options: [
801
+ { value: 'small', label: '1-3 developers', hint: 'Solo or small team' },
802
+ { value: 'medium', label: '3-10 developers', hint: 'Medium team' },
803
+ { value: 'large', label: '10-20 developers', hint: 'Large team' },
804
+ { value: 'enterprise', label: '20+ developers', hint: 'Enterprise' },
805
+ ],
806
+ })
807
+
808
+ if (clack.isCancel(teamSize)) handleCancel()
809
+
810
+ const recs = getRecommendations(result, { teamSize })
811
+
812
+ // Display recommendations
813
+ const recLines = []
814
+ recLines.push(recs.reason)
815
+ recLines.push('')
816
+
817
+ if (recs.monorepoNote) {
818
+ recLines.push(recs.monorepoNote)
819
+ recLines.push('')
820
+ }
821
+
822
+ for (const rec of recs.recommendations) {
823
+ const tagLabel = rec.tag === 'recommended' ? `${GREEN}RECOMMENDED${NC}`
824
+ : rec.tag === 'backend-recommended' ? `${YELLOW}BACKEND${NC}`
825
+ : `${DIM}ALTERNATIVE${NC}`
826
+ const sameNote = rec.isSameArch ? ` ${DIM}(current)${NC}` : ''
827
+
828
+ recLines.push(` ${tagLabel} ${BOLD}${rec.name}${NC}${sameNote}`)
829
+ recLines.push(` ${DIM}${rec.description}${NC}`)
830
+
831
+ if (rec.migration) {
832
+ const effortColor = rec.migration.effort === 'low' ? GREEN : rec.migration.effort === 'medium' ? YELLOW : RED
833
+ recLines.push(` Migration: ${effortColor}${rec.migration.effort}${NC} - ${rec.migration.description}`)
834
+ recLines.push(` Agents: ${rec.migration.agents.join(', ')}`)
835
+ }
836
+
837
+ recLines.push(` Variants:`)
838
+ for (const v of rec.variants) {
839
+ recLines.push(` ${BOLD}${v.name}${NC}: ${v.description.slice(0, 100)}${v.description.length > 100 ? '...' : ''}`)
840
+ if (v.directoryStructure) {
841
+ for (const line of v.directoryStructure.slice(0, 6)) {
842
+ recLines.push(` ${DIM}${line}${NC}`)
843
+ }
844
+ if (v.directoryStructure.length > 6) {
845
+ recLines.push(` ${DIM}... (${v.directoryStructure.length - 6} more)${NC}`)
846
+ }
847
+ }
848
+ }
849
+ recLines.push('')
850
+ }
851
+
852
+ // Framework notes
853
+ if (recs.frameworkNotes) {
854
+ recLines.push(`${BOLD}Framework Notes:${NC}`)
855
+ for (const note of recs.frameworkNotes.extraNotes) {
856
+ recLines.push(` - ${note}`)
857
+ }
858
+ if (recs.frameworkNotes.preferredStateManagement) {
859
+ recLines.push(` State management: ${recs.frameworkNotes.preferredStateManagement}`)
860
+ }
861
+ }
862
+
863
+ clack.note(recLines.join('\n'), 'Architecture Recommendations')
864
+
865
+ // Offer to generate ARCHITECTURE.md
866
+ const generateArch = await clack.confirm({
867
+ message: 'Generate docs/ARCHITECTURE.md for the recommended architecture?',
868
+ initialValue: false,
869
+ })
870
+
871
+ if (clack.isCancel(generateArch)) handleCancel()
872
+
873
+ if (generateArch && recs.recommendations.length > 0) {
874
+ const archChoice = recs.recommendations.length > 1
875
+ ? await clack.select({
876
+ message: 'Which architecture?',
877
+ options: recs.recommendations.map(r => ({
878
+ value: r.id,
879
+ label: r.name,
880
+ hint: r.tag === 'recommended' ? 'Recommended' : r.tag,
881
+ })),
882
+ })
883
+ : recs.recommendations[0].id
884
+
885
+ if (clack.isCancel(archChoice)) handleCancel()
886
+
887
+ const variantChoice = await clack.select({
888
+ message: 'Which variant?',
889
+ options: [
890
+ { value: 'full', label: 'Full', hint: 'All layers and patterns' },
891
+ { value: 'lite', label: 'Simplified', hint: 'Fewer layers, same principles' },
892
+ ],
893
+ })
894
+
895
+ if (clack.isCancel(variantChoice)) handleCancel()
896
+
897
+ const guide = generateArchitectureGuide({
898
+ architecture: archChoice,
899
+ framework: framework || 'react',
900
+ variant: variantChoice,
901
+ nextjsRouter: result.nextjsRouter,
902
+ })
903
+
904
+ const archDest = join(cwd, 'docs', 'ARCHITECTURE.md')
905
+ if (existsSync(archDest)) {
906
+ const overwrite = await clack.confirm({
907
+ message: 'docs/ARCHITECTURE.md already exists. Overwrite?',
908
+ initialValue: false,
909
+ })
910
+ if (clack.isCancel(overwrite)) handleCancel()
911
+ if (!overwrite) {
912
+ clack.log.info('Skipped ARCHITECTURE.md generation.')
913
+ clack.outro('Detection complete!')
914
+ return
915
+ }
916
+ }
917
+
918
+ mkdirSync(dirname(archDest), { recursive: true })
919
+ writeFileSync(archDest, guide)
920
+ clack.log.success(`Generated docs/ARCHITECTURE.md (${ARCHITECTURE_PATTERNS[archChoice]?.name || archChoice} - ${variantChoice})`)
921
+ }
922
+
923
+ clack.outro('Detection complete! Use /migrate-architecture to apply changes.')
924
+ }
925
+
751
926
  // ── Command Router ───────────────────────────────────
752
927
 
753
- if (command === 'create-agent') {
928
+ if (command === 'detect') {
929
+ detectArchitecture().catch(err => {
930
+ clack.log.error(err.message)
931
+ process.exit(1)
932
+ })
933
+ } else if (command === 'create-agent') {
754
934
  createAgent().catch(err => {
755
935
  clack.log.error(err.message)
756
936
  process.exit(1)
@@ -928,6 +1108,182 @@ async function main() {
928
1108
  }
929
1109
  }
930
1110
 
1111
+ // ── Architecture Detection & Guide ──────────────────
1112
+
1113
+ let installArch = false
1114
+ let selectedArchitecture = 'modular'
1115
+ let selectedArchVariant = 'full'
1116
+ let generateCustomArch = false
1117
+
1118
+ // Detect current architecture
1119
+ const archDetection = detectProjectArchitecture(cwd, { framework })
1120
+ const detectedArch = archDetection.architecture
1121
+ const detectedArchName = ARCHITECTURE_PATTERNS[detectedArch]?.name || detectedArch
1122
+
1123
+ if (detectedArch && detectedArch !== 'unstructured') {
1124
+ clack.log.info(`Detected architecture: ${BOLD}${detectedArchName}${NC}`)
1125
+ }
1126
+
1127
+ // Monorepo detection
1128
+ if (archDetection.monorepo) {
1129
+ clack.log.info(`Monorepo detected: ${BOLD}${archDetection.monorepo.name}${NC} (${archDetection.monorepo.apps.length} apps/packages)`)
1130
+ }
1131
+
1132
+ // Ask about architecture
1133
+ const archAction = await clack.select({
1134
+ message: 'Architecture guide for your project?',
1135
+ options: [
1136
+ {
1137
+ value: 'detect-and-suggest',
1138
+ label: 'Detect & suggest improvements',
1139
+ hint: 'Analyze current architecture and recommend best practices',
1140
+ },
1141
+ {
1142
+ value: 'choose',
1143
+ label: 'Choose a specific architecture',
1144
+ hint: 'Pick from our catalog of patterns (Modular, Clean, Hexagonal, DDD, ...)',
1145
+ },
1146
+ {
1147
+ value: 'default',
1148
+ label: `Use default (Modular)`,
1149
+ hint: 'Install the standard modular ARCHITECTURE.md',
1150
+ },
1151
+ {
1152
+ value: 'skip',
1153
+ label: 'Skip',
1154
+ hint: 'No architecture guide',
1155
+ },
1156
+ ],
1157
+ })
1158
+
1159
+ if (clack.isCancel(archAction)) handleCancel()
1160
+
1161
+ if (archAction === 'detect-and-suggest') {
1162
+ // Ask team size for better recommendations
1163
+ const teamSize = await clack.select({
1164
+ message: 'Team size?',
1165
+ options: [
1166
+ { value: 'small', label: '1-3 developers' },
1167
+ { value: 'medium', label: '3-10 developers' },
1168
+ { value: 'large', label: '10-20 developers' },
1169
+ { value: 'enterprise', label: '20+ developers' },
1170
+ ],
1171
+ })
1172
+
1173
+ if (clack.isCancel(teamSize)) handleCancel()
1174
+
1175
+ const recs = getRecommendations(archDetection, { teamSize })
1176
+
1177
+ // Show recommendations
1178
+ const recOptions = []
1179
+ for (const rec of recs.recommendations) {
1180
+ const tagPrefix = rec.tag === 'recommended' ? '[RECOMMENDED] '
1181
+ : rec.tag === 'backend-recommended' ? '[BACKEND] '
1182
+ : ''
1183
+ const effortNote = rec.migration ? ` (effort: ${rec.migration.effort})` : ''
1184
+ const sameNote = rec.isSameArch ? ' (current)' : ''
1185
+
1186
+ recOptions.push({
1187
+ value: rec.id,
1188
+ label: `${tagPrefix}${rec.name}${sameNote}`,
1189
+ hint: `${rec.description.slice(0, 60)}${effortNote}`,
1190
+ })
1191
+ }
1192
+
1193
+ recOptions.push({ value: 'skip', label: 'Skip', hint: 'No architecture guide' })
1194
+
1195
+ if (recs.reason) {
1196
+ clack.log.info(recs.reason)
1197
+ }
1198
+
1199
+ const archChoice = await clack.select({
1200
+ message: 'Which architecture to adopt?',
1201
+ options: recOptions,
1202
+ })
1203
+
1204
+ if (clack.isCancel(archChoice)) handleCancel()
1205
+
1206
+ if (archChoice !== 'skip') {
1207
+ selectedArchitecture = archChoice
1208
+ installArch = true
1209
+ generateCustomArch = true
1210
+
1211
+ // Choose variant
1212
+ const chosenRec = recs.recommendations.find(r => r.id === archChoice)
1213
+ if (chosenRec?.variants.length > 0) {
1214
+ const variantOptions = chosenRec.variants.map(v => ({
1215
+ value: v.id,
1216
+ label: v.name,
1217
+ hint: v.description.slice(0, 70),
1218
+ }))
1219
+
1220
+ const variantChoice = await clack.select({
1221
+ message: 'Which variant?',
1222
+ options: variantOptions,
1223
+ })
1224
+
1225
+ if (clack.isCancel(variantChoice)) handleCancel()
1226
+ selectedArchVariant = variantChoice
1227
+ }
1228
+
1229
+ // Show directory preview
1230
+ const chosenVariant = chosenRec?.variants.find(v => v.id === selectedArchVariant)
1231
+ if (chosenVariant?.directoryStructure) {
1232
+ clack.note(
1233
+ chosenVariant.directoryStructure.join('\n'),
1234
+ `${ARCHITECTURE_PATTERNS[selectedArchitecture]?.name || selectedArchitecture} (${selectedArchVariant})`
1235
+ )
1236
+ }
1237
+
1238
+ // If it's a migration, show migration info
1239
+ if (chosenRec?.migration && !chosenRec.isSameArch) {
1240
+ clack.log.info(`${DIM}Migration: ${chosenRec.migration.description}${NC}`)
1241
+ clack.log.info(`${DIM}After install, use /migrate-architecture to execute the migration.${NC}`)
1242
+ clack.log.info(`${DIM}Agents: ${chosenRec.migration.agents.join(', ')}${NC}`)
1243
+ }
1244
+ }
1245
+ } else if (archAction === 'choose') {
1246
+ // Direct architecture selection
1247
+ const archOptions = [
1248
+ { value: 'modular', label: 'Modular (Feature-Based)', hint: 'Recommended for most projects' },
1249
+ { value: 'clean', label: 'Clean Architecture', hint: 'Domain > Use Cases > Adapters > Frameworks' },
1250
+ { value: 'hexagonal', label: 'Hexagonal (Ports & Adapters)', hint: 'Core isolated, infrastructure swappable' },
1251
+ { value: 'fsd', label: 'Feature-Sliced Design', hint: 'Strict layered: app > pages > features > entities > shared' },
1252
+ { value: 'ddd', label: 'Domain-Driven Design', hint: 'Bounded contexts, aggregates, domain events' },
1253
+ { value: 'modular-monolith', label: 'Modular Monolith', hint: 'Single deploy, strict boundaries (backend/fullstack)' },
1254
+ { value: 'atomic', label: 'Atomic Design', hint: 'Components by granularity: atoms > molecules > organisms' },
1255
+ { value: 'cqrs', label: 'CQRS', hint: 'Separate command/query paths (backend)' },
1256
+ { value: 'mvc', label: 'MVC / Layered', hint: 'Classic horizontal slicing (backend)' },
1257
+ ]
1258
+
1259
+ const archChoice = await clack.select({
1260
+ message: 'Which architecture pattern?',
1261
+ options: archOptions,
1262
+ })
1263
+
1264
+ if (clack.isCancel(archChoice)) handleCancel()
1265
+ selectedArchitecture = archChoice
1266
+ installArch = true
1267
+ generateCustomArch = true
1268
+
1269
+ // Variant
1270
+ const variantChoice = await clack.select({
1271
+ message: 'Which variant?',
1272
+ options: [
1273
+ { value: 'full', label: 'Full', hint: 'All layers and patterns - for established teams' },
1274
+ { value: 'lite', label: 'Simplified', hint: 'Fewer layers, same principles - for smaller teams' },
1275
+ ],
1276
+ })
1277
+
1278
+ if (clack.isCancel(variantChoice)) handleCancel()
1279
+ selectedArchVariant = variantChoice
1280
+ } else if (archAction === 'default') {
1281
+ installArch = true
1282
+ selectedArchitecture = 'modular'
1283
+ selectedArchVariant = 'full'
1284
+ }
1285
+ // archAction === 'skip': installArch remains false
1286
+
931
1287
  // ── Install files ──────────────────────────────────
932
1288
 
933
1289
  const packDir = join(ROOT, 'packs', framework)
@@ -1033,13 +1389,27 @@ async function main() {
1033
1389
  nativeHooksInstalled = setupNativeHooks(cwd, selectedHooks)
1034
1390
  }
1035
1391
 
1036
- // Install ARCHITECTURE.md
1392
+ // Install ARCHITECTURE.md (only if user opted in)
1037
1393
  const archDest = join(cwd, 'docs', 'ARCHITECTURE.md')
1038
1394
  let archInstalled = false
1039
- if (!existsSync(archDest) && existsSync(archSource)) {
1040
- mkdirSync(dirname(archDest), { recursive: true })
1041
- cpSync(archSource, archDest)
1042
- archInstalled = true
1395
+ if (installArch) {
1396
+ if (generateCustomArch) {
1397
+ // Generate architecture guide for the selected pattern + framework + variant
1398
+ const guide = generateArchitectureGuide({
1399
+ architecture: selectedArchitecture,
1400
+ framework,
1401
+ variant: selectedArchVariant,
1402
+ nextjsRouter: archDetection.nextjsRouter,
1403
+ })
1404
+ mkdirSync(dirname(archDest), { recursive: true })
1405
+ writeFileSync(archDest, guide)
1406
+ archInstalled = true
1407
+ } else if (!existsSync(archDest) && existsSync(archSource)) {
1408
+ // Fallback to pack default
1409
+ mkdirSync(dirname(archDest), { recursive: true })
1410
+ cpSync(archSource, archDest)
1411
+ archInstalled = true
1412
+ }
1043
1413
  }
1044
1414
 
1045
1415
  // Install CLAUDE.md
@@ -1061,7 +1431,11 @@ async function main() {
1061
1431
  agentNames.forEach(name => summaryLines.push(`\u2713 @${name}`))
1062
1432
  if (skillCount > 0) summaryLines.push(`\u2713 ${skillCount} skills`)
1063
1433
  if (nativeHooksInstalled > 0) summaryLines.push(`\u2713 ${nativeHooksInstalled} native hooks`)
1064
- if (archInstalled) summaryLines.push('\u2713 docs/ARCHITECTURE.md')
1434
+ if (archInstalled) {
1435
+ const archLabel = ARCHITECTURE_PATTERNS[selectedArchitecture]?.name || selectedArchitecture
1436
+ const varLabel = selectedArchVariant === 'lite' ? ' (Simplified)' : ''
1437
+ summaryLines.push(`\u2713 docs/ARCHITECTURE.md (${archLabel}${varLabel})`)
1438
+ }
1065
1439
  if (claudeInstalled) summaryLines.push('\u2713 CLAUDE.md')
1066
1440
 
1067
1441
  const scopeLabel = installGlobal ? 'Global' : 'Project'
@@ -1080,7 +1454,7 @@ async function main() {
1080
1454
  ? readdirSync(skillsDest, { withFileTypes: true }).filter(d => d.isDirectory()).map(d => '/' + d.name)
1081
1455
  : []
1082
1456
 
1083
- clack.note(buildGettingStarted(agentNames, installedSkills), 'Getting started')
1457
+ clack.note(buildGettingStarted(agentNames, installedSkills, archInstalled), 'Getting started')
1084
1458
 
1085
1459
  if (mode === 'lite') {
1086
1460
  clack.log.info(`${DIM}Lite mode: agents run on Haiku (lower cost, faster).${NC}`)