@enactprotocol/shared 1.2.13 → 2.0.1

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 (207) hide show
  1. package/README.md +44 -0
  2. package/dist/config.d.ts +164 -0
  3. package/dist/config.d.ts.map +1 -0
  4. package/dist/config.js +386 -0
  5. package/dist/config.js.map +1 -0
  6. package/dist/constants.d.ts +15 -5
  7. package/dist/constants.d.ts.map +1 -0
  8. package/dist/constants.js +24 -8
  9. package/dist/constants.js.map +1 -0
  10. package/dist/execution/command.d.ts +102 -0
  11. package/dist/execution/command.d.ts.map +1 -0
  12. package/dist/execution/command.js +262 -0
  13. package/dist/execution/command.js.map +1 -0
  14. package/dist/execution/index.d.ts +12 -0
  15. package/dist/execution/index.d.ts.map +1 -0
  16. package/dist/execution/index.js +17 -0
  17. package/dist/execution/index.js.map +1 -0
  18. package/dist/execution/runtime.d.ts +82 -0
  19. package/dist/execution/runtime.d.ts.map +1 -0
  20. package/dist/execution/runtime.js +273 -0
  21. package/dist/execution/runtime.js.map +1 -0
  22. package/dist/execution/types.d.ts +306 -0
  23. package/dist/execution/types.d.ts.map +1 -0
  24. package/dist/execution/types.js +14 -0
  25. package/dist/execution/types.js.map +1 -0
  26. package/dist/execution/validation.d.ts +43 -0
  27. package/dist/execution/validation.d.ts.map +1 -0
  28. package/dist/execution/validation.js +430 -0
  29. package/dist/execution/validation.js.map +1 -0
  30. package/dist/index.d.ts +21 -21
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +49 -25
  33. package/dist/index.js.map +1 -0
  34. package/dist/manifest/index.d.ts +7 -0
  35. package/dist/manifest/index.d.ts.map +1 -0
  36. package/dist/manifest/index.js +10 -0
  37. package/dist/manifest/index.js.map +1 -0
  38. package/dist/manifest/loader.d.ts +76 -0
  39. package/dist/manifest/loader.d.ts.map +1 -0
  40. package/dist/manifest/loader.js +146 -0
  41. package/dist/manifest/loader.js.map +1 -0
  42. package/dist/manifest/parser.d.ts +64 -0
  43. package/dist/manifest/parser.d.ts.map +1 -0
  44. package/dist/manifest/parser.js +135 -0
  45. package/dist/manifest/parser.js.map +1 -0
  46. package/dist/manifest/validator.d.ts +95 -0
  47. package/dist/manifest/validator.d.ts.map +1 -0
  48. package/dist/manifest/validator.js +258 -0
  49. package/dist/manifest/validator.js.map +1 -0
  50. package/dist/paths.d.ts +57 -0
  51. package/dist/paths.d.ts.map +1 -0
  52. package/dist/paths.js +93 -0
  53. package/dist/paths.js.map +1 -0
  54. package/dist/registry.d.ts +73 -0
  55. package/dist/registry.d.ts.map +1 -0
  56. package/dist/registry.js +147 -0
  57. package/dist/registry.js.map +1 -0
  58. package/dist/resolver.d.ts +89 -0
  59. package/dist/resolver.d.ts.map +1 -0
  60. package/dist/resolver.js +282 -0
  61. package/dist/resolver.js.map +1 -0
  62. package/dist/types/index.d.ts +6 -0
  63. package/dist/types/index.d.ts.map +1 -0
  64. package/dist/types/index.js +5 -0
  65. package/dist/types/index.js.map +1 -0
  66. package/dist/types/manifest.d.ts +201 -0
  67. package/dist/types/manifest.d.ts.map +1 -0
  68. package/dist/types/manifest.js +13 -0
  69. package/dist/types/manifest.js.map +1 -0
  70. package/dist/types.d.ts +5 -132
  71. package/dist/types.d.ts.map +1 -0
  72. package/dist/types.js +5 -3
  73. package/dist/types.js.map +1 -0
  74. package/dist/utils/fs.d.ts +105 -0
  75. package/dist/utils/fs.d.ts.map +1 -0
  76. package/dist/utils/fs.js +233 -0
  77. package/dist/utils/fs.js.map +1 -0
  78. package/dist/utils/logger.d.ts +102 -25
  79. package/dist/utils/logger.d.ts.map +1 -0
  80. package/dist/utils/logger.js +214 -57
  81. package/dist/utils/logger.js.map +1 -0
  82. package/dist/utils/version.d.ts +60 -2
  83. package/dist/utils/version.d.ts.map +1 -0
  84. package/dist/utils/version.js +255 -31
  85. package/dist/utils/version.js.map +1 -0
  86. package/package.json +16 -58
  87. package/src/config.ts +510 -0
  88. package/src/constants.ts +36 -0
  89. package/src/execution/command.ts +314 -0
  90. package/src/execution/index.ts +73 -0
  91. package/src/execution/runtime.ts +308 -0
  92. package/src/execution/types.ts +379 -0
  93. package/src/execution/validation.ts +508 -0
  94. package/src/index.ts +238 -30
  95. package/src/manifest/index.ts +36 -0
  96. package/src/manifest/loader.ts +187 -0
  97. package/src/manifest/parser.ts +173 -0
  98. package/src/manifest/validator.ts +309 -0
  99. package/src/paths.ts +108 -0
  100. package/src/registry.ts +219 -0
  101. package/src/resolver.ts +345 -0
  102. package/src/types/index.ts +30 -0
  103. package/src/types/manifest.ts +255 -0
  104. package/src/types.ts +5 -188
  105. package/src/utils/fs.ts +281 -0
  106. package/src/utils/logger.ts +270 -59
  107. package/src/utils/version.ts +304 -36
  108. package/tests/config.test.ts +515 -0
  109. package/tests/execution/command.test.ts +317 -0
  110. package/tests/execution/validation.test.ts +384 -0
  111. package/tests/fixtures/invalid-tool.yaml +4 -0
  112. package/tests/fixtures/valid-tool.md +62 -0
  113. package/tests/fixtures/valid-tool.yaml +40 -0
  114. package/tests/index.test.ts +8 -0
  115. package/tests/manifest/loader.test.ts +291 -0
  116. package/tests/manifest/parser.test.ts +345 -0
  117. package/tests/manifest/validator.test.ts +394 -0
  118. package/tests/manifest-types.test.ts +358 -0
  119. package/tests/paths.test.ts +153 -0
  120. package/tests/registry.test.ts +231 -0
  121. package/tests/resolver.test.ts +272 -0
  122. package/tests/utils/fs.test.ts +388 -0
  123. package/tests/utils/logger.test.ts +480 -0
  124. package/tests/utils/version.test.ts +390 -0
  125. package/tsconfig.json +12 -0
  126. package/dist/LocalToolResolver.d.ts +0 -84
  127. package/dist/LocalToolResolver.js +0 -353
  128. package/dist/api/enact-api.d.ts +0 -130
  129. package/dist/api/enact-api.js +0 -428
  130. package/dist/api/index.d.ts +0 -2
  131. package/dist/api/index.js +0 -2
  132. package/dist/api/types.d.ts +0 -103
  133. package/dist/api/types.js +0 -1
  134. package/dist/core/DaggerExecutionProvider.d.ts +0 -169
  135. package/dist/core/DaggerExecutionProvider.js +0 -1029
  136. package/dist/core/DirectExecutionProvider.d.ts +0 -23
  137. package/dist/core/DirectExecutionProvider.js +0 -406
  138. package/dist/core/EnactCore.d.ts +0 -162
  139. package/dist/core/EnactCore.js +0 -597
  140. package/dist/core/NativeExecutionProvider.d.ts +0 -9
  141. package/dist/core/NativeExecutionProvider.js +0 -16
  142. package/dist/core/index.d.ts +0 -3
  143. package/dist/core/index.js +0 -3
  144. package/dist/exec/index.d.ts +0 -3
  145. package/dist/exec/index.js +0 -3
  146. package/dist/exec/logger.d.ts +0 -11
  147. package/dist/exec/logger.js +0 -57
  148. package/dist/exec/validate.d.ts +0 -5
  149. package/dist/exec/validate.js +0 -167
  150. package/dist/lib/enact-direct.d.ts +0 -150
  151. package/dist/lib/enact-direct.js +0 -159
  152. package/dist/lib/index.d.ts +0 -1
  153. package/dist/lib/index.js +0 -1
  154. package/dist/security/index.d.ts +0 -3
  155. package/dist/security/index.js +0 -3
  156. package/dist/security/security.d.ts +0 -23
  157. package/dist/security/security.js +0 -137
  158. package/dist/security/sign.d.ts +0 -103
  159. package/dist/security/sign.js +0 -666
  160. package/dist/security/verification-enforcer.d.ts +0 -53
  161. package/dist/security/verification-enforcer.js +0 -204
  162. package/dist/services/McpCoreService.d.ts +0 -98
  163. package/dist/services/McpCoreService.js +0 -124
  164. package/dist/services/index.d.ts +0 -1
  165. package/dist/services/index.js +0 -1
  166. package/dist/utils/config.d.ts +0 -111
  167. package/dist/utils/config.js +0 -342
  168. package/dist/utils/env-loader.d.ts +0 -54
  169. package/dist/utils/env-loader.js +0 -270
  170. package/dist/utils/help.d.ts +0 -36
  171. package/dist/utils/help.js +0 -248
  172. package/dist/utils/index.d.ts +0 -7
  173. package/dist/utils/index.js +0 -7
  174. package/dist/utils/silent-monitor.d.ts +0 -67
  175. package/dist/utils/silent-monitor.js +0 -242
  176. package/dist/utils/timeout.d.ts +0 -5
  177. package/dist/utils/timeout.js +0 -23
  178. package/dist/web/env-manager-server.d.ts +0 -29
  179. package/dist/web/env-manager-server.js +0 -367
  180. package/dist/web/index.d.ts +0 -1
  181. package/dist/web/index.js +0 -1
  182. package/src/LocalToolResolver.ts +0 -424
  183. package/src/api/enact-api.ts +0 -604
  184. package/src/api/index.ts +0 -2
  185. package/src/api/types.ts +0 -114
  186. package/src/core/DaggerExecutionProvider.ts +0 -1357
  187. package/src/core/DirectExecutionProvider.ts +0 -484
  188. package/src/core/EnactCore.ts +0 -847
  189. package/src/core/index.ts +0 -3
  190. package/src/exec/index.ts +0 -3
  191. package/src/exec/logger.ts +0 -63
  192. package/src/exec/validate.ts +0 -238
  193. package/src/lib/enact-direct.ts +0 -254
  194. package/src/lib/index.ts +0 -1
  195. package/src/services/McpCoreService.ts +0 -201
  196. package/src/services/index.ts +0 -1
  197. package/src/utils/config.ts +0 -438
  198. package/src/utils/env-loader.ts +0 -370
  199. package/src/utils/help.ts +0 -257
  200. package/src/utils/index.ts +0 -7
  201. package/src/utils/silent-monitor.ts +0 -328
  202. package/src/utils/timeout.ts +0 -26
  203. package/src/web/env-manager-server.ts +0 -465
  204. package/src/web/index.ts +0 -1
  205. package/src/web/static/app.js +0 -663
  206. package/src/web/static/index.html +0 -117
  207. 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
- }