Skip to content

feat: populate org/artist folders via opencode during sandbox setup#27

Open
sweetmantech wants to merge 7 commits intomainfrom
sweetmantech/myc-4229-tasks-setup-sandbox-opencode-recoup-setup-skill
Open

feat: populate org/artist folders via opencode during sandbox setup#27
sweetmantech wants to merge 7 commits intomainfrom
sweetmantech/myc-4229-tasks-setup-sandbox-opencode-recoup-setup-skill

Conversation

@sweetmantech
Copy link
Contributor

@sweetmantech sweetmantech commented Feb 12, 2026

Summary

  • Adds populateArtistFolders orchestrator that installs the setup-sandbox skill and runs opencode to create orgs/<org>/artists/<artist> folder structure
  • Extracts ensureOpenCode helper (DRY: combines installOpenCode + writeOpenCodeConfig — always called together)
  • Extracts installRecoupCLI helper (SRP: matches installOpenCode pattern)
  • Wires populateArtistFolders into setupSandboxTask between ensureGithubRepo and snapshotAndPersist
  • Increases setupSandboxTask maxDuration from 5 → 10 minutes for opencode + LLM round-trips
  • Refactors runSandboxCommandTask to use ensureOpenCode

New files

  • src/sandboxes/ensureOpenCode.ts
  • src/sandboxes/installRecoupCLI.ts
  • src/sandboxes/populateArtistFolders.ts

Modified files

  • src/tasks/setupSandboxTask.ts
  • src/tasks/runSandboxCommandTask.ts

Environment variables needed

  • RECOUP_API_KEY — already in Tasks env, now passed into sandbox for CLI auth
  • VERCEL_AI_GATEWAY_API_KEY — already used by writeOpenCodeConfig

Test plan

  • npx tsc --noEmit — no new type errors
  • Trigger setup-sandbox task locally via pnpm dev
  • Verify sandbox filesystem contains orgs/*/artists/*/ structure
  • Verify GitHub repo has the folders committed and pushed

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Sandbox setup now populates artist folders, installs the Recoup CLI, and runs the required setup skill to provision content.
  • Refactor

    • OpenCode installation and configuration consolidated into a single orchestrated step during sandbox initialization.
  • Chores

    • Sandbox setup timeout increased from 5 to 10 minutes to accommodate the additional initialization steps.

… 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]>
@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

Warning

Rate limit exceeded

@sweetmantech has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 29 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📝 Walkthrough

Walkthrough

Adds sandbox utilities and integrates them into setup/run tasks: a new orchestrator ensureOpenCode, a Recoup CLI installer, and populateArtistFolders which runs OpenCode, installs a skill, and executes it; setupSandboxTask now calls the population step and its timeout is extended.

Changes

Cohort / File(s) Summary
OpenCode Orchestrator
src/sandboxes/ensureOpenCode.ts, src/tasks/runSandboxCommandTask.ts
New ensureOpenCode(sandbox) combines OpenCode installation and configuration; runSandboxCommandTask now calls ensureOpenCode in sandbox setup instead of separate calls.
Recoup CLI Installer
src/sandboxes/installRecoupCLI.ts
Adds installRecoupCLI(sandbox) to install @recoupable/cli@latest via npm install -g (runs with sudo in sandbox), logs and throws on non‑zero exit.
Artist Folder Population
src/sandboxes/populateArtistFolders.ts, src/tasks/setupSandboxTask.ts
Adds populateArtistFolders(sandbox) which ensures OpenCode, installs Recoup CLI, installs setup-sandbox skill via npx, and runs it through opencode (requires RECOUP_API_KEY); setupSandboxTask awaits this step and increases maxDuration to 10 minutes.

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()
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped into a sandbox bright and neat,
ensured OpenCode and made installs complete,
Recoup spins up and skills take flight,
folders bloom in morning light,
the rabbit smiles — setup's done, what a treat!

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely summarizes the main change: adding functionality to populate org/artist folders via opencode during sandbox setup, which aligns with the core objective of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

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

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sweetmantech/myc-4229-tasks-setup-sandbox-opencode-recoup-setup-skill

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

@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.

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 omits stdout unlike installOpenCode.

installOpenCode (in src/sandboxes/installOpenCode.ts) captures both stdout and stderr on failure, while this function only captures stderr. 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" but maxAttempts: 1 means one retry attempt.

Not introduced by this PR, but since it's visible: maxAttempts: 1 allows one retry (up to 2 total runs), while setupSandboxTask uses maxAttempts: 0 for truly zero retries. The comment on line 24 is misleading. Consider aligning if sandbox operations are genuinely not idempotent.

Comment on lines +37 to +40
const recoupApiKey = process.env.RECOUP_API_KEY;
if (!recoupApiKey) {
throw new Error("Missing RECOUP_API_KEY environment variable");
}
Copy link

Choose a reason for hiding this comment

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

🛠️ 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.

sweetmantech and others added 6 commits February 13, 2026 10:01
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]>
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]>
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

Comments