@enactprotocol/mcp-server 1.2.4 → 1.2.6
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/dist/index.js +632 -577
- package/dist/index.js.bak +632 -577
- package/package.json +2 -5
package/dist/index.js
CHANGED
|
@@ -235541,6 +235541,49 @@ class DaggerExecutionProvider extends ExecutionProvider {
|
|
|
235541
235541
|
});
|
|
235542
235542
|
});
|
|
235543
235543
|
}
|
|
235544
|
+
async setupDirectoryMount(client, container, mountSpec) {
|
|
235545
|
+
try {
|
|
235546
|
+
let localPath2;
|
|
235547
|
+
let containerPath;
|
|
235548
|
+
const colonIndex = mountSpec.indexOf(":");
|
|
235549
|
+
if (colonIndex > 0) {
|
|
235550
|
+
const potentialDriveLetter = mountSpec.substring(0, colonIndex);
|
|
235551
|
+
const isWindowsDrive = potentialDriveLetter.length === 1 && /[A-Za-z]/.test(potentialDriveLetter);
|
|
235552
|
+
if (isWindowsDrive) {
|
|
235553
|
+
const nextColonIndex = mountSpec.indexOf(":", colonIndex + 1);
|
|
235554
|
+
if (nextColonIndex > 0) {
|
|
235555
|
+
localPath2 = mountSpec.substring(0, nextColonIndex);
|
|
235556
|
+
containerPath = mountSpec.substring(nextColonIndex + 1);
|
|
235557
|
+
} else {
|
|
235558
|
+
localPath2 = mountSpec;
|
|
235559
|
+
containerPath = "/workspace/src";
|
|
235560
|
+
}
|
|
235561
|
+
} else {
|
|
235562
|
+
localPath2 = mountSpec.substring(0, colonIndex);
|
|
235563
|
+
containerPath = mountSpec.substring(colonIndex + 1);
|
|
235564
|
+
}
|
|
235565
|
+
} else if (colonIndex === 0) {
|
|
235566
|
+
localPath2 = "";
|
|
235567
|
+
containerPath = mountSpec.substring(1);
|
|
235568
|
+
} else {
|
|
235569
|
+
localPath2 = mountSpec;
|
|
235570
|
+
containerPath = "/workspace/src";
|
|
235571
|
+
}
|
|
235572
|
+
const path7 = __require("path");
|
|
235573
|
+
const resolvedLocalPath = path7.resolve(localPath2);
|
|
235574
|
+
const fs4 = __require("fs");
|
|
235575
|
+
if (!fs4.existsSync(resolvedLocalPath)) {
|
|
235576
|
+
throw new Error(`Mount source directory does not exist: ${resolvedLocalPath}`);
|
|
235577
|
+
}
|
|
235578
|
+
const hostDirectory = client.host().directory(resolvedLocalPath);
|
|
235579
|
+
container = container.withMountedDirectory(containerPath, hostDirectory);
|
|
235580
|
+
logger_default.debug(`\uD83D\uDCC2 Mounted ${resolvedLocalPath} -> ${containerPath}`);
|
|
235581
|
+
return container;
|
|
235582
|
+
} catch (error) {
|
|
235583
|
+
logger_default.error(`Failed to setup directory mount: ${error}`);
|
|
235584
|
+
throw error;
|
|
235585
|
+
}
|
|
235586
|
+
}
|
|
235544
235587
|
async setupContainer(client, environment, inputs, tool) {
|
|
235545
235588
|
const containerImage = tool?.from || this.options.baseImage;
|
|
235546
235589
|
logger_default.debug(`\uD83D\uDE80 Setting up container with image: ${containerImage}${tool?.from ? " (from tool.from)" : " (default baseImage)"}`);
|
|
@@ -235548,6 +235591,9 @@ class DaggerExecutionProvider extends ExecutionProvider {
|
|
|
235548
235591
|
logger_default.debug("\uD83D\uDCE6 Base container created");
|
|
235549
235592
|
container = container.withWorkdir(this.options.workdir);
|
|
235550
235593
|
logger_default.debug(`\uD83D\uDCC1 Working directory set to: ${this.options.workdir}`);
|
|
235594
|
+
if (environment.mount) {
|
|
235595
|
+
container = await this.setupDirectoryMount(client, container, environment.mount);
|
|
235596
|
+
}
|
|
235551
235597
|
for (const [key, value] of Object.entries(environment.vars)) {
|
|
235552
235598
|
container = container.withEnvVariable(key, String(value));
|
|
235553
235599
|
}
|
|
@@ -238982,7 +239028,10 @@ class EnactCore {
|
|
|
238982
239028
|
throw new Error(`Tool ${tool.name} does not have any signatures`);
|
|
238983
239029
|
}
|
|
238984
239030
|
const documentForVerification = {
|
|
238985
|
-
command: tool.command
|
|
239031
|
+
command: tool.command,
|
|
239032
|
+
description: tool.description,
|
|
239033
|
+
from: tool.from,
|
|
239034
|
+
name: tool.name
|
|
238986
239035
|
};
|
|
238987
239036
|
const referenceSignature = {
|
|
238988
239037
|
signature: tool.signatures[0].value,
|
|
@@ -238990,12 +239039,11 @@ class EnactCore {
|
|
|
238990
239039
|
algorithm: tool.signatures[0].algorithm,
|
|
238991
239040
|
timestamp: new Date(tool.signatures[0].created).getTime()
|
|
238992
239041
|
};
|
|
238993
|
-
const canonicalDoc = SigningService.getCanonicalDocument(documentForVerification, { includeFields: ["command"] });
|
|
239042
|
+
const canonicalDoc = SigningService.getCanonicalDocument(documentForVerification, { includeFields: ["command", "description", "from", "name"] });
|
|
238994
239043
|
const docString = JSON.stringify(canonicalDoc);
|
|
238995
239044
|
const messageHash = CryptoUtils.hash(docString);
|
|
238996
239045
|
const directVerify = CryptoUtils.verify(referenceSignature.publicKey, messageHash, referenceSignature.signature);
|
|
238997
|
-
const isValid2 = SigningService.verifyDocument(documentForVerification, referenceSignature, { includeFields: ["command"] });
|
|
238998
|
-
console.log("Final verification result:", isValid2);
|
|
239046
|
+
const isValid2 = SigningService.verifyDocument(documentForVerification, referenceSignature, { includeFields: ["command", "description", "from", "name"] });
|
|
238999
239047
|
if (!isValid2) {
|
|
239000
239048
|
throw new Error(`Tool ${tool.name} has invalid signatures`);
|
|
239001
239049
|
}
|
|
@@ -239025,7 +239073,8 @@ class EnactCore {
|
|
|
239025
239073
|
vars: { ...envVars, ...validatedInputs },
|
|
239026
239074
|
resources: {
|
|
239027
239075
|
timeout: options.timeout || tool.timeout || this.options.defaultTimeout
|
|
239028
|
-
}
|
|
239076
|
+
},
|
|
239077
|
+
mount: options.mount
|
|
239029
239078
|
});
|
|
239030
239079
|
} catch (error) {
|
|
239031
239080
|
return {
|
|
@@ -239181,577 +239230,154 @@ class EnactCore {
|
|
|
239181
239230
|
return `exec_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
239182
239231
|
}
|
|
239183
239232
|
}
|
|
239184
|
-
// ../shared/dist/
|
|
239185
|
-
var
|
|
239186
|
-
|
|
239187
|
-
|
|
239188
|
-
|
|
239189
|
-
|
|
239190
|
-
|
|
239191
|
-
|
|
239192
|
-
|
|
239193
|
-
|
|
239194
|
-
|
|
239195
|
-
|
|
239196
|
-
|
|
239197
|
-
class McpSilentOperationMonitor {
|
|
239198
|
-
getOriginalConsoleError() {
|
|
239199
|
-
return this.originalConsoleError;
|
|
239200
|
-
}
|
|
239201
|
-
constructor() {
|
|
239202
|
-
this.isMonitoring = false;
|
|
239203
|
-
this.violations = [];
|
|
239204
|
-
this.consoleOutput = [];
|
|
239205
|
-
this.processExitAttempts = 0;
|
|
239206
|
-
this.readlineUsageDetected = false;
|
|
239207
|
-
this.startTime = 0;
|
|
239208
|
-
this.originalConsoleLog = console.log;
|
|
239209
|
-
this.originalConsoleError = console.error;
|
|
239210
|
-
this.originalConsoleWarn = console.warn;
|
|
239211
|
-
this.originalConsoleInfo = console.info;
|
|
239212
|
-
this.originalProcessExit = process.exit;
|
|
239213
|
-
this.originalStdoutWrite = process.stdout.write;
|
|
239214
|
-
this.originalStderrWrite = process.stderr.write;
|
|
239233
|
+
// ../shared/dist/LocalToolResolver.js
|
|
239234
|
+
var yaml2 = __toESM(require_dist3(), 1);
|
|
239235
|
+
import { promises as fs5, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
239236
|
+
import { join as join4, resolve, basename as basename2 } from "path";
|
|
239237
|
+
class LocalToolResolver {
|
|
239238
|
+
constructor(enactCore, localToolsDir = "./tools", cacheDir = "./.tool-cache") {
|
|
239239
|
+
this.enactCore = enactCore;
|
|
239240
|
+
this.toolCache = new Map;
|
|
239241
|
+
this.aliases = new Map;
|
|
239242
|
+
this.favorites = new Set;
|
|
239243
|
+
this.localToolsDir = resolve(localToolsDir);
|
|
239244
|
+
this.cacheDir = resolve(cacheDir);
|
|
239245
|
+
this.loadConfiguration();
|
|
239215
239246
|
}
|
|
239216
|
-
|
|
239217
|
-
|
|
239218
|
-
|
|
239247
|
+
async resolveTool(toolName) {
|
|
239248
|
+
const resolvedName = this.aliases.get(toolName) || toolName;
|
|
239249
|
+
const localTool = await this.getLocalTool(resolvedName);
|
|
239250
|
+
if (localTool) {
|
|
239251
|
+
return {
|
|
239252
|
+
tool: localTool,
|
|
239253
|
+
source: "local",
|
|
239254
|
+
metadata: { path: localTool.path }
|
|
239255
|
+
};
|
|
239219
239256
|
}
|
|
239220
|
-
|
|
239221
|
-
this.
|
|
239222
|
-
|
|
239223
|
-
|
|
239224
|
-
|
|
239225
|
-
|
|
239226
|
-
|
|
239227
|
-
|
|
239228
|
-
|
|
239229
|
-
this.
|
|
239230
|
-
|
|
239231
|
-
|
|
239232
|
-
|
|
239233
|
-
|
|
239234
|
-
|
|
239235
|
-
|
|
239236
|
-
|
|
239237
|
-
const message = args.join(" ");
|
|
239238
|
-
this.consoleOutput.push(`[WARN] ${message}`);
|
|
239239
|
-
this.violations.push(`Console.warn called: ${message}`);
|
|
239240
|
-
};
|
|
239241
|
-
console.info = (...args) => {
|
|
239242
|
-
const message = args.join(" ");
|
|
239243
|
-
this.consoleOutput.push(`[INFO] ${message}`);
|
|
239244
|
-
this.violations.push(`Console.info called: ${message}`);
|
|
239245
|
-
};
|
|
239246
|
-
process.exit = (code) => {
|
|
239247
|
-
this.processExitAttempts++;
|
|
239248
|
-
this.violations.push(`Process.exit called with code: ${code}`);
|
|
239249
|
-
throw new Error(`Process exit intercepted: ${code}`);
|
|
239250
|
-
};
|
|
239251
|
-
process.stdout.write = (chunk, ...args) => {
|
|
239252
|
-
if (typeof chunk === "string" && chunk.trim()) {
|
|
239253
|
-
this.consoleOutput.push(`[STDOUT] ${chunk}`);
|
|
239254
|
-
this.violations.push(`Process.stdout.write called: ${chunk.substring(0, 100)}...`);
|
|
239255
|
-
}
|
|
239256
|
-
return true;
|
|
239257
|
-
};
|
|
239258
|
-
process.stderr.write = (chunk, ...args) => {
|
|
239259
|
-
if (typeof chunk === "string" && chunk.trim()) {
|
|
239260
|
-
this.consoleOutput.push(`[STDERR] ${chunk}`);
|
|
239261
|
-
this.violations.push(`Process.stderr.write called: ${chunk.substring(0, 100)}...`);
|
|
239262
|
-
}
|
|
239263
|
-
return true;
|
|
239264
|
-
};
|
|
239265
|
-
const originalRequire = __require;
|
|
239266
|
-
const monitor = this;
|
|
239267
|
-
global.require = function(id) {
|
|
239268
|
-
if (id === "readline" || id.includes("readline")) {
|
|
239269
|
-
monitor.readlineUsageDetected = true;
|
|
239270
|
-
monitor.violations.push("Readline module usage detected");
|
|
239257
|
+
const cachedTool = this.toolCache.get(resolvedName);
|
|
239258
|
+
if (cachedTool && !this.isCacheExpired(cachedTool)) {
|
|
239259
|
+
return {
|
|
239260
|
+
tool: cachedTool,
|
|
239261
|
+
source: "cache",
|
|
239262
|
+
metadata: { cachedAt: cachedTool.lastModified }
|
|
239263
|
+
};
|
|
239264
|
+
}
|
|
239265
|
+
try {
|
|
239266
|
+
const registryTool = await this.enactCore.getToolByName(resolvedName);
|
|
239267
|
+
if (registryTool) {
|
|
239268
|
+
await this.cacheRegistryTool(resolvedName, registryTool);
|
|
239269
|
+
return {
|
|
239270
|
+
tool: registryTool,
|
|
239271
|
+
source: "registry",
|
|
239272
|
+
metadata: { cached: true }
|
|
239273
|
+
};
|
|
239271
239274
|
}
|
|
239272
|
-
|
|
239273
|
-
|
|
239274
|
-
}
|
|
239275
|
-
stopMonitoring() {
|
|
239276
|
-
if (!this.isMonitoring) {
|
|
239277
|
-
throw new Error("Monitor is not currently running");
|
|
239275
|
+
} catch (error) {
|
|
239276
|
+
logger_default.debug(`Registry lookup failed for ${resolvedName}:`, error);
|
|
239278
239277
|
}
|
|
239279
|
-
|
|
239280
|
-
console.error = this.originalConsoleError;
|
|
239281
|
-
console.warn = this.originalConsoleWarn;
|
|
239282
|
-
console.info = this.originalConsoleInfo;
|
|
239283
|
-
process.exit = this.originalProcessExit;
|
|
239284
|
-
process.stdout.write = this.originalStdoutWrite;
|
|
239285
|
-
process.stderr.write = this.originalStderrWrite;
|
|
239286
|
-
global.require = __require;
|
|
239287
|
-
this.isMonitoring = false;
|
|
239288
|
-
return {
|
|
239289
|
-
violations: [...this.violations],
|
|
239290
|
-
consoleOutputDetected: [...this.consoleOutput],
|
|
239291
|
-
processExitAttempts: this.processExitAttempts,
|
|
239292
|
-
readlineUsageDetected: this.readlineUsageDetected,
|
|
239293
|
-
duration: Date.now() - this.startTime,
|
|
239294
|
-
timestamp: new Date().toISOString()
|
|
239295
|
-
};
|
|
239278
|
+
return null;
|
|
239296
239279
|
}
|
|
239297
|
-
|
|
239298
|
-
|
|
239280
|
+
async getLocalTool(toolName) {
|
|
239281
|
+
const possiblePaths = [
|
|
239282
|
+
join4(this.localToolsDir, `${toolName}.yaml`),
|
|
239283
|
+
join4(this.localToolsDir, `${toolName}.yml`),
|
|
239284
|
+
join4(this.localToolsDir, toolName, "tool.yaml"),
|
|
239285
|
+
join4(this.localToolsDir, toolName, "tool.yml"),
|
|
239286
|
+
join4(this.localToolsDir, toolName, `${toolName}.yaml`),
|
|
239287
|
+
join4(this.localToolsDir, toolName, `${toolName}.yml`)
|
|
239288
|
+
];
|
|
239289
|
+
for (const toolPath of possiblePaths) {
|
|
239290
|
+
try {
|
|
239291
|
+
const stats = await fs5.stat(toolPath);
|
|
239292
|
+
const content = await fs5.readFile(toolPath, "utf-8");
|
|
239293
|
+
const definition = yaml2.parse(content);
|
|
239294
|
+
if (definition && (definition.name === toolName || definition.name === undefined)) {
|
|
239295
|
+
return {
|
|
239296
|
+
name: definition.name || toolName,
|
|
239297
|
+
path: toolPath,
|
|
239298
|
+
definition,
|
|
239299
|
+
lastModified: stats.mtime,
|
|
239300
|
+
cached: false
|
|
239301
|
+
};
|
|
239302
|
+
}
|
|
239303
|
+
} catch (error) {
|
|
239304
|
+
continue;
|
|
239305
|
+
}
|
|
239306
|
+
}
|
|
239307
|
+
return null;
|
|
239299
239308
|
}
|
|
239300
|
-
|
|
239301
|
-
|
|
239309
|
+
async cacheRegistryTool(toolName, tool) {
|
|
239310
|
+
try {
|
|
239311
|
+
await fs5.mkdir(this.cacheDir, { recursive: true });
|
|
239312
|
+
const cachePath = join4(this.cacheDir, `${toolName}.yaml`);
|
|
239313
|
+
const cacheData = {
|
|
239314
|
+
...tool,
|
|
239315
|
+
_cached: true,
|
|
239316
|
+
_cachedAt: new Date().toISOString(),
|
|
239317
|
+
_source: "registry"
|
|
239318
|
+
};
|
|
239319
|
+
await fs5.writeFile(cachePath, yaml2.stringify(cacheData));
|
|
239320
|
+
this.toolCache.set(toolName, {
|
|
239321
|
+
name: toolName,
|
|
239322
|
+
path: cachePath,
|
|
239323
|
+
definition: tool,
|
|
239324
|
+
lastModified: new Date,
|
|
239325
|
+
cached: true
|
|
239326
|
+
});
|
|
239327
|
+
logger_default.debug(`Cached registry tool: ${toolName}`);
|
|
239328
|
+
} catch (error) {
|
|
239329
|
+
logger_default.warn(`Failed to cache tool ${toolName}:`, error);
|
|
239330
|
+
}
|
|
239302
239331
|
}
|
|
239303
|
-
|
|
239304
|
-
|
|
239305
|
-
function validateSilentEnvironment() {
|
|
239306
|
-
const issues = [];
|
|
239307
|
-
if (process.env.CI !== "true") {
|
|
239308
|
-
issues.push('CI environment variable not set to "true"');
|
|
239332
|
+
isCacheExpired(tool, maxAge = 24 * 60 * 60 * 1000) {
|
|
239333
|
+
return Date.now() - tool.lastModified.getTime() > maxAge;
|
|
239309
239334
|
}
|
|
239310
|
-
|
|
239311
|
-
|
|
239335
|
+
async listAllTools() {
|
|
239336
|
+
const localTools = await this.scanLocalTools();
|
|
239337
|
+
const cachedTools = Array.from(this.toolCache.values());
|
|
239338
|
+
return {
|
|
239339
|
+
local: localTools,
|
|
239340
|
+
cached: cachedTools,
|
|
239341
|
+
favorites: Array.from(this.favorites),
|
|
239342
|
+
aliases: Object.fromEntries(this.aliases)
|
|
239343
|
+
};
|
|
239312
239344
|
}
|
|
239313
|
-
|
|
239314
|
-
|
|
239315
|
-
|
|
239316
|
-
|
|
239317
|
-
|
|
239318
|
-
|
|
239319
|
-
|
|
239320
|
-
|
|
239321
|
-
|
|
239322
|
-
|
|
239323
|
-
|
|
239324
|
-
|
|
239325
|
-
|
|
239326
|
-
|
|
239327
|
-
|
|
239328
|
-
|
|
239329
|
-
|
|
239330
|
-
|
|
239331
|
-
|
|
239332
|
-
|
|
239333
|
-
|
|
239334
|
-
|
|
239335
|
-
|
|
239336
|
-
|
|
239337
|
-
|
|
239338
|
-
|
|
239339
|
-
|
|
239340
|
-
|
|
239341
|
-
|
|
239342
|
-
join4(__dirname3, "..", "src", "web", "static"),
|
|
239343
|
-
join4(__dirname3, "..", "..", "src", "web", "static"),
|
|
239344
|
-
join4(process.cwd(), "src", "web", "static"),
|
|
239345
|
-
join4(__dirname3, "..", "..", "..", "src", "web", "static"),
|
|
239346
|
-
join4(__dirname3, "..", "..", "src", "web", "static")
|
|
239347
|
-
];
|
|
239348
|
-
for (const candidate of candidates) {
|
|
239349
|
-
if (existsSync4(join4(candidate, "index.html"))) {
|
|
239350
|
-
logger_default.debug(`Found static directory: ${candidate}`);
|
|
239351
|
-
return candidate;
|
|
239352
|
-
}
|
|
239353
|
-
}
|
|
239354
|
-
throw new Error("Could not find static directory. Tried: " + candidates.join(", "));
|
|
239355
|
-
}
|
|
239356
|
-
var STATIC_DIR = findStaticDir();
|
|
239357
|
-
function parseDotEnv(content) {
|
|
239358
|
-
const vars = {};
|
|
239359
|
-
const lines = content.split(`
|
|
239360
|
-
`);
|
|
239361
|
-
for (const line of lines) {
|
|
239362
|
-
const trimmed = line.trim();
|
|
239363
|
-
if (!trimmed || trimmed.startsWith("#")) {
|
|
239364
|
-
continue;
|
|
239365
|
-
}
|
|
239366
|
-
const equalIndex = trimmed.indexOf("=");
|
|
239367
|
-
if (equalIndex === -1) {
|
|
239368
|
-
continue;
|
|
239369
|
-
}
|
|
239370
|
-
const key = trimmed.slice(0, equalIndex).trim();
|
|
239371
|
-
let value = trimmed.slice(equalIndex + 1).trim();
|
|
239372
|
-
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
239373
|
-
value = value.slice(1, -1);
|
|
239374
|
-
}
|
|
239375
|
-
if (key) {
|
|
239376
|
-
vars[key] = value;
|
|
239377
|
-
}
|
|
239378
|
-
}
|
|
239379
|
-
return vars;
|
|
239380
|
-
}
|
|
239381
|
-
function generateDotEnv(vars) {
|
|
239382
|
-
return Object.entries(vars).map(([key, value]) => {
|
|
239383
|
-
const needsQuotes = value.includes(" ") || value.includes("\t") || value.includes(`
|
|
239384
|
-
`) || value.includes('"');
|
|
239385
|
-
const escapedValue = needsQuotes ? `"${value.replace(/"/g, "\\\"")}"` : value;
|
|
239386
|
-
return `${key}=${escapedValue}`;
|
|
239387
|
-
}).join(`
|
|
239388
|
-
`) + `
|
|
239389
|
-
`;
|
|
239390
|
-
}
|
|
239391
|
-
async function getAllPackageNamespaces() {
|
|
239392
|
-
const packages = [];
|
|
239393
|
-
if (!existsSync4(ENV_BASE_DIR)) {
|
|
239394
|
-
return packages;
|
|
239395
|
-
}
|
|
239396
|
-
try {
|
|
239397
|
-
await scanDirectory(ENV_BASE_DIR, "", packages);
|
|
239398
|
-
} catch (error) {
|
|
239399
|
-
logger_default.error("Failed to scan env directory:", error);
|
|
239400
|
-
}
|
|
239401
|
-
return packages;
|
|
239402
|
-
}
|
|
239403
|
-
async function scanDirectory(dir, relativePath, packages) {
|
|
239404
|
-
try {
|
|
239405
|
-
const entries = await readdir(dir);
|
|
239406
|
-
for (const entry of entries) {
|
|
239407
|
-
const fullPath = join4(dir, entry);
|
|
239408
|
-
const stats = await stat2(fullPath);
|
|
239409
|
-
if (stats.isDirectory()) {
|
|
239410
|
-
const newRelativePath = relativePath ? `${relativePath}/${entry}` : entry;
|
|
239411
|
-
await scanDirectory(fullPath, newRelativePath, packages);
|
|
239412
|
-
} else if (entry === ".env") {
|
|
239413
|
-
const namespace = relativePath || "root";
|
|
239414
|
-
try {
|
|
239415
|
-
const content = await readFile3(fullPath, "utf8");
|
|
239416
|
-
const variables = parseDotEnv(content);
|
|
239417
|
-
packages.push({
|
|
239418
|
-
namespace,
|
|
239419
|
-
path: fullPath,
|
|
239420
|
-
variables
|
|
239421
|
-
});
|
|
239422
|
-
} catch (error) {
|
|
239423
|
-
logger_default.error(`Failed to read .env file at ${fullPath}:`, error);
|
|
239424
|
-
}
|
|
239425
|
-
}
|
|
239426
|
-
}
|
|
239427
|
-
} catch (error) {
|
|
239428
|
-
logger_default.error(`Failed to scan directory ${dir}:`, error);
|
|
239429
|
-
}
|
|
239430
|
-
}
|
|
239431
|
-
async function getPackageEnvVars(namespace) {
|
|
239432
|
-
const envFile = join4(ENV_BASE_DIR, namespace, ".env");
|
|
239433
|
-
if (!existsSync4(envFile)) {
|
|
239434
|
-
return {};
|
|
239435
|
-
}
|
|
239436
|
-
try {
|
|
239437
|
-
const content = await readFile3(envFile, "utf8");
|
|
239438
|
-
return parseDotEnv(content);
|
|
239439
|
-
} catch (error) {
|
|
239440
|
-
logger_default.error(`Failed to read env file for ${namespace}:`, error);
|
|
239441
|
-
return {};
|
|
239442
|
-
}
|
|
239443
|
-
}
|
|
239444
|
-
async function setPackageEnvVar(namespace, key, value) {
|
|
239445
|
-
const envFile = join4(ENV_BASE_DIR, namespace, ".env");
|
|
239446
|
-
const envDir = dirname3(envFile);
|
|
239447
|
-
if (!existsSync4(envDir)) {
|
|
239448
|
-
await mkdir2(envDir, { recursive: true });
|
|
239449
|
-
}
|
|
239450
|
-
const existingVars = await getPackageEnvVars(namespace);
|
|
239451
|
-
existingVars[key] = value;
|
|
239452
|
-
const envContent = generateDotEnv(existingVars);
|
|
239453
|
-
await writeFile2(envFile, envContent, "utf8");
|
|
239454
|
-
}
|
|
239455
|
-
async function deletePackageEnvVar(namespace, key) {
|
|
239456
|
-
const existingVars = await getPackageEnvVars(namespace);
|
|
239457
|
-
if (!(key in existingVars)) {
|
|
239458
|
-
throw new Error(`Environment variable '${key}' not found in package '${namespace}'`);
|
|
239459
|
-
}
|
|
239460
|
-
delete existingVars[key];
|
|
239461
|
-
const envFile = join4(ENV_BASE_DIR, namespace, ".env");
|
|
239462
|
-
const envContent = generateDotEnv(existingVars);
|
|
239463
|
-
await writeFile2(envFile, envContent, "utf8");
|
|
239464
|
-
}
|
|
239465
|
-
async function serveStaticFile(filePath, res) {
|
|
239466
|
-
try {
|
|
239467
|
-
const content = await readFile3(filePath, "utf8");
|
|
239468
|
-
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
239469
|
-
let contentType = "text/plain";
|
|
239470
|
-
switch (ext) {
|
|
239471
|
-
case "html":
|
|
239472
|
-
contentType = "text/html";
|
|
239473
|
-
break;
|
|
239474
|
-
case "css":
|
|
239475
|
-
contentType = "text/css";
|
|
239476
|
-
break;
|
|
239477
|
-
case "js":
|
|
239478
|
-
contentType = "application/javascript";
|
|
239479
|
-
break;
|
|
239480
|
-
case "json":
|
|
239481
|
-
contentType = "application/json";
|
|
239482
|
-
break;
|
|
239483
|
-
}
|
|
239484
|
-
res.writeHead(200, { "Content-Type": contentType });
|
|
239485
|
-
res.end(content);
|
|
239486
|
-
} catch (error) {
|
|
239487
|
-
logger_default.error("Error serving static file:", error);
|
|
239488
|
-
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
239489
|
-
res.end("File not found");
|
|
239490
|
-
}
|
|
239491
|
-
}
|
|
239492
|
-
async function handleRequest(req, res) {
|
|
239493
|
-
const urlParts = parse3(req.url || "", true);
|
|
239494
|
-
const pathname = urlParts.pathname || "/";
|
|
239495
|
-
const method = req.method || "GET";
|
|
239496
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
239497
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
239498
|
-
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
239499
|
-
if (method === "OPTIONS") {
|
|
239500
|
-
res.writeHead(200);
|
|
239501
|
-
res.end();
|
|
239502
|
-
return;
|
|
239503
|
-
}
|
|
239504
|
-
try {
|
|
239505
|
-
if (pathname === "/") {
|
|
239506
|
-
await serveStaticFile(join4(STATIC_DIR, "index.html"), res);
|
|
239507
|
-
} else if (pathname === "/style.css") {
|
|
239508
|
-
await serveStaticFile(join4(STATIC_DIR, "style.css"), res);
|
|
239509
|
-
} else if (pathname === "/app.js") {
|
|
239510
|
-
await serveStaticFile(join4(STATIC_DIR, "app.js"), res);
|
|
239511
|
-
} else if (pathname === "/favicon.ico") {
|
|
239512
|
-
const favicon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">\uD83C\uDF10</text></svg>`;
|
|
239513
|
-
res.writeHead(200, { "Content-Type": "image/svg+xml" });
|
|
239514
|
-
res.end(favicon);
|
|
239515
|
-
} else if (pathname === "/api/packages" && method === "GET") {
|
|
239516
|
-
const packages = await getAllPackageNamespaces();
|
|
239517
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
239518
|
-
res.end(JSON.stringify({ packages }));
|
|
239519
|
-
} else if (pathname === "/api/packages" && method === "POST") {
|
|
239520
|
-
const body = await getRequestBody(req);
|
|
239521
|
-
const { namespace } = JSON.parse(body);
|
|
239522
|
-
if (!namespace) {
|
|
239523
|
-
res.writeHead(400, { "Content-Type": "application/json" });
|
|
239524
|
-
res.end(JSON.stringify({ error: "Namespace is required" }));
|
|
239525
|
-
return;
|
|
239526
|
-
}
|
|
239527
|
-
const envDir = join4(ENV_BASE_DIR, namespace);
|
|
239528
|
-
const envFile = join4(envDir, ".env");
|
|
239529
|
-
if (!existsSync4(envDir)) {
|
|
239530
|
-
await mkdir2(envDir, { recursive: true });
|
|
239531
|
-
}
|
|
239532
|
-
if (!existsSync4(envFile)) {
|
|
239533
|
-
await writeFile2(envFile, "", "utf8");
|
|
239534
|
-
}
|
|
239535
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
239536
|
-
res.end(JSON.stringify({ success: true }));
|
|
239537
|
-
} else if (pathname?.startsWith("/api/packages/") && method === "GET") {
|
|
239538
|
-
const namespace = decodeURIComponent(pathname.replace("/api/packages/", ""));
|
|
239539
|
-
const variables = await getPackageEnvVars(namespace);
|
|
239540
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
239541
|
-
res.end(JSON.stringify({ namespace, variables }));
|
|
239542
|
-
} else if (pathname?.startsWith("/api/packages/") && pathname.endsWith("/variables") && method === "POST") {
|
|
239543
|
-
const namespace = decodeURIComponent(pathname.replace("/api/packages/", "").replace("/variables", ""));
|
|
239544
|
-
const body = await getRequestBody(req);
|
|
239545
|
-
const { key, value } = JSON.parse(body);
|
|
239546
|
-
if (!key || value === undefined) {
|
|
239547
|
-
res.writeHead(400, { "Content-Type": "application/json" });
|
|
239548
|
-
res.end(JSON.stringify({ error: "Key and value are required" }));
|
|
239549
|
-
return;
|
|
239550
|
-
}
|
|
239551
|
-
await setPackageEnvVar(namespace, key, value);
|
|
239552
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
239553
|
-
res.end(JSON.stringify({ success: true }));
|
|
239554
|
-
} else if (pathname?.includes("/variables/") && method === "DELETE") {
|
|
239555
|
-
const pathParts = pathname.split("/");
|
|
239556
|
-
const variableIndex = pathParts.indexOf("variables");
|
|
239557
|
-
const namespace = decodeURIComponent(pathParts.slice(3, variableIndex).join("/"));
|
|
239558
|
-
const key = decodeURIComponent(pathParts[variableIndex + 1]);
|
|
239559
|
-
await deletePackageEnvVar(namespace, key);
|
|
239560
|
-
res.writeHead(200, { "Content-Type": "application/json" });
|
|
239561
|
-
res.end(JSON.stringify({ success: true }));
|
|
239562
|
-
} else {
|
|
239563
|
-
res.writeHead(404, { "Content-Type": "application/json" });
|
|
239564
|
-
res.end(JSON.stringify({ error: "Not found" }));
|
|
239565
|
-
}
|
|
239566
|
-
} catch (error) {
|
|
239567
|
-
logger_default.error("Web server error:", error);
|
|
239568
|
-
res.writeHead(500, { "Content-Type": "application/json" });
|
|
239569
|
-
res.end(JSON.stringify({
|
|
239570
|
-
error: error instanceof Error ? error.message : "Internal server error"
|
|
239571
|
-
}));
|
|
239572
|
-
}
|
|
239573
|
-
}
|
|
239574
|
-
function getRequestBody(req) {
|
|
239575
|
-
return new Promise((resolve, reject) => {
|
|
239576
|
-
let body = "";
|
|
239577
|
-
req.on("data", (chunk) => {
|
|
239578
|
-
body += chunk.toString();
|
|
239579
|
-
});
|
|
239580
|
-
req.on("end", () => {
|
|
239581
|
-
resolve(body);
|
|
239582
|
-
});
|
|
239583
|
-
req.on("error", reject);
|
|
239584
|
-
});
|
|
239585
|
-
}
|
|
239586
|
-
function startEnvManagerServer(port = 5555) {
|
|
239587
|
-
return new Promise((resolve, reject) => {
|
|
239588
|
-
const server2 = createServer(handleRequest);
|
|
239589
|
-
server2.listen(port, () => {
|
|
239590
|
-
const actualPort = server2.address()?.port || port;
|
|
239591
|
-
logger_default.info(`\uD83C\uDF10 Environment Manager web server started on http://localhost:${actualPort}`);
|
|
239592
|
-
resolve({ server: server2, port: actualPort });
|
|
239593
|
-
});
|
|
239594
|
-
server2.on("error", (error) => {
|
|
239595
|
-
if (error.code === "EADDRINUSE") {
|
|
239596
|
-
server2.listen(0, () => {
|
|
239597
|
-
const actualPort = server2.address()?.port;
|
|
239598
|
-
logger_default.info(`\uD83C\uDF10 Environment Manager web server started on http://localhost:${actualPort} (port ${port} was in use)`);
|
|
239599
|
-
resolve({ server: server2, port: actualPort });
|
|
239600
|
-
});
|
|
239601
|
-
} else {
|
|
239602
|
-
reject(error);
|
|
239603
|
-
}
|
|
239604
|
-
});
|
|
239605
|
-
});
|
|
239606
|
-
}
|
|
239607
|
-
// ../shared/dist/LocalToolResolver.js
|
|
239608
|
-
var yaml2 = __toESM(require_dist3(), 1);
|
|
239609
|
-
import { promises as fs5, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
239610
|
-
import { join as join5, resolve, basename as basename2 } from "path";
|
|
239611
|
-
class LocalToolResolver {
|
|
239612
|
-
constructor(enactCore, localToolsDir = "./tools", cacheDir = "./.tool-cache") {
|
|
239613
|
-
this.enactCore = enactCore;
|
|
239614
|
-
this.toolCache = new Map;
|
|
239615
|
-
this.aliases = new Map;
|
|
239616
|
-
this.favorites = new Set;
|
|
239617
|
-
this.localToolsDir = resolve(localToolsDir);
|
|
239618
|
-
this.cacheDir = resolve(cacheDir);
|
|
239619
|
-
this.loadConfiguration();
|
|
239620
|
-
}
|
|
239621
|
-
async resolveTool(toolName) {
|
|
239622
|
-
const resolvedName = this.aliases.get(toolName) || toolName;
|
|
239623
|
-
const localTool = await this.getLocalTool(resolvedName);
|
|
239624
|
-
if (localTool) {
|
|
239625
|
-
return {
|
|
239626
|
-
tool: localTool,
|
|
239627
|
-
source: "local",
|
|
239628
|
-
metadata: { path: localTool.path }
|
|
239629
|
-
};
|
|
239630
|
-
}
|
|
239631
|
-
const cachedTool = this.toolCache.get(resolvedName);
|
|
239632
|
-
if (cachedTool && !this.isCacheExpired(cachedTool)) {
|
|
239633
|
-
return {
|
|
239634
|
-
tool: cachedTool,
|
|
239635
|
-
source: "cache",
|
|
239636
|
-
metadata: { cachedAt: cachedTool.lastModified }
|
|
239637
|
-
};
|
|
239638
|
-
}
|
|
239639
|
-
try {
|
|
239640
|
-
const registryTool = await this.enactCore.getToolByName(resolvedName);
|
|
239641
|
-
if (registryTool) {
|
|
239642
|
-
await this.cacheRegistryTool(resolvedName, registryTool);
|
|
239643
|
-
return {
|
|
239644
|
-
tool: registryTool,
|
|
239645
|
-
source: "registry",
|
|
239646
|
-
metadata: { cached: true }
|
|
239647
|
-
};
|
|
239648
|
-
}
|
|
239649
|
-
} catch (error) {
|
|
239650
|
-
logger_default.debug(`Registry lookup failed for ${resolvedName}:`, error);
|
|
239651
|
-
}
|
|
239652
|
-
return null;
|
|
239653
|
-
}
|
|
239654
|
-
async getLocalTool(toolName) {
|
|
239655
|
-
const possiblePaths = [
|
|
239656
|
-
join5(this.localToolsDir, `${toolName}.yaml`),
|
|
239657
|
-
join5(this.localToolsDir, `${toolName}.yml`),
|
|
239658
|
-
join5(this.localToolsDir, toolName, "tool.yaml"),
|
|
239659
|
-
join5(this.localToolsDir, toolName, "tool.yml"),
|
|
239660
|
-
join5(this.localToolsDir, toolName, `${toolName}.yaml`),
|
|
239661
|
-
join5(this.localToolsDir, toolName, `${toolName}.yml`)
|
|
239662
|
-
];
|
|
239663
|
-
for (const toolPath of possiblePaths) {
|
|
239664
|
-
try {
|
|
239665
|
-
const stats = await fs5.stat(toolPath);
|
|
239666
|
-
const content = await fs5.readFile(toolPath, "utf-8");
|
|
239667
|
-
const definition = yaml2.parse(content);
|
|
239668
|
-
if (definition && (definition.name === toolName || definition.name === undefined)) {
|
|
239669
|
-
return {
|
|
239670
|
-
name: definition.name || toolName,
|
|
239671
|
-
path: toolPath,
|
|
239672
|
-
definition,
|
|
239673
|
-
lastModified: stats.mtime,
|
|
239674
|
-
cached: false
|
|
239675
|
-
};
|
|
239676
|
-
}
|
|
239677
|
-
} catch (error) {
|
|
239678
|
-
continue;
|
|
239679
|
-
}
|
|
239680
|
-
}
|
|
239681
|
-
return null;
|
|
239682
|
-
}
|
|
239683
|
-
async cacheRegistryTool(toolName, tool) {
|
|
239684
|
-
try {
|
|
239685
|
-
await fs5.mkdir(this.cacheDir, { recursive: true });
|
|
239686
|
-
const cachePath = join5(this.cacheDir, `${toolName}.yaml`);
|
|
239687
|
-
const cacheData = {
|
|
239688
|
-
...tool,
|
|
239689
|
-
_cached: true,
|
|
239690
|
-
_cachedAt: new Date().toISOString(),
|
|
239691
|
-
_source: "registry"
|
|
239692
|
-
};
|
|
239693
|
-
await fs5.writeFile(cachePath, yaml2.stringify(cacheData));
|
|
239694
|
-
this.toolCache.set(toolName, {
|
|
239695
|
-
name: toolName,
|
|
239696
|
-
path: cachePath,
|
|
239697
|
-
definition: tool,
|
|
239698
|
-
lastModified: new Date,
|
|
239699
|
-
cached: true
|
|
239700
|
-
});
|
|
239701
|
-
logger_default.debug(`Cached registry tool: ${toolName}`);
|
|
239702
|
-
} catch (error) {
|
|
239703
|
-
logger_default.warn(`Failed to cache tool ${toolName}:`, error);
|
|
239704
|
-
}
|
|
239705
|
-
}
|
|
239706
|
-
isCacheExpired(tool, maxAge = 24 * 60 * 60 * 1000) {
|
|
239707
|
-
return Date.now() - tool.lastModified.getTime() > maxAge;
|
|
239708
|
-
}
|
|
239709
|
-
async listAllTools() {
|
|
239710
|
-
const localTools = await this.scanLocalTools();
|
|
239711
|
-
const cachedTools = Array.from(this.toolCache.values());
|
|
239712
|
-
return {
|
|
239713
|
-
local: localTools,
|
|
239714
|
-
cached: cachedTools,
|
|
239715
|
-
favorites: Array.from(this.favorites),
|
|
239716
|
-
aliases: Object.fromEntries(this.aliases)
|
|
239717
|
-
};
|
|
239718
|
-
}
|
|
239719
|
-
async scanLocalTools() {
|
|
239720
|
-
const tools = [];
|
|
239721
|
-
try {
|
|
239722
|
-
await fs5.mkdir(this.localToolsDir, { recursive: true });
|
|
239723
|
-
const entries = await this.scanDirectory(this.localToolsDir);
|
|
239724
|
-
for (const entry of entries) {
|
|
239725
|
-
if (entry.endsWith(".yaml") || entry.endsWith(".yml")) {
|
|
239726
|
-
try {
|
|
239727
|
-
const content = await fs5.readFile(entry, "utf-8");
|
|
239728
|
-
const definition = yaml2.parse(content);
|
|
239729
|
-
if (definition && (definition.name || definition.command)) {
|
|
239730
|
-
const stats = await fs5.stat(entry);
|
|
239731
|
-
tools.push({
|
|
239732
|
-
name: definition.name || basename2(entry, ".yaml").replace(".yml", ""),
|
|
239733
|
-
path: entry,
|
|
239734
|
-
definition,
|
|
239735
|
-
lastModified: stats.mtime,
|
|
239736
|
-
cached: false
|
|
239737
|
-
});
|
|
239738
|
-
}
|
|
239739
|
-
} catch (error) {
|
|
239740
|
-
logger_default.debug(`Skipping invalid tool file ${entry}:`, error);
|
|
239741
|
-
}
|
|
239742
|
-
}
|
|
239743
|
-
}
|
|
239744
|
-
} catch (error) {
|
|
239745
|
-
logger_default.warn(`Failed to scan local tools directory:`, error);
|
|
239746
|
-
}
|
|
239747
|
-
return tools;
|
|
239345
|
+
async scanLocalTools() {
|
|
239346
|
+
const tools = [];
|
|
239347
|
+
try {
|
|
239348
|
+
await fs5.mkdir(this.localToolsDir, { recursive: true });
|
|
239349
|
+
const entries = await this.scanDirectory(this.localToolsDir);
|
|
239350
|
+
for (const entry of entries) {
|
|
239351
|
+
if (entry.endsWith(".yaml") || entry.endsWith(".yml")) {
|
|
239352
|
+
try {
|
|
239353
|
+
const content = await fs5.readFile(entry, "utf-8");
|
|
239354
|
+
const definition = yaml2.parse(content);
|
|
239355
|
+
if (definition && (definition.name || definition.command)) {
|
|
239356
|
+
const stats = await fs5.stat(entry);
|
|
239357
|
+
tools.push({
|
|
239358
|
+
name: definition.name || basename2(entry, ".yaml").replace(".yml", ""),
|
|
239359
|
+
path: entry,
|
|
239360
|
+
definition,
|
|
239361
|
+
lastModified: stats.mtime,
|
|
239362
|
+
cached: false
|
|
239363
|
+
});
|
|
239364
|
+
}
|
|
239365
|
+
} catch (error) {
|
|
239366
|
+
logger_default.debug(`Skipping invalid tool file ${entry}:`, error);
|
|
239367
|
+
}
|
|
239368
|
+
}
|
|
239369
|
+
}
|
|
239370
|
+
} catch (error) {
|
|
239371
|
+
logger_default.warn(`Failed to scan local tools directory:`, error);
|
|
239372
|
+
}
|
|
239373
|
+
return tools;
|
|
239748
239374
|
}
|
|
239749
239375
|
async scanDirectory(dir) {
|
|
239750
239376
|
const files = [];
|
|
239751
239377
|
try {
|
|
239752
239378
|
const entries = await fs5.readdir(dir, { withFileTypes: true });
|
|
239753
239379
|
for (const entry of entries) {
|
|
239754
|
-
const fullPath =
|
|
239380
|
+
const fullPath = join4(dir, entry.name);
|
|
239755
239381
|
if (entry.isDirectory()) {
|
|
239756
239382
|
const subFiles = await this.scanDirectory(fullPath);
|
|
239757
239383
|
files.push(...subFiles);
|
|
@@ -239810,13 +239436,13 @@ class LocalToolResolver {
|
|
|
239810
239436
|
}
|
|
239811
239437
|
loadConfiguration() {
|
|
239812
239438
|
try {
|
|
239813
|
-
const configPath =
|
|
239814
|
-
const
|
|
239815
|
-
if (
|
|
239816
|
-
this.aliases = new Map(Object.entries(
|
|
239439
|
+
const configPath = join4(this.localToolsDir, "config.json");
|
|
239440
|
+
const config = JSON.parse(readFileSync3(configPath, "utf-8"));
|
|
239441
|
+
if (config.aliases) {
|
|
239442
|
+
this.aliases = new Map(Object.entries(config.aliases));
|
|
239817
239443
|
}
|
|
239818
|
-
if (
|
|
239819
|
-
this.favorites = new Set(
|
|
239444
|
+
if (config.favorites) {
|
|
239445
|
+
this.favorites = new Set(config.favorites);
|
|
239820
239446
|
}
|
|
239821
239447
|
} catch (error) {
|
|
239822
239448
|
logger_default.debug("No tool configuration found, using defaults");
|
|
@@ -239824,13 +239450,13 @@ class LocalToolResolver {
|
|
|
239824
239450
|
}
|
|
239825
239451
|
saveConfiguration() {
|
|
239826
239452
|
try {
|
|
239827
|
-
const configPath =
|
|
239828
|
-
const
|
|
239453
|
+
const configPath = join4(this.localToolsDir, "config.json");
|
|
239454
|
+
const config = {
|
|
239829
239455
|
aliases: Object.fromEntries(this.aliases),
|
|
239830
239456
|
favorites: Array.from(this.favorites),
|
|
239831
239457
|
lastUpdated: new Date().toISOString()
|
|
239832
239458
|
};
|
|
239833
|
-
writeFileSync(configPath, JSON.stringify(
|
|
239459
|
+
writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
239834
239460
|
} catch (error) {
|
|
239835
239461
|
logger_default.warn("Failed to save tool configuration:", error);
|
|
239836
239462
|
}
|
|
@@ -239854,11 +239480,11 @@ class LocalToolResolver {
|
|
|
239854
239480
|
}
|
|
239855
239481
|
}
|
|
239856
239482
|
};
|
|
239857
|
-
const samplePath =
|
|
239483
|
+
const samplePath = join4(this.localToolsDir, "hello-world.yaml");
|
|
239858
239484
|
await fs5.writeFile(samplePath, yaml2.stringify(sampleTool));
|
|
239859
239485
|
logger_default.info(`Created sample tool at ${samplePath}`);
|
|
239860
239486
|
}
|
|
239861
|
-
const readmePath =
|
|
239487
|
+
const readmePath = join4(this.localToolsDir, "README.md");
|
|
239862
239488
|
const readme = `# Local Tools Directory
|
|
239863
239489
|
|
|
239864
239490
|
This directory contains your local Enact tools. Tools can be organized as:
|
|
@@ -239890,6 +239516,148 @@ Use the MCP tools to manage this directory programmatically.
|
|
|
239890
239516
|
}
|
|
239891
239517
|
}
|
|
239892
239518
|
var LocalToolResolver_default = LocalToolResolver;
|
|
239519
|
+
// ../shared/dist/utils/help.js
|
|
239520
|
+
var __dirname = "/Users/keithgroves/projects/enact/enact-cli/packages/shared/dist/utils";
|
|
239521
|
+
// ../shared/dist/utils/version.js
|
|
239522
|
+
var __filename = "/Users/keithgroves/projects/enact/enact-cli/packages/shared/dist/utils/version.js";
|
|
239523
|
+
// ../shared/dist/utils/logger.js
|
|
239524
|
+
var LogLevel;
|
|
239525
|
+
(function(LogLevel2) {
|
|
239526
|
+
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
239527
|
+
LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
|
|
239528
|
+
LogLevel2[LogLevel2["SUCCESS"] = 2] = "SUCCESS";
|
|
239529
|
+
LogLevel2[LogLevel2["WARN"] = 3] = "WARN";
|
|
239530
|
+
LogLevel2[LogLevel2["ERROR"] = 4] = "ERROR";
|
|
239531
|
+
})(LogLevel || (LogLevel = {}));
|
|
239532
|
+
var currentLogLevel = LogLevel.INFO;
|
|
239533
|
+
// ../shared/dist/utils/silent-monitor.js
|
|
239534
|
+
class McpSilentOperationMonitor {
|
|
239535
|
+
getOriginalConsoleError() {
|
|
239536
|
+
return this.originalConsoleError;
|
|
239537
|
+
}
|
|
239538
|
+
constructor() {
|
|
239539
|
+
this.isMonitoring = false;
|
|
239540
|
+
this.violations = [];
|
|
239541
|
+
this.consoleOutput = [];
|
|
239542
|
+
this.processExitAttempts = 0;
|
|
239543
|
+
this.readlineUsageDetected = false;
|
|
239544
|
+
this.startTime = 0;
|
|
239545
|
+
this.originalConsoleLog = console.log;
|
|
239546
|
+
this.originalConsoleError = console.error;
|
|
239547
|
+
this.originalConsoleWarn = console.warn;
|
|
239548
|
+
this.originalConsoleInfo = console.info;
|
|
239549
|
+
this.originalProcessExit = process.exit;
|
|
239550
|
+
this.originalStdoutWrite = process.stdout.write;
|
|
239551
|
+
this.originalStderrWrite = process.stderr.write;
|
|
239552
|
+
}
|
|
239553
|
+
startMonitoring() {
|
|
239554
|
+
if (this.isMonitoring) {
|
|
239555
|
+
return;
|
|
239556
|
+
}
|
|
239557
|
+
this.isMonitoring = true;
|
|
239558
|
+
this.violations = [];
|
|
239559
|
+
this.consoleOutput = [];
|
|
239560
|
+
this.processExitAttempts = 0;
|
|
239561
|
+
this.readlineUsageDetected = false;
|
|
239562
|
+
this.startTime = Date.now();
|
|
239563
|
+
console.log = (...args) => {
|
|
239564
|
+
const message = args.join(" ");
|
|
239565
|
+
this.consoleOutput.push(`[LOG] ${message}`);
|
|
239566
|
+
this.violations.push(`Console.log called: ${message}`);
|
|
239567
|
+
};
|
|
239568
|
+
console.error = (...args) => {
|
|
239569
|
+
const message = args.join(" ");
|
|
239570
|
+
this.consoleOutput.push(`[ERROR] ${message}`);
|
|
239571
|
+
this.violations.push(`Console.error called: ${message}`);
|
|
239572
|
+
};
|
|
239573
|
+
console.warn = (...args) => {
|
|
239574
|
+
const message = args.join(" ");
|
|
239575
|
+
this.consoleOutput.push(`[WARN] ${message}`);
|
|
239576
|
+
this.violations.push(`Console.warn called: ${message}`);
|
|
239577
|
+
};
|
|
239578
|
+
console.info = (...args) => {
|
|
239579
|
+
const message = args.join(" ");
|
|
239580
|
+
this.consoleOutput.push(`[INFO] ${message}`);
|
|
239581
|
+
this.violations.push(`Console.info called: ${message}`);
|
|
239582
|
+
};
|
|
239583
|
+
process.exit = (code) => {
|
|
239584
|
+
this.processExitAttempts++;
|
|
239585
|
+
this.violations.push(`Process.exit called with code: ${code}`);
|
|
239586
|
+
throw new Error(`Process exit intercepted: ${code}`);
|
|
239587
|
+
};
|
|
239588
|
+
process.stdout.write = (chunk, ...args) => {
|
|
239589
|
+
if (typeof chunk === "string" && chunk.trim()) {
|
|
239590
|
+
this.consoleOutput.push(`[STDOUT] ${chunk}`);
|
|
239591
|
+
this.violations.push(`Process.stdout.write called: ${chunk.substring(0, 100)}...`);
|
|
239592
|
+
}
|
|
239593
|
+
return true;
|
|
239594
|
+
};
|
|
239595
|
+
process.stderr.write = (chunk, ...args) => {
|
|
239596
|
+
if (typeof chunk === "string" && chunk.trim()) {
|
|
239597
|
+
this.consoleOutput.push(`[STDERR] ${chunk}`);
|
|
239598
|
+
this.violations.push(`Process.stderr.write called: ${chunk.substring(0, 100)}...`);
|
|
239599
|
+
}
|
|
239600
|
+
return true;
|
|
239601
|
+
};
|
|
239602
|
+
const originalRequire = __require;
|
|
239603
|
+
const monitor = this;
|
|
239604
|
+
global.require = function(id) {
|
|
239605
|
+
if (id === "readline" || id.includes("readline")) {
|
|
239606
|
+
monitor.readlineUsageDetected = true;
|
|
239607
|
+
monitor.violations.push("Readline module usage detected");
|
|
239608
|
+
}
|
|
239609
|
+
return originalRequire.apply(this, arguments);
|
|
239610
|
+
};
|
|
239611
|
+
}
|
|
239612
|
+
stopMonitoring() {
|
|
239613
|
+
if (!this.isMonitoring) {
|
|
239614
|
+
throw new Error("Monitor is not currently running");
|
|
239615
|
+
}
|
|
239616
|
+
console.log = this.originalConsoleLog;
|
|
239617
|
+
console.error = this.originalConsoleError;
|
|
239618
|
+
console.warn = this.originalConsoleWarn;
|
|
239619
|
+
console.info = this.originalConsoleInfo;
|
|
239620
|
+
process.exit = this.originalProcessExit;
|
|
239621
|
+
process.stdout.write = this.originalStdoutWrite;
|
|
239622
|
+
process.stderr.write = this.originalStderrWrite;
|
|
239623
|
+
global.require = __require;
|
|
239624
|
+
this.isMonitoring = false;
|
|
239625
|
+
return {
|
|
239626
|
+
violations: [...this.violations],
|
|
239627
|
+
consoleOutputDetected: [...this.consoleOutput],
|
|
239628
|
+
processExitAttempts: this.processExitAttempts,
|
|
239629
|
+
readlineUsageDetected: this.readlineUsageDetected,
|
|
239630
|
+
duration: Date.now() - this.startTime,
|
|
239631
|
+
timestamp: new Date().toISOString()
|
|
239632
|
+
};
|
|
239633
|
+
}
|
|
239634
|
+
isCurrentlyMonitoring() {
|
|
239635
|
+
return this.isMonitoring;
|
|
239636
|
+
}
|
|
239637
|
+
getViolations() {
|
|
239638
|
+
return [...this.violations];
|
|
239639
|
+
}
|
|
239640
|
+
}
|
|
239641
|
+
var globalMonitor = new McpSilentOperationMonitor;
|
|
239642
|
+
function validateSilentEnvironment() {
|
|
239643
|
+
const issues = [];
|
|
239644
|
+
if (process.env.CI !== "true") {
|
|
239645
|
+
issues.push('CI environment variable not set to "true"');
|
|
239646
|
+
}
|
|
239647
|
+
if (process.env.ENACT_SKIP_INTERACTIVE !== "true") {
|
|
239648
|
+
issues.push('ENACT_SKIP_INTERACTIVE not set to "true"');
|
|
239649
|
+
}
|
|
239650
|
+
if (process.env.DEBUG === "true" || process.env.VERBOSE === "true") {
|
|
239651
|
+
issues.push("DEBUG or VERBOSE environment variables are enabled");
|
|
239652
|
+
}
|
|
239653
|
+
if (process.stdin.isTTY) {
|
|
239654
|
+
issues.push("Process is running in TTY mode (potentially interactive)");
|
|
239655
|
+
}
|
|
239656
|
+
return {
|
|
239657
|
+
valid: issues.length === 0,
|
|
239658
|
+
issues
|
|
239659
|
+
};
|
|
239660
|
+
}
|
|
239893
239661
|
// ../shared/dist/services/McpCoreService.js
|
|
239894
239662
|
class McpCoreService {
|
|
239895
239663
|
constructor(options) {
|
|
@@ -239969,6 +239737,287 @@ class McpCoreService {
|
|
|
239969
239737
|
}
|
|
239970
239738
|
}
|
|
239971
239739
|
var mcpCoreService = new McpCoreService;
|
|
239740
|
+
// ../shared/dist/web/env-manager-server.js
|
|
239741
|
+
import { createServer } from "http";
|
|
239742
|
+
import { parse as parse4 } from "url";
|
|
239743
|
+
import { readFile as readFile3, writeFile as writeFile2, mkdir as mkdir2, readdir, stat as stat2 } from "fs/promises";
|
|
239744
|
+
import { existsSync as existsSync4 } from "fs";
|
|
239745
|
+
import { join as join5, dirname as dirname3 } from "path";
|
|
239746
|
+
import { homedir as homedir4 } from "os";
|
|
239747
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
239748
|
+
var __filename3 = fileURLToPath4(import.meta.url);
|
|
239749
|
+
var __dirname3 = dirname3(__filename3);
|
|
239750
|
+
var CONFIG_DIR3 = join5(homedir4(), ".enact");
|
|
239751
|
+
var ENV_BASE_DIR = join5(CONFIG_DIR3, "env");
|
|
239752
|
+
function findStaticDir() {
|
|
239753
|
+
const candidates = [
|
|
239754
|
+
join5(__dirname3, "web", "static"),
|
|
239755
|
+
join5(__dirname3, "static"),
|
|
239756
|
+
join5(__dirname3, "..", "src", "web", "static"),
|
|
239757
|
+
join5(__dirname3, "..", "..", "src", "web", "static"),
|
|
239758
|
+
join5(process.cwd(), "src", "web", "static"),
|
|
239759
|
+
join5(__dirname3, "..", "..", "..", "src", "web", "static"),
|
|
239760
|
+
join5(__dirname3, "..", "..", "src", "web", "static")
|
|
239761
|
+
];
|
|
239762
|
+
for (const candidate of candidates) {
|
|
239763
|
+
if (existsSync4(join5(candidate, "index.html"))) {
|
|
239764
|
+
logger_default.debug(`Found static directory: ${candidate}`);
|
|
239765
|
+
return candidate;
|
|
239766
|
+
}
|
|
239767
|
+
}
|
|
239768
|
+
throw new Error("Could not find static directory. Tried: " + candidates.join(", "));
|
|
239769
|
+
}
|
|
239770
|
+
var STATIC_DIR = findStaticDir();
|
|
239771
|
+
function parseDotEnv(content) {
|
|
239772
|
+
const vars = {};
|
|
239773
|
+
const lines = content.split(`
|
|
239774
|
+
`);
|
|
239775
|
+
for (const line of lines) {
|
|
239776
|
+
const trimmed = line.trim();
|
|
239777
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
239778
|
+
continue;
|
|
239779
|
+
}
|
|
239780
|
+
const equalIndex = trimmed.indexOf("=");
|
|
239781
|
+
if (equalIndex === -1) {
|
|
239782
|
+
continue;
|
|
239783
|
+
}
|
|
239784
|
+
const key = trimmed.slice(0, equalIndex).trim();
|
|
239785
|
+
let value = trimmed.slice(equalIndex + 1).trim();
|
|
239786
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
239787
|
+
value = value.slice(1, -1);
|
|
239788
|
+
}
|
|
239789
|
+
if (key) {
|
|
239790
|
+
vars[key] = value;
|
|
239791
|
+
}
|
|
239792
|
+
}
|
|
239793
|
+
return vars;
|
|
239794
|
+
}
|
|
239795
|
+
function generateDotEnv(vars) {
|
|
239796
|
+
return Object.entries(vars).map(([key, value]) => {
|
|
239797
|
+
const needsQuotes = value.includes(" ") || value.includes("\t") || value.includes(`
|
|
239798
|
+
`) || value.includes('"');
|
|
239799
|
+
const escapedValue = needsQuotes ? `"${value.replace(/"/g, "\\\"")}"` : value;
|
|
239800
|
+
return `${key}=${escapedValue}`;
|
|
239801
|
+
}).join(`
|
|
239802
|
+
`) + `
|
|
239803
|
+
`;
|
|
239804
|
+
}
|
|
239805
|
+
async function getAllPackageNamespaces() {
|
|
239806
|
+
const packages = [];
|
|
239807
|
+
if (!existsSync4(ENV_BASE_DIR)) {
|
|
239808
|
+
return packages;
|
|
239809
|
+
}
|
|
239810
|
+
try {
|
|
239811
|
+
await scanDirectory(ENV_BASE_DIR, "", packages);
|
|
239812
|
+
} catch (error) {
|
|
239813
|
+
logger_default.error("Failed to scan env directory:", error);
|
|
239814
|
+
}
|
|
239815
|
+
return packages;
|
|
239816
|
+
}
|
|
239817
|
+
async function scanDirectory(dir, relativePath, packages) {
|
|
239818
|
+
try {
|
|
239819
|
+
const entries = await readdir(dir);
|
|
239820
|
+
for (const entry of entries) {
|
|
239821
|
+
const fullPath = join5(dir, entry);
|
|
239822
|
+
const stats = await stat2(fullPath);
|
|
239823
|
+
if (stats.isDirectory()) {
|
|
239824
|
+
const newRelativePath = relativePath ? `${relativePath}/${entry}` : entry;
|
|
239825
|
+
await scanDirectory(fullPath, newRelativePath, packages);
|
|
239826
|
+
} else if (entry === ".env") {
|
|
239827
|
+
const namespace = relativePath || "root";
|
|
239828
|
+
try {
|
|
239829
|
+
const content = await readFile3(fullPath, "utf8");
|
|
239830
|
+
const variables = parseDotEnv(content);
|
|
239831
|
+
packages.push({
|
|
239832
|
+
namespace,
|
|
239833
|
+
path: fullPath,
|
|
239834
|
+
variables
|
|
239835
|
+
});
|
|
239836
|
+
} catch (error) {
|
|
239837
|
+
logger_default.error(`Failed to read .env file at ${fullPath}:`, error);
|
|
239838
|
+
}
|
|
239839
|
+
}
|
|
239840
|
+
}
|
|
239841
|
+
} catch (error) {
|
|
239842
|
+
logger_default.error(`Failed to scan directory ${dir}:`, error);
|
|
239843
|
+
}
|
|
239844
|
+
}
|
|
239845
|
+
async function getPackageEnvVars(namespace) {
|
|
239846
|
+
const envFile = join5(ENV_BASE_DIR, namespace, ".env");
|
|
239847
|
+
if (!existsSync4(envFile)) {
|
|
239848
|
+
return {};
|
|
239849
|
+
}
|
|
239850
|
+
try {
|
|
239851
|
+
const content = await readFile3(envFile, "utf8");
|
|
239852
|
+
return parseDotEnv(content);
|
|
239853
|
+
} catch (error) {
|
|
239854
|
+
logger_default.error(`Failed to read env file for ${namespace}:`, error);
|
|
239855
|
+
return {};
|
|
239856
|
+
}
|
|
239857
|
+
}
|
|
239858
|
+
async function setPackageEnvVar(namespace, key, value) {
|
|
239859
|
+
const envFile = join5(ENV_BASE_DIR, namespace, ".env");
|
|
239860
|
+
const envDir = dirname3(envFile);
|
|
239861
|
+
if (!existsSync4(envDir)) {
|
|
239862
|
+
await mkdir2(envDir, { recursive: true });
|
|
239863
|
+
}
|
|
239864
|
+
const existingVars = await getPackageEnvVars(namespace);
|
|
239865
|
+
existingVars[key] = value;
|
|
239866
|
+
const envContent = generateDotEnv(existingVars);
|
|
239867
|
+
await writeFile2(envFile, envContent, "utf8");
|
|
239868
|
+
}
|
|
239869
|
+
async function deletePackageEnvVar(namespace, key) {
|
|
239870
|
+
const existingVars = await getPackageEnvVars(namespace);
|
|
239871
|
+
if (!(key in existingVars)) {
|
|
239872
|
+
throw new Error(`Environment variable '${key}' not found in package '${namespace}'`);
|
|
239873
|
+
}
|
|
239874
|
+
delete existingVars[key];
|
|
239875
|
+
const envFile = join5(ENV_BASE_DIR, namespace, ".env");
|
|
239876
|
+
const envContent = generateDotEnv(existingVars);
|
|
239877
|
+
await writeFile2(envFile, envContent, "utf8");
|
|
239878
|
+
}
|
|
239879
|
+
async function serveStaticFile(filePath, res) {
|
|
239880
|
+
try {
|
|
239881
|
+
const content = await readFile3(filePath, "utf8");
|
|
239882
|
+
const ext = filePath.split(".").pop()?.toLowerCase();
|
|
239883
|
+
let contentType = "text/plain";
|
|
239884
|
+
switch (ext) {
|
|
239885
|
+
case "html":
|
|
239886
|
+
contentType = "text/html";
|
|
239887
|
+
break;
|
|
239888
|
+
case "css":
|
|
239889
|
+
contentType = "text/css";
|
|
239890
|
+
break;
|
|
239891
|
+
case "js":
|
|
239892
|
+
contentType = "application/javascript";
|
|
239893
|
+
break;
|
|
239894
|
+
case "json":
|
|
239895
|
+
contentType = "application/json";
|
|
239896
|
+
break;
|
|
239897
|
+
}
|
|
239898
|
+
res.writeHead(200, { "Content-Type": contentType });
|
|
239899
|
+
res.end(content);
|
|
239900
|
+
} catch (error) {
|
|
239901
|
+
logger_default.error("Error serving static file:", error);
|
|
239902
|
+
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
239903
|
+
res.end("File not found");
|
|
239904
|
+
}
|
|
239905
|
+
}
|
|
239906
|
+
async function handleRequest(req, res) {
|
|
239907
|
+
const urlParts = parse4(req.url || "", true);
|
|
239908
|
+
const pathname = urlParts.pathname || "/";
|
|
239909
|
+
const method = req.method || "GET";
|
|
239910
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
239911
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
|
|
239912
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
|
|
239913
|
+
if (method === "OPTIONS") {
|
|
239914
|
+
res.writeHead(200);
|
|
239915
|
+
res.end();
|
|
239916
|
+
return;
|
|
239917
|
+
}
|
|
239918
|
+
try {
|
|
239919
|
+
if (pathname === "/") {
|
|
239920
|
+
await serveStaticFile(join5(STATIC_DIR, "index.html"), res);
|
|
239921
|
+
} else if (pathname === "/style.css") {
|
|
239922
|
+
await serveStaticFile(join5(STATIC_DIR, "style.css"), res);
|
|
239923
|
+
} else if (pathname === "/app.js") {
|
|
239924
|
+
await serveStaticFile(join5(STATIC_DIR, "app.js"), res);
|
|
239925
|
+
} else if (pathname === "/favicon.ico") {
|
|
239926
|
+
const favicon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">\uD83C\uDF10</text></svg>`;
|
|
239927
|
+
res.writeHead(200, { "Content-Type": "image/svg+xml" });
|
|
239928
|
+
res.end(favicon);
|
|
239929
|
+
} else if (pathname === "/api/packages" && method === "GET") {
|
|
239930
|
+
const packages = await getAllPackageNamespaces();
|
|
239931
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
239932
|
+
res.end(JSON.stringify({ packages }));
|
|
239933
|
+
} else if (pathname === "/api/packages" && method === "POST") {
|
|
239934
|
+
const body = await getRequestBody(req);
|
|
239935
|
+
const { namespace } = JSON.parse(body);
|
|
239936
|
+
if (!namespace) {
|
|
239937
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
239938
|
+
res.end(JSON.stringify({ error: "Namespace is required" }));
|
|
239939
|
+
return;
|
|
239940
|
+
}
|
|
239941
|
+
const envDir = join5(ENV_BASE_DIR, namespace);
|
|
239942
|
+
const envFile = join5(envDir, ".env");
|
|
239943
|
+
if (!existsSync4(envDir)) {
|
|
239944
|
+
await mkdir2(envDir, { recursive: true });
|
|
239945
|
+
}
|
|
239946
|
+
if (!existsSync4(envFile)) {
|
|
239947
|
+
await writeFile2(envFile, "", "utf8");
|
|
239948
|
+
}
|
|
239949
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
239950
|
+
res.end(JSON.stringify({ success: true }));
|
|
239951
|
+
} else if (pathname?.startsWith("/api/packages/") && method === "GET") {
|
|
239952
|
+
const namespace = decodeURIComponent(pathname.replace("/api/packages/", ""));
|
|
239953
|
+
const variables = await getPackageEnvVars(namespace);
|
|
239954
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
239955
|
+
res.end(JSON.stringify({ namespace, variables }));
|
|
239956
|
+
} else if (pathname?.startsWith("/api/packages/") && pathname.endsWith("/variables") && method === "POST") {
|
|
239957
|
+
const namespace = decodeURIComponent(pathname.replace("/api/packages/", "").replace("/variables", ""));
|
|
239958
|
+
const body = await getRequestBody(req);
|
|
239959
|
+
const { key, value } = JSON.parse(body);
|
|
239960
|
+
if (!key || value === undefined) {
|
|
239961
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
239962
|
+
res.end(JSON.stringify({ error: "Key and value are required" }));
|
|
239963
|
+
return;
|
|
239964
|
+
}
|
|
239965
|
+
await setPackageEnvVar(namespace, key, value);
|
|
239966
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
239967
|
+
res.end(JSON.stringify({ success: true }));
|
|
239968
|
+
} else if (pathname?.includes("/variables/") && method === "DELETE") {
|
|
239969
|
+
const pathParts = pathname.split("/");
|
|
239970
|
+
const variableIndex = pathParts.indexOf("variables");
|
|
239971
|
+
const namespace = decodeURIComponent(pathParts.slice(3, variableIndex).join("/"));
|
|
239972
|
+
const key = decodeURIComponent(pathParts[variableIndex + 1]);
|
|
239973
|
+
await deletePackageEnvVar(namespace, key);
|
|
239974
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
239975
|
+
res.end(JSON.stringify({ success: true }));
|
|
239976
|
+
} else {
|
|
239977
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
239978
|
+
res.end(JSON.stringify({ error: "Not found" }));
|
|
239979
|
+
}
|
|
239980
|
+
} catch (error) {
|
|
239981
|
+
logger_default.error("Web server error:", error);
|
|
239982
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
239983
|
+
res.end(JSON.stringify({
|
|
239984
|
+
error: error instanceof Error ? error.message : "Internal server error"
|
|
239985
|
+
}));
|
|
239986
|
+
}
|
|
239987
|
+
}
|
|
239988
|
+
function getRequestBody(req) {
|
|
239989
|
+
return new Promise((resolve2, reject) => {
|
|
239990
|
+
let body = "";
|
|
239991
|
+
req.on("data", (chunk) => {
|
|
239992
|
+
body += chunk.toString();
|
|
239993
|
+
});
|
|
239994
|
+
req.on("end", () => {
|
|
239995
|
+
resolve2(body);
|
|
239996
|
+
});
|
|
239997
|
+
req.on("error", reject);
|
|
239998
|
+
});
|
|
239999
|
+
}
|
|
240000
|
+
function startEnvManagerServer(port = 5555) {
|
|
240001
|
+
return new Promise((resolve2, reject) => {
|
|
240002
|
+
const server2 = createServer(handleRequest);
|
|
240003
|
+
server2.listen(port, () => {
|
|
240004
|
+
const actualPort = server2.address()?.port || port;
|
|
240005
|
+
logger_default.info(`\uD83C\uDF10 Environment Manager web server started on http://localhost:${actualPort}`);
|
|
240006
|
+
resolve2({ server: server2, port: actualPort });
|
|
240007
|
+
});
|
|
240008
|
+
server2.on("error", (error) => {
|
|
240009
|
+
if (error.code === "EADDRINUSE") {
|
|
240010
|
+
server2.listen(0, () => {
|
|
240011
|
+
const actualPort = server2.address()?.port;
|
|
240012
|
+
logger_default.info(`\uD83C\uDF10 Environment Manager web server started on http://localhost:${actualPort} (port ${port} was in use)`);
|
|
240013
|
+
resolve2({ server: server2, port: actualPort });
|
|
240014
|
+
});
|
|
240015
|
+
} else {
|
|
240016
|
+
reject(error);
|
|
240017
|
+
}
|
|
240018
|
+
});
|
|
240019
|
+
});
|
|
240020
|
+
}
|
|
239972
240021
|
// ../shared/dist/lib/enact-direct.js
|
|
239973
240022
|
class EnactDirect {
|
|
239974
240023
|
constructor(options = {}) {
|
|
@@ -240141,7 +240190,8 @@ server2.registerTool("execute-tool-by-name", {
|
|
|
240141
240190
|
dryRun: exports_external.boolean().optional().describe("Dry run mode"),
|
|
240142
240191
|
verbose: exports_external.boolean().optional().describe("Verbose output"),
|
|
240143
240192
|
async: exports_external.boolean().optional().describe("Run in background for long operations"),
|
|
240144
|
-
forceRegistry: exports_external.boolean().optional().describe("Skip local resolution and go straight to registry")
|
|
240193
|
+
forceRegistry: exports_external.boolean().optional().describe("Skip local resolution and go straight to registry"),
|
|
240194
|
+
mount: exports_external.string().optional().describe("Mount local directory to container (format: 'localPath' or 'localPath:containerPath')")
|
|
240145
240195
|
}
|
|
240146
240196
|
}, async (params) => {
|
|
240147
240197
|
const {
|
|
@@ -240153,7 +240203,8 @@ server2.registerTool("execute-tool-by-name", {
|
|
|
240153
240203
|
dryRun,
|
|
240154
240204
|
verbose,
|
|
240155
240205
|
async = false,
|
|
240156
|
-
forceRegistry = false
|
|
240206
|
+
forceRegistry = false,
|
|
240207
|
+
mount
|
|
240157
240208
|
} = params;
|
|
240158
240209
|
try {
|
|
240159
240210
|
logger_default.info(`Executing tool: ${name} (localFile: ${localFile}, async: ${async})`);
|
|
@@ -240244,7 +240295,7 @@ ${suggestions.map((s2) => ` • ${s2}`).join(`
|
|
|
240244
240295
|
}
|
|
240245
240296
|
const isLongRunning = toolToExecute.name.includes("dagger") || toolToExecute.name.includes("docker") || toolToExecute.name.includes("build") || async;
|
|
240246
240297
|
if (isLongRunning) {
|
|
240247
|
-
const operationId = `${toolToExecute.name}-${Date.now()}-${Math.random().toString(36).
|
|
240298
|
+
const operationId = `${toolToExecute.name}-${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
|
240248
240299
|
let executionPromise;
|
|
240249
240300
|
if (isLocalFile) {
|
|
240250
240301
|
const yamlContent = await import("fs/promises").then((fs6) => fs6.readFile(toolToExecute.path, "utf-8"));
|
|
@@ -240253,6 +240304,7 @@ ${suggestions.map((s2) => ` • ${s2}`).join(`
|
|
|
240253
240304
|
force: dangerouslySkipVerification || true,
|
|
240254
240305
|
dryRun,
|
|
240255
240306
|
verbose,
|
|
240307
|
+
mount,
|
|
240256
240308
|
isLocalFile: true
|
|
240257
240309
|
});
|
|
240258
240310
|
} else {
|
|
@@ -240261,6 +240313,7 @@ ${suggestions.map((s2) => ` • ${s2}`).join(`
|
|
|
240261
240313
|
force: dangerouslySkipVerification,
|
|
240262
240314
|
dryRun,
|
|
240263
240315
|
verbose,
|
|
240316
|
+
mount,
|
|
240264
240317
|
isLocalFile: false
|
|
240265
240318
|
});
|
|
240266
240319
|
}
|
|
@@ -240303,14 +240356,16 @@ Operation ID: ${operationId}
|
|
|
240303
240356
|
timeout: timeout3 || "120s",
|
|
240304
240357
|
force: dangerouslySkipVerification || true,
|
|
240305
240358
|
dryRun,
|
|
240306
|
-
verbose
|
|
240359
|
+
verbose,
|
|
240360
|
+
mount
|
|
240307
240361
|
});
|
|
240308
240362
|
} else {
|
|
240309
240363
|
result = await enactCore.executeToolByName(toolToExecute.name || name, inputs, {
|
|
240310
240364
|
timeout: timeout3 || "120s",
|
|
240311
240365
|
force: dangerouslySkipVerification,
|
|
240312
240366
|
dryRun,
|
|
240313
|
-
verbose
|
|
240367
|
+
verbose,
|
|
240368
|
+
mount
|
|
240314
240369
|
});
|
|
240315
240370
|
}
|
|
240316
240371
|
if (!result.success) {
|