@enactprotocol/shared 1.0.12

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 (97) hide show
  1. package/dist/LocalToolResolver.d.ts +84 -0
  2. package/dist/LocalToolResolver.js +353 -0
  3. package/dist/api/enact-api.d.ts +124 -0
  4. package/dist/api/enact-api.js +406 -0
  5. package/dist/api/index.d.ts +2 -0
  6. package/dist/api/index.js +2 -0
  7. package/dist/api/types.d.ts +83 -0
  8. package/dist/api/types.js +1 -0
  9. package/dist/core/DaggerExecutionProvider.d.ts +169 -0
  10. package/dist/core/DaggerExecutionProvider.js +996 -0
  11. package/dist/core/DirectExecutionProvider.d.ts +23 -0
  12. package/dist/core/DirectExecutionProvider.js +406 -0
  13. package/dist/core/EnactCore.d.ts +138 -0
  14. package/dist/core/EnactCore.js +609 -0
  15. package/dist/core/index.d.ts +3 -0
  16. package/dist/core/index.js +3 -0
  17. package/dist/exec/index.d.ts +3 -0
  18. package/dist/exec/index.js +3 -0
  19. package/dist/exec/logger.d.ts +11 -0
  20. package/dist/exec/logger.js +57 -0
  21. package/dist/exec/validate.d.ts +5 -0
  22. package/dist/exec/validate.js +167 -0
  23. package/dist/index.d.ts +25 -0
  24. package/dist/index.js +29 -0
  25. package/dist/lib/enact-direct.d.ts +156 -0
  26. package/dist/lib/enact-direct.js +158 -0
  27. package/dist/lib/index.d.ts +1 -0
  28. package/dist/lib/index.js +1 -0
  29. package/dist/security/index.d.ts +3 -0
  30. package/dist/security/index.js +3 -0
  31. package/dist/security/security.d.ts +23 -0
  32. package/dist/security/security.js +137 -0
  33. package/dist/security/sign.d.ts +103 -0
  34. package/dist/security/sign.js +532 -0
  35. package/dist/security/verification-enforcer.d.ts +41 -0
  36. package/dist/security/verification-enforcer.js +181 -0
  37. package/dist/services/McpCoreService.d.ts +102 -0
  38. package/dist/services/McpCoreService.js +120 -0
  39. package/dist/services/index.d.ts +1 -0
  40. package/dist/services/index.js +1 -0
  41. package/dist/types.d.ts +130 -0
  42. package/dist/types.js +3 -0
  43. package/dist/utils/config.d.ts +32 -0
  44. package/dist/utils/config.js +78 -0
  45. package/dist/utils/env-loader.d.ts +54 -0
  46. package/dist/utils/env-loader.js +270 -0
  47. package/dist/utils/help.d.ts +36 -0
  48. package/dist/utils/help.js +248 -0
  49. package/dist/utils/index.d.ts +7 -0
  50. package/dist/utils/index.js +7 -0
  51. package/dist/utils/logger.d.ts +35 -0
  52. package/dist/utils/logger.js +75 -0
  53. package/dist/utils/silent-monitor.d.ts +67 -0
  54. package/dist/utils/silent-monitor.js +242 -0
  55. package/dist/utils/timeout.d.ts +5 -0
  56. package/dist/utils/timeout.js +23 -0
  57. package/dist/utils/version.d.ts +4 -0
  58. package/dist/utils/version.js +14 -0
  59. package/dist/web/env-manager-server.d.ts +29 -0
  60. package/dist/web/env-manager-server.js +367 -0
  61. package/dist/web/index.d.ts +1 -0
  62. package/dist/web/index.js +1 -0
  63. package/package.json +79 -0
  64. package/src/LocalToolResolver.ts +424 -0
  65. package/src/api/enact-api.ts +569 -0
  66. package/src/api/index.ts +2 -0
  67. package/src/api/types.ts +93 -0
  68. package/src/core/DaggerExecutionProvider.ts +1308 -0
  69. package/src/core/DirectExecutionProvider.ts +484 -0
  70. package/src/core/EnactCore.ts +833 -0
  71. package/src/core/index.ts +3 -0
  72. package/src/exec/index.ts +3 -0
  73. package/src/exec/logger.ts +63 -0
  74. package/src/exec/validate.ts +238 -0
  75. package/src/index.ts +42 -0
  76. package/src/lib/enact-direct.ts +258 -0
  77. package/src/lib/index.ts +1 -0
  78. package/src/security/index.ts +3 -0
  79. package/src/security/security.ts +188 -0
  80. package/src/security/sign.ts +797 -0
  81. package/src/security/verification-enforcer.ts +268 -0
  82. package/src/services/McpCoreService.ts +203 -0
  83. package/src/services/index.ts +1 -0
  84. package/src/types.ts +190 -0
  85. package/src/utils/config.ts +97 -0
  86. package/src/utils/env-loader.ts +370 -0
  87. package/src/utils/help.ts +257 -0
  88. package/src/utils/index.ts +7 -0
  89. package/src/utils/logger.ts +83 -0
  90. package/src/utils/silent-monitor.ts +328 -0
  91. package/src/utils/timeout.ts +26 -0
  92. package/src/utils/version.ts +16 -0
  93. package/src/web/env-manager-server.ts +465 -0
  94. package/src/web/index.ts +1 -0
  95. package/src/web/static/app.js +663 -0
  96. package/src/web/static/index.html +117 -0
  97. package/src/web/static/style.css +291 -0
@@ -0,0 +1,75 @@
1
+ // src/utils/logger.ts
2
+ import pc from "picocolors";
3
+ export var LogLevel;
4
+ (function (LogLevel) {
5
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
6
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
7
+ LogLevel[LogLevel["SUCCESS"] = 2] = "SUCCESS";
8
+ LogLevel[LogLevel["WARN"] = 3] = "WARN";
9
+ LogLevel[LogLevel["ERROR"] = 4] = "ERROR";
10
+ })(LogLevel || (LogLevel = {}));
11
+ // Default log level
12
+ let currentLogLevel = LogLevel.INFO;
13
+ /**
14
+ * Sets the current log level
15
+ */
16
+ export function setLogLevel(level) {
17
+ currentLogLevel = level;
18
+ }
19
+ /**
20
+ * Debug log - only shown when log level is DEBUG
21
+ */
22
+ export function debug(message) {
23
+ if (currentLogLevel <= LogLevel.DEBUG) {
24
+ console.error(pc.dim(`🔍 ${message}`));
25
+ }
26
+ }
27
+ /**
28
+ * Info log - general information
29
+ */
30
+ export function info(message) {
31
+ if (currentLogLevel <= LogLevel.INFO) {
32
+ console.error(pc.blue(`ℹ️ ${message}`));
33
+ }
34
+ }
35
+ /**
36
+ * Success log - operation completed successfully
37
+ */
38
+ export function success(message) {
39
+ if (currentLogLevel <= LogLevel.SUCCESS) {
40
+ console.error(pc.green(`✓ ${message}`));
41
+ }
42
+ }
43
+ /**
44
+ * Warning log - non-critical issues
45
+ */
46
+ export function warn(message) {
47
+ if (currentLogLevel <= LogLevel.WARN) {
48
+ console.error(pc.yellow(`⚠️ ${message}`));
49
+ }
50
+ }
51
+ /**
52
+ * Error log - critical issues
53
+ */
54
+ export function error(message, details) {
55
+ if (currentLogLevel <= LogLevel.ERROR) {
56
+ console.error(pc.red(`✗ Error: ${message}`));
57
+ if (details && currentLogLevel === LogLevel.DEBUG) {
58
+ console.error(pc.dim("Details:"));
59
+ console.error(details);
60
+ }
61
+ }
62
+ }
63
+ /**
64
+ * Table log - display tabular data
65
+ */
66
+ export function table(data, columns) {
67
+ if (currentLogLevel <= LogLevel.INFO) {
68
+ if (columns) {
69
+ console.table(data, columns);
70
+ }
71
+ else {
72
+ console.table(data);
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,67 @@
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
+ interface SilentOperationMonitor {
6
+ startMonitoring(): void;
7
+ stopMonitoring(): SilentOperationReport;
8
+ isCurrentlyMonitoring(): boolean;
9
+ getViolations(): string[];
10
+ }
11
+ interface SilentOperationReport {
12
+ violations: string[];
13
+ consoleOutputDetected: string[];
14
+ processExitAttempts: number;
15
+ readlineUsageDetected: boolean;
16
+ duration: number;
17
+ timestamp: string;
18
+ }
19
+ declare class McpSilentOperationMonitor implements SilentOperationMonitor {
20
+ private isMonitoring;
21
+ private violations;
22
+ private consoleOutput;
23
+ private processExitAttempts;
24
+ private readlineUsageDetected;
25
+ private startTime;
26
+ private originalConsoleLog;
27
+ private originalConsoleError;
28
+ private originalConsoleWarn;
29
+ private originalConsoleInfo;
30
+ private originalProcessExit;
31
+ private originalStdoutWrite;
32
+ private originalStderrWrite;
33
+ getOriginalConsoleError(): typeof console.error;
34
+ constructor();
35
+ startMonitoring(): void;
36
+ stopMonitoring(): SilentOperationReport;
37
+ isCurrentlyMonitoring(): boolean;
38
+ getViolations(): string[];
39
+ }
40
+ /**
41
+ * Global monitor instance
42
+ */
43
+ declare const globalMonitor: McpSilentOperationMonitor;
44
+ /**
45
+ * Decorator to ensure a function operates silently
46
+ */
47
+ export declare function ensureSilent<T extends (...args: any[]) => any>(fn: T): T;
48
+ /**
49
+ * Higher-order function to wrap MCP tool handlers for silent operation
50
+ */
51
+ export declare function silentMcpTool<T extends (...args: any[]) => Promise<any>>(handler: T): T;
52
+ /**
53
+ * Utility to check if environment is properly configured for silent operation
54
+ */
55
+ export declare function validateSilentEnvironment(): {
56
+ valid: boolean;
57
+ issues: string[];
58
+ };
59
+ /**
60
+ * Logger specifically for MCP silent operation monitoring
61
+ */
62
+ export declare const silentLogger: {
63
+ logViolation: (violation: string) => void;
64
+ logReport: (report: SilentOperationReport) => void;
65
+ };
66
+ export { globalMonitor, McpSilentOperationMonitor };
67
+ export type { SilentOperationMonitor, SilentOperationReport };
@@ -0,0 +1,242 @@
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
+ class McpSilentOperationMonitor {
6
+ // Public getters for original methods
7
+ getOriginalConsoleError() {
8
+ return this.originalConsoleError;
9
+ }
10
+ constructor() {
11
+ this.isMonitoring = false;
12
+ this.violations = [];
13
+ this.consoleOutput = [];
14
+ this.processExitAttempts = 0;
15
+ this.readlineUsageDetected = false;
16
+ this.startTime = 0;
17
+ // Store original methods
18
+ this.originalConsoleLog = console.log;
19
+ this.originalConsoleError = console.error;
20
+ this.originalConsoleWarn = console.warn;
21
+ this.originalConsoleInfo = console.info;
22
+ this.originalProcessExit = process.exit;
23
+ this.originalStdoutWrite = process.stdout.write;
24
+ this.originalStderrWrite = process.stderr.write;
25
+ }
26
+ startMonitoring() {
27
+ if (this.isMonitoring) {
28
+ return;
29
+ }
30
+ this.isMonitoring = true;
31
+ this.violations = [];
32
+ this.consoleOutput = [];
33
+ this.processExitAttempts = 0;
34
+ this.readlineUsageDetected = false;
35
+ this.startTime = Date.now();
36
+ // Hook console methods
37
+ console.log = (...args) => {
38
+ const message = args.join(" ");
39
+ this.consoleOutput.push(`[LOG] ${message}`);
40
+ this.violations.push(`Console.log called: ${message}`);
41
+ };
42
+ console.error = (...args) => {
43
+ const message = args.join(" ");
44
+ this.consoleOutput.push(`[ERROR] ${message}`);
45
+ this.violations.push(`Console.error called: ${message}`);
46
+ };
47
+ console.warn = (...args) => {
48
+ const message = args.join(" ");
49
+ this.consoleOutput.push(`[WARN] ${message}`);
50
+ this.violations.push(`Console.warn called: ${message}`);
51
+ };
52
+ console.info = (...args) => {
53
+ const message = args.join(" ");
54
+ this.consoleOutput.push(`[INFO] ${message}`);
55
+ this.violations.push(`Console.info called: ${message}`);
56
+ };
57
+ // Hook process.exit
58
+ process.exit = ((code) => {
59
+ this.processExitAttempts++;
60
+ this.violations.push(`Process.exit called with code: ${code}`);
61
+ throw new Error(`Process exit intercepted: ${code}`);
62
+ });
63
+ // Hook stdout/stderr
64
+ process.stdout.write = ((chunk, ...args) => {
65
+ if (typeof chunk === "string" && chunk.trim()) {
66
+ this.consoleOutput.push(`[STDOUT] ${chunk}`);
67
+ this.violations.push(`Process.stdout.write called: ${chunk.substring(0, 100)}...`);
68
+ }
69
+ return true;
70
+ });
71
+ process.stderr.write = ((chunk, ...args) => {
72
+ if (typeof chunk === "string" && chunk.trim()) {
73
+ this.consoleOutput.push(`[STDERR] ${chunk}`);
74
+ this.violations.push(`Process.stderr.write called: ${chunk.substring(0, 100)}...`);
75
+ }
76
+ return true;
77
+ });
78
+ // Hook readline (if it gets required)
79
+ const originalRequire = require;
80
+ const monitor = this;
81
+ global.require = function (id) {
82
+ if (id === "readline" || id.includes("readline")) {
83
+ monitor.readlineUsageDetected = true;
84
+ monitor.violations.push("Readline module usage detected");
85
+ }
86
+ return originalRequire.apply(this, arguments);
87
+ };
88
+ }
89
+ stopMonitoring() {
90
+ if (!this.isMonitoring) {
91
+ throw new Error("Monitor is not currently running");
92
+ }
93
+ // Restore original methods
94
+ console.log = this.originalConsoleLog;
95
+ console.error = this.originalConsoleError;
96
+ console.warn = this.originalConsoleWarn;
97
+ console.info = this.originalConsoleInfo;
98
+ process.exit = this.originalProcessExit;
99
+ process.stdout.write = this.originalStdoutWrite;
100
+ process.stderr.write = this.originalStderrWrite;
101
+ // Restore require
102
+ global.require = require;
103
+ this.isMonitoring = false;
104
+ return {
105
+ violations: [...this.violations],
106
+ consoleOutputDetected: [...this.consoleOutput],
107
+ processExitAttempts: this.processExitAttempts,
108
+ readlineUsageDetected: this.readlineUsageDetected,
109
+ duration: Date.now() - this.startTime,
110
+ timestamp: new Date().toISOString(),
111
+ };
112
+ }
113
+ isCurrentlyMonitoring() {
114
+ return this.isMonitoring;
115
+ }
116
+ getViolations() {
117
+ return [...this.violations];
118
+ }
119
+ }
120
+ /**
121
+ * Global monitor instance
122
+ */
123
+ const globalMonitor = new McpSilentOperationMonitor();
124
+ /**
125
+ * Decorator to ensure a function operates silently
126
+ */
127
+ export function ensureSilent(fn) {
128
+ return ((...args) => {
129
+ const wasMonitoring = globalMonitor.isCurrentlyMonitoring();
130
+ if (!wasMonitoring) {
131
+ globalMonitor.startMonitoring();
132
+ }
133
+ try {
134
+ const result = fn(...args);
135
+ // Handle both sync and async functions
136
+ if (result && typeof result.then === "function") {
137
+ return result.finally(() => {
138
+ if (!wasMonitoring) {
139
+ const report = globalMonitor.stopMonitoring();
140
+ if (report.violations.length > 0) {
141
+ throw new Error(`Silent operation violated: ${report.violations.join(", ")}`);
142
+ }
143
+ }
144
+ });
145
+ }
146
+ else {
147
+ if (!wasMonitoring) {
148
+ const report = globalMonitor.stopMonitoring();
149
+ if (report.violations.length > 0) {
150
+ throw new Error(`Silent operation violated: ${report.violations.join(", ")}`);
151
+ }
152
+ }
153
+ return result;
154
+ }
155
+ }
156
+ catch (error) {
157
+ if (!wasMonitoring && globalMonitor.isCurrentlyMonitoring()) {
158
+ globalMonitor.stopMonitoring();
159
+ }
160
+ throw error;
161
+ }
162
+ });
163
+ }
164
+ /**
165
+ * Higher-order function to wrap MCP tool handlers for silent operation
166
+ */
167
+ export function silentMcpTool(handler) {
168
+ return (async (...args) => {
169
+ const monitor = new McpSilentOperationMonitor();
170
+ monitor.startMonitoring();
171
+ try {
172
+ const result = await handler(...args);
173
+ const report = monitor.stopMonitoring();
174
+ if (report.violations.length > 0) {
175
+ // Log violations using the original console methods for debugging
176
+ globalMonitor.getOriginalConsoleError()("🚨 MCP Tool Handler Violations:", report.violations);
177
+ // In production, you might want to return an error response instead of throwing
178
+ if (process.env.NODE_ENV === "production") {
179
+ return {
180
+ content: [
181
+ {
182
+ type: "text",
183
+ text: "Internal error: Silent operation requirements violated",
184
+ },
185
+ ],
186
+ isError: true,
187
+ };
188
+ }
189
+ }
190
+ return result;
191
+ }
192
+ catch (error) {
193
+ const report = monitor.stopMonitoring();
194
+ if (report.violations.length > 0) {
195
+ globalMonitor.getOriginalConsoleError()("🚨 MCP Tool Handler Violations during error:", report.violations);
196
+ }
197
+ throw error;
198
+ }
199
+ });
200
+ }
201
+ /**
202
+ * Utility to check if environment is properly configured for silent operation
203
+ */
204
+ export function validateSilentEnvironment() {
205
+ const issues = [];
206
+ // Check environment variables
207
+ if (process.env.CI !== "true") {
208
+ issues.push('CI environment variable not set to "true"');
209
+ }
210
+ if (process.env.ENACT_SKIP_INTERACTIVE !== "true") {
211
+ issues.push('ENACT_SKIP_INTERACTIVE not set to "true"');
212
+ }
213
+ if (process.env.DEBUG === "true" || process.env.VERBOSE === "true") {
214
+ issues.push("DEBUG or VERBOSE environment variables are enabled");
215
+ }
216
+ // Check if we're in a TTY (which might indicate interactive mode)
217
+ if (process.stdin.isTTY) {
218
+ issues.push("Process is running in TTY mode (potentially interactive)");
219
+ }
220
+ return {
221
+ valid: issues.length === 0,
222
+ issues,
223
+ };
224
+ }
225
+ /**
226
+ * Logger specifically for MCP silent operation monitoring
227
+ */
228
+ export const silentLogger = {
229
+ logViolation: (violation) => {
230
+ // Use stderr directly to bypass any console mocking
231
+ process.stderr.write(`[SILENT-VIOLATION] ${new Date().toISOString()}: ${violation}\n`);
232
+ },
233
+ logReport: (report) => {
234
+ if (report.violations.length > 0) {
235
+ process.stderr.write(`[SILENT-REPORT] ${report.timestamp}: ${report.violations.length} violations in ${report.duration}ms\n`);
236
+ report.violations.forEach((violation) => {
237
+ process.stderr.write(` - ${violation}\n`);
238
+ });
239
+ }
240
+ },
241
+ };
242
+ export { globalMonitor, McpSilentOperationMonitor };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Parse timeout string to milliseconds
3
+ * Supports formats like "30s", "5m", "2h"
4
+ */
5
+ export declare function parseTimeout(timeout: string): number;
@@ -0,0 +1,23 @@
1
+ // src/utils/timeout.ts - Shared timeout parsing utility
2
+ /**
3
+ * Parse timeout string to milliseconds
4
+ * Supports formats like "30s", "5m", "2h"
5
+ */
6
+ export function parseTimeout(timeout) {
7
+ const match = timeout.match(/^(\d+)([smh])$/);
8
+ if (!match) {
9
+ return 30000; // Default 30 seconds
10
+ }
11
+ const value = parseInt(match[1]);
12
+ const unit = match[2];
13
+ switch (unit) {
14
+ case "s":
15
+ return value * 1000;
16
+ case "m":
17
+ return value * 60 * 1000;
18
+ case "h":
19
+ return value * 60 * 60 * 1000;
20
+ default:
21
+ return 30000; // Default fallback
22
+ }
23
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Displays the CLI version with nice formatting
3
+ */
4
+ export declare function showVersion(): void;
@@ -0,0 +1,14 @@
1
+ // src/utils/version.ts
2
+ import pc from "picocolors";
3
+ /**
4
+ * Displays the CLI version with nice formatting
5
+ */
6
+ export function showVersion() {
7
+ // Bun automatically sets npm_package_version when running scripts via package.json
8
+ const version = process.env.npm_package_version || "0.0.1-dev";
9
+ const versionText = `v${version}`;
10
+ console.error(`
11
+ ${pc.bold("Enact CLI")} ${pc.cyan(versionText)}
12
+ ${pc.dim("A tool to create and publish enact documents.")}
13
+ `);
14
+ }
@@ -0,0 +1,29 @@
1
+ interface PackageEnvInfo {
2
+ namespace: string;
3
+ path: string;
4
+ variables: Record<string, string>;
5
+ }
6
+ /**
7
+ * Get all package namespaces with environment variables
8
+ */
9
+ declare function getAllPackageNamespaces(): Promise<PackageEnvInfo[]>;
10
+ /**
11
+ * Get environment variables for a specific package namespace
12
+ */
13
+ declare function getPackageEnvVars(namespace: string): Promise<Record<string, string>>;
14
+ /**
15
+ * Set environment variable for a package namespace
16
+ */
17
+ declare function setPackageEnvVar(namespace: string, key: string, value: string): Promise<void>;
18
+ /**
19
+ * Delete environment variable for a package namespace
20
+ */
21
+ declare function deletePackageEnvVar(namespace: string, key: string): Promise<void>;
22
+ /**
23
+ * Start the web server
24
+ */
25
+ export declare function startEnvManagerServer(port?: number): Promise<{
26
+ server: any;
27
+ port: number;
28
+ }>;
29
+ export { getAllPackageNamespaces, getPackageEnvVars, setPackageEnvVar, deletePackageEnvVar, };