@mrpatronz/nexusflow 0.2.4 โ†’ 0.2.6

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 (48) hide show
  1. package/dist/commands/commands.test.d.ts +2 -0
  2. package/dist/commands/commands.test.d.ts.map +1 -0
  3. package/dist/commands/commands.test.js +132 -0
  4. package/dist/commands/commands.test.js.map +1 -0
  5. package/dist/commands/doctor.d.ts +7 -0
  6. package/dist/commands/doctor.d.ts.map +1 -0
  7. package/dist/commands/doctor.js +286 -0
  8. package/dist/commands/doctor.js.map +1 -0
  9. package/dist/commands/handoff.d.ts +8 -0
  10. package/dist/commands/handoff.d.ts.map +1 -0
  11. package/dist/commands/handoff.js +235 -0
  12. package/dist/commands/handoff.js.map +1 -0
  13. package/dist/commands/refresh.d.ts +11 -0
  14. package/dist/commands/refresh.d.ts.map +1 -0
  15. package/dist/commands/refresh.js +121 -0
  16. package/dist/commands/refresh.js.map +1 -0
  17. package/dist/core/workspace.d.ts.map +1 -1
  18. package/dist/core/workspace.js +12 -0
  19. package/dist/core/workspace.js.map +1 -1
  20. package/dist/core/worktree.js +2 -2
  21. package/dist/core/worktree.js.map +1 -1
  22. package/dist/generators/base.d.ts.map +1 -1
  23. package/dist/generators/base.js +17 -8
  24. package/dist/generators/base.js.map +1 -1
  25. package/dist/generators/index.d.ts +1 -1
  26. package/dist/generators/index.d.ts.map +1 -1
  27. package/dist/generators/index.js +4 -1
  28. package/dist/generators/index.js.map +1 -1
  29. package/dist/generators/map-generator.d.ts.map +1 -1
  30. package/dist/generators/map-generator.js +33 -6
  31. package/dist/generators/map-generator.js.map +1 -1
  32. package/dist/generators/plan-generator.d.ts.map +1 -1
  33. package/dist/generators/plan-generator.js +3 -0
  34. package/dist/generators/plan-generator.js.map +1 -1
  35. package/dist/index.js +43 -0
  36. package/dist/index.js.map +1 -1
  37. package/package.json +1 -1
  38. package/src/commands/commands.test.ts +155 -0
  39. package/src/commands/doctor.ts +301 -0
  40. package/src/commands/handoff.ts +266 -0
  41. package/src/commands/refresh.ts +139 -0
  42. package/src/core/workspace.ts +16 -0
  43. package/src/core/worktree.ts +2 -2
  44. package/src/generators/base.ts +15 -7
  45. package/src/generators/index.ts +4 -0
  46. package/src/generators/map-generator.ts +32 -6
  47. package/src/generators/plan-generator.ts +3 -0
  48. package/src/index.ts +43 -0
@@ -0,0 +1,301 @@
1
+ import chalk from 'chalk';
2
+ import { select } from '@inquirer/prompts';
3
+ import * as path from 'node:path';
4
+ import * as fs from 'node:fs/promises';
5
+ import { execa } from 'execa';
6
+
7
+ import { loadConfig } from '../core/config.js';
8
+ import { listWorkspaces, loadFeatureConfig } from '../core/workspace.js';
9
+ import { getRepoStatus } from '../utils/multi-git.js';
10
+ import { analyzeAllRepos } from '../analyzers/index.js';
11
+ import { globby } from 'globby';
12
+
13
+ /**
14
+ * Runs the doctor command to diagnose workspace state.
15
+ *
16
+ * @param workspaceArg - Optional workspace path.
17
+ */
18
+ export async function doctorCommand(workspaceArg?: string): Promise<void> {
19
+ console.log(chalk.bold.cyan('\n๐Ÿฉบ NexusFlow โ€” Workspace Doctor\n'));
20
+
21
+ const workspacePath = await resolveWorkspace(workspaceArg);
22
+ if (!workspacePath) return;
23
+
24
+ const feature = await loadFeatureConfig(workspacePath);
25
+ if (!feature) {
26
+ console.error(chalk.red('โœ– Failed to load workspace configuration. Ensure nexusflow.json exists.'));
27
+ return;
28
+ }
29
+
30
+ const allRepos = await Promise.all(
31
+ feature.repos.map(async (r) => {
32
+ const repoName = path.basename(r);
33
+ return {
34
+ name: repoName,
35
+ path: r,
36
+ defaultBranch: 'main',
37
+ };
38
+ })
39
+ );
40
+
41
+ console.log(chalk.cyan('Running diagnostics...\n'));
42
+
43
+ const warnings: string[] = [];
44
+ const errors: string[] = [];
45
+
46
+ // โ”€โ”€ 1. Worktree Paths Check โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
47
+ console.log(chalk.bold('๐Ÿ“ Worktree Paths:'));
48
+ let worktreeErrors = false;
49
+ for (const repo of allRepos) {
50
+ try {
51
+ const stat = await fs.stat(repo.path);
52
+ if (!stat.isDirectory()) {
53
+ errors.push(`Worktree path for "${repo.name}" is not a directory.`);
54
+ console.log(` ${chalk.red('โœ–')} ${repo.name}: Path is not a directory`);
55
+ worktreeErrors = true;
56
+ } else {
57
+ console.log(` ${chalk.green('โœ”')} ${repo.name}: Directory exists`);
58
+ }
59
+ } catch {
60
+ errors.push(`Worktree path for "${repo.name}" does not exist: ${repo.path}`);
61
+ console.log(` ${chalk.red('โœ–')} ${repo.name}: Path does not exist`);
62
+ worktreeErrors = true;
63
+ }
64
+ }
65
+ console.log();
66
+
67
+ if (worktreeErrors) {
68
+ console.error(chalk.red('โœ– Worktree errors detected. Cannot complete diagnostics.\n'));
69
+ return;
70
+ }
71
+
72
+ // โ”€โ”€ 2. Run Analysis for detailed checks โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
73
+ const analysis = await analyzeAllRepos(allRepos);
74
+ console.log();
75
+
76
+ // โ”€โ”€ 3. Branch & Git Status Checks โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
77
+ console.log(chalk.bold('๐ŸŒฟ Branch Alignment & Git Status:'));
78
+ for (const repo of allRepos) {
79
+ let branch = 'unknown';
80
+ try {
81
+ const { stdout } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: repo.path });
82
+ branch = stdout.trim();
83
+ } catch {}
84
+
85
+ if (branch !== feature.branchName) {
86
+ warnings.push(`Repository "${repo.name}" is checked out on branch "${branch}", but workspace branch is "${feature.branchName}".`);
87
+ console.log(` ${chalk.yellow('โš ')} ${repo.name}: Branch mismatch (${chalk.bold(branch)} vs expected ${chalk.bold(feature.branchName)})`);
88
+ } else {
89
+ console.log(` ${chalk.green('โœ”')} ${repo.name}: Aligned on branch "${branch}"`);
90
+ }
91
+
92
+ const status = await getRepoStatus(repo.path);
93
+ if (status.hasChanges) {
94
+ warnings.push(`Repository "${repo.name}" has uncommitted changes.`);
95
+ console.log(` ${chalk.dim(`โ†ณ Has uncommitted changes (${status.summary})`)}`);
96
+ }
97
+ }
98
+ console.log();
99
+
100
+ // โ”€โ”€ 4. Package Registry, Local Feeds, and Temporary Local Versions โ”€โ”€โ”€โ”€โ”€
101
+ console.log(chalk.bold('๐Ÿ“ฆ Local Package Setup & Reference Versioning:'));
102
+ let hasCsharp = false;
103
+ let hasNode = false;
104
+
105
+ for (const repo of allRepos) {
106
+ const a = analysis.get(repo.path);
107
+ if (!a) continue;
108
+
109
+ if (a.techStack.languages.includes('csharp')) hasCsharp = true;
110
+ if (a.techStack.languages.includes('typescript') || a.techStack.languages.includes('javascript')) hasNode = true;
111
+
112
+ // Check for temporary/uncommitted versions in C# csproj
113
+ if (a.techStack.languages.includes('csharp')) {
114
+ try {
115
+ const csprojs = await globby('**/*.csproj', {
116
+ cwd: repo.path,
117
+ absolute: true,
118
+ ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
119
+ });
120
+
121
+ for (const csproj of csprojs) {
122
+ const content = await fs.readFile(csproj, 'utf-8');
123
+ if (content.toLowerCase().includes('-local') || content.toLowerCase().includes('-dev')) {
124
+ warnings.push(`Temporary package version (e.g. ending in "-local" or "-dev") found in "${path.basename(csproj)}".`);
125
+ console.log(` ${chalk.yellow('โš ')} ${repo.name}: Temporary local package version found in "${path.basename(csproj)}"`);
126
+ }
127
+ }
128
+ } catch {}
129
+
130
+ // NuGet local feed checks: check if any local NuGet source is defined in local NuGet.configs
131
+ if (a.nugetFeeds && a.nugetFeeds.length === 0) {
132
+ // Find if there are NuGet.config files
133
+ try {
134
+ const nugetConfigs = await globby('**/NuGet.config', {
135
+ cwd: repo.path,
136
+ ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
137
+ });
138
+ if (nugetConfigs.length === 0) {
139
+ warnings.push(`Repository "${repo.name}" does not have a NuGet.config. It might not resolve local package dependencies.`);
140
+ console.log(` ${chalk.yellow('โš ')} ${repo.name}: No NuGet.config found (needed to configure local package feeds)`);
141
+ }
142
+ } catch {}
143
+ }
144
+ }
145
+
146
+ // Check for relative path/file: dependencies in Node package.json
147
+ if (a.techStack.languages.includes('typescript') || a.techStack.languages.includes('javascript')) {
148
+ try {
149
+ const pjs = await globby('**/package.json', {
150
+ cwd: repo.path,
151
+ absolute: true,
152
+ ignore: ['**/node_modules/**', '**/bin/**', '**/obj/**', '**/dist/**', '**/out/**', '**/.git/**'],
153
+ });
154
+
155
+ for (const pj of pjs) {
156
+ const content = await fs.readFile(pj, 'utf-8');
157
+ if (content.includes('"file:') || content.includes('"link:')) {
158
+ warnings.push(`Temporary package link/file reference (e.g., "file:../") found in "${path.basename(pj)}".`);
159
+ console.log(` ${chalk.yellow('โš ')} ${repo.name}: Temporary local dependency reference ("file:" or "link:") found in "${path.basename(pj)}"`);
160
+ }
161
+ }
162
+ } catch {}
163
+ }
164
+ }
165
+
166
+ if (hasCsharp || hasNode) {
167
+ console.log(` ${chalk.green('โœ”')} Local registry feeds/link validation completed.`);
168
+ } else {
169
+ console.log(` ${chalk.dim('No C# or Node.js repositories to validate.')}`);
170
+ }
171
+ console.log();
172
+
173
+ // โ”€โ”€ 5. Test Commands & Fallbacks โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
174
+ console.log(chalk.bold('๐Ÿงช Test Commands:'));
175
+ for (const repo of allRepos) {
176
+ const a = analysis.get(repo.path);
177
+ if (!a) continue;
178
+
179
+ const testCommand = getTestCommand(a);
180
+ if (testCommand === 'npm test' && !a.techStack.languages.includes('typescript') && !a.techStack.languages.includes('javascript')) {
181
+ warnings.push(`Repository "${repo.name}" fell back to default test command "npm test".`);
182
+ console.log(` ${chalk.yellow('โš ')} ${repo.name}: Using default fallback test command "npm test"`);
183
+ } else {
184
+ console.log(` ${chalk.green('โœ”')} ${repo.name}: Test command is "${testCommand}"`);
185
+ }
186
+ }
187
+ console.log();
188
+
189
+ // โ”€โ”€ 6. Missing Core Files โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
190
+ console.log(chalk.bold('๐Ÿ“„ Core Artifacts:'));
191
+ const coreFiles = [
192
+ { name: 'WORKSPACE.md', required: true },
193
+ { name: 'nexusflow-knowledge.md', required: true },
194
+ { name: 'nexusflow-plan.md', required: true },
195
+ ];
196
+
197
+ // Add expected maps
198
+ for (const repo of allRepos) {
199
+ coreFiles.push({ name: `nexusflow-map-${repo.name}.md`, required: true });
200
+ }
201
+
202
+ for (const file of coreFiles) {
203
+ const filePath = path.join(workspacePath, file.name);
204
+ try {
205
+ await fs.access(filePath);
206
+ console.log(` ${chalk.green('โœ”')} ${file.name} exists`);
207
+ } catch {
208
+ warnings.push(`Missing core workspace artifact: "${file.name}".`);
209
+ console.log(` ${chalk.yellow('โš ')} ${file.name} is missing`);
210
+ }
211
+ }
212
+
213
+ // Check VS Code Settings for search.useIgnoreFiles: false
214
+ const vscodeSettingsPath = path.join(workspacePath, '.vscode', 'settings.json');
215
+ try {
216
+ const content = await fs.readFile(vscodeSettingsPath, 'utf-8');
217
+ const parsed = JSON.parse(content);
218
+ if (parsed['search.useIgnoreFiles'] === false) {
219
+ console.log(` ${chalk.green('โœ”')} .vscode/settings.json is configured correctly (search.useIgnoreFiles: false)`);
220
+ } else {
221
+ warnings.push('.vscode/settings.json search.useIgnoreFiles is not set to false. VS Code global search may ignore repository files.');
222
+ console.log(` ${chalk.yellow('โš ')} .vscode/settings.json: search.useIgnoreFiles is not set to false`);
223
+ }
224
+ } catch {
225
+ warnings.push('Missing .vscode/settings.json. VS Code search might not work properly inside sub-repos.');
226
+ console.log(` ${chalk.yellow('โš ')} .vscode/settings.json is missing or invalid`);
227
+ }
228
+ console.log();
229
+
230
+ // โ”€โ”€ Summary Report โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
231
+ console.log(chalk.bold('๐Ÿ“Š Diagnostic Summary:'));
232
+ if (errors.length === 0 && warnings.length === 0) {
233
+ console.log(chalk.bold.green(' โœ” All checks passed! Workspace is healthy.\n'));
234
+ } else {
235
+ if (errors.length > 0) {
236
+ console.log(chalk.bold.red(` โœ– ${errors.length} error(s) found. Fix them before proceeding.`));
237
+ for (const err of errors) console.log(` - ${err}`);
238
+ }
239
+ if (warnings.length > 0) {
240
+ console.log(chalk.bold.yellow(` โš  ${warnings.length} warning(s) found.`));
241
+ for (const warn of warnings) console.log(` - ${warn}`);
242
+ }
243
+ console.log();
244
+ }
245
+ }
246
+
247
+ /**
248
+ * Resolves correct test command candidate.
249
+ */
250
+ function getTestCommand(analysis: any): string {
251
+ if (analysis.techStack.languages.includes('csharp')) {
252
+ return 'dotnet test';
253
+ }
254
+ if (analysis.techStack.languages.includes('typescript') || analysis.techStack.languages.includes('javascript')) {
255
+ return 'npm test';
256
+ }
257
+ if (analysis.techStack.languages.includes('python')) {
258
+ return 'pytest';
259
+ }
260
+ if (analysis.techStack.languages.includes('go')) {
261
+ return 'go test ./...';
262
+ }
263
+ return 'npm test'; // fallback
264
+ }
265
+
266
+ /**
267
+ * Resolves a workspace path.
268
+ */
269
+ async function resolveWorkspace(workspaceArg?: string): Promise<string | null> {
270
+ if (workspaceArg) {
271
+ const absolutePath = path.resolve(workspaceArg);
272
+ try {
273
+ await fs.access(path.join(absolutePath, 'nexusflow.json'));
274
+ return absolutePath;
275
+ } catch {
276
+ console.error(chalk.red(`โœ– Invalid workspace: No nexusflow.json found at ${absolutePath}`));
277
+ return null;
278
+ }
279
+ }
280
+
281
+ const cwdFeature = await loadFeatureConfig(process.cwd());
282
+ if (cwdFeature) return process.cwd();
283
+
284
+ const config = await loadConfig();
285
+ const workspaces = await listWorkspaces(config.workspacesDir);
286
+
287
+ if (workspaces.length === 0) {
288
+ console.log(chalk.yellow('No workspaces found.\n'));
289
+ return null;
290
+ }
291
+
292
+ const selected = await select({
293
+ message: 'Select a workspace to diagnose:',
294
+ choices: workspaces.map((ws) => ({
295
+ name: `${ws.branchName} ${chalk.dim(`(${ws.repos.length} repos)`)}`,
296
+ value: ws.workspacePath,
297
+ })),
298
+ });
299
+
300
+ return selected;
301
+ }
@@ -0,0 +1,266 @@
1
+ import chalk from 'chalk';
2
+ import { select } from '@inquirer/prompts';
3
+ import * as path from 'node:path';
4
+ import * as fs from 'node:fs/promises';
5
+ import { execa } from 'execa';
6
+
7
+ import { loadConfig } from '../core/config.js';
8
+ import { listWorkspaces, loadFeatureConfig } from '../core/workspace.js';
9
+ import { getWorkspaceRepos, getRepoStatus } from '../utils/multi-git.js';
10
+ import { analyzeAllRepos } from '../analyzers/index.js';
11
+ import { buildDependencyGraph } from '../generators/plan-generator.js';
12
+
13
+ /**
14
+ * Runs the handoff command.
15
+ * Auto-detects workspace from CWD or prompts user to select one.
16
+ *
17
+ * @param workspaceArg - Optional workspace path from CLI.
18
+ */
19
+ export async function handoffCommand(workspaceArg?: string): Promise<void> {
20
+ console.log(chalk.bold.cyan('\n๐Ÿค NexusFlow โ€” Handoff Bundle\n'));
21
+
22
+ const workspacePath = await resolveWorkspace(workspaceArg);
23
+ if (!workspacePath) return;
24
+
25
+ const feature = await loadFeatureConfig(workspacePath);
26
+ if (!feature) {
27
+ console.error(chalk.red('โœ– Failed to load workspace configuration. Ensure nexusflow.json exists.'));
28
+ return;
29
+ }
30
+
31
+ const allRepos = await Promise.all(
32
+ feature.repos.map(async (r) => {
33
+ const repoName = path.basename(r);
34
+ return {
35
+ name: repoName,
36
+ path: r,
37
+ defaultBranch: 'main',
38
+ };
39
+ })
40
+ );
41
+
42
+ console.log(chalk.cyan('Retrieving repository statuses and running analysis...'));
43
+ const analysis = await analyzeAllRepos(allRepos);
44
+
45
+ const reposStatusInfo = await Promise.all(
46
+ allRepos.map(async (repo) => {
47
+ const status = await getRepoStatus(repo.path);
48
+ const branch = await getRepoBranch(repo.path);
49
+ const repoAnalysis = analysis.get(repo.path);
50
+
51
+ const suggestedFiles = getSuggestedFiles(repo.path, status.changedFiles, repoAnalysis);
52
+ const testCommand = getTestCommand(repo.path, repoAnalysis);
53
+
54
+ return {
55
+ name: repo.name,
56
+ path: repo.path,
57
+ branch,
58
+ dirtySummary: status.summary,
59
+ isDirty: status.hasChanges,
60
+ changedFiles: status.changedFiles,
61
+ suggestedFiles,
62
+ testCommand,
63
+ };
64
+ })
65
+ );
66
+
67
+ // Parse knowledge from nexusflow-knowledge.md if it exists
68
+ const knowledgePath = path.join(workspacePath, 'nexusflow-knowledge.md');
69
+ let extractedGotchas = '_None recorded yet._';
70
+ let extractedDecisions = '_None recorded yet._';
71
+ let extractedQuestions = '_None recorded yet._';
72
+
73
+ try {
74
+ const knowledgeContent = await fs.readFile(knowledgePath, 'utf-8');
75
+ extractedGotchas = extractSection(knowledgeContent, 'Known Gotchas');
76
+ extractedDecisions = extractSection(knowledgeContent, 'Architecture Decisions');
77
+ extractedQuestions = extractSection(knowledgeContent, 'Clarifying Questions for the User');
78
+ } catch {}
79
+
80
+ // Build dependency description
81
+ let depGraphDescription = '';
82
+ try {
83
+ const graph = buildDependencyGraph(analysis, allRepos);
84
+ const relations: string[] = [];
85
+ for (const [name, node] of graph) {
86
+ if (node.dependsOn.length > 0) {
87
+ relations.push(`- **${name}** depends on: ${node.dependsOn.map(d => `\`${d}\``).join(', ')}`);
88
+ }
89
+ }
90
+ depGraphDescription = relations.length > 0 ? relations.join('\n') : '_No inter-repo package dependencies detected._';
91
+ } catch {
92
+ depGraphDescription = '_Error generating dependency graph._';
93
+ }
94
+
95
+ const timestamp = new Date().toISOString();
96
+
97
+ // Format handoff bundle
98
+ const md: string[] = [];
99
+ md.push(`# NexusFlow Handoff Bundle โ€” ${feature.branchName}`);
100
+ md.push('');
101
+ md.push(`> **Workspace Path:** \`${workspacePath}\``);
102
+ md.push(`> **Current Branch:** \`${feature.branchName}\``);
103
+ md.push(`> **Generated:** ${timestamp} (UTC)`);
104
+ md.push('> **Instruction:** Read this handoff bundle first to resume context immediately.');
105
+ md.push('');
106
+ md.push('## ๐Ÿ“‹ Repository Statuses');
107
+ md.push('');
108
+ md.push('| Repository | Branch | Git Status | Suggested Files to Read |');
109
+ md.push('|---|---|---|---|');
110
+
111
+ for (const r of reposStatusInfo) {
112
+ const filesList = r.suggestedFiles.map(f => `\`${f}\``).join(', ') || 'โ€”';
113
+ const statusText = r.isDirty ? `โš ๏ธ ${r.dirtySummary}` : 'โœ… Clean';
114
+ md.push(`| **${r.name}** | \`${r.branch}\` | ${statusText} | ${filesList} |`);
115
+ }
116
+ md.push('');
117
+
118
+ md.push('## ๐Ÿงช Verification & Run Commands');
119
+ md.push('');
120
+ for (const r of reposStatusInfo) {
121
+ md.push(`- **${r.name}**: \`${r.testCommand}\``);
122
+ }
123
+ md.push('');
124
+
125
+ md.push('## ๐Ÿ—๏ธ Inter-Repo Package Graph');
126
+ md.push('');
127
+ md.push(depGraphDescription);
128
+ md.push('');
129
+
130
+ md.push('## ๐Ÿ“ Active Session Context (from nexusflow-knowledge.md)');
131
+ md.push('');
132
+ md.push('### Open Gotchas & Blockers');
133
+ md.push(extractedGotchas);
134
+ md.push('');
135
+ md.push('### Recent Architecture Decisions');
136
+ md.push(extractedDecisions);
137
+ md.push('');
138
+ md.push('### Outstanding Clarifying Questions');
139
+ md.push(extractedQuestions);
140
+ md.push('');
141
+
142
+ const handoffFilePath = path.join(workspacePath, 'nexusflow-handoff.md');
143
+ await fs.writeFile(handoffFilePath, md.join('\n'), 'utf-8');
144
+
145
+ console.log(chalk.green(`\nโœ… Generated handoff bundle: ${chalk.bold('nexusflow-handoff.md')}`));
146
+ console.log(chalk.dim(` Path: ${handoffFilePath}\n`));
147
+ }
148
+
149
+ /**
150
+ * Gets the current branch name of a repository.
151
+ */
152
+ async function getRepoBranch(repoPath: string): Promise<string> {
153
+ try {
154
+ const { stdout } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: repoPath });
155
+ return stdout.trim();
156
+ } catch {
157
+ return 'unknown';
158
+ }
159
+ }
160
+
161
+ /**
162
+ * Determines a candidate list of files to read first.
163
+ */
164
+ function getSuggestedFiles(repoPath: string, dirtyFiles: string[], analysis?: any): string[] {
165
+ if (dirtyFiles.length > 0) {
166
+ return dirtyFiles.slice(0, 3).map(f => f.replace(/\\/g, '/'));
167
+ }
168
+
169
+ const suggestions: string[] = [];
170
+ if (analysis && analysis.runConfig && analysis.runConfig.entryPoints) {
171
+ for (const ep of analysis.runConfig.entryPoints) {
172
+ if (ep.projectPath && !suggestions.includes(ep.projectPath)) {
173
+ suggestions.push(ep.projectPath);
174
+ }
175
+ }
176
+ }
177
+
178
+ suggestions.push('README.md');
179
+ return suggestions.slice(0, 3);
180
+ }
181
+
182
+ /**
183
+ * Resolves correct test command.
184
+ */
185
+ function getTestCommand(repoPath: string, analysis?: any): string {
186
+ if (analysis) {
187
+ if (analysis.techStack.languages.includes('csharp')) {
188
+ return 'dotnet test';
189
+ }
190
+ if (analysis.techStack.languages.includes('typescript') || analysis.techStack.languages.includes('javascript')) {
191
+ return 'npm test';
192
+ }
193
+ if (analysis.techStack.languages.includes('python')) {
194
+ return 'pytest';
195
+ }
196
+ if (analysis.techStack.languages.includes('go')) {
197
+ return 'go test ./...';
198
+ }
199
+ }
200
+ return 'npm test'; // fallback
201
+ }
202
+
203
+ /**
204
+ * Extracts a specific section from the knowledge file.
205
+ */
206
+ function extractSection(content: string, header: string): string {
207
+ const lines = content.split('\n');
208
+ const index = lines.findIndex(l => l.trim().startsWith(`## ${header}`));
209
+ if (index === -1) return '_None recorded yet._';
210
+
211
+ const resultLines: string[] = [];
212
+ for (let i = index + 1; i < lines.length; i++) {
213
+ if (lines[i]!.trim().startsWith('##')) break;
214
+ resultLines.push(lines[i]!);
215
+ }
216
+
217
+ const sectionContent = resultLines.join('\n').trim();
218
+ if (
219
+ !sectionContent ||
220
+ sectionContent.includes('No assumptions recorded yet') ||
221
+ sectionContent.includes('No open questions recorded yet') ||
222
+ sectionContent.includes('No decisions recorded yet') ||
223
+ sectionContent.includes('No gotchas recorded yet') ||
224
+ sectionContent.includes('AI assistant to populate')
225
+ ) {
226
+ return '_None recorded yet._';
227
+ }
228
+ return sectionContent;
229
+ }
230
+
231
+ /**
232
+ * Resolves a workspace path.
233
+ */
234
+ async function resolveWorkspace(workspaceArg?: string): Promise<string | null> {
235
+ if (workspaceArg) {
236
+ const absolutePath = path.resolve(workspaceArg);
237
+ try {
238
+ await fs.access(path.join(absolutePath, 'nexusflow.json'));
239
+ return absolutePath;
240
+ } catch {
241
+ console.error(chalk.red(`โœ– Invalid workspace: No nexusflow.json found at ${absolutePath}`));
242
+ return null;
243
+ }
244
+ }
245
+
246
+ const cwdFeature = await loadFeatureConfig(process.cwd());
247
+ if (cwdFeature) return process.cwd();
248
+
249
+ const config = await loadConfig();
250
+ const workspaces = await listWorkspaces(config.workspacesDir);
251
+
252
+ if (workspaces.length === 0) {
253
+ console.log(chalk.yellow('No workspaces found.\n'));
254
+ return null;
255
+ }
256
+
257
+ const selected = await select({
258
+ message: 'Select a workspace:',
259
+ choices: workspaces.map((ws) => ({
260
+ name: `${ws.branchName} ${chalk.dim(`(${ws.repos.length} repos)`)}`,
261
+ value: ws.workspacePath,
262
+ })),
263
+ });
264
+
265
+ return selected;
266
+ }