@enactprotocol/shared 2.2.2 → 2.3.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 (111) hide show
  1. package/README.md +1 -18
  2. package/dist/config.d.ts +12 -0
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/config.js +32 -6
  5. package/dist/config.js.map +1 -1
  6. package/dist/execution/action-command.d.ts +131 -0
  7. package/dist/execution/action-command.d.ts.map +1 -0
  8. package/dist/execution/action-command.js +300 -0
  9. package/dist/execution/action-command.js.map +1 -0
  10. package/dist/execution/command.d.ts +8 -8
  11. package/dist/execution/command.js +6 -6
  12. package/dist/execution/index.d.ts +1 -0
  13. package/dist/execution/index.d.ts.map +1 -1
  14. package/dist/execution/index.js +2 -0
  15. package/dist/execution/index.js.map +1 -1
  16. package/dist/execution/types.d.ts +5 -2
  17. package/dist/execution/types.d.ts.map +1 -1
  18. package/dist/execution/types.js.map +1 -1
  19. package/dist/index.d.ts +9 -7
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +14 -5
  22. package/dist/index.js.map +1 -1
  23. package/dist/manifest/actions-loader.d.ts +29 -0
  24. package/dist/manifest/actions-loader.d.ts.map +1 -0
  25. package/dist/manifest/actions-loader.js +34 -0
  26. package/dist/manifest/actions-loader.js.map +1 -0
  27. package/dist/manifest/actions-parser.d.ts +69 -0
  28. package/dist/manifest/actions-parser.d.ts.map +1 -0
  29. package/dist/manifest/actions-parser.js +265 -0
  30. package/dist/manifest/actions-parser.js.map +1 -0
  31. package/dist/manifest/index.d.ts +2 -0
  32. package/dist/manifest/index.d.ts.map +1 -1
  33. package/dist/manifest/index.js +4 -0
  34. package/dist/manifest/index.js.map +1 -1
  35. package/dist/manifest/loader.d.ts +7 -2
  36. package/dist/manifest/loader.d.ts.map +1 -1
  37. package/dist/manifest/loader.js +71 -4
  38. package/dist/manifest/loader.js.map +1 -1
  39. package/dist/manifest/parser.d.ts +1 -0
  40. package/dist/manifest/parser.d.ts.map +1 -1
  41. package/dist/manifest/parser.js +1 -0
  42. package/dist/manifest/parser.js.map +1 -1
  43. package/dist/manifest/scripts.d.ts +19 -0
  44. package/dist/manifest/scripts.d.ts.map +1 -0
  45. package/dist/manifest/scripts.js +102 -0
  46. package/dist/manifest/scripts.js.map +1 -0
  47. package/dist/manifest/validator.d.ts +1 -8
  48. package/dist/manifest/validator.d.ts.map +1 -1
  49. package/dist/manifest/validator.js +14 -13
  50. package/dist/manifest/validator.js.map +1 -1
  51. package/dist/mcp-registry.js +5 -5
  52. package/dist/mcp-registry.js.map +1 -1
  53. package/dist/paths.d.ts +9 -2
  54. package/dist/paths.d.ts.map +1 -1
  55. package/dist/paths.js +12 -3
  56. package/dist/paths.js.map +1 -1
  57. package/dist/registry.d.ts +47 -2
  58. package/dist/registry.d.ts.map +1 -1
  59. package/dist/registry.js +100 -7
  60. package/dist/registry.js.map +1 -1
  61. package/dist/resolver.d.ts +55 -4
  62. package/dist/resolver.d.ts.map +1 -1
  63. package/dist/resolver.js +144 -77
  64. package/dist/resolver.js.map +1 -1
  65. package/dist/types/actions.d.ts +194 -0
  66. package/dist/types/actions.d.ts.map +1 -0
  67. package/dist/types/actions.js +32 -0
  68. package/dist/types/actions.js.map +1 -0
  69. package/dist/types/index.d.ts +3 -1
  70. package/dist/types/index.d.ts.map +1 -1
  71. package/dist/types/index.js +1 -0
  72. package/dist/types/index.js.map +1 -1
  73. package/dist/types/manifest.d.ts +50 -5
  74. package/dist/types/manifest.d.ts.map +1 -1
  75. package/dist/types/manifest.js +10 -2
  76. package/dist/types/manifest.js.map +1 -1
  77. package/package.json +2 -2
  78. package/src/config.ts +48 -6
  79. package/src/execution/action-command.ts +417 -0
  80. package/src/execution/command.ts +8 -8
  81. package/src/execution/index.ts +17 -0
  82. package/src/execution/types.ts +13 -2
  83. package/src/index.ts +43 -0
  84. package/src/manifest/actions-loader.ts +49 -0
  85. package/src/manifest/index.ts +12 -0
  86. package/src/manifest/loader.ts +77 -4
  87. package/src/manifest/parser.ts +1 -0
  88. package/src/manifest/scripts.ts +116 -0
  89. package/src/manifest/validator.ts +15 -14
  90. package/src/mcp-registry.ts +5 -5
  91. package/src/paths.ts +13 -3
  92. package/src/registry.ts +136 -7
  93. package/src/resolver.ts +185 -79
  94. package/src/types/actions.ts +223 -0
  95. package/src/types/index.ts +11 -0
  96. package/src/types/manifest.ts +67 -6
  97. package/tests/action-command.test.ts +249 -0
  98. package/tests/config-normalization.test.ts +279 -0
  99. package/tests/config.test.ts +4 -1
  100. package/tests/effective-input-schema.test.ts +86 -0
  101. package/tests/fixtures/valid-tool.md +5 -12
  102. package/tests/fixtures/valid-tool.yaml +3 -10
  103. package/tests/hooks.test.ts +177 -0
  104. package/tests/manifest/loader.test.ts +34 -20
  105. package/tests/manifest/parser.test.ts +11 -15
  106. package/tests/manifest/validator.test.ts +7 -17
  107. package/tests/manifest-types.test.ts +9 -11
  108. package/tests/paths.test.ts +11 -4
  109. package/tests/registry.test.ts +204 -8
  110. package/tests/resolver.test.ts +90 -6
  111. package/tsconfig.tsbuildinfo +1 -1
@@ -1,6 +1,7 @@
1
1
  import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2
2
  import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { join } from "node:path";
4
+ import { addAlias, addToolToRegistry, removeAlias } from "../src/registry";
4
5
  import {
5
6
  ToolResolveError,
6
7
  getToolPath,
@@ -24,7 +25,7 @@ describe("tool resolver", () => {
24
25
 
25
26
  // Create a project-level tool
26
27
  writeFileSync(
27
- join(PROJECT_ENACT_DIR, "tools", "test", "project-tool", "enact.yaml"),
28
+ join(PROJECT_ENACT_DIR, "tools", "test", "project-tool", "skill.yaml"),
28
29
  `
29
30
  name: test/project-tool
30
31
  description: A project-level test tool
@@ -36,7 +37,7 @@ version: "1.0.0"
36
37
  // Create a direct tool directory for path-based resolution
37
38
  mkdirSync(join(TEST_DIR, "direct-tool"), { recursive: true });
38
39
  writeFileSync(
39
- join(TEST_DIR, "direct-tool", "enact.yaml"),
40
+ join(TEST_DIR, "direct-tool", "skill.yaml"),
40
41
  `
41
42
  name: test/direct-tool
42
43
  description: A directly referenced tool
@@ -73,11 +74,11 @@ Documentation here.
73
74
  describe("utility functions", () => {
74
75
  describe("normalizeToolName", () => {
75
76
  test("lowercases name", () => {
76
- expect(normalizeToolName("Acme/Utils/Greeter")).toBe("acme/utils/greeter");
77
+ expect(normalizeToolName("Acme/Greeter")).toBe("acme/greeter");
77
78
  });
78
79
 
79
80
  test("converts backslashes to forward slashes", () => {
80
- expect(normalizeToolName("acme\\utils\\greeter")).toBe("acme/utils/greeter");
81
+ expect(normalizeToolName("acme\\greeter")).toBe("acme/greeter");
81
82
  });
82
83
 
83
84
  test("trims whitespace", () => {
@@ -87,7 +88,11 @@ Documentation here.
87
88
 
88
89
  describe("toolNameToPath", () => {
89
90
  test("returns path-like string", () => {
90
- expect(toolNameToPath("acme/utils/greeter")).toBe("acme/utils/greeter");
91
+ expect(toolNameToPath("acme/greeter")).toBe("acme/greeter");
92
+ });
93
+
94
+ test("strips @ prefix for disk paths", () => {
95
+ expect(toolNameToPath("@acme/greeter")).toBe("acme/greeter");
91
96
  });
92
97
 
93
98
  test("normalizes backslashes", () => {
@@ -141,7 +146,7 @@ Documentation here.
141
146
  });
142
147
 
143
148
  test("resolves tool from manifest file directly", () => {
144
- const manifestPath = join(TEST_DIR, "direct-tool", "enact.yaml");
149
+ const manifestPath = join(TEST_DIR, "direct-tool", "skill.yaml");
145
150
  const result = resolveToolFromPath(manifestPath);
146
151
 
147
152
  expect(result.manifest.name).toBe("test/direct-tool");
@@ -269,4 +274,83 @@ Documentation here.
269
274
  expect(error.searchedLocations).toEqual(["/path/1", "/path/2"]);
270
275
  });
271
276
  });
277
+
278
+ describe("alias resolution", () => {
279
+ test("resolves tool via alias", () => {
280
+ // Set up an alias for the project tool
281
+ addToolToRegistry("test/project-tool", "1.0.0", "project", PROJECT_DIR);
282
+ addAlias("pt", "test/project-tool", "project", PROJECT_DIR);
283
+
284
+ try {
285
+ // Resolve using the alias (no slashes = potential alias)
286
+ const result = resolveTool("pt", { startDir: PROJECT_DIR });
287
+ expect(result.manifest.name).toBe("test/project-tool");
288
+ expect(result.location).toBe("project");
289
+ } finally {
290
+ // Clean up
291
+ removeAlias("pt", "project", PROJECT_DIR);
292
+ rmSync(join(PROJECT_ENACT_DIR, "tools.json"), { force: true });
293
+ }
294
+ });
295
+
296
+ test("alias resolution is case-insensitive (normalized to lowercase)", () => {
297
+ addToolToRegistry("test/project-tool", "1.0.0", "project", PROJECT_DIR);
298
+ addAlias("mytool", "test/project-tool", "project", PROJECT_DIR);
299
+
300
+ try {
301
+ // Lowercase alias should work
302
+ const result = resolveTool("mytool", { startDir: PROJECT_DIR });
303
+ expect(result.manifest.name).toBe("test/project-tool");
304
+
305
+ // Uppercase alias should also work (normalized to lowercase)
306
+ const upperResult = resolveTool("MYTOOL", { startDir: PROJECT_DIR });
307
+ expect(upperResult.manifest.name).toBe("test/project-tool");
308
+
309
+ // Mixed case should also work
310
+ const mixedResult = resolveTool("MyTool", { startDir: PROJECT_DIR });
311
+ expect(mixedResult.manifest.name).toBe("test/project-tool");
312
+ } finally {
313
+ removeAlias("mytool", "project", PROJECT_DIR);
314
+ rmSync(join(PROJECT_ENACT_DIR, "tools.json"), { force: true });
315
+ }
316
+ });
317
+
318
+ test("full tool names bypass alias resolution", () => {
319
+ addToolToRegistry("test/project-tool", "1.0.0", "project", PROJECT_DIR);
320
+ // Create an alias that would conflict if checked
321
+ addAlias("test/project-tool", "some/other-tool", "project", PROJECT_DIR);
322
+
323
+ try {
324
+ // Full name with slashes should resolve directly, not via alias
325
+ const result = resolveTool("test/project-tool", { startDir: PROJECT_DIR });
326
+ expect(result.manifest.name).toBe("test/project-tool");
327
+ } finally {
328
+ removeAlias("test/project-tool", "project", PROJECT_DIR);
329
+ rmSync(join(PROJECT_ENACT_DIR, "tools.json"), { force: true });
330
+ }
331
+ });
332
+
333
+ test("tryResolveTool works with aliases", () => {
334
+ addToolToRegistry("test/project-tool", "1.0.0", "project", PROJECT_DIR);
335
+ addAlias("try-alias", "test/project-tool", "project", PROJECT_DIR);
336
+
337
+ try {
338
+ const result = tryResolveTool("try-alias", { startDir: PROJECT_DIR });
339
+ expect(result).not.toBeNull();
340
+ expect(result?.manifest.name).toBe("test/project-tool");
341
+ } finally {
342
+ removeAlias("try-alias", "project", PROJECT_DIR);
343
+ rmSync(join(PROJECT_ENACT_DIR, "tools.json"), { force: true });
344
+ }
345
+ });
346
+
347
+ test("non-existent alias returns null from tryResolveTool", () => {
348
+ const result = tryResolveTool("nonexistent-alias", {
349
+ startDir: PROJECT_DIR,
350
+ skipUser: true,
351
+ skipCache: true,
352
+ });
353
+ expect(result).toBeNull();
354
+ });
355
+ });
272
356
  });