@mrpatronz/nexusflow 0.2.7 → 0.2.8
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.
- package/.github/workflows/release.yml +7 -0
- package/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +6 -1
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +58 -0
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +73 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +11 -1
- package/dist/core/config.js.map +1 -1
- package/dist/core/config.test.d.ts +2 -0
- package/dist/core/config.test.d.ts.map +1 -0
- package/dist/core/config.test.js +75 -0
- package/dist/core/config.test.js.map +1 -0
- package/dist/core/scanner.test.d.ts +2 -0
- package/dist/core/scanner.test.d.ts.map +1 -0
- package/dist/core/scanner.test.js +53 -0
- package/dist/core/scanner.test.js.map +1 -0
- package/dist/generators/base.d.ts.map +1 -1
- package/dist/generators/base.js +8 -2
- package/dist/generators/base.js.map +1 -1
- package/dist/generators/skills-generator.js +1 -1
- package/dist/generators/skills-generator.js.map +1 -1
- package/dist/gui/assets/index-Ca2VRMrQ.js +22 -0
- package/dist/gui/assets/index-fj0RJiOb.css +2 -0
- package/dist/gui/index.html +2 -2
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +132 -93
- package/dist/mcp/server.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +132 -11
- package/dist/server.js.map +1 -1
- package/dist/server.test.d.ts +2 -0
- package/dist/server.test.d.ts.map +1 -0
- package/dist/server.test.js +318 -0
- package/dist/server.test.js.map +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/detect-ai.test.d.ts +2 -0
- package/dist/utils/detect-ai.test.d.ts.map +1 -0
- package/dist/utils/detect-ai.test.js +37 -0
- package/dist/utils/detect-ai.test.js.map +1 -0
- package/dist/utils/detect-editors.test.d.ts +2 -0
- package/dist/utils/detect-editors.test.d.ts.map +1 -0
- package/dist/utils/detect-editors.test.js +39 -0
- package/dist/utils/detect-editors.test.js.map +1 -0
- package/dist/utils/git.test.d.ts +2 -0
- package/dist/utils/git.test.d.ts.map +1 -0
- package/dist/utils/git.test.js +55 -0
- package/dist/utils/git.test.js.map +1 -0
- package/dist/utils/local-ai.d.ts +27 -0
- package/dist/utils/local-ai.d.ts.map +1 -0
- package/dist/utils/local-ai.js +96 -0
- package/dist/utils/local-ai.js.map +1 -0
- package/dist/utils/local-ai.test.d.ts +2 -0
- package/dist/utils/local-ai.test.d.ts.map +1 -0
- package/dist/utils/local-ai.test.js +108 -0
- package/dist/utils/local-ai.test.js.map +1 -0
- package/dist/utils/system-scanner.d.ts +16 -0
- package/dist/utils/system-scanner.d.ts.map +1 -0
- package/dist/utils/system-scanner.js +85 -0
- package/dist/utils/system-scanner.js.map +1 -0
- package/dist/utils/system-scanner.test.d.ts +2 -0
- package/dist/utils/system-scanner.test.d.ts.map +1 -0
- package/dist/utils/system-scanner.test.js +73 -0
- package/dist/utils/system-scanner.test.js.map +1 -0
- package/gui/e2e/wizard.spec.ts +327 -0
- package/gui/package-lock.json +64 -0
- package/gui/package.json +4 -1
- package/gui/playwright.config.ts +41 -0
- package/gui/src/App.tsx +376 -786
- package/gui/src/index.css +16 -0
- package/package.json +3 -1
- package/scripts/simulate-workspaces.ts +55 -0
- package/src/commands/create.ts +7 -1
- package/src/commands/doctor.ts +56 -0
- package/src/commands/init.ts +77 -1
- package/src/core/config.test.ts +96 -0
- package/src/core/config.ts +11 -1
- package/src/core/scanner.test.ts +61 -0
- package/src/generators/base.ts +13 -2
- package/src/generators/skills-generator.ts +1 -1
- package/src/mcp/server.ts +144 -95
- package/src/server.test.ts +367 -0
- package/src/server.ts +139 -10
- package/src/types.ts +16 -0
- package/src/utils/detect-ai.test.ts +44 -0
- package/src/utils/detect-editors.test.ts +47 -0
- package/src/utils/git.test.ts +74 -0
- package/src/utils/local-ai.test.ts +130 -0
- package/src/utils/local-ai.ts +111 -0
- package/src/utils/system-scanner.test.ts +89 -0
- package/src/utils/system-scanner.ts +96 -0
- package/vitest.config.ts +2 -1
- package/dist/gui/assets/index-BgEo5w2Q.js +0 -22
- 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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import * as fs from 'node:fs/promises';
|
|
3
|
+
import { execa } from 'execa';
|
|
4
|
+
import { app } from './server.js';
|
|
5
|
+
import * as workspace from './core/workspace.js';
|
|
6
|
+
import * as config from './core/config.js';
|
|
7
|
+
import * as systemScanner from './utils/system-scanner.js';
|
|
8
|
+
import * as localAi from './utils/local-ai.js';
|
|
9
|
+
import * as updateCheck from './utils/update-check.js';
|
|
10
|
+
|
|
11
|
+
// Mock dependencies
|
|
12
|
+
vi.mock('node:fs/promises');
|
|
13
|
+
vi.mock('execa');
|
|
14
|
+
vi.mock('./core/workspace.js');
|
|
15
|
+
vi.mock('./core/config.js');
|
|
16
|
+
vi.mock('./utils/system-scanner.js');
|
|
17
|
+
vi.mock('./utils/local-ai.js');
|
|
18
|
+
vi.mock('./utils/update-check.js');
|
|
19
|
+
|
|
20
|
+
describe('Server API Endpoints Unit Tests', () => {
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
vi.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('POST /api/open-editor', () => {
|
|
26
|
+
it('should return 400 for forbidden editor commands', async () => {
|
|
27
|
+
const response = await app.request('/api/open-editor', {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: { 'Content-Type': 'application/json' },
|
|
30
|
+
body: JSON.stringify({
|
|
31
|
+
workspacePath: '/mock/workspace/path',
|
|
32
|
+
command: 'rm -rf /'
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(response.status).toBe(400);
|
|
37
|
+
const data = await response.json();
|
|
38
|
+
expect(data.error).toBe('Forbidden editor command');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should return 400 if workspace path does not exist', async () => {
|
|
42
|
+
vi.spyOn(fs, 'stat').mockRejectedValue(new Error('File not found'));
|
|
43
|
+
|
|
44
|
+
const response = await app.request('/api/open-editor', {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
headers: { 'Content-Type': 'application/json' },
|
|
47
|
+
body: JSON.stringify({
|
|
48
|
+
workspacePath: '/non-existent/path',
|
|
49
|
+
command: 'code-insiders'
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(response.status).toBe(400);
|
|
54
|
+
const data = await response.json();
|
|
55
|
+
expect(data.error).toBe('Workspace path does not exist');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('should return 400 if workspace path is not a directory', async () => {
|
|
59
|
+
vi.spyOn(fs, 'stat').mockResolvedValue({
|
|
60
|
+
isDirectory: () => false
|
|
61
|
+
} as any);
|
|
62
|
+
|
|
63
|
+
const response = await app.request('/api/open-editor', {
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: { 'Content-Type': 'application/json' },
|
|
66
|
+
body: JSON.stringify({
|
|
67
|
+
workspacePath: '/mock/file.txt',
|
|
68
|
+
command: 'code-insiders'
|
|
69
|
+
})
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
expect(response.status).toBe(400);
|
|
73
|
+
const data = await response.json();
|
|
74
|
+
expect(data.error).toBe('Workspace path is not a directory');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should call execa with detached, stdio, shell, and cleanup options and return success', async () => {
|
|
78
|
+
vi.spyOn(fs, 'stat').mockResolvedValue({
|
|
79
|
+
isDirectory: () => true
|
|
80
|
+
} as any);
|
|
81
|
+
|
|
82
|
+
// Mock execa to return a dummy child process with a catch method
|
|
83
|
+
const dummyChild = {
|
|
84
|
+
unref: vi.fn(),
|
|
85
|
+
catch: vi.fn().mockReturnThis()
|
|
86
|
+
};
|
|
87
|
+
vi.mocked(execa).mockReturnValue(dummyChild as any);
|
|
88
|
+
|
|
89
|
+
const response = await app.request('/api/open-editor', {
|
|
90
|
+
method: 'POST',
|
|
91
|
+
headers: { 'Content-Type': 'application/json' },
|
|
92
|
+
body: JSON.stringify({
|
|
93
|
+
workspacePath: '/mock/workspace/dir',
|
|
94
|
+
command: 'code-insiders'
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
expect(response.status).toBe(200);
|
|
99
|
+
const data = await response.json();
|
|
100
|
+
expect(data.success).toBe(true);
|
|
101
|
+
|
|
102
|
+
const isWin = process.platform === 'win32';
|
|
103
|
+
expect(execa).toHaveBeenCalledWith('code-insiders', ['/mock/workspace/dir'], {
|
|
104
|
+
detached: true,
|
|
105
|
+
stdio: 'ignore',
|
|
106
|
+
shell: isWin,
|
|
107
|
+
cleanup: false
|
|
108
|
+
});
|
|
109
|
+
expect(dummyChild.unref).toHaveBeenCalled();
|
|
110
|
+
expect(dummyChild.catch).toHaveBeenCalled();
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('POST /api/workspace/:id/resume', () => {
|
|
115
|
+
it('should fail with 400 if command is forbidden', async () => {
|
|
116
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
117
|
+
workspacesDir: '/mock/workspaces'
|
|
118
|
+
} as any);
|
|
119
|
+
vi.spyOn(workspace, 'loadFeatureConfig').mockResolvedValue({
|
|
120
|
+
id: 'test-ws',
|
|
121
|
+
repos: [],
|
|
122
|
+
assistants: ['antigravity']
|
|
123
|
+
} as any);
|
|
124
|
+
|
|
125
|
+
const response = await app.request('/api/workspace/test-ws/resume', {
|
|
126
|
+
method: 'POST',
|
|
127
|
+
headers: { 'Content-Type': 'application/json' },
|
|
128
|
+
body: JSON.stringify({
|
|
129
|
+
command: 'malicious-editor',
|
|
130
|
+
assistant: 'antigravity'
|
|
131
|
+
})
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
expect(response.status).toBe(400);
|
|
135
|
+
const data = await response.json();
|
|
136
|
+
expect(data.error).toBe('Forbidden editor command');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should spawn the editor with proper options when resuming', async () => {
|
|
140
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
141
|
+
workspacesDir: '/mock/workspaces'
|
|
142
|
+
} as any);
|
|
143
|
+
vi.spyOn(workspace, 'loadFeatureConfig').mockResolvedValue({
|
|
144
|
+
id: 'test-ws',
|
|
145
|
+
repos: [],
|
|
146
|
+
assistants: ['antigravity']
|
|
147
|
+
} as any);
|
|
148
|
+
|
|
149
|
+
const dummyChild = {
|
|
150
|
+
unref: vi.fn(),
|
|
151
|
+
catch: vi.fn().mockReturnThis()
|
|
152
|
+
};
|
|
153
|
+
vi.mocked(execa).mockReturnValue(dummyChild as any);
|
|
154
|
+
|
|
155
|
+
const response = await app.request('/api/workspace/test-ws/resume', {
|
|
156
|
+
method: 'POST',
|
|
157
|
+
headers: { 'Content-Type': 'application/json' },
|
|
158
|
+
body: JSON.stringify({
|
|
159
|
+
command: 'code',
|
|
160
|
+
assistant: 'antigravity'
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(response.status).toBe(200);
|
|
165
|
+
const data = await response.json();
|
|
166
|
+
expect(data.success).toBe(true);
|
|
167
|
+
|
|
168
|
+
const isWin = process.platform === 'win32';
|
|
169
|
+
expect(execa).toHaveBeenCalledWith('code', [expect.any(String)], {
|
|
170
|
+
detached: true,
|
|
171
|
+
stdio: 'ignore',
|
|
172
|
+
shell: isWin,
|
|
173
|
+
cleanup: false
|
|
174
|
+
});
|
|
175
|
+
expect(dummyChild.unref).toHaveBeenCalled();
|
|
176
|
+
expect(dummyChild.catch).toHaveBeenCalled();
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe('GET /api/config', () => {
|
|
181
|
+
it('should load configuration successfully', async () => {
|
|
182
|
+
vi.spyOn(config, 'getConfigDir').mockReturnValue('/mock/config-dir');
|
|
183
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
184
|
+
devDir: '/mock/dev',
|
|
185
|
+
scanDepth: 2
|
|
186
|
+
} as any);
|
|
187
|
+
vi.spyOn(fs, 'access').mockResolvedValue();
|
|
188
|
+
|
|
189
|
+
const response = await app.request('/api/config');
|
|
190
|
+
expect(response.status).toBe(200);
|
|
191
|
+
const data = await response.json();
|
|
192
|
+
expect(data.config.devDir).toBe('/mock/dev');
|
|
193
|
+
expect(data.exists).toBe(true);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('POST /api/config', () => {
|
|
198
|
+
it('should validate endpoint domain safety', async () => {
|
|
199
|
+
const response = await app.request('/api/config', {
|
|
200
|
+
method: 'POST',
|
|
201
|
+
headers: { 'Content-Type': 'application/json' },
|
|
202
|
+
body: JSON.stringify({
|
|
203
|
+
localLlm: {
|
|
204
|
+
enabled: true,
|
|
205
|
+
endpoint: 'http://malicious-external-domain.com'
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
expect(response.status).toBe(400);
|
|
211
|
+
const data = await response.json();
|
|
212
|
+
expect(data.error).toContain('Local AI endpoint must be localhost, 127.0.0.1, or a private LAN IP.');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('should save safe endpoint and config', async () => {
|
|
216
|
+
vi.spyOn(config, 'saveConfig').mockResolvedValue();
|
|
217
|
+
|
|
218
|
+
const response = await app.request('/api/config', {
|
|
219
|
+
method: 'POST',
|
|
220
|
+
headers: { 'Content-Type': 'application/json' },
|
|
221
|
+
body: JSON.stringify({
|
|
222
|
+
localLlm: {
|
|
223
|
+
enabled: true,
|
|
224
|
+
endpoint: 'http://127.0.0.1:11434'
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
expect(response.status).toBe(200);
|
|
230
|
+
const data = await response.json();
|
|
231
|
+
expect(data.success).toBe(true);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
describe('POST /api/local-llm/test', () => {
|
|
236
|
+
it('should reject unsafe endpoints', async () => {
|
|
237
|
+
const response = await app.request('/api/local-llm/test', {
|
|
238
|
+
method: 'POST',
|
|
239
|
+
headers: { 'Content-Type': 'application/json' },
|
|
240
|
+
body: JSON.stringify({
|
|
241
|
+
endpoint: 'http://unsafe-domain.com',
|
|
242
|
+
provider: 'ollama',
|
|
243
|
+
model: 'qwen2.5-coder:1.5b'
|
|
244
|
+
})
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
expect(response.status).toBe(400);
|
|
248
|
+
const data = await response.json();
|
|
249
|
+
expect(data.success).toBe(false);
|
|
250
|
+
expect(data.error).toContain('Local AI endpoint must be');
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it('should perform inference shoot test if shoot = true', async () => {
|
|
254
|
+
vi.spyOn(localAi, 'callLocalLlm').mockResolvedValue('OK\n');
|
|
255
|
+
|
|
256
|
+
const response = await app.request('/api/local-llm/test', {
|
|
257
|
+
method: 'POST',
|
|
258
|
+
headers: { 'Content-Type': 'application/json' },
|
|
259
|
+
body: JSON.stringify({
|
|
260
|
+
endpoint: 'http://localhost:11434',
|
|
261
|
+
provider: 'ollama',
|
|
262
|
+
model: 'qwen2.5-coder:1.5b',
|
|
263
|
+
shoot: true
|
|
264
|
+
})
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
expect(response.status).toBe(200);
|
|
268
|
+
const data = await response.json();
|
|
269
|
+
expect(data.success).toBe(true);
|
|
270
|
+
expect(data.modelReady).toBe(true);
|
|
271
|
+
expect(data.message).toContain('Inference test succeeded');
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
describe('GET /api/local-llm/recommend', () => {
|
|
276
|
+
it('should fetch system specs and return them', async () => {
|
|
277
|
+
vi.spyOn(systemScanner, 'scanSystemSpecs').mockResolvedValue({
|
|
278
|
+
totalRamGb: 16,
|
|
279
|
+
gpuName: 'Nvidia RTX 4080',
|
|
280
|
+
hasHardwareAcceleration: true,
|
|
281
|
+
recommendedModel: 'qwen2.5-coder:7b'
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
const response = await app.request('/api/local-llm/recommend');
|
|
285
|
+
expect(response.status).toBe(200);
|
|
286
|
+
const data = await response.json();
|
|
287
|
+
expect(data.totalRamGb).toBe(16);
|
|
288
|
+
expect(data.gpuName).toBe('Nvidia RTX 4080');
|
|
289
|
+
expect(data.recommendedModel).toBe('qwen2.5-coder:7b');
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe('GET and PUT /api/workspace/:id/knowledge', () => {
|
|
294
|
+
it('should get workspace knowledge content', async () => {
|
|
295
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
296
|
+
workspacesDir: '/mock/workspaces'
|
|
297
|
+
} as any);
|
|
298
|
+
vi.spyOn(fs, 'readFile').mockResolvedValue('# Mock Knowledge File content');
|
|
299
|
+
|
|
300
|
+
const response = await app.request('/api/workspace/test-ws/knowledge');
|
|
301
|
+
expect(response.status).toBe(200);
|
|
302
|
+
const data = await response.json();
|
|
303
|
+
expect(data.content).toBe('# Mock Knowledge File content');
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('should write workspace knowledge content', async () => {
|
|
307
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
308
|
+
workspacesDir: '/mock/workspaces'
|
|
309
|
+
} as any);
|
|
310
|
+
vi.spyOn(fs, 'writeFile').mockResolvedValue();
|
|
311
|
+
|
|
312
|
+
const response = await app.request('/api/workspace/test-ws/knowledge', {
|
|
313
|
+
method: 'PUT',
|
|
314
|
+
headers: { 'Content-Type': 'application/json' },
|
|
315
|
+
body: JSON.stringify({ content: '# Updated Content' })
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
expect(response.status).toBe(200);
|
|
319
|
+
const data = await response.json();
|
|
320
|
+
expect(data.success).toBe(true);
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
describe('GET /api/workspace/:id/plan', () => {
|
|
325
|
+
it('should get workspace plan content', async () => {
|
|
326
|
+
vi.spyOn(config, 'loadConfig').mockResolvedValue({
|
|
327
|
+
workspacesDir: '/mock/workspaces'
|
|
328
|
+
} as any);
|
|
329
|
+
vi.spyOn(fs, 'readFile').mockResolvedValue('# Mock Plan content');
|
|
330
|
+
|
|
331
|
+
const response = await app.request('/api/workspace/test-ws/plan');
|
|
332
|
+
expect(response.status).toBe(200);
|
|
333
|
+
const data = await response.json();
|
|
334
|
+
expect(data.content).toBe('# Mock Plan content');
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
describe('POST /api/updates/install', () => {
|
|
339
|
+
it('should fail if tool not found', async () => {
|
|
340
|
+
const response = await app.request('/api/updates/install', {
|
|
341
|
+
method: 'POST',
|
|
342
|
+
headers: { 'Content-Type': 'application/json' },
|
|
343
|
+
body: JSON.stringify({ toolId: 'invalid-tool' })
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
expect(response.status).toBe(404);
|
|
347
|
+
const data = await response.json();
|
|
348
|
+
expect(data.error).toBe('Tool not found');
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('should install tool successfully if execa exits with 0', async () => {
|
|
352
|
+
vi.mocked(execa).mockResolvedValue({ exitCode: 0, stdout: 'Successfully updated' } as any);
|
|
353
|
+
|
|
354
|
+
const response = await app.request('/api/updates/install', {
|
|
355
|
+
method: 'POST',
|
|
356
|
+
headers: { 'Content-Type': 'application/json' },
|
|
357
|
+
body: JSON.stringify({ toolId: 'repomix' })
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
expect(response.status).toBe(200);
|
|
361
|
+
const data = await response.json();
|
|
362
|
+
expect(data.success).toBe(true);
|
|
363
|
+
expect(data.output).toBe('Successfully updated');
|
|
364
|
+
expect(execa).toHaveBeenCalledWith('npm', ['install', '-g', 'repomix'], expect.any(Object));
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
});
|