@mrpatronz/nexusflow 0.2.13 → 0.2.17

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.
Files changed (186) hide show
  1. package/.github/dependabot.yml +52 -52
  2. package/.github/workflows/dependabot-merge.yml +53 -0
  3. package/.github/workflows/release.yml +112 -100
  4. package/.vscode/launch.json +17 -17
  5. package/.vscode/tasks.json +17 -17
  6. package/GETTING_STARTED.md +114 -109
  7. package/README.md +336 -311
  8. package/desktop/build-installer.js +228 -0
  9. package/desktop/build.js +118 -0
  10. package/desktop/installer/nexusflow.iss +35 -0
  11. package/desktop/neutralino.config.json +39 -0
  12. package/desktop/package-lock.json +1060 -0
  13. package/desktop/package.json +14 -0
  14. package/dist/commands/desktop.d.ts +12 -0
  15. package/dist/commands/desktop.d.ts.map +1 -0
  16. package/dist/commands/desktop.js +119 -0
  17. package/dist/commands/desktop.js.map +1 -0
  18. package/dist/commands/sync.d.ts.map +1 -1
  19. package/dist/commands/sync.js +1 -3
  20. package/dist/commands/sync.js.map +1 -1
  21. package/dist/commands/tui.d.ts +8 -0
  22. package/dist/commands/tui.d.ts.map +1 -0
  23. package/dist/commands/tui.js +386 -0
  24. package/dist/commands/tui.js.map +1 -0
  25. package/dist/commands/ui.d.ts +3 -1
  26. package/dist/commands/ui.d.ts.map +1 -1
  27. package/dist/commands/ui.js +76 -19
  28. package/dist/commands/ui.js.map +1 -1
  29. package/dist/generators/base.d.ts.map +1 -1
  30. package/dist/generators/base.js +78 -66
  31. package/dist/generators/base.js.map +1 -1
  32. package/dist/generators/codex.js +11 -11
  33. package/dist/generators/copilot.js +17 -17
  34. package/dist/generators/cursor.js +5 -5
  35. package/dist/generators/index.js +50 -50
  36. package/dist/generators/map-generator.js +14 -14
  37. package/dist/generators/skills-generator.js +28 -28
  38. package/dist/gui/app_logo.png +0 -0
  39. package/dist/gui/assets/index-Ct3qq-X4.js +25 -0
  40. package/dist/gui/assets/index-P_ZrgHXg.css +1 -0
  41. package/dist/gui/icons.svg +24 -24
  42. package/dist/gui/index.html +18 -18
  43. package/dist/index.js +43 -0
  44. package/dist/index.js.map +1 -1
  45. package/dist/server.d.ts.map +1 -1
  46. package/dist/server.js +182 -1
  47. package/dist/server.js.map +1 -1
  48. package/dist/server.test.js +78 -0
  49. package/dist/server.test.js.map +1 -1
  50. package/dist/types.d.ts +4 -0
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/utils/git.d.ts +16 -0
  53. package/dist/utils/git.d.ts.map +1 -1
  54. package/dist/utils/git.js +52 -0
  55. package/dist/utils/git.js.map +1 -1
  56. package/dist/utils/multi-git.d.ts +2 -0
  57. package/dist/utils/multi-git.d.ts.map +1 -1
  58. package/dist/utils/multi-git.js +5 -2
  59. package/dist/utils/multi-git.js.map +1 -1
  60. package/dist/utils/update-check.d.ts +3 -1
  61. package/dist/utils/update-check.d.ts.map +1 -1
  62. package/dist/utils/update-check.js +23 -6
  63. package/dist/utils/update-check.js.map +1 -1
  64. package/dist/utils/workflows.d.ts +11 -0
  65. package/dist/utils/workflows.d.ts.map +1 -0
  66. package/dist/utils/workflows.js +156 -0
  67. package/dist/utils/workflows.js.map +1 -0
  68. package/dist/utils/workflows.test.d.ts +2 -0
  69. package/dist/utils/workflows.test.d.ts.map +1 -0
  70. package/dist/utils/workflows.test.js +86 -0
  71. package/dist/utils/workflows.test.js.map +1 -0
  72. package/extension/media/icon.svg +1 -0
  73. package/extension/package-lock.json +2673 -2811
  74. package/extension/package.json +108 -70
  75. package/extension/src/extension.ts +631 -204
  76. package/extension/tsconfig.json +21 -19
  77. package/gui/README.md +73 -73
  78. package/gui/e2e/wizard.spec.ts +346 -327
  79. package/gui/eslint.config.js +26 -26
  80. package/gui/index.html +17 -17
  81. package/gui/package-lock.json +3079 -3118
  82. package/gui/package.json +36 -36
  83. package/gui/playwright.config.ts +41 -41
  84. package/gui/public/app_logo.png +0 -0
  85. package/gui/public/icons.svg +24 -24
  86. package/gui/src/App.css +1 -1
  87. package/gui/src/App.tsx +3407 -2722
  88. package/gui/src/assets/vite.svg +1 -1
  89. package/gui/src/features/changes/ChangesViewer.tsx +388 -388
  90. package/gui/src/features/knowledge/KnowledgeBase.tsx +84 -84
  91. package/gui/src/features/onboarding/OnboardingWizard.tsx +230 -230
  92. package/gui/src/features/plan/ImplementationPlan.tsx +32 -32
  93. package/gui/src/features/services/ServiceConsole.tsx +250 -250
  94. package/gui/src/features/sessions/SessionHistory.tsx +195 -195
  95. package/gui/src/features/workspace/WorkspaceList.tsx +666 -666
  96. package/gui/src/index.css +152 -110
  97. package/gui/src/main.tsx +94 -10
  98. package/gui/src/types.ts +62 -62
  99. package/gui/tsconfig.app.json +25 -25
  100. package/gui/tsconfig.json +7 -7
  101. package/gui/tsconfig.node.json +24 -24
  102. package/gui/vite.config.ts +12 -12
  103. package/package.json +56 -56
  104. package/resources/workflows/plan-implement-review.md +8 -0
  105. package/resources/workflows/research-verify.md +6 -0
  106. package/resources/workflows/solo-developer.md +3 -0
  107. package/scripts/simulate-workspaces.ts +55 -55
  108. package/src/analyzers/detect-apis.ts +290 -290
  109. package/src/analyzers/detect-deps.ts +315 -315
  110. package/src/analyzers/detect-existing.ts +74 -74
  111. package/src/analyzers/detect-ports.ts +110 -110
  112. package/src/analyzers/index.ts +97 -97
  113. package/src/analyzers/messaging-analyzer.ts +254 -254
  114. package/src/analyzers/readme-summarizer.ts +102 -102
  115. package/src/analyzers/run-analyzer.ts +269 -269
  116. package/src/analyzers/tech-stack.ts +283 -283
  117. package/src/commands/add-repo.ts +157 -157
  118. package/src/commands/commands.test.ts +155 -155
  119. package/src/commands/commit.ts +131 -131
  120. package/src/commands/create.ts +207 -207
  121. package/src/commands/desktop.ts +128 -0
  122. package/src/commands/diff.ts +125 -125
  123. package/src/commands/doctor.ts +357 -357
  124. package/src/commands/handoff.ts +266 -266
  125. package/src/commands/init.ts +134 -134
  126. package/src/commands/list.ts +46 -46
  127. package/src/commands/logs.ts +63 -63
  128. package/src/commands/mcp.ts +92 -92
  129. package/src/commands/open.ts +129 -129
  130. package/src/commands/pack.ts +73 -73
  131. package/src/commands/refresh.ts +147 -147
  132. package/src/commands/remove.ts +98 -98
  133. package/src/commands/start.ts +117 -117
  134. package/src/commands/status.ts +54 -54
  135. package/src/commands/stop.ts +55 -55
  136. package/src/commands/sync.ts +151 -153
  137. package/src/commands/tui.ts +424 -0
  138. package/src/commands/ui.ts +111 -47
  139. package/src/core/config.test.ts +96 -96
  140. package/src/core/config.ts +115 -115
  141. package/src/core/graph.ts +344 -344
  142. package/src/core/packer.test.ts +99 -99
  143. package/src/core/packer.ts +107 -107
  144. package/src/core/scanner.test.ts +61 -61
  145. package/src/core/scanner.ts +91 -91
  146. package/src/core/workspace.ts +380 -380
  147. package/src/core/worktree.ts +120 -120
  148. package/src/generators/antigravity.ts +32 -32
  149. package/src/generators/base.ts +240 -227
  150. package/src/generators/claude.ts +34 -34
  151. package/src/generators/codex.ts +48 -48
  152. package/src/generators/copilot.ts +56 -56
  153. package/src/generators/cursor.ts +44 -44
  154. package/src/generators/index.ts +250 -250
  155. package/src/generators/map-generator.test.ts +159 -159
  156. package/src/generators/map-generator.ts +542 -542
  157. package/src/generators/plan-generator.ts +481 -481
  158. package/src/generators/skills-generator.ts +259 -259
  159. package/src/index.ts +426 -382
  160. package/src/mcp/server.ts +294 -294
  161. package/src/orchestration/detect.ts +313 -313
  162. package/src/orchestration/index.ts +7 -7
  163. package/src/orchestration/runner.ts +283 -283
  164. package/src/server.test.ts +555 -464
  165. package/src/server.ts +1308 -1104
  166. package/src/types.ts +408 -403
  167. package/src/utils/detect-ai.test.ts +44 -44
  168. package/src/utils/detect-ai.ts +84 -84
  169. package/src/utils/detect-editors.test.ts +48 -48
  170. package/src/utils/detect-editors.ts +57 -57
  171. package/src/utils/git.test.ts +74 -74
  172. package/src/utils/git.ts +117 -61
  173. package/src/utils/local-ai.test.ts +130 -130
  174. package/src/utils/local-ai.ts +111 -111
  175. package/src/utils/multi-git.ts +313 -306
  176. package/src/utils/prompts.ts +209 -209
  177. package/src/utils/session-finder.ts +483 -483
  178. package/src/utils/system-scanner.test.ts +89 -89
  179. package/src/utils/system-scanner.ts +96 -96
  180. package/src/utils/update-check.ts +309 -275
  181. package/src/utils/workflows.test.ts +114 -0
  182. package/src/utils/workflows.ts +178 -0
  183. package/tsconfig.json +19 -19
  184. package/vitest.config.ts +14 -14
  185. package/dist/gui/assets/index-CFWwqFux.js +0 -23
  186. package/dist/gui/assets/index-Dvc9QMvl.css +0 -2
@@ -1,542 +1,542 @@
1
- /**
2
- * @module generators/map-generator
3
- * Generates a nexusflow-map-<repo>.md file for each repository in the workspace.
4
- * Provides a localized, token-efficient architectural map for AI assistants.
5
- */
6
-
7
- import * as fs from 'node:fs/promises';
8
- import * as path from 'node:path';
9
- import { globby } from 'globby';
10
- import type { ProjectAnalysis, RepoInfo } from '../types.js';
11
-
12
- interface PatternRule {
13
- name: string;
14
- label: string;
15
- regex: RegExp;
16
- description: string;
17
- }
18
-
19
- const LANG_PATTERNS: Record<string, PatternRule[]> = {
20
- csharp: [
21
- {
22
- name: 'FluentValidation',
23
- label: 'FluentValidation Validator subclasses',
24
- regex: /:\s*AbstractValidator\s*</g,
25
- description: 'Used for domain/command validation rules.'
26
- },
27
- {
28
- name: 'MediatR Handlers',
29
- label: 'MediatR Request Handlers',
30
- regex: /:\s*IRequestHandler\s*</g,
31
- description: 'Used for CQRS command/query handler pattern.'
32
- },
33
- {
34
- name: 'MediatR Requests',
35
- label: 'MediatR Requests/Commands',
36
- regex: /:\s*IRequest\b(?!Handler)/g,
37
- description: 'Used for MediatR command/query dispatching.'
38
- },
39
- {
40
- name: 'AutoMapper Profiles',
41
- label: 'AutoMapper Mapping Profiles',
42
- regex: /:\s*Profile\b/g,
43
- description: 'Used for object-to-object mappings.'
44
- },
45
- {
46
- name: 'DataAnnotations',
47
- label: 'DataAnnotations Validation Attributes',
48
- regex: /using\s+System\.ComponentModel\.DataAnnotations;/g,
49
- description: 'Used for property-level attribute validation.'
50
- }
51
- ],
52
- typescript: [
53
- {
54
- name: 'Zod Schemas',
55
- label: 'Zod Object Schemas',
56
- regex: /z\.object\s*\(/g,
57
- description: 'Used for schema parsing/validation.'
58
- },
59
- {
60
- name: 'NestJS Controllers',
61
- label: 'NestJS Routing Controllers',
62
- regex: /@Controller\s*\(/g,
63
- description: 'Used for controller routing endpoints.'
64
- },
65
- {
66
- name: 'NestJS Injectables',
67
- label: 'NestJS Injectable Services',
68
- regex: /@Injectable\s*\(\)/g,
69
- description: 'Used for dependency injection services.'
70
- },
71
- {
72
- name: 'React Components',
73
- label: 'React Functional Components',
74
- regex: /React\.FC/g,
75
- description: 'Used for component UI views.'
76
- }
77
- ],
78
- javascript: [
79
- {
80
- name: 'Zod Schemas',
81
- label: 'Zod Object Schemas',
82
- regex: /z\.object\s*\(/g,
83
- description: 'Used for schema parsing/validation.'
84
- }
85
- ],
86
- python: [
87
- {
88
- name: 'Pydantic Models',
89
- label: 'Pydantic BaseModel subclasses',
90
- regex: /class\s+\w+\s*\(\s*BaseModel\s*\)/g,
91
- description: 'Used for data schemas and validation.'
92
- },
93
- {
94
- name: 'FastAPI Routers',
95
- label: 'FastAPI APIRouter instances',
96
- regex: /=([\s\S]*?)APIRouter\s*\(/g,
97
- description: 'Used for endpoint routing.'
98
- }
99
- ],
100
- go: [
101
- {
102
- name: 'Go JSON tags',
103
- label: 'Go JSON struct tags',
104
- regex: /`json:"[^"]+"`/g,
105
- description: 'Used for struct serialization/deserialization.'
106
- }
107
- ]
108
- };
109
-
110
- /**
111
- * Generates a `nexusflow-map-<repo>.md` file in the workspace root.
112
- *
113
- * @param repo - The repository metadata.
114
- * @param analysis - The repository analysis result.
115
- * @param workspacePath - Absolute path to the workspace root directory.
116
- */
117
- export async function generateRepoMap(
118
- repo: RepoInfo,
119
- analysis: ProjectAnalysis,
120
- workspacePath: string,
121
- allProducedPackages: Set<string> = new Set(),
122
- ): Promise<void> {
123
- const repoName = repo.name;
124
- const worktreePath = path.join(workspacePath, repoName);
125
-
126
- const md: string[] = [];
127
-
128
- md.push(`# Repository Architecture Map — ${repoName}`);
129
- md.push('');
130
- md.push(`> **Repository Path**: \`${worktreePath}\``);
131
- md.push(`> **Generated At**: ${new Date().toISOString()} (UTC)`);
132
- md.push(`> **Regeneration Command**: Run \`nexusflow refresh\` to update this map.`);
133
- md.push(`> **Note**: Maps are advisory snapshots of the codebase. Always verify route parameters, patterns, and filenames before relying on them.`);
134
- md.push('');
135
-
136
-
137
- // 1. Solution/Project Layout
138
- md.push('## 🏗️ Project Layout');
139
- md.push('');
140
-
141
- try {
142
- const slnFiles = await globby('**/*.sln', {
143
- cwd: worktreePath,
144
- ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
145
- });
146
-
147
- const csprojFiles = await globby('**/*.csproj', {
148
- cwd: worktreePath,
149
- ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
150
- });
151
-
152
- const packageJsons = await globby('**/package.json', {
153
- cwd: worktreePath,
154
- ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
155
- });
156
-
157
- if (slnFiles.length > 0) {
158
- md.push('### .NET Solutions');
159
- for (const sln of slnFiles) {
160
- md.push(`- **Solution**: \`${sln}\``);
161
- }
162
- md.push('');
163
- }
164
-
165
- if (csprojFiles.length > 0) {
166
- md.push('### .NET Projects');
167
- for (const csproj of csprojFiles) {
168
- const isTest = csproj.toLowerCase().includes('test') || csproj.toLowerCase().includes('spec');
169
- const role = isTest ? 'Test Suite' : 'App/Library';
170
- md.push(`- \`${csproj}\` (${role})`);
171
- }
172
- md.push('');
173
- }
174
-
175
- if (packageJsons.length > 0) {
176
- md.push('### npm Packages & Modules');
177
- for (const pj of packageJsons) {
178
- md.push(`- \`${pj}\``);
179
- }
180
- md.push('');
181
- }
182
- } catch {
183
- md.push('_No project layout files discovered or error occurred._');
184
- md.push('');
185
- }
186
-
187
- // 1.5. Messaging Topology
188
- md.push('## 📨 Messaging Topology');
189
- md.push('');
190
- if (analysis.messaging && (analysis.messaging.publishers.length > 0 || analysis.messaging.subscribers.length > 0)) {
191
- if (analysis.messaging.publishers.length > 0) {
192
- md.push('### Publishes');
193
- md.push('| Message Contract | Topic/Queue/Channel | Publisher (file) |');
194
- md.push('|---|---|---|');
195
- for (const p of analysis.messaging.publishers) {
196
- const fileLink = p.publisherFile
197
- ? `[${path.basename(p.publisherFile)}](file:///${path.join(worktreePath, p.publisherFile)})`
198
- : '—';
199
- md.push(`| ${p.contractType} | ${p.topicOrQueue} | ${fileLink} |`);
200
- }
201
- md.push('');
202
- }
203
-
204
- if (analysis.messaging.subscribers.length > 0) {
205
- md.push('### Subscribes');
206
- md.push('| Message Contract | Handler (file) | Registered in |');
207
- md.push('|---|---|---|');
208
- for (const s of analysis.messaging.subscribers) {
209
- const handlerLink = s.handlerFile
210
- ? `[${path.basename(s.handlerFile)}](file:///${path.join(worktreePath, s.handlerFile)})`
211
- : '—';
212
- const regLink = s.registrationFile
213
- ? `[${path.basename(s.registrationFile)}](file:///${path.join(worktreePath, s.registrationFile)})`
214
- : '—';
215
- md.push(`| ${s.contractType} | ${handlerLink} | ${regLink} |`);
216
- }
217
- md.push('');
218
- }
219
- } else {
220
- md.push('_No pub/sub messaging patterns detected in this repository._');
221
- md.push('');
222
- }
223
-
224
- // 2. Extensible Usage Pattern Scanning
225
- md.push('## 💡 Detected Architectural Patterns & Usages');
226
- md.push('');
227
-
228
- const detectedLanguages = analysis.techStack.languages;
229
- const patternExamples = new Map<string, { label: string; firstFile?: string; description: string }>();
230
-
231
- // Initialize examples
232
- for (const lang of detectedLanguages) {
233
- const rules = LANG_PATTERNS[lang] || [];
234
- for (const rule of rules) {
235
- patternExamples.set(rule.name, { label: rule.label, description: rule.description });
236
- }
237
- }
238
-
239
- // Scan files for pattern usage
240
- try {
241
- const extensions = detectedLanguages.map(l => {
242
- if (l === 'csharp') return 'cs';
243
- if (l === 'typescript') return 'ts';
244
- if (l === 'javascript') return 'js';
245
- if (l === 'python') return 'py';
246
- if (l === 'go') return 'go';
247
- return '';
248
- }).filter(ext => ext !== '');
249
-
250
- if (extensions.length > 0) {
251
- const globPattern = extensions.length === 1 ? `**/*.${extensions[0]}` : `**/*.{${extensions.join(',')}}`;
252
- const srcFiles = await globby(globPattern, {
253
- cwd: worktreePath,
254
- ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
255
- });
256
-
257
- for (const file of srcFiles) {
258
- const fullPath = path.join(worktreePath, file);
259
- const content = await fs.readFile(fullPath, 'utf-8');
260
-
261
- for (const lang of detectedLanguages) {
262
- const rules = LANG_PATTERNS[lang] || [];
263
- for (const rule of rules) {
264
- const val = patternExamples.get(rule.name)!;
265
- if (val.firstFile) continue; // Already found an example
266
-
267
- rule.regex.lastIndex = 0;
268
- if (rule.regex.test(content)) {
269
- val.firstFile = file.replace(/\\/g, '/');
270
- }
271
- }
272
- }
273
- }
274
- }
275
- } catch {
276
- // Ignore errors
277
- }
278
-
279
- md.push('### Static Analysis Findings');
280
- let hasFindings = false;
281
- if (patternExamples.size > 0) {
282
- for (const [, v] of patternExamples) {
283
- if (v.firstFile) {
284
- hasFindings = true;
285
- const fileLink = `[${path.basename(v.firstFile)}](file:///${path.join(worktreePath, v.firstFile).replace(/\\/g, '/')})`;
286
- md.push(`- **${v.label}** example: ${fileLink} _(${v.description})_`);
287
- }
288
- }
289
- }
290
- if (!hasFindings) {
291
- md.push('_No architectural usage patterns detected via static analysis._');
292
- }
293
- md.push('');
294
-
295
- md.push('### Packages Present (Dependencies)');
296
- // Filter dependencies: only show internal packages produced by repos in this workspace,
297
- // or those matching a common organization namespace prefix (e.g. if one package is MyOrg.Common, then MyOrg.*).
298
- const internalPrefixes = Array.from(allProducedPackages).map(p => {
299
- const parts = p.split('.');
300
- return parts.length > 1 ? parts[0] + '.' : null;
301
- }).filter((p): p is string => p !== null);
302
-
303
- const filteredDeps = analysis.dependencies.filter(dep => {
304
- const depNameLower = dep.name.toLowerCase();
305
- if (allProducedPackages.has(depNameLower)) return true;
306
- return internalPrefixes.some(prefix => depNameLower.startsWith(prefix));
307
- });
308
-
309
- if (filteredDeps.length > 0) {
310
- for (const dep of filteredDeps) {
311
- md.push(`- \`${dep.name}\` (${dep.version || 'unknown version'})`);
312
- }
313
- } else {
314
- md.push('_No cross-repo or organization-internal package dependencies detected._');
315
- }
316
- md.push('');
317
-
318
- // 3. Endpoint Inventory
319
- md.push('## 🔌 API Endpoints');
320
- md.push('');
321
- if (analysis.endpoints.length > 0) {
322
- md.push('| Endpoint Group (Router/Module/File) | Route Prefix / Pattern | Verbs | Source File |');
323
- md.push('|:---|:---|:---|:---|');
324
-
325
- // Group endpoints by source file
326
- const grouped = new Map<string, typeof analysis.endpoints>();
327
- for (const ep of analysis.endpoints) {
328
- const src = ep.source || 'Unknown';
329
- if (!grouped.has(src)) {
330
- grouped.set(src, []);
331
- }
332
- grouped.get(src)!.push(ep);
333
- }
334
-
335
- const findCommonPrefix = (paths: string[]): string => {
336
- if (paths.length === 0) return '';
337
- if (paths.length === 1) return paths[0]!;
338
- const sorted = [...paths].sort();
339
- const first = sorted[0]!.split('/');
340
- const last = sorted[sorted.length - 1]!.split('/');
341
- const common: string[] = [];
342
- for (let i = 0; i < first.length; i++) {
343
- if (first[i] === last[i]) {
344
- common.push(first[i]!);
345
- } else {
346
- break;
347
- }
348
- }
349
- const prefix = common.join('/');
350
- return prefix || '/';
351
- };
352
-
353
- for (const [src, eps] of grouped) {
354
- const groupName = src !== 'Unknown' ? path.basename(src, path.extname(src)) : 'Inferred';
355
- const paths = eps.map(e => e.path);
356
- const commonPrefix = findCommonPrefix(paths);
357
- const verbs = Array.from(new Set(eps.map(e => e.method.toUpperCase()))).join(', ');
358
- const sourceLink = src !== 'Unknown'
359
- ? `[${path.basename(src)}](file:///${path.join(worktreePath, src).replace(/\\/g, '/')})`
360
- : '—';
361
- md.push(`| ${groupName} | \`${commonPrefix}\` | \`${verbs}\` | ${sourceLink} |`);
362
- }
363
- } else {
364
- md.push('_No endpoints detected._');
365
- }
366
- md.push('');
367
-
368
- // 4. Test Landscape
369
- md.push('## 🧪 Test Landscape & Command');
370
- md.push('');
371
- const testFrameworks: string[] = [];
372
- let testCommand = '';
373
-
374
- for (const dep of analysis.dependencies) {
375
- const name = dep.name.toLowerCase();
376
- if (name.includes('xunit')) testFrameworks.push('xUnit');
377
- if (name.includes('mstest') || name.includes('microsoft.testplatform')) testFrameworks.push('MSTest');
378
- if (name.includes('nunit')) testFrameworks.push('NUnit');
379
- if (name.includes('jest')) testFrameworks.push('Jest');
380
- if (name.includes('vitest')) testFrameworks.push('Vitest');
381
- if (name.includes('cypress')) testFrameworks.push('Cypress');
382
- if (name.includes('playwright')) testFrameworks.push('Playwright');
383
- }
384
-
385
- if (analysis.techStack.languages.includes('csharp')) {
386
- testCommand = 'dotnet test';
387
- try {
388
- const slns = await globby('**/*.sln', {
389
- cwd: worktreePath,
390
- ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
391
- });
392
- if (slns.length > 0) {
393
- testCommand = `dotnet test ${slns[0]}`;
394
- }
395
- } catch {}
396
- } else if (analysis.techStack.languages.includes('typescript') || analysis.techStack.languages.includes('javascript')) {
397
- testCommand = 'npm test';
398
- }
399
-
400
- if (testFrameworks.length > 0) {
401
- md.push(`- **Frameworks**: ${testFrameworks.join(', ')}`);
402
- } else {
403
- md.push('- **Frameworks**: None explicitly detected');
404
- }
405
- if (testCommand) {
406
- md.push(`- **Run Command**: \`${testCommand}\``);
407
- }
408
- md.push('');
409
-
410
- // 4.5. Running Locally
411
- md.push('## ▶️ Running Locally');
412
- md.push('');
413
- if (analysis.runConfig) {
414
- const { entryPoints, databases, sharedInfraWarnings, committedSecrets } = analysis.runConfig;
415
-
416
- if (entryPoints.length > 0) {
417
- md.push('### Entry Points');
418
- for (const ep of entryPoints) {
419
- md.push(`- **${ep.type.toUpperCase()} App**: \`${ep.command || 'dotnet run'}\` (configured in \`${ep.projectPath}\`)`);
420
- }
421
- md.push('');
422
- }
423
-
424
- if (databases.length > 0) {
425
- md.push('### Databases & Data Stores');
426
- md.push('| Provider | Target Host | Config File |');
427
- md.push('|---|---|---|');
428
- for (const db of databases) {
429
- md.push(`| ${db.provider} | ${db.host} | \`${db.configFile}\` |`);
430
- }
431
- md.push('');
432
- }
433
-
434
- if (sharedInfraWarnings.length > 0) {
435
- md.push('### ⚠️ Shared Infrastructure Warnings');
436
- for (const w of sharedInfraWarnings) {
437
- md.push(`- ${w.warning}`);
438
- }
439
- md.push('');
440
- }
441
-
442
- if (committedSecrets.length > 0) {
443
- md.push('### 🔒 Potential Committed Secrets');
444
- for (const s of committedSecrets) {
445
- md.push(`- **Warning**: Possible plaintext secret/key/password found in \`${s.file}\` (key hint: \`${s.lineHint}\`)`);
446
- }
447
- md.push('');
448
- }
449
- } else {
450
- md.push('_No run configurations detected._');
451
- md.push('');
452
- }
453
-
454
- // 5. Custom Skills
455
- md.push('## 🛠️ Custom Agent Skills');
456
- md.push('');
457
- try {
458
- const skills = await globby('**/SKILL.md', {
459
- cwd: worktreePath,
460
- absolute: true,
461
- ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
462
- });
463
-
464
- if (skills.length > 0) {
465
- md.push('The following custom agent skills are available in this repository:');
466
- for (const skill of skills) {
467
- const relativeSkill = path.relative(worktreePath, skill);
468
- const skillName = path.basename(path.dirname(skill));
469
- md.push(`- **${skillName}**: [${relativeSkill}](file:///${skill})`);
470
- }
471
- } else {
472
- md.push('_No custom agent skills found in this repository._');
473
- }
474
- } catch {
475
- md.push('_No custom agent skills found in this repository._');
476
- }
477
- md.push('');
478
-
479
- // 6. AI Configurations
480
- md.push('## 📄 AI Assistant Configurations');
481
- md.push('');
482
- if (analysis.existingAIConfigs.length > 0) {
483
- md.push('Incorporate instructions from these local configurations:');
484
- for (const config of analysis.existingAIConfigs) {
485
- md.push(`- [${config.relativePath}](file:///${path.join(worktreePath, config.relativePath)}) (${config.assistant})`);
486
- }
487
- } else {
488
- md.push('_No pre-existing AI configurations found in this repository._');
489
- }
490
- md.push('');
491
-
492
- // 7. Project-Specific Conventions (Agent-Defined)
493
- md.push('## 📝 Discovered Conventions');
494
- md.push('');
495
-
496
- const conventionsFile = path.join(workspacePath, `nexusflow-conventions-${repoName}.md`);
497
- let customConventions = '';
498
-
499
- let conventionsExist = false;
500
- try {
501
- await fs.access(conventionsFile);
502
- conventionsExist = true;
503
- } catch {}
504
-
505
- if (!conventionsExist) {
506
- const starterContent = `# Repository Conventions — ${repoName}
507
-
508
- Use this file to record project-specific coding conventions, patterns, gotchas, and constraints learned during development.
509
- Future AI assistant sessions will read these conventions from the repository map.
510
-
511
- ## Coding Patterns
512
- <!-- E.g., Use ErrorContent structure for errors instead of plain strings -->
513
-
514
- - None recorded yet.
515
-
516
- ## Gotchas & Watch-outs
517
- <!-- E.g., Non-nullable enum required attributes gotchas -->
518
-
519
- - None recorded yet.
520
- `;
521
- try {
522
- await fs.writeFile(conventionsFile, starterContent, 'utf-8');
523
- customConventions = starterContent.replace(/^#\s+.+\n?/, '').trim();
524
- } catch {}
525
- } else {
526
- try {
527
- customConventions = await fs.readFile(conventionsFile, 'utf-8');
528
- customConventions = customConventions.replace(/^#\s+.+\n?/, '').trim();
529
- } catch {}
530
- }
531
-
532
- if (customConventions) {
533
- md.push(customConventions);
534
- md.push('');
535
- } else {
536
- md.push('- None recorded yet.');
537
- md.push('');
538
- }
539
-
540
- const outPath = path.join(workspacePath, `nexusflow-map-${repoName}.md`);
541
- await fs.writeFile(outPath, md.join('\n'), 'utf-8');
542
- }
1
+ /**
2
+ * @module generators/map-generator
3
+ * Generates a nexusflow-map-<repo>.md file for each repository in the workspace.
4
+ * Provides a localized, token-efficient architectural map for AI assistants.
5
+ */
6
+
7
+ import * as fs from 'node:fs/promises';
8
+ import * as path from 'node:path';
9
+ import { globby } from 'globby';
10
+ import type { ProjectAnalysis, RepoInfo } from '../types.js';
11
+
12
+ interface PatternRule {
13
+ name: string;
14
+ label: string;
15
+ regex: RegExp;
16
+ description: string;
17
+ }
18
+
19
+ const LANG_PATTERNS: Record<string, PatternRule[]> = {
20
+ csharp: [
21
+ {
22
+ name: 'FluentValidation',
23
+ label: 'FluentValidation Validator subclasses',
24
+ regex: /:\s*AbstractValidator\s*</g,
25
+ description: 'Used for domain/command validation rules.'
26
+ },
27
+ {
28
+ name: 'MediatR Handlers',
29
+ label: 'MediatR Request Handlers',
30
+ regex: /:\s*IRequestHandler\s*</g,
31
+ description: 'Used for CQRS command/query handler pattern.'
32
+ },
33
+ {
34
+ name: 'MediatR Requests',
35
+ label: 'MediatR Requests/Commands',
36
+ regex: /:\s*IRequest\b(?!Handler)/g,
37
+ description: 'Used for MediatR command/query dispatching.'
38
+ },
39
+ {
40
+ name: 'AutoMapper Profiles',
41
+ label: 'AutoMapper Mapping Profiles',
42
+ regex: /:\s*Profile\b/g,
43
+ description: 'Used for object-to-object mappings.'
44
+ },
45
+ {
46
+ name: 'DataAnnotations',
47
+ label: 'DataAnnotations Validation Attributes',
48
+ regex: /using\s+System\.ComponentModel\.DataAnnotations;/g,
49
+ description: 'Used for property-level attribute validation.'
50
+ }
51
+ ],
52
+ typescript: [
53
+ {
54
+ name: 'Zod Schemas',
55
+ label: 'Zod Object Schemas',
56
+ regex: /z\.object\s*\(/g,
57
+ description: 'Used for schema parsing/validation.'
58
+ },
59
+ {
60
+ name: 'NestJS Controllers',
61
+ label: 'NestJS Routing Controllers',
62
+ regex: /@Controller\s*\(/g,
63
+ description: 'Used for controller routing endpoints.'
64
+ },
65
+ {
66
+ name: 'NestJS Injectables',
67
+ label: 'NestJS Injectable Services',
68
+ regex: /@Injectable\s*\(\)/g,
69
+ description: 'Used for dependency injection services.'
70
+ },
71
+ {
72
+ name: 'React Components',
73
+ label: 'React Functional Components',
74
+ regex: /React\.FC/g,
75
+ description: 'Used for component UI views.'
76
+ }
77
+ ],
78
+ javascript: [
79
+ {
80
+ name: 'Zod Schemas',
81
+ label: 'Zod Object Schemas',
82
+ regex: /z\.object\s*\(/g,
83
+ description: 'Used for schema parsing/validation.'
84
+ }
85
+ ],
86
+ python: [
87
+ {
88
+ name: 'Pydantic Models',
89
+ label: 'Pydantic BaseModel subclasses',
90
+ regex: /class\s+\w+\s*\(\s*BaseModel\s*\)/g,
91
+ description: 'Used for data schemas and validation.'
92
+ },
93
+ {
94
+ name: 'FastAPI Routers',
95
+ label: 'FastAPI APIRouter instances',
96
+ regex: /=([\s\S]*?)APIRouter\s*\(/g,
97
+ description: 'Used for endpoint routing.'
98
+ }
99
+ ],
100
+ go: [
101
+ {
102
+ name: 'Go JSON tags',
103
+ label: 'Go JSON struct tags',
104
+ regex: /`json:"[^"]+"`/g,
105
+ description: 'Used for struct serialization/deserialization.'
106
+ }
107
+ ]
108
+ };
109
+
110
+ /**
111
+ * Generates a `nexusflow-map-<repo>.md` file in the workspace root.
112
+ *
113
+ * @param repo - The repository metadata.
114
+ * @param analysis - The repository analysis result.
115
+ * @param workspacePath - Absolute path to the workspace root directory.
116
+ */
117
+ export async function generateRepoMap(
118
+ repo: RepoInfo,
119
+ analysis: ProjectAnalysis,
120
+ workspacePath: string,
121
+ allProducedPackages: Set<string> = new Set(),
122
+ ): Promise<void> {
123
+ const repoName = repo.name;
124
+ const worktreePath = path.join(workspacePath, repoName);
125
+
126
+ const md: string[] = [];
127
+
128
+ md.push(`# Repository Architecture Map — ${repoName}`);
129
+ md.push('');
130
+ md.push(`> **Repository Path**: \`${worktreePath}\``);
131
+ md.push(`> **Generated At**: ${new Date().toISOString()} (UTC)`);
132
+ md.push(`> **Regeneration Command**: Run \`nexusflow refresh\` to update this map.`);
133
+ md.push(`> **Note**: Maps are advisory snapshots of the codebase. Always verify route parameters, patterns, and filenames before relying on them.`);
134
+ md.push('');
135
+
136
+
137
+ // 1. Solution/Project Layout
138
+ md.push('## 🏗️ Project Layout');
139
+ md.push('');
140
+
141
+ try {
142
+ const slnFiles = await globby('**/*.sln', {
143
+ cwd: worktreePath,
144
+ ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
145
+ });
146
+
147
+ const csprojFiles = await globby('**/*.csproj', {
148
+ cwd: worktreePath,
149
+ ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
150
+ });
151
+
152
+ const packageJsons = await globby('**/package.json', {
153
+ cwd: worktreePath,
154
+ ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
155
+ });
156
+
157
+ if (slnFiles.length > 0) {
158
+ md.push('### .NET Solutions');
159
+ for (const sln of slnFiles) {
160
+ md.push(`- **Solution**: \`${sln}\``);
161
+ }
162
+ md.push('');
163
+ }
164
+
165
+ if (csprojFiles.length > 0) {
166
+ md.push('### .NET Projects');
167
+ for (const csproj of csprojFiles) {
168
+ const isTest = csproj.toLowerCase().includes('test') || csproj.toLowerCase().includes('spec');
169
+ const role = isTest ? 'Test Suite' : 'App/Library';
170
+ md.push(`- \`${csproj}\` (${role})`);
171
+ }
172
+ md.push('');
173
+ }
174
+
175
+ if (packageJsons.length > 0) {
176
+ md.push('### npm Packages & Modules');
177
+ for (const pj of packageJsons) {
178
+ md.push(`- \`${pj}\``);
179
+ }
180
+ md.push('');
181
+ }
182
+ } catch {
183
+ md.push('_No project layout files discovered or error occurred._');
184
+ md.push('');
185
+ }
186
+
187
+ // 1.5. Messaging Topology
188
+ md.push('## 📨 Messaging Topology');
189
+ md.push('');
190
+ if (analysis.messaging && (analysis.messaging.publishers.length > 0 || analysis.messaging.subscribers.length > 0)) {
191
+ if (analysis.messaging.publishers.length > 0) {
192
+ md.push('### Publishes');
193
+ md.push('| Message Contract | Topic/Queue/Channel | Publisher (file) |');
194
+ md.push('|---|---|---|');
195
+ for (const p of analysis.messaging.publishers) {
196
+ const fileLink = p.publisherFile
197
+ ? `[${path.basename(p.publisherFile)}](file:///${path.join(worktreePath, p.publisherFile)})`
198
+ : '—';
199
+ md.push(`| ${p.contractType} | ${p.topicOrQueue} | ${fileLink} |`);
200
+ }
201
+ md.push('');
202
+ }
203
+
204
+ if (analysis.messaging.subscribers.length > 0) {
205
+ md.push('### Subscribes');
206
+ md.push('| Message Contract | Handler (file) | Registered in |');
207
+ md.push('|---|---|---|');
208
+ for (const s of analysis.messaging.subscribers) {
209
+ const handlerLink = s.handlerFile
210
+ ? `[${path.basename(s.handlerFile)}](file:///${path.join(worktreePath, s.handlerFile)})`
211
+ : '—';
212
+ const regLink = s.registrationFile
213
+ ? `[${path.basename(s.registrationFile)}](file:///${path.join(worktreePath, s.registrationFile)})`
214
+ : '—';
215
+ md.push(`| ${s.contractType} | ${handlerLink} | ${regLink} |`);
216
+ }
217
+ md.push('');
218
+ }
219
+ } else {
220
+ md.push('_No pub/sub messaging patterns detected in this repository._');
221
+ md.push('');
222
+ }
223
+
224
+ // 2. Extensible Usage Pattern Scanning
225
+ md.push('## 💡 Detected Architectural Patterns & Usages');
226
+ md.push('');
227
+
228
+ const detectedLanguages = analysis.techStack.languages;
229
+ const patternExamples = new Map<string, { label: string; firstFile?: string; description: string }>();
230
+
231
+ // Initialize examples
232
+ for (const lang of detectedLanguages) {
233
+ const rules = LANG_PATTERNS[lang] || [];
234
+ for (const rule of rules) {
235
+ patternExamples.set(rule.name, { label: rule.label, description: rule.description });
236
+ }
237
+ }
238
+
239
+ // Scan files for pattern usage
240
+ try {
241
+ const extensions = detectedLanguages.map(l => {
242
+ if (l === 'csharp') return 'cs';
243
+ if (l === 'typescript') return 'ts';
244
+ if (l === 'javascript') return 'js';
245
+ if (l === 'python') return 'py';
246
+ if (l === 'go') return 'go';
247
+ return '';
248
+ }).filter(ext => ext !== '');
249
+
250
+ if (extensions.length > 0) {
251
+ const globPattern = extensions.length === 1 ? `**/*.${extensions[0]}` : `**/*.{${extensions.join(',')}}`;
252
+ const srcFiles = await globby(globPattern, {
253
+ cwd: worktreePath,
254
+ ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
255
+ });
256
+
257
+ for (const file of srcFiles) {
258
+ const fullPath = path.join(worktreePath, file);
259
+ const content = await fs.readFile(fullPath, 'utf-8');
260
+
261
+ for (const lang of detectedLanguages) {
262
+ const rules = LANG_PATTERNS[lang] || [];
263
+ for (const rule of rules) {
264
+ const val = patternExamples.get(rule.name)!;
265
+ if (val.firstFile) continue; // Already found an example
266
+
267
+ rule.regex.lastIndex = 0;
268
+ if (rule.regex.test(content)) {
269
+ val.firstFile = file.replace(/\\/g, '/');
270
+ }
271
+ }
272
+ }
273
+ }
274
+ }
275
+ } catch {
276
+ // Ignore errors
277
+ }
278
+
279
+ md.push('### Static Analysis Findings');
280
+ let hasFindings = false;
281
+ if (patternExamples.size > 0) {
282
+ for (const [, v] of patternExamples) {
283
+ if (v.firstFile) {
284
+ hasFindings = true;
285
+ const fileLink = `[${path.basename(v.firstFile)}](file:///${path.join(worktreePath, v.firstFile).replace(/\\/g, '/')})`;
286
+ md.push(`- **${v.label}** example: ${fileLink} _(${v.description})_`);
287
+ }
288
+ }
289
+ }
290
+ if (!hasFindings) {
291
+ md.push('_No architectural usage patterns detected via static analysis._');
292
+ }
293
+ md.push('');
294
+
295
+ md.push('### Packages Present (Dependencies)');
296
+ // Filter dependencies: only show internal packages produced by repos in this workspace,
297
+ // or those matching a common organization namespace prefix (e.g. if one package is MyOrg.Common, then MyOrg.*).
298
+ const internalPrefixes = Array.from(allProducedPackages).map(p => {
299
+ const parts = p.split('.');
300
+ return parts.length > 1 ? parts[0] + '.' : null;
301
+ }).filter((p): p is string => p !== null);
302
+
303
+ const filteredDeps = analysis.dependencies.filter(dep => {
304
+ const depNameLower = dep.name.toLowerCase();
305
+ if (allProducedPackages.has(depNameLower)) return true;
306
+ return internalPrefixes.some(prefix => depNameLower.startsWith(prefix));
307
+ });
308
+
309
+ if (filteredDeps.length > 0) {
310
+ for (const dep of filteredDeps) {
311
+ md.push(`- \`${dep.name}\` (${dep.version || 'unknown version'})`);
312
+ }
313
+ } else {
314
+ md.push('_No cross-repo or organization-internal package dependencies detected._');
315
+ }
316
+ md.push('');
317
+
318
+ // 3. Endpoint Inventory
319
+ md.push('## 🔌 API Endpoints');
320
+ md.push('');
321
+ if (analysis.endpoints.length > 0) {
322
+ md.push('| Endpoint Group (Router/Module/File) | Route Prefix / Pattern | Verbs | Source File |');
323
+ md.push('|:---|:---|:---|:---|');
324
+
325
+ // Group endpoints by source file
326
+ const grouped = new Map<string, typeof analysis.endpoints>();
327
+ for (const ep of analysis.endpoints) {
328
+ const src = ep.source || 'Unknown';
329
+ if (!grouped.has(src)) {
330
+ grouped.set(src, []);
331
+ }
332
+ grouped.get(src)!.push(ep);
333
+ }
334
+
335
+ const findCommonPrefix = (paths: string[]): string => {
336
+ if (paths.length === 0) return '';
337
+ if (paths.length === 1) return paths[0]!;
338
+ const sorted = [...paths].sort();
339
+ const first = sorted[0]!.split('/');
340
+ const last = sorted[sorted.length - 1]!.split('/');
341
+ const common: string[] = [];
342
+ for (let i = 0; i < first.length; i++) {
343
+ if (first[i] === last[i]) {
344
+ common.push(first[i]!);
345
+ } else {
346
+ break;
347
+ }
348
+ }
349
+ const prefix = common.join('/');
350
+ return prefix || '/';
351
+ };
352
+
353
+ for (const [src, eps] of grouped) {
354
+ const groupName = src !== 'Unknown' ? path.basename(src, path.extname(src)) : 'Inferred';
355
+ const paths = eps.map(e => e.path);
356
+ const commonPrefix = findCommonPrefix(paths);
357
+ const verbs = Array.from(new Set(eps.map(e => e.method.toUpperCase()))).join(', ');
358
+ const sourceLink = src !== 'Unknown'
359
+ ? `[${path.basename(src)}](file:///${path.join(worktreePath, src).replace(/\\/g, '/')})`
360
+ : '—';
361
+ md.push(`| ${groupName} | \`${commonPrefix}\` | \`${verbs}\` | ${sourceLink} |`);
362
+ }
363
+ } else {
364
+ md.push('_No endpoints detected._');
365
+ }
366
+ md.push('');
367
+
368
+ // 4. Test Landscape
369
+ md.push('## 🧪 Test Landscape & Command');
370
+ md.push('');
371
+ const testFrameworks: string[] = [];
372
+ let testCommand = '';
373
+
374
+ for (const dep of analysis.dependencies) {
375
+ const name = dep.name.toLowerCase();
376
+ if (name.includes('xunit')) testFrameworks.push('xUnit');
377
+ if (name.includes('mstest') || name.includes('microsoft.testplatform')) testFrameworks.push('MSTest');
378
+ if (name.includes('nunit')) testFrameworks.push('NUnit');
379
+ if (name.includes('jest')) testFrameworks.push('Jest');
380
+ if (name.includes('vitest')) testFrameworks.push('Vitest');
381
+ if (name.includes('cypress')) testFrameworks.push('Cypress');
382
+ if (name.includes('playwright')) testFrameworks.push('Playwright');
383
+ }
384
+
385
+ if (analysis.techStack.languages.includes('csharp')) {
386
+ testCommand = 'dotnet test';
387
+ try {
388
+ const slns = await globby('**/*.sln', {
389
+ cwd: worktreePath,
390
+ ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
391
+ });
392
+ if (slns.length > 0) {
393
+ testCommand = `dotnet test ${slns[0]}`;
394
+ }
395
+ } catch {}
396
+ } else if (analysis.techStack.languages.includes('typescript') || analysis.techStack.languages.includes('javascript')) {
397
+ testCommand = 'npm test';
398
+ }
399
+
400
+ if (testFrameworks.length > 0) {
401
+ md.push(`- **Frameworks**: ${testFrameworks.join(', ')}`);
402
+ } else {
403
+ md.push('- **Frameworks**: None explicitly detected');
404
+ }
405
+ if (testCommand) {
406
+ md.push(`- **Run Command**: \`${testCommand}\``);
407
+ }
408
+ md.push('');
409
+
410
+ // 4.5. Running Locally
411
+ md.push('## ▶️ Running Locally');
412
+ md.push('');
413
+ if (analysis.runConfig) {
414
+ const { entryPoints, databases, sharedInfraWarnings, committedSecrets } = analysis.runConfig;
415
+
416
+ if (entryPoints.length > 0) {
417
+ md.push('### Entry Points');
418
+ for (const ep of entryPoints) {
419
+ md.push(`- **${ep.type.toUpperCase()} App**: \`${ep.command || 'dotnet run'}\` (configured in \`${ep.projectPath}\`)`);
420
+ }
421
+ md.push('');
422
+ }
423
+
424
+ if (databases.length > 0) {
425
+ md.push('### Databases & Data Stores');
426
+ md.push('| Provider | Target Host | Config File |');
427
+ md.push('|---|---|---|');
428
+ for (const db of databases) {
429
+ md.push(`| ${db.provider} | ${db.host} | \`${db.configFile}\` |`);
430
+ }
431
+ md.push('');
432
+ }
433
+
434
+ if (sharedInfraWarnings.length > 0) {
435
+ md.push('### ⚠️ Shared Infrastructure Warnings');
436
+ for (const w of sharedInfraWarnings) {
437
+ md.push(`- ${w.warning}`);
438
+ }
439
+ md.push('');
440
+ }
441
+
442
+ if (committedSecrets.length > 0) {
443
+ md.push('### 🔒 Potential Committed Secrets');
444
+ for (const s of committedSecrets) {
445
+ md.push(`- **Warning**: Possible plaintext secret/key/password found in \`${s.file}\` (key hint: \`${s.lineHint}\`)`);
446
+ }
447
+ md.push('');
448
+ }
449
+ } else {
450
+ md.push('_No run configurations detected._');
451
+ md.push('');
452
+ }
453
+
454
+ // 5. Custom Skills
455
+ md.push('## 🛠️ Custom Agent Skills');
456
+ md.push('');
457
+ try {
458
+ const skills = await globby('**/SKILL.md', {
459
+ cwd: worktreePath,
460
+ absolute: true,
461
+ ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
462
+ });
463
+
464
+ if (skills.length > 0) {
465
+ md.push('The following custom agent skills are available in this repository:');
466
+ for (const skill of skills) {
467
+ const relativeSkill = path.relative(worktreePath, skill);
468
+ const skillName = path.basename(path.dirname(skill));
469
+ md.push(`- **${skillName}**: [${relativeSkill}](file:///${skill})`);
470
+ }
471
+ } else {
472
+ md.push('_No custom agent skills found in this repository._');
473
+ }
474
+ } catch {
475
+ md.push('_No custom agent skills found in this repository._');
476
+ }
477
+ md.push('');
478
+
479
+ // 6. AI Configurations
480
+ md.push('## 📄 AI Assistant Configurations');
481
+ md.push('');
482
+ if (analysis.existingAIConfigs.length > 0) {
483
+ md.push('Incorporate instructions from these local configurations:');
484
+ for (const config of analysis.existingAIConfigs) {
485
+ md.push(`- [${config.relativePath}](file:///${path.join(worktreePath, config.relativePath)}) (${config.assistant})`);
486
+ }
487
+ } else {
488
+ md.push('_No pre-existing AI configurations found in this repository._');
489
+ }
490
+ md.push('');
491
+
492
+ // 7. Project-Specific Conventions (Agent-Defined)
493
+ md.push('## 📝 Discovered Conventions');
494
+ md.push('');
495
+
496
+ const conventionsFile = path.join(workspacePath, `nexusflow-conventions-${repoName}.md`);
497
+ let customConventions = '';
498
+
499
+ let conventionsExist = false;
500
+ try {
501
+ await fs.access(conventionsFile);
502
+ conventionsExist = true;
503
+ } catch {}
504
+
505
+ if (!conventionsExist) {
506
+ const starterContent = `# Repository Conventions — ${repoName}
507
+
508
+ Use this file to record project-specific coding conventions, patterns, gotchas, and constraints learned during development.
509
+ Future AI assistant sessions will read these conventions from the repository map.
510
+
511
+ ## Coding Patterns
512
+ <!-- E.g., Use ErrorContent structure for errors instead of plain strings -->
513
+
514
+ - None recorded yet.
515
+
516
+ ## Gotchas & Watch-outs
517
+ <!-- E.g., Non-nullable enum required attributes gotchas -->
518
+
519
+ - None recorded yet.
520
+ `;
521
+ try {
522
+ await fs.writeFile(conventionsFile, starterContent, 'utf-8');
523
+ customConventions = starterContent.replace(/^#\s+.+\n?/, '').trim();
524
+ } catch {}
525
+ } else {
526
+ try {
527
+ customConventions = await fs.readFile(conventionsFile, 'utf-8');
528
+ customConventions = customConventions.replace(/^#\s+.+\n?/, '').trim();
529
+ } catch {}
530
+ }
531
+
532
+ if (customConventions) {
533
+ md.push(customConventions);
534
+ md.push('');
535
+ } else {
536
+ md.push('- None recorded yet.');
537
+ md.push('');
538
+ }
539
+
540
+ const outPath = path.join(workspacePath, `nexusflow-map-${repoName}.md`);
541
+ await fs.writeFile(outPath, md.join('\n'), 'utf-8');
542
+ }