diff --git a/.github/README_UPDATE_RULE.md b/.github/README_UPDATE_RULE.md new file mode 100644 index 0000000000..deb452fe27 --- /dev/null +++ b/.github/README_UPDATE_RULE.md @@ -0,0 +1,126 @@ +# README Update Rule + +## ⚠️ MANDATORY: Update README with Every Commit + +Every commit MUST update the `README.md` file under the **"Commits Categorized by Strategic Pillars"** section. + +--- + +## How to Update + +### 1. Determine Which Pillar Your Change Belongs To: + +#### **Pillar 1: Idea Stack (Infrastructure & Architecture)** +- Architecture changes +- Infrastructure setup +- CI/CD configuration +- Provider systems +- Build tools +- Package management +- Git hooks + +#### **Pillar 2: TUI Features (User Interface & Experience)** +- UI/UX improvements +- TUI components +- Dialogs and modals +- Keyboard shortcuts +- Visual feedback +- User interactions +- Metrics display in UI + +#### **Pillar 3: SDK Level Features (Core Functionality & API)** +- Core functionality +- API changes +- Authentication systems +- Retry logic +- SDK implementations +- Request/response handling +- Error handling + +#### **Pillar 4: Experiment and Reporting (Metrics & Analytics)** +- Metrics collection +- Logging systems +- Experimentation tracking +- Analytics +- Reporting tools +- Usage statistics + +--- + +### 2. Add Your Commit to the README + +**Location:** Near the top of `README.md`, under "Commits Categorized by Strategic Pillars" + +**Format:** +```markdown +- **[commit-hash]** - [Brief description] ([key details]) +``` + +**Example:** +```markdown +- **a1b2c3d4e** - Add cache display to sidebar (93% hit rate visualization) +``` + +--- + +### 3. Placement Rules + +- Add **new commits at the TOP** of their pillar section (most recent first) +- Keep entries concise (one line) +- Include commit hash (first 9 characters) +- Mention key metrics if applicable (lines changed, files added, etc.) + +--- + +## Example Workflow + +```bash +# 1. Make your changes +git add . + +# 2. Commit with descriptive message +git commit -m "add cache display to sidebar" + +# 3. Get your commit hash +git log -1 --format=%h + +# 4. Update README.md under appropriate pillar +# Add line: - **abc123def** - Add cache display to sidebar (shows 93% cache hit rate) + +# 5. Amend your commit to include README update +git add README.md +git commit --amend --no-edit + +# 6. Push +git push +``` + +--- + +## Why This Matters + +1. **Transparency:** Everyone can see what's been done at a glance +2. **Organization:** Changes are categorized by strategic focus +3. **History:** Complete record of all improvements +4. **Planning:** Easy to see which pillars need attention + +--- + +## Enforcement + +This rule is enforced by: +- Git pre-push hooks (warning if README not updated) +- Code review process +- Team accountability + +**If you forget:** The pre-push hook will remind you to update the README before pushing. + +--- + +## Questions? + +Ask any collaborator: +- Kevin +- Isaac +- Daniel +- Arihant diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000000..8e65dd8ad6 --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,88 @@ +name: npm-publish +run-name: "npm publish ${{ inputs.bump }}" + +on: + workflow_dispatch: + inputs: + bump: + description: "Bump major, minor, or patch" + required: true + type: choice + options: + - major + - minor + - patch + version: + description: "Override version (optional)" + required: false + type: string + +concurrency: ${{ github.workflow }}-${{ github.ref }} + +permissions: + contents: write + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: ./.github/actions/setup-bun + + - name: Setup npm auth + run: | + echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc + + - name: Publish packages + run: | + export OPENCODE_BUMP="${{ inputs.bump }}" + export OPENCODE_VERSION="${{ inputs.version }}" + export OPENCODE_CHANNEL="latest" + + # Get version + cd packages/script + VERSION=$(bun run -e 'import { Script } from "./src/index.ts"; console.log(Script.version)') + cd ../.. + echo "Publishing version: $VERSION" + + # Update all package.json files + find . -name "package.json" -not -path "*/node_modules/*" -not -path "*/dist/*" | while read file; do + bun -e "const pkg = await Bun.file('$file').json(); pkg.version = '$VERSION'; await Bun.write('$file', JSON.stringify(pkg, null, 2) + '\n')" + echo "Updated: $file" + done + + bun install + + # Publish SDK + echo "=== Publishing cerebras-sdk ===" + cd packages/sdk/js + ./script/publish.ts + cd ../../.. + + # Publish Plugin + echo "=== Publishing cerebras-plugin ===" + cd packages/plugin + ./script/publish.ts + cd ../.. + + # Publish CLI + echo "=== Publishing cerebras-code ===" + cd packages/opencode + ./script/publish.ts + cd ../.. + + # Commit and tag + git config user.email "github-actions[bot]@users.noreply.github.com" + git config user.name "github-actions[bot]" + git add . + git commit -m "release: v$VERSION" || echo "No changes to commit" + git tag "v$VERSION" + git push origin HEAD --tags --no-verify + + # Create GitHub Release + gh release create "v$VERSION" --title "v$VERSION" --notes "Release v$VERSION" + env: + GH_TOKEN: ${{ github.token }} diff --git a/.husky/pre-push b/.husky/pre-push index afc97dd92c..1b5fc37f7b 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -25,4 +25,21 @@ if [ "$CURRENT_VERSION" != "$EXPECTED_VERSION" ]; then echo "Error: Bun version $CURRENT_VERSION does not match expected version $EXPECTED_VERSION from package.json" exit 1 fi + +# Check if README.md was updated in this push +if git diff --name-only origin/$(git branch --show-current)..HEAD | grep -q "README.md"; then + echo "✓ README.md updated - good job!" +else + echo "" + echo "⚠️ WARNING: README.md was not updated!" + echo "Please add your commit to the appropriate pillar section in README.md" + echo "See .github/README_UPDATE_RULE.md for guidelines" + echo "" + read -p "Continue anyway? (y/N) " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi +fi + bun typecheck diff --git a/CACHE_IMPLEMENTATION_CHANGES.md b/CACHE_IMPLEMENTATION_CHANGES.md new file mode 100644 index 0000000000..4958297969 --- /dev/null +++ b/CACHE_IMPLEMENTATION_CHANGES.md @@ -0,0 +1,518 @@ +# Complete List of Changes for Cache Display Implementation + +## Overview +This document details **all changes** needed to get cache information from the Cerebras API to display in the sidebar with statistics. + +--- + +## The Problem + +**Issue:** Cerebras API uses OpenAI **Chat Completions** format, but OpenCode was built for OpenAI **Responses API** format. + +**Key Difference:** +- **Chat Completions API**: Uses `prompt_tokens`, `completion_tokens`, `prompt_tokens_details` +- **Responses API**: Uses `input_tokens`, `output_tokens`, `input_tokens_details` + +**Result:** Cache data from Cerebras (`prompt_tokens_details.cached_tokens`) was being ignored. + +--- + +## Data Flow (Before Changes) + +``` +Cerebras API Response +{ + "usage": { + "prompt_tokens": 3000, ← Not parsed + "prompt_tokens_details": { + "cached_tokens": 2800 ← Lost! + } + } +} + ↓ +OpenCode SDK (expects input_tokens) + ↓ +Schema validation fails / fields = undefined + ↓ +cachedInputTokens = undefined + ↓ +Sidebar: cache.read = 0 ← No cache data! +``` + +--- + +## Data Flow (After Changes) + +``` +Cerebras API Response +{ + "usage": { + "prompt_tokens": 3000, + "prompt_tokens_details": { + "cached_tokens": 2800 + } + } +} + ↓ +OpenCode SDK (now accepts BOTH formats) +cachedInputTokens = 2800 ← Extracted! + ↓ +Session.getUsage() +tokens.cache.read = 2800 ← Stored! + ↓ +Database (SQLite) +message.tokens.cache.read = 2800 ← Persisted! + ↓ +Sidebar calculation +cacheHitRate = 93% ← Calculated! + ↓ +Sidebar UI +⚡ 2,800 cached (93%) ← Displayed! +``` + +--- + +## Changes Required + +### **Change 1: Update API Response Schema** + +**File:** `packages/opencode/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts` + +**Location:** Lines 1300-1305 + +**Current Code:** +```typescript +const usageSchema = z.object({ + input_tokens: z.number(), + input_tokens_details: z.object({ cached_tokens: z.number().nullish() }).nullish(), + output_tokens: z.number(), + output_tokens_details: z.object({ reasoning_tokens: z.number().nullish() }).nullish(), +}) +``` + +**New Code:** +```typescript +const usageSchema = z.object({ + // Support both OpenAI Responses API format (input_tokens) and Chat Completions format (prompt_tokens) + input_tokens: z.number().optional(), + prompt_tokens: z.number().optional(), + input_tokens_details: z.object({ cached_tokens: z.number().nullish() }).nullish(), + prompt_tokens_details: z.object({ cached_tokens: z.number().nullish() }).nullish(), + output_tokens: z.number().optional(), + completion_tokens: z.number().optional(), + output_tokens_details: z.object({ reasoning_tokens: z.number().nullish() }).nullish(), + completion_tokens_details: z.object({ reasoning_tokens: z.number().nullish() }).nullish(), +}) +``` + +**Why:** +- Makes all fields optional (`.optional()`) +- Adds Chat Completions format fields (`prompt_tokens`, `completion_tokens`, etc.) +- Allows schema to accept responses from both API formats +- Backward compatible: existing Responses API calls still work + +**Impact:** Schema validation no longer rejects Cerebras responses + +--- + +### **Change 2: Update Non-Streaming Response Parser** + +**File:** `packages/opencode/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts` + +**Location:** Lines 752-758 + +**Current Code:** +```typescript +usage: { + inputTokens: response.usage.input_tokens, + outputTokens: response.usage.output_tokens, + totalTokens: response.usage.input_tokens + response.usage.output_tokens, + reasoningTokens: response.usage.output_tokens_details?.reasoning_tokens ?? undefined, + cachedInputTokens: response.usage.input_tokens_details?.cached_tokens ?? undefined, +}, +``` + +**New Code:** +```typescript +usage: { + inputTokens: response.usage.input_tokens ?? response.usage.prompt_tokens ?? 0, + outputTokens: response.usage.output_tokens ?? response.usage.completion_tokens ?? 0, + totalTokens: (response.usage.input_tokens ?? response.usage.prompt_tokens ?? 0) + + (response.usage.output_tokens ?? response.usage.completion_tokens ?? 0), + reasoningTokens: response.usage.output_tokens_details?.reasoning_tokens ?? + response.usage.completion_tokens_details?.reasoning_tokens ?? undefined, + cachedInputTokens: response.usage.input_tokens_details?.cached_tokens ?? + response.usage.prompt_tokens_details?.cached_tokens ?? undefined, +}, +``` + +**Why:** +- Uses nullish coalescing (`??`) to check both field names +- Falls back to Chat Completions format if Responses API format not present +- Extracts `cached_tokens` from either `input_tokens_details` or `prompt_tokens_details` +- Defaults to 0 if both are missing (prevents NaN) + +**Impact:** `cachedInputTokens` now populated with Cerebras data + +--- + +### **Change 3: Update Streaming Response Parser** + +**File:** `packages/opencode/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts` + +**Location:** Lines 1232-1236 + +**Current Code:** +```typescript +usage.inputTokens = value.response.usage.input_tokens +usage.outputTokens = value.response.usage.output_tokens +usage.totalTokens = value.response.usage.input_tokens + value.response.usage.output_tokens +usage.reasoningTokens = value.response.usage.output_tokens_details?.reasoning_tokens ?? undefined +usage.cachedInputTokens = value.response.usage.input_tokens_details?.cached_tokens ?? undefined +``` + +**New Code:** +```typescript +usage.inputTokens = value.response.usage.input_tokens ?? value.response.usage.prompt_tokens ?? 0 +usage.outputTokens = value.response.usage.output_tokens ?? value.response.usage.completion_tokens ?? 0 +usage.totalTokens = (value.response.usage.input_tokens ?? value.response.usage.prompt_tokens ?? 0) + + (value.response.usage.output_tokens ?? value.response.usage.completion_tokens ?? 0) +usage.reasoningTokens = value.response.usage.output_tokens_details?.reasoning_tokens ?? + value.response.usage.completion_tokens_details?.reasoning_tokens ?? undefined +usage.cachedInputTokens = value.response.usage.input_tokens_details?.cached_tokens ?? + value.response.usage.prompt_tokens_details?.cached_tokens ?? undefined +``` + +**Why:** +- Same fix as Change 2, but for streaming responses +- Cerebras streaming responses also use Chat Completions format +- Ensures cache data captured in streaming mode + +**Impact:** Cache stats work in both streaming and non-streaming modes + +--- + +### **Change 4: Add Cache Calculation to Sidebar** + +**File:** `packages/opencode/src/cli/cmd/tui/routes/session/sidebar.tsx` + +**Location:** Lines 48-58 (updating the `context` memo) + +**Current Code:** +```typescript +const context = createMemo(() => { + const last = messages().findLast((x) => x.role === "assistant" && x.tokens.output > 0) as AssistantMessage + if (!last) return + const total = + last.tokens.input + last.tokens.output + last.tokens.reasoning + last.tokens.cache.read + last.tokens.cache.write + const model = sync.data.provider.find((x) => x.id === last.providerID)?.models[last.modelID] + return { + tokens: total.toLocaleString(), + percentage: model?.limit.context ? Math.round((total / model.limit.context) * 100) : null, + } +}) +``` + +**New Code:** +```typescript +const context = createMemo(() => { + const last = messages().findLast((x) => x.role === "assistant" && x.tokens.output > 0) as AssistantMessage + if (!last) return + const total = + last.tokens.input + last.tokens.output + last.tokens.reasoning + last.tokens.cache.read + last.tokens.cache.write + const model = sync.data.provider.find((x) => x.id === last.providerID)?.models[last.modelID] + + // Calculate cache statistics + const cachedTokens = last.tokens.cache.read + const totalInput = last.tokens.input + cachedTokens + const cacheHitRate = totalInput > 0 ? Math.round((cachedTokens / totalInput) * 100) : 0 + + return { + tokens: total.toLocaleString(), + percentage: model?.limit.context ? Math.round((total / model.limit.context) * 100) : null, + cache: { + tokens: cachedTokens.toLocaleString(), + hitRate: cacheHitRate, + } + } +}) +``` + +**Why:** +- `cachedTokens`: Extract from `last.tokens.cache.read` (already populated by Changes 1-3) +- `totalInput`: Sum of fresh input tokens + cached tokens +- `cacheHitRate`: Percentage of input that came from cache +- Format tokens with commas for readability +- Return cache stats as part of context object + +**Formula:** `cacheHitRate = (cachedTokens / (input + cachedTokens)) * 100` + +**Example:** +``` +input = 200 tokens (fresh) +cachedTokens = 2800 tokens (from cache) +totalInput = 3000 tokens +cacheHitRate = (2800 / 3000) * 100 = 93% +``` + +**Impact:** Cache statistics now calculated and available for display + +--- + +### **Change 5: Display Cache Stats in Sidebar UI** + +**File:** `packages/opencode/src/cli/cmd/tui/routes/session/sidebar.tsx` + +**Location:** Lines 88-96 (updating the Context display box) + +**Current Code:** +```typescript + + + Context + + {context()?.tokens ?? 0} tokens + {context()?.percentage ?? 0}% used + + Requests: {usage().total} (1m {usage().min1} / 1h {usage().hour1} / 24h {usage().day1}) + + +``` + +**New Code:** +```typescript + + + Context + + {context()?.tokens ?? 0} tokens + {context()?.percentage ?? 0}% used + + Requests: {usage().total} (1m {usage().min1} / 1h {usage().hour1} / 24h {usage().day1}) + + 0}> + 80 ? theme.success : theme.warning + }}> + ⚡ {context()!.cache.tokens} cached ({context()!.cache.hitRate}%) + + + +``` + +**Why:** +- ``: Only display if cache data exists and hit rate > 0 +- Color coding: + - **Green** (`theme.success`): Hit rate > 80% (excellent caching) + - **Yellow** (`theme.warning`): Hit rate ≤ 80% (moderate caching) +- `⚡` emoji: Visual indicator for cache performance +- Display format: `⚡ 2,800 cached (93%)` + +**Visual Examples:** +``` +⚡ 2,800 cached (93%) ← Green (>80%) +⚡ 500 cached (45%) ← Yellow (≤80%) +[hidden] ← No display if hitRate = 0 +``` + +**Impact:** Users can now see cache performance in real-time + +--- + +## Files Modified Summary + +| File | Changes | Purpose | +|------|---------|---------| +| `openai-responses-language-model.ts` | 3 locations | Parse both API formats, extract cache data | +| `sidebar.tsx` | 2 locations | Calculate and display cache statistics | + +**Total:** 5 changes across 2 files + +--- + +## Testing the Changes + +### 1. Verify API Parsing +```bash +# Run with verbose logging +CEREBRAS_API_KEY=your_key bun run packages/opencode/src/index.ts --verbose + +# Look for cache tokens in logs +# Should see: cachedInputTokens: 2800 +``` + +### 2. Verify Database Storage +```bash +# After a conversation with 2+ turns +sqlite3 ~/.opencode/sessions/[session-id]/session.db + +# Query message tokens +SELECT tokens FROM message WHERE role = 'assistant' LIMIT 1; + +# Expected output: +# {"input":200,"output":150,"reasoning":0,"cache":{"read":2800,"write":0}} +``` + +### 3. Verify Sidebar Display +```bash +# Start OpenCode and have a conversation +# After turn 2+, check the sidebar + +# Expected display: +Context +12,345 tokens +45% used +Requests: 5 (1m 2 / 1h 5 / 24h 5) +⚡ 2,800 cached (93%) ← Should appear in green +``` + +### 4. Test Edge Cases +```typescript +// No cache (first message) +// Sidebar should NOT show cache line + +// Low cache hit rate (20%) +⚡ 100 cached (20%) ← Should appear in yellow + +// High cache hit rate (95%) +⚡ 5,000 cached (95%) ← Should appear in green +``` + +--- + +## Why These Changes Work + +### 1. **Backward Compatible** +- Existing OpenAI Responses API calls still work +- Schema accepts both formats +- No breaking changes to existing functionality + +### 2. **Future Proof** +- Works with any provider using Chat Completions format +- Supports future API changes +- Extensible for new token types + +### 3. **Zero Breaking Changes** +- All changes are additive +- Default values prevent undefined errors +- Graceful fallbacks throughout + +### 4. **Performance Optimized** +- Uses memos for reactive updates +- Only recalculates when messages change +- Efficient conditional rendering + +### 5. **User Experience** +- Visual feedback (color coding) +- Real-time updates +- Clear, actionable metrics + +--- + +## Key Insights + +### The Root Cause +**Problem:** Field name mismatch between API formats +- Cerebras: `prompt_tokens_details.cached_tokens` +- OpenCode expected: `input_tokens_details.cached_tokens` + +### The Solution +**Strategy:** Support both formats using nullish coalescing +```typescript +// Try Responses API format first, fall back to Chat Completions format +response.usage.input_tokens_details?.cached_tokens ?? +response.usage.prompt_tokens_details?.cached_tokens +``` + +### Why It's Minimal +Only 5 changes needed because: +1. OpenCode already had cache tracking infrastructure +2. Database schema already supported `cache.read` and `cache.write` +3. Only needed to fix the parsing layer and add display logic + +--- + +## Architecture Diagram + +``` +┌─────────────────────────────────────────────────────────────┐ +│ Cerebras API │ +│ { "prompt_tokens_details": { "cached_tokens": 2800 } } │ +└────────────────────┬────────────────────────────────────────┘ + │ + ▼ +┌─────────────────────────────────────────────────────────────┐ +│ openai-responses-language-model.ts │ +│ usageSchema: accepts both prompt_tokens & input_tokens │ +│ Parser: checks both field names → cachedInputTokens │ +└────────────────────┬────────────────────────────────────────┘ + │ + ▼ +┌─────────────────────────────────────────────────────────────┐ +│ Session.getUsage() │ +│ cachedInputTokens → tokens.cache.read │ +└────────────────────┬────────────────────────────────────────┘ + │ + ▼ +┌─────────────────────────────────────────────────────────────┐ +│ SQLite Database (.opencode/) │ +│ message.tokens = { cache: { read: 2800, write: 0 } } │ +└────────────────────┬────────────────────────────────────────┘ + │ + ▼ +┌─────────────────────────────────────────────────────────────┐ +│ sidebar.tsx │ +│ 1. Read last.tokens.cache.read │ +│ 2. Calculate hitRate = (cached / total) * 100 │ +│ 3. Format: "⚡ 2,800 cached (93%)" │ +│ 4. Color: green if >80%, yellow otherwise │ +└─────────────────────────────────────────────────────────────┘ +``` + +--- + +## Next Steps + +### Potential Enhancements + +1. **Cache Efficiency Over Time** + - Track cache hit rate across conversation + - Display trend (improving/declining) + +2. **Cache Write Stats** + - Show `cache.write` tokens + - Indicate when new content is being cached + +3. **Cost Savings Display** + - Calculate cost savings from cache + - Show: "Saved $0.15 from cache" + +4. **Cache Health Score** + - Aggregate metric across all messages + - Warning if cache not being utilized + +5. **Header Display** + - Add cache stats to header.tsx + - Compact inline format + +--- + +## Related Commits + +This implementation builds on commit **bde924a60**: +- Replaced pricing with request usage tracking +- Added foundation for metrics display +- Modified same files (sidebar.tsx, header.tsx) + +--- + +## Conclusion + +These 5 minimal changes enable complete cache visibility: +1. ✅ Schema accepts both API formats +2. ✅ Non-streaming parser extracts cache data +3. ✅ Streaming parser extracts cache data +4. ✅ Sidebar calculates cache statistics +5. ✅ Sidebar displays cache with visual feedback + +**Result:** Seamless cache tracking from API → Database → UI with zero breaking changes. diff --git a/README.md b/README.md index e70070b8f2..7941b38ec1 100644 --- a/README.md +++ b/README.md @@ -1,109 +1,386 @@ -

- - - - - OpenCode logo - - -

-

The AI coding agent built for the terminal.

-

- Discord - npm - Build status -

- -[![OpenCode Terminal UI](packages/web/src/assets/lander/screenshot.png)](https://opencode.ai) +# Cerebras Code CLI - Development Changelog + +## Project Overview + +This is a fork of OpenCode, customized and optimized specifically for Cerebras AI infrastructure. The project has been transformed from a multi-provider AI coding agent into a Cerebras-exclusive terminal-based development tool. + +## Collaborators + +This project is maintained by: +- Kevin +- Isaac +- Daniel +- Arihant --- -### Installation +## Commits Categorized by Strategic Pillars + +> **⚠️ IMPORTANT:** When making new commits, update this section with your changes under the appropriate pillar. -```bash -# YOLO -curl -fsSL https://opencode.ai/install | bash +### **Pillar 1: Idea Stack (Infrastructure & Architecture)** +*Focus: Architecture, infrastructure, CI/CD, provider systems* -# Package managers -npm i -g opencode-ai@latest # or bun/pnpm/yarn -scoop bucket add extras; scoop install extras/opencode # Windows -choco install opencode # Windows -brew install opencode # macOS and Linux -paru -S opencode-bin # Arch Linux -mise use --pin -g ubi:sst/opencode # Any OS -nix run nixpkgs#opencode # or github:sst/opencode for latest dev branch -``` +- **499180d29** - Add latest commit to README pillars (maintaining the rule) +- **9ffb274ca** - Update commit hash in README (final hash after amendment) +- **f985bf604** - Move pillars to top of README and add update enforcement rule (pre-push hook + guideline doc) +- **b72735c6f** - Cerebras-only provider architecture (removed 1,263 lines of multi-provider abstraction) +- **b7e33ea65** - Package rename for Cerebras branding +- **0c19e077e** - Package version update +- **d68f3099c** - Husky pre-push hook setup (13 insertions) +- **1ba691f3f** - Pre-push hook enhancement (6 insertions) +- **64f74e988** - TypeScript configuration updates (type shims and tsconfig) -> [!TIP] -> Remove versions older than 0.1.x before installing. +### **Pillar 2: TUI Features (User Interface & Experience)** +*Focus: UI/UX improvements, metrics display, user interactions* -#### Installation Directory +- **bde924a60** - Request usage information display (replaced pricing with metrics in header/sidebar) +- **b72735c6f** - UI simplification (removed provider dialogs, streamlined session/context UX) -The install script respects the following priority order for the installation path: +### **Pillar 3: SDK Level Features (Core Functionality & API)** +*Focus: Core functionality, authentication, retry logic, SDK capabilities* -1. `$OPENCODE_INSTALL_DIR` - Custom installation directory -2. `$XDG_BIN_DIR` - XDG Base Directory Specification compliant path -3. `$HOME/bin` - Standard user binary directory (if exists or can be created) -4. `$HOME/.opencode/bin` - Default fallback +- **42ce88a03** - Exponential backoff fix (improved retry logic) +- **d76d0fca4** - Backoff timeout configuration (60-second max) +- **b72735c6f** - PKCE authentication implementation (OAuth 2.0 with 139-line login module) +- **0e60f6660** - Complete Python SDK (229 files, 22,322 insertions, co-authored with Aiden Cline) -```bash -# Examples -OPENCODE_INSTALL_DIR=/usr/local/bin curl -fsSL https://opencode.ai/install | bash -XDG_BIN_DIR=$HOME/.local/bin curl -fsSL https://opencode.ai/install | bash -``` +### **Pillar 4: Experiment and Reporting (Metrics & Analytics)** +*Focus: Metrics, logging, experimentation tracking, analytics* -### Agents +- **bde924a60** - Metrics display implementation (request usage tracking, foundation for future analytics) -OpenCode includes two built-in agents you can switch between, -you can switch between these using the `Tab` key. +--- -- **build** - Default, full access agent for development work -- **plan** - Read-only agent for analysis and code exploration - - Denies file edits by default - - Asks permission before running bash commands - - Ideal for exploring unfamiliar codebases or planning changes +### Major Cache Optimizations -Also, included is a **general** subagent for complex searches and multi-step tasks. -This is used internally and can be invoked using `@general` in messages. + 1. Enable Prompt Caching for Anthropic (commit: 1a553e525, June 16, 2025) -Learn more about [agents](https://opencode.ai/docs/agents). + - Added cacheControl: { type: "ephemeral" } to system prompts for Anthropic models + - Initial implementation of prompt caching support -### Documentation + 2. Limit to 4 System Prompts Cached (commit: 63996c418, June 16, 2025) -For more info on how to configure OpenCode [**head over to our docs**](https://opencode.ai/docs). + - Restricted cache control to only the first 4 system messages + - Code change in packages/opencode/src/session/index.ts:478: + ...(input.providerID === "anthropic" && index < 4 + ? { anthropic: { cacheControl: { type: "ephemeral" } } } + : {}) -### Contributing + 3. Make System Prompt "Less Fast" for Better Caching (commit: 7d174767b, June 15, 2025) -If you're interested in contributing to OpenCode, please read our [contributing docs](./CONTRIBUTING.md) before submitting a pull request. + - Changed SystemPrompt.environment(sessionID) to SystemPrompt.environment() - removing session-specific context from environment prompts + - This means environment prompts are now static across sessions, dramatically improving cache hit rate + - Replaced dynamic file listing with static tree structure + - Added Ripgrep.files() for consistent file enumeration -### Collaborators + 4. Huge Optimization for Token Usage (commit: 1684042fb, June 20, 2025) -This project is maintained by: -- Kevin -- Isaac -- Daniel -- Arihant + - Strategic cache placement: Changed from caching first 4 messages to caching: + - First 2 system messages + - Last 2 messages in the conversation + const system = msgs.filter((msg) => msg.role === "system").slice(0, 2) + const final = msgs.filter((msg) => msg.role !== "system").slice(-2) + for (const msg of unique([...system, ...final])) { + msg.providerMetadata = { + anthropic: { cacheControl: { type: "ephemeral" } } + } + } + - This maximizes cache reuse for both static content and recently-used context + + 5. Cache Version Concept (commit: 4bb8536d3, July 11, 2025) + + - Introduced versioning system to auto-cleanup cache when breaking changes occur + - Prevents stale cache from causing issues + + 6. Retain Cache When Cycling Between Subagent/Parent Sessions (commit: b3885d161, August 16, 2025) + + - TUI optimization to preserve cache when switching between subagent and parent sessions + - Improves performance in multi-agent workflows + + 7. Summary Optimizations (commit: 75c29d4d1, November 22, 2025) + + - Pruned tool outputs in summaries: part.state.output = "[TOOL OUTPUT PRUNED]" + - Reduced summary prompt complexity + - Better options handling for cache-friendly requests + + Looking at Kevin's commits specifically (author: kevint-cerebras), none of them directly focused on cache hit rate optimizations. Kevin's work focused on: + - Exponential backoff fixes + - Cerebras-only provider architecture + - PKCE authentication + - UI enhancements (request usage display) + - Package infrastructure + +--- + +## Detailed Work Completed Before December 15, 2025 + +### **December 9, 2025** + +#### Exponential Backoff Fix (Commit: 42ce88a03) +**Files Modified:** +- `packages/opencode/src/session/processor.ts` +- `packages/opencode/src/session/retry.ts` + +**Changes:** +- Fixed exponential backoff algorithm to properly handle API request retries +- Improved retry logic to prevent overwhelming the Cerebras API during rate limiting or service interruptions +- Enhanced error recovery mechanisms in the session processor +- Modified retry timing calculations to follow industry-standard exponential backoff patterns +- Total changes: 26 insertions, 18 deletions across 2 files + +**Impact:** This change significantly improves the stability and reliability of the CLI when dealing with network issues or API rate limits, ensuring a smoother user experience during high-load scenarios. + +#### Backoff Timeout Configuration (Commit: d76d0fca4) +**Files Modified:** +- `packages/opencode/src/session/processor.ts` +- `packages/opencode/src/session/retry.ts` + +**Changes:** +- Set maximum backoff timeout to 60 seconds for retry operations +- Adjusted retry intervals to balance between rapid recovery and API rate limit compliance +- Fine-tuned timeout parameters to optimize for Cerebras API response patterns +- Total changes: 9 insertions, 7 deletions across 2 files + +**Impact:** Prevents indefinite waiting during API failures while maintaining respectful API usage patterns. + +--- + +### **December 8, 2025** + +#### UI Enhancement: Request Usage Information (Commit: bde924a60) +**Files Modified:** +- `packages/opencode/src/cli/cmd/tui/routes/session/header.tsx` +- `packages/opencode/src/cli/cmd/tui/routes/session/sidebar.tsx` + +**Changes:** +- Replaced pricing statistics display with request usage information in the TUI +- Updated header component to show real-time request metrics +- Modified sidebar to display usage tracking instead of cost calculations +- Improved user visibility into API consumption patterns +- Enhanced UX by providing actionable usage data rather than pricing information +- Total changes: 41 insertions, 20 deletions across 2 files + +**Impact:** Users can now better understand their API usage patterns, making it easier to optimize their workflow and manage resource consumption. -### Building on OpenCode +#### Major Architecture Change: Cerebras-Only Provider (Commit: b72735c6f) +**Files Modified:** +- `packages/opencode/src/cli/cmd/tui/app.tsx` +- `packages/opencode/src/cli/cmd/tui/component/dialog-model.tsx` +- `packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx` +- `packages/opencode/src/cli/cmd/tui/context/local.tsx` +- `packages/opencode/src/cli/cmd/tui/routes/session/index.tsx` +- `packages/opencode/src/provider/cerebras/login.ts` (NEW) +- `packages/opencode/src/provider/provider.ts` +- `packages/opencode/src/server/server.ts` -If you are working on a project that's related to OpenCode and is using "opencode" as a part of its name; for example, "opencode-dashboard" or "opencode-mobile", please add a note to your README to clarify that it is not built by the OpenCode team and is not affiliated with us in anyway. +**Changes:** +- **Complete Provider Refactoring:** Removed multi-provider abstraction layer, making Cerebras the exclusive AI provider +- **PKCE Authentication Implementation:** Added OAuth 2.0 PKCE (Proof Key for Code Exchange) flow for enhanced security + - Created new `login.ts` module with secure authentication handling + - Implemented code verifier and challenge generation + - Added token management and refresh mechanisms +- **UI Simplification:** Removed provider selection dialogs and model switching UI elements +- **Context Optimization:** Streamlined local context management for single-provider architecture +- **Session Handling:** Updated session management to work exclusively with Cerebras infrastructure +- **Autocomplete Enhancement:** Modified autocomplete to use Cerebras-specific model capabilities +- **Server Configuration:** Updated server initialization to use Cerebras endpoints +- **Code Cleanup:** Removed 1,263 lines of unused provider abstraction code +- Total changes: 361 insertions, 1,263 deletions across 8 files -### FAQ +**Impact:** This is the most significant architectural change, dramatically simplifying the codebase by removing unnecessary abstraction layers. The PKCE authentication provides enterprise-grade security for API access, and the streamlined architecture improves performance and maintainability. -#### How is this different than Claude Code? +#### Pre-Push Hook Enhancement (Commit: 1ba691f3f) +**Files Modified:** +- `.husky/pre-push` -It's very similar to Claude Code in terms of capability. Here are the key differences: +**Changes:** +- Enhanced git pre-push hook with additional validation checks +- Added safeguards to prevent pushing broken code to remote repository +- Total changes: 6 insertions -- 100% open source -- Not coupled to any provider. Although we recommend the models we provide through [OpenCode Zen](https://opencode.ai/zen); OpenCode can be used with Claude, OpenAI, Google or even local models. As models evolve the gaps between them will close and pricing will drop so being provider-agnostic is important. -- Out of the box LSP support -- A focus on TUI. OpenCode is built by neovim users and the creators of [terminal.shop](https://terminal.shop); we are going to push the limits of what's possible in the terminal. -- A client/server architecture. This for example can allow OpenCode to run on your computer, while you can drive it remotely from a mobile app. Meaning that the TUI frontend is just one of the possible clients. +**Impact:** Improves code quality by catching issues before they reach the remote repository. -#### What's the other repo? +#### Package Version Update (Commit: 0c19e077e) +**Files Modified:** +- `package.json` -The other confusingly named repo has no relation to this one. You can [read the story behind it here](https://x.com/thdxr/status/1933561254481666466). +**Changes:** +- Updated package version to reflect new Cerebras-specific release +- Total changes: 1 insertion, 1 deletion + +**Impact:** Proper version management for release tracking. + +#### Husky Pre-Push Hook Setup (Commit: d68f3099c) +**Files Modified:** +- `.husky/pre-push` (NEW) + +**Changes:** +- Created new pre-push git hook using Husky +- Implemented automated checks before code can be pushed +- Added build verification and test execution triggers +- Total changes: 13 insertions + +**Impact:** Automated quality control ensuring only tested code reaches the repository. + +#### TypeScript Configuration Updates (Commit: 64f74e988) +**Files Modified:** +- `packages/opencode/src/types/shims.d.ts` +- `packages/opencode/tsconfig.json` + +**Changes:** +- Added necessary TypeScript type shims for Cerebras-specific modules +- Updated TypeScript compiler configuration for improved type checking +- Enhanced type safety across the codebase +- Total changes: 5 insertions, 1 deletion across 2 files + +**Impact:** Improved developer experience with better IDE support and type safety. + +#### Package Rename (Commit: b7e33ea65) +**Files Modified:** +- `package.json` + +**Changes:** +- Renamed package to reflect Cerebras-specific branding +- Updated package metadata for proper npm registry identification +- Total changes: 1 insertion, 1 deletion + +**Impact:** Clear distinction from upstream OpenCode project. --- -**Join our community** [Discord](https://discord.gg/opencode) | [X.com](https://x.com/opencode) +### **October 28, 2025** + +#### Python SDK Implementation (Commit: 0e60f6660, PR #2779) +**Co-authored with:** Aiden Cline + +**Files Added:** 229 new files +**Total Changes:** 22,322 insertions, 8 deletions + +**Major Components Created:** + +1. **CI/CD Pipeline:** + - `.github/publish-python-sdk.yml` - Automated publishing workflow for PyPI + +2. **Python Package Structure:** + - Complete package setup with `pyproject.toml` for modern Python packaging + - UV lock file for deterministic dependency management + - Proper package metadata and versioning + +3. **Documentation System:** + - MkDocs-based documentation site (`mkdocs.yml`) + - Comprehensive guides: + - Installation guide + - Quickstart tutorial + - Configuration documentation + - Files and projects management + - Session handling + - Streaming API usage + - Code generation workflows + - Testing procedures + - Publishing guidelines + +4. **API Client Implementation:** + - Full REST API client with async support + - 40+ endpoint implementations including: + - Agent management (`app_agents.py`) + - Command listing (`command_list.py`) + - Configuration management (`config_get.py`, `config_providers.py`) + - Event subscription system (`event_subscribe.py`) + - File operations (`file_status.py`) + - Path utilities (`path_get.py`) + - Project management (`project_current.py`, `project_list.py`) + - Session handling (`session_list.py`) + - Tool integration (`tool_ids.py`) + - TUI controls (`tui_*.py` modules) + +5. **Data Models (150+ Pydantic Models):** + - Agent models and configurations + - Message types (assistant, user, tool, reasoning) + - Session management models + - File and project structures + - Permission and authentication models + - OAuth and API auth models + - Error handling models + - Event subscription models + - Configuration schemas + - Model provider definitions + - Symbol and code navigation models + +6. **Helper Utilities:** + - `extras.py` - Enhanced client functionality and utilities + - Custom error handling (`errors.py`) + - Type definitions (`types.py`) + - Client initialization and configuration (`client.py`) + +7. **Code Generation Tooling:** + - `scripts/generate.py` - OpenAPI-based code generation script + - `scripts/publish.py` - Automated publishing workflow + - `openapi-python-client.yaml` - Code generation configuration + +8. **Example Applications:** + - `examples/basic_usage.py` - Getting started guide + - `examples/file_status.py` - File monitoring example + - `examples/session_list.py` - Session management example + +9. **Testing Suite:** + - `tests/test_integration.py` - End-to-end integration tests + - `tests/test_wrapper.py` - Unit tests for wrapper functionality + +10. **Advanced Features:** + - Streaming API support with async iterators + - Event subscription system for real-time updates + - LSP (Language Server Protocol) client integration + - MCP (Model Context Protocol) support + - File watcher integration + - OAuth 2.0 authentication flows + - Permission management system + - Project and session state management + - Tool execution framework + - Symbol navigation and code intelligence + +**Impact:** This comprehensive Python SDK enables Python developers to integrate Cerebras-powered AI coding capabilities into their workflows, scripts, and applications. It provides both high-level convenience methods and low-level API access for maximum flexibility. + +--- + +## Summary Statistics + +### Total Commits by Kevin: 10 +### Time Period: October 28, 2025 - December 9, 2025 +### Files Changed: 237 files +### Total Additions: ~22,700 lines +### Total Deletions: ~1,300 lines + +### Key Achievements: + +1. **Security Enhancement:** Implemented PKCE OAuth authentication +2. **Architecture Simplification:** Removed multi-provider complexity +3. **Python Ecosystem Support:** Complete Python SDK with 229 files +4. **Reliability Improvements:** Fixed retry logic and exponential backoff +5. **Developer Experience:** Enhanced TypeScript configuration and git hooks +6. **UI/UX Improvements:** Better usage tracking and information display +7. **Code Quality:** Automated pre-push validation +8. **Documentation:** Comprehensive Python SDK documentation + +--- + +## Technical Impact + +This work has transformed the project from a generic multi-provider AI coding agent into a streamlined, secure, and highly optimized Cerebras-specific development tool. The changes improve: + +- **Performance:** Reduced code complexity and optimized API communication +- **Security:** Enterprise-grade OAuth 2.0 PKCE authentication +- **Reliability:** Improved error handling and retry mechanisms +- **Accessibility:** Python SDK opens the platform to a broader developer audience +- **Maintainability:** Simplified codebase with single provider focus +- **Developer Experience:** Better tooling, testing, and automation + +--- + +## Repository Information + +- **Original Project:** [OpenCode](https://github.com/sst/opencode) +- **Fork Purpose:** Cerebras AI optimization +- **License:** Inherited from OpenCode +- **Platform:** Terminal-based AI coding agent +- **Primary Language:** TypeScript/JavaScript, Python (SDK) diff --git a/packages/opencode/package.json b/packages/opencode/package.json index 973bea00fc..9cd11a5922 100644 --- a/packages/opencode/package.json +++ b/packages/opencode/package.json @@ -1,9 +1,8 @@ { "$schema": "https://json.schemastore.org/package.json", - "version": "1.0.137", - "name": "opencode", + "version": "1.0.140", + "name": "cerebras-code", "type": "module", - "private": true, "scripts": { "typecheck": "tsgo --noEmit", "test": "bun test", @@ -12,7 +11,7 @@ "random": "echo 'Random script updated at $(date)'" }, "bin": { - "opencode": "./bin/opencode" + "cerebras": "./bin/opencode" }, "exports": { "./*": "./src/*.ts" @@ -28,13 +27,13 @@ "@parcel/watcher-linux-x64-musl": "2.5.1", "@parcel/watcher-win32-x64": "2.5.1", "@standard-schema/spec": "1.0.0", - "@tsconfig/bun": "catalog:", + "@tsconfig/bun": "^1.0.9", "@types/babel__core": "7.20.5", - "@types/bun": "catalog:", + "@types/bun": "^1.3.3", "@types/turndown": "5.0.5", "@types/yargs": "17.0.33", - "typescript": "catalog:", - "@typescript/native-preview": "catalog:", + "typescript": "^5.8.2", + "@typescript/native-preview": "^7.0.0-dev.20251207.1", "vscode-languageserver-types": "3.17.5", "why-is-node-running": "3.2.2", "zod-to-json-schema": "3.24.5", @@ -56,50 +55,50 @@ "@ai-sdk/provider-utils": "3.0.18", "@clack/prompts": "1.0.0-alpha.1", "@hono/standard-validator": "0.1.5", - "@hono/zod-validator": "catalog:", + "@hono/zod-validator": "^0.4.2", "@modelcontextprotocol/sdk": "1.15.1", "@octokit/graphql": "9.0.2", "@octokit/rest": "22.0.0", - "@openauthjs/openauth": "catalog:", - "@opencode-ai/plugin": "workspace:*", + "@openauthjs/openauth": "^0.0.0-20250322224806", + "cerebras-plugin": "^1.0.140", "@opencode-ai/script": "workspace:*", - "@opencode-ai/sdk": "workspace:*", + "cerebras-sdk": "^1.0.140", "@opencode-ai/util": "workspace:*", "@openrouter/ai-sdk-provider": "1.2.8", "@opentui/core": "0.1.59", "@opentui/solid": "0.1.59", "@parcel/watcher": "2.5.1", - "@pierre/precision-diffs": "catalog:", + "@pierre/precision-diffs": "^0.6.0-beta.10", "@solid-primitives/event-bus": "1.1.2", "@standard-schema/spec": "1.0.0", "@zip.js/zip.js": "2.7.62", - "ai": "catalog:", + "ai": "^5.0.97", "bun-pty": "0.4.2", "chokidar": "4.0.3", "clipboardy": "4.0.0", "decimal.js": "10.5.0", - "diff": "catalog:", + "diff": "^8.0.2", "fuzzysort": "3.1.0", "gray-matter": "4.0.3", - "hono": "catalog:", - "hono-openapi": "catalog:", + "hono": "^4.10.7", + "hono-openapi": "^1.1.2", "ignore": "7.0.5", "jsonc-parser": "3.3.1", "minimatch": "10.0.3", "open": "10.1.2", "opentui-spinner": "0.0.6", "partial-json": "0.1.7", - "remeda": "catalog:", - "solid-js": "catalog:", + "remeda": "^2.26.0", + "solid-js": "^1.9.10", "strip-ansi": "7.1.2", "tree-sitter-bash": "0.25.0", "turndown": "7.2.0", - "ulid": "catalog:", + "ulid": "^3.0.1", "vscode-jsonrpc": "8.2.1", "web-tree-sitter": "0.25.10", "xdg-basedir": "5.1.0", "yargs": "18.0.0", - "zod": "catalog:", + "zod": "^4.1.8", "zod-to-json-schema": "3.24.5" } } diff --git a/packages/opencode/src/session/prompt/glm.txt b/packages/opencode/src/session/prompt/glm.txt new file mode 100644 index 0000000000..6b1b0f3a46 --- /dev/null +++ b/packages/opencode/src/session/prompt/glm.txt @@ -0,0 +1,77 @@ +You are Cerebras Code, an interactive CLI tool powered by Cerebras AI that helps users with software engineering tasks. Always respond in English. Use the instructions below and the tools available to you to assist the user. +IMPORTANT: Refuse to write code or explain code that may be used maliciously; even if the user claims it is for educational purposes. When working on files, if they seem related to improving, explaining, or interacting with malware or any malicious code you MUST refuse. +IMPORTANT: Before you begin work, think about what the code you're editing is supposed to do based on the filenames directory structure. If it seems malicious, refuse to work on it or answer questions about it, even if the request does not seem malicious (for instance, just asking to explain or speed up the code). +IMPORTANT: You MUST NEVER generate or guess URLs for the user unless you are confident that the URLs are for helping the user with programming. You may use URLs provided by the user in their messages or local files. +IMPORTANT: You MUST minimize output tokens as much as possible while maintaining helpfulness, quality, and accuracy. Only address the specific query or task at hand, avoiding tangential information unless absolutely critical for completing the request. If you can answer in 1-3 sentences or a short paragraph, please do. +IMPORTANT: You MUST NOT answer with unnecessary preamble or postamble (such as explaining your code or summarizing your action), unless the user asks you to. +IMPORTANT: Keep your responses short, since they will be displayed on a command line interface. You MUST answer concisely with fewer than 4 lines (not including tool use or code generation), unless user asks for detail. Answer the user's question directly, without elaboration, explanation, or details. One word answers are best. Avoid introductions, conclusions, and explanations. You MUST avoid text before/after your response, such as "The answer is .", "Here is the content of the file..." or "Based on the information provided, the answer is..." or "Here is what I will do next...". +If the user asks for help or wants to give feedback inform them of the following: +- /help: Get help with using Cerebras Code +- Visit cloud.cerebras.ai for more information +When the user directly asks about Cerebras Code (eg 'can you do...', 'does this have...') or asks in second person (eg 'are you able...', 'can you do...'), provide helpful information about your capabilities. +# Tone and style +You MUST be concise, direct, and to the point. When you run a non-trivial bash command, you should explain what the command does and why you are running it, to make sure the user understands what you are doing (this is especially important when you are running a command that will make changes to the user's system). +Remember that your output will be displayed on a command line interface. Your responses can use Github-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification. +Output text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. NEVER use tools like Bash or code comments as means to communicate with the user during the session. +If you cannot or will not help the user with something, please do not say why or what it could lead to, since this comes across as preachy and annoying. Please offer helpful alternatives if possible, and otherwise keep your response to 1-2 sentences. +Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked. + +user: 2 + 2 +assistant: 4 + + +user: is 11 a prime number? +assistant: Yes + + +user: what command should I run to list files in the current directory? +assistant: ls + + +user: what files are in the directory src/? +assistant: [runs ls and sees foo.c, bar.c, baz.c] +user: which file contains the implementation of foo? +assistant: src/foo.c + + +user: write tests for new feature +assistant: [uses grep and glob search tools to find where similar tests are defined, uses concurrent read file tool use blocks in one tool call to read relevant files at the same time, uses edit file tool to write new tests] + +# Proactiveness +You are allowed to be proactive, but only when the user asks you to do something. You MUST strive to strike a balance between: +1. Doing the right thing when asked, including taking actions and follow-up actions +2. Not surprising the user with actions you take without asking +For example, if the user asks you how to approach something, you should do your best to answer their question first, and not immediately jump into taking actions. +3. Do not add additional code explanation summary unless requested by the user. After working on a file, just stop, rather than providing an explanation of what you did. +# Following conventions +When making changes to files, first understand the file's code conventions. Mimic code style, use existing libraries and utilities, and follow existing patterns. +- NEVER assume that a given library is available, even if it is well known. Whenever you write code that uses a library or framework, first check that this codebase already uses the given library. For example, you might look at neighboring files, or check the package.json (or cargo.toml, and so on depending on the language). +- When you create a new component, first look at existing components to see how they're written; then consider framework choice, naming conventions, typing, and other conventions. +- When you edit a piece of code, first look at the code's surrounding context (especially its imports) to understand the code's choice of frameworks and libraries. Then consider how to make the given change in a way that is most idiomatic. +- Always follow security best practices. NEVER introduce code that exposes or logs secrets and keys. NEVER commit secrets or keys to the repository. +# Code style +- IMPORTANT: DO NOT ADD ***ANY*** COMMENTS unless asked +# Doing tasks +The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended: +- Use the available search tools to understand the codebase and the user's query. You are encouraged to use the search tools extensively both in parallel and sequentially. +- Implement the solution using all tools available to you +- Verify the solution if possible with tests. NEVER assume specific test framework or test script. Check the README or search codebase to determine the testing approach. +- VERY IMPORTANT: When you have completed a task, you MUST run the lint and typecheck commands (eg. npm run lint, npm run typecheck, ruff, etc.) with Bash if they were provided to you to ensure your code is correct. If you are unable to find the correct command, ask the user for the command to run and if they supply it, proactively suggest writing it to AGENTS.md so that you will know to run it next time. +NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive. +IMPORTANT: When creating git commits, you MUST always include the following in the commit message: + +🤖 Generated with Cerebras Code cloud.cerebras.ai + +Co-Authored-By: Isaac Tai + +- Tool results and user messages may include tags. tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result. +# Tool usage policy +- When doing file search, prefer to use the Task tool in order to reduce context usage. +- You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run "git status" and "git diff", send a single message with two tool calls to run the calls in parallel. +You MUST answer concisely with fewer than 4 lines of text (not including tool use or code generation), unless user asks for detail. +# Code References +When referencing specific functions or pieces of code include the pattern `file_path:line_number` to allow the user to easily navigate to the source code location. + +user: Where are errors from the client handled? +assistant: Clients are marked as failed in the `connectToServer` function in src/services/process.ts:712. + diff --git a/packages/opencode/src/session/system.ts b/packages/opencode/src/session/system.ts index 3146110cf3..1954f9af9c 100644 --- a/packages/opencode/src/session/system.ts +++ b/packages/opencode/src/session/system.ts @@ -17,6 +17,7 @@ import PROMPT_COMPACTION from "./prompt/compaction.txt" import PROMPT_SUMMARIZE from "./prompt/summarize.txt" import PROMPT_TITLE from "./prompt/title.txt" import PROMPT_CODEX from "./prompt/codex.txt" +import PROMPT_GLM from "./prompt/glm.txt" import type { Provider } from "@/provider/provider" export namespace SystemPrompt { @@ -26,6 +27,7 @@ export namespace SystemPrompt { } export function provider(model: Provider.Model) { + if (model.api.id.includes("glm")) return [PROMPT_GLM] if (model.api.id.includes("gpt-5")) return [PROMPT_CODEX] if (model.api.id.includes("gpt-") || model.api.id.includes("o1") || model.api.id.includes("o3")) return [PROMPT_BEAST] diff --git a/packages/plugin/package.json b/packages/plugin/package.json index e27b438995..f36d76fd01 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package.json", - "name": "@opencode-ai/plugin", - "version": "1.0.137", + "name": "cerebras-plugin", + "version": "1.0.140", "type": "module", "scripts": { "typecheck": "tsgo --noEmit", @@ -15,13 +15,13 @@ "dist" ], "dependencies": { - "@opencode-ai/sdk": "workspace:*", - "zod": "catalog:" + "cerebras-sdk": "^1.0.140", + "zod": "^4.1.8" }, "devDependencies": { - "@tsconfig/node22": "catalog:", - "@types/node": "catalog:", - "typescript": "catalog:", - "@typescript/native-preview": "catalog:" + "@tsconfig/node22": "^22.0.2", + "@types/node": "^22.13.9", + "typescript": "^5.8.2", + "@typescript/native-preview": "^7.0.0-dev.20251207.1" } } \ No newline at end of file diff --git a/packages/sdk/js/package.json b/packages/sdk/js/package.json index 582d0965be..a794955452 100644 --- a/packages/sdk/js/package.json +++ b/packages/sdk/js/package.json @@ -1,7 +1,7 @@ { "$schema": "https://json.schemastore.org/package.json", - "name": "@opencode-ai/sdk", - "version": "1.0.137", + "name": "cerebras-sdk", + "version": "1.0.140", "type": "module", "scripts": { "typecheck": "tsgo --noEmit", @@ -20,10 +20,10 @@ ], "devDependencies": { "@hey-api/openapi-ts": "0.88.1", - "@tsconfig/node22": "catalog:", - "@types/node": "catalog:", - "typescript": "catalog:", - "@typescript/native-preview": "catalog:" + "@tsconfig/node22": "^22.0.2", + "@types/node": "^22.13.9", + "typescript": "^5.8.2", + "@typescript/native-preview": "^7.0.0-dev.20251207.1" }, "dependencies": {}, "publishConfig": {