specialist-agent 2.9.0 → 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)
@@ -208,9 +212,13 @@ function buildGettingStarted(agentNames, installedSkills, archInstalled) {
208
212
  lines.push('Agents enforce the architecture defined in docs/ARCHITECTURE.md.')
209
213
  lines.push('They ensure consistency across modules \u2014 the more you use them,')
210
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"')
211
219
  } else {
212
220
  lines.push('Agents use generic best practices for your framework.')
213
- lines.push('To customize patterns, add a docs/ARCHITECTURE.md to your project.')
221
+ lines.push('To customize patterns, run: specialist-agent detect')
214
222
  }
215
223
  lines.push('')
216
224
  lines.push('Examples:')
@@ -249,7 +257,7 @@ function buildGettingStarted(agentNames, installedSkills, archInstalled) {
249
257
 
250
258
  const args = process.argv.slice(2)
251
259
 
252
- const validCommands = ['init', 'create-agent', 'list', 'profiles', 'community']
260
+ const validCommands = ['init', 'create-agent', 'list', 'profiles', 'community', 'detect']
253
261
  const command = args.find(a => !a.startsWith('-'))
254
262
  if (command && !validCommands.includes(command)) {
255
263
  console.error(` ${YELLOW}Unknown command: ${command}${NC}`)
@@ -266,6 +274,7 @@ if (args.includes('--help') || args.includes('-h')) {
266
274
  console.log()
267
275
  console.log(' Commands:')
268
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}`)
269
278
  console.log(` create-agent <name> ${DIM}Create a custom agent from template${NC}`)
270
279
  console.log(` list ${DIM}List installed agents and skills${NC}`)
271
280
  console.log(` profiles ${DIM}Manage AI team profiles${NC}`)
@@ -753,9 +762,175 @@ async function manageCommunity() {
753
762
  }
754
763
  }
755
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
+
756
926
  // ── Command Router ───────────────────────────────────
757
927
 
758
- 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') {
759
934
  createAgent().catch(err => {
760
935
  clack.log.error(err.message)
761
936
  process.exit(1)
@@ -933,17 +1108,181 @@ async function main() {
933
1108
  }
934
1109
  }
935
1110
 
936
- // ── Architecture Guide (optional) ─────────────────
1111
+ // ── Architecture Detection & Guide ──────────────────
937
1112
 
938
1113
  let installArch = false
1114
+ let selectedArchitecture = 'modular'
1115
+ let selectedArchVariant = 'full'
1116
+ let generateCustomArch = false
939
1117
 
940
- const wantArch = await clack.confirm({
941
- message: `Install architecture guide? ${DIM}(docs/ARCHITECTURE.md)${NC}`,
942
- initialValue: false,
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
+ ],
943
1157
  })
944
1158
 
945
- if (clack.isCancel(wantArch)) handleCancel()
946
- installArch = wantArch
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
947
1286
 
948
1287
  // ── Install files ──────────────────────────────────
949
1288
 
@@ -1053,10 +1392,24 @@ async function main() {
1053
1392
  // Install ARCHITECTURE.md (only if user opted in)
1054
1393
  const archDest = join(cwd, 'docs', 'ARCHITECTURE.md')
1055
1394
  let archInstalled = false
1056
- if (installArch && !existsSync(archDest) && existsSync(archSource)) {
1057
- mkdirSync(dirname(archDest), { recursive: true })
1058
- cpSync(archSource, archDest)
1059
- 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
+ }
1060
1413
  }
1061
1414
 
1062
1415
  // Install CLAUDE.md
@@ -1078,7 +1431,11 @@ async function main() {
1078
1431
  agentNames.forEach(name => summaryLines.push(`\u2713 @${name}`))
1079
1432
  if (skillCount > 0) summaryLines.push(`\u2713 ${skillCount} skills`)
1080
1433
  if (nativeHooksInstalled > 0) summaryLines.push(`\u2713 ${nativeHooksInstalled} native hooks`)
1081
- 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
+ }
1082
1439
  if (claudeInstalled) summaryLines.push('\u2713 CLAUDE.md')
1083
1440
 
1084
1441
  const scopeLabel = installGlobal ? 'Global' : 'Project'