8000 Follow-ups to #5215 (#5216) · lwsinclair/rushstack@2aa34a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2aa34a1

Browse files
authored
* Follow-ups to microsoft#5215 * Follow-ups to microsoft#5215 * Follow-ups to microsoft#5215 * Follow-ups to microsoft#5215
1 parent f57dd76 commit 2aa34a1

File tree

7 files changed

+89
-31
lines changed

7 files changed

+89
-31
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"text": "---\ntitle: rush install-autoinstaller\n---\n\n```\nusage: rush install-autoinstaller [-h] --name AUTOINSTALLER_NAME\n\nUse this command to install dependencies for an autoinstaller folder.\n\nOptional arguments:\n -h, --help Show this help message and exit.\n --name AUTOINSTALLER_NAME\n The name of the autoinstaller, which must be one of\n the folders under common/autoinstallers.\n```\n\n## See also\n\n- [rush update-autoinstaller](../commands/rush_update-autoinstaller.md)\n- [rush init-autoinstaller](../commands/rush_init-autoinstaller.md)",
4+
"score": 0.7231232
5+
},
6+
{
7+
"text": "---\ntitle: rush install-autoinstaller\n---\n\n```\n用法:rush install-autoinstaller [-h] --name AUTOINSTALLER_NAME\n\n使用该指令给一个项目安装依赖。\n\n可选参数:\n -h, --help 展示帮助信息并退出\n --name AUTOINSTALLER_NAME\n 指定自动安装的包名,它必须是 common/autoinstallers\n 下的一个文件夹。\n```\n\n## See also\n\n- [rush update-autoinstaller](../commands/rush_update-autoinstaller.md)\n- [rush init-autoinstaller](../commands/rush_init-autoinstaller.md)",
8+
"score": 0.7132133
9+
},
10+
{
11+
"text": "---\ntitle: rush update-autoinstaller\n---\n\n```\nusage: rush update-autoinstaller [-h] --name AUTOINSTALLER_NAME\n\nUse this command to regenerate the shrinkwrap file for an autoinstaller\nfolder.\n\nOptional arguments:\n -h, --help Show this help message and exit.\n --name AUTOINSTALLER_NAME\n The name of the autoinstaller, which must be one of\n the folders under common/autoinstallers.\n```\n\n## See also\n\n- [rush install-autoinstaller](../commands/rush_install-autoinstaller.md)\n- [rush init-autoinstaller](../commands/rush_init-autoinstaller.md)",
12+
"score": 0.6632131
13+
},
14+
{
15+
"text": "---\ntitle: rush update-autoinstaller\n---\n\n```\nusage: rush update-autoinstaller [-h] --name AUTOINSTALLER_NAME\n\nUse this command to regenerate the shrinkwrap file for an autoinstaller\nfolder.\n\nOptional arguments:\n -h, --help Show this help message and exit.\n --name AUTOINSTALLER_NAME\n The name of the autoinstaller, which must be one of\n the folders under common/autoinstallers.\n```\n\n## See also\n\n- [rush install-autoinstaller](../commands/rush_install-autoinstaller.md)\n- [rush init-autoinstaller](../commands/rush_init-autoinstaller.md)",
16+
"score": 0.6528328
17+
}
18+
]

apps/rush-mcp-server/src/tools/docs.tool.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// See LICENSE in the project root for license information.
33

44
import { z } from 'zod';
5+
import { JsonFile } from '@rushstack/node-core-library';
6+
import path from 'path';
57

68
import { BaseTool, type CallToolResult } from './base.tool';
79

@@ -20,30 +22,37 @@ export class RushDocsTool extends BaseTool {
2022
super({
2123
name: 'rush_docs',
2224
description:
23-
'Search and retrieve relevant sections from Rush official documentation based on user queries.',
25+
'Search and retrieve relevant sections from the official Rush documentation based on user queries.',
2426
schema: {
2527
userQuery: z.string().describe('The user query to search for relevant documentation sections.')
2628
}
2729
});
2830
}
2931

30-
public async executeAsync({ userQuery }: { userQuery: string }): Promise<CallToolResult> {
31-
// An example of a knowledge base that can run, but needs to be replaced with Microsoft’s service.
32-
const response: Response = await fetch('http://47.120.46.115/search', {
33-
method: 'POST',
34-
headers: {
35-
'Content-Type': 'application/json'
36-
},
37-
body: JSON.stringify({ query: userQuery, topK: 10 })
38-
});
32+
// TODO: replace with Microsoft's service
33+
private _searchDocs(query: string): IDocsResult {
34+
const startTime: number = Date.now();
35+
36+
const results: IDocsResult['results'] = JsonFile.load(
37+
path.join(__dirname, '../rush-doc-fragment.mock.json')
38+
);
39+
40+
return {
41+
query,
42+
results,
43+
count: results.length,
44+
searchTimeMs: Date.now() - startTime
45+
};
46+
}
3947

40-
const result: IDocsResult = (await response.json()) as IDocsResult;
48+
public async executeAsync({ userQuery }: { userQuery: string }): Promise<CallToolResult> {
49+
const docSearchResult: IDocsResult = this._searchDocs(userQuery);
4150

4251
return {
4352
content: [
4453
{
4554
type: 'text',
46-
text: result.results.map((item) => item.text).join('\n')
55+
text: docSearchResult.results.map((item) => item.text).join('\n\n')
4756
}
4857
]
4958
};

apps/rush-mcp-server/src/tools/migrate-project.tool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ export class RushMigrateProjectTool extends BaseTool {
125125
type: 'text',
126126
text:
127127
`Project "${projectName}" migrated to subspace "${targetSubspaceName}" successfully. ` +
128-
`You can ask whether user wants to run "rush update --subspace ${targetSubspaceName}" to update the project. ` +
129-
`If user says "yes" you can run "rush update --subspace ${targetSubspaceName}" directly for them.`
128+
`You can ask whether the user wants to run "rush update --subspace ${targetSubspaceName}" to update the project. ` +
129+
`If the user says "yes", you can run "rush update --subspace ${targetSubspaceName}" directly for them.`
130130
}
131131
]
132132
};

apps/rush-mcp-server/src/tools/rush-command-validator.tool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class RushCommandValidatorTool extends BaseTool {
8888
content: [
8989
{
9090
type: 'text',
91-
text: `The package "${packageName}" does not exist in the Rush workspace. You can retrive package name from 'package.json' file in the project folder.`
91+
text: `The package "${packageName}" does not exist in the Rush workspace. You can retrieve the package name from the 'package.json' file in the project folder.`
9292
}
9393
]
9494
};

apps/rush-mcp-server/src/utilities/command-runner.ts

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import type * as child_process from 'child_process';
4+
import type { ChildProcess } from 'child_process';
55
import { Executable, type IExecutableSpawnSyncOptions } from '@rushstack/node-core-library';
66

77
interface ICommandResult {
@@ -49,21 +49,38 @@ export class CommandRunner {
4949
): Promise<ICommandResult> {
5050
const commandPath: string = this._resolveCommand(command);
5151

52-
const result: child_process.SpawnSyncReturns<string> = Executable.spawnSync(commandPath, args, options);
53-
54-
const status: number = result.status ?? 1;
55-
56-
if (status !== 0) {
57-
throw new CommandExecutionError(command, args, result.stderr, status);
58-
}
59-
60-
return {
61-
status,
62-
stdout: result.stdout,
63-
stderr: result.stderr,
64-
command,
65-
args
66-
};
52+
return new Promise((resolve, reject) => {
53+
const childProcess: ChildProcess = Executable.spawn(commandPath, args, options);
54+
let stdout: string = '';
55+
let stderr: string = '';
56+
57+
childProcess.stdout?.on('data', (data) => {
58+
stdout += data.toString();
59+
});
60+
61+
childProcess.stderr?.on('data', (data) => {
62+
stderr += data.toString();
63+
});
64+
65+
childProcess.on('close', (status) => {
66+
if (status !== 0) {
67+
reject(new CommandExecutionError(command, args, stderr, status ?? 1));
68+
return;
69+
}
70+
71+
resolve({
72+
status: status ?? 0,
73+
stdout,
74+
stderr,
75+
command,
76+
args
77+
});
78+
});
79+
80+
childProcess.on('error', (error) => {
81+
reject(error);
82+
});
83+
});
6784
}
6885

6986
public static async runRushCommandAsync(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/mcp-server",
5+
"comment": "Follow-ups to #5215",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@rushstack/mcp-server"
10+
}

common/config/rush/nonbrowser-approved-packages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,10 @@
973973
{
974974
"name": "xmldoc",
975975
"allowedCategories": [ "libraries" ]
976+
},
977+
{
978+
"name": "zod",
979+
"allowedCategories": [ "libraries" ]
976980
}
977981
]
978982
}

0 commit comments

Comments
 (0)
0