@enactprotocol/shared 1.2.11 → 2.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 (134) hide show
  1. package/README.md +44 -0
  2. package/package.json +16 -58
  3. package/src/config.ts +476 -0
  4. package/src/constants.ts +36 -0
  5. package/src/execution/command.ts +314 -0
  6. package/src/execution/index.ts +73 -0
  7. package/src/execution/runtime.ts +308 -0
  8. package/src/execution/types.ts +379 -0
  9. package/src/execution/validation.ts +508 -0
  10. package/src/index.ts +237 -30
  11. package/src/manifest/index.ts +36 -0
  12. package/src/manifest/loader.ts +187 -0
  13. package/src/manifest/parser.ts +173 -0
  14. package/src/manifest/validator.ts +309 -0
  15. package/src/paths.ts +108 -0
  16. package/src/registry.ts +219 -0
  17. package/src/resolver.ts +345 -0
  18. package/src/types/index.ts +30 -0
  19. package/src/types/manifest.ts +255 -0
  20. package/src/types.ts +5 -188
  21. package/src/utils/fs.ts +281 -0
  22. package/src/utils/logger.ts +270 -59
  23. package/src/utils/version.ts +304 -36
  24. package/tests/config.test.ts +515 -0
  25. package/tests/execution/command.test.ts +317 -0
  26. package/tests/execution/validation.test.ts +384 -0
  27. package/tests/fixtures/invalid-tool.yaml +4 -0
  28. package/tests/fixtures/valid-tool.md +62 -0
  29. package/tests/fixtures/valid-tool.yaml +40 -0
  30. package/tests/index.test.ts +8 -0
  31. package/tests/manifest/loader.test.ts +291 -0
  32. package/tests/manifest/parser.test.ts +345 -0
  33. package/tests/manifest/validator.test.ts +394 -0
  34. package/tests/manifest-types.test.ts +358 -0
  35. package/tests/paths.test.ts +153 -0
  36. package/tests/registry.test.ts +231 -0
  37. package/tests/resolver.test.ts +272 -0
  38. package/tests/utils/fs.test.ts +388 -0
  39. package/tests/utils/logger.test.ts +480 -0
  40. package/tests/utils/version.test.ts +390 -0
  41. package/tsconfig.json +12 -0
  42. package/tsconfig.tsbuildinfo +1 -0
  43. package/dist/LocalToolResolver.d.ts +0 -84
  44. package/dist/LocalToolResolver.js +0 -353
  45. package/dist/api/enact-api.d.ts +0 -130
  46. package/dist/api/enact-api.js +0 -428
  47. package/dist/api/index.d.ts +0 -2
  48. package/dist/api/index.js +0 -2
  49. package/dist/api/types.d.ts +0 -103
  50. package/dist/api/types.js +0 -1
  51. package/dist/constants.d.ts +0 -7
  52. package/dist/constants.js +0 -10
  53. package/dist/core/DaggerExecutionProvider.d.ts +0 -169
  54. package/dist/core/DaggerExecutionProvider.js +0 -1029
  55. package/dist/core/DirectExecutionProvider.d.ts +0 -23
  56. package/dist/core/DirectExecutionProvider.js +0 -406
  57. package/dist/core/EnactCore.d.ts +0 -162
  58. package/dist/core/EnactCore.js +0 -597
  59. package/dist/core/NativeExecutionProvider.d.ts +0 -9
  60. package/dist/core/NativeExecutionProvider.js +0 -16
  61. package/dist/core/index.d.ts +0 -3
  62. package/dist/core/index.js +0 -3
  63. package/dist/exec/index.d.ts +0 -3
  64. package/dist/exec/index.js +0 -3
  65. package/dist/exec/logger.d.ts +0 -11
  66. package/dist/exec/logger.js +0 -57
  67. package/dist/exec/validate.d.ts +0 -5
  68. package/dist/exec/validate.js +0 -167
  69. package/dist/index.d.ts +0 -21
  70. package/dist/index.js +0 -25
  71. package/dist/lib/enact-direct.d.ts +0 -150
  72. package/dist/lib/enact-direct.js +0 -159
  73. package/dist/lib/index.d.ts +0 -1
  74. package/dist/lib/index.js +0 -1
  75. package/dist/security/index.d.ts +0 -3
  76. package/dist/security/index.js +0 -3
  77. package/dist/security/security.d.ts +0 -23
  78. package/dist/security/security.js +0 -137
  79. package/dist/security/sign.d.ts +0 -103
  80. package/dist/security/sign.js +0 -666
  81. package/dist/security/verification-enforcer.d.ts +0 -53
  82. package/dist/security/verification-enforcer.js +0 -204
  83. package/dist/services/McpCoreService.d.ts +0 -98
  84. package/dist/services/McpCoreService.js +0 -124
  85. package/dist/services/index.d.ts +0 -1
  86. package/dist/services/index.js +0 -1
  87. package/dist/types.d.ts +0 -132
  88. package/dist/types.js +0 -3
  89. package/dist/utils/config.d.ts +0 -111
  90. package/dist/utils/config.js +0 -342
  91. package/dist/utils/env-loader.d.ts +0 -54
  92. package/dist/utils/env-loader.js +0 -270
  93. package/dist/utils/help.d.ts +0 -36
  94. package/dist/utils/help.js +0 -248
  95. package/dist/utils/index.d.ts +0 -7
  96. package/dist/utils/index.js +0 -7
  97. package/dist/utils/logger.d.ts +0 -35
  98. package/dist/utils/logger.js +0 -75
  99. package/dist/utils/silent-monitor.d.ts +0 -67
  100. package/dist/utils/silent-monitor.js +0 -242
  101. package/dist/utils/timeout.d.ts +0 -5
  102. package/dist/utils/timeout.js +0 -23
  103. package/dist/utils/version.d.ts +0 -4
  104. package/dist/utils/version.js +0 -35
  105. package/dist/web/env-manager-server.d.ts +0 -29
  106. package/dist/web/env-manager-server.js +0 -367
  107. package/dist/web/index.d.ts +0 -1
  108. package/dist/web/index.js +0 -1
  109. package/src/LocalToolResolver.ts +0 -424
  110. package/src/api/enact-api.ts +0 -604
  111. package/src/api/index.ts +0 -2
  112. package/src/api/types.ts +0 -114
  113. package/src/core/DaggerExecutionProvider.ts +0 -1357
  114. package/src/core/DirectExecutionProvider.ts +0 -484
  115. package/src/core/EnactCore.ts +0 -847
  116. package/src/core/index.ts +0 -3
  117. package/src/exec/index.ts +0 -3
  118. package/src/exec/logger.ts +0 -63
  119. package/src/exec/validate.ts +0 -238
  120. package/src/lib/enact-direct.ts +0 -254
  121. package/src/lib/index.ts +0 -1
  122. package/src/services/McpCoreService.ts +0 -201
  123. package/src/services/index.ts +0 -1
  124. package/src/utils/config.ts +0 -438
  125. package/src/utils/env-loader.ts +0 -370
  126. package/src/utils/help.ts +0 -257
  127. package/src/utils/index.ts +0 -7
  128. package/src/utils/silent-monitor.ts +0 -328
  129. package/src/utils/timeout.ts +0 -26
  130. package/src/web/env-manager-server.ts +0 -465
  131. package/src/web/index.ts +0 -1
  132. package/src/web/static/app.js +0 -663
  133. package/src/web/static/index.html +0 -117
  134. package/src/web/static/style.css +0 -291
@@ -1,328 +0,0 @@
1
- /**
2
- * Runtime silent operation monitor for MCP server
3
- * This utility can be used to ensure the MCP server remains silent during operation
4
- */
5
-
6
- interface SilentOperationMonitor {
7
- startMonitoring(): void;
8
- stopMonitoring(): SilentOperationReport;
9
- isCurrentlyMonitoring(): boolean;
10
- getViolations(): string[];
11
- }
12
-
13
- interface SilentOperationReport {
14
- violations: string[];
15
- consoleOutputDetected: string[];
16
- processExitAttempts: number;
17
- readlineUsageDetected: boolean;
18
- duration: number;
19
- timestamp: string;
20
- }
21
-
22
- class McpSilentOperationMonitor implements SilentOperationMonitor {
23
- private isMonitoring = false;
24
- private violations: string[] = [];
25
- private consoleOutput: string[] = [];
26
- private processExitAttempts = 0;
27
- private readlineUsageDetected = false;
28
- private startTime = 0;
29
-
30
- private originalConsoleLog: typeof console.log;
31
- private originalConsoleError: typeof console.error;
32
- private originalConsoleWarn: typeof console.warn;
33
- private originalConsoleInfo: typeof console.info;
34
- private originalProcessExit: typeof process.exit;
35
- private originalStdoutWrite: typeof process.stdout.write;
36
- private originalStderrWrite: typeof process.stderr.write;
37
-
38
- // Public getters for original methods
39
- public getOriginalConsoleError(): typeof console.error {
40
- return this.originalConsoleError;
41
- }
42
-
43
- constructor() {
44
- // Store original methods
45
- this.originalConsoleLog = console.log;
46
- this.originalConsoleError = console.error;
47
- this.originalConsoleWarn = console.warn;
48
- this.originalConsoleInfo = console.info;
49
- this.originalProcessExit = process.exit;
50
- this.originalStdoutWrite = process.stdout.write;
51
- this.originalStderrWrite = process.stderr.write;
52
- }
53
-
54
- startMonitoring(): void {
55
- if (this.isMonitoring) {
56
- return;
57
- }
58
-
59
- this.isMonitoring = true;
60
- this.violations = [];
61
- this.consoleOutput = [];
62
- this.processExitAttempts = 0;
63
- this.readlineUsageDetected = false;
64
- this.startTime = Date.now();
65
-
66
- // Hook console methods
67
- console.log = (...args: any[]) => {
68
- const message = args.join(" ");
69
- this.consoleOutput.push(`[LOG] ${message}`);
70
- this.violations.push(`Console.log called: ${message}`);
71
- };
72
-
73
- console.error = (...args: any[]) => {
74
- const message = args.join(" ");
75
- this.consoleOutput.push(`[ERROR] ${message}`);
76
- this.violations.push(`Console.error called: ${message}`);
77
- };
78
-
79
- console.warn = (...args: any[]) => {
80
- const message = args.join(" ");
81
- this.consoleOutput.push(`[WARN] ${message}`);
82
- this.violations.push(`Console.warn called: ${message}`);
83
- };
84
-
85
- console.info = (...args: any[]) => {
86
- const message = args.join(" ");
87
- this.consoleOutput.push(`[INFO] ${message}`);
88
- this.violations.push(`Console.info called: ${message}`);
89
- };
90
-
91
- // Hook process.exit
92
- process.exit = ((code?: number) => {
93
- this.processExitAttempts++;
94
- this.violations.push(`Process.exit called with code: ${code}`);
95
- throw new Error(`Process exit intercepted: ${code}`);
96
- }) as any;
97
-
98
- // Hook stdout/stderr
99
- process.stdout.write = ((chunk: any, ...args: any[]) => {
100
- if (typeof chunk === "string" && chunk.trim()) {
101
- this.consoleOutput.push(`[STDOUT] ${chunk}`);
102
- this.violations.push(
103
- `Process.stdout.write called: ${chunk.substring(0, 100)}...`,
104
- );
105
- }
106
- return true;
107
- }) as any;
108
-
109
- process.stderr.write = ((chunk: any, ...args: any[]) => {
110
- if (typeof chunk === "string" && chunk.trim()) {
111
- this.consoleOutput.push(`[STDERR] ${chunk}`);
112
- this.violations.push(
113
- `Process.stderr.write called: ${chunk.substring(0, 100)}...`,
114
- );
115
- }
116
- return true;
117
- }) as any;
118
-
119
- // Hook readline (if it gets required)
120
- const originalRequire = require;
121
- const monitor = this;
122
- (global as any).require = function (id: string) {
123
- if (id === "readline" || id.includes("readline")) {
124
- monitor.readlineUsageDetected = true;
125
- monitor.violations.push("Readline module usage detected");
126
- }
127
- return originalRequire.apply(this, arguments as any);
128
- };
129
- }
130
-
131
- stopMonitoring(): SilentOperationReport {
132
- if (!this.isMonitoring) {
133
- throw new Error("Monitor is not currently running");
134
- }
135
-
136
- // Restore original methods
137
- console.log = this.originalConsoleLog;
138
- console.error = this.originalConsoleError;
139
- console.warn = this.originalConsoleWarn;
140
- console.info = this.originalConsoleInfo;
141
- process.exit = this.originalProcessExit;
142
- process.stdout.write = this.originalStdoutWrite;
143
- process.stderr.write = this.originalStderrWrite;
144
-
145
- // Restore require
146
- (global as any).require = require;
147
-
148
- this.isMonitoring = false;
149
-
150
- return {
151
- violations: [...this.violations],
152
- consoleOutputDetected: [...this.consoleOutput],
153
- processExitAttempts: this.processExitAttempts,
154
- readlineUsageDetected: this.readlineUsageDetected,
155
- duration: Date.now() - this.startTime,
156
- timestamp: new Date().toISOString(),
157
- };
158
- }
159
-
160
- isCurrentlyMonitoring(): boolean {
161
- return this.isMonitoring;
162
- }
163
-
164
- getViolations(): string[] {
165
- return [...this.violations];
166
- }
167
- }
168
-
169
- /**
170
- * Global monitor instance
171
- */
172
- const globalMonitor = new McpSilentOperationMonitor();
173
-
174
- /**
175
- * Decorator to ensure a function operates silently
176
- */
177
- export function ensureSilent<T extends (...args: any[]) => any>(fn: T): T {
178
- return ((...args: any[]) => {
179
- const wasMonitoring = globalMonitor.isCurrentlyMonitoring();
180
-
181
- if (!wasMonitoring) {
182
- globalMonitor.startMonitoring();
183
- }
184
-
185
- try {
186
- const result = fn(...args);
187
-
188
- // Handle both sync and async functions
189
- if (result && typeof result.then === "function") {
190
- return result.finally(() => {
191
- if (!wasMonitoring) {
192
- const report = globalMonitor.stopMonitoring();
193
- if (report.violations.length > 0) {
194
- throw new Error(
195
- `Silent operation violated: ${report.violations.join(", ")}`,
196
- );
197
- }
198
- }
199
- });
200
- } else {
201
- if (!wasMonitoring) {
202
- const report = globalMonitor.stopMonitoring();
203
- if (report.violations.length > 0) {
204
- throw new Error(
205
- `Silent operation violated: ${report.violations.join(", ")}`,
206
- );
207
- }
208
- }
209
- return result;
210
- }
211
- } catch (error) {
212
- if (!wasMonitoring && globalMonitor.isCurrentlyMonitoring()) {
213
- globalMonitor.stopMonitoring();
214
- }
215
- throw error;
216
- }
217
- }) as T;
218
- }
219
-
220
- /**
221
- * Higher-order function to wrap MCP tool handlers for silent operation
222
- */
223
- export function silentMcpTool<T extends (...args: any[]) => Promise<any>>(
224
- handler: T,
225
- ): T {
226
- return (async (...args: any[]) => {
227
- const monitor = new McpSilentOperationMonitor();
228
- monitor.startMonitoring();
229
-
230
- try {
231
- const result = await handler(...args);
232
- const report = monitor.stopMonitoring();
233
-
234
- if (report.violations.length > 0) {
235
- // Log violations using the original console methods for debugging
236
- globalMonitor.getOriginalConsoleError()(
237
- "🚨 MCP Tool Handler Violations:",
238
- report.violations,
239
- );
240
-
241
- // In production, you might want to return an error response instead of throwing
242
- if (process.env.NODE_ENV === "production") {
243
- return {
244
- content: [
245
- {
246
- type: "text",
247
- text: "Internal error: Silent operation requirements violated",
248
- },
249
- ],
250
- isError: true,
251
- };
252
- }
253
- }
254
-
255
- return result;
256
- } catch (error) {
257
- const report = monitor.stopMonitoring();
258
-
259
- if (report.violations.length > 0) {
260
- globalMonitor.getOriginalConsoleError()(
261
- "🚨 MCP Tool Handler Violations during error:",
262
- report.violations,
263
- );
264
- }
265
-
266
- throw error;
267
- }
268
- }) as T;
269
- }
270
-
271
- /**
272
- * Utility to check if environment is properly configured for silent operation
273
- */
274
- export function validateSilentEnvironment(): {
275
- valid: boolean;
276
- issues: string[];
277
- } {
278
- const issues: string[] = [];
279
-
280
- // Check environment variables
281
- if (process.env.CI !== "true") {
282
- issues.push('CI environment variable not set to "true"');
283
- }
284
-
285
- if (process.env.ENACT_SKIP_INTERACTIVE !== "true") {
286
- issues.push('ENACT_SKIP_INTERACTIVE not set to "true"');
287
- }
288
-
289
- if (process.env.DEBUG === "true" || process.env.VERBOSE === "true") {
290
- issues.push("DEBUG or VERBOSE environment variables are enabled");
291
- }
292
-
293
- // Check if we're in a TTY (which might indicate interactive mode)
294
- if (process.stdin.isTTY) {
295
- issues.push("Process is running in TTY mode (potentially interactive)");
296
- }
297
-
298
- return {
299
- valid: issues.length === 0,
300
- issues,
301
- };
302
- }
303
-
304
- /**
305
- * Logger specifically for MCP silent operation monitoring
306
- */
307
- export const silentLogger = {
308
- logViolation: (violation: string) => {
309
- // Use stderr directly to bypass any console mocking
310
- process.stderr.write(
311
- `[SILENT-VIOLATION] ${new Date().toISOString()}: ${violation}\n`,
312
- );
313
- },
314
-
315
- logReport: (report: SilentOperationReport) => {
316
- if (report.violations.length > 0) {
317
- process.stderr.write(
318
- `[SILENT-REPORT] ${report.timestamp}: ${report.violations.length} violations in ${report.duration}ms\n`,
319
- );
320
- report.violations.forEach((violation) => {
321
- process.stderr.write(` - ${violation}\n`);
322
- });
323
- }
324
- },
325
- };
326
-
327
- export { globalMonitor, McpSilentOperationMonitor };
328
- export type { SilentOperationMonitor, SilentOperationReport };
@@ -1,26 +0,0 @@
1
- // src/utils/timeout.ts - Shared timeout parsing utility
2
-
3
- /**
4
- * Parse timeout string to milliseconds
5
- * Supports formats like "30s", "5m", "2h"
6
- */
7
- export function parseTimeout(timeout: string): number {
8
- const match = timeout.match(/^(\d+)([smh])$/);
9
- if (!match) {
10
- return 30000; // Default 30 seconds
11
- }
12
-
13
- const value = parseInt(match[1]);
14
- const unit = match[2];
15
-
16
- switch (unit) {
17
- case "s":
18
- return value * 1000;
19
- case "m":
20
- return value * 60 * 1000;
21
- case "h":
22
- return value * 60 * 60 * 1000;
23
- default:
24
- return 30000; // Default fallback
25
- }
26
- }