agent: @U0AJM7X8FBR How can we give Recoup the ability to use a chartmetric API#104
agent: @U0AJM7X8FBR How can we give Recoup the ability to use a chartmetric API#104sweetmantech wants to merge 1 commit intomainfrom
Conversation
Passes the Chartmetric refresh token from Trigger.dev secrets into both getSandboxEnv (for Claude Code agent runs) and setupOpenClaw (for OpenClaw openclaw.json env config) using the same optional pattern as GITHUB_TOKEN. The agent in the sandbox can now use the chartmetric skill via bash without the token being exposed to users — it lives only in Trigger.dev secrets and is injected at runtime. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR adds optional Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/sandboxes/getSandboxEnv.ts`:
- Around line 23-26: Replace the direct read of
process.env.CHARTMETRIC_REFRESH_TOKEN in getSandboxEnv.ts with a Zod-validated
parse: define a Zod schema (e.g., SandboxEnvSchema) that includes
CHARTMETRIC_REFRESH_TOKEN as a string (optional or required per spec), call
SandboxEnvSchema.parse(process.env) (or safeParse and handle errors) to produce
parsedEnv, and then set env.CHARTMETRIC_REFRESH_TOKEN =
parsedEnv.CHARTMETRIC_REFRESH_TOKEN; update any related code to use the parsed
object instead of raw process.env. Ensure you reference SandboxEnvSchema and
parsedEnv in the change and handle validation failures consistently with the
repo’s error handling.
In `@src/sandboxes/setupOpenClaw.ts`:
- Line 48: The template is interpolating raw secret text into the generated
`node -e` script (the `chartmetricRefreshToken` insertion in
src/sandboxes/setupOpenClaw.ts), which can break quoting or allow injection;
update the template to serialize the token value with a safe JS literal encoder
(e.g., use JSON.stringify(chartmetricRefreshToken) when building the
`c.env.CHARTMETRIC_REFRESH_TOKEN = ...` assignment) so the embedded value is
properly escaped and quoted before insertion into the `node -e` script.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 243d7330-11a2-49b1-964a-ea51eb9010a2
📒 Files selected for processing (2)
src/sandboxes/getSandboxEnv.tssrc/sandboxes/setupOpenClaw.ts
| const chartmetricRefreshToken = process.env.CHARTMETRIC_REFRESH_TOKEN; | ||
| if (chartmetricRefreshToken) { | ||
| env.CHARTMETRIC_REFRESH_TOKEN = chartmetricRefreshToken; | ||
| } |
There was a problem hiding this comment.
Validate CHARTMETRIC_REFRESH_TOKEN through a Zod env schema before use.
Line 23 reads from process.env directly; this bypasses the repo’s schema-validation requirement for TS sources. Please parse env once (e.g., with a Zod schema) and build env from parsed output.
Suggested refactor
+import { z } from "zod";
+
+const SandboxEnvSchema = z.object({
+ RECOUP_API_KEY: z.string().min(1),
+ GITHUB_TOKEN: z.string().min(1).optional(),
+ CHARTMETRIC_REFRESH_TOKEN: z.string().min(1).optional(),
+});
+
export function getSandboxEnv(
accountId: string
): Record<string, string> {
- const apiKey = process.env.RECOUP_API_KEY;
+ const parsedEnv = SandboxEnvSchema.parse(process.env);
+ const apiKey = parsedEnv.RECOUP_API_KEY;
if (!apiKey) {
throw new Error("Missing RECOUP_API_KEY environment variable");
}
@@
- const githubToken = process.env.GITHUB_TOKEN;
+ const githubToken = parsedEnv.GITHUB_TOKEN;
@@
- const chartmetricRefreshToken = process.env.CHARTMETRIC_REFRESH_TOKEN;
+ const chartmetricRefreshToken = parsedEnv.CHARTMETRIC_REFRESH_TOKEN;As per coding guidelines, Use Zod for schema validation.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/sandboxes/getSandboxEnv.ts` around lines 23 - 26, Replace the direct read
of process.env.CHARTMETRIC_REFRESH_TOKEN in getSandboxEnv.ts with a
Zod-validated parse: define a Zod schema (e.g., SandboxEnvSchema) that includes
CHARTMETRIC_REFRESH_TOKEN as a string (optional or required per spec), call
SandboxEnvSchema.parse(process.env) (or safeParse and handle errors) to produce
parsedEnv, and then set env.CHARTMETRIC_REFRESH_TOKEN =
parsedEnv.CHARTMETRIC_REFRESH_TOKEN; update any related code to use the parsed
object instead of raw process.env. Ensure you reference SandboxEnvSchema and
parsedEnv in the change and handle validation failures consistently with the
repo’s error handling.
| c.env.RECOUP_API_KEY = '${process.env.RECOUP_API_KEY}'; | ||
| c.env.RECOUP_ACCOUNT_ID = '${accountId}'; | ||
| ${githubToken ? `c.env.GITHUB_TOKEN = '${githubToken}';` : ""} | ||
| ${chartmetricRefreshToken ? `c.env.CHARTMETRIC_REFRESH_TOKEN = '${chartmetricRefreshToken}';` : ""} |
There was a problem hiding this comment.
Escape token values before embedding into the node -e script.
Line 48 interpolates a raw secret inside a quoted JS snippet. A token containing quote/escape characters can break command generation and opens an injection risk. Use JSON.stringify(...) for assignment literals.
Safer assignment serialization
- ${chartmetricRefreshToken ? `c.env.CHARTMETRIC_REFRESH_TOKEN = '${chartmetricRefreshToken}';` : ""}
+ ${chartmetricRefreshToken ? `c.env.CHARTMETRIC_REFRESH_TOKEN = ${JSON.stringify(chartmetricRefreshToken)};` : ""}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ${chartmetricRefreshToken ? `c.env.CHARTMETRIC_REFRESH_TOKEN = '${chartmetricRefreshToken}';` : ""} | |
| ${chartmetricRefreshToken ? `c.env.CHARTMETRIC_REFRESH_TOKEN = ${JSON.stringify(chartmetricRefreshToken)};` : ""} |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/sandboxes/setupOpenClaw.ts` at line 48, The template is interpolating raw
secret text into the generated `node -e` script (the `chartmetricRefreshToken`
insertion in src/sandboxes/setupOpenClaw.ts), which can break quoting or allow
injection; update the template to serialize the token value with a safe JS
literal encoder (e.g., use JSON.stringify(chartmetricRefreshToken) when building
the `c.env.CHARTMETRIC_REFRESH_TOKEN = ...` assignment) so the embedded value is
properly escaped and quoted before insertion into the `node -e` script.
Automated PR from coding agent.
Prompt: @U0AJM7X8FBR How can we give Recoup the ability to use a chartmetric API key in a sandbox without exposing the key?
I want the agent in the sandbox to be able to use our chartmetric skill (in the skills repo and also installed in sandboxes) so we don't have to build a bunch of tools - it just uses bash and the skill
Summary by CodeRabbit