@anurag134/nexusmcp 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +45 -2
  2. package/dist/index.js +208 -0
  3. package/dist/samples/mock-gitlab.js +88 -0
  4. package/dist/src/common/type.js +1 -0
  5. package/dist/src/common/utils.js +28 -0
  6. package/dist/src/database/db.js +151 -0
  7. package/dist/src/database/type.js +1 -0
  8. package/dist/src/module/checkpoint/controller.js +30 -0
  9. package/dist/src/module/checkpoint/service.js +59 -0
  10. package/dist/src/module/checkpoint/type.js +1 -0
  11. package/dist/src/module/checkpoint/utils.js +41 -0
  12. package/dist/src/module/dashboard/controller.js +39 -0
  13. package/dist/src/module/dashboard/service.js +86 -0
  14. package/dist/src/module/dashboard/type.js +1 -0
  15. package/dist/src/module/dashboard/utils.js +874 -0
  16. package/dist/src/module/mcp/controller.js +35 -0
  17. package/dist/src/module/mcp/service.js +254 -0
  18. package/dist/src/module/mcp/type.js +1 -0
  19. package/dist/src/module/mcp/utils.js +24 -0
  20. package/dist/src/module/router/controller.js +16 -0
  21. package/dist/src/module/router/service.js +56 -0
  22. package/dist/src/module/router/type.js +1 -0
  23. package/dist/src/module/router/utils.js +77 -0
  24. package/dist/src/module/security/controller.js +15 -0
  25. package/dist/src/module/security/service.js +124 -0
  26. package/dist/src/module/security/type.js +6 -0
  27. package/dist/src/module/security/utils.js +210 -0
  28. package/dist/src/module/upstream/controller.js +353 -0
  29. package/dist/src/module/upstream/service.js +344 -0
  30. package/dist/src/module/upstream/type.js +1 -0
  31. package/dist/src/module/upstream/utils.js +135 -0
  32. package/dist/tools/github-publisher/index.js +187 -0
  33. package/package.json +38 -4
@@ -0,0 +1,35 @@
1
+ import { CommonUtils } from "../../common/utils.js";
2
+ export class McpController {
3
+ mcpService;
4
+ constructor(mcpService) {
5
+ this.mcpService = mcpService;
6
+ }
7
+ registerRoutes(server) {
8
+ server.get("/mcp/sse", this.handleSseConnection.bind(this));
9
+ server.post("/mcp/message", this.handleRpcMessage.bind(this));
10
+ }
11
+ async handleSseConnection(req, reply) {
12
+ const sessionId = CommonUtils.generateId("sess");
13
+ reply.raw.writeHead(200, {
14
+ "Content-Type": "text/event-stream",
15
+ "Cache-Control": "no-cache, no-transform",
16
+ "Connection": "keep-alive",
17
+ "Access-Control-Allow-Origin": "*",
18
+ "X-Accel-Buffering": "no"
19
+ });
20
+ this.mcpService.registerSession(sessionId, reply);
21
+ const endpointUrl = `/mcp/message?sessionId=${sessionId}`;
22
+ this.mcpService.sendToSession(sessionId, "endpoint", endpointUrl);
23
+ }
24
+ async handleRpcMessage(req, reply) {
25
+ const sessionId = req.query?.sessionId;
26
+ if (!sessionId) {
27
+ reply.status(400).send({ error: "Missing sessionId parameter" });
28
+ return;
29
+ }
30
+ const body = req.body;
31
+ const response = await this.mcpService.handleRpcMessage(sessionId, body);
32
+ this.mcpService.sendToSession(sessionId, "message", response);
33
+ reply.status(202).send({ status: "accepted" });
34
+ }
35
+ }
@@ -0,0 +1,254 @@
1
+ import { McpUtils } from "./utils.js";
2
+ import { RiskTier } from "../security/type.js";
3
+ import { CommonUtils } from "../../common/utils.js";
4
+ export class McpService {
5
+ db;
6
+ router;
7
+ upstream;
8
+ security;
9
+ checkpoint;
10
+ sessions = new Map();
11
+ heartbeatInterval = null;
12
+ constructor(db, router, upstream, security, checkpoint) {
13
+ this.db = db;
14
+ this.router = router;
15
+ this.upstream = upstream;
16
+ this.security = security;
17
+ this.checkpoint = checkpoint;
18
+ this.startHeartbeatSupervisor();
19
+ }
20
+ startHeartbeatSupervisor() {
21
+ this.heartbeatInterval = setInterval(() => {
22
+ const now = Date.now();
23
+ for (const [id, session] of this.sessions.entries()) {
24
+ try {
25
+ session.reply.raw.write(": ping\n\n");
26
+ session.lastHeartbeat = now;
27
+ }
28
+ catch {
29
+ this.removeSession(id);
30
+ }
31
+ }
32
+ }, 15000);
33
+ }
34
+ registerSession(id, reply) {
35
+ this.sessions.set(id, {
36
+ id,
37
+ reply,
38
+ createdAt: Date.now(),
39
+ lastHeartbeat: Date.now()
40
+ });
41
+ this.db.registerSession({
42
+ id,
43
+ client_name: "Cursor/IDE-Client",
44
+ connected_at: Date.now(),
45
+ last_active: Date.now(),
46
+ is_active: 1
47
+ });
48
+ reply.raw.on("close", () => {
49
+ this.removeSession(id);
50
+ });
51
+ }
52
+ removeSession(id) {
53
+ this.sessions.delete(id);
54
+ this.db.closeSession(id);
55
+ }
56
+ sendToSession(sessionId, eventName, data) {
57
+ const session = this.sessions.get(sessionId);
58
+ if (!session) {
59
+ return false;
60
+ }
61
+ const chunk = McpUtils.formatSseEvent(eventName, data);
62
+ session.reply.raw.write(chunk);
63
+ return true;
64
+ }
65
+ async handleRpcMessage(sessionId, request) {
66
+ const reqId = request.id ?? null;
67
+ switch (request.method) {
68
+ case "initialize":
69
+ return McpUtils.createSuccessResponse(reqId, {
70
+ protocolVersion: "2024-11-05",
71
+ capabilities: {
72
+ tools: { listChanged: false }
73
+ },
74
+ serverInfo: {
75
+ name: "nexusmcp",
76
+ version: "1.0.0"
77
+ }
78
+ });
79
+ case "notifications/initialized":
80
+ return McpUtils.createSuccessResponse(reqId, {});
81
+ case "ping":
82
+ return McpUtils.createSuccessResponse(reqId, {});
83
+ case "tools/list":
84
+ return McpUtils.createSuccessResponse(reqId, {
85
+ tools: this.getGatewaySyntheticTools()
86
+ });
87
+ case "tools/call":
88
+ return await this.handleToolCall(sessionId, reqId, request.params || {});
89
+ default:
90
+ return McpUtils.createErrorResponse(reqId, -32601, `Method "${request.method}" not found.`);
91
+ }
92
+ }
93
+ getGatewaySyntheticTools() {
94
+ return [
95
+ {
96
+ name: "nexus_search_tools",
97
+ description: "Intelligently search and retrieve matching tools for user intent. Use this to discover capabilities across all connected upstream servers without bloating context.",
98
+ inputSchema: {
99
+ type: "object",
100
+ properties: {
101
+ intent: {
102
+ type: "string",
103
+ description: "The user's goal or task (e.g. 'create merge request', 'query user table', 'post message to slack')."
104
+ },
105
+ limit: {
106
+ type: "number",
107
+ description: "Maximum number of candidate tools to return (default: 4)."
108
+ }
109
+ },
110
+ required: ["intent"]
111
+ }
112
+ },
113
+ {
114
+ name: "nexus_execute",
115
+ description: "Executes a discovered tool against its upstream MCP server with automatic credential injection, PII masking, safety risk checks, and git auto-checkpointing.",
116
+ inputSchema: {
117
+ type: "object",
118
+ properties: {
119
+ tool_name: {
120
+ type: "string",
121
+ description: "The exact name of the tool discovered via nexus_search_tools."
122
+ },
123
+ arguments: {
124
+ type: "object",
125
+ description: "Parameters required by the tool's schema."
126
+ }
127
+ },
128
+ required: ["tool_name", "arguments"]
129
+ }
130
+ },
131
+ {
132
+ name: "nexus_list_servers",
133
+ description: "Lists all connected upstream MCP servers and their health status.",
134
+ inputSchema: {
135
+ type: "object",
136
+ properties: {}
137
+ }
138
+ },
139
+ {
140
+ name: "nexus_rollback",
141
+ description: "Reverts the local repository workspace to the pre-execution state of the latest checkpoint.",
142
+ inputSchema: {
143
+ type: "object",
144
+ properties: {}
145
+ }
146
+ },
147
+ {
148
+ name: "nexus_diff",
149
+ description: "Inspects the current working directory git diffs since the last checkpoint.",
150
+ inputSchema: {
151
+ type: "object",
152
+ properties: {}
153
+ }
154
+ }
155
+ ];
156
+ }
157
+ async handleToolCall(sessionId, reqId, params) {
158
+ const toolName = String(params.name || "");
159
+ const args = params.arguments || {};
160
+ const startTime = Date.now();
161
+ if (toolName === "nexus_search_tools") {
162
+ const intent = String(args.intent || "");
163
+ const limit = Number(args.limit) || 4;
164
+ const matches = this.router.searchTools(intent, limit);
165
+ const totalTools = this.router.getIndexedCount();
166
+ const filteredOut = Math.max(0, totalTools - matches.length);
167
+ const estimatedTokensSaved = filteredOut * 250;
168
+ const formattedText = matches.length > 0
169
+ ? `Found ${matches.length} matching tools for intent "${intent}":\n\n` +
170
+ matches.map((m, i) => `${i + 1}. **${m.toolName}** [Domain: ${m.domain}, Relevance: ${(m.score * 100).toFixed(0)}%]\n Description: ${m.description}\n Schema: \`${JSON.stringify(m.schema)}\``).join("\n\n") +
171
+ `\n\n[Token Saver: Filtered out ${filteredOut} irrelevant tools. Saved ~${estimatedTokensSaved} context tokens.]`
172
+ : `No matching tools found for intent "${intent}". Available domains: ${this.getDomainSummary()}`;
173
+ this.db.logAudit({
174
+ id: CommonUtils.generateId("aud"),
175
+ session_id: sessionId,
176
+ tool_name: "nexus_search_tools",
177
+ parameters: JSON.stringify(args),
178
+ duration_ms: Date.now() - startTime,
179
+ status: "SUCCESS",
180
+ tokens_saved: estimatedTokensSaved,
181
+ created_at: Date.now()
182
+ });
183
+ return McpUtils.createSuccessResponse(reqId, {
184
+ content: [{ type: "text", text: formattedText }]
185
+ });
186
+ }
187
+ if (toolName === "nexus_execute") {
188
+ const targetTool = String(args.tool_name || "");
189
+ const targetArgs = args.arguments || {};
190
+ const risk = this.security.assessToolRisk(targetTool, targetArgs);
191
+ if (risk.tier === RiskTier.CRITICAL) {
192
+ return McpUtils.createErrorResponse(reqId, -32001, `CRITICAL SAFETY INTERCEPTION: Command blocked. Reason: ${risk.reason}`);
193
+ }
194
+ if (risk.tier === RiskTier.MUTATING) {
195
+ this.checkpoint.createCheckpoint(targetTool);
196
+ }
197
+ const executionResult = await this.upstream.executeTool(targetTool, targetArgs);
198
+ this.db.logAudit({
199
+ id: CommonUtils.generateId("aud"),
200
+ session_id: sessionId,
201
+ tool_name: targetTool,
202
+ parameters: JSON.stringify(targetArgs),
203
+ duration_ms: executionResult.durationMs,
204
+ status: executionResult.isError ? "ERROR" : "SUCCESS",
205
+ tokens_saved: executionResult.tokensSaved || 0,
206
+ created_at: Date.now()
207
+ });
208
+ return McpUtils.createSuccessResponse(reqId, {
209
+ content: executionResult.content,
210
+ isError: executionResult.isError
211
+ });
212
+ }
213
+ if (toolName === "nexus_rollback") {
214
+ const rollbackResult = this.checkpoint.rollbackLatest();
215
+ return McpUtils.createSuccessResponse(reqId, {
216
+ content: [{ type: "text", text: rollbackResult.message }],
217
+ isError: !rollbackResult.success
218
+ });
219
+ }
220
+ if (toolName === "nexus_diff") {
221
+ const diffResult = this.checkpoint.getDiff();
222
+ return McpUtils.createSuccessResponse(reqId, {
223
+ content: [{ type: "text", text: diffResult.diff }]
224
+ });
225
+ }
226
+ if (toolName === "nexus_list_servers") {
227
+ const servers = this.db.getAllServers();
228
+ const totalTools = this.router.getIndexedCount();
229
+ const serverList = servers.map(s => `• **${s.name}** (${s.transport}): Status = ${s.status}`).join("\n");
230
+ const summaryText = `NexusMCP Gateway Status:\n• Connected Upstream Servers: ${servers.length}\n• Total Indexed Tools: ${totalTools}\n\nServers:\n${serverList || "No upstream servers registered yet. Add one via web UI or CLI."}`;
231
+ return McpUtils.createSuccessResponse(reqId, {
232
+ content: [{ type: "text", text: summaryText }]
233
+ });
234
+ }
235
+ return McpUtils.createErrorResponse(reqId, -32601, `Unknown tool "${toolName}". Available gateway tools: nexus_search_tools, nexus_execute, nexus_list_servers, nexus_rollback, nexus_diff.`);
236
+ }
237
+ getDomainSummary() {
238
+ const servers = this.db.getAllServers();
239
+ return servers.map(s => s.name).join(", ") || "none";
240
+ }
241
+ shutdown() {
242
+ if (this.heartbeatInterval) {
243
+ clearInterval(this.heartbeatInterval);
244
+ this.heartbeatInterval = null;
245
+ }
246
+ for (const session of this.sessions.values()) {
247
+ try {
248
+ session.reply.raw.end();
249
+ }
250
+ catch { }
251
+ }
252
+ this.sessions.clear();
253
+ }
254
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ export class McpUtils {
2
+ static formatSseEvent(eventName, data) {
3
+ const serialized = typeof data === "string" ? data : JSON.stringify(data);
4
+ return `event: ${eventName}\ndata: ${serialized}\n\n`;
5
+ }
6
+ static createSuccessResponse(id, result) {
7
+ return {
8
+ jsonrpc: "2.0",
9
+ id,
10
+ result
11
+ };
12
+ }
13
+ static createErrorResponse(id, code, message, data) {
14
+ return {
15
+ jsonrpc: "2.0",
16
+ id,
17
+ error: {
18
+ code,
19
+ message,
20
+ data
21
+ }
22
+ };
23
+ }
24
+ }
@@ -0,0 +1,16 @@
1
+ import { CommonUtils } from "../../common/utils.js";
2
+ export class RouterController {
3
+ routerService;
4
+ constructor(routerService) {
5
+ this.routerService = routerService;
6
+ }
7
+ registerRoutes(server) {
8
+ server.post("/api/router/search", this.searchTools.bind(this));
9
+ }
10
+ async searchTools(req, reply) {
11
+ const intent = req.body?.intent || "";
12
+ const maxResults = req.body?.maxResults || 4;
13
+ const results = this.routerService.searchTools(intent, maxResults);
14
+ reply.send(CommonUtils.successResponse(results));
15
+ }
16
+ }
@@ -0,0 +1,56 @@
1
+ import { RouterUtils } from "./utils.js";
2
+ import { CommonUtils } from "../../common/utils.js";
3
+ export class RouterService {
4
+ index = new Map();
5
+ indexTool(id, name, description, domain, schemaJson) {
6
+ const rawText = `${name} ${description} ${domain}`;
7
+ const tokens = RouterUtils.tokenize(rawText);
8
+ const vector = RouterUtils.buildFrequencyVector(tokens);
9
+ this.index.set(name, {
10
+ id,
11
+ name,
12
+ description,
13
+ domain,
14
+ schemaJson,
15
+ tokens,
16
+ vector
17
+ });
18
+ }
19
+ removeTool(name) {
20
+ this.index.delete(name);
21
+ }
22
+ clear() {
23
+ this.index.clear();
24
+ }
25
+ searchTools(intent, maxResults = 4) {
26
+ const queryTokens = RouterUtils.tokenize(intent);
27
+ const queryVector = RouterUtils.buildFrequencyVector(queryTokens);
28
+ const results = [];
29
+ for (const doc of this.index.values()) {
30
+ let score = RouterUtils.cosineSimilarity(queryVector, doc.vector);
31
+ for (const token of queryTokens) {
32
+ if (doc.name.toLowerCase().includes(token)) {
33
+ score += 0.35;
34
+ }
35
+ }
36
+ if (score > 0.05) {
37
+ const parsedSchema = CommonUtils.safeJsonParse(doc.schemaJson, {});
38
+ results.push({
39
+ toolName: doc.name,
40
+ score,
41
+ description: doc.description,
42
+ domain: doc.domain,
43
+ schema: parsedSchema
44
+ });
45
+ }
46
+ }
47
+ results.sort((a, b) => b.score - a.score);
48
+ return results.slice(0, maxResults);
49
+ }
50
+ pruneOutput(rawText, options) {
51
+ return RouterUtils.pruneOutput(rawText, options);
52
+ }
53
+ getIndexedCount() {
54
+ return this.index.size;
55
+ }
56
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,77 @@
1
+ export class RouterUtils {
2
+ static stopWords = new Set([
3
+ "a", "an", "the", "and", "or", "in", "on", "at", "to", "for", "with", "is", "are", "it",
4
+ "of", "by", "from", "as", "into", "like", "through", "after", "over", "between", "out"
5
+ ]);
6
+ static ERROR_PATTERNS = [
7
+ /\bError\b/i,
8
+ /\bFailed\b/i,
9
+ /\bException\b/i,
10
+ /\bFATAL\b/i,
11
+ /at\s+.*\(\S+:\d+:\d+\)/,
12
+ /npm ERR!/,
13
+ /TS\d{4}:/
14
+ ];
15
+ static tokenize(text) {
16
+ const cleaned = text.toLowerCase().replace(/[^a-z0-9_\s-]/g, " ");
17
+ const words = cleaned.split(/\s+/).filter(w => w.length > 1 && !this.stopWords.has(w));
18
+ const subwords = [];
19
+ for (const word of words) {
20
+ subwords.push(word);
21
+ if (word.includes("_") || word.includes("-")) {
22
+ const parts = word.split(/[_-]/).filter(p => p.length > 1);
23
+ subwords.push(...parts);
24
+ }
25
+ }
26
+ return subwords;
27
+ }
28
+ static buildFrequencyVector(tokens) {
29
+ const vec = {};
30
+ for (const token of tokens) {
31
+ vec[token] = (vec[token] || 0) + 1;
32
+ }
33
+ const magnitude = Math.sqrt(Object.values(vec).reduce((sum, val) => sum + val * val, 0));
34
+ if (magnitude > 0) {
35
+ for (const token of Object.keys(vec)) {
36
+ vec[token] = vec[token] / magnitude;
37
+ }
38
+ }
39
+ return vec;
40
+ }
41
+ static cosineSimilarity(vecA, vecB) {
42
+ let dotProduct = 0;
43
+ for (const term of Object.keys(vecA)) {
44
+ if (vecB[term]) {
45
+ dotProduct += vecA[term] * vecB[term];
46
+ }
47
+ }
48
+ return dotProduct;
49
+ }
50
+ static pruneOutput(rawText, options) {
51
+ const headLines = options?.headLines ?? 50;
52
+ const tailLines = options?.tailLines ?? 100;
53
+ const maxTotal = options?.maxTotalLines ?? 200;
54
+ const lines = rawText.split(/\r?\n/);
55
+ if (lines.length <= maxTotal) {
56
+ return rawText;
57
+ }
58
+ const head = lines.slice(0, headLines);
59
+ const tail = lines.slice(-tailLines);
60
+ const middle = lines.slice(headLines, -tailLines);
61
+ const errorLines = [];
62
+ for (let i = 0; i < middle.length; i++) {
63
+ if (this.ERROR_PATTERNS.some(p => p.test(middle[i]))) {
64
+ if (i > 0 && !errorLines.includes(middle[i - 1])) {
65
+ errorLines.push(middle[i - 1]);
66
+ }
67
+ errorLines.push(middle[i]);
68
+ if (i < middle.length - 1) {
69
+ errorLines.push(middle[i + 1]);
70
+ }
71
+ }
72
+ }
73
+ const foldedCount = middle.length - errorLines.length;
74
+ const marker = `\n[... ${foldedCount} passing log lines folded by NexusMCP to save context tokens ...]\n`;
75
+ return [...head, marker, ...errorLines, "\n--- [Tail Output] ---", ...tail].join("\n");
76
+ }
77
+ }
@@ -0,0 +1,15 @@
1
+ import { CommonUtils } from "../../common/utils.js";
2
+ export class SecurityController {
3
+ securityService;
4
+ constructor(securityService) {
5
+ this.securityService = securityService;
6
+ }
7
+ registerRoutes(server) {
8
+ server.post("/api/security/test-mask", this.testMask.bind(this));
9
+ }
10
+ async testMask(req, reply) {
11
+ const text = req.body?.text || "";
12
+ const result = this.securityService.maskContent(text);
13
+ reply.send(CommonUtils.successResponse(result));
14
+ }
15
+ }
@@ -0,0 +1,124 @@
1
+ import os from "node:os";
2
+ import path from "node:path";
3
+ import { SecurityUtils } from "./utils.js";
4
+ export class SecurityService {
5
+ rules;
6
+ vault = new Map();
7
+ vaultDir;
8
+ constructor(baseDir) {
9
+ this.rules = SecurityUtils.getStandardRules();
10
+ this.vaultDir = baseDir ? path.join(baseDir, "vault") : path.join(os.homedir(), ".nexusmcp", "vault");
11
+ }
12
+ maskContent(rawText) {
13
+ let text = rawText;
14
+ let maskedCount = 0;
15
+ const typesDetected = [];
16
+ for (const item of this.vault.values()) {
17
+ if (item.value && item.value.length >= 6 && text.includes(item.value)) {
18
+ text = text.split(item.value).join("[REDACTED_VAULT_SECRET]");
19
+ maskedCount++;
20
+ if (!typesDetected.includes("Vault Secret")) {
21
+ typesDetected.push("Vault Secret");
22
+ }
23
+ }
24
+ }
25
+ for (const rule of this.rules) {
26
+ const matches = text.match(rule.pattern);
27
+ if (matches && matches.length > 0) {
28
+ maskedCount += matches.length;
29
+ if (!typesDetected.includes(rule.name)) {
30
+ typesDetected.push(rule.name);
31
+ }
32
+ text = text.replace(rule.pattern, rule.mask);
33
+ }
34
+ }
35
+ return {
36
+ content: text,
37
+ maskedCount,
38
+ typesDetected
39
+ };
40
+ }
41
+ assessRisk(actionText) {
42
+ return SecurityUtils.assessRisk(actionText);
43
+ }
44
+ assessToolRisk(toolName, args) {
45
+ const surface = SecurityUtils.extractRiskSurface(toolName, args);
46
+ return SecurityUtils.assessRisk(surface);
47
+ }
48
+ setSecret(serverId, key, value) {
49
+ const vaultKey = `${serverId}:${key}`;
50
+ this.vault.set(vaultKey, {
51
+ key,
52
+ value,
53
+ serverId,
54
+ updatedAt: Date.now()
55
+ });
56
+ SecurityUtils.storeOsSecret(this.vaultDir, serverId, key, value);
57
+ }
58
+ getSecret(serverId, key) {
59
+ const cached = this.vault.get(`${serverId}:${key}`)?.value;
60
+ if (cached) {
61
+ return cached;
62
+ }
63
+ const loaded = SecurityUtils.loadOsSecret(this.vaultDir, serverId, key);
64
+ if (loaded) {
65
+ this.vault.set(`${serverId}:${key}`, { key, value: loaded, serverId, updatedAt: Date.now() });
66
+ return loaded;
67
+ }
68
+ return undefined;
69
+ }
70
+ removeServerSecrets(serverId) {
71
+ for (const [k, item] of this.vault.entries()) {
72
+ if (item.serverId === serverId) {
73
+ this.vault.delete(k);
74
+ }
75
+ }
76
+ SecurityUtils.deleteOsSecretsForServer(this.vaultDir, serverId);
77
+ }
78
+ injectSecrets(serverId, env) {
79
+ const result = {};
80
+ for (const [key, value] of Object.entries(env)) {
81
+ if (value === SecurityUtils.VAULT_MARKER) {
82
+ const secret = this.getSecret(serverId, key);
83
+ if (secret) {
84
+ result[key] = secret;
85
+ }
86
+ }
87
+ else if (SecurityUtils.isEnvReference(value)) {
88
+ result[key] = SecurityUtils.resolveEnvReference(value);
89
+ }
90
+ else if (value) {
91
+ result[key] = value;
92
+ }
93
+ }
94
+ for (const [, item] of this.vault.entries()) {
95
+ if (item.serverId === serverId && item.value) {
96
+ result[item.key] = item.value;
97
+ }
98
+ }
99
+ return result;
100
+ }
101
+ persistSecretsAndReturnMarkers(serverId, env) {
102
+ const markers = {};
103
+ for (const [key, value] of Object.entries(env)) {
104
+ if (value === "••••••••" || value === SecurityUtils.VAULT_MARKER) {
105
+ markers[key] = SecurityUtils.VAULT_MARKER;
106
+ }
107
+ else if (SecurityUtils.isEnvReference(value)) {
108
+ markers[key] = value;
109
+ }
110
+ else if (value) {
111
+ this.setSecret(serverId, key, value);
112
+ markers[key] = SecurityUtils.VAULT_MARKER;
113
+ }
114
+ }
115
+ return markers;
116
+ }
117
+ maskEnvForDisplay(env) {
118
+ const masked = {};
119
+ for (const [key, value] of Object.entries(env)) {
120
+ masked[key] = SecurityUtils.isEnvReference(value) ? value : "••••••••";
121
+ }
122
+ return masked;
123
+ }
124
+ }
@@ -0,0 +1,6 @@
1
+ export var RiskTier;
2
+ (function (RiskTier) {
3
+ RiskTier["SAFE"] = "SAFE";
4
+ RiskTier["MUTATING"] = "MUTATING";
5
+ RiskTier["CRITICAL"] = "CRITICAL";
6
+ })(RiskTier || (RiskTier = {}));