@mrpatronz/nexusflow 0.2.17 → 0.2.18

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