Skip to content

Commit e3a5f6b

Browse files
authored
docs: add CONTRIBUTING.md (#85)
1 parent a3a4a33 commit e3a5f6b

File tree

1 file changed

+245
-0
lines changed

1 file changed

+245
-0
lines changed

CONTRIBUTING.md

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
# Contributing to Oh My OpenCode
2+
3+
First off, thanks for taking the time to contribute! This document provides guidelines and instructions for contributing to oh-my-opencode.
4+
5+
## Table of Contents
6+
7+
- [Code of Conduct](#code-of-conduct)
8+
- [Getting Started](#getting-started)
9+
- [Prerequisites](#prerequisites)
10+
- [Development Setup](#development-setup)
11+
- [Testing Your Changes Locally](#testing-your-changes-locally)
12+
- [Project Structure](#project-structure)
13+
- [Development Workflow](#development-workflow)
14+
- [Build Commands](#build-commands)
15+
- [Code Style & Conventions](#code-style--conventions)
16+
- [Making Changes](#making-changes)
17+
- [Adding a New Agent](#adding-a-new-agent)
18+
- [Adding a New Hook](#adding-a-new-hook)
19+
- [Adding a New Tool](#adding-a-new-tool)
20+
- [Adding a New MCP Server](#adding-a-new-mcp-server)
21+
- [Pull Request Process](#pull-request-process)
22+
- [Publishing](#publishing)
23+
- [Getting Help](#getting-help)
24+
25+
## Code of Conduct
26+
27+
Be respectful, inclusive, and constructive. We're all here to make better tools together.
28+
29+
## Getting Started
30+
31+
### Prerequisites
32+
33+
- **Bun** (latest version) - The only supported package manager
34+
- **TypeScript 5.7.3+** - For type checking and declarations
35+
- **OpenCode 1.0.150+** - For testing the plugin
36+
37+
### Development Setup
38+
39+
```bash
40+
# Clone the repository
41+
git clone https://github.com/code-yeongyu/oh-my-opencode.git
42+
cd oh-my-opencode
43+
44+
# Install dependencies (bun only - never use npm/yarn)
45+
bun install
46+
47+
# Build the project
48+
bun run build
49+
```
50+
51+
### Testing Your Changes Locally
52+
53+
After making changes, you can test your local build in OpenCode:
54+
55+
1. **Build the project**:
56+
```bash
57+
bun run build
58+
```
59+
60+
2. **Update your OpenCode config** (`~/.config/opencode/opencode.json` or `opencode.jsonc`):
61+
```json
62+
{
63+
"plugin": [
64+
"file:///absolute/path/to/oh-my-opencode/dist/index.js"
65+
]
66+
}
67+
```
68+
69+
For example, if your project is at `/Users/yourname/projects/oh-my-opencode`:
70+
```json
71+
{
72+
"plugin": [
73+
"file:///Users/yourname/projects/oh-my-opencode/dist/index.js"
74+
]
75+
}
76+
```
77+
78+
> **Note**: Remove `"oh-my-opencode"` from the plugin array if it exists, to avoid conflicts with the npm version.
79+
80+
3. **Restart OpenCode** to load the changes.
81+
82+
4. **Verify** the plugin is loaded by checking for OmO agent availability or startup messages.
83+
84+
## Project Structure
85+
86+
```
87+
oh-my-opencode/
88+
├── src/
89+
│ ├── agents/ # AI agents (OmO, oracle, librarian, explore, etc.)
90+
│ ├── hooks/ # 21 lifecycle hooks
91+
│ ├── tools/ # LSP (11), AST-Grep, Grep, Glob, etc.
92+
│ ├── mcp/ # MCP server integrations (context7, websearch_exa, grep_app)
93+
│ ├── features/ # Claude Code compatibility layers
94+
│ ├── config/ # Zod schemas and TypeScript types
95+
│ ├── auth/ # Google Antigravity OAuth
96+
│ ├── shared/ # Common utilities
97+
│ └── index.ts # Main plugin entry (OhMyOpenCodePlugin)
98+
├── script/ # Build utilities (build-schema.ts, publish.ts)
99+
├── assets/ # JSON schema
100+
└── dist/ # Build output (ESM + .d.ts)
101+
```
102+
103+
## Development Workflow
104+
105+
### Build Commands
106+
107+
```bash
108+
# Type check only
109+
bun run typecheck
110+
111+
# Full build (ESM + TypeScript declarations + JSON schema)
112+
bun run build
113+
114+
# Clean build output and rebuild
115+
bun run rebuild
116+
117+
# Build schema only (after modifying src/config/schema.ts)
118+
bun run build:schema
119+
```
120+
121+
### Code Style & Conventions
122+
123+
| Convention | Rule |
124+
|------------|------|
125+
| Package Manager | **Bun only** (`bun run`, `bun build`, `bunx`) |
126+
| Types | Use `bun-types`, not `@types/node` |
127+
| Directory Naming | kebab-case (`ast-grep/`, `claude-code-hooks/`) |
128+
| File Operations | Never use bash commands (mkdir/touch/rm) for file creation in code |
129+
| Tool Structure | Each tool: `index.ts`, `types.ts`, `constants.ts`, `tools.ts`, `utils.ts` |
130+
| Hook Pattern | `createXXXHook(input: PluginInput)` function naming |
131+
| Exports | Barrel pattern (`export * from "./module"` in index.ts) |
132+
133+
**Anti-Patterns (Do Not Do)**:
134+
- Using npm/yarn instead of bun
135+
- Using `@types/node` instead of `bun-types`
136+
- Suppressing TypeScript errors with `as any`, `@ts-ignore`, `@ts-expect-error`
137+
- Generic AI-generated comment bloat
138+
- Direct `bun publish` (use GitHub Actions only)
139+
- Local version modifications in `package.json`
140+
141+
## Making Changes
142+
143+
### Adding a New Agent
144+
145+
1. Create a new `.ts` file in `src/agents/`
146+
2. Define the agent configuration following existing patterns
147+
3. Add to `builtinAgents` in `src/agents/index.ts`
148+
4. Update `src/agents/types.ts` if needed
149+
5. Run `bun run build:schema` to update the JSON schema
150+
151+
```typescript
152+
// src/agents/my-agent.ts
153+
import type { AgentConfig } from "./types";
154+
155+
export const myAgent: AgentConfig = {
156+
name: "my-agent",
157+
model: "anthropic/claude-sonnet-4-5",
158+
description: "Description of what this agent does",
159+
prompt: `Your agent's system prompt here`,
160+
temperature: 0.1,
161+
// ... other config
162+
};
163+
```
164+
165+
### Adding a New Hook
166+
167+
1. Create a new directory in `src/hooks/` (kebab-case)
168+
2. Implement `createXXXHook()` function returning event handlers
169+
3. Export from `src/hooks/index.ts`
170+
171+
```typescript
172+
// src/hooks/my-hook/index.ts
173+
import type { PluginInput } from "@opencode-ai/plugin";
174+
175+
export function createMyHook(input: PluginInput) {
176+
return {
177+
onSessionStart: async () => {
178+
// Hook logic here
179+
},
180+
};
181+
}
182+
```
183+
184+
### Adding a New Tool
185+
186+
1. Create a new directory in `src/tools/` with required files:
187+
- `index.ts` - Main exports
188+
- `types.ts` - TypeScript interfaces
189+
- `constants.ts` - Constants and tool descriptions
190+
- `tools.ts` - Tool implementations
191+
- `utils.ts` - Helper functions
192+
2. Add to `builtinTools` in `src/tools/index.ts`
193+
194+
### Adding a New MCP Server
195+
196+
1. Create configuration in `src/mcp/`
197+
2. Add to `src/mcp/index.ts`
198+
3. Document in README if it requires external setup
199+
200+
## Pull Request Process
201+
202+
1. **Fork** the repository and create your branch from `master`
203+
2. **Make changes** following the conventions above
204+
3. **Build and test** locally:
205+
```bash
206+
bun run typecheck # Ensure no type errors
207+
bun run build # Ensure build succeeds
208+
```
209+
4. **Test in OpenCode** using the local build method described above
210+
5. **Commit** with clear, descriptive messages:
211+
- Use present tense ("Add feature" not "Added feature")
212+
- Reference issues if applicable ("Fix #123")
213+
6. **Push** to your fork and create a Pull Request
214+
7. **Describe** your changes clearly in the PR description
215+
216+
### PR Checklist
217+
218+
- [ ] Code follows project conventions
219+
- [ ] `bun run typecheck` passes
220+
- [ ] `bun run build` succeeds
221+
- [ ] Tested locally with OpenCode
222+
- [ ] Updated documentation if needed (README, AGENTS.md)
223+
- [ ] No version changes in `package.json`
224+
225+
## Publishing
226+
227+
**Important**: Publishing is handled exclusively through GitHub Actions.
228+
229+
- **Never** run `bun publish` directly (OIDC provenance issues)
230+
- **Never** modify `package.json` version locally
231+
- Maintainers use GitHub Actions workflow_dispatch:
232+
```bash
233+
gh workflow run publish -f bump=patch # or minor/major
234+
```
235+
236+
## Getting Help
237+
238+
- **Project Knowledge**: Check `AGENTS.md` for detailed project documentation
239+
- **Code Patterns**: Review existing implementations in `src/`
240+
- **Issues**: Open an issue for bugs or feature requests
241+
- **Discussions**: Start a discussion for questions or ideas
242+
243+
---
244+
245+
Thank you for contributing to Oh My OpenCode! Your efforts help make AI-assisted coding better for everyone.

0 commit comments

Comments
 (0)