@enactprotocol/cli 2.0.0 → 2.0.2

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 (119) hide show
  1. package/dist/commands/auth/index.d.ts +12 -0
  2. package/dist/commands/auth/index.d.ts.map +1 -0
  3. package/dist/commands/auth/index.js +743 -0
  4. package/dist/commands/auth/index.js.map +1 -0
  5. package/dist/commands/cache/index.d.ts +11 -0
  6. package/dist/commands/cache/index.d.ts.map +1 -0
  7. package/dist/commands/cache/index.js +304 -0
  8. package/dist/commands/cache/index.js.map +1 -0
  9. package/dist/commands/config/index.d.ts +11 -0
  10. package/dist/commands/config/index.d.ts.map +1 -0
  11. package/dist/commands/config/index.js +138 -0
  12. package/dist/commands/config/index.js.map +1 -0
  13. package/dist/commands/env/index.d.ts +11 -0
  14. package/dist/commands/env/index.d.ts.map +1 -0
  15. package/dist/commands/env/index.js +303 -0
  16. package/dist/commands/env/index.js.map +1 -0
  17. package/dist/commands/exec/index.d.ts +12 -0
  18. package/dist/commands/exec/index.d.ts.map +1 -0
  19. package/dist/commands/exec/index.js +154 -0
  20. package/dist/commands/exec/index.js.map +1 -0
  21. package/dist/commands/get/index.d.ts +11 -0
  22. package/dist/commands/get/index.d.ts.map +1 -0
  23. package/dist/commands/get/index.js +151 -0
  24. package/dist/commands/get/index.js.map +1 -0
  25. package/dist/commands/index.d.ts +25 -0
  26. package/dist/commands/index.d.ts.map +1 -0
  27. package/dist/commands/index.js +28 -0
  28. package/dist/commands/index.js.map +1 -0
  29. package/dist/commands/init/index.d.ts +11 -0
  30. package/dist/commands/init/index.d.ts.map +1 -0
  31. package/dist/commands/init/index.js +192 -0
  32. package/dist/commands/init/index.js.map +1 -0
  33. package/dist/commands/inspect/index.d.ts +13 -0
  34. package/dist/commands/inspect/index.d.ts.map +1 -0
  35. package/dist/commands/inspect/index.js +199 -0
  36. package/dist/commands/inspect/index.js.map +1 -0
  37. package/dist/commands/install/index.d.ts +16 -0
  38. package/dist/commands/install/index.d.ts.map +1 -0
  39. package/dist/commands/install/index.js +520 -0
  40. package/dist/commands/install/index.js.map +1 -0
  41. package/dist/commands/list/index.d.ts +15 -0
  42. package/dist/commands/list/index.d.ts.map +1 -0
  43. package/dist/commands/list/index.js +103 -0
  44. package/dist/commands/list/index.js.map +1 -0
  45. package/dist/commands/publish/index.d.ts +11 -0
  46. package/dist/commands/publish/index.d.ts.map +1 -0
  47. package/dist/commands/publish/index.js +274 -0
  48. package/dist/commands/publish/index.js.map +1 -0
  49. package/dist/commands/report/index.d.ts +12 -0
  50. package/dist/commands/report/index.d.ts.map +1 -0
  51. package/dist/commands/report/index.js +279 -0
  52. package/dist/commands/report/index.js.map +1 -0
  53. package/dist/commands/run/index.d.ts +16 -0
  54. package/dist/commands/run/index.d.ts.map +1 -0
  55. package/dist/commands/run/index.js +525 -0
  56. package/dist/commands/run/index.js.map +1 -0
  57. package/dist/commands/search/index.d.ts +12 -0
  58. package/dist/commands/search/index.d.ts.map +1 -0
  59. package/dist/commands/search/index.js +275 -0
  60. package/dist/commands/search/index.js.map +1 -0
  61. package/dist/commands/setup/index.d.ts +11 -0
  62. package/dist/commands/setup/index.d.ts.map +1 -0
  63. package/dist/commands/setup/index.js +241 -0
  64. package/dist/commands/setup/index.js.map +1 -0
  65. package/dist/commands/sign/index.d.ts +17 -0
  66. package/dist/commands/sign/index.d.ts.map +1 -0
  67. package/dist/commands/sign/index.js +507 -0
  68. package/dist/commands/sign/index.js.map +1 -0
  69. package/dist/commands/trust/index.d.ts +13 -0
  70. package/dist/commands/trust/index.d.ts.map +1 -0
  71. package/dist/commands/trust/index.js +366 -0
  72. package/dist/commands/trust/index.js.map +1 -0
  73. package/dist/commands/unyank/index.d.ts +11 -0
  74. package/dist/commands/unyank/index.d.ts.map +1 -0
  75. package/dist/commands/unyank/index.js +87 -0
  76. package/dist/commands/unyank/index.js.map +1 -0
  77. package/dist/commands/yank/index.d.ts +13 -0
  78. package/dist/commands/yank/index.d.ts.map +1 -0
  79. package/dist/commands/yank/index.js +109 -0
  80. package/dist/commands/yank/index.js.map +1 -0
  81. package/dist/index.d.ts +10 -0
  82. package/dist/index.d.ts.map +1 -0
  83. package/dist/index.js +68 -0
  84. package/dist/index.js.map +1 -0
  85. package/dist/types.d.ts +69 -0
  86. package/dist/types.d.ts.map +1 -0
  87. package/dist/types.js +15 -0
  88. package/dist/types.js.map +1 -0
  89. package/dist/utils/errors.d.ts +159 -0
  90. package/dist/utils/errors.d.ts.map +1 -0
  91. package/dist/utils/errors.js +321 -0
  92. package/dist/utils/errors.js.map +1 -0
  93. package/dist/utils/exit-codes.d.ts +83 -0
  94. package/dist/utils/exit-codes.d.ts.map +1 -0
  95. package/dist/utils/exit-codes.js +126 -0
  96. package/dist/utils/exit-codes.js.map +1 -0
  97. package/dist/utils/ignore.d.ts +25 -0
  98. package/dist/utils/ignore.d.ts.map +1 -0
  99. package/dist/utils/ignore.js +123 -0
  100. package/dist/utils/ignore.js.map +1 -0
  101. package/dist/utils/index.d.ts +8 -0
  102. package/dist/utils/index.d.ts.map +1 -0
  103. package/dist/utils/index.js +12 -0
  104. package/dist/utils/index.js.map +1 -0
  105. package/dist/utils/output.d.ts +103 -0
  106. package/dist/utils/output.d.ts.map +1 -0
  107. package/dist/utils/output.js +201 -0
  108. package/dist/utils/output.js.map +1 -0
  109. package/dist/utils/spinner.d.ts +83 -0
  110. package/dist/utils/spinner.d.ts.map +1 -0
  111. package/dist/utils/spinner.js +162 -0
  112. package/dist/utils/spinner.js.map +1 -0
  113. package/package.json +5 -5
  114. package/src/commands/index.ts +1 -0
  115. package/src/commands/init/index.ts +231 -0
  116. package/src/index.ts +7 -1
  117. package/tests/index.test.ts +1 -1
  118. package/tsconfig.json +1 -0
  119. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,231 @@
1
+ /**
2
+ * enact init command
3
+ *
4
+ * Create a basic tool template in the current directory.
5
+ */
6
+
7
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { getSecret } from "@enactprotocol/secrets";
10
+ import type { Command } from "commander";
11
+ import type { CommandContext, GlobalOptions } from "../../types";
12
+ import { error, formatError, info, success, warning } from "../../utils";
13
+
14
+ /** Namespace for stored auth tokens */
15
+ const AUTH_NAMESPACE = "enact:auth";
16
+ const ACCESS_TOKEN_KEY = "access_token";
17
+ const AUTH_METHOD_KEY = "auth_method";
18
+
19
+ /** Supabase configuration */
20
+ const SUPABASE_URL = process.env.SUPABASE_URL || "https://siikwkfgsmouioodghho.supabase.co";
21
+ const SUPABASE_ANON_KEY =
22
+ process.env.SUPABASE_ANON_KEY ??
23
+ "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InNpaWt3a2Znc21vdWlvb2RnaGhvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjQ2MTkzMzksImV4cCI6MjA4MDE5NTMzOX0.kxnx6-IPFhmGx6rzNx36vbyhFMFZKP_jFqaDbKnJ_E0";
24
+
25
+ interface InitOptions extends GlobalOptions {
26
+ name?: string;
27
+ force?: boolean;
28
+ }
29
+
30
+ /**
31
+ * Get the current logged-in username
32
+ */
33
+ async function getCurrentUsername(): Promise<string | null> {
34
+ const accessToken = await getSecret(AUTH_NAMESPACE, ACCESS_TOKEN_KEY);
35
+ if (!accessToken) {
36
+ return null;
37
+ }
38
+
39
+ const authMethod = await getSecret(AUTH_NAMESPACE, AUTH_METHOD_KEY);
40
+
41
+ if (authMethod === "supabase") {
42
+ // Get user from Supabase
43
+ try {
44
+ const userResponse = await fetch(`${SUPABASE_URL}/auth/v1/user`, {
45
+ headers: {
46
+ Authorization: `Bearer ${accessToken}`,
47
+ apikey: SUPABASE_ANON_KEY,
48
+ },
49
+ });
50
+
51
+ if (!userResponse.ok) {
52
+ return null;
53
+ }
54
+
55
+ const user = (await userResponse.json()) as {
56
+ id: string;
57
+ email?: string;
58
+ user_metadata?: {
59
+ user_name?: string;
60
+ username?: string;
61
+ full_name?: string;
62
+ };
63
+ };
64
+
65
+ // Try to get profile username from database
66
+ const profileResponse = await fetch(
67
+ `${SUPABASE_URL}/rest/v1/profiles?id=eq.${user.id}&select=username`,
68
+ {
69
+ headers: {
70
+ Authorization: `Bearer ${accessToken}`,
71
+ apikey: SUPABASE_ANON_KEY,
72
+ },
73
+ }
74
+ );
75
+
76
+ if (profileResponse.ok) {
77
+ const profiles = (await profileResponse.json()) as Array<{ username: string }>;
78
+ if (profiles[0]?.username) {
79
+ return profiles[0].username;
80
+ }
81
+ }
82
+
83
+ // Fall back to user_metadata
84
+ return (
85
+ user.user_metadata?.username ||
86
+ user.user_metadata?.user_name ||
87
+ user.user_metadata?.full_name ||
88
+ user.email?.split("@")[0] ||
89
+ null
90
+ );
91
+ } catch {
92
+ return null;
93
+ }
94
+ }
95
+
96
+ // Legacy API auth - use the API client
97
+ try {
98
+ const { createApiClient, getCurrentUser } = await import("@enactprotocol/api");
99
+ const client = createApiClient();
100
+ client.setAuthToken(accessToken);
101
+ const user = await getCurrentUser(client);
102
+ return user.username;
103
+ } catch {
104
+ return null;
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Generate the tool template content
110
+ */
111
+ function generateToolTemplate(toolName: string): string {
112
+ return `---
113
+ name: ${toolName}
114
+ description: A simple tool that echoes a greeting
115
+ version: 0.1.0
116
+ enact: "2.0"
117
+
118
+ from: alpine:latest
119
+
120
+ inputSchema:
121
+ type: object
122
+ properties:
123
+ name:
124
+ type: string
125
+ description: Name to greet
126
+ default: World
127
+ required: []
128
+
129
+ command: |
130
+ echo "Hello, \${name}!"
131
+ ---
132
+
133
+ # ${toolName}
134
+
135
+ A simple greeting tool created with \`enact init\`.
136
+
137
+ ## Usage
138
+
139
+ \`\`\`bash
140
+ enact run ./ --args '{"name": "Alice"}'
141
+ \`\`\`
142
+
143
+ ## Customization
144
+
145
+ Edit this file to create your own tool:
146
+
147
+ 1. Update the \`name\` and \`description\` in the frontmatter
148
+ 2. Modify the \`inputSchema\` to define your tool's inputs
149
+ 3. Change the \`command\` to run your desired shell commands
150
+ 4. Update this documentation section
151
+
152
+ ## Learn More
153
+
154
+ - [Enact Documentation](https://enact.dev/docs)
155
+ - [Tool Manifest Reference](https://enact.dev/docs/manifest)
156
+ `;
157
+ }
158
+
159
+ /**
160
+ * Init command handler
161
+ */
162
+ async function initHandler(options: InitOptions, ctx: CommandContext): Promise<void> {
163
+ const targetDir = ctx.cwd;
164
+ const manifestPath = join(targetDir, "enact.md");
165
+
166
+ // Check if manifest already exists
167
+ if (existsSync(manifestPath) && !options.force) {
168
+ warning(`Tool manifest already exists at: ${manifestPath}`);
169
+ info("Use --force to overwrite");
170
+ return;
171
+ }
172
+
173
+ // Get username for the tool name
174
+ let toolName = options.name;
175
+
176
+ if (!toolName) {
177
+ const username = await getCurrentUsername();
178
+ if (username) {
179
+ toolName = `${username}/my-tool`;
180
+ info(`Using logged-in username: ${username}`);
181
+ } else {
182
+ toolName = "my-tool";
183
+ info("Not logged in - using generic tool name");
184
+ info("Run 'enact auth login' to use your username in tool names");
185
+ }
186
+ }
187
+
188
+ // Generate and write the template
189
+ const content = generateToolTemplate(toolName);
190
+
191
+ // Ensure directory exists
192
+ if (!existsSync(targetDir)) {
193
+ mkdirSync(targetDir, { recursive: true });
194
+ }
195
+
196
+ writeFileSync(manifestPath, content, "utf-8");
197
+
198
+ success(`Created tool template: ${manifestPath}`);
199
+ info("");
200
+ info("Next steps:");
201
+ info(" 1. Edit enact.md to customize your tool");
202
+ info(" 2. Run 'enact run ./' to test your tool");
203
+ info(" 3. Run 'enact publish' to share your tool");
204
+ }
205
+
206
+ /**
207
+ * Configure the init command
208
+ */
209
+ export function configureInitCommand(program: Command): void {
210
+ program
211
+ .command("init")
212
+ .description("Create a new tool template in the current directory")
213
+ .option("-n, --name <name>", "Tool name (default: username/my-tool or my-tool)")
214
+ .option("-f, --force", "Overwrite existing enact.md file")
215
+ .option("-v, --verbose", "Show detailed output")
216
+ .action(async (options: InitOptions) => {
217
+ const ctx: CommandContext = {
218
+ cwd: process.cwd(),
219
+ options,
220
+ isCI: Boolean(process.env.CI),
221
+ isInteractive: process.stdout.isTTY ?? false,
222
+ };
223
+
224
+ try {
225
+ await initHandler(options, ctx);
226
+ } catch (err) {
227
+ error(formatError(err));
228
+ process.exit(1);
229
+ }
230
+ });
231
+ }
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  * User-facing commands for tool execution, discovery, and management.
8
8
  */
9
9
 
10
+ import { ensureGlobalSetup } from "@enactprotocol/shared";
10
11
  import { Command } from "commander";
11
12
  import {
12
13
  configureAuthCommand,
@@ -15,6 +16,7 @@ import {
15
16
  configureEnvCommand,
16
17
  configureExecCommand,
17
18
  configureGetCommand,
19
+ configureInitCommand,
18
20
  configureInspectCommand,
19
21
  configureInstallCommand,
20
22
  configureListCommand,
@@ -30,13 +32,16 @@ import {
30
32
  } from "./commands";
31
33
  import { error, formatError } from "./utils";
32
34
 
33
- export const version = "0.1.0";
35
+ export const version = "2.0.2";
34
36
 
35
37
  // Export types for external use
36
38
  export type { GlobalOptions, CommandContext } from "./types";
37
39
 
38
40
  // Main CLI entry point
39
41
  async function main() {
42
+ // Ensure global setup is complete on first run
43
+ ensureGlobalSetup();
44
+
40
45
  const program = new Command();
41
46
 
42
47
  program
@@ -48,6 +53,7 @@ async function main() {
48
53
 
49
54
  // Configure all commands
50
55
  configureSetupCommand(program);
56
+ configureInitCommand(program);
51
57
  configureRunCommand(program);
52
58
  configureExecCommand(program);
53
59
  configureInstallCommand(program);
@@ -3,6 +3,6 @@ import { version } from "../src/index";
3
3
 
4
4
  describe("@enactprotocol/cli", () => {
5
5
  test("exports version", () => {
6
- expect(version).toBe("0.1.0");
6
+ expect(version).toBe("2.0.1");
7
7
  });
8
8
  });
package/tsconfig.json CHANGED
@@ -9,6 +9,7 @@
9
9
  "include": ["src/**/*"],
10
10
  "exclude": ["node_modules", "dist", "tests"],
11
11
  "references": [
12
+ { "path": "../trust" },
12
13
  { "path": "../shared" },
13
14
  { "path": "../secrets" },
14
15
  { "path": "../execution" },