@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
package/src/mcp/server.ts CHANGED
@@ -9,6 +9,7 @@ import * as fs from 'node:fs/promises';
9
9
  import * as path from 'node:path';
10
10
  import { loadConfig } from '../core/config.js';
11
11
  import { loadFeatureConfig } from '../core/workspace.js';
12
+ import { callLocalLlm } from '../utils/local-ai.js';
12
13
 
13
14
  export async function startMcpServer(workspacePath?: string) {
14
15
  const server = new Server(
@@ -24,86 +25,73 @@ export async function startMcpServer(workspacePath?: string) {
24
25
  );
25
26
 
26
27
  server.setRequestHandler(ListToolsRequestSchema, async () => {
27
- return {
28
- tools: [
29
- {
30
- name: 'search_workspace',
31
- description: 'Search for a string or regex across all repositories in the NexusFlow workspace. Extremely fast and useful for finding where a specific variable, function, or concept is used across microservices.',
32
- inputSchema: {
33
- type: 'object',
34
- properties: {
35
- query: {
36
- type: 'string',
37
- description: 'The search query or regular expression',
38
- },
39
- workspaceId: {
40
- type: 'string',
41
- description: 'Optional ID/branchName of the workspace to search. If omitted, uses the currently active workspace.',
42
- },
28
+ const config = await loadConfig();
29
+ const tools: any[] = [
30
+ {
31
+ name: 'search_workspace',
32
+ description: 'Search for a string or regex across all repositories in the NexusFlow workspace. Extremely fast and useful for finding where a specific variable, function, or concept is used across microservices.',
33
+ inputSchema: {
34
+ type: 'object',
35
+ properties: {
36
+ query: {
37
+ type: 'string',
38
+ description: 'The search query or regular expression',
43
39
  },
44
- required: ['query'],
45
- },
46
- },
47
- {
48
- name: 'get_service_logs',
49
- description: 'Get the recent logs for a specific running service in the workspace to debug runtime issues.',
50
- inputSchema: {
51
- type: 'object',
52
- properties: {
53
- serviceName: {
54
- type: 'string',
55
- description: 'The name of the service to fetch logs for (e.g. "frontend", "backend-api")',
56
- },
57
- lines: {
58
- type: 'number',
59
- description: 'Number of lines to fetch. Default 50.',
60
- },
61
- workspaceId: {
62
- type: 'string',
63
- description: 'Optional ID/branchName of the workspace. If omitted, uses the currently active workspace.',
64
- },
40
+ workspaceId: {
41
+ type: 'string',
42
+ description: 'Optional ID/branchName of the workspace to search. If omitted, uses the currently active workspace.',
65
43
  },
66
- required: ['serviceName'],
67
44
  },
45
+ required: ['query'],
68
46
  },
69
- {
70
- name: 'get_workspace_graph',
71
- description: 'Retrieve the structural architecture graph of the NexusFlow workspace. Contains nodes for repos, packages, API endpoints, and exposed ports, plus relation edges (CONTAINS, DEPENDS_ON, EXPOSES, CALLS). Highly token-efficient for global workspace context.',
72
- inputSchema: {
73
- type: 'object',
74
- properties: {
75
- workspaceId: {
76
- type: 'string',
77
- description: 'Optional ID/branchName of the workspace. If omitted, uses the currently active workspace.',
78
- },
47
+ },
48
+ {
49
+ name: 'get_service_logs',
50
+ description: 'Get the recent logs for a specific running service in the workspace to debug runtime issues.',
51
+ inputSchema: {
52
+ type: 'object',
53
+ properties: {
54
+ serviceName: {
55
+ type: 'string',
56
+ description: 'The name of the service to fetch logs for (e.g. "frontend", "backend-api")',
57
+ },
58
+ lines: {
59
+ type: 'number',
60
+ description: 'Number of lines to fetch. Default 50.',
61
+ },
62
+ workspaceId: {
63
+ type: 'string',
64
+ description: 'Optional ID/branchName of the workspace. If omitted, uses the currently active workspace.',
79
65
  },
80
66
  },
67
+ required: ['serviceName'],
81
68
  },
82
- {
83
- name: 'query_workspace_graph',
84
- description: 'Query the workspace architecture graph by filtering nodes or edges (e.g., node types like "repo", "package", "endpoint", "port", or edge types like "DEPENDS_ON", "EXPOSES", "CALLS"). Reduces token payload by fetching specific architectural paths.',
85
- inputSchema: {
86
- type: 'object',
87
- properties: {
88
- nodeType: {
89
- type: 'string',
90
- enum: ['repo', 'package', 'endpoint', 'port'],
91
- description: 'Optional node type to filter.',
92
- },
93
- edgeType: {
94
- type: 'string',
95
- enum: ['DEPENDS_ON', 'EXPOSES', 'CALLS'],
96
- description: 'Optional edge/relation type to filter.',
97
- },
98
- workspaceId: {
99
- type: 'string',
100
- description: 'Optional ID/branchName of the workspace. If omitted, uses the currently active workspace.',
101
- },
69
+ },
70
+ ];
71
+
72
+ if (config.localLlm?.enabled) {
73
+ tools.push({
74
+ name: 'delegate_to_local_agent',
75
+ description: 'Delegate simple, high-volume, or repetitive tasks (like searching code, parsing raw service logs, or generating boilerplate) to the local Small Language Model (SLM) running on the user\'s machine to save remote tokens.',
76
+ inputSchema: {
77
+ type: 'object',
78
+ properties: {
79
+ instruction: {
80
+ type: 'string',
81
+ description: 'The specific instruction for the local agent (e.g., "Scan the last 50 lines of logs and explain the database error").',
82
+ },
83
+ filesToRead: {
84
+ type: 'array',
85
+ items: { type: 'string' },
86
+ description: 'Optional list of workspace-relative file paths or log files that the local agent should read and use as context.',
102
87
  },
103
88
  },
89
+ required: ['instruction'],
104
90
  },
105
- ],
106
- };
91
+ });
92
+ }
93
+
94
+ return { tools };
107
95
  });
108
96
 
109
97
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
@@ -121,6 +109,90 @@ export async function startMcpServer(workspacePath?: string) {
121
109
  }
122
110
  }
123
111
 
112
+ if (name === 'delegate_to_local_agent') {
113
+ const instruction = (args as any).instruction;
114
+ const filesToRead = (args as any).filesToRead || [];
115
+
116
+ try {
117
+ if (!config.localLlm || !config.localLlm.enabled) {
118
+ throw new Error('Local AI agent delegation is disabled. Enable it in ~/.nexusflow/config.json or settings.');
119
+ }
120
+
121
+ const contextFiles: { path: string; content: string }[] = [];
122
+ const normalizedWorkspace = resolvedWorkspacePath.endsWith(path.sep)
123
+ ? resolvedWorkspacePath
124
+ : resolvedWorkspacePath + path.sep;
125
+
126
+ for (const relativePath of filesToRead) {
127
+ const filePath = path.resolve(resolvedWorkspacePath, relativePath);
128
+
129
+ if (!filePath.startsWith(normalizedWorkspace)) {
130
+ contextFiles.push({
131
+ path: relativePath,
132
+ content: '[Access denied: path is outside workspace boundary]',
133
+ });
134
+ continue;
135
+ }
136
+
137
+ try {
138
+ const content = await fs.readFile(filePath, 'utf-8');
139
+ // Truncate file content if it's too large to prevent overloading local SLM
140
+ const truncatedContent = content.length > 50000
141
+ ? content.substring(0, 50000) + '\n\n[Content truncated by NexusFlow to save local context size...]'
142
+ : content;
143
+
144
+ contextFiles.push({
145
+ path: relativePath,
146
+ content: truncatedContent,
147
+ });
148
+ } catch (e: any) {
149
+ contextFiles.push({
150
+ path: relativePath,
151
+ content: `[Error reading file: ${e.message || 'unknown error'}]`,
152
+ });
153
+ }
154
+ }
155
+
156
+ // Build messages
157
+ const messages: import('../utils/local-ai.js').LocalLlmMessage[] = [];
158
+ let systemPrompt = 'You are the NexusFlow local assistant. You are running locally on the user\'s machine to help the remote supervisor agent solve a specific sub-task in a multi-repo workspace.\n';
159
+ systemPrompt += 'Your goal is to be extremely precise, concise, and return only the distilled findings/code to save remote network tokens. Keep your response short, focused, and directly address the instruction.';
160
+
161
+ messages.push({ role: 'system', content: systemPrompt });
162
+
163
+ let userPrompt = '';
164
+ if (contextFiles.length > 0) {
165
+ userPrompt += 'Here is the local file/log context:\n\n';
166
+ for (const file of contextFiles) {
167
+ userPrompt += `--- FILE: ${file.path} ---\n${file.content}\n\n`;
168
+ }
169
+ }
170
+ userPrompt += `Instruction: ${instruction}`;
171
+ messages.push({ role: 'user', content: userPrompt });
172
+
173
+ const result = await callLocalLlm(config.localLlm, messages);
174
+
175
+ return {
176
+ content: [
177
+ {
178
+ type: 'text',
179
+ text: result,
180
+ },
181
+ ],
182
+ };
183
+ } catch (error: any) {
184
+ return {
185
+ content: [
186
+ {
187
+ type: 'text',
188
+ text: `Error delegating to local agent: ${error.message}`,
189
+ },
190
+ ],
191
+ isError: true,
192
+ };
193
+ }
194
+ }
195
+
124
196
  if (name === 'search_workspace') {
125
197
  const query = (args as any).query;
126
198
  try {
@@ -142,9 +214,7 @@ export async function startMcpServer(workspacePath?: string) {
142
214
  allResults += lines.join('\n') + '\n';
143
215
  }
144
216
  } catch (e: any) {
145
- if (e.exitCode !== 1) {
146
- console.error(`Error searching in ${repoName}:`, e);
147
- }
217
+ // Ignore error or exitCode 1 (no match)
148
218
  }
149
219
  }
150
220
 
@@ -215,28 +285,7 @@ export async function startMcpServer(workspacePath?: string) {
215
285
  }
216
286
  }
217
287
 
218
- if (name === 'get_workspace_graph') {
219
- return {
220
- content: [
221
- {
222
- type: 'text',
223
- text: 'This tool has been deprecated. Use nexusflow-plan.md for dependency information.',
224
- },
225
- ],
226
- };
227
- }
228
-
229
- if (name === 'query_workspace_graph') {
230
- return {
231
- content: [
232
- {
233
- type: 'text',
234
- text: 'This tool has been deprecated. Use nexusflow-plan.md for dependency information.',
235
- },
236
- ],
237
- };
238
- }
239
-
288
+ // Unknown tool
240
289
  throw new Error(`Tool not found: ${name}`);
241
290
  });
242
291