This document defines the core standards and operational protocols for agents working on the Opencode codebase.
Opencode is a Bun-powered monorepo for AI-driven development. It utilizes a high-performance stack including TypeScript 5.8+, SolidJS, and SST. The architecture emphasizes erasable syntax, minimal runtime overhead, and strict type safety.- Development: MUST run
bun devto start the core Opencode application. - Testing:
- Root tests are disabled. MUST run tests from within specific package directories (e.g.,
cd packages/opencode && bun test). - To test Opencode specifically, use
bun devinpackages/opencode.
- Root tests are disabled. MUST run tests from within specific package directories (e.g.,
- Typechecking: SHOULD use
bun run typecheck(Turbo-powered) for workspace-wide validation. - SDK: MUST regenerate the JavaScript SDK using
./packages/sdk/js/script/build.tsafter API changes. - Git: The default branch is
dev. - Fork Syncing:
- Agents MUST stash the
.opencodefolder before syncing with upstream. - Agents MUST NOT sync the
.opencodefolder from upstream. - Ensure NO EXTRA FILES (untracked or new upstream files) are accidentally added during sync.
- Agents MUST stash the
- File Headers: Every file MUST start with a 2-3 sentence comment explaining its purpose.
- File Size: Files SHOULD NOT exceed 200 lines. Files over 300 lines MUST be split.
- Function Size: Functions SHOULD NOT exceed 40 lines.
- Barrels: Every module directory MUST have an
index.tsfile. Consumers MUST import from the barrel, not deep paths. - Domain Separation: Organize code by business domain, not technical layers.
- Minimalism: Avoid
try/catchandelsestatements where possible. Prefer "Fail Fast" patterns. - Variables: PREFER single-word variable names. AVOID
letstatements and unnecessary destructuring. - Logging: MUST NOT use
console.log,console.error, or other logging. Trust the type system. - DRY: Pattern recognition is mandatory. Abstract similar code immediately into shared utilities.
- Strictness: MUST NOT use
any. Useunknownand narrow via control flow. - Types vs Interfaces: Prefer
typefor data shapes; useinterfaceonly for extensible public APIs. - Erasable Syntax: MUST NOT use
enum,namespace, or constructor parameter properties. - Imports: MUST use
import typefor type-only imports and MUST include.jsextensions in Node.js compatible imports.
- Parallelism: Agents MUST use parallel tool calls whenever multiple independent operations are possible.
- Verification: Agents MUST verify code changes by running relevant tests or build commands before reporting completion.
- XML Tags: Documentation and instructions SHOULD use XML tags (e.g.,
<instructions>,<workflow>) for clarity as perRFC-XML-STYLE-GUIDE.md.