@mrpatronz/nexusflow 0.2.7 → 0.2.11

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 (99) hide show
  1. package/.github/workflows/release.yml +7 -0
  2. package/dist/commands/create.d.ts.map +1 -1
  3. package/dist/commands/create.js +6 -1
  4. package/dist/commands/create.js.map +1 -1
  5. package/dist/commands/doctor.d.ts.map +1 -1
  6. package/dist/commands/doctor.js +58 -0
  7. package/dist/commands/doctor.js.map +1 -1
  8. package/dist/commands/init.d.ts.map +1 -1
  9. package/dist/commands/init.js +73 -1
  10. package/dist/commands/init.js.map +1 -1
  11. package/dist/core/config.d.ts.map +1 -1
  12. package/dist/core/config.js +11 -1
  13. package/dist/core/config.js.map +1 -1
  14. package/dist/core/config.test.d.ts +2 -0
  15. package/dist/core/config.test.d.ts.map +1 -0
  16. package/dist/core/config.test.js +75 -0
  17. package/dist/core/config.test.js.map +1 -0
  18. package/dist/core/scanner.test.d.ts +2 -0
  19. package/dist/core/scanner.test.d.ts.map +1 -0
  20. package/dist/core/scanner.test.js +53 -0
  21. package/dist/core/scanner.test.js.map +1 -0
  22. package/dist/generators/base.d.ts.map +1 -1
  23. package/dist/generators/base.js +8 -2
  24. package/dist/generators/base.js.map +1 -1
  25. package/dist/generators/skills-generator.js +1 -1
  26. package/dist/generators/skills-generator.js.map +1 -1
  27. package/dist/gui/assets/index-Ca2VRMrQ.js +22 -0
  28. package/dist/gui/assets/index-fj0RJiOb.css +2 -0
  29. package/dist/gui/index.html +2 -2
  30. package/dist/mcp/server.d.ts.map +1 -1
  31. package/dist/mcp/server.js +132 -93
  32. package/dist/mcp/server.js.map +1 -1
  33. package/dist/server.d.ts.map +1 -1
  34. package/dist/server.js +134 -12
  35. package/dist/server.js.map +1 -1
  36. package/dist/server.test.d.ts +2 -0
  37. package/dist/server.test.d.ts.map +1 -0
  38. package/dist/server.test.js +401 -0
  39. package/dist/server.test.js.map +1 -0
  40. package/dist/types.d.ts +12 -0
  41. package/dist/types.d.ts.map +1 -1
  42. package/dist/utils/detect-ai.test.d.ts +2 -0
  43. package/dist/utils/detect-ai.test.d.ts.map +1 -0
  44. package/dist/utils/detect-ai.test.js +37 -0
  45. package/dist/utils/detect-ai.test.js.map +1 -0
  46. package/dist/utils/detect-editors.test.d.ts +2 -0
  47. package/dist/utils/detect-editors.test.d.ts.map +1 -0
  48. package/dist/utils/detect-editors.test.js +39 -0
  49. package/dist/utils/detect-editors.test.js.map +1 -0
  50. package/dist/utils/git.test.d.ts +2 -0
  51. package/dist/utils/git.test.d.ts.map +1 -0
  52. package/dist/utils/git.test.js +55 -0
  53. package/dist/utils/git.test.js.map +1 -0
  54. package/dist/utils/local-ai.d.ts +27 -0
  55. package/dist/utils/local-ai.d.ts.map +1 -0
  56. package/dist/utils/local-ai.js +96 -0
  57. package/dist/utils/local-ai.js.map +1 -0
  58. package/dist/utils/local-ai.test.d.ts +2 -0
  59. package/dist/utils/local-ai.test.d.ts.map +1 -0
  60. package/dist/utils/local-ai.test.js +108 -0
  61. package/dist/utils/local-ai.test.js.map +1 -0
  62. package/dist/utils/system-scanner.d.ts +16 -0
  63. package/dist/utils/system-scanner.d.ts.map +1 -0
  64. package/dist/utils/system-scanner.js +85 -0
  65. package/dist/utils/system-scanner.js.map +1 -0
  66. package/dist/utils/system-scanner.test.d.ts +2 -0
  67. package/dist/utils/system-scanner.test.d.ts.map +1 -0
  68. package/dist/utils/system-scanner.test.js +73 -0
  69. package/dist/utils/system-scanner.test.js.map +1 -0
  70. package/gui/e2e/wizard.spec.ts +327 -0
  71. package/gui/package-lock.json +64 -0
  72. package/gui/package.json +4 -1
  73. package/gui/playwright.config.ts +41 -0
  74. package/gui/src/App.tsx +376 -786
  75. package/gui/src/index.css +16 -0
  76. package/package.json +3 -1
  77. package/scripts/simulate-workspaces.ts +55 -0
  78. package/src/commands/create.ts +7 -1
  79. package/src/commands/doctor.ts +56 -0
  80. package/src/commands/init.ts +77 -1
  81. package/src/core/config.test.ts +96 -0
  82. package/src/core/config.ts +11 -1
  83. package/src/core/scanner.test.ts +61 -0
  84. package/src/generators/base.ts +13 -2
  85. package/src/generators/skills-generator.ts +1 -1
  86. package/src/mcp/server.ts +144 -95
  87. package/src/server.test.ts +464 -0
  88. package/src/server.ts +141 -11
  89. package/src/types.ts +16 -0
  90. package/src/utils/detect-ai.test.ts +44 -0
  91. package/src/utils/detect-editors.test.ts +47 -0
  92. package/src/utils/git.test.ts +74 -0
  93. package/src/utils/local-ai.test.ts +130 -0
  94. package/src/utils/local-ai.ts +111 -0
  95. package/src/utils/system-scanner.test.ts +89 -0
  96. package/src/utils/system-scanner.ts +96 -0
  97. package/vitest.config.ts +2 -1
  98. package/dist/gui/assets/index-BgEo5w2Q.js +0 -22
  99. package/dist/gui/assets/index-D-VigurY.css +0 -2
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @module utils/local-ai
3
+ * Handles requests to local LLM servers (Ollama or OpenAI-compatible like LM Studio).
4
+ */
5
+
6
+ import type { LocalLlmConfig } from '../types.js';
7
+
8
+ export interface LocalLlmMessage {
9
+ role: 'system' | 'user' | 'assistant';
10
+ content: string;
11
+ }
12
+
13
+ /**
14
+ * Sends a chat completion request to the configured local LLM provider.
15
+ * Supports Ollama-specific API and standard OpenAI-compatible endpoints.
16
+ */
17
+ export async function callLocalLlm(
18
+ config: LocalLlmConfig,
19
+ messages: LocalLlmMessage[],
20
+ ): Promise<string> {
21
+ const { provider, endpoint, model } = config;
22
+ const cleanEndpoint = endpoint.replace(/\/$/, '');
23
+ const controller = new AbortController();
24
+ const timeout = setTimeout(() => controller.abort(), 60_000);
25
+
26
+ try {
27
+ if (provider === 'ollama') {
28
+ const url = `${cleanEndpoint}/api/chat`;
29
+ const response = await fetch(url, {
30
+ method: 'POST',
31
+ headers: {
32
+ 'Content-Type': 'application/json',
33
+ },
34
+ body: JSON.stringify({
35
+ model,
36
+ messages,
37
+ stream: false,
38
+ }),
39
+ signal: controller.signal,
40
+ });
41
+
42
+ if (!response.ok) {
43
+ const text = await response.text();
44
+ throw new Error(`Ollama request failed with status ${response.status}: ${text}`);
45
+ }
46
+
47
+ const data: any = await response.json();
48
+ if (data?.message?.content) {
49
+ return data.message.content;
50
+ }
51
+ throw new Error('Invalid response format received from Ollama');
52
+ } else {
53
+ // OpenAI-compatible provider
54
+ const url = getOpenAiCompatibleUrl(cleanEndpoint, '/v1/chat/completions');
55
+
56
+ const response = await fetch(url, {
57
+ method: 'POST',
58
+ headers: {
59
+ 'Content-Type': 'application/json',
60
+ },
61
+ body: JSON.stringify({
62
+ model,
63
+ messages,
64
+ stream: false,
65
+ }),
66
+ signal: controller.signal,
67
+ });
68
+
69
+ if (!response.ok) {
70
+ const text = await response.text();
71
+ throw new Error(`OpenAI-compatible request failed with status ${response.status}: ${text}`);
72
+ }
73
+
74
+ const data: any = await response.json();
75
+ if (data?.choices?.[0]?.message?.content) {
76
+ return data.choices[0].message.content;
77
+ }
78
+ throw new Error('Invalid response format received from OpenAI-compatible endpoint');
79
+ }
80
+ } catch (error: any) {
81
+ if (error.name === 'AbortError') {
82
+ throw new Error('Local LLM request timed out after 60 seconds');
83
+ }
84
+ throw error;
85
+ } finally {
86
+ clearTimeout(timeout);
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Checks whether a target model name matches any model in an Ollama model list.
92
+ * Handles tag variations like 'model' vs 'model:latest' vs 'model:7b'.
93
+ */
94
+ export function isOllamaModelAvailable(models: { name: string }[], targetModel: string): boolean {
95
+ const normalize = (name: string) => name.includes(':') ? name : `${name}:latest`;
96
+ const targetNorm = normalize(targetModel);
97
+ return models.some((m) => normalize(m.name) === targetNorm);
98
+ }
99
+
100
+ /**
101
+ * Helper to build standard OpenAI compatible URLs.
102
+ * Handles cases where the configured endpoint already has or does not have `/v1`.
103
+ */
104
+ export function getOpenAiCompatibleUrl(endpoint: string, suffix: string): string {
105
+ const cleanEndpoint = endpoint.replace(/\/$/, '');
106
+ const hasV1 = /\/v1\/?$/.test(cleanEndpoint);
107
+ if (hasV1) {
108
+ return `${cleanEndpoint.replace(/\/v1\/?$/, '')}${suffix}`;
109
+ }
110
+ return `${cleanEndpoint}${suffix}`;
111
+ }
@@ -0,0 +1,89 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { execa } from 'execa';
3
+ import * as os from 'node:os';
4
+ import { scanSystemSpecs } from './system-scanner.js';
5
+
6
+ vi.mock('execa');
7
+ vi.mock('node:os', async () => {
8
+ const actual = await vi.importActual<typeof import('node:os')>('node:os');
9
+ return {
10
+ ...actual,
11
+ totalmem: vi.fn(),
12
+ platform: vi.fn(),
13
+ };
14
+ });
15
+
16
+ describe('scanSystemSpecs', () => {
17
+ beforeEach(() => {
18
+ vi.clearAllMocks();
19
+ });
20
+
21
+ it('should recommend 7b on windows with 16GB RAM even if no GPU detected', async () => {
22
+ vi.mocked(os.totalmem).mockReturnValue(16 * 1024 * 1024 * 1024);
23
+ vi.mocked(os.platform).mockReturnValue('win32');
24
+ vi.mocked(execa).mockResolvedValue({ stdout: '' } as any);
25
+
26
+ const specs = await scanSystemSpecs();
27
+
28
+ expect(specs.totalRamGb).toBe(16);
29
+ expect(specs.gpuName).toBe('Unknown/Integrated');
30
+ expect(specs.hasHardwareAcceleration).toBe(false);
31
+ expect(specs.recommendedModel).toBe('qwen2.5-coder:7b');
32
+ });
33
+
34
+ it('should recommend 1.5b on windows with 8GB RAM and no GPU', async () => {
35
+ vi.mocked(os.totalmem).mockReturnValue(8 * 1024 * 1024 * 1024);
36
+ vi.mocked(os.platform).mockReturnValue('win32');
37
+ vi.mocked(execa).mockResolvedValue({ stdout: '' } as any);
38
+
39
+ const specs = await scanSystemSpecs();
40
+
41
+ expect(specs.totalRamGb).toBe(8);
42
+ expect(specs.recommendedModel).toBe('qwen2.5-coder:1.5b');
43
+ });
44
+
45
+ it('should detect Nvidia GPU on Windows and recommend 7b with 12GB RAM', async () => {
46
+ vi.mocked(os.totalmem).mockReturnValue(12 * 1024 * 1024 * 1024);
47
+ vi.mocked(os.platform).mockReturnValue('win32');
48
+ vi.mocked(execa).mockResolvedValue({
49
+ stdout: 'NVIDIA GeForce RTX 4070 Laptop GPU\r\n'
50
+ } as any);
51
+
52
+ const specs = await scanSystemSpecs();
53
+
54
+ expect(specs.totalRamGb).toBe(12);
55
+ expect(specs.gpuName).toBe('NVIDIA GeForce RTX 4070 Laptop GPU');
56
+ expect(specs.hasHardwareAcceleration).toBe(true);
57
+ expect(specs.recommendedModel).toBe('qwen2.5-coder:7b');
58
+ });
59
+
60
+ it('should detect Apple Silicon on Darwin and recommend 7b with 12GB RAM', async () => {
61
+ vi.mocked(os.totalmem).mockReturnValue(12 * 1024 * 1024 * 1024);
62
+ vi.mocked(os.platform).mockReturnValue('darwin');
63
+ vi.mocked(execa).mockResolvedValue({
64
+ stdout: 'Apple M3 Max\n'
65
+ } as any);
66
+
67
+ const specs = await scanSystemSpecs();
68
+
69
+ expect(specs.totalRamGb).toBe(12);
70
+ expect(specs.gpuName).toBe('Apple Silicon (Integrated)');
71
+ expect(specs.hasHardwareAcceleration).toBe(true);
72
+ expect(specs.recommendedModel).toBe('qwen2.5-coder:7b');
73
+ });
74
+
75
+ it('should detect Linux GPU and recommend 7b with 12GB RAM', async () => {
76
+ vi.mocked(os.totalmem).mockReturnValue(12 * 1024 * 1024 * 1024);
77
+ vi.mocked(os.platform).mockReturnValue('linux');
78
+ vi.mocked(execa).mockResolvedValue({
79
+ stdout: '01:00.0 VGA compatible controller: NVIDIA Corporation AD104 [GeForce RTX 4070 Ti] (rev a1)\n'
80
+ } as any);
81
+
82
+ const specs = await scanSystemSpecs();
83
+
84
+ expect(specs.totalRamGb).toBe(12);
85
+ expect(specs.gpuName).toBe('NVIDIA Corporation AD104 [GeForce RTX 4070 Ti] (rev a1)');
86
+ expect(specs.hasHardwareAcceleration).toBe(true);
87
+ expect(specs.recommendedModel).toBe('qwen2.5-coder:7b');
88
+ });
89
+ });
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @module utils/system-scanner
3
+ * Detects local system specifications (RAM, GPU) and recommends the optimal local LLM size.
4
+ */
5
+
6
+ import { execa } from 'execa';
7
+ import * as os from 'node:os';
8
+
9
+ export interface SystemSpecs {
10
+ totalRamGb: number;
11
+ gpuName: string;
12
+ hasHardwareAcceleration: boolean;
13
+ recommendedModel: string;
14
+ }
15
+
16
+ /**
17
+ * Probes the local operating system to detect RAM and GPU specifications,
18
+ * returning a recommended local LLM model name.
19
+ */
20
+ export async function scanSystemSpecs(): Promise<SystemSpecs> {
21
+ const totalRamGb = Math.round(os.totalmem() / (1024 * 1024 * 1024));
22
+ let gpuName = 'Unknown/Integrated';
23
+ let hasHardwareAcceleration = false;
24
+
25
+ const platform = os.platform();
26
+
27
+ try {
28
+ if (platform === 'win32') {
29
+ const { stdout } = await execa('powershell', ['-NoProfile', '-Command', 'Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name'], { reject: false });
30
+ if (stdout) {
31
+ const lines = stdout.split('\n')
32
+ .map(l => l.trim())
33
+ .filter(l => l && l.toLowerCase() !== 'name');
34
+
35
+ if (lines.length > 0) {
36
+ gpuName = lines.join(', ');
37
+ const lowerGpu = gpuName.toLowerCase();
38
+ if (
39
+ lowerGpu.includes('nvidia') ||
40
+ lowerGpu.includes('radeon') ||
41
+ lowerGpu.includes('geforce') ||
42
+ lowerGpu.includes('rtx') ||
43
+ lowerGpu.includes('gtx')
44
+ ) {
45
+ hasHardwareAcceleration = true;
46
+ }
47
+ }
48
+ }
49
+ } else if (platform === 'darwin') {
50
+ const { stdout } = await execa('sysctl', ['-n', 'machdep.cpu.brand_string'], { reject: false });
51
+ if (stdout && stdout.toLowerCase().includes('apple')) {
52
+ gpuName = 'Apple Silicon (Integrated)';
53
+ hasHardwareAcceleration = true;
54
+ } else {
55
+ const { stdout: spOut } = await execa('system_profiler', ['SPDisplaysDataType'], { reject: false });
56
+ if (spOut) {
57
+ gpuName = 'Intel Mac GPU';
58
+ const lowerGpu = spOut.toLowerCase();
59
+ if (lowerGpu.includes('amd') || lowerGpu.includes('radeon') || lowerGpu.includes('nvidia')) {
60
+ hasHardwareAcceleration = true;
61
+ }
62
+ }
63
+ }
64
+ } else if (platform === 'linux') {
65
+ const { stdout } = await execa('lspci', [], { reject: false });
66
+ if (stdout) {
67
+ const gpuLines = stdout.split('\n').filter(line => line.toLowerCase().includes('vga') || line.toLowerCase().includes('3d'));
68
+ if (gpuLines.length > 0) {
69
+ gpuName = gpuLines.map(line => line.split(':').pop()?.trim()).filter(Boolean).join(', ');
70
+ const lowerGpu = gpuName.toLowerCase();
71
+ if (lowerGpu.includes('nvidia') || lowerGpu.includes('amd') || lowerGpu.includes('radeon')) {
72
+ hasHardwareAcceleration = true;
73
+ }
74
+ }
75
+ }
76
+ }
77
+ } catch {
78
+ // Ignore execution failures, fall back to default values
79
+ }
80
+
81
+ // Recommendation logic:
82
+ // - RAM >= 12GB AND has dedicated GPU/Apple Silicon -> Recommend 7B
83
+ // - RAM >= 16GB regardless of GPU -> Recommend 7B (can run fine on CPU)
84
+ // - Otherwise -> Recommend 1.5B (fast and safe)
85
+ let recommendedModel = 'qwen2.5-coder:1.5b';
86
+ if ((totalRamGb >= 12 && hasHardwareAcceleration) || totalRamGb >= 16) {
87
+ recommendedModel = 'qwen2.5-coder:7b';
88
+ }
89
+
90
+ return {
91
+ totalRamGb,
92
+ gpuName,
93
+ hasHardwareAcceleration,
94
+ recommendedModel,
95
+ };
96
+ }
package/vitest.config.ts CHANGED
@@ -7,7 +7,8 @@ export default defineConfig({
7
7
  '**/dist/**',
8
8
  '**/cypress/**',
9
9
  '**/.{idea,git,cache,output,temp}/**',
10
- '**/scratch/**'
10
+ '**/scratch/**',
11
+ '**/gui/**'
11
12
  ]
12
13
  }
13
14
  });