Skip to content

agent: @U0AJM7X8FBR How can we give Recoup the ability to use a chartmetric API#107

Open
recoup-coding-agent wants to merge 3 commits intomainfrom
agent/-u0ajm7x8fbr-how-can-we-give-r-1773964072471
Open

agent: @U0AJM7X8FBR How can we give Recoup the ability to use a chartmetric API#107
recoup-coding-agent wants to merge 3 commits intomainfrom
agent/-u0ajm7x8fbr-how-can-we-give-r-1773964072471

Conversation

@recoup-coding-agent
Copy link
Copy Markdown
Collaborator

@recoup-coding-agent recoup-coding-agent commented Mar 19, 2026

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?

Changes:

  • src/sandboxes/getSandboxEnv.ts — added optional CHARTMETRIC_REFRESH_TOKEN pass-through (same pattern as GITHUB_TOKEN). No-op if the env var is not set.
  • src/sandboxes/setupOpenClaw.ts — added optional CHARTMETRIC_REFRESH_TOKEN injection into openclaw.json env block, so the OpenClaw agent and all subprocess spawns inherit it.

Summary by CodeRabbit

  • New Features
    • The Chartmetric base URL is now automatically included in sandbox environments and injected into local sandbox tooling, ensuring calls use the designated Chartmetric endpoint.
  • Tests
    • Sandbox environment tests updated to expect the Chartmetric base URL being present.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b669892d-8087-424e-968d-5fb8195df369

📥 Commits

Reviewing files that changed from the base of the PR and between 3dc39ad and f069a08.

📒 Files selected for processing (3)
  • src/sandboxes/__tests__/getSandboxEnv.test.ts
  • src/sandboxes/getSandboxEnv.ts
  • src/sandboxes/setupOpenClaw.ts
✅ Files skipped from review due to trivial changes (3)
  • src/sandboxes/getSandboxEnv.ts
  • src/sandboxes/tests/getSandboxEnv.test.ts
  • src/sandboxes/setupOpenClaw.ts

📝 Walkthrough

Walkthrough

getSandboxEnv and setupOpenClaw were updated to include a CHARTMETRIC_BASE_URL environment variable set to "https://recoup-api.vercel.app/api/chartmetric" (always present in getSandboxEnv and injected into OpenClaw config/logging). No other env-injection logic was changed.

Changes

Cohort / File(s) Summary
Sandbox env construction
src/sandboxes/getSandboxEnv.ts
Always add CHARTMETRIC_BASE_URL = "https://recoup-api.vercel.app/api/chartmetric" to the returned env object. Existing RECOUP_* and GITHUB_TOKEN behavior unchanged.
OpenClaw setup / env injection
src/sandboxes/setupOpenClaw.ts
Add CHARTMETRIC_BASE_URL to the "Injecting env vars..." log payload and to the sandbox.runCommand script that writes ~/.openclaw/openclaw.json. Conditional GITHUB_TOKEN injection unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🐰 I hopped through code with tiny paws,
Pushed a URL into the cause,
Chartmetric now finds its way,
Into sandboxes bright as day —
Hooray for tiny env applause! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The pull request title is vague and uses a generic question format that doesn't clearly summarize the main change. It reads like a conversation prompt rather than a descriptive commit message. Consider using a more descriptive title like 'Add CHARTMETRIC_BASE_URL injection to sandbox environments' that clearly states what was added and why.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/-u0ajm7x8fbr-how-can-we-give-r-1773964072471
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/sandboxes/setupOpenClaw.ts (1)

47-48: Consider escaping token values in shell-interpolated strings.

Both GITHUB_TOKEN and CHARTMETRIC_REFRESH_TOKEN are directly interpolated into a JavaScript string inside a shell command. If a token contains single quotes or other special characters, it could break the script or cause unexpected behavior.

While environment variables are typically trusted, consider escaping or using a safer injection method (e.g., passing values via stdin or environment variables to the Node subprocess).

♻️ Example safer approach using environment variables
-  const injectEnv = await sandbox.runCommand({
-    cmd: "sh",
-    args: [
-      "-c",
-      `node -e "
-        const fs = require('fs');
-        const p = require('os').homedir() + '/.openclaw/openclaw.json';
-        const c = JSON.parse(fs.readFileSync(p, 'utf8'));
-        c.env = c.env || {};
-        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}';` : ""}
-        ...
-      "`,
-    ],
-  });
+  const injectEnv = await sandbox.runCommand({
+    cmd: "sh",
+    args: [
+      "-c",
+      `node -e "
+        const fs = require('fs');
+        const p = require('os').homedir() + '/.openclaw/openclaw.json';
+        const c = JSON.parse(fs.readFileSync(p, 'utf8'));
+        c.env = c.env || {};
+        c.env.RECOUP_API_KEY = process.env.INJECT_RECOUP_API_KEY;
+        c.env.RECOUP_ACCOUNT_ID = process.env.INJECT_RECOUP_ACCOUNT_ID;
+        if (process.env.INJECT_GITHUB_TOKEN) c.env.GITHUB_TOKEN = process.env.INJECT_GITHUB_TOKEN;
+        if (process.env.INJECT_CHARTMETRIC_REFRESH_TOKEN) c.env.CHARTMETRIC_REFRESH_TOKEN = process.env.INJECT_CHARTMETRIC_REFRESH_TOKEN;
+        ...
+      "`,
+    ],
+    env: {
+      INJECT_RECOUP_API_KEY: process.env.RECOUP_API_KEY,
+      INJECT_RECOUP_ACCOUNT_ID: accountId,
+      ...(githubToken && { INJECT_GITHUB_TOKEN: githubToken }),
+      ...(chartmetricRefreshToken && { INJECT_CHARTMETRIC_REFRESH_TOKEN: chartmetricRefreshToken }),
+    },
+  });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/sandboxes/setupOpenClaw.ts` around lines 47 - 48, The template currently
interpolates githubToken and chartmetricRefreshToken directly into the shell
string setting c.env.GITHUB_TOKEN and c.env.CHARTMETRIC_REFRESH_TOKEN, which can
break if tokens contain quotes or special chars; update the code in
src/sandboxes/setupOpenClaw.ts to safely inject these values by escaping or
serializing them (e.g., replace the direct interpolation with
JSON.stringify(githubToken) and JSON.stringify(chartmetricRefreshToken) or
otherwise escape single quotes) or, preferably, pass them via the spawned
process environment instead of embedding in the shell string; target the exact
interpolations that produce "c.env.GITHUB_TOKEN = '...';" and
"c.env.CHARTMETRIC_REFRESH_TOKEN = '...';" and ensure the final string is
produced using the safe serialization/escape approach.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/sandboxes/setupOpenClaw.ts`:
- Around line 47-48: The template currently interpolates githubToken and
chartmetricRefreshToken directly into the shell string setting
c.env.GITHUB_TOKEN and c.env.CHARTMETRIC_REFRESH_TOKEN, which can break if
tokens contain quotes or special chars; update the code in
src/sandboxes/setupOpenClaw.ts to safely inject these values by escaping or
serializing them (e.g., replace the direct interpolation with
JSON.stringify(githubToken) and JSON.stringify(chartmetricRefreshToken) or
otherwise escape single quotes) or, preferably, pass them via the spawned
process environment instead of embedding in the shell string; target the exact
interpolations that produce "c.env.GITHUB_TOKEN = '...';" and
"c.env.CHARTMETRIC_REFRESH_TOKEN = '...';" and ensure the final string is
produced using the safe serialization/escape approach.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 355f7229-b4bc-4bc2-ae63-f17ec711093d

📥 Commits

Reviewing files that changed from the base of the PR and between 5df28de and 3dc39ad.

📒 Files selected for processing (2)
  • src/sandboxes/getSandboxEnv.ts
  • src/sandboxes/setupOpenClaw.ts

Recoup Agent and others added 2 commits March 20, 2026 00:08
Implements Option A for credits: sandboxes now receive CHARTMETRIC_BASE_URL
pointing to the api proxy (https://recoup-api.vercel.app/api/chartmetric)
instead of the raw CHARTMETRIC_REFRESH_TOKEN. The proxy handles token exchange,
credit deduction, and forwards requests to Chartmetric — keeping the key
server-side only.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tests were failing because the new CHARTMETRIC_BASE_URL env var was added
to getSandboxEnv but the test assertions were not updated to expect it.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant