@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
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Manifest validator using Zod
3
+ *
4
+ * Validates that parsed manifests conform to the Enact specification
5
+ */
6
+ import { z } from "zod/v4";
7
+ // ==================== Zod Schemas ====================
8
+ /**
9
+ * Environment variable schema
10
+ */
11
+ const EnvVariableSchema = z.object({
12
+ description: z.string().min(1, "Description is required"),
13
+ secret: z.boolean().optional(),
14
+ default: z.string().optional(),
15
+ });
16
+ /**
17
+ * Author schema
18
+ */
19
+ const AuthorSchema = z.object({
20
+ name: z.string().min(1, "Author name is required"),
21
+ email: z.string().email().optional(),
22
+ url: z.string().url().optional(),
23
+ });
24
+ /**
25
+ * Tool annotations schema
26
+ */
27
+ const ToolAnnotationsSchema = z.object({
28
+ title: z.string().optional(),
29
+ readOnlyHint: z.boolean().optional(),
30
+ destructiveHint: z.boolean().optional(),
31
+ idempotentHint: z.boolean().optional(),
32
+ openWorldHint: z.boolean().optional(),
33
+ });
34
+ /**
35
+ * Resource requirements schema
36
+ */
37
+ const ResourceRequirementsSchema = z.object({
38
+ memory: z.string().optional(),
39
+ gpu: z.string().optional(),
40
+ disk: z.string().optional(),
41
+ });
42
+ /**
43
+ * Tool example schema
44
+ */
45
+ const ToolExampleSchema = z.object({
46
+ input: z.record(z.string(), z.unknown()).optional(),
47
+ output: z.unknown().optional(),
48
+ description: z.string().optional(),
49
+ });
50
+ /**
51
+ * JSON Schema validation (basic structure check)
52
+ * We don't fully validate JSON Schema here, just ensure it's an object
53
+ */
54
+ const JsonSchemaSchema = z
55
+ .object({
56
+ type: z.string().optional(),
57
+ properties: z.record(z.string(), z.unknown()).optional(),
58
+ required: z.array(z.string()).optional(),
59
+ items: z.unknown().optional(),
60
+ enum: z.array(z.unknown()).optional(),
61
+ description: z.string().optional(),
62
+ })
63
+ .passthrough(); // Allow additional JSON Schema fields
64
+ /**
65
+ * Semantic version regex
66
+ */
67
+ const SEMVER_REGEX = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
68
+ /**
69
+ * Tool name regex - hierarchical path format
70
+ */
71
+ const TOOL_NAME_REGEX = /^[a-z0-9_-]+(?:\/[a-z0-9_-]+)+$/;
72
+ /**
73
+ * Go duration regex (used for timeout)
74
+ */
75
+ const GO_DURATION_REGEX = /^(\d+)(ns|us|µs|ms|s|m|h)$/;
76
+ /**
77
+ * Complete tool manifest schema
78
+ */
79
+ const ToolManifestSchema = z
80
+ .object({
81
+ // Required fields
82
+ name: z
83
+ .string()
84
+ .min(1, "Tool name is required")
85
+ .regex(TOOL_NAME_REGEX, "Tool name must be hierarchical path format (e.g., 'org/tool' or 'org/category/tool')"),
86
+ description: z
87
+ .string()
88
+ .min(1, "Description is required")
89
+ .max(500, "Description should be 500 characters or less"),
90
+ // Recommended fields
91
+ enact: z.string().optional(),
92
+ version: z
93
+ .string()
94
+ .regex(SEMVER_REGEX, "Version must be valid semver (e.g., '1.0.0')")
95
+ .optional(),
96
+ from: z.string().optional(),
97
+ command: z.string().optional(),
98
+ timeout: z
99
+ .string()
100
+ .regex(GO_DURATION_REGEX, "Timeout must be Go duration format (e.g., '30s', '5m', '1h')")
101
+ .optional(),
102
+ license: z.string().optional(),
103
+ tags: z.array(z.string()).optional(),
104
+ // Schema fields
105
+ inputSchema: JsonSchemaSchema.optional(),
106
+ outputSchema: JsonSchemaSchema.optional(),
107
+ // Environment variables
108
+ env: z.record(z.string(), EnvVariableSchema).optional(),
109
+ // Behavior & Resources
110
+ annotations: ToolAnnotationsSchema.optional(),
111
+ resources: ResourceRequirementsSchema.optional(),
112
+ // Documentation
113
+ doc: z.string().optional(),
114
+ authors: z.array(AuthorSchema).optional(),
115
+ // Testing
116
+ examples: z.array(ToolExampleSchema).optional(),
117
+ })
118
+ .passthrough(); // Allow x-* custom fields
119
+ // ==================== Validation Functions ====================
120
+ /**
121
+ * Convert Zod error to our ValidationError format
122
+ */
123
+ function zodErrorToValidationErrors(zodError) {
124
+ return zodError.issues.map((issue) => ({
125
+ path: issue.path.join("."),
126
+ message: issue.message,
127
+ code: issue.code,
128
+ }));
129
+ }
130
+ /**
131
+ * Generate warnings for recommended but missing fields
132
+ */
133
+ function generateWarnings(manifest) {
134
+ const warnings = [];
135
+ // Check for recommended fields
136
+ if (!manifest.enact) {
137
+ warnings.push({
138
+ path: "enact",
139
+ message: "Protocol version (enact) is recommended for compatibility",
140
+ code: "MISSING_RECOMMENDED",
141
+ });
142
+ }
143
+ if (!manifest.version) {
144
+ warnings.push({
145
+ path: "version",
146
+ message: "Tool version is recommended for versioning and updates",
147
+ code: "MISSING_RECOMMENDED",
148
+ });
149
+ }
150
+ if (!manifest.from && manifest.command) {
151
+ warnings.push({
152
+ path: "from",
153
+ message: "Container image (from) is recommended for reproducibility",
154
+ code: "MISSING_RECOMMENDED",
155
+ });
156
+ }
157
+ if (!manifest.license) {
158
+ warnings.push({
159
+ path: "license",
160
+ message: "License is recommended for published tools",
161
+ code: "MISSING_RECOMMENDED",
162
+ });
163
+ }
164
+ if (!manifest.inputSchema && manifest.command) {
165
+ warnings.push({
166
+ path: "inputSchema",
167
+ message: "Input schema is recommended for tools with parameters",
168
+ code: "MISSING_RECOMMENDED",
169
+ });
170
+ }
171
+ if (!manifest.outputSchema) {
172
+ warnings.push({
173
+ path: "outputSchema",
174
+ message: "Output schema is recommended for structured output validation",
175
+ code: "MISSING_RECOMMENDED",
176
+ });
177
+ }
178
+ // Check for potential issues
179
+ if (manifest.env) {
180
+ for (const [key, value] of Object.entries(manifest.env)) {
181
+ if (value.secret && value.default) {
182
+ warnings.push({
183
+ path: `env.${key}`,
184
+ message: "Secret variables should not have default values",
185
+ code: "SECRET_WITH_DEFAULT",
186
+ });
187
+ }
188
+ }
189
+ }
190
+ // Check for timeout on command tools
191
+ if (manifest.command && !manifest.timeout) {
192
+ warnings.push({
193
+ path: "timeout",
194
+ message: "Timeout is recommended for command-based tools",
195
+ code: "MISSING_RECOMMENDED",
196
+ });
197
+ }
198
+ return warnings;
199
+ }
200
+ /**
201
+ * Validate a tool manifest
202
+ *
203
+ * @param manifest - The manifest to validate (parsed but unvalidated)
204
+ * @returns ValidationResult with valid flag, errors, and warnings
205
+ */
206
+ export function validateManifest(manifest) {
207
+ const result = ToolManifestSchema.safeParse(manifest);
208
+ if (!result.success) {
209
+ return {
210
+ valid: false,
211
+ errors: zodErrorToValidationErrors(result.error),
212
+ warnings: [],
213
+ };
214
+ }
215
+ // Generate warnings for missing recommended fields
216
+ const warnings = generateWarnings(result.data);
217
+ return {
218
+ valid: true,
219
+ warnings: warnings.length > 0 ? warnings : undefined,
220
+ };
221
+ }
222
+ /**
223
+ * Validate and return the typed manifest
224
+ * Throws if validation fails
225
+ *
226
+ * @param manifest - The manifest to validate
227
+ * @returns The validated ToolManifest
228
+ * @throws Error if validation fails
229
+ */
230
+ export function validateManifestStrict(manifest) {
231
+ const result = validateManifest(manifest);
232
+ if (!result.valid) {
233
+ const errorMessages = result.errors?.map((e) => `${e.path}: ${e.message}`).join(", ");
234
+ throw new Error(`Manifest validation failed: ${errorMessages}`);
235
+ }
236
+ return manifest;
237
+ }
238
+ /**
239
+ * Check if a string is a valid tool name
240
+ */
241
+ export function isValidToolName(name) {
242
+ return TOOL_NAME_REGEX.test(name);
243
+ }
244
+ /**
245
+ * Check if a string is a valid semver version
246
+ */
247
+ export function isValidVersion(version) {
248
+ return SEMVER_REGEX.test(version);
249
+ }
250
+ /**
251
+ * Check if a string is a valid Go duration
252
+ */
253
+ export function isValidTimeout(timeout) {
254
+ return GO_DURATION_REGEX.test(timeout);
255
+ }
256
+ // Export the schema for external use
257
+ export { ToolManifestSchema };
258
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAQ3B,wDAAwD;AAExD;;GAEG;AACH,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACjC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,yBAAyB,CAAC;IACzD,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC9B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,IAAI,EA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AAM,CAAC,IAAoB,CAAC,CAAC;IAE/D,OAAO;QACL,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;KACrD,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAAiB;IACtD,MAAM,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAE1C,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtF,MAAM,IAAI,KAAK,CAAC,+BAA+B,aAAa,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,QAAwB,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,OAAO,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,OAAO,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACzC,CAAC;AAED,qCAAqC;AACrC,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Path resolution utilities for Enact directories and tool locations
3
+ */
4
+ /**
5
+ * Scope for tool directories
6
+ */
7
+ export type ToolScope = "user" | "project";
8
+ /**
9
+ * Get the Enact home directory (~/.enact/)
10
+ * @returns Absolute path to ~/.enact/
11
+ */
12
+ export declare function getEnactHome(): string;
13
+ /**
14
+ * Get the project-level .enact directory
15
+ * Searches up from current working directory to find .enact/
16
+ * NOTE: Does NOT return ~/.enact/ - that's the global home, not a project dir
17
+ * @param startDir - Directory to start searching from (defaults to cwd)
18
+ * @returns Absolute path to .enact/ or null if not found
19
+ */
20
+ export declare function getProjectEnactDir(startDir?: string): string | null;
21
+ /**
22
+ * Get the tools directory for specified scope
23
+ *
24
+ * NOTE: For global scope ("user"), this is DEPRECATED.
25
+ * Global tools are now tracked in ~/.enact/tools.json and stored in cache.
26
+ * Use getToolsJsonPath("global") and getToolCachePath() from ./registry instead.
27
+ *
28
+ * For project scope, this returns .enact/tools/ where project tools are copied.
29
+ *
30
+ * @param scope - 'user' for ~/.enact/tools/ (deprecated) or 'project' for .enact/tools/
31
+ * @param startDir - For project scope, directory to start searching from
32
+ * @returns Absolute path to tools directory or null if project scope and not found
33
+ * @deprecated Use registry.ts functions for global tools
34
+ */
35
+ export declare function getToolsDir(scope: ToolScope, startDir?: string): string | null;
36
+ /**
37
+ * Get the cache directory (~/.enact/cache/)
38
+ * @returns Absolute path to ~/.enact/cache/
39
+ */
40
+ export declare function getCacheDir(): string;
41
+ /**
42
+ * Get the configuration file path (~/.enact/config.yaml)
43
+ * @returns Absolute path to ~/.enact/config.yaml
44
+ */
45
+ export declare function getConfigPath(): string;
46
+ /**
47
+ * Get the global .env file path (~/.enact/.env)
48
+ * @returns Absolute path to ~/.enact/.env
49
+ */
50
+ export declare function getGlobalEnvPath(): string;
51
+ /**
52
+ * Get the project .env file path (.enact/.env)
53
+ * @param startDir - Directory to start searching from
54
+ * @returns Absolute path to .enact/.env or null if not found
55
+ */
56
+ export declare function getProjectEnvPath(startDir?: string): string | null;
57
+ //# sourceMappingURL=paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;AAE3C;;;GAGG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAoBnE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAS9E;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGlE"}
package/dist/paths.js ADDED
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Path resolution utilities for Enact directories and tool locations
3
+ */
4
+ import { existsSync } from "node:fs";
5
+ import { homedir } from "node:os";
6
+ import { join, resolve } from "node:path";
7
+ /**
8
+ * Get the Enact home directory (~/.enact/)
9
+ * @returns Absolute path to ~/.enact/
10
+ */
11
+ export function getEnactHome() {
12
+ return join(homedir(), ".enact");
13
+ }
14
+ /**
15
+ * Get the project-level .enact directory
16
+ * Searches up from current working directory to find .enact/
17
+ * NOTE: Does NOT return ~/.enact/ - that's the global home, not a project dir
18
+ * @param startDir - Directory to start searching from (defaults to cwd)
19
+ * @returns Absolute path to .enact/ or null if not found
20
+ */
21
+ export function getProjectEnactDir(startDir) {
22
+ let currentDir = resolve(startDir ?? process.cwd());
23
+ const root = resolve("/");
24
+ const enactHome = getEnactHome();
25
+ // Walk up directory tree looking for .enact/
26
+ while (currentDir !== root) {
27
+ const enactDir = join(currentDir, ".enact");
28
+ // Skip ~/.enact/ - that's the global home, not a project directory
29
+ if (existsSync(enactDir) && enactDir !== enactHome) {
30
+ return enactDir;
31
+ }
32
+ const parentDir = resolve(currentDir, "..");
33
+ if (parentDir === currentDir) {
34
+ break; // Reached root
35
+ }
36
+ currentDir = parentDir;
37
+ }
38
+ return null;
39
+ }
40
+ /**
41
+ * Get the tools directory for specified scope
42
+ *
43
+ * NOTE: For global scope ("user"), this is DEPRECATED.
44
+ * Global tools are now tracked in ~/.enact/tools.json and stored in cache.
45
+ * Use getToolsJsonPath("global") and getToolCachePath() from ./registry instead.
46
+ *
47
+ * For project scope, this returns .enact/tools/ where project tools are copied.
48
+ *
49
+ * @param scope - 'user' for ~/.enact/tools/ (deprecated) or 'project' for .enact/tools/
50
+ * @param startDir - For project scope, directory to start searching from
51
+ * @returns Absolute path to tools directory or null if project scope and not found
52
+ * @deprecated Use registry.ts functions for global tools
53
+ */
54
+ export function getToolsDir(scope, startDir) {
55
+ if (scope === "user") {
56
+ // DEPRECATED: Global tools now use tools.json + cache
57
+ // This path is kept for backward compatibility during migration
58
+ return join(getEnactHome(), "tools");
59
+ }
60
+ const projectDir = getProjectEnactDir(startDir);
61
+ return projectDir ? join(projectDir, "tools") : null;
62
+ }
63
+ /**
64
+ * Get the cache directory (~/.enact/cache/)
65
+ * @returns Absolute path to ~/.enact/cache/
66
+ */
67
+ export function getCacheDir() {
68
+ return join(getEnactHome(), "cache");
69
+ }
70
+ /**
71
+ * Get the configuration file path (~/.enact/config.yaml)
72
+ * @returns Absolute path to ~/.enact/config.yaml
73
+ */
74
+ export function getConfigPath() {
75
+ return join(getEnactHome(), "config.yaml");
76
+ }
77
+ /**
78
+ * Get the global .env file path (~/.enact/.env)
79
+ * @returns Absolute path to ~/.enact/.env
80
+ */
81
+ export function getGlobalEnvPath() {
82
+ return join(getEnactHome(), ".env");
83
+ }
84
+ /**
85
+ * Get the project .env file path (.enact/.env)
86
+ * @param startDir - Directory to start searching from
87
+ * @returns Absolute path to .enact/.env or null if not found
88
+ */
89
+ export function getProjectEnvPath(startDir) {
90
+ const projectDir = getProjectEnactDir(startDir);
91
+ return projectDir ? join(projectDir, ".env") : null;
92
+ }
93
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAO1C;;;GAGG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAiB;IAClD,IAAI,UAAU,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACpD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1B,MAAM,SAAS,GAAG,YAAY,EAAE,CAAC;IAEjC,6CAA6C;IAC7C,OAAO,UAAU,KAAK,IAAI,EAAE,CAAC;QAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC5C,mEAAmE;QACnE,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YACnD,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC5C,IAAI,SAAS,KAAK,UAAU,EAAE,CAAC;YAC7B,MAAM,CAAC,eAAe;QACxB,CAAC;QACD,UAAU,GAAG,SAAS,CAAC;IACzB,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,KAAgB,EAAE,QAAiB;IAC7D,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QACrB,sDAAsD;QACtD,gEAAgE;QAChE,OAAO,IAAI,CAAC,YAAY,EAAE,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,UAAU,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAChD,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACvD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,IAAI,CAAC,YAAY,EAAE,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,IAAI,CAAC,YAAY,EAAE,EAAE,aAAa,CAAC,CAAC;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,IAAI,CAAC,YAAY,EAAE,EAAE,MAAM,CAAC,CAAC;AACtC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAiB;IACjD,MAAM,UAAU,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAChD,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACtD,CAAC"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Local tool registry management
3
+ *
4
+ * Manages tools.json files for tracking installed tools:
5
+ * - Global: ~/.enact/tools.json (installed with -g)
6
+ * - Project: .enact/tools.json (project dependencies)
7
+ *
8
+ * Tools are stored in cache and referenced by version in tools.json.
9
+ * This eliminates the need for a separate ~/.enact/tools/ directory.
10
+ */
11
+ /**
12
+ * Structure of tools.json file
13
+ */
14
+ export interface ToolsRegistry {
15
+ /** Map of tool name to installed version */
16
+ tools: Record<string, string>;
17
+ }
18
+ /**
19
+ * Scope for tool registry
20
+ */
21
+ export type RegistryScope = "global" | "project";
22
+ /**
23
+ * Information about an installed tool
24
+ */
25
+ export interface InstalledToolInfo {
26
+ name: string;
27
+ version: string;
28
+ scope: RegistryScope;
29
+ cachePath: string;
30
+ }
31
+ /**
32
+ * Get the path to tools.json for the specified scope
33
+ */
34
+ export declare function getToolsJsonPath(scope: RegistryScope, startDir?: string): string | null;
35
+ /**
36
+ * Load tools.json from the specified scope
37
+ * Returns empty registry if file doesn't exist
38
+ */
39
+ export declare function loadToolsRegistry(scope: RegistryScope, startDir?: string): ToolsRegistry;
40
+ /**
41
+ * Save tools.json to the specified scope
42
+ */
43
+ export declare function saveToolsRegistry(registry: ToolsRegistry, scope: RegistryScope, startDir?: string): void;
44
+ /**
45
+ * Add a tool to the registry
46
+ */
47
+ export declare function addToolToRegistry(toolName: string, version: string, scope: RegistryScope, startDir?: string): void;
48
+ /**
49
+ * Remove a tool from the registry
50
+ */
51
+ export declare function removeToolFromRegistry(toolName: string, scope: RegistryScope, startDir?: string): boolean;
52
+ /**
53
+ * Check if a tool is installed in the registry
54
+ */
55
+ export declare function isToolInstalled(toolName: string, scope: RegistryScope, startDir?: string): boolean;
56
+ /**
57
+ * Get the installed version of a tool
58
+ * Returns null if not installed
59
+ */
60
+ export declare function getInstalledVersion(toolName: string, scope: RegistryScope, startDir?: string): string | null;
61
+ /**
62
+ * Get the cache path for an installed tool
63
+ */
64
+ export declare function getToolCachePath(toolName: string, version: string): string;
65
+ /**
66
+ * List all installed tools in a registry
67
+ */
68
+ export declare function listInstalledTools(scope: RegistryScope, startDir?: string): InstalledToolInfo[];
69
+ /**
70
+ * Get tool info if installed (checks cache path exists)
71
+ */
72
+ export declare function getInstalledToolInfo(toolName: string, scope: RegistryScope, startDir?: string): InstalledToolInfo | null;
73
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"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AE,aAAa,EACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,GAAG,IAAI,CAGf;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAI1E;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAc/F;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,aAAa,EACpB,QAAQ,CAAC,EAAE,MAAM,GAChB,iBAAiB,GAAG,IAAI,CAoB1B"}
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Local tool registry management
3
+ *
4
+ * Manages tools.json files for tracking installed tools:
5
+ * - Global: ~/.enact/tools.json (installed with -g)
6
+ * - Project: .enact/tools.json (project dependencies)
7
+ *
8
+ * Tools are stored in cache and referenced by version in tools.json.
9
+ * This eliminates the need for a separate ~/.enact/tools/ directory.
10
+ */
11
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
12
+ import { dirname, join } from "node:path";
13
+ import { getCacheDir, getEnactHome, getProjectEnactDir } from "./paths";
14
+ /**
15
+ * Get the path to tools.json for the specified scope
16
+ */
17
+ export function getToolsJsonPath(scope, startDir) {
18
+ if (scope === "global") {
19
+ return join(getEnactHome(), "tools.json");
20
+ }
21
+ const projectDir = getProjectEnactDir(startDir);
22
+ return projectDir ? join(projectDir, "tools.json") : null;
23
+ }
24
+ /**
25
+ * Load tools.json from the specified scope
26
+ * Returns empty registry if file doesn't exist
27
+ */
28
+ export function loadToolsRegistry(scope, startDir) {
29
+ const registryPath = getToolsJsonPath(scope, startDir);
30
+ if (!registryPath || !existsSync(registryPath)) {
31
+ return { tools: {} };
32
+ }
33
+ try {
34
+ const content = readFileSync(registryPath, "utf-8");
35
+ const parsed = JSON.parse(content);
36
+ return {
37
+ tools: parsed.tools ?? {},
38
+ };
39
+ }
40
+ catch {
41
+ // Return empty registry on parse error
42
+ return { tools: {} };
43
+ }
44
+ }
45
+ /**
46
+ * Save tools.json to the specified scope
47
+ */
48
+ export function saveToolsRegistry(registry, scope, startDir) {
49
+ let registryPath = getToolsJsonPath(scope, startDir);
50
+ // For project scope, create .enact/ directory if it doesn't exist
51
+ if (!registryPath && scope === "project") {
52
+ const projectRoot = startDir ?? process.cwd();
53
+ const enactDir = join(projectRoot, ".enact");
54
+ mkdirSync(enactDir, { recursive: true });
55
+ registryPath = join(enactDir, "tools.json");
56
+ }
57
+ if (!registryPath) {
58
+ throw new Error("Cannot save project registry: unable to determine registry path");
59
+ }
60
+ // Ensure directory exists
61
+ const dir = dirname(registryPath);
62
+ if (!existsSync(dir)) {
63
+ mkdirSync(dir, { recursive: true });
64
+ }
65
+ const content = JSON.stringify(registry, null, 2);
66
+ writeFileSync(registryPath, content, "utf-8");
67
+ }
68
+ /**
69
+ * Add a tool to the registry
70
+ */
71
+ export function addToolToRegistry(toolName, version, scope, startDir) {
72
+ const registry = loadToolsRegistry(scope, startDir);
73
+ registry.tools[toolName] = version;
74
+ saveToolsRegistry(registry, scope, startDir);
75
+ }
76
+ /**
77
+ * Remove a tool from the registry
78
+ */
79
+ export function removeToolFromRegistry(toolName, scope, startDir) {
80
+ const registry = loadToolsRegistry(scope, startDir);
81
+ if (!(toolName in registry.tools)) {
82
+ return false;
83
+ }
84
+ delete registry.tools[toolName];
85
+ saveToolsRegistry(registry, scope, startDir);
86
+ return true;
87
+ }
88
+ /**
89
+ * Check if a tool is installed in the registry
90
+ */
91
+ export function isToolInstalled(toolName, scope, startDir) {
92
+ const registry = loadToolsRegistry(scope, startDir);
93
+ return toolName in registry.tools;
94
+ }
95
+ /**
96
+ * Get the installed version of a tool
97
+ * Returns null if not installed
98
+ */
99
+ export function getInstalledVersion(toolName, scope, startDir) {
100
+ const registry = loadToolsRegistry(scope, startDir);
101
+ return registry.tools[toolName] ?? null;
102
+ }
103
+ /**
104
+ * Get the cache path for an installed tool
105
+ */
106
+ export function getToolCachePath(toolName, version) {
107
+ const cacheDir = getCacheDir();
108
+ const normalizedVersion = version.startsWith("v") ? version.slice(1) : version;
109
+ return join(cacheDir, toolName, `v${normalizedVersion}`);
110
+ }
111
+ /**
112
+ * List all installed tools in a registry
113
+ */
114
+ export function listInstalledTools(scope, startDir) {
115
+ const registry = loadToolsRegistry(scope, startDir);
116
+ const tools = [];
117
+ for (const [name, version] of Object.entries(registry.tools)) {
118
+ tools.push({
119
+ name,
120
+ version,
121
+ scope,
122
+ cachePath: getToolCachePath(name, version),
123
+ });
124
+ }
125
+ return tools;
126
+ }
127
+ /**
128
+ * Get tool info if installed (checks cache path exists)
129
+ */
130
+ export function getInstalledToolInfo(toolName, scope, startDir) {
131
+ const version = getInstalledVersion(toolName, scope, startDir);
132
+ if (!version) {
133
+ return null;
134
+ }
135
+ const cachePath = getToolCachePath(toolName, version);
136
+ // Verify cache exists
137
+ if (!existsSync(cachePath)) {
138
+ return null;
139
+ }
140
+ return {
141
+ name: toolName,
142
+ version,
143
+ scope,
144
+ cachePath,
145
+ };
146
+ }
147
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAyBxE;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAoB,EAAE,QAAiB;IACtE,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC,YAAY,EAAE,EAAE,YAAY,CAAC,CA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