(args: z.infer<typeof Args>, _ctx: ToolContext)
| 22 | argsSchema = Args; |
| 23 | |
| 24 | async execute(args: z.infer<typeof Args>, _ctx: ToolContext): Promise<ToolResult> { |
| 25 | const envVar = args.env_var.trim().toUpperCase(); |
| 26 | const value = args.value.trim(); |
| 27 | if (!/^[A-Z][A-Z0-9_]{2,63}$/.test(envVar)) { |
| 28 | return { content: `[SAVE_KEY_ERROR] "${envVar}" is not a valid environment variable name (A-Z, 0-9, _).`, isError: true }; |
| 29 | } |
| 30 | if (!value || value.length < 8) { |
| 31 | return { content: '[SAVE_KEY_ERROR] That does not look like a key (too short). Ask the user to re-paste it.', isError: true }; |
| 32 | } |
| 33 | if (/\s/.test(value)) { |
| 34 | return { content: '[SAVE_KEY_ERROR] The value contains whitespace — probably a paste accident. Ask the user to re-paste just the key.', isError: true }; |
| 35 | } |
| 36 | |
| 37 | const { setEnvKey } = await import('../../setup/env-writer.js'); |
| 38 | const file = await setEnvKey(envVar, value); |
| 39 | process.env[envVar] = value; // live for THIS session — the blocked task can retry right away |
| 40 | |
| 41 | const { findServiceKey } = await import('../../setup/key-guidance.js'); |
| 42 | const svc = findServiceKey(envVar); |
| 43 | const unlocked = svc ? ` ${svc.service} is now available — ${svc.unlocks}.` : ''; |
| 44 | return { |
| 45 | content: `✓ ${envVar} saved to ${file} (chmod 600) and loaded into this session.${unlocked} Retry the blocked step now.`, |
| 46 | metadata: { envVar, service: svc?.service }, |
| 47 | }; |
| 48 | } |
| 49 | } |
nothing calls this directly
no test coverage detected