Skip to content

Development

eddy.wijaya edited this page Apr 3, 2026 · 3 revisions

πŸ› οΈ Development

Set up, build, test, and contribute to opencode-codex-quota.


πŸ“‹ Prerequisites

Requirement Version
Node.js >= 20
TypeScript >= 6.0
npm Latest

πŸš€ Setup

# Clone the repository
git clone https://github.com/guyinwonder168/opencode-codex-quota.git
cd opencode-codex-quota

# Install dependencies
npm install

πŸ“¦ Commands

Command Description
npm run build TypeScript β†’ dist/
npm run typecheck Type checking only (no emit)
npm test Run all tests
npm run test:coverage Run tests with coverage report
npm run lint Check code style (Biome)
npm run lint:fix Fix code style issues

πŸ§ͺ Testing

Tests use vitest with the Arrange-Act-Assert pattern. Mocks for fetch and fs are set up per test.

# Run all tests
npm test

# Run specific test file
npm test -- tests/auth-reader.test.ts

# Run with coverage
npm run test:coverage

Test Files

File Coverage
tests/auth-reader.test.ts Auth reading, JWT parsing, E1/E2/E3/E9/E10/E11 errors
tests/api-client.test.ts API calls, timeout, validation, E4–E8 errors
tests/markdown.test.ts Progress bars, clock formatting, compact/full output
tests/errors.test.ts All E1–E11 error message formatting
tests/index.test.ts Plugin module shape, hooks, command registration
tests/integration.test.ts Full pipeline from auth β†’ API β†’ Markdown

πŸ—οΈ Project Structure

opencode-codex-quota/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts              # Plugin entry point, tool definition
β”‚   β”œβ”€β”€ types.ts              # All TypeScript interfaces
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ auth-reader.ts    # Read auth.json β†’ parse JWT β†’ credentials
β”‚   β”‚   └── api-client.ts     # Call wham/usage β†’ typed QuotaResponse
β”‚   └── formatter/
β”‚       β”œβ”€β”€ markdown.ts       # QuotaResponse β†’ Markdown string
β”‚       └── errors.ts         # Error codes β†’ Markdown error messages
└── tests/
    β”œβ”€β”€ auth-reader.test.ts
    β”œβ”€β”€ api-client.test.ts
    β”œβ”€β”€ markdown.test.ts
    β”œβ”€β”€ errors.test.ts
    β”œβ”€β”€ index.test.ts
    └── integration.test.ts

πŸ”§ Local Testing

After building, point OpenCode at your local package:

{
  "plugin": ["./path/to/opencode-codex-quota"]
}

Then run /codex_quota in OpenCode to test.


πŸ“ Code Quality

The project uses Biome for linting and formatting:

  • No any types β€” enforced by noExplicitAny: "error"
  • No banned imports β€” enforced by noBannedImports: "error"
  • 2-space indentation β€” spaces, not tabs
  • Organized imports β€” auto-sorted

Run npm run lint before committing.


πŸ”„ Commit Strategy

Commits follow a structured wave pattern:

Commit Description
1 chore: project scaffolding with node.js, typescript, biome config
2 feat: add TypeScript type definitions for API + auth
3 feat: AuthReader service β€” read auth.json, parse JWT, handle E1-E11 errors
4 feat: ApiClient service β€” query wham/usage with timeout, validation, E4-E8 errors
5 feat: Formatter β€” Markdown output with compact/full modes, progress bars, time formatting
6 feat: error formatter β€” Markdown output for all E1-E11 scenarios
7 feat: plugin entry point β€” codex_quota tool with compact/full modes
8 test: integration tests β€” full pipeline from auth through API to markdown output
9 docs: add README with installation, usage, and development instructions

🀝 Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.


πŸ“– Next Steps

πŸ“š opencode-codex-quota

Getting Started

Reference

Development


GitHub Repository Β· npm Β· Issues

Clone this wiki locally