# Connecting VS Code to BytesBrains Cruise

This guide walks you through connecting Visual Studio Code to BytesBrains Cruise via the official `BytesBrains.bytesbrains-cruise` extension.

Whether you are completing a Round 2 practical assessment task (using your $5 complimentary credit) or configuring your development environment, follow these steps to configure your editor and start running prompts through Cruise.

---

## Prerequisites & Supported Versions

- **Editor:** Visual Studio Code (VS Code 1.104+; required for Copilot Chat model provider integration and agent mode).
- **Extension:** GitHub Copilot and GitHub Copilot Chat extensions installed and active.
- **BytesBrains Account:** An active account on [bytesbrains.com](https://bytesbrains.com).

---

## 1. Before You Start (Workspace & Credit Check)

1. Sign in to your account at [bytesbrains.com/login](https://bytesbrains.com/login).
2. Ensure you have an active workspace. Cruise requires a workspace to assign credits and route requests. (If you see `cruiseGrantState: no_workspace`, create or select your workspace first).
3. **Check your balance:**
   - Go to [bytesbrains.com/dashboard/cruise/spend](https://bytesbrains.com/dashboard/cruise/spend) or the **Credits** tab.
   - For candidates, verify your **$5.00** complimentary credit grant is reflected in your workspace.
   - **Important note on candidate credit:** Your $5 grant is intended to cover both your coding agent interactions in VS Code and the automated `wrok.in` code reviews on GitHub. Spend it deliberately!

---

## 2. Issue a Dedicated API Key

1. In the Cruise dashboard, open the **Keys** tab at [bytesbrains.com/dashboard/cruise/keys](https://bytesbrains.com/dashboard/cruise/keys).
2. Click **Create Key**.
3. Name your key descriptively (e.g., `vscode-agent` or `practical-task-vscode`).
4. Select the project associated with your task.
5. Copy your newly generated key immediately. It begins with the prefix `cru_live_`. Store it securely.
   - *Security hygiene:* Never commit your Cruise API key to git repositories or share it publicly. It will be entered directly into VS Code's secure credential prompt.

---

## 3. Connect the Client (Install & Configure Extension)

### Step 3.1: Install the Extension
- **Marketplace Link:** [Install BytesBrains Cruise from VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=BytesBrains.bytesbrains-cruise)
- **Direct in VS Code:**
  1. Open the Extensions view (`Cmd+Shift+X` on macOS, `Ctrl+Shift+X` on Windows/Linux).
  2. Search for `BytesBrains Cruise`.
  3. Click **Install** on the extension published by **BytesBrains** (`BytesBrains.bytesbrains-cruise`).
  *(Note for VSCodium / Theia users: The extension is also available on [Open VSX](https://open-vsx.org/extension/bytesbrains/bytesbrains-cruise)).*

### Step 3.2: Configure Your API Key
1. Open GitHub Copilot Chat in VS Code (`Cmd+Shift+I` / `Ctrl+Shift+I` or click the chat bubble icon in the activity bar).
2. When prompted by the Cruise extension, paste your Cruise API key (`cru_live_...`).
3. *(Alternative configuration:)* Open the VS Code Command Palette (`Cmd+Shift+P` / `Ctrl+Shift+P`), run `Preferences: Open User Settings`, search for `BytesBrains Cruise`, and enter your API key under `bytesbrainsCruise.apiKey`.

### Step 3.3: Select Cruise Models and Agent Mode
1. In the Copilot Chat window, locate the model picker dropdown at the bottom of the chat panel.
2. Select one of the Cruise model lanes:
   - **`bb/agentic-coding`** (Recommended): Optimized for code generation, multi-file refactoring, debugging, and terminal operations.
   - **`bb/chat-assistant`**: General conversational queries and high-level project discussions.
3. Switch Copilot Chat to **Agent Mode** (`@agent` or click the agent mode toggle) so the agent can inspect your workspace files, propose edits, and execute test runs.

---

## 4. Check It Works (Verification & Spend Tracking)

1. In Copilot Chat, send a test prompt with `bb/agentic-coding` selected:
   ```text
   Review the workspace directory structure and summarize the project.
   ```
2. Verify that the agent responds with insightful project analysis.
3. **Verify spend reflection on the dashboard:**
   - Go to [bytesbrains.com/dashboard/cruise/spend](https://bytesbrains.com/dashboard/cruise/spend).
   - Confirm that the request is recorded in your per-request ledger.
   - Cruise records the timestamp, model selected, prompt and completion tokens, and the exact dollar amount deducted.

---

## 5. Choosing a Lane

Instead of hardcoding a specific proprietary model ID in your codebase or agent settings, Cruise uses **Lanes**:
- A lane names *the work* rather than a single provider model.
- At runtime, Cruise allocates the most cost-effective and capable member model that satisfies the task requirements. If one provider experiences latency or an outage, Cruise automatically falls back to an available alternative without interrupting your work.
- **Recommended Lane for Coding:** `bb/agentic-coding`
- To learn more about how lanes evaluate candidate models and fallbacks, see [Cruise Lanes Overview](https://bytesbrains.com/cruise#cruise-lanes-title).

---

## 6. When It Refuses (Error Handling & Troubleshooting)

If an agent call fails or is rejected by the gateway, check for these standard Cruise refusal codes:

### `wallet_exhausted` (HTTP 402 Payment Required)
- **What it means:** The workspace prepaid credit balance has reached zero ($0.00). Requests are refused until funds are added.
- **For Candidates:** Do not top up personal funds. Contact the hiring team via your application page to request review or grant extension. See [bytesbrains.com/careers/application](https://bytesbrains.com/careers/application).
- **For Customers:** Top up your workspace balance in the Cruise dashboard under Credits & Billing.

### `budget_exhausted` (HTTP 429 Too Many Requests)
- **What it means:** The project hard budget ceiling set for this key or project has been reached.
- **For Candidates:** Check that requests are assigned to your active hiring project, or contact hiring if limits persist.
- **For Customers:** Review and adjust project budget thresholds on the Projects tab in your Cruise workspace ([bytesbrains.com/dashboard/cruise/projects](https://bytesbrains.com/dashboard/cruise/projects)).

### `invalid_api_key` (HTTP 401 Unauthorized)
- **What it means:** The API key provided does not match an active key in your Cruise workspace.
- **For Candidates:** Verify that the key starts with "cru_live_", was copied completely with no leading or trailing whitespace, and is active in your Keys tab.
- **For Customers:** Check key status or generate a new dedicated key on the Keys tab ([bytesbrains.com/dashboard/cruise/keys](https://bytesbrains.com/dashboard/cruise/keys)).

---

## 7. Assessment Guidance for Candidates

If you are completing the Round 2 practical assessment task for BytesBrains:
1. **Grant Budget:** You have $5.00 complimentary credit. This credit is shared across your coding agent and automated `wrok.in` PR reviews. Use it thoughtfully.
2. **AI Code Reviews with wrok.in:**
   - Install the `wrok.in` GitHub app on your dedicated public task repository.
   - Configure BYOK in `wrok.in` using your Cruise API key.
   - Every pull request opened on your repo will be reviewed by `wrok.in`. Direct your agent to inspect comments, rework code, push updates, and reply on each review thread.
3. **Keep a JOURNEY.md:**
   - Document your journey in `JOURNEY.md` in the root of your repo: your design choices, agent prompts, obstacles faced, and how you worked through review feedback.
4. **Final Submission:**
   - Once all PR reviews pass and tests are green, submit your repository and pull request link directly on your application page at [bytesbrains.com/careers/application](https://bytesbrains.com/careers/application).
