coding
Root: language selection, paradigm guidance, code quality SOLID/DRY/YAGNI, PR standards
What this skill does
# coding
## Purpose
This skill enables OpenClaw to assist with coding tasks, including selecting programming languages, guiding on paradigms (e.g., OOP, functional), enforcing code quality principles like SOLID, DRY, and YAGNI, and adhering to PR standards such as meaningful commits and code reviews.
## When to Use
Use this skill when writing new code, refactoring existing code, or reviewing pull requests. Apply it for language selection in multi-language projects, paradigm decisions in complex systems, or quality checks to avoid anti-patterns. Ideal for developers facing decisions on code structure or standards compliance.
## Key Capabilities
- Language selection: Automatically suggests languages based on project needs, e.g., recommending Python for scripting or Java for enterprise apps.
- Paradigm guidance: Provides advice on paradigms like OOP (e.g., use classes for encapsulation) or functional programming (e.g., prefer immutability).
- Code quality enforcement: Checks for SOLID principles (e.g., Single Responsibility: ensure classes have one reason to change) and DRY/YAGNI (e.g., detect duplicated code blocks).
- PR standards: Validates commits against rules like atomic changes and descriptive messages.
- Integration with tools: Parses Git diffs for PR reviews or analyzes code snippets for quality metrics.
## Usage Patterns
To use this skill, invoke OpenClaw via CLI or API, specifying inputs like code snippets or project context. For language selection, provide project requirements; for paradigm guidance, include code samples. Always pass an API key via environment variable, e.g., set `$OPENCLAW_API_KEY` before commands. Structure requests with JSON payloads containing fields like "language", "code", and "paradigm". Handle responses by parsing JSON for suggestions or corrections. Example pattern: Pipe code through OpenClaw for real-time feedback in a CI/CD pipeline.
## Common Commands/API
Use the OpenClaw CLI for quick tasks or the REST API for programmatic access. CLI commands require `$OPENCLAW_API_KEY` set. API endpoints use POST requests with JSON bodies.
- CLI Command: `openclaw code --language python --paradigm oop --check solid < input.txt`
- Flags: `--language` specifies the language (e.g., "python", "java"); `--paradigm` sets guidance type (e.g., "oop"); `--check` enables quality checks (e.g., "solid", "dry").
- Output: JSON with suggestions, e.g., {"suggestion": "Use a class for this function."}
- API Endpoint: POST to `/api/coding/assist`
- Body: JSON like {"code": "def add(a, b): return a + b", "language": "python", "checks": ["dry", "yagni"]}
- Headers: Include `Authorization: Bearer $OPENCLAW_API_KEY`
- Response: JSON object, e.g., {"quality_score": 8, "issues": ["Function violates DRY principle"]}
- Code Snippet for API Call (Python):
```python
import requests
api_key = os.environ.get('OPENCLAW_API_KEY')
response = requests.post('https://api.openclaw.ai/api/coding/assist', headers={'Authorization': f'Bearer {api_key}'}, json={'code': 'some code', 'language': 'js'})
print(response.json()['suggestion'])
```
- Config Format: Use JSON for configurations, e.g.,
```
{
"default_language": "python",
"checks": ["solid", "dry"],
"paradigm": "functional"
}
```
Save as `.openclaw-config.json` in your project root for CLI overrides.
## Integration Notes
Integrate this skill into IDEs like VS Code via extensions or scripts that call the API. For CI/CD, use it in GitHub Actions by adding a step: `run: openclaw code --check solid --input path/to/code.py`. Ensure `$OPENCLAW_API_KEY` is stored securely, e.g., in GitHub Secrets as `OPENCLAW_API_KEY`. For web apps, embed API calls in backend services, handling rate limits (e.g., 100 requests/min). Test integrations with mock responses to avoid live API hits during development.
## Error Handling
When errors occur, check HTTP status codes from API responses (e.g., 401 for unauthorized, indicating missing `$OPENCLAW_API_KEY`). For CLI, parse error messages like "Error: Invalid language specified" and retry with corrections. Implement retry logic for transient errors (e.g., 5xx status codes) using exponential backoff. In code, wrap API calls in try-except blocks:
```python
try:
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
except requests.exceptions.HTTPError as e:
print(f"Error: {e.response.status_code} - {e.response.text}")
```
Log errors with context, such as the input code, for debugging.
## Concrete Usage Examples
1. **Example 1: Generating Code with Language Selection**
- Task: Write a simple function in Python using OOP paradigm.
- Command: `openclaw code --language python --paradigm oop --prompt "Implement a counter class"`
- Expected: Output JSON with code like {"code": "class Counter: def __init__(self): self.count = 0"}
- How: Set `$OPENCLAW_API_KEY`, run the command, and integrate the response into your project.
2. **Example 2: Code Quality Review for PR**
- Task: Check a JavaScript snippet for DRY and SOLID violations.
- API Call: POST to `/api/coding/assist` with body {"code": "function add(a) { return a + 1; } function addTwo(b) { return b + 2; }", "language": "js", "checks": ["dry"]}
- Expected: Response like {"issues": ["Functions are similar; consider a generic add function to follow DRY"]}
- How: Use the response to refactor code before committing, e.g., merge functions in your editor.
## Graph Relationships
- Related to: debugging (shares code analysis capabilities), testing (enforces quality for testability), deployment (guides on production-ready code).
- Clusters: coding (primary), software (secondary for broader development tasks).
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.