@enactprotocol/shared 1.2.13 → 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,67 +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
- 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 };
@@ -1,242 +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
- 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 };
@@ -1,5 +0,0 @@
1
- /**
2
- * Parse timeout string to milliseconds
3
- * Supports formats like "30s", "5m", "2h"
4
- */
5
- export declare function parseTimeout(timeout: string): number;
@@ -1,23 +0,0 @@
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
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * Displays the CLI version with nice formatting
3
- */
4
- export declare function showVersion(): void;
@@ -1,35 +0,0 @@
1
- // src/utils/version.ts
2
- import pc from "picocolors";
3
- import { readFileSync } from "fs";
4
- import { join, dirname } from "path";
5
- import { fileURLToPath } from "url";
6
- /**
7
- * Displays the CLI version with nice formatting
8
- */
9
- export function showVersion() {
10
- let version = "0.0.1-dev";
11
- try {
12
- // Try to get version from environment first (for npm scripts)
13
- if (process.env.npm_package_version) {
14
- version = process.env.npm_package_version;
15
- }
16
- else {
17
- // When running as installed binary, read from package.json
18
- // Go up from shared/dist/utils/version.js to find package.json
19
- const currentFile = typeof __filename !== 'undefined' ? __filename : fileURLToPath(import.meta.url);
20
- const sharedDir = dirname(dirname(dirname(currentFile)));
21
- const packageJsonPath = join(sharedDir, 'package.json');
22
- const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
23
- version = packageJson.version;
24
- }
25
- }
26
- catch (error) {
27
- // Fall back to default version if anything fails
28
- version = "1.0.14";
29
- }
30
- const versionText = `v${version}`;
31
- console.error(`
32
- ${pc.bold("Enact CLI")} ${pc.cyan(versionText)}
33
- ${pc.dim("A tool to create and publish enact documents.")}
34
- `);
35
- }
@@ -1,29 +0,0 @@
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, };