2025-06-15 10:05:41 +08:00
# opencode agent guidelines
2025-06-04 00:38:48 +08:00
## Build/Test Commands
2025-06-05 01:12:13 +08:00
2025-06-04 00:38:48 +08:00
- **Install**: `bun install`
- **Run**: `bun run index.ts`
- **Typecheck**: `bun run typecheck` (npm run typecheck)
- **Test**: `bun test` (runs all tests)
- **Single test**: `bun test test/tool/tool.test.ts` (specific test file)
## Code Style
2025-06-05 01:12:13 +08:00
2025-06-04 00:38:48 +08:00
- **Runtime**: Bun with TypeScript ESM modules
- **Imports**: Use relative imports for local modules, named imports preferred
- **Types**: Zod schemas for validation, TypeScript interfaces for structure
- **Naming**: camelCase for variables/functions, PascalCase for classes/namespaces
- **Error handling**: Use Result patterns, avoid throwing exceptions in tools
- **File structure**: Namespace-based organization (e.g., `Tool.define()` , `Session.create()` )
2025-06-15 09:23:57 +08:00
2025-06-04 00:38:48 +08:00
## Architecture
2025-06-05 01:12:13 +08:00
2025-06-04 00:38:48 +08:00
- **Tools**: Implement `Tool.Info` interface with `execute()` method
- **Context**: Pass `sessionID` in tool context, use `App.provide()` for DI
- **Validation**: All inputs validated with Zod schemas
- **Logging**: Use `Log.create({ service: "name" })` pattern
2025-06-05 01:12:13 +08:00
- **Storage**: Use `Storage` namespace for persistence
2025-06-27 20:46:42 +08:00
- **API Client**: Go TUI communicates with TypeScript server via stainless SDK. When adding/modifying server endpoints in `packages/opencode/src/server/server.ts` , ask the user to generate a new client SDK to proceed with client-side changes.