@qwen-code/qwen-code 0.9.0-preview.2 → 0.9.0-preview.3
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/cli.js +512 -525
- package/package.json +2 -2
package/cli.js
CHANGED
|
@@ -26270,21 +26270,21 @@ var init_from = __esm({
|
|
|
26270
26270
|
init_fetch_blob();
|
|
26271
26271
|
({ stat } = fs2);
|
|
26272
26272
|
blobFromSync = /* @__PURE__ */ __name((path123, type) => fromBlob(statSync(path123), path123, type), "blobFromSync");
|
|
26273
|
-
blobFrom = /* @__PURE__ */ __name((path123, type) => stat(path123).then((
|
|
26274
|
-
fileFrom = /* @__PURE__ */ __name((path123, type) => stat(path123).then((
|
|
26273
|
+
blobFrom = /* @__PURE__ */ __name((path123, type) => stat(path123).then((stat11) => fromBlob(stat11, path123, type)), "blobFrom");
|
|
26274
|
+
fileFrom = /* @__PURE__ */ __name((path123, type) => stat(path123).then((stat11) => fromFile(stat11, path123, type)), "fileFrom");
|
|
26275
26275
|
fileFromSync = /* @__PURE__ */ __name((path123, type) => fromFile(statSync(path123), path123, type), "fileFromSync");
|
|
26276
|
-
fromBlob = /* @__PURE__ */ __name((
|
|
26276
|
+
fromBlob = /* @__PURE__ */ __name((stat11, path123, type = "") => new fetch_blob_default([new BlobDataItem({
|
|
26277
26277
|
path: path123,
|
|
26278
|
-
size:
|
|
26279
|
-
lastModified:
|
|
26278
|
+
size: stat11.size,
|
|
26279
|
+
lastModified: stat11.mtimeMs,
|
|
26280
26280
|
start: 0
|
|
26281
26281
|
})], { type }), "fromBlob");
|
|
26282
|
-
fromFile = /* @__PURE__ */ __name((
|
|
26282
|
+
fromFile = /* @__PURE__ */ __name((stat11, path123, type = "") => new file_default([new BlobDataItem({
|
|
26283
26283
|
path: path123,
|
|
26284
|
-
size:
|
|
26285
|
-
lastModified:
|
|
26284
|
+
size: stat11.size,
|
|
26285
|
+
lastModified: stat11.mtimeMs,
|
|
26286
26286
|
start: 0
|
|
26287
|
-
})], basename(path123), { type, lastModified:
|
|
26287
|
+
})], basename(path123), { type, lastModified: stat11.mtimeMs }), "fromFile");
|
|
26288
26288
|
BlobDataItem = class _BlobDataItem {
|
|
26289
26289
|
static {
|
|
26290
26290
|
__name(this, "BlobDataItem");
|
|
@@ -123529,18 +123529,18 @@ var require_async = __commonJS({
|
|
|
123529
123529
|
];
|
|
123530
123530
|
}, "defaultPaths");
|
|
123531
123531
|
var defaultIsFile = /* @__PURE__ */ __name(function isFile3(file, cb) {
|
|
123532
|
-
fs110.stat(file, function(err,
|
|
123532
|
+
fs110.stat(file, function(err, stat11) {
|
|
123533
123533
|
if (!err) {
|
|
123534
|
-
return cb(null,
|
|
123534
|
+
return cb(null, stat11.isFile() || stat11.isFIFO());
|
|
123535
123535
|
}
|
|
123536
123536
|
if (err.code === "ENOENT" || err.code === "ENOTDIR") return cb(null, false);
|
|
123537
123537
|
return cb(err);
|
|
123538
123538
|
});
|
|
123539
123539
|
}, "isFile");
|
|
123540
123540
|
var defaultIsDir = /* @__PURE__ */ __name(function isDirectory(dir, cb) {
|
|
123541
|
-
fs110.stat(dir, function(err,
|
|
123541
|
+
fs110.stat(dir, function(err, stat11) {
|
|
123542
123542
|
if (!err) {
|
|
123543
|
-
return cb(null,
|
|
123543
|
+
return cb(null, stat11.isDirectory());
|
|
123544
123544
|
}
|
|
123545
123545
|
if (err.code === "ENOENT" || err.code === "ENOTDIR") return cb(null, false);
|
|
123546
123546
|
return cb(err);
|
|
@@ -124036,21 +124036,21 @@ var require_sync = __commonJS({
|
|
|
124036
124036
|
}, "defaultPaths");
|
|
124037
124037
|
var defaultIsFile = /* @__PURE__ */ __name(function isFile3(file) {
|
|
124038
124038
|
try {
|
|
124039
|
-
var
|
|
124039
|
+
var stat11 = fs110.statSync(file, { throwIfNoEntry: false });
|
|
124040
124040
|
} catch (e4) {
|
|
124041
124041
|
if (e4 && (e4.code === "ENOENT" || e4.code === "ENOTDIR")) return false;
|
|
124042
124042
|
throw e4;
|
|
124043
124043
|
}
|
|
124044
|
-
return !!
|
|
124044
|
+
return !!stat11 && (stat11.isFile() || stat11.isFIFO());
|
|
124045
124045
|
}, "isFile");
|
|
124046
124046
|
var defaultIsDir = /* @__PURE__ */ __name(function isDirectory(dir) {
|
|
124047
124047
|
try {
|
|
124048
|
-
var
|
|
124048
|
+
var stat11 = fs110.statSync(dir, { throwIfNoEntry: false });
|
|
124049
124049
|
} catch (e4) {
|
|
124050
124050
|
if (e4 && (e4.code === "ENOENT" || e4.code === "ENOTDIR")) return false;
|
|
124051
124051
|
throw e4;
|
|
124052
124052
|
}
|
|
124053
|
-
return !!
|
|
124053
|
+
return !!stat11 && stat11.isDirectory();
|
|
124054
124054
|
}, "isDirectory");
|
|
124055
124055
|
var defaultRealpathSync = /* @__PURE__ */ __name(function realpathSync8(x3) {
|
|
124056
124056
|
try {
|
|
@@ -124476,14 +124476,14 @@ var require_require_in_the_middle = __commonJS({
|
|
|
124476
124476
|
moduleName2 = parsedPath.name;
|
|
124477
124477
|
basedir = parsedPath.dir;
|
|
124478
124478
|
} else {
|
|
124479
|
-
const
|
|
124480
|
-
if (
|
|
124479
|
+
const stat11 = moduleDetailsFromPath(filename);
|
|
124480
|
+
if (stat11 === void 0) {
|
|
124481
124481
|
debug3("could not parse filename: %s", filename);
|
|
124482
124482
|
return exports3;
|
|
124483
124483
|
}
|
|
124484
|
-
moduleName2 =
|
|
124485
|
-
basedir =
|
|
124486
|
-
const fullModuleName = resolveModuleName(
|
|
124484
|
+
moduleName2 = stat11.name;
|
|
124485
|
+
basedir = stat11.basedir;
|
|
124486
|
+
const fullModuleName = resolveModuleName(stat11);
|
|
124487
124487
|
debug3("resolved filename to module: %s (id: %s, resolved: %s, basedir: %s)", moduleName2, id, fullModuleName, basedir);
|
|
124488
124488
|
let matchFound = false;
|
|
124489
124489
|
if (hasWhitelist) {
|
|
@@ -124547,9 +124547,9 @@ var require_require_in_the_middle = __commonJS({
|
|
|
124547
124547
|
}
|
|
124548
124548
|
}
|
|
124549
124549
|
};
|
|
124550
|
-
function resolveModuleName(
|
|
124551
|
-
const normalizedPath = path123.sep !== "/" ?
|
|
124552
|
-
return path123.posix.join(
|
|
124550
|
+
function resolveModuleName(stat11) {
|
|
124551
|
+
const normalizedPath = path123.sep !== "/" ? stat11.path.split(path123.sep).join("/") : stat11.path;
|
|
124552
|
+
return path123.posix.join(stat11.name, normalizedPath).replace(normalize11, "");
|
|
124553
124553
|
}
|
|
124554
124554
|
__name(resolveModuleName, "resolveModuleName");
|
|
124555
124555
|
}
|
|
@@ -155848,7 +155848,7 @@ __export(geminiContentGenerator_exports, {
|
|
|
155848
155848
|
createGeminiContentGenerator: () => createGeminiContentGenerator
|
|
155849
155849
|
});
|
|
155850
155850
|
function createGeminiContentGenerator(config2, gcConfig) {
|
|
155851
|
-
const version2 = "0.9.0-preview.
|
|
155851
|
+
const version2 = "0.9.0-preview.3";
|
|
155852
155852
|
const userAgent2 = config2.userAgent || `QwenCode/${version2} (${process.platform}; ${process.arch})`;
|
|
155853
155853
|
const baseHeaders = {
|
|
155854
155854
|
"User-Agent": userAgent2
|
|
@@ -187415,12 +187415,12 @@ var require_src36 = __commonJS({
|
|
|
187415
187415
|
function check2(path123, isFile3, isDirectory) {
|
|
187416
187416
|
log(`checking %s`, path123);
|
|
187417
187417
|
try {
|
|
187418
|
-
const
|
|
187419
|
-
if (
|
|
187418
|
+
const stat11 = fs_1.statSync(path123);
|
|
187419
|
+
if (stat11.isFile() && isFile3) {
|
|
187420
187420
|
log(`[OK] path represents a file`);
|
|
187421
187421
|
return true;
|
|
187422
187422
|
}
|
|
187423
|
-
if (
|
|
187423
|
+
if (stat11.isDirectory() && isDirectory) {
|
|
187424
187424
|
log(`[OK] path represents a directory`);
|
|
187425
187425
|
return true;
|
|
187426
187426
|
}
|
|
@@ -203472,16 +203472,16 @@ var require_windows = __commonJS({
|
|
|
203472
203472
|
return false;
|
|
203473
203473
|
}
|
|
203474
203474
|
__name(checkPathExt, "checkPathExt");
|
|
203475
|
-
function checkStat(
|
|
203476
|
-
if (!
|
|
203475
|
+
function checkStat(stat11, path123, options2) {
|
|
203476
|
+
if (!stat11.isSymbolicLink() && !stat11.isFile()) {
|
|
203477
203477
|
return false;
|
|
203478
203478
|
}
|
|
203479
203479
|
return checkPathExt(path123, options2);
|
|
203480
203480
|
}
|
|
203481
203481
|
__name(checkStat, "checkStat");
|
|
203482
203482
|
function isexe(path123, options2, cb) {
|
|
203483
|
-
fs110.stat(path123, function(er2,
|
|
203484
|
-
cb(er2, er2 ? false : checkStat(
|
|
203483
|
+
fs110.stat(path123, function(er2, stat11) {
|
|
203484
|
+
cb(er2, er2 ? false : checkStat(stat11, path123, options2));
|
|
203485
203485
|
});
|
|
203486
203486
|
}
|
|
203487
203487
|
__name(isexe, "isexe");
|
|
@@ -203500,8 +203500,8 @@ var require_mode = __commonJS({
|
|
|
203500
203500
|
isexe.sync = sync2;
|
|
203501
203501
|
var fs110 = __require("fs");
|
|
203502
203502
|
function isexe(path123, options2, cb) {
|
|
203503
|
-
fs110.stat(path123, function(er2,
|
|
203504
|
-
cb(er2, er2 ? false : checkStat(
|
|
203503
|
+
fs110.stat(path123, function(er2, stat11) {
|
|
203504
|
+
cb(er2, er2 ? false : checkStat(stat11, options2));
|
|
203505
203505
|
});
|
|
203506
203506
|
}
|
|
203507
203507
|
__name(isexe, "isexe");
|
|
@@ -203509,14 +203509,14 @@ var require_mode = __commonJS({
|
|
|
203509
203509
|
return checkStat(fs110.statSync(path123), options2);
|
|
203510
203510
|
}
|
|
203511
203511
|
__name(sync2, "sync");
|
|
203512
|
-
function checkStat(
|
|
203513
|
-
return
|
|
203512
|
+
function checkStat(stat11, options2) {
|
|
203513
|
+
return stat11.isFile() && checkMode(stat11, options2);
|
|
203514
203514
|
}
|
|
203515
203515
|
__name(checkStat, "checkStat");
|
|
203516
|
-
function checkMode(
|
|
203517
|
-
var mod2 =
|
|
203518
|
-
var uid =
|
|
203519
|
-
var gid =
|
|
203516
|
+
function checkMode(stat11, options2) {
|
|
203517
|
+
var mod2 = stat11.mode;
|
|
203518
|
+
var uid = stat11.uid;
|
|
203519
|
+
var gid = stat11.gid;
|
|
203520
203520
|
var myUid = options2.uid !== void 0 ? options2.uid : process.getuid && process.getuid();
|
|
203521
203521
|
var myGid = options2.gid !== void 0 ? options2.gid : process.getgid && process.getgid();
|
|
203522
203522
|
var u2 = parseInt("100", 8);
|
|
@@ -204647,14 +204647,14 @@ var init_ide_client = __esm({
|
|
|
204647
204647
|
const fileContents = await Promise.all(lockFiles.map(async (file) => {
|
|
204648
204648
|
const fullPath = path32.join(ideDir, file);
|
|
204649
204649
|
try {
|
|
204650
|
-
const
|
|
204650
|
+
const stat11 = await fs32.promises.stat(fullPath);
|
|
204651
204651
|
const content = await fs32.promises.readFile(fullPath, "utf8");
|
|
204652
204652
|
try {
|
|
204653
204653
|
const parsed = JSON.parse(content);
|
|
204654
|
-
return { file, mtimeMs:
|
|
204654
|
+
return { file, mtimeMs: stat11.mtimeMs, parsed };
|
|
204655
204655
|
} catch (e4) {
|
|
204656
204656
|
logger.debug("Failed to parse JSON from lock file: ", e4);
|
|
204657
|
-
return { file, mtimeMs:
|
|
204657
|
+
return { file, mtimeMs: stat11.mtimeMs, parsed: void 0 };
|
|
204658
204658
|
}
|
|
204659
204659
|
} catch (e4) {
|
|
204660
204660
|
logger.debug("Failed to read/stat IDE lock file:", e4);
|
|
@@ -210920,82 +210920,6 @@ function getMCPServerStatus(serverName) {
|
|
|
210920
210920
|
function getMCPDiscoveryState() {
|
|
210921
210921
|
return mcpDiscoveryState;
|
|
210922
210922
|
}
|
|
210923
|
-
function extractWWWAuthenticateHeader(errorString) {
|
|
210924
|
-
const patterns = [
|
|
210925
|
-
/www-authenticate:\s*([^\n\r]+)/i,
|
|
210926
|
-
/WWW-Authenticate:\s*([^\n\r]+)/i,
|
|
210927
|
-
/"www-authenticate":\s*"([^"]+)"/i,
|
|
210928
|
-
/'www-authenticate':\s*'([^']+)'/i
|
|
210929
|
-
];
|
|
210930
|
-
for (const pattern of patterns) {
|
|
210931
|
-
const match2 = errorString.match(pattern);
|
|
210932
|
-
if (match2) {
|
|
210933
|
-
return match2[1].trim();
|
|
210934
|
-
}
|
|
210935
|
-
}
|
|
210936
|
-
return null;
|
|
210937
|
-
}
|
|
210938
|
-
async function handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthenticate) {
|
|
210939
|
-
try {
|
|
210940
|
-
console.log(`\u{1F510} '${mcpServerName}' requires OAuth authentication`);
|
|
210941
|
-
let oauthConfig;
|
|
210942
|
-
const resourceMetadataUri = OAuthUtils.parseWWWAuthenticateHeader(wwwAuthenticate);
|
|
210943
|
-
if (resourceMetadataUri) {
|
|
210944
|
-
oauthConfig = await OAuthUtils.discoverOAuthConfig(resourceMetadataUri);
|
|
210945
|
-
} else if (hasNetworkTransport(mcpServerConfig)) {
|
|
210946
|
-
const serverUrl2 = new URL(mcpServerConfig.httpUrl || mcpServerConfig.url);
|
|
210947
|
-
const baseUrl = `${serverUrl2.protocol}//${serverUrl2.host}`;
|
|
210948
|
-
oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl);
|
|
210949
|
-
}
|
|
210950
|
-
if (!oauthConfig) {
|
|
210951
|
-
console.error(`\u274C Could not configure OAuth for '${mcpServerName}' - please authenticate manually with /mcp auth ${mcpServerName}`);
|
|
210952
|
-
return false;
|
|
210953
|
-
}
|
|
210954
|
-
const oauthAuthConfig = {
|
|
210955
|
-
enabled: true,
|
|
210956
|
-
authorizationUrl: oauthConfig.authorizationUrl,
|
|
210957
|
-
tokenUrl: oauthConfig.tokenUrl,
|
|
210958
|
-
scopes: oauthConfig.scopes || []
|
|
210959
|
-
};
|
|
210960
|
-
const serverUrl = mcpServerConfig.httpUrl || mcpServerConfig.url;
|
|
210961
|
-
console.log(`Starting OAuth authentication for server '${mcpServerName}'...`);
|
|
210962
|
-
const authProvider = new MCPOAuthProvider(new MCPOAuthTokenStorage());
|
|
210963
|
-
await authProvider.authenticate(mcpServerName, oauthAuthConfig, serverUrl);
|
|
210964
|
-
console.log(`OAuth authentication successful for server '${mcpServerName}'`);
|
|
210965
|
-
return true;
|
|
210966
|
-
} catch (error2) {
|
|
210967
|
-
console.error(`Failed to handle automatic OAuth for server '${mcpServerName}': ${getErrorMessage(error2)}`);
|
|
210968
|
-
return false;
|
|
210969
|
-
}
|
|
210970
|
-
}
|
|
210971
|
-
async function createTransportWithOAuth(mcpServerName, mcpServerConfig, accessToken) {
|
|
210972
|
-
try {
|
|
210973
|
-
if (mcpServerConfig.httpUrl) {
|
|
210974
|
-
const oauthTransportOptions = {
|
|
210975
|
-
requestInit: {
|
|
210976
|
-
headers: {
|
|
210977
|
-
...mcpServerConfig.headers,
|
|
210978
|
-
Authorization: `Bearer ${accessToken}`
|
|
210979
|
-
}
|
|
210980
|
-
}
|
|
210981
|
-
};
|
|
210982
|
-
return new StreamableHTTPClientTransport(new URL(mcpServerConfig.httpUrl), oauthTransportOptions);
|
|
210983
|
-
} else if (mcpServerConfig.url) {
|
|
210984
|
-
return new SSEClientTransport(new URL(mcpServerConfig.url), {
|
|
210985
|
-
requestInit: {
|
|
210986
|
-
headers: {
|
|
210987
|
-
...mcpServerConfig.headers,
|
|
210988
|
-
Authorization: `Bearer ${accessToken}`
|
|
210989
|
-
}
|
|
210990
|
-
}
|
|
210991
|
-
});
|
|
210992
|
-
}
|
|
210993
|
-
return null;
|
|
210994
|
-
} catch (error2) {
|
|
210995
|
-
console.error(`Failed to create OAuth transport for server '${mcpServerName}': ${getErrorMessage(error2)}`);
|
|
210996
|
-
return null;
|
|
210997
|
-
}
|
|
210998
|
-
}
|
|
210999
210923
|
function populateMcpServerCommand(mcpServers, mcpServerCommand) {
|
|
211000
210924
|
if (mcpServerCommand) {
|
|
211001
210925
|
const cmd = mcpServerCommand;
|
|
@@ -211010,32 +210934,6 @@ function populateMcpServerCommand(mcpServers, mcpServerCommand) {
|
|
|
211010
210934
|
}
|
|
211011
210935
|
return mcpServers;
|
|
211012
210936
|
}
|
|
211013
|
-
async function connectAndDiscover(mcpServerName, mcpServerConfig, toolRegistry, promptRegistry, debugMode, workspaceContext, cliConfig, sendSdkMcpMessage) {
|
|
211014
|
-
updateMCPServerStatus(mcpServerName, MCPServerStatus.CONNECTING);
|
|
211015
|
-
let mcpClient;
|
|
211016
|
-
try {
|
|
211017
|
-
mcpClient = await connectToMcpServer(mcpServerName, mcpServerConfig, debugMode, workspaceContext, sendSdkMcpMessage);
|
|
211018
|
-
mcpClient.onerror = (error2) => {
|
|
211019
|
-
console.error(`MCP ERROR (${mcpServerName}):`, error2.toString());
|
|
211020
|
-
updateMCPServerStatus(mcpServerName, MCPServerStatus.DISCONNECTED);
|
|
211021
|
-
};
|
|
211022
|
-
const prompts3 = await discoverPrompts(mcpServerName, mcpClient, promptRegistry);
|
|
211023
|
-
const tools = await discoverTools(mcpServerName, mcpServerConfig, mcpClient, cliConfig);
|
|
211024
|
-
if (prompts3.length === 0 && tools.length === 0) {
|
|
211025
|
-
throw new Error("No prompts or tools found on the server.");
|
|
211026
|
-
}
|
|
211027
|
-
updateMCPServerStatus(mcpServerName, MCPServerStatus.CONNECTED);
|
|
211028
|
-
for (const tool of tools) {
|
|
211029
|
-
toolRegistry.registerTool(tool);
|
|
211030
|
-
}
|
|
211031
|
-
} catch (error2) {
|
|
211032
|
-
if (mcpClient) {
|
|
211033
|
-
mcpClient.close();
|
|
211034
|
-
}
|
|
211035
|
-
console.error(`Error connecting to MCP server '${mcpServerName}': ${getErrorMessage(error2)}`);
|
|
211036
|
-
updateMCPServerStatus(mcpServerName, MCPServerStatus.DISCONNECTED);
|
|
211037
|
-
}
|
|
211038
|
-
}
|
|
211039
210937
|
async function discoverTools(mcpServerName, mcpServerConfig, mcpClient, cliConfig) {
|
|
211040
210938
|
try {
|
|
211041
210939
|
const mcpCallableTool = mcpToTool(mcpClient, {
|
|
@@ -211101,241 +210999,6 @@ async function invokeMcpPrompt(mcpServerName, mcpClient, promptName, promptParam
|
|
|
211101
210999
|
throw error2;
|
|
211102
211000
|
}
|
|
211103
211001
|
}
|
|
211104
|
-
function hasNetworkTransport(config2) {
|
|
211105
|
-
return !!(config2.url || config2.httpUrl);
|
|
211106
|
-
}
|
|
211107
|
-
async function connectToMcpServer(mcpServerName, mcpServerConfig, debugMode, workspaceContext, sendSdkMcpMessage) {
|
|
211108
|
-
const mcpClient = new Client({
|
|
211109
|
-
name: "qwen-code-mcp-client",
|
|
211110
|
-
version: "0.0.1"
|
|
211111
|
-
});
|
|
211112
|
-
mcpClient.registerCapabilities({
|
|
211113
|
-
roots: {
|
|
211114
|
-
listChanged: true
|
|
211115
|
-
}
|
|
211116
|
-
});
|
|
211117
|
-
mcpClient.setRequestHandler(ListRootsRequestSchema, async () => {
|
|
211118
|
-
const roots = [];
|
|
211119
|
-
for (const dir of workspaceContext.getDirectories()) {
|
|
211120
|
-
roots.push({
|
|
211121
|
-
uri: pathToFileURL(dir).toString(),
|
|
211122
|
-
name: basename11(dir)
|
|
211123
|
-
});
|
|
211124
|
-
}
|
|
211125
|
-
return {
|
|
211126
|
-
roots
|
|
211127
|
-
};
|
|
211128
|
-
});
|
|
211129
|
-
let unlistenDirectories = workspaceContext.onDirectoriesChanged(async () => {
|
|
211130
|
-
try {
|
|
211131
|
-
await mcpClient.notification({
|
|
211132
|
-
method: "notifications/roots/list_changed"
|
|
211133
|
-
});
|
|
211134
|
-
} catch (_2) {
|
|
211135
|
-
unlistenDirectories?.();
|
|
211136
|
-
unlistenDirectories = void 0;
|
|
211137
|
-
}
|
|
211138
|
-
});
|
|
211139
|
-
const oldOnClose = mcpClient.onclose;
|
|
211140
|
-
mcpClient.onclose = () => {
|
|
211141
|
-
oldOnClose?.();
|
|
211142
|
-
unlistenDirectories?.();
|
|
211143
|
-
unlistenDirectories = void 0;
|
|
211144
|
-
};
|
|
211145
|
-
try {
|
|
211146
|
-
const transport = await createTransport(mcpServerName, mcpServerConfig, debugMode, sendSdkMcpMessage);
|
|
211147
|
-
try {
|
|
211148
|
-
await mcpClient.connect(transport, {
|
|
211149
|
-
timeout: mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC
|
|
211150
|
-
});
|
|
211151
|
-
return mcpClient;
|
|
211152
|
-
} catch (error2) {
|
|
211153
|
-
await transport.close();
|
|
211154
|
-
throw error2;
|
|
211155
|
-
}
|
|
211156
|
-
} catch (error2) {
|
|
211157
|
-
const errorString = String(error2);
|
|
211158
|
-
if (errorString.includes("401") && hasNetworkTransport(mcpServerConfig)) {
|
|
211159
|
-
mcpServerRequiresOAuth.set(mcpServerName, true);
|
|
211160
|
-
const shouldTriggerOAuth = mcpServerConfig.httpUrl || mcpServerConfig.oauth?.enabled;
|
|
211161
|
-
if (!shouldTriggerOAuth) {
|
|
211162
|
-
const tokenStorage = new MCPOAuthTokenStorage();
|
|
211163
|
-
const credentials = await tokenStorage.getCredentials(mcpServerName);
|
|
211164
|
-
if (credentials) {
|
|
211165
|
-
const authProvider = new MCPOAuthProvider(tokenStorage);
|
|
211166
|
-
const hasStoredTokens = await authProvider.getValidToken(mcpServerName, {
|
|
211167
|
-
// Pass client ID if available
|
|
211168
|
-
clientId: credentials.clientId
|
|
211169
|
-
});
|
|
211170
|
-
if (hasStoredTokens) {
|
|
211171
|
-
console.log(`Stored OAuth token for SSE server '${mcpServerName}' was rejected. Please re-authenticate using: /mcp auth ${mcpServerName}`);
|
|
211172
|
-
} else {
|
|
211173
|
-
console.log(`401 error received for SSE server '${mcpServerName}' without OAuth configuration. Please authenticate using: /mcp auth ${mcpServerName}`);
|
|
211174
|
-
}
|
|
211175
|
-
}
|
|
211176
|
-
throw new Error(`401 error received for SSE server '${mcpServerName}' without OAuth configuration. Please authenticate using: /mcp auth ${mcpServerName}`);
|
|
211177
|
-
}
|
|
211178
|
-
let wwwAuthenticate = extractWWWAuthenticateHeader(errorString);
|
|
211179
|
-
if (!wwwAuthenticate && hasNetworkTransport(mcpServerConfig)) {
|
|
211180
|
-
console.log(`No www-authenticate header in error, trying to fetch it from server...`);
|
|
211181
|
-
try {
|
|
211182
|
-
const urlToFetch = mcpServerConfig.httpUrl || mcpServerConfig.url;
|
|
211183
|
-
const response = await fetch(urlToFetch, {
|
|
211184
|
-
method: "HEAD",
|
|
211185
|
-
headers: {
|
|
211186
|
-
Accept: mcpServerConfig.httpUrl ? "application/json" : "text/event-stream"
|
|
211187
|
-
},
|
|
211188
|
-
signal: AbortSignal.timeout(5e3)
|
|
211189
|
-
});
|
|
211190
|
-
if (response.status === 401) {
|
|
211191
|
-
wwwAuthenticate = response.headers.get("www-authenticate");
|
|
211192
|
-
if (wwwAuthenticate) {
|
|
211193
|
-
console.log(`Found www-authenticate header from server: ${wwwAuthenticate}`);
|
|
211194
|
-
}
|
|
211195
|
-
}
|
|
211196
|
-
} catch (fetchError) {
|
|
211197
|
-
console.debug(`Failed to fetch www-authenticate header: ${getErrorMessage(fetchError)}`);
|
|
211198
|
-
}
|
|
211199
|
-
}
|
|
211200
|
-
if (wwwAuthenticate) {
|
|
211201
|
-
console.log(`Received 401 with www-authenticate header: ${wwwAuthenticate}`);
|
|
211202
|
-
const oauthSuccess = await handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthenticate);
|
|
211203
|
-
if (oauthSuccess) {
|
|
211204
|
-
console.log(`Retrying connection to '${mcpServerName}' with OAuth token...`);
|
|
211205
|
-
const tokenStorage = new MCPOAuthTokenStorage();
|
|
211206
|
-
const credentials = await tokenStorage.getCredentials(mcpServerName);
|
|
211207
|
-
if (credentials) {
|
|
211208
|
-
const authProvider = new MCPOAuthProvider(tokenStorage);
|
|
211209
|
-
const accessToken = await authProvider.getValidToken(mcpServerName, {
|
|
211210
|
-
// Pass client ID if available
|
|
211211
|
-
clientId: credentials.clientId
|
|
211212
|
-
});
|
|
211213
|
-
if (accessToken) {
|
|
211214
|
-
const oauthTransport = await createTransportWithOAuth(mcpServerName, mcpServerConfig, accessToken);
|
|
211215
|
-
if (oauthTransport) {
|
|
211216
|
-
try {
|
|
211217
|
-
await mcpClient.connect(oauthTransport, {
|
|
211218
|
-
timeout: mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC
|
|
211219
|
-
});
|
|
211220
|
-
return mcpClient;
|
|
211221
|
-
} catch (retryError) {
|
|
211222
|
-
console.error(`Failed to connect with OAuth token: ${getErrorMessage(retryError)}`);
|
|
211223
|
-
throw retryError;
|
|
211224
|
-
}
|
|
211225
|
-
} else {
|
|
211226
|
-
console.error(`Failed to create OAuth transport for server '${mcpServerName}'`);
|
|
211227
|
-
throw new Error(`Failed to create OAuth transport for server '${mcpServerName}'`);
|
|
211228
|
-
}
|
|
211229
|
-
} else {
|
|
211230
|
-
console.error(`Failed to get OAuth token for server '${mcpServerName}'`);
|
|
211231
|
-
throw new Error(`Failed to get OAuth token for server '${mcpServerName}'`);
|
|
211232
|
-
}
|
|
211233
|
-
} else {
|
|
211234
|
-
console.error(`Failed to get credentials for server '${mcpServerName}' after successful OAuth authentication`);
|
|
211235
|
-
throw new Error(`Failed to get credentials for server '${mcpServerName}' after successful OAuth authentication`);
|
|
211236
|
-
}
|
|
211237
|
-
} else {
|
|
211238
|
-
console.error(`Failed to handle automatic OAuth for server '${mcpServerName}'`);
|
|
211239
|
-
throw new Error(`Failed to handle automatic OAuth for server '${mcpServerName}'`);
|
|
211240
|
-
}
|
|
211241
|
-
} else {
|
|
211242
|
-
const shouldTryDiscovery = mcpServerConfig.httpUrl || mcpServerConfig.oauth?.enabled;
|
|
211243
|
-
if (!shouldTryDiscovery) {
|
|
211244
|
-
const tokenStorage = new MCPOAuthTokenStorage();
|
|
211245
|
-
const credentials = await tokenStorage.getCredentials(mcpServerName);
|
|
211246
|
-
if (credentials) {
|
|
211247
|
-
const authProvider = new MCPOAuthProvider(tokenStorage);
|
|
211248
|
-
const hasStoredTokens = await authProvider.getValidToken(mcpServerName, {
|
|
211249
|
-
// Pass client ID if available
|
|
211250
|
-
clientId: credentials.clientId
|
|
211251
|
-
});
|
|
211252
|
-
if (hasStoredTokens) {
|
|
211253
|
-
console.log(`Stored OAuth token for SSE server '${mcpServerName}' was rejected. Please re-authenticate using: /mcp auth ${mcpServerName}`);
|
|
211254
|
-
} else {
|
|
211255
|
-
console.log(`401 error received for SSE server '${mcpServerName}' without OAuth configuration. Please authenticate using: /mcp auth ${mcpServerName}`);
|
|
211256
|
-
}
|
|
211257
|
-
}
|
|
211258
|
-
throw new Error(`401 error received for SSE server '${mcpServerName}' without OAuth configuration. Please authenticate using: /mcp auth ${mcpServerName}`);
|
|
211259
|
-
}
|
|
211260
|
-
console.log(`\u{1F50D} Attempting OAuth discovery for '${mcpServerName}'...`);
|
|
211261
|
-
if (hasNetworkTransport(mcpServerConfig)) {
|
|
211262
|
-
const serverUrl = new URL(mcpServerConfig.httpUrl || mcpServerConfig.url);
|
|
211263
|
-
const baseUrl = `${serverUrl.protocol}//${serverUrl.host}`;
|
|
211264
|
-
try {
|
|
211265
|
-
const oauthConfig = await OAuthUtils.discoverOAuthConfig(baseUrl);
|
|
211266
|
-
if (oauthConfig) {
|
|
211267
|
-
console.log(`Discovered OAuth configuration from base URL for server '${mcpServerName}'`);
|
|
211268
|
-
const oauthAuthConfig = {
|
|
211269
|
-
enabled: true,
|
|
211270
|
-
authorizationUrl: oauthConfig.authorizationUrl,
|
|
211271
|
-
tokenUrl: oauthConfig.tokenUrl,
|
|
211272
|
-
scopes: oauthConfig.scopes || []
|
|
211273
|
-
};
|
|
211274
|
-
const authServerUrl = mcpServerConfig.httpUrl || mcpServerConfig.url;
|
|
211275
|
-
console.log(`Starting OAuth authentication for server '${mcpServerName}'...`);
|
|
211276
|
-
const authProvider = new MCPOAuthProvider(new MCPOAuthTokenStorage());
|
|
211277
|
-
await authProvider.authenticate(mcpServerName, oauthAuthConfig, authServerUrl);
|
|
211278
|
-
const tokenStorage = new MCPOAuthTokenStorage();
|
|
211279
|
-
const credentials = await tokenStorage.getCredentials(mcpServerName);
|
|
211280
|
-
if (credentials) {
|
|
211281
|
-
const authProvider2 = new MCPOAuthProvider(tokenStorage);
|
|
211282
|
-
const accessToken = await authProvider2.getValidToken(mcpServerName, {
|
|
211283
|
-
// Pass client ID if available
|
|
211284
|
-
clientId: credentials.clientId
|
|
211285
|
-
});
|
|
211286
|
-
if (accessToken) {
|
|
211287
|
-
const oauthTransport = await createTransportWithOAuth(mcpServerName, mcpServerConfig, accessToken);
|
|
211288
|
-
if (oauthTransport) {
|
|
211289
|
-
try {
|
|
211290
|
-
await mcpClient.connect(oauthTransport, {
|
|
211291
|
-
timeout: mcpServerConfig.timeout ?? MCP_DEFAULT_TIMEOUT_MSEC
|
|
211292
|
-
});
|
|
211293
|
-
return mcpClient;
|
|
211294
|
-
} catch (retryError) {
|
|
211295
|
-
console.error(`Failed to connect with OAuth token: ${getErrorMessage(retryError)}`);
|
|
211296
|
-
throw retryError;
|
|
211297
|
-
}
|
|
211298
|
-
} else {
|
|
211299
|
-
console.error(`Failed to create OAuth transport for server '${mcpServerName}'`);
|
|
211300
|
-
throw new Error(`Failed to create OAuth transport for server '${mcpServerName}'`);
|
|
211301
|
-
}
|
|
211302
|
-
} else {
|
|
211303
|
-
console.error(`Failed to get OAuth token for server '${mcpServerName}'`);
|
|
211304
|
-
throw new Error(`Failed to get OAuth token for server '${mcpServerName}'`);
|
|
211305
|
-
}
|
|
211306
|
-
} else {
|
|
211307
|
-
console.error(`Failed to get stored credentials for server '${mcpServerName}'`);
|
|
211308
|
-
throw new Error(`Failed to get stored credentials for server '${mcpServerName}'`);
|
|
211309
|
-
}
|
|
211310
|
-
} else {
|
|
211311
|
-
console.error(`\u274C Could not configure OAuth for '${mcpServerName}' - please authenticate manually with /mcp auth ${mcpServerName}`);
|
|
211312
|
-
throw new Error(`OAuth configuration failed for '${mcpServerName}'. Please authenticate manually with /mcp auth ${mcpServerName}`);
|
|
211313
|
-
}
|
|
211314
|
-
} catch (discoveryError) {
|
|
211315
|
-
console.error(`\u274C OAuth discovery failed for '${mcpServerName}' - please authenticate manually with /mcp auth ${mcpServerName}`);
|
|
211316
|
-
throw discoveryError;
|
|
211317
|
-
}
|
|
211318
|
-
} else {
|
|
211319
|
-
console.error(`\u274C '${mcpServerName}' requires authentication but no OAuth configuration found`);
|
|
211320
|
-
throw new Error(`MCP server '${mcpServerName}' requires authentication. Please configure OAuth or check server settings.`);
|
|
211321
|
-
}
|
|
211322
|
-
}
|
|
211323
|
-
} else {
|
|
211324
|
-
const errorMessage = error2.message || String(error2);
|
|
211325
|
-
const isNetworkError = errorMessage.includes("ENOTFOUND") || errorMessage.includes("ECONNREFUSED");
|
|
211326
|
-
let conciseError;
|
|
211327
|
-
if (isNetworkError) {
|
|
211328
|
-
conciseError = `Cannot connect to '${mcpServerName}' - server may be down or URL incorrect`;
|
|
211329
|
-
} else {
|
|
211330
|
-
conciseError = `Connection failed for '${mcpServerName}': ${errorMessage}`;
|
|
211331
|
-
}
|
|
211332
|
-
if (process.env["SANDBOX"]) {
|
|
211333
|
-
conciseError += ` (check sandbox availability)`;
|
|
211334
|
-
}
|
|
211335
|
-
throw new Error(conciseError);
|
|
211336
|
-
}
|
|
211337
|
-
}
|
|
211338
|
-
}
|
|
211339
211002
|
async function createTransport(mcpServerName, mcpServerConfig, debugMode, sendSdkMcpMessage) {
|
|
211340
211003
|
if (isSdkMcpServerConfig(mcpServerConfig)) {
|
|
211341
211004
|
if (!sendSdkMcpMessage) {
|
|
@@ -211460,7 +211123,7 @@ function isEnabled(funcDecl, mcpServerName, mcpServerConfig) {
|
|
|
211460
211123
|
}
|
|
211461
211124
|
return !includeTools || includeTools.some((tool) => tool === funcDecl.name || tool.startsWith(`${funcDecl.name}(`));
|
|
211462
211125
|
}
|
|
211463
|
-
var import_shell_quote3, MCP_DEFAULT_TIMEOUT_MSEC, MCPServerStatus, MCPDiscoveryState, McpClient, serverStatuses, mcpDiscoveryState,
|
|
211126
|
+
var import_shell_quote3, MCP_DEFAULT_TIMEOUT_MSEC, MCPServerStatus, MCPDiscoveryState, McpClient, serverStatuses, mcpDiscoveryState, statusChangeListeners;
|
|
211464
211127
|
var init_mcp_client = __esm({
|
|
211465
211128
|
"packages/core/dist/src/tools/mcp-client.js"() {
|
|
211466
211129
|
"use strict";
|
|
@@ -211592,6 +211255,15 @@ var init_mcp_client = __esm({
|
|
|
211592
211255
|
getStatus() {
|
|
211593
211256
|
return this.status;
|
|
211594
211257
|
}
|
|
211258
|
+
async readResource(uri, options2) {
|
|
211259
|
+
if (this.status !== MCPServerStatus.CONNECTED) {
|
|
211260
|
+
throw new Error("Client is not connected.");
|
|
211261
|
+
}
|
|
211262
|
+
if (this.client.getServerCapabilities()?.resources == null) {
|
|
211263
|
+
throw new Error("MCP server does not support resources.");
|
|
211264
|
+
}
|
|
211265
|
+
return this.client.request({ method: "resources/read", params: { uri } }, ReadResourceResultSchema, options2);
|
|
211266
|
+
}
|
|
211595
211267
|
updateStatus(status) {
|
|
211596
211268
|
this.status = status;
|
|
211597
211269
|
updateMCPServerStatus(this.serverName, status);
|
|
@@ -211608,21 +211280,14 @@ var init_mcp_client = __esm({
|
|
|
211608
211280
|
};
|
|
211609
211281
|
serverStatuses = /* @__PURE__ */ new Map();
|
|
211610
211282
|
mcpDiscoveryState = MCPDiscoveryState.NOT_STARTED;
|
|
211611
|
-
mcpServerRequiresOAuth = /* @__PURE__ */ new Map();
|
|
211612
211283
|
statusChangeListeners = [];
|
|
211613
211284
|
__name(updateMCPServerStatus, "updateMCPServerStatus");
|
|
211614
211285
|
__name(getMCPServerStatus, "getMCPServerStatus");
|
|
211615
211286
|
__name(getMCPDiscoveryState, "getMCPDiscoveryState");
|
|
211616
|
-
__name(extractWWWAuthenticateHeader, "extractWWWAuthenticateHeader");
|
|
211617
|
-
__name(handleAutomaticOAuth, "handleAutomaticOAuth");
|
|
211618
|
-
__name(createTransportWithOAuth, "createTransportWithOAuth");
|
|
211619
211287
|
__name(populateMcpServerCommand, "populateMcpServerCommand");
|
|
211620
|
-
__name(connectAndDiscover, "connectAndDiscover");
|
|
211621
211288
|
__name(discoverTools, "discoverTools");
|
|
211622
211289
|
__name(discoverPrompts, "discoverPrompts");
|
|
211623
211290
|
__name(invokeMcpPrompt, "invokeMcpPrompt");
|
|
211624
|
-
__name(hasNetworkTransport, "hasNetworkTransport");
|
|
211625
|
-
__name(connectToMcpServer, "connectToMcpServer");
|
|
211626
211291
|
__name(createTransport, "createTransport");
|
|
211627
211292
|
__name(isEnabled, "isEnabled");
|
|
211628
211293
|
}
|
|
@@ -211683,6 +211348,42 @@ var init_mcp_client_manager = __esm({
|
|
|
211683
211348
|
await Promise.all(discoveryPromises);
|
|
211684
211349
|
this.discoveryState = MCPDiscoveryState.COMPLETED;
|
|
211685
211350
|
}
|
|
211351
|
+
/**
|
|
211352
|
+
* Connects to a single MCP server and discovers its tools/prompts.
|
|
211353
|
+
* The connected client is tracked so it can be closed by {@link stop}.
|
|
211354
|
+
*
|
|
211355
|
+
* This is primarily used for on-demand re-discovery flows (e.g. after OAuth).
|
|
211356
|
+
*/
|
|
211357
|
+
async discoverMcpToolsForServer(serverName, cliConfig) {
|
|
211358
|
+
const servers = populateMcpServerCommand(this.cliConfig.getMcpServers() || {}, this.cliConfig.getMcpServerCommand());
|
|
211359
|
+
const serverConfig = servers[serverName];
|
|
211360
|
+
if (!serverConfig) {
|
|
211361
|
+
return;
|
|
211362
|
+
}
|
|
211363
|
+
const existingClient = this.clients.get(serverName);
|
|
211364
|
+
if (existingClient) {
|
|
211365
|
+
try {
|
|
211366
|
+
await existingClient.disconnect();
|
|
211367
|
+
} catch (error2) {
|
|
211368
|
+
console.error(`Error stopping client '${serverName}': ${getErrorMessage(error2)}`);
|
|
211369
|
+
} finally {
|
|
211370
|
+
this.clients.delete(serverName);
|
|
211371
|
+
this.eventEmitter?.emit("mcp-client-update", this.clients);
|
|
211372
|
+
}
|
|
211373
|
+
}
|
|
211374
|
+
const sdkCallback = isSdkMcpServerConfig(serverConfig) ? this.sendSdkMcpMessage : void 0;
|
|
211375
|
+
const client = new McpClient(serverName, serverConfig, this.toolRegistry, this.cliConfig.getPromptRegistry(), this.cliConfig.getWorkspaceContext(), this.cliConfig.getDebugMode(), sdkCallback);
|
|
211376
|
+
this.clients.set(serverName, client);
|
|
211377
|
+
this.eventEmitter?.emit("mcp-client-update", this.clients);
|
|
211378
|
+
try {
|
|
211379
|
+
await client.connect();
|
|
211380
|
+
await client.discover(cliConfig);
|
|
211381
|
+
} catch (error2) {
|
|
211382
|
+
console.error(`Error during discovery for server '${serverName}': ${getErrorMessage(error2)}`);
|
|
211383
|
+
} finally {
|
|
211384
|
+
this.eventEmitter?.emit("mcp-client-update", this.clients);
|
|
211385
|
+
}
|
|
211386
|
+
}
|
|
211686
211387
|
/**
|
|
211687
211388
|
* Stops all running local MCP servers and closes all client connections.
|
|
211688
211389
|
* This is the cleanup method to be called on application exit.
|
|
@@ -211701,6 +211402,24 @@ var init_mcp_client_manager = __esm({
|
|
|
211701
211402
|
getDiscoveryState() {
|
|
211702
211403
|
return this.discoveryState;
|
|
211703
211404
|
}
|
|
211405
|
+
async readResource(serverName, uri, options2) {
|
|
211406
|
+
let client = this.clients.get(serverName);
|
|
211407
|
+
if (!client) {
|
|
211408
|
+
const servers = populateMcpServerCommand(this.cliConfig.getMcpServers() || {}, this.cliConfig.getMcpServerCommand());
|
|
211409
|
+
const serverConfig = servers[serverName];
|
|
211410
|
+
if (!serverConfig) {
|
|
211411
|
+
throw new Error(`MCP server '${serverName}' is not configured.`);
|
|
211412
|
+
}
|
|
211413
|
+
const sdkCallback = isSdkMcpServerConfig(serverConfig) ? this.sendSdkMcpMessage : void 0;
|
|
211414
|
+
client = new McpClient(serverName, serverConfig, this.toolRegistry, this.cliConfig.getPromptRegistry(), this.cliConfig.getWorkspaceContext(), this.cliConfig.getDebugMode(), sdkCallback);
|
|
211415
|
+
this.clients.set(serverName, client);
|
|
211416
|
+
this.eventEmitter?.emit("mcp-client-update", this.clients);
|
|
211417
|
+
}
|
|
211418
|
+
if (client.getStatus() !== MCPServerStatus.CONNECTED) {
|
|
211419
|
+
await client.connect();
|
|
211420
|
+
}
|
|
211421
|
+
return client.readResource(uri, options2);
|
|
211422
|
+
}
|
|
211704
211423
|
};
|
|
211705
211424
|
}
|
|
211706
211425
|
});
|
|
@@ -211714,7 +211433,6 @@ var init_tool_registry = __esm({
|
|
|
211714
211433
|
"use strict";
|
|
211715
211434
|
init_esbuild_shims();
|
|
211716
211435
|
init_tools();
|
|
211717
|
-
init_mcp_client();
|
|
211718
211436
|
init_mcp_client_manager();
|
|
211719
211437
|
init_mcp_tool();
|
|
211720
211438
|
import_shell_quote4 = __toESM(require_shell_quote(), 1);
|
|
@@ -211923,11 +211641,7 @@ Signal: Signal number or \`(none)\` if no signal was received.
|
|
|
211923
211641
|
}
|
|
211924
211642
|
}
|
|
211925
211643
|
this.config.getPromptRegistry().removePromptsByServer(serverName);
|
|
211926
|
-
|
|
211927
|
-
const serverConfig = mcpServers[serverName];
|
|
211928
|
-
if (serverConfig) {
|
|
211929
|
-
await connectAndDiscover(serverName, serverConfig, this, this.config.getPromptRegistry(), this.config.getDebugMode(), this.config.getWorkspaceContext(), this.config);
|
|
211930
|
-
}
|
|
211644
|
+
await this.mcpClientManager.discoverMcpToolsForServer(serverName, this.config);
|
|
211931
211645
|
}
|
|
211932
211646
|
async discoverAndRegisterToolsFromCommand() {
|
|
211933
211647
|
const discoveryCmd = this.config.getToolDiscoveryCommand();
|
|
@@ -212074,6 +211788,23 @@ Signal: Signal number or \`(none)\` if no signal was received.
|
|
|
212074
211788
|
getTool(name3) {
|
|
212075
211789
|
return this.tools.get(name3);
|
|
212076
211790
|
}
|
|
211791
|
+
async readMcpResource(serverName, uri, options2) {
|
|
211792
|
+
if (!this.config.isTrustedFolder()) {
|
|
211793
|
+
throw new Error("MCP resources are unavailable in untrusted folders.");
|
|
211794
|
+
}
|
|
211795
|
+
return this.mcpClientManager.readResource(serverName, uri, options2);
|
|
211796
|
+
}
|
|
211797
|
+
/**
|
|
211798
|
+
* Stops all MCP clients and cleans up resources.
|
|
211799
|
+
* This method is idempotent and safe to call multiple times.
|
|
211800
|
+
*/
|
|
211801
|
+
async stop() {
|
|
211802
|
+
try {
|
|
211803
|
+
await this.mcpClientManager.stop();
|
|
211804
|
+
} catch (error2) {
|
|
211805
|
+
console.error("Error stopping MCP clients:", error2);
|
|
211806
|
+
}
|
|
211807
|
+
}
|
|
212077
211808
|
};
|
|
212078
211809
|
}
|
|
212079
211810
|
});
|
|
@@ -217698,7 +217429,7 @@ ${textContent2}
|
|
|
217698
217429
|
return `Fetching content from ${this.params.url} and processing with prompt: "${displayPrompt}"`;
|
|
217699
217430
|
}
|
|
217700
217431
|
async shouldConfirmExecute() {
|
|
217701
|
-
if (this.config.getApprovalMode() === ApprovalMode.AUTO_EDIT) {
|
|
217432
|
+
if (this.config.getApprovalMode() === ApprovalMode.AUTO_EDIT || this.config.getApprovalMode() === ApprovalMode.PLAN) {
|
|
217702
217433
|
return false;
|
|
217703
217434
|
}
|
|
217704
217435
|
const confirmationDetails = {
|
|
@@ -218089,7 +217820,7 @@ var init_web_search = __esm({
|
|
|
218089
217820
|
return ` (Searching the web via ${provider})`;
|
|
218090
217821
|
}
|
|
218091
217822
|
async shouldConfirmExecute(_abortSignal) {
|
|
218092
|
-
if (this.config.getApprovalMode() === ApprovalMode.AUTO_EDIT) {
|
|
217823
|
+
if (this.config.getApprovalMode() === ApprovalMode.AUTO_EDIT || this.config.getApprovalMode() === ApprovalMode.PLAN) {
|
|
218093
217824
|
return false;
|
|
218094
217825
|
}
|
|
218095
217826
|
const confirmationDetails = {
|
|
@@ -221097,8 +220828,8 @@ var init_esm21 = __esm({
|
|
|
221097
220828
|
}
|
|
221098
220829
|
return this._userIgnored(path123, stats);
|
|
221099
220830
|
}
|
|
221100
|
-
_isntIgnored(path123,
|
|
221101
|
-
return !this._isIgnored(path123,
|
|
220831
|
+
_isntIgnored(path123, stat11) {
|
|
220832
|
+
return !this._isIgnored(path123, stat11);
|
|
221102
220833
|
}
|
|
221103
220834
|
/**
|
|
221104
220835
|
* Provides a set of common helpers and properties relating to symlink handling.
|
|
@@ -221402,9 +221133,15 @@ async function loadSkillsFromDir(baseDir) {
|
|
|
221402
221133
|
return [];
|
|
221403
221134
|
}
|
|
221404
221135
|
}
|
|
221136
|
+
function normalizeSkillFileContent(content) {
|
|
221137
|
+
let normalized2 = content.replace(/^\uFEFF/, "");
|
|
221138
|
+
normalized2 = normalized2.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
221139
|
+
return normalized2;
|
|
221140
|
+
}
|
|
221405
221141
|
function parseSkillContent(content, filePath) {
|
|
221406
|
-
const
|
|
221407
|
-
const
|
|
221142
|
+
const normalizedContent = normalizeSkillFileContent(content);
|
|
221143
|
+
const frontmatterRegex = /^---\n([\s\S]*?)\n---(?:\n|$)([\s\S]*)$/;
|
|
221144
|
+
const match2 = normalizedContent.match(frontmatterRegex);
|
|
221408
221145
|
if (!match2) {
|
|
221409
221146
|
throw new Error("Invalid format: missing YAML frontmatter");
|
|
221410
221147
|
}
|
|
@@ -221485,6 +221222,7 @@ var init_skill_load = __esm({
|
|
|
221485
221222
|
init_yaml_parser();
|
|
221486
221223
|
SKILL_MANIFEST_FILE = "SKILL.md";
|
|
221487
221224
|
__name(loadSkillsFromDir, "loadSkillsFromDir");
|
|
221225
|
+
__name(normalizeSkillFileContent, "normalizeSkillFileContent");
|
|
221488
221226
|
__name(parseSkillContent, "parseSkillContent");
|
|
221489
221227
|
__name(validateConfig, "validateConfig");
|
|
221490
221228
|
}
|
|
@@ -221495,7 +221233,7 @@ import * as fs45 from "fs/promises";
|
|
|
221495
221233
|
import * as fsSync2 from "fs";
|
|
221496
221234
|
import * as path49 from "path";
|
|
221497
221235
|
import * as os19 from "os";
|
|
221498
|
-
function
|
|
221236
|
+
function normalizeSkillFileContent2(content) {
|
|
221499
221237
|
let normalized2 = content.replace(/^\uFEFF/, "");
|
|
221500
221238
|
normalized2 = normalized2.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
221501
221239
|
return normalized2;
|
|
@@ -221707,7 +221445,7 @@ var init_skill_manager = __esm({
|
|
|
221707
221445
|
*/
|
|
221708
221446
|
parseSkillContent(content, filePath, level) {
|
|
221709
221447
|
try {
|
|
221710
|
-
const normalizedContent =
|
|
221448
|
+
const normalizedContent = normalizeSkillFileContent2(content);
|
|
221711
221449
|
const frontmatterRegex = /^---\n([\s\S]*?)\n---(?:\n|$)([\s\S]*)$/;
|
|
221712
221450
|
const match2 = normalizedContent.match(frontmatterRegex);
|
|
221713
221451
|
if (!match2) {
|
|
@@ -221795,9 +221533,23 @@ var init_skill_manager = __esm({
|
|
|
221795
221533
|
const entries = await fs45.readdir(baseDir, { withFileTypes: true });
|
|
221796
221534
|
const skills = [];
|
|
221797
221535
|
for (const entry of entries) {
|
|
221798
|
-
|
|
221536
|
+
const isDirectory = entry.isDirectory();
|
|
221537
|
+
const isSymlink = entry.isSymbolicLink();
|
|
221538
|
+
if (!isDirectory && !isSymlink)
|
|
221799
221539
|
continue;
|
|
221800
221540
|
const skillDir = path49.join(baseDir, entry.name);
|
|
221541
|
+
if (isSymlink) {
|
|
221542
|
+
try {
|
|
221543
|
+
const targetStat = await fs45.stat(skillDir);
|
|
221544
|
+
if (!targetStat.isDirectory()) {
|
|
221545
|
+
console.warn(`Skipping symlink ${entry.name} that does not point to a directory`);
|
|
221546
|
+
continue;
|
|
221547
|
+
}
|
|
221548
|
+
} catch (error2) {
|
|
221549
|
+
console.warn(`Skipping invalid symlink ${entry.name}: ${error2 instanceof Error ? error2.message : "Unknown error"}`);
|
|
221550
|
+
continue;
|
|
221551
|
+
}
|
|
221552
|
+
}
|
|
221801
221553
|
const skillManifest = path49.join(skillDir, SKILL_MANIFEST_FILE2);
|
|
221802
221554
|
try {
|
|
221803
221555
|
await fs45.access(skillManifest);
|
|
@@ -221885,7 +221637,7 @@ var init_skill_manager = __esm({
|
|
|
221885
221637
|
}
|
|
221886
221638
|
}
|
|
221887
221639
|
};
|
|
221888
|
-
__name(
|
|
221640
|
+
__name(normalizeSkillFileContent2, "normalizeSkillFileContent");
|
|
221889
221641
|
}
|
|
221890
221642
|
});
|
|
221891
221643
|
|
|
@@ -225161,16 +224913,16 @@ var init_list = __esm({
|
|
|
225161
224913
|
let fd;
|
|
225162
224914
|
try {
|
|
225163
224915
|
fd = fs48.openSync(file, "r");
|
|
225164
|
-
const
|
|
224916
|
+
const stat11 = fs48.fstatSync(fd);
|
|
225165
224917
|
const readSize = opt.maxReadSize || 16 * 1024 * 1024;
|
|
225166
|
-
if (
|
|
225167
|
-
const buf = Buffer.allocUnsafe(
|
|
225168
|
-
const read3 = fs48.readSync(fd, buf, 0,
|
|
224918
|
+
if (stat11.size < readSize) {
|
|
224919
|
+
const buf = Buffer.allocUnsafe(stat11.size);
|
|
224920
|
+
const read3 = fs48.readSync(fd, buf, 0, stat11.size, 0);
|
|
225169
224921
|
p2.end(read3 === buf.byteLength ? buf : buf.subarray(0, read3));
|
|
225170
224922
|
} else {
|
|
225171
224923
|
let pos2 = 0;
|
|
225172
224924
|
const buf = Buffer.allocUnsafe(readSize);
|
|
225173
|
-
while (pos2 <
|
|
224925
|
+
while (pos2 < stat11.size) {
|
|
225174
224926
|
const bytesRead = fs48.readSync(fd, buf, 0, readSize, pos2);
|
|
225175
224927
|
if (bytesRead === 0)
|
|
225176
224928
|
break;
|
|
@@ -225195,13 +224947,13 @@ var init_list = __esm({
|
|
|
225195
224947
|
const p2 = new Promise((resolve31, reject) => {
|
|
225196
224948
|
parse14.on("error", reject);
|
|
225197
224949
|
parse14.on("end", resolve31);
|
|
225198
|
-
fs48.stat(file, (er2,
|
|
224950
|
+
fs48.stat(file, (er2, stat11) => {
|
|
225199
224951
|
if (er2) {
|
|
225200
224952
|
reject(er2);
|
|
225201
224953
|
} else {
|
|
225202
224954
|
const stream2 = new ReadStream(file, {
|
|
225203
224955
|
readSize,
|
|
225204
|
-
size:
|
|
224956
|
+
size: stat11.size
|
|
225205
224957
|
});
|
|
225206
224958
|
stream2.on("error", reject);
|
|
225207
224959
|
stream2.pipe(parse14);
|
|
@@ -225417,21 +225169,21 @@ var init_write_entry = __esm({
|
|
|
225417
225169
|
return super.emit(ev, ...data);
|
|
225418
225170
|
}
|
|
225419
225171
|
[LSTAT]() {
|
|
225420
|
-
fs49.lstat(this.absolute, (er2,
|
|
225172
|
+
fs49.lstat(this.absolute, (er2, stat11) => {
|
|
225421
225173
|
if (er2) {
|
|
225422
225174
|
return this.emit("error", er2);
|
|
225423
225175
|
}
|
|
225424
|
-
this[ONLSTAT](
|
|
225176
|
+
this[ONLSTAT](stat11);
|
|
225425
225177
|
});
|
|
225426
225178
|
}
|
|
225427
|
-
[ONLSTAT](
|
|
225428
|
-
this.statCache.set(this.absolute,
|
|
225429
|
-
this.stat =
|
|
225430
|
-
if (!
|
|
225431
|
-
|
|
225179
|
+
[ONLSTAT](stat11) {
|
|
225180
|
+
this.statCache.set(this.absolute, stat11);
|
|
225181
|
+
this.stat = stat11;
|
|
225182
|
+
if (!stat11.isFile()) {
|
|
225183
|
+
stat11.size = 0;
|
|
225432
225184
|
}
|
|
225433
|
-
this.type = getType3(
|
|
225434
|
-
this.emit("stat",
|
|
225185
|
+
this.type = getType3(stat11);
|
|
225186
|
+
this.emit("stat", stat11);
|
|
225435
225187
|
this[PROCESS2]();
|
|
225436
225188
|
}
|
|
225437
225189
|
[PROCESS2]() {
|
|
@@ -225881,7 +225633,7 @@ var init_write_entry = __esm({
|
|
|
225881
225633
|
return this;
|
|
225882
225634
|
}
|
|
225883
225635
|
};
|
|
225884
|
-
getType3 = /* @__PURE__ */ __name((
|
|
225636
|
+
getType3 = /* @__PURE__ */ __name((stat11) => stat11.isFile() ? "File" : stat11.isDirectory() ? "Directory" : stat11.isSymbolicLink() ? "SymbolicLink" : "Unsupported", "getType");
|
|
225885
225637
|
}
|
|
225886
225638
|
});
|
|
225887
225639
|
|
|
@@ -226481,21 +226233,21 @@ var init_pack = __esm({
|
|
|
226481
226233
|
[STAT](job) {
|
|
226482
226234
|
job.pending = true;
|
|
226483
226235
|
this[JOBS] += 1;
|
|
226484
|
-
const
|
|
226485
|
-
fs50[
|
|
226236
|
+
const stat11 = this.follow ? "stat" : "lstat";
|
|
226237
|
+
fs50[stat11](job.absolute, (er2, stat12) => {
|
|
226486
226238
|
job.pending = false;
|
|
226487
226239
|
this[JOBS] -= 1;
|
|
226488
226240
|
if (er2) {
|
|
226489
226241
|
this.emit("error", er2);
|
|
226490
226242
|
} else {
|
|
226491
|
-
this[ONSTAT](job,
|
|
226243
|
+
this[ONSTAT](job, stat12);
|
|
226492
226244
|
}
|
|
226493
226245
|
});
|
|
226494
226246
|
}
|
|
226495
|
-
[ONSTAT](job,
|
|
226496
|
-
this.statCache.set(job.absolute,
|
|
226497
|
-
job.stat =
|
|
226498
|
-
if (!this.filter(job.path,
|
|
226247
|
+
[ONSTAT](job, stat11) {
|
|
226248
|
+
this.statCache.set(job.absolute, stat11);
|
|
226249
|
+
job.stat = stat11;
|
|
226250
|
+
if (!this.filter(job.path, stat11)) {
|
|
226499
226251
|
job.ignore = true;
|
|
226500
226252
|
}
|
|
226501
226253
|
this[PROCESS3]();
|
|
@@ -226677,8 +226429,8 @@ var init_pack = __esm({
|
|
|
226677
226429
|
resume() {
|
|
226678
226430
|
}
|
|
226679
226431
|
[STAT](job) {
|
|
226680
|
-
const
|
|
226681
|
-
this[ONSTAT](job, fs50[
|
|
226432
|
+
const stat11 = this.follow ? "statSync" : "lstatSync";
|
|
226433
|
+
this[ONSTAT](job, fs50[stat11](job.absolute));
|
|
226682
226434
|
}
|
|
226683
226435
|
[READDIR](job) {
|
|
226684
226436
|
this[ONREADDIR](job, fs50.readdirSync(job.absolute));
|
|
@@ -227978,11 +227730,11 @@ var init_extract = __esm({
|
|
|
227978
227730
|
extractFileSync = /* @__PURE__ */ __name((opt) => {
|
|
227979
227731
|
const u2 = new UnpackSync(opt);
|
|
227980
227732
|
const file = opt.file;
|
|
227981
|
-
const
|
|
227733
|
+
const stat11 = fs55.statSync(file);
|
|
227982
227734
|
const readSize = opt.maxReadSize || 16 * 1024 * 1024;
|
|
227983
227735
|
const stream2 = new ReadStreamSync(file, {
|
|
227984
227736
|
readSize,
|
|
227985
|
-
size:
|
|
227737
|
+
size: stat11.size
|
|
227986
227738
|
});
|
|
227987
227739
|
stream2.pipe(u2);
|
|
227988
227740
|
}, "extractFileSync");
|
|
@@ -227993,13 +227745,13 @@ var init_extract = __esm({
|
|
|
227993
227745
|
const p2 = new Promise((resolve31, reject) => {
|
|
227994
227746
|
u2.on("error", reject);
|
|
227995
227747
|
u2.on("close", resolve31);
|
|
227996
|
-
fs55.stat(file, (er2,
|
|
227748
|
+
fs55.stat(file, (er2, stat11) => {
|
|
227997
227749
|
if (er2) {
|
|
227998
227750
|
reject(er2);
|
|
227999
227751
|
} else {
|
|
228000
227752
|
const stream2 = new ReadStream(file, {
|
|
228001
227753
|
readSize,
|
|
228002
|
-
size:
|
|
227754
|
+
size: stat11.size
|
|
228003
227755
|
});
|
|
228004
227756
|
stream2.on("error", reject);
|
|
228005
227757
|
stream2.pipe(u2);
|
|
@@ -228244,9 +227996,9 @@ var init_update = __esm({
|
|
|
228244
227996
|
if (!opt.mtimeCache) {
|
|
228245
227997
|
opt.mtimeCache = /* @__PURE__ */ new Map();
|
|
228246
227998
|
}
|
|
228247
|
-
opt.filter = filter4 ? (path123,
|
|
228248
|
-
((opt.mtimeCache?.get(path123) ??
|
|
228249
|
-
((opt.mtimeCache?.get(path123) ??
|
|
227999
|
+
opt.filter = filter4 ? (path123, stat11) => filter4(path123, stat11) && !/* c8 ignore start */
|
|
228000
|
+
((opt.mtimeCache?.get(path123) ?? stat11.mtime ?? 0) > (stat11.mtime ?? 0)) : (path123, stat11) => !/* c8 ignore start */
|
|
228001
|
+
((opt.mtimeCache?.get(path123) ?? stat11.mtime ?? 0) > (stat11.mtime ?? 0));
|
|
228250
228002
|
}, "mtimeFilter");
|
|
228251
228003
|
}
|
|
228252
228004
|
});
|
|
@@ -232923,8 +232675,8 @@ async function collectResources(resourcePaths, pluginRoot, destDir) {
|
|
|
232923
232675
|
console.warn(`Resource path not found: ${resolvedPath}`);
|
|
232924
232676
|
continue;
|
|
232925
232677
|
}
|
|
232926
|
-
const
|
|
232927
|
-
if (
|
|
232678
|
+
const stat11 = fs60.statSync(resolvedPath);
|
|
232679
|
+
if (stat11.isDirectory()) {
|
|
232928
232680
|
const dirName = path62.basename(resolvedPath);
|
|
232929
232681
|
const parentDir = path62.dirname(resolvedPath);
|
|
232930
232682
|
if (dirName === destFolderName && parentDir === pluginRoot) {
|
|
@@ -243032,12 +242784,6 @@ var init_config3 = __esm({
|
|
|
243032
242784
|
getSessionId() {
|
|
243033
242785
|
return this.sessionId;
|
|
243034
242786
|
}
|
|
243035
|
-
/**
|
|
243036
|
-
* Releases resources owned by the config instance.
|
|
243037
|
-
*/
|
|
243038
|
-
async shutdown() {
|
|
243039
|
-
this.skillManager?.stopWatching();
|
|
243040
|
-
}
|
|
243041
242787
|
/**
|
|
243042
242788
|
* Starts a new session and resets session-scoped services.
|
|
243043
242789
|
*/
|
|
@@ -243172,6 +242918,24 @@ var init_config3 = __esm({
|
|
|
243172
242918
|
getToolRegistry() {
|
|
243173
242919
|
return this.toolRegistry;
|
|
243174
242920
|
}
|
|
242921
|
+
/**
|
|
242922
|
+
* Shuts down the Config and releases all resources.
|
|
242923
|
+
* This method is idempotent and safe to call multiple times.
|
|
242924
|
+
* It handles the case where initialization was not completed.
|
|
242925
|
+
*/
|
|
242926
|
+
async shutdown() {
|
|
242927
|
+
if (!this.initialized) {
|
|
242928
|
+
return;
|
|
242929
|
+
}
|
|
242930
|
+
try {
|
|
242931
|
+
this.skillManager?.stopWatching();
|
|
242932
|
+
if (this.toolRegistry) {
|
|
242933
|
+
await this.toolRegistry.stop();
|
|
242934
|
+
}
|
|
242935
|
+
} catch (error2) {
|
|
242936
|
+
console.error("Error during Config shutdown:", error2);
|
|
242937
|
+
}
|
|
242938
|
+
}
|
|
243175
242939
|
getPromptRegistry() {
|
|
243176
242940
|
return this.promptRegistry;
|
|
243177
242941
|
}
|
|
@@ -245917,12 +245681,12 @@ var require_resolve_symlink = __commonJS({
|
|
|
245917
245681
|
fs_1.default.realpath(path123, (error2, resolvedPath) => {
|
|
245918
245682
|
if (error2)
|
|
245919
245683
|
return queue.dequeue(suppressErrors ? null : error2, state);
|
|
245920
|
-
fs_1.default.stat(resolvedPath, (error3,
|
|
245684
|
+
fs_1.default.stat(resolvedPath, (error3, stat11) => {
|
|
245921
245685
|
if (error3)
|
|
245922
245686
|
return queue.dequeue(suppressErrors ? null : error3, state);
|
|
245923
|
-
if (
|
|
245687
|
+
if (stat11.isDirectory() && isRecursive(path123, resolvedPath, state))
|
|
245924
245688
|
return queue.dequeue(null, state);
|
|
245925
|
-
callback(
|
|
245689
|
+
callback(stat11, resolvedPath);
|
|
245926
245690
|
queue.dequeue(null, state);
|
|
245927
245691
|
});
|
|
245928
245692
|
});
|
|
@@ -245932,10 +245696,10 @@ var require_resolve_symlink = __commonJS({
|
|
|
245932
245696
|
queue.enqueue();
|
|
245933
245697
|
try {
|
|
245934
245698
|
const resolvedPath = fs_1.default.realpathSync(path123);
|
|
245935
|
-
const
|
|
245936
|
-
if (
|
|
245699
|
+
const stat11 = fs_1.default.statSync(resolvedPath);
|
|
245700
|
+
if (stat11.isDirectory() && isRecursive(path123, resolvedPath, state))
|
|
245937
245701
|
return;
|
|
245938
|
-
callback(
|
|
245702
|
+
callback(stat11, resolvedPath);
|
|
245939
245703
|
} catch (e4) {
|
|
245940
245704
|
if (!suppressErrors)
|
|
245941
245705
|
throw e4;
|
|
@@ -246254,8 +246018,8 @@ var require_walker = __commonJS({
|
|
|
246254
246018
|
this.walkDirectory(this.state, path123, path123, depth - 1, this.walk);
|
|
246255
246019
|
} else if (this.resolveSymlink && entry.isSymbolicLink()) {
|
|
246256
246020
|
let path123 = joinPath.joinPathWithBasePath(entry.name, directoryPath);
|
|
246257
|
-
this.resolveSymlink(path123, this.state, (
|
|
246258
|
-
if (
|
|
246021
|
+
this.resolveSymlink(path123, this.state, (stat11, resolvedPath) => {
|
|
246022
|
+
if (stat11.isDirectory()) {
|
|
246259
246023
|
resolvedPath = (0, utils_1.normalizePath)(resolvedPath, this.state.options);
|
|
246260
246024
|
if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path123 + pathSeparator))
|
|
246261
246025
|
return;
|
|
@@ -248183,7 +247947,7 @@ var init_skills = __esm({
|
|
|
248183
247947
|
import * as fs70 from "node:fs";
|
|
248184
247948
|
import * as path75 from "node:path";
|
|
248185
247949
|
import * as https5 from "node:https";
|
|
248186
|
-
import { stat as
|
|
247950
|
+
import { stat as stat7 } from "node:fs/promises";
|
|
248187
247951
|
function parseSourceAndPluginName(source2) {
|
|
248188
247952
|
const urlSchemes = ["http://", "https://", "git@", "sso://"];
|
|
248189
247953
|
let repoEndIndex = source2.length;
|
|
@@ -248308,7 +248072,7 @@ async function parseInstallSource(source2) {
|
|
|
248308
248072
|
}
|
|
248309
248073
|
} else {
|
|
248310
248074
|
try {
|
|
248311
|
-
await
|
|
248075
|
+
await stat7(repo);
|
|
248312
248076
|
installMetadata = {
|
|
248313
248077
|
source: repo,
|
|
248314
248078
|
type: "local",
|
|
@@ -373328,7 +373092,7 @@ __name(getPackageJson, "getPackageJson");
|
|
|
373328
373092
|
// packages/cli/src/utils/version.ts
|
|
373329
373093
|
async function getCliVersion() {
|
|
373330
373094
|
const pkgJson = await getPackageJson();
|
|
373331
|
-
return "0.9.0-preview.
|
|
373095
|
+
return "0.9.0-preview.3";
|
|
373332
373096
|
}
|
|
373333
373097
|
__name(getCliVersion, "getCliVersion");
|
|
373334
373098
|
|
|
@@ -380864,7 +380628,7 @@ var formatDuration = /* @__PURE__ */ __name((milliseconds) => {
|
|
|
380864
380628
|
|
|
380865
380629
|
// packages/cli/src/generated/git-commit.ts
|
|
380866
380630
|
init_esbuild_shims();
|
|
380867
|
-
var GIT_COMMIT_INFO2 = "
|
|
380631
|
+
var GIT_COMMIT_INFO2 = "365cfbdd";
|
|
380868
380632
|
|
|
380869
380633
|
// packages/cli/src/utils/systemInfo.ts
|
|
380870
380634
|
async function getNpmVersion() {
|
|
@@ -387307,6 +387071,161 @@ function parseAllAtCommands(query) {
|
|
|
387307
387071
|
);
|
|
387308
387072
|
}
|
|
387309
387073
|
__name(parseAllAtCommands, "parseAllAtCommands");
|
|
387074
|
+
function getConfiguredMcpServerNames(config2) {
|
|
387075
|
+
const names = new Set(Object.keys(config2.getMcpServers() ?? {}));
|
|
387076
|
+
if (config2.getMcpServerCommand()) {
|
|
387077
|
+
names.add("mcp");
|
|
387078
|
+
}
|
|
387079
|
+
return names;
|
|
387080
|
+
}
|
|
387081
|
+
__name(getConfiguredMcpServerNames, "getConfiguredMcpServerNames");
|
|
387082
|
+
function normalizeMcpResourceUri(serverName, resource) {
|
|
387083
|
+
if (resource.includes("://")) {
|
|
387084
|
+
return resource;
|
|
387085
|
+
}
|
|
387086
|
+
const cleaned = resource.startsWith("/") ? resource.slice(1) : resource;
|
|
387087
|
+
return `${serverName}://${cleaned}`;
|
|
387088
|
+
}
|
|
387089
|
+
__name(normalizeMcpResourceUri, "normalizeMcpResourceUri");
|
|
387090
|
+
function splitLeadingToken(text) {
|
|
387091
|
+
let i3 = 0;
|
|
387092
|
+
while (i3 < text.length && /\s/.test(text[i3])) {
|
|
387093
|
+
i3++;
|
|
387094
|
+
}
|
|
387095
|
+
if (i3 >= text.length) {
|
|
387096
|
+
return null;
|
|
387097
|
+
}
|
|
387098
|
+
let token2 = "";
|
|
387099
|
+
let inEscape = false;
|
|
387100
|
+
while (i3 < text.length) {
|
|
387101
|
+
const char = text[i3];
|
|
387102
|
+
if (inEscape) {
|
|
387103
|
+
token2 += char;
|
|
387104
|
+
inEscape = false;
|
|
387105
|
+
i3++;
|
|
387106
|
+
continue;
|
|
387107
|
+
}
|
|
387108
|
+
if (char === "\\") {
|
|
387109
|
+
inEscape = true;
|
|
387110
|
+
i3++;
|
|
387111
|
+
continue;
|
|
387112
|
+
}
|
|
387113
|
+
if (/[,\s;!?()[\]{}]/.test(char)) {
|
|
387114
|
+
break;
|
|
387115
|
+
}
|
|
387116
|
+
if (char === ".") {
|
|
387117
|
+
const nextChar = i3 + 1 < text.length ? text[i3 + 1] : "";
|
|
387118
|
+
if (nextChar === "" || /\s/.test(nextChar)) {
|
|
387119
|
+
break;
|
|
387120
|
+
}
|
|
387121
|
+
}
|
|
387122
|
+
token2 += char;
|
|
387123
|
+
i3++;
|
|
387124
|
+
}
|
|
387125
|
+
if (!token2) {
|
|
387126
|
+
return null;
|
|
387127
|
+
}
|
|
387128
|
+
return { token: token2, rest: text.slice(i3) };
|
|
387129
|
+
}
|
|
387130
|
+
__name(splitLeadingToken, "splitLeadingToken");
|
|
387131
|
+
function extractMcpResourceAtReferences(parts, config2) {
|
|
387132
|
+
const configuredServers = getConfiguredMcpServerNames(config2);
|
|
387133
|
+
const refs = [];
|
|
387134
|
+
const merged = [];
|
|
387135
|
+
for (let i3 = 0; i3 < parts.length; i3++) {
|
|
387136
|
+
const part = parts[i3];
|
|
387137
|
+
if (part.type !== "atPath") {
|
|
387138
|
+
merged.push(part);
|
|
387139
|
+
continue;
|
|
387140
|
+
}
|
|
387141
|
+
const atText = part.content;
|
|
387142
|
+
const colonIndex = atText.indexOf(":");
|
|
387143
|
+
if (!atText.startsWith("@") || colonIndex <= 1) {
|
|
387144
|
+
merged.push(part);
|
|
387145
|
+
continue;
|
|
387146
|
+
}
|
|
387147
|
+
const serverName = atText.slice(1, colonIndex);
|
|
387148
|
+
if (!configuredServers.has(serverName)) {
|
|
387149
|
+
merged.push(part);
|
|
387150
|
+
continue;
|
|
387151
|
+
}
|
|
387152
|
+
let resource = atText.slice(colonIndex + 1);
|
|
387153
|
+
if (!resource) {
|
|
387154
|
+
const next = parts[i3 + 1];
|
|
387155
|
+
if (next?.type === "text") {
|
|
387156
|
+
const tokenInfo = splitLeadingToken(next.content);
|
|
387157
|
+
if (tokenInfo) {
|
|
387158
|
+
resource = tokenInfo.token;
|
|
387159
|
+
const remainingText = tokenInfo.rest;
|
|
387160
|
+
parts[i3 + 1] = { type: "text", content: remainingText };
|
|
387161
|
+
}
|
|
387162
|
+
}
|
|
387163
|
+
}
|
|
387164
|
+
if (!resource) {
|
|
387165
|
+
merged.push({ type: "text", content: atText });
|
|
387166
|
+
continue;
|
|
387167
|
+
}
|
|
387168
|
+
const normalizedResource = resource.includes("://") ? resource : resource.startsWith("/") ? resource.slice(1) : resource;
|
|
387169
|
+
const normalizedAtCommand = `@${serverName}:${normalizedResource}`;
|
|
387170
|
+
refs.push({
|
|
387171
|
+
atCommand: normalizedAtCommand,
|
|
387172
|
+
serverName,
|
|
387173
|
+
uri: normalizeMcpResourceUri(serverName, normalizedResource)
|
|
387174
|
+
});
|
|
387175
|
+
merged.push({ type: "atPath", content: normalizedAtCommand });
|
|
387176
|
+
}
|
|
387177
|
+
return {
|
|
387178
|
+
parts: merged.filter(
|
|
387179
|
+
(p2) => !(p2.type === "text" && p2.content.trim() === "")
|
|
387180
|
+
),
|
|
387181
|
+
refs
|
|
387182
|
+
};
|
|
387183
|
+
}
|
|
387184
|
+
__name(extractMcpResourceAtReferences, "extractMcpResourceAtReferences");
|
|
387185
|
+
function formatMcpResourceContents(raw2, limits) {
|
|
387186
|
+
if (!raw2 || typeof raw2 !== "object") {
|
|
387187
|
+
return "[Error: Invalid MCP resource response]";
|
|
387188
|
+
}
|
|
387189
|
+
const contents = raw2.contents;
|
|
387190
|
+
if (!Array.isArray(contents)) {
|
|
387191
|
+
return "[Error: Invalid MCP resource response]";
|
|
387192
|
+
}
|
|
387193
|
+
const parts = [];
|
|
387194
|
+
for (const item of contents) {
|
|
387195
|
+
if (!item || typeof item !== "object") {
|
|
387196
|
+
continue;
|
|
387197
|
+
}
|
|
387198
|
+
const text = item.text;
|
|
387199
|
+
const blob = item.blob;
|
|
387200
|
+
const mimeType = item.mimeType;
|
|
387201
|
+
if (typeof text === "string") {
|
|
387202
|
+
parts.push(text);
|
|
387203
|
+
continue;
|
|
387204
|
+
}
|
|
387205
|
+
if (typeof blob === "string") {
|
|
387206
|
+
const mimeTypeLabel = typeof mimeType === "string" ? mimeType : "application/octet-stream";
|
|
387207
|
+
parts.push(
|
|
387208
|
+
`[Binary MCP resource omitted (mimeType: ${mimeTypeLabel}, bytes: ${blob.length})]`
|
|
387209
|
+
);
|
|
387210
|
+
}
|
|
387211
|
+
}
|
|
387212
|
+
let combined = parts.join("\n\n");
|
|
387213
|
+
const maxLines = limits.maxLinesPerResource;
|
|
387214
|
+
if (Number.isFinite(maxLines)) {
|
|
387215
|
+
const lines = combined.split("\n");
|
|
387216
|
+
if (lines.length > maxLines) {
|
|
387217
|
+
combined = `${lines.slice(0, maxLines).join("\n")}
|
|
387218
|
+
[truncated]`;
|
|
387219
|
+
}
|
|
387220
|
+
}
|
|
387221
|
+
const maxChars = limits.maxCharsPerResource;
|
|
387222
|
+
if (Number.isFinite(maxChars) && combined.length > maxChars) {
|
|
387223
|
+
combined = `${combined.slice(0, maxChars)}
|
|
387224
|
+
[truncated]`;
|
|
387225
|
+
}
|
|
387226
|
+
return combined;
|
|
387227
|
+
}
|
|
387228
|
+
__name(formatMcpResourceContents, "formatMcpResourceContents");
|
|
387310
387229
|
async function handleAtCommand({
|
|
387311
387230
|
query,
|
|
387312
387231
|
config: config2,
|
|
@@ -387315,10 +387234,15 @@ async function handleAtCommand({
|
|
|
387315
387234
|
messageId: userMessageTimestamp,
|
|
387316
387235
|
signal
|
|
387317
387236
|
}) {
|
|
387318
|
-
const
|
|
387237
|
+
const parsedParts = parseAllAtCommands(query);
|
|
387238
|
+
const { parts: commandParts, refs: mcpResourceRefs } = extractMcpResourceAtReferences(parsedParts, config2);
|
|
387239
|
+
const mcpAtCommands = new Set(mcpResourceRefs.map((r5) => r5.atCommand));
|
|
387319
387240
|
const atPathCommandParts = commandParts.filter(
|
|
387320
387241
|
(part) => part.type === "atPath"
|
|
387321
387242
|
);
|
|
387243
|
+
const fileAtPathCommandParts = atPathCommandParts.filter(
|
|
387244
|
+
(part) => !mcpAtCommands.has(part.content)
|
|
387245
|
+
);
|
|
387322
387246
|
if (atPathCommandParts.length === 0) {
|
|
387323
387247
|
return { processedQuery: [{ text: query }], shouldProceed: true };
|
|
387324
387248
|
}
|
|
@@ -387335,14 +387259,7 @@ async function handleAtCommand({
|
|
|
387335
387259
|
const toolRegistry = config2.getToolRegistry();
|
|
387336
387260
|
const readManyFilesTool = toolRegistry.getTool("read_many_files");
|
|
387337
387261
|
const globTool = toolRegistry.getTool("glob");
|
|
387338
|
-
|
|
387339
|
-
addItem(
|
|
387340
|
-
{ type: "error", text: "Error: read_many_files tool not found." },
|
|
387341
|
-
userMessageTimestamp
|
|
387342
|
-
);
|
|
387343
|
-
return { processedQuery: null, shouldProceed: false };
|
|
387344
|
-
}
|
|
387345
|
-
for (const atPathPart of atPathCommandParts) {
|
|
387262
|
+
for (const atPathPart of fileAtPathCommandParts) {
|
|
387346
387263
|
const originalAtPath = atPathPart.content;
|
|
387347
387264
|
if (originalAtPath === "@") {
|
|
387348
387265
|
onDebugMessage(
|
|
@@ -387502,7 +387419,7 @@ ${messages.join("\n")}`;
|
|
|
387502
387419
|
console.log(message);
|
|
387503
387420
|
onDebugMessage(message);
|
|
387504
387421
|
}
|
|
387505
|
-
if (pathSpecsToRead.length === 0) {
|
|
387422
|
+
if (pathSpecsToRead.length === 0 && mcpResourceRefs.length === 0) {
|
|
387506
387423
|
onDebugMessage("No valid file paths found in @ commands to read.");
|
|
387507
387424
|
if (initialQueryText === "@" && query.trim() === "@") {
|
|
387508
387425
|
return { processedQuery: [{ text: query }], shouldProceed: true };
|
|
@@ -387515,76 +387432,146 @@ ${messages.join("\n")}`;
|
|
|
387515
387432
|
};
|
|
387516
387433
|
}
|
|
387517
387434
|
const processedQueryParts = [{ text: initialQueryText }];
|
|
387518
|
-
const
|
|
387519
|
-
|
|
387520
|
-
|
|
387521
|
-
|
|
387522
|
-
|
|
387435
|
+
const toolDisplays = [];
|
|
387436
|
+
if (pathSpecsToRead.length > 0) {
|
|
387437
|
+
if (!readManyFilesTool) {
|
|
387438
|
+
addItem(
|
|
387439
|
+
{ type: "error", text: "Error: read_many_files tool not found." },
|
|
387440
|
+
userMessageTimestamp
|
|
387441
|
+
);
|
|
387442
|
+
return { processedQuery: null, shouldProceed: false };
|
|
387523
387443
|
}
|
|
387524
|
-
|
|
387525
|
-
|
|
387526
|
-
|
|
387527
|
-
|
|
387528
|
-
|
|
387529
|
-
|
|
387530
|
-
|
|
387531
|
-
|
|
387532
|
-
|
|
387533
|
-
|
|
387534
|
-
|
|
387535
|
-
|
|
387536
|
-
|
|
387537
|
-
|
|
387538
|
-
|
|
387539
|
-
|
|
387540
|
-
|
|
387541
|
-
|
|
387542
|
-
|
|
387444
|
+
const toolArgs = {
|
|
387445
|
+
paths: pathSpecsToRead,
|
|
387446
|
+
file_filtering_options: {
|
|
387447
|
+
respect_git_ignore: respectFileIgnore.respectGitIgnore,
|
|
387448
|
+
respect_qwen_ignore: respectFileIgnore.respectQwenIgnore
|
|
387449
|
+
}
|
|
387450
|
+
// Use configuration setting
|
|
387451
|
+
};
|
|
387452
|
+
let invocation = void 0;
|
|
387453
|
+
try {
|
|
387454
|
+
invocation = readManyFilesTool.build(toolArgs);
|
|
387455
|
+
const result = await invocation.execute(signal);
|
|
387456
|
+
toolDisplays.push({
|
|
387457
|
+
callId: `client-read-${userMessageTimestamp}`,
|
|
387458
|
+
name: readManyFilesTool.displayName,
|
|
387459
|
+
description: invocation.getDescription(),
|
|
387460
|
+
status: "Success" /* Success */,
|
|
387461
|
+
resultDisplay: result.returnDisplay || `Successfully read: ${contentLabelsForDisplay.join(", ")}`,
|
|
387462
|
+
confirmationDetails: void 0
|
|
387543
387463
|
});
|
|
387544
|
-
|
|
387545
|
-
|
|
387546
|
-
|
|
387547
|
-
|
|
387548
|
-
|
|
387549
|
-
|
|
387550
|
-
|
|
387551
|
-
|
|
387464
|
+
if (Array.isArray(result.llmContent)) {
|
|
387465
|
+
const fileContentRegex = /^--- (.*?) ---\n\n([\s\S]*?)\n\n$/;
|
|
387466
|
+
processedQueryParts.push({
|
|
387467
|
+
text: "\n--- Content from referenced files ---"
|
|
387468
|
+
});
|
|
387469
|
+
for (const part of result.llmContent) {
|
|
387470
|
+
if (typeof part === "string") {
|
|
387471
|
+
const match2 = fileContentRegex.exec(part);
|
|
387472
|
+
if (match2) {
|
|
387473
|
+
const filePathSpecInContent = match2[1];
|
|
387474
|
+
const fileActualContent = match2[2].trim();
|
|
387475
|
+
processedQueryParts.push({
|
|
387476
|
+
text: `
|
|
387552
387477
|
Content from @${filePathSpecInContent}:
|
|
387553
387478
|
`
|
|
387554
|
-
|
|
387555
|
-
|
|
387479
|
+
});
|
|
387480
|
+
processedQueryParts.push({ text: fileActualContent });
|
|
387481
|
+
} else {
|
|
387482
|
+
processedQueryParts.push({ text: part });
|
|
387483
|
+
}
|
|
387556
387484
|
} else {
|
|
387557
|
-
processedQueryParts.push(
|
|
387485
|
+
processedQueryParts.push(part);
|
|
387558
387486
|
}
|
|
387559
|
-
} else {
|
|
387560
|
-
processedQueryParts.push(part);
|
|
387561
387487
|
}
|
|
387488
|
+
} else {
|
|
387489
|
+
onDebugMessage(
|
|
387490
|
+
"read_many_files tool returned no content or empty content."
|
|
387491
|
+
);
|
|
387562
387492
|
}
|
|
387563
|
-
}
|
|
387564
|
-
|
|
387565
|
-
|
|
387493
|
+
} catch (error2) {
|
|
387494
|
+
toolDisplays.push({
|
|
387495
|
+
callId: `client-read-${userMessageTimestamp}`,
|
|
387496
|
+
name: readManyFilesTool.displayName,
|
|
387497
|
+
description: invocation?.getDescription() ?? "Error attempting to execute tool to read files",
|
|
387498
|
+
status: "Error" /* Error */,
|
|
387499
|
+
resultDisplay: `Error reading files (${contentLabelsForDisplay.join(", ")}): ${getErrorMessage(error2)}`,
|
|
387500
|
+
confirmationDetails: void 0
|
|
387501
|
+
});
|
|
387502
|
+
addItem(
|
|
387503
|
+
{ type: "tool_group", tools: toolDisplays },
|
|
387504
|
+
userMessageTimestamp
|
|
387566
387505
|
);
|
|
387506
|
+
return { processedQuery: null, shouldProceed: false };
|
|
387567
387507
|
}
|
|
387508
|
+
}
|
|
387509
|
+
if (mcpResourceRefs.length > 0) {
|
|
387510
|
+
const totalCharLimit = config2.getTruncateToolOutputThreshold();
|
|
387511
|
+
const totalLineLimit = config2.getTruncateToolOutputLines();
|
|
387512
|
+
const maxCharsPerResource = Number.isFinite(totalCharLimit) ? Math.floor(totalCharLimit / Math.max(1, mcpResourceRefs.length)) : Number.POSITIVE_INFINITY;
|
|
387513
|
+
const maxLinesPerResource = Number.isFinite(totalLineLimit) ? Math.floor(totalLineLimit / Math.max(1, mcpResourceRefs.length)) : Number.POSITIVE_INFINITY;
|
|
387514
|
+
processedQueryParts.push({
|
|
387515
|
+
text: "\n--- Content from referenced MCP resources ---"
|
|
387516
|
+
});
|
|
387517
|
+
for (let i3 = 0; i3 < mcpResourceRefs.length; i3++) {
|
|
387518
|
+
const ref = mcpResourceRefs[i3];
|
|
387519
|
+
let resourceResult;
|
|
387520
|
+
try {
|
|
387521
|
+
if (signal.aborted) {
|
|
387522
|
+
const error2 = new Error("MCP resource read aborted");
|
|
387523
|
+
error2.name = "AbortError";
|
|
387524
|
+
throw error2;
|
|
387525
|
+
}
|
|
387526
|
+
resourceResult = await toolRegistry.readMcpResource(
|
|
387527
|
+
ref.serverName,
|
|
387528
|
+
ref.uri,
|
|
387529
|
+
{ signal }
|
|
387530
|
+
);
|
|
387531
|
+
toolDisplays.push({
|
|
387532
|
+
callId: `client-mcp-resource-${userMessageTimestamp}-${i3}`,
|
|
387533
|
+
name: "McpResourceRead",
|
|
387534
|
+
description: `Read MCP resource ${ref.uri} (server: ${ref.serverName})`,
|
|
387535
|
+
status: "Success" /* Success */,
|
|
387536
|
+
resultDisplay: `Read: ${ref.uri}`,
|
|
387537
|
+
confirmationDetails: void 0
|
|
387538
|
+
});
|
|
387539
|
+
} catch (error2) {
|
|
387540
|
+
toolDisplays.push({
|
|
387541
|
+
callId: `client-mcp-resource-${userMessageTimestamp}-${i3}`,
|
|
387542
|
+
name: "McpResourceRead",
|
|
387543
|
+
description: `Read MCP resource ${ref.uri} (server: ${ref.serverName})`,
|
|
387544
|
+
status: "Error" /* Error */,
|
|
387545
|
+
resultDisplay: `Error reading MCP resource (${ref.uri}): ${getErrorMessage(error2)}`,
|
|
387546
|
+
confirmationDetails: void 0
|
|
387547
|
+
});
|
|
387548
|
+
addItem(
|
|
387549
|
+
{ type: "tool_group", tools: toolDisplays },
|
|
387550
|
+
userMessageTimestamp
|
|
387551
|
+
);
|
|
387552
|
+
return { processedQuery: null, shouldProceed: false };
|
|
387553
|
+
}
|
|
387554
|
+
processedQueryParts.push({
|
|
387555
|
+
text: `
|
|
387556
|
+
Content from ${ref.atCommand}:
|
|
387557
|
+
`
|
|
387558
|
+
});
|
|
387559
|
+
processedQueryParts.push({
|
|
387560
|
+
text: formatMcpResourceContents(resourceResult, {
|
|
387561
|
+
maxCharsPerResource,
|
|
387562
|
+
maxLinesPerResource
|
|
387563
|
+
})
|
|
387564
|
+
});
|
|
387565
|
+
}
|
|
387566
|
+
processedQueryParts.push({ text: "\n--- End of MCP resource content ---" });
|
|
387567
|
+
}
|
|
387568
|
+
if (toolDisplays.length > 0) {
|
|
387568
387569
|
addItem(
|
|
387569
|
-
{ type: "tool_group", tools:
|
|
387570
|
-
userMessageTimestamp
|
|
387571
|
-
);
|
|
387572
|
-
return { processedQuery: processedQueryParts, shouldProceed: true };
|
|
387573
|
-
} catch (error2) {
|
|
387574
|
-
toolCallDisplay = {
|
|
387575
|
-
callId: `client-read-${userMessageTimestamp}`,
|
|
387576
|
-
name: readManyFilesTool.displayName,
|
|
387577
|
-
description: invocation?.getDescription() ?? "Error attempting to execute tool to read files",
|
|
387578
|
-
status: "Error" /* Error */,
|
|
387579
|
-
resultDisplay: `Error reading files (${contentLabelsForDisplay.join(", ")}): ${getErrorMessage(error2)}`,
|
|
387580
|
-
confirmationDetails: void 0
|
|
387581
|
-
};
|
|
387582
|
-
addItem(
|
|
387583
|
-
{ type: "tool_group", tools: [toolCallDisplay] },
|
|
387570
|
+
{ type: "tool_group", tools: toolDisplays },
|
|
387584
387571
|
userMessageTimestamp
|
|
387585
387572
|
);
|
|
387586
|
-
return { processedQuery: null, shouldProceed: false };
|
|
387587
387573
|
}
|
|
387574
|
+
return { processedQuery: processedQueryParts, shouldProceed: true };
|
|
387588
387575
|
}
|
|
387589
387576
|
__name(handleAtCommand, "handleAtCommand");
|
|
387590
387577
|
|
|
@@ -434286,7 +434273,7 @@ var GeminiAgent = class {
|
|
|
434286
434273
|
name: APPROVAL_MODE_INFO[mode].name,
|
|
434287
434274
|
description: APPROVAL_MODE_INFO[mode].description
|
|
434288
434275
|
}));
|
|
434289
|
-
const version2 = "0.9.0-preview.
|
|
434276
|
+
const version2 = "0.9.0-preview.3";
|
|
434290
434277
|
return {
|
|
434291
434278
|
protocolVersion: PROTOCOL_VERSION,
|
|
434292
434279
|
agentInfo: {
|