2026-01-13 14:57:43 +00:00
- To regenerate the JavaScript SDK, run `./packages/sdk/js/script/build.ts` .
2025-12-22 22:21:49 +00:00
- ALWAYS USE PARALLEL TOOLS WHEN APPLICABLE.
2026-01-13 14:57:43 +00:00
- The default branch in this repo is `dev` .
2026-02-06 05:36:08 +00:00
- Local `main` ref may not exist; use `dev` or `origin/dev` for diffs.
2026-01-30 04:10:50 +00:00
- Prefer automation: execute requested actions without confirmation unless blocked by missing info or safety/irreversibility.
2026-01-25 05:07:01 +00:00
## Style Guide
2026-02-02 03:28:00 +00:00
### General Principles
2026-01-25 05:07:01 +00:00
- Keep things in one function unless composable or reusable
2026-05-10 06:48:19 +00:00
- Do not extract single-use helpers preemptively. Inline the logic at the call site unless the helper is reused, hides a genuinely complex boundary, or has a clear independent name that improves the caller.
2026-01-25 05:07:01 +00:00
- Avoid `try` /`catch` where possible
- Avoid using the `any` type
- Use Bun APIs when possible, like `Bun.file()`
2026-01-26 05:04:00 +00:00
- Rely on type inference when possible; avoid explicit type annotations or interfaces unless necessary for exports or clarity
2026-02-02 01:52:17 +00:00
- Prefer functional array methods (flatMap, filter, map) over for loops; use type guards on filter to maintain type inference downstream
2026-04-17 01:35:26 +00:00
- In `src/config` , follow the existing self-export pattern at the top of the file (for example `export * as ConfigAgent from "./agent"` ) when adding a new config module.
2026-01-25 05:07:01 +00:00
2026-02-02 03:28:00 +00:00
Reduce total variable count by inlining when a value is only used once.
2026-01-25 05:07:01 +00:00
```ts
2026-02-02 03:28:00 +00:00
// Good
const journal = await Bun.file(path.join(dir, "journal.json")).json()
// Bad
const journalPath = path.join(dir, "journal.json")
const journal = await Bun.file(journalPath).json()
2026-01-25 05:07:01 +00:00
```
2026-02-02 03:28:00 +00:00
### Destructuring
Avoid unnecessary destructuring. Use dot notation to preserve context.
2026-01-25 05:07:01 +00:00
```ts
2026-02-02 03:28:00 +00:00
// Good
obj.a
obj.b
// Bad
const { a, b } = obj
```
### Variables
Prefer `const` over `let` . Use ternaries or early returns instead of reassignment.
2026-01-25 05:07:01 +00:00
2026-02-02 03:28:00 +00:00
```ts
// Good
const foo = condition ? 1 : 2
// Bad
let foo
2026-01-25 05:07:01 +00:00
if (condition) foo = 1
else foo = 2
```
2026-02-02 03:28:00 +00:00
### Control Flow
2026-01-25 05:07:01 +00:00
2026-02-02 03:28:00 +00:00
Avoid `else` statements. Prefer early returns.
2026-01-25 05:07:01 +00:00
```ts
2026-02-02 03:28:00 +00:00
// Good
2026-01-25 05:07:01 +00:00
function foo() {
if (condition) return 1
return 2
}
2026-02-02 03:28:00 +00:00
// Bad
2026-01-25 05:07:01 +00:00
function foo() {
if (condition) return 1
else return 2
}
```
2026-02-02 03:28:00 +00:00
### Schema Definitions (Drizzle)
2026-01-25 05:07:01 +00:00
2026-02-02 03:28:00 +00:00
Use snake_case for field names so column names don't need to be redefined as strings.
2026-01-25 05:07:01 +00:00
```ts
2026-02-02 03:28:00 +00:00
// Good
const table = sqliteTable("session", {
id: text().primaryKey(),
project_id: text().notNull(),
created_at: integer().notNull(),
})
// Bad
const table = sqliteTable("session", {
id: text("id").primaryKey(),
projectID: text("project_id").notNull(),
createdAt: integer("created_at").notNull(),
})
2026-01-25 05:07:01 +00:00
```
2026-01-25 22:54:17 +00:00
## Testing
2026-02-02 03:28:00 +00:00
- Avoid mocks as much as possible
- Test actual implementation, do not duplicate logic into tests
2026-02-14 04:19:02 +00:00
- Tests cannot run from repo root (guard: `do-not-run-tests-from-root` ); run from package dirs like `packages/opencode` .
2026-03-10 16:53:47 +00:00
## Type Checking
- Always run `bun typecheck` from package directories (e.g., `packages/opencode` ), never `tsc` directly.