feat: populate org/artist folders via opencode during sandbox setup#27
feat: populate org/artist folders via opencode during sandbox setup#27sweetmantech wants to merge 7 commits intomainfrom
Conversation
… setup - Add ensureOpenCode helper (DRY: combines installOpenCode + writeOpenCodeConfig) - Add installRecoupCLI helper for global CLI install in sandbox - Add populateArtistFolders orchestrator that installs the setup-sandbox skill and runs opencode to create org/artist folder structure - Wire populateArtistFolders into setupSandboxTask between ensureGithubRepo and snapshotAndPersist - Increase setupSandboxTask maxDuration from 5 to 10 minutes - Refactor runSandboxCommandTask to use ensureOpenCode Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughAdds sandbox utilities and integrates them into setup/run tasks: a new orchestrator Changes
Sequence Diagram(s)sequenceDiagram
actor SetupTask
participant Sandbox
participant EnsureOpenCode
participant RecoupCLI
participant OpencodeSkill
SetupTask->>Sandbox: start setup
SetupTask->>EnsureOpenCode: ensureOpenCode(sandbox)
EnsureOpenCode-->>Sandbox: install & configure OpenCode
SetupTask->>RecoupCLI: installRecoupCLI(sandbox)
RecoupCLI-->>Sandbox: npm install -g `@recoupable/cli`@latest
SetupTask->>OpencodeSkill: npx install setup-sandbox (in Sandbox)
OpencodeSkill-->>Sandbox: skill installed
SetupTask->>OpencodeSkill: run skill via opencode (RECOUP_API_KEY)
OpencodeSkill-->>Sandbox: create/populate artist folders
SetupTask->>Sandbox: snapshotAndPersist()
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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: 1
🤖 Fix all issues with AI agents
In `@src/sandboxes/populateArtistFolders.ts`:
- Around line 37-40: Fail-fast: move the RECOUP_API_KEY validation to the start
of populateArtistFolders to avoid running expensive setup when the key is
missing. Locate the function populateArtistFolders in
src/sandboxes/populateArtistFolders.ts and move the block that reads
process.env.RECOUP_API_KEY and throws ("Missing RECOUP_API_KEY environment
variable") to the very top of that function before calling ensureOpenCode or
installRecoupCLI; then remove the duplicate check currently present near the
ensureOpenCode/installRecoupCLI calls. Ensure the code still assigns
recoupApiKey to a local variable that subsequent calls use.
🧹 Nitpick comments (2)
src/sandboxes/installRecoupCLI.ts (1)
19-26: Minor inconsistency: error handling omitsstdoutunlikeinstallOpenCode.
installOpenCode(insrc/sandboxes/installOpenCode.ts) captures bothstdoutandstderron failure, while this function only capturesstderr. npm can sometimes emit useful diagnostics to stdout during failed installs. Consider aligning the two for consistent debugging output.♻️ Suggested fix
if (result.exitCode !== 0) { + const stdout = (await result.stdout()) || ""; const stderr = (await result.stderr()) || ""; logger.error("Failed to install Recoup CLI", { exitCode: result.exitCode, + stdout, stderr, }); throw new Error("Failed to install Recoup CLI"); }src/tasks/runSandboxCommandTask.ts (1)
23-25: Pre-existing: comment says "No retries" butmaxAttempts: 1means one retry attempt.Not introduced by this PR, but since it's visible:
maxAttempts: 1allows one retry (up to 2 total runs), whilesetupSandboxTaskusesmaxAttempts: 0for truly zero retries. The comment on line 24 is misleading. Consider aligning if sandbox operations are genuinely not idempotent.
| const recoupApiKey = process.env.RECOUP_API_KEY; | ||
| if (!recoupApiKey) { | ||
| throw new Error("Missing RECOUP_API_KEY environment variable"); | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major
Move RECOUP_API_KEY validation to the top of the function for fail-fast behavior.
Currently, the env var check runs after ensureOpenCode and installRecoupCLI have already completed (potentially expensive npm installs). If the key is missing, those installs were wasted time. Validate early.
♻️ Suggested reorder
export async function populateArtistFolders(sandbox: Sandbox): Promise<void> {
logger.log("Starting artist folder population via opencode + skill");
+ const recoupApiKey = process.env.RECOUP_API_KEY;
+ if (!recoupApiKey) {
+ throw new Error("Missing RECOUP_API_KEY environment variable");
+ }
+
await ensureOpenCode(sandbox);
await installRecoupCLI(sandbox);And remove the duplicate check at lines 37–40.
🤖 Prompt for AI Agents
In `@src/sandboxes/populateArtistFolders.ts` around lines 37 - 40, Fail-fast: move
the RECOUP_API_KEY validation to the start of populateArtistFolders to avoid
running expensive setup when the key is missing. Locate the function
populateArtistFolders in src/sandboxes/populateArtistFolders.ts and move the
block that reads process.env.RECOUP_API_KEY and throws ("Missing RECOUP_API_KEY
environment variable") to the very top of that function before calling
ensureOpenCode or installRecoupCLI; then remove the duplicate check currently
present near the ensureOpenCode/installRecoupCLI calls. Ensure the code still
assigns recoupApiKey to a local variable that subsequent calls use.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Previously only logged stderr on failure. Now logs full output regardless of exit code so we can verify the skill was actually installed. Co-Authored-By: Claude Opus 4.6 <[email protected]>
The skills CLI prompts for agent selection interactively, which doesn't work in a sandbox. Use -y (auto-confirm) and -g (global). Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
The skill now uses --account flag when RECOUP_ACCOUNT_ID is set, allowing org API keys to query data for a specific account. Co-Authored-By: Claude Opus 4.6 <[email protected]>
git init defaults to master, but the setup-sandbox skill pushes to origin main. For empty repos where no checkout happens, the local branch stays master causing the push to fail silently. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary
populateArtistFoldersorchestrator that installs the setup-sandbox skill and runs opencode to createorgs/<org>/artists/<artist>folder structureensureOpenCodehelper (DRY: combinesinstallOpenCode+writeOpenCodeConfig— always called together)installRecoupCLIhelper (SRP: matchesinstallOpenCodepattern)populateArtistFoldersintosetupSandboxTaskbetweenensureGithubRepoandsnapshotAndPersistsetupSandboxTaskmaxDuration from 5 → 10 minutes for opencode + LLM round-tripsrunSandboxCommandTaskto useensureOpenCodeNew files
src/sandboxes/ensureOpenCode.tssrc/sandboxes/installRecoupCLI.tssrc/sandboxes/populateArtistFolders.tsModified files
src/tasks/setupSandboxTask.tssrc/tasks/runSandboxCommandTask.tsEnvironment variables needed
RECOUP_API_KEY— already in Tasks env, now passed into sandbox for CLI authVERCEL_AI_GATEWAY_API_KEY— already used bywriteOpenCodeConfigTest plan
npx tsc --noEmit— no new type errorssetup-sandboxtask locally viapnpm devorgs/*/artists/*/structure🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Refactor
Chores