Skip to content

Latest commit

 

History

History
161 lines (124 loc) · 3.67 KB

File metadata and controls

161 lines (124 loc) · 3.67 KB

AGENTS.md - OhMyOpenCode Toggle Tool

This repository contains a simple Node.js tool for toggling OhMyOpenCode plugin status.

Build/Test Commands

Note: This project has no build step. It's a pure Node.js script.

Running Tests

Tests are manual integration checks via CI. Run locally:

# Setup test config
cp config.example.json opencode.json

# Test all commands
node omo-toggle/omo-toggle.js status
node omo-toggle/omo-toggle.js off
node omo-toggle/omo-toggle.js on

# Or use the convenience script (after installation)
cd %USERPROFILE%\.config\opencode
omo status
omo off
omo on

Test via CI:

# GitHub Actions workflow (automated)
./.github/workflows/ci.yml
# Tests on Node.js 16.x, 18.x, 20.x

Running the Tool

# Direct execution
node omo-toggle/omo-toggle.js [command]

# After installation
odo [command]
opo [command]

# Valid commands: on, off, enable, disable, status

Code Style Guidelines

JavaScript/Node.js

Language: CommonJS (not ESM modules)

Imports:

  • Use require() for built-in modules only
  • No external dependencies
  • Import order: built-ins first (fs, path, etc.)
// ✅ Correct
const fs = require('fs');
const path = require('path');

Indentation:

  • 4 spaces (no tabs)

Naming Conventions:

  • Variables: camelCase (configText, configPath)
  • Files: kebab-case (omo-toggle.js)

Error Handling:

  • Use try-catch blocks for file operations
  • Console.error for error messages
  • process.exit(1) on fatal errors
try {
  configText = fs.readFileSync(configPath, 'utf8');
} catch (error) {
  console.error('无法读取配置文件:', error.message);
  process.exit(1);
}

Comments & Messages:

  • Use Chinese for user-facing messages
  • Use English for inline code comments (mixed codebase)
  • Include emoji for status messages: ✅ ❌
// 获取命令行参数
const command = process.argv[2];

console.log('✅ OhMyOpenCode 已启用');
console.error('无法读取配置文件:', error.message);

Code Organization

Project Structure:

  • /omo-toggle/ - Core tool directory
    • omo-toggle.js - Main logic
    • omo.bat - Windows batch wrapper
  • / - Root directory
    • omo.bat - Installation shortcut
    • install.bat - Windows installer
    • config.example.json - Config template
    • README.md - Chinese documentation

Script Entry Point:

  • Shebang: #!/usr/bin/env node
  • CLI args: process.argv[2] for commands
  • Exit codes: 0 for success, 1 for errors

Files & Configurations

Target Config File: opencode.json (not in repo)

  • Location: Parent directory of script
  • Modified in-place for enable/disable toggling

No Build Tools:

  • No package.json
  • No dependencies
  • No TypeScript
  • No linting config

Windows Batch Scripts

Style:

  • Use @echo off (silent execution)
  • SET variables for paths
  • XCOPY for directory copy
  • COPY for file copy
  • >nul to suppress copy output
  • Error handling with errorlevel
@echo off
setlocal enabledelayedexpansion
set TARGET_DIR=%USERPROFILE%\.config\opencode

Development Notes

Core Logic:

  • Plugin enabled when "oh-my-opencode" appears in config
  • Plugin disabled when "oh-my-opencode" appears commented (// prefix)
  • Simple string replacement: removes/adds // prefix
  • Status check: searches for unquoted plugin string

Critical Paths:

  • Config path: path.join(__dirname, '..', 'opencode.json')
  • This assumes the script runs from omo-toggle/ subdirectory

Platform Support:

  • Primary: Windows (batch scripts)
  • Cross-platform: Node.js script runs anywhere

No Testing Framework:

  • Manual testing only
  • CI runs direct Node.js commands (no test harness)