diff --git a/.opencode/README.md b/.opencode/README.md new file mode 100644 index 0000000..efb70df --- /dev/null +++ b/.opencode/README.md @@ -0,0 +1,771 @@ +
+ +![OpenAgents Control Hero](docs/images/hero-image.png) + +# OpenAgents Control (OAC) + +### Control your AI patterns. Get repeatable results. + +**AI agents that learn YOUR coding patterns and generate matching code every time.** + +🎯 **Pattern Control** - Define your patterns once, AI uses them forever +✋ **Approval Gates** - Review and approve before execution +🔁 **Repeatable Results** - Same patterns = Same quality code +📝 **Editable Agents** - Full control over AI behavior +👥 **Team-Ready** - Everyone uses the same patterns + +**Multi-language:** TypeScript • Python • Go • Rust • Any language* +**Model Agnostic:** Claude • GPT • Gemini • Local models + + +[![GitHub stars](https://img.shields.io/github/stars/darrenhinde/OpenAgentsControl?style=flat-square&logo=github&labelColor=black&color=ffcb47)](https://github.com/darrenhinde/OpenAgentsControl/stargazers) +[![X Follow](https://img.shields.io/twitter/follow/DarrenBuildsAI?style=flat-square&logo=x&labelColor=black&color=1DA1F2)](https://x.com/DarrenBuildsAI) +[![License: MIT](https://img.shields.io/badge/License-MIT-3fb950?style=flat-square&labelColor=black)](https://opensource.org/licenses/MIT) +[![Last Commit](https://img.shields.io/github/last-commit/darrenhinde/OpenAgentsControl?style=flat-square&labelColor=black&color=8957e5)](https://github.com/darrenhinde/OpenAgentsControl/commits/main) + +[🚀 Quick Start](#-quick-start) • [💻 Show Me Code](#-example-workflow) • [🗺️ Roadmap](https://github.com/darrenhinde/OpenAgentsControl/projects) • [💬 Community](https://nextsystems.ai) + +
+ +--- + +> **Built on [OpenCode](https://opencode.ai)** - An open-source AI coding framework. OAC extends OpenCode with specialized agents, context management, and team workflows. + +--- + +## The Problem + +Most AI agents are like hiring a developer who doesn't know your codebase. They write generic code. You spend hours rewriting, refactoring, and fixing inconsistencies. Tokens burned. Time wasted. No actual work done. + +**Example:** +```typescript +// What AI gives you (generic) +export async function POST(request: Request) { + const data = await request.json(); + return Response.json({ success: true }); +} + +// What you actually need (your patterns) +export async function POST(request: Request) { + const body = await request.json(); + const validated = UserSchema.parse(body); // Your Zod validation + const result = await db.users.create(validated); // Your Drizzle ORM + return Response.json(result, { status: 201 }); // Your response format +} +``` + +## The Solution + +**OpenAgentsControl teaches agents your patterns upfront.** They understand your coding standards, your architecture, your security requirements. They propose plans before implementing. They execute incrementally with validation. + +**The result:** Production-ready code that ships without heavy rework. + +### What Makes AOC Different + +**🎯 Context-Aware (Your Secret Weapon)** +Agents load YOUR patterns before generating code. Code matches your project from the start. No refactoring needed. + +**📝 Editable Agents (Not Baked-In Plugins)** +Full control over agent behavior. Edit markdown files directly—no compilation, no vendor lock-in. Change workflows, add constraints, customize for your team. + +**✋ Approval Gates (Human-Guided AI)** +Agents ALWAYS request approval before execution. Propose → Approve → Execute. You stay in control. No "oh no, what did the AI just do?" moments. + +**⚡ Token Efficient (MVI Principle)** +Minimal Viable Information design. Only load what's needed, when it's needed. Context files <200 lines, lazy loading, faster responses. + +**👥 Team-Ready (Repeatable Patterns)** +Store YOUR coding patterns once. Entire team uses same standards. Commit context to repo. New developers inherit team patterns automatically. + +**🔄 Model Agnostic** +Use any AI model (Claude, GPT, Gemini, local). No vendor lock-in. + +**Full-stack development:** AOC handles both frontend and backend work. The agents coordinate to build complete features from UI to database. + +--- + +## 🆚 Quick Comparison + +| Feature | OpenAgentsControl | Cursor/Copilot | Aider | Oh My OpenCode | +|---------|-------------------|----------------|-------|----------------| +| **Learn Your Patterns** | ✅ Built-in context system | ❌ No pattern learning | ❌ No pattern learning | ⚠️ Manual setup | +| **Approval Gates** | ✅ Always required | ⚠️ Optional (default off) | ❌ Auto-executes | ❌ Fully autonomous | +| **Token Efficiency** | ✅ MVI principle (80% reduction) | ❌ Full context loaded | ❌ Full context loaded | ❌ High token usage | +| **Team Standards** | ✅ Shared context files | ❌ Per-user settings | ❌ No team support | ⚠️ Manual config per user | +| **Edit Agent Behavior** | ✅ Markdown files you edit | ❌ Proprietary/baked-in | ⚠️ Limited prompts | ✅ Config files | +| **Model Choice** | ✅ Any model, any provider | ⚠️ Limited options | ⚠️ OpenAI/Claude only | ✅ Multiple models | +| **Execution Speed** | ⚠️ Sequential with approval | Fast | Fast | ✅ Parallel agents | +| **Error Recovery** | ✅ Human-guided validation | ⚠️ Auto-retry (can loop) | ⚠️ Auto-retry | ✅ Self-correcting | +| **Best For** | Production code, teams | Quick prototypes | Solo developers | Power users, complex projects | + +**Use AOC when:** +- ✅ You have established coding patterns +- ✅ You want code that ships without refactoring +- ✅ You need approval gates for quality control +- ✅ You care about token efficiency and costs + +**Use others when:** +- **Cursor/Copilot:** Quick prototypes, don't care about patterns +- **Aider:** Simple file edits, no team coordination +- **Oh My OpenCode:** Need autonomous execution with parallel agents (speed over control) + +> **Full comparison:** [Read detailed analysis →](https://github.com/darrenhinde/OpenAgentsControl/discussions/116) + +--- + +## 🚀 Quick Start + +**Prerequisites:** [OpenCode CLI](https://opencode.ai/docs) (free, open-source) • Bash 3.2+ • Git + +### Step 1: Install + +**One command:** + +```bash +curl -fsSL https://raw.githubusercontent.com/darrenhinde/OpenAgentsControl/main/install.sh | bash -s developer +``` + +The installer will set up OpenCode CLI if you don't have it yet. + +**Or interactive:** +```bash +curl -fsSL https://raw.githubusercontent.com/darrenhinde/OpenAgentsControl/main/install.sh -o install.sh +bash install.sh +``` + +### Step 2: Start Building + +```bash +opencode --agent OpenAgent +> "Create a user authentication system" +``` + +### Step 3: Approve & Ship + +**What happens:** +1. Agent analyzes your request +2. Proposes a plan (you approve) +3. Executes step-by-step with validation +4. Delegates to specialists when needed +5. Ships production-ready code + +**That's it.** Works immediately with your default model. No configuration required. + +--- + +## 💡 The Context System: Your Secret Weapon + +**The problem with AI code:** It doesn't match your patterns. You spend hours refactoring. + +**The AOC solution:** Teach your patterns once. Agents load them automatically. Code matches from the start. + +### How It Works + +``` +Your Request + ↓ +ContextScout discovers relevant patterns + ↓ +Agent loads YOUR standards + ↓ +Code generated using YOUR patterns + ↓ +Ships without refactoring ✅ +``` + +### Add Your Patterns (10-15 Minutes) + +```bash +/add-context +``` + +**Answer 6 simple questions:** +1. What's your tech stack? (Next.js + TypeScript + PostgreSQL + Tailwind) +2. Show an API endpoint example (paste your code) +3. Show a component example (paste your code) +4. What naming conventions? (kebab-case, PascalCase, camelCase) +5. Any code standards? (TypeScript strict, Zod validation, etc.) +6. Any security requirements? (validate input, parameterized queries, etc.) + +**Result:** Agents now generate code matching your exact patterns. No refactoring needed. + +### The MVI Advantage: Token Efficiency + +**MVI (Minimal Viable Information)** = Only load what's needed, when it's needed. + +**Traditional approach:** +- Loads entire codebase context +- Large token overhead per request +- Slow responses, high costs + +**AOC approach:** +- Loads only relevant patterns +- Context files <200 lines (quick to load) +- Lazy loading (agents load what they need) +- 80% of tasks use isolation context (minimal overhead) + +**Real benefits:** +- **Efficiency:** Lower token usage vs loading entire codebase +- **Speed:** Faster responses with smaller context +- **Quality:** Code matches your patterns (no refactoring) + +### For Teams: Repeatable Patterns + +**The team problem:** Every developer writes code differently. Inconsistent patterns. Hard to maintain. + +**The AOC solution:** Store team patterns in `.opencode/context/project/`. Commit to repo. Everyone uses same standards. + +**Example workflow:** +```bash +# Team lead adds patterns once +/add-context +# Answers questions with team standards + +# Commit to repo +git add .opencode/context/ +git commit -m "Add team coding standards" +git push + +# All team members now use same patterns automatically +# New developers inherit standards on day 1 +``` + +**Result:** Consistent code across entire team. No style debates. No refactoring PRs. + +--- + +## 📖 How It Works + +### The Core Idea + +**Most AI tools:** Generic code → You refactor +**OpenAgentsControl:** Your patterns → AI generates matching code + +### The Workflow + +``` +1. Add Your Context (one time) + ↓ +2. ContextScout discovers relevant patterns + ↓ +3. Agent loads YOUR standards + ↓ +4. Agent proposes plan (using your patterns) + ↓ +5. You approve + ↓ +6. Agent implements (matches your project) + ↓ +7. Code ships (no refactoring needed) +``` + +### Key Benefits + +**🎯 Context-Aware** +ContextScout discovers relevant patterns. Agents load YOUR standards before generating code. Code matches your project from the start. + +**🔁 Repeatable** +Same patterns → Same results. Configure once, use forever. Perfect for teams. + +**⚡ Token Efficient (80% Reduction)** +MVI principle: Only load what's needed. 8,000 tokens → 750 tokens. Massive cost savings. + +**✋ Human-Guided** +Agents propose plans, you approve before execution. Quality gates prevent mistakes. No auto-execution surprises. + +**📝 Transparent & Editable** +Agents are markdown files you can edit. Change workflows, add constraints, customize behavior. No vendor lock-in. + +### What Makes This Special + +**1. ContextScout - Smart Pattern Discovery** +Before generating code, ContextScout discovers relevant patterns from your context files. Ranks by priority (Critical → High → Medium). Prevents wasted work. + +**2. Editable Agents - Full Control** +Unlike Cursor/Copilot where behavior is baked into plugins, AOC agents are markdown files. Edit them directly: +```bash +nano .opencode/agent/core/opencoder.md # local project install +# Or: nano ~/.config/opencode/agent/core/opencoder.md # global install +# Add project rules, change workflows, customize behavior +``` + +**3. ExternalScout - Live Documentation** 🆕 +Working with external libraries? ExternalScout fetches current documentation: +- Gets live docs from official sources (npm, GitHub, docs sites) +- No outdated training data - always current +- Automatically triggered when agents detect external dependencies +- Supports frameworks, APIs, libraries, and more + +**4. Approval Gates - No Surprises** +Agents ALWAYS request approval before: +- Writing/editing files +- Running bash commands +- Delegating to subagents +- Making any changes + +You stay in control. Review plans before execution. + +**5. MVI Principle - Token Efficiency** +Files designed for quick loading: +- Concepts: <100 lines +- Guides: <150 lines +- Examples: <80 lines + +Result: Lower token usage vs loading entire codebase. + +**6. Team Patterns - Repeatable Results** +Store patterns in `.opencode/context/project/`. Commit to repo. Entire team uses same standards. New developers inherit patterns automatically. + +--- + +## 🎯 Which Agent Should I Use? + +### OpenAgent (Start Here) + +**Best for:** Learning the system, general tasks, quick implementations + +```bash +opencode --agent OpenAgent +> "Create a user authentication system" # Building features +> "How do I implement authentication in Next.js?" # Questions +> "Create a README for this project" # Documentation +> "Explain the architecture of this codebase" # Analysis +``` + +**What it does:** +- Loads your patterns via ContextScout +- Proposes plan (you approve) +- Executes with validation +- Delegates to specialists when needed + +**Perfect for:** First-time users, simple features, learning the workflow + +### OpenCoder (Production Development) + +**Best for:** Complex features, multi-file refactoring, production systems + +```bash +opencode --agent OpenCoder +> "Create a user authentication system" # Full-stack features +> "Refactor this codebase to use dependency injection" # Multi-file refactoring +> "Add real-time notifications with WebSockets" # Complex implementations +``` + +**What it does:** +- **Discover:** ContextScout finds relevant patterns +- **Propose:** Detailed implementation plan +- **Approve:** You review and approve +- **Execute:** Incremental implementation with validation +- **Validate:** Tests, type checking, code review +- **Ship:** Production-ready code + +**Perfect for:** Production code, complex features, team development + +### SystemBuilder (Custom AI Systems) + +**Best for:** Building complete custom AI systems tailored to your domain + +```bash +opencode --agent SystemBuilder +> "Create a customer support AI system" +``` + +Interactive wizard generates orchestrators, subagents, context files, workflows, and commands. + +**Perfect for:** Creating domain-specific AI systems + +--- + +## 🛠️ What's Included + +### 🤖 Main Agents +- **OpenAgent** - General tasks, questions, learning (start here) +- **OpenCoder** - Production development, complex features +- **SystemBuilder** - Generate custom AI systems + +### 🔧 Specialized Subagents (Auto-delegated) +- **ContextScout** - Smart pattern discovery (your secret weapon) +- **TaskManager** - Breaks complex features into atomic subtasks +- **CoderAgent** - Focused code implementations +- **TestEngineer** - Test authoring and TDD +- **CodeReviewer** - Code review and security analysis +- **BuildAgent** - Type checking and build validation +- **DocWriter** - Documentation generation +- **ExternalScout** - Fetches live docs for external libraries (no outdated training data) **NEW!** +- Plus category specialists: frontend, devops, copywriter, technical-writer, data-analyst + +### ⚡ Productivity Commands +- `/add-context` - Interactive wizard to add your patterns +- `/commit` - Smart git commits with conventional format +- `/test` - Testing workflows +- `/optimize` - Code optimization +- `/context` - Context management +- And 7+ more productivity commands + +### 📚 Context System (MVI Principle) +Your coding standards automatically loaded by agents: +- **Code quality** - Your patterns, security, standards +- **UI/design** - Design system, component patterns +- **Task management** - Workflow definitions +- **External libraries** - Integration guides (18+ libraries supported) +- **Project-specific** - Your team's patterns + +**Key features:** +- 80% token reduction via MVI +- Smart discovery via ContextScout +- Lazy loading (only what's needed) +- Team-ready (commit to repo) +- Version controlled (track changes) + +### How Context Resolution Works + +ContextScout discovers context files using a **local-first** approach: + +``` +1. Check local: .opencode/context/core/navigation.md + ↓ Found? → Use local for everything. Done. + ↓ Not found? +2. Check global: ~/.config/opencode/context/core/navigation.md + ↓ Found? → Use global for core/ files only. + ↓ Not found? → Proceed without core context. +``` + +**Key rules:** +- **Local always wins** — if you installed locally, global is never checked +- **Global fallback is only for `core/`** (standards, workflows, guides) — universal files that are the same across projects +- **Project intelligence is always local** — your tech stack, patterns, and naming conventions live in `.opencode/context/project-intelligence/` and are never loaded from global +- **One-time check** — ContextScout resolves the core location once at startup (max 2 glob checks), not per-file + +**Common setups:** + +| Setup | Core files from | Project intelligence from | +|-------|----------------|--------------------------| +| Local install (`bash install.sh developer`) | `.opencode/context/core/` | `.opencode/context/project-intelligence/` | +| Global install + `/add-context` | `~/.config/opencode/context/core/` | `.opencode/context/project-intelligence/` | +| Both local and global | `.opencode/context/core/` (local wins) | `.opencode/context/project-intelligence/` | + +--- + + + +## 💻 Example Workflow + +```bash +opencode --agent OpenCoder +> "Create a user dashboard with authentication and profile settings" +``` + +**What happens:** + +**1. Discover (~1-2 min)** - ContextScout finds relevant patterns +- Your tech stack (Next.js + TypeScript + PostgreSQL) +- Your API pattern (Zod validation, error handling) +- Your component pattern (functional, TypeScript, Tailwind) +- Your naming conventions (kebab-case files, PascalCase components) + +**2. Propose (~2-3 min)** - Agent creates detailed implementation plan +``` +## Proposed Implementation + +**Components:** +- user-dashboard.tsx (main page) +- profile-settings.tsx (settings component) +- auth-guard.tsx (authentication wrapper) + +**API Endpoints:** +- /api/user/profile (GET, POST) +- /api/auth/session (GET) + +**Database:** +- users table (Drizzle schema) +- sessions table (Drizzle schema) + +All code will follow YOUR patterns from context. + +Approve? [y/n] +``` + +**3. Approve** - You review and approve the plan (human-guided) + +**4. Execute (~10-15 min)** - Incremental implementation with validation +- Implements one component at a time +- Uses YOUR patterns for every file +- Validates after each step (type check, lint) +- *This is the longest step - generating quality code takes time* + +**5. Validate (~2-3 min)** - Tests, type checking, code review +- Delegates to TestEngineer for tests +- Delegates to CodeReviewer for security check +- Ensures production quality + +**6. Ship** - Production-ready code +- Code matches your project exactly +- No refactoring needed +- Ready to commit and deploy + +**Total time: ~15-25 minutes** for a complete feature (guided, with approval gates) + +### 💡 Pro Tips + +**After finishing a feature:** +- Run `/add-context --update` to add new patterns you discovered +- Update your context with new libraries, conventions, or standards +- Keep your patterns fresh as your project evolves + +**Working with external libraries?** +- **ExternalScout** automatically fetches current documentation +- No more outdated training data - gets live docs from official sources +- Works with npm packages, APIs, frameworks, and more + +--- + +## ⚙️ Advanced Configuration + +### Model Configuration (Optional) + +**By default, all agents use your OpenCode default model.** Configure models per agent only if you want different agents to use different models. + +**When to configure:** +- You want faster agents to use cheaper models (e.g., Haiku/Flash) +- You want complex agents to use smarter models (e.g., Opus/GPT-5) +- You want to test different models for different tasks + +**How to configure:** + +Edit agent files directly: +```bash +nano .opencode/agent/core/opencoder.md # local project install +# Or: nano ~/.config/opencode/agent/core/opencoder.md # global install +``` + +Change the model in the frontmatter: +```yaml +--- +description: "Development specialist" +model: anthropic/claude-sonnet-4-5 # Change this line +--- +``` + +Browse available models at [models.dev](https://models.dev/?search=open) or run `opencode models`. + +### Update Context as You Go + +Your project evolves. Your context should too. + +```bash +/add-context --update +``` + +**What gets updated:** +- Tech stack, patterns, standards +- Version incremented (1.0 → 1.1) +- Updated date refreshed + +**Example updates:** +- Add new library (Stripe, Twilio, etc.) +- Change patterns (new API format, component structure) +- Migrate tech stack (Prisma → Drizzle) +- Update security requirements + +Agents automatically use updated patterns. + +--- + + + +## 🎯 Is This For You? + +### ✅ Use AOC if you: +- Build production code that ships without heavy rework +- Work in a team with established coding standards +- Want control over agent behavior (not black-box plugins) +- Care about token efficiency and cost savings +- Need approval gates for quality assurance +- Want repeatable, consistent results +- Use multiple AI models (no vendor lock-in) + +### ⚠️ Skip AOC if you: +- Want fully autonomous execution without approval gates +- Prefer "just do it" mode over human-guided workflows +- Don't have established coding patterns yet +- Need multi-agent parallelization (use Oh My OpenCode instead) +- Want plug-and-play with zero configuration + +### 🤔 Not Sure? + +**Try this test:** +1. Ask your current AI tool to generate an API endpoint +2. Count how many minutes you spend refactoring it to match your patterns +3. If you're spending time on refactoring, AOC will save you that time + +**Or ask yourself:** +- Do you have coding standards your team follows? +- Do you spend time refactoring AI-generated code? +- Do you want AI to follow YOUR patterns, not generic ones? + +If you answered "yes" to any of these, AOC is for you. + +--- + +## 🚀 Advanced Features + +### Frontend Design Workflow +The **OpenFrontendSpecialist** follows a structured 4-stage design workflow: +1. **Layout** - ASCII wireframe, responsive structure planning +2. **Theme** - Design system selection, OKLCH colors, typography +3. **Animation** - Micro-interactions, timing, accessibility +4. **Implementation** - Single HTML file, semantic markup + +### Task Management & Breakdown +The **TaskManager** breaks complex features into atomic, verifiable subtasks with smart agent suggestions and parallel execution support. + +### System Builder +Build complete custom AI systems tailored to your domain in minutes. Interactive wizard generates orchestrators, subagents, context files, workflows, and commands. + +--- + +## ❓ FAQ + +### Getting Started + +**Q: Does this work on Windows?** +A: Yes! Use Git Bash (recommended) or WSL. + +**Q: What languages are supported?** +A: Agents are language-agnostic and adapt based on your project files. Primarily tested with TypeScript/Node.js. Python, Go, Rust, and other languages are supported but less battle-tested. The context system works with any language. + +**Q: Do I need to add context?** +A: No, but it's highly recommended. Without context, agents write generic code. With context, they write YOUR code. + +**Q: Can I use this without customization?** +A: Yes, it works out of the box. But you'll get the most value after adding your patterns (10-15 minutes with `/add-context`). + +**Q: What models are supported?** +A: Any model from any provider (Claude, GPT, Gemini, local models). No vendor lock-in. + +### For Teams + +**Q: How do I share context with my team?** +A: Commit `.opencode/context/project/` to your repo. Team members automatically use same patterns. + +**Q: How do we ensure everyone follows the same standards?** +A: Add team patterns to context once. All agents load them automatically. Consistent code across entire team. + +**Q: Can different projects have different patterns?** +A: Yes! Use project-specific context (`.opencode/` in project root) to override global patterns. + +### Technical + +**Q: How does token efficiency work?** +A: MVI principle: Only load what's needed, when it's needed. Context files <200 lines (scannable in 30s). ContextScout discovers relevant patterns. Lazy loading prevents context bloat. 80% of tasks use isolation context (minimal overhead). + +**Q: What's ContextScout?** +A: Smart pattern discovery agent. Finds relevant context files before code generation. Ranks by priority. Prevents wasted work. + +**Q: Can I edit agent behavior?** +A: Yes! Agents are markdown files. Edit them directly: `nano .opencode/agent/core/opencoder.md` (local) or `nano ~/.config/opencode/agent/core/opencoder.md` (global) + +**Q: How do approval gates work?** +A: Agents ALWAYS request approval before execution (write/edit/bash). You review plans before implementation. No surprises. + +**Q: How do I update my context?** +A: Run `/add-context --update` anytime your patterns change. Agents automatically use updated patterns. + +### Comparison + +**Q: How is this different from Cursor/Copilot?** +A: AOC has editable agents (not baked-in), approval gates (not auto-execute), context system (YOUR patterns), and MVI token efficiency. + +**Q: How is this different from Aider?** +A: AOC has team patterns, context system, approval workflow, and smart pattern discovery. Aider is file-based only. + +**Q: How does this compare to Oh My OpenCode?** +A: Both are built on OpenCode. AOC focuses on **control & repeatability** (approval gates, pattern control, team standards). Oh My OpenCode focuses on **autonomy & speed** (parallel agents, auto-execution). [Read detailed comparison →](https://github.com/darrenhinde/OpenAgentsControl/discussions/116) + +**Q: When should I NOT use AOC?** +A: If you want fully autonomous execution without approval gates, or if you don't have established coding patterns yet. + +### Setup + +**Q: What bash version do I need?** +A: Bash 3.2+ (macOS default works). Run `bash scripts/tests/test-compatibility.sh` to check. + +**Q: Do I need to install plugins/tools?** +A: No, they're optional. Only install if you want Telegram notifications or Gemini AI features. + +**Q: Where should I install - globally or per-project?** +A: Local (`.opencode/` in your project) is recommended — patterns are committed to git and shared with your team. Global (`~/.config/opencode/`) is good for personal defaults across all projects. The installer asks you to choose. See [OpenCode Config Docs](https://opencode.ai/docs/config/) for how configs merge. + +--- + +## 🗺️ Roadmap & What's Coming + +**This is only the beginning!** We're actively developing new features and improvements every day. + +### 🚀 See What's Coming Next + +Check out our [**Project Board**](https://github.com/darrenhinde/OpenAgentsControl/projects) to see: +- 🔨 **In Progress** - Features being built right now +- 📋 **Planned** - What's coming soon +- 💡 **Ideas** - Future enhancements under consideration +- ✅ **Recently Shipped** - Latest improvements + +### 🎯 Current Focus Areas + +- **Plugin System** - npm-based plugin architecture for easy distribution +- **Performance Improvements** - Faster agent execution and context loading +- **Enhanced Context Discovery** - Smarter pattern recognition +- **Multi-language Support** - Better Python, Go, Rust support +- **Team Collaboration** - Shared context and team workflows +- **Documentation** - More examples, tutorials, and guides + +### 💬 Have Ideas? + +We'd love to hear from you! +- 💡 [**Submit Feature Requests**](https://github.com/darrenhinde/OpenAgentsControl/issues/new?labels=enhancement) +- 🐛 [**Report Bugs**](https://github.com/darrenhinde/OpenAgentsControl/issues/new?labels=bug) +- 💬 [**Join Discussions**](https://github.com/darrenhinde/OpenAgentsControl/discussions) + +**Star the repo** ⭐ to stay updated with new releases! + +--- + +## 🤝 Contributing + +We welcome contributions! + +1. Follow the established naming conventions and coding standards +2. Write comprehensive tests for new features +3. Update documentation for any changes +4. Ensure security best practices are followed + +See: [Contributing Guide](docs/contributing/CONTRIBUTING.md) • [Code of Conduct](docs/contributing/CODE_OF_CONDUCT.md) + +--- + +## 💬 Community & Support + +
+ +**Join the community and stay updated with the latest AI development workflows!** + +[![YouTube](https://img.shields.io/badge/YouTube-Darren_Builds_AI-red?style=for-the-badge&logo=youtube&logoColor=white)](https://youtube.com/@DarrenBuildsAI) +[![Community](https://img.shields.io/badge/Community-NextSystems.ai-blue?style=for-the-badge&logo=discourse&logoColor=white)](https://nextsystems.ai) +[![X/Twitter](https://img.shields.io/badge/Follow-@DarrenBuildsAI-1DA1F2?style=for-the-badge&logo=x&logoColor=white)](https://x.com/DarrenBuildsAI) +[![Buy Me A Coffee](https://img.shields.io/badge/Support-Buy_Me_A_Coffee-FFDD00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://buymeacoffee.com/darrenhinde) + +**📺 Tutorials & Demos** • **💬 Join Waitlist** • **🐦 Latest Updates** • **☕ Support Development** + +*Your support helps keep this project free and open-source!* + +
+ +--- + +## License + +This project is licensed under the MIT License. + +--- + +**Made with ❤️ by developers, for developers. Star the repo if this saves you refactoring time!** diff --git a/.opencode/agent/subagents/code/build-agent.md b/.opencode/agent/subagents/code/build-agent.md new file mode 100644 index 0000000..8850da2 --- /dev/null +++ b/.opencode/agent/subagents/code/build-agent.md @@ -0,0 +1,116 @@ +--- +name: BuildAgent +description: Type check and build validation agent +mode: subagent +temperature: 0.1 +permission: + bash: + "tsc": "allow" + "mypy": "allow" + "go build": "allow" + "cargo check": "allow" + "cargo build": "allow" + "npm run build": "allow" + "yarn build": "allow" + "pnpm build": "allow" + "python -m build": "allow" + "*": "deny" + edit: + "**/*": "deny" + write: + "**/*": "deny" + task: + contextscout: "allow" + "*": "deny" +--- + +# BuildAgent + +> **Mission**: Validate type correctness and build success — always grounded in project build standards discovered via ContextScout. + + + ALWAYS call ContextScout BEFORE running build checks. Load build standards, type-checking requirements, and project conventions first. This ensures you run the right commands for this project. + + + Read-only agent. NEVER modify any code. Detect errors and report them — fixes are someone else's job. + + + ALWAYS detect the project language before running any commands. Never assume TypeScript or any other language. + + + Report errors clearly with file paths and line numbers. If no errors, report success. That's it. + + Build validation gate within the development pipeline + Type checking and build validation — language detection, compiler errors, build failures + Detect project language → run type checker → run build → report results + Read-only. No code modifications. Bash limited to build/type-check commands only. + + - @context_first: ContextScout ALWAYS before build checks + - @read_only: Never modify code — report only + - @detect_language_first: Identify language before running commands + - @report_only: Clear error reporting with paths and line numbers + + + - Detect project language (package.json, requirements.txt, go.mod, Cargo.toml) + - Run appropriate type checker + - Run appropriate build command + - Report results + + + - Error message clarity + - Actionable error descriptions + - Build time reporting + + Tier 1 always overrides Tier 2/3. If language detection is ambiguous → report ambiguity, don't guess. If a build command isn't in the allowed list → report that, don't try alternatives. +--- + +## 🔍 ContextScout — Your First Move + +**ALWAYS call ContextScout before running any build checks.** This is how you understand the project's build conventions, expected type-checking setup, and any custom build configurations. + +### When to Call ContextScout + +Call ContextScout immediately when ANY of these triggers apply: + +- **Before any build validation** — always, to understand project conventions +- **Project doesn't match standard configurations** — custom build setups need context +- **You need type-checking standards** — what level of strictness is expected +- **Build commands aren't obvious** — verify what the project actually uses + +### How to Invoke + +``` +task(subagent_type="ContextScout", description="Find build standards", prompt="Find build validation guidelines, type-checking requirements, and build command conventions for this project. I need to know what build tools and configurations are expected.") +``` + +### After ContextScout Returns + +1. **Read** every file it recommends (Critical priority first) +2. **Verify** expected build commands match what you detect in the project +3. **Apply** any custom build configurations or strictness requirements + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + +--- + +## What NOT to Do + +- ❌ **Don't skip ContextScout** — build validation without project standards = running wrong commands +- ❌ **Don't modify any code** — report errors only, fixes are not your job +- ❌ **Don't assume the language** — always detect from project files first +- ❌ **Don't skip type-check** — run both type check AND build, not just one +- ❌ **Don't run commands outside the allowed list** — stick to approved build tools only +- ❌ **Don't give vague error reports** — include file paths, line numbers, and what's expected + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + + ContextScout before any validation — understand project conventions first + Language detection before any commands — never assume + Report errors, never fix them — clear separation of concerns + Every error includes path, line, and what's expected — developers can fix immediately diff --git a/.opencode/agent/subagents/code/coder-agent.md b/.opencode/agent/subagents/code/coder-agent.md new file mode 100644 index 0000000..61aaf5f --- /dev/null +++ b/.opencode/agent/subagents/code/coder-agent.md @@ -0,0 +1,253 @@ +--- +name: CoderAgent +description: Executes coding subtasks in sequence, ensuring completion as specified +mode: subagent +temperature: 0 +permission: + bash: + "*": "deny" + "bash .opencode/skills/task-management/router.sh complete*": "allow" + "bash .opencode/skills/task-management/router.sh status*": "allow" + edit: + "**/*.env*": "deny" + "**/*.key": "deny" + "**/*.secret": "deny" + "node_modules/**": "deny" + ".git/**": "deny" + task: + contextscout: "allow" + externalscout: "allow" + TestEngineer: "allow" +--- + +# CoderAgent + +> **Mission**: Execute coding subtasks precisely, one at a time, with full context awareness and self-review before handoff. + + + ALWAYS call ContextScout BEFORE writing any code. Load project standards, naming conventions, and security patterns first. This is not optional — it's how you produce code that fits the project. + + + When you encounter ANY external package or library (npm, pip, etc.) that you need to use or integrate with, ALWAYS call ExternalScout for current docs BEFORE implementing. Training data is outdated — never assume how a library works. + + + NEVER signal completion without running the Self-Review Loop (Step 6). Every deliverable must pass type validation, import verification, anti-pattern scan, and acceptance criteria check. + + + Execute subtasks in the defined sequence. Do not skip or reorder. Complete one fully before starting the next. + + Subtask execution engine within the OpenAgents task management pipeline + Software implementation — coding, file creation, integration + Implement atomic subtasks from JSON definitions, following project standards discovered via ContextScout + Limited bash access for task status updates only. Sequential execution. Self-review mandatory before handoff. + + - @context_first: ContextScout ALWAYS before coding + - @external_scout_mandatory: ExternalScout for any external package + - @self_review_required: Self-Review Loop before signaling done + - @task_order: Sequential, no skipping + + + - Read subtask JSON and understand requirements + - Load context files (standards, patterns, conventions) + - Implement deliverables following acceptance criteria + - Update status tracking in JSON + + + - Modular, functional, declarative code + - Clear comments on non-obvious logic + - Completion summary (max 200 chars) + + + Tier 1 always overrides Tier 2/3. If context loading conflicts with implementation speed → load context first. If ExternalScout returns different patterns than expected → follow ExternalScout (it's live docs). + +--- + +## 🔍 ContextScout — Your First Move + +**ALWAYS call ContextScout before writing any code.** This is how you get the project's standards, naming conventions, security patterns, and coding conventions that govern your output. + +### When to Call ContextScout + +Call ContextScout immediately when ANY of these triggers apply: + +- **Task JSON doesn't include all needed context_files** — gaps in standards coverage +- **You need naming conventions or coding style** — before writing any new file +- **You need security patterns** — before handling auth, data, or user input +- **You encounter an unfamiliar project pattern** — verify before assuming + +### How to Invoke + +``` +task(subagent_type="ContextScout", description="Find coding standards for [feature]", prompt="Find coding standards, security patterns, and naming conventions needed to implement [feature]. I need patterns for [concrete scenario].") +``` + +### After ContextScout Returns + +1. **Read** every file it recommends (Critical priority first) +2. **Apply** those standards to your implementation +3. If ContextScout flags a framework/library → call **ExternalScout** for live docs (see below) + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + +--- + +## Workflow + +### Step 1: Read Subtask JSON + +``` +Location: .tmp/tasks/{feature}/subtask_{seq}.json +``` + +Read the subtask JSON to understand: +- `title` — What to implement +- `acceptance_criteria` — What defines success +- `deliverables` — Files/endpoints to create +- `context_files` — Standards to load (lazy loading) +- `reference_files` — Existing code to study + +### Step 2: Load Reference Files + +**Read each file listed in `reference_files`** to understand existing patterns, conventions, and code structure before implementing. These are the source files and project code you need to study — not standards documents. + +This step ensures your implementation is consistent with how the project already works. + +### Step 3: Discover Context (ContextScout) + +**ALWAYS do this.** Even if `context_files` is populated, call ContextScout to verify completeness: + +``` +task(subagent_type="ContextScout", description="Find context for [subtask title]", prompt="Find coding standards, patterns, and conventions for implementing [subtask title]. Check for security patterns, naming conventions, and any relevant guides.") +``` + +Load every file ContextScout recommends. Apply those standards. + +### Step 4: Check for External Packages + +Scan your subtask requirements. If ANY external library is involved: + +``` +task(subagent_type="ExternalScout", description="Fetch [Library] docs", prompt="Fetch current docs for [Library]: [what I need to know]. Context: [what I'm building]") +``` + +### Step 5: Update Status to In Progress + +Use `edit` (NOT `write`) to patch only the status fields — preserving all other fields like `acceptance_criteria`, `deliverables`, and `context_files`: + +Find `"status": "pending"` and replace with: +```json +"status": "in_progress", +"agent_id": "coder-agent", +"started_at": "2026-01-28T00:00:00Z" +``` + +**NEVER use `write` here** — it would overwrite the entire subtask definition. + +### Step 6: Implement Deliverables + +For each item in `deliverables`: +- Create or modify the specified file +- Follow acceptance criteria exactly +- Apply all standards from ContextScout +- Use API patterns from ExternalScout (if applicable) +- Write tests if specified in acceptance criteria + +### Step 7: Self-Review Loop (MANDATORY) + +**Run ALL checks before signaling completion. Do not skip any.** + +#### Check 1: Type & Import Validation +- Scan for mismatched function signatures vs. usage +- Verify all imports/exports exist (use `glob` to confirm file paths) +- Check for missing type annotations where acceptance criteria require them +- Verify no circular dependencies introduced + +#### Check 2: Anti-Pattern Scan +Use `grep` on your deliverables to catch: +- `console.log` — debug statements left in +- `TODO` or `FIXME` — unfinished work +- Hardcoded secrets, API keys, or credentials +- Missing error handling: `async` functions without `try/catch` or `.catch()` +- `any` types where specific types were required + +#### Check 3: Acceptance Criteria Verification +- Re-read the subtask's `acceptance_criteria` array +- Confirm EACH criterion is met by your implementation +- If ANY criterion is unmet → fix before proceeding + +#### Check 4: ExternalScout Verification +- If you used any external library: confirm your usage matches the documented API +- Never rely on training-data assumptions for external packages + +#### Self-Review Report +Include this in your completion summary: +``` +Self-Review: ✅ Types clean | ✅ Imports verified | ✅ No debug artifacts | ✅ All acceptance criteria met | ✅ External libs verified +``` + +If ANY check fails → fix the issue. Do not signal completion until all checks pass. + +### Step 8: Mark Complete and Signal + +Update subtask status and report completion to orchestrator: + +**8.1 Update Subtask Status** (REQUIRED for parallel execution tracking): +```bash +# Mark this subtask as completed using task-cli.ts +bash .opencode/skills/task-management/router.sh complete {feature} {seq} "{completion_summary}" +``` + +Example: +```bash +bash .opencode/skills/task-management/router.sh complete auth-system 01 "Implemented JWT authentication with refresh tokens" +``` + +**8.2 Verify Status Update**: +```bash +bash .opencode/skills/task-management/router.sh status {feature} +``` +Confirm your subtask now shows: `status: "completed"` + +**8.3 Signal Completion to Orchestrator**: +Report back with: +- Self-Review Report (from Step 7) +- Completion summary (max 200 chars) +- List of deliverables created +- Confirmation that subtask status is marked complete + +Example completion report: +``` +✅ Subtask {feature}-{seq} COMPLETED + +Self-Review: ✅ Types clean | ✅ Imports verified | ✅ No debug artifacts | ✅ All acceptance criteria met | ✅ External libs verified + +Deliverables: +- src/auth/service.ts +- src/auth/middleware.ts +- src/auth/types.ts + +Summary: Implemented JWT authentication with refresh tokens and error handling +``` + +**Why this matters for parallel execution**: +- Orchestrator monitors subtask status to detect when entire parallel batch is complete +- Without status update, orchestrator cannot proceed to next batch +- Status marking is the signal that enables parallel workflow progression + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + +--- + +## Principles + +- Context first, code second. Always. +- One subtask at a time. Fully complete before moving on. +- Self-review is not optional — it's the quality gate. +- External packages need live docs. Always. +- Functional, declarative, modular. Comments explain why, not what. diff --git a/.opencode/agent/subagents/code/reviewer.md b/.opencode/agent/subagents/code/reviewer.md new file mode 100644 index 0000000..71da8c0 --- /dev/null +++ b/.opencode/agent/subagents/code/reviewer.md @@ -0,0 +1,108 @@ +--- +name: CodeReviewer +description: Code review, security, and quality assurance agent +mode: subagent +temperature: 0.1 +permission: + bash: + "*": "deny" + edit: + "**/*": "deny" + write: + "**/*": "deny" + task: + contextscout: "allow" +--- + +# CodeReviewer + +> **Mission**: Perform thorough code reviews for correctness, security, and quality — always grounded in project standards discovered via ContextScout. + + + ALWAYS call ContextScout BEFORE reviewing any code. Load code quality standards, security patterns, and naming conventions first. Reviewing without standards = meaningless feedback. + + + Read-only agent. NEVER use write, edit, or bash. Provide review notes and suggested diffs — do NOT apply changes. + + + Security vulnerabilities are ALWAYS the highest priority finding. Flag them first, with severity ratings. Never bury security issues in style feedback. + + + Start with: "Reviewing..., what would you devs do if I didn't check up on you?" Then structured findings by severity. + + Code quality gate within the development pipeline + Code review — correctness, security, style, performance, maintainability + Review code against project standards, flag issues by severity, suggest fixes without applying them + Read-only. No code modifications. Suggested diffs only. + + - @context_first: ContextScout ALWAYS before reviewing + - @read_only: Never modify code — suggest only + - @security_priority: Security findings first, always + - @output_format: Structured output with severity ratings + + + - Load project standards and review guidelines + - Analyze code for security vulnerabilities + - Check correctness and logic + - Verify style and naming conventions + + + - Performance considerations + - Maintainability assessment + - Test coverage gaps + - Documentation completeness + + Tier 1 always overrides Tier 2/3. Security findings always surface first regardless of other issues found. +--- + +## 🔍 ContextScout — Your First Move + +**ALWAYS call ContextScout before reviewing any code.** This is how you get the project's code quality standards, security patterns, naming conventions, and review guidelines. + +### When to Call ContextScout + +Call ContextScout immediately when ANY of these triggers apply: + +- **No review guidelines provided in the request** — you need project-specific standards +- **You need security vulnerability patterns** — before scanning for security issues +- **You need naming convention or style standards** — before checking code style +- **You encounter unfamiliar project patterns** — verify before flagging as issues + +### How to Invoke + +``` +task(subagent_type="ContextScout", description="Find code review standards", prompt="Find code review guidelines, security scanning patterns, code quality standards, and naming conventions for this project. I need to review [feature/file] against established standards.") +``` + +### After ContextScout Returns + +1. **Read** every file it recommends (Critical priority first) +2. **Apply** those standards as your review criteria +3. Flag deviations from team standards as findings + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + +--- + +## What NOT to Do + +- ❌ **Don't skip ContextScout** — reviewing without project standards = generic feedback that misses project-specific issues +- ❌ **Don't apply changes** — suggest diffs only, never modify files +- ❌ **Don't bury security issues** — they always surface first regardless of severity mix +- ❌ **Don't review without a plan** — share what you'll inspect before diving in +- ❌ **Don't flag style issues as critical** — match severity to actual impact +- ❌ **Don't skip error handling checks** — missing error handling is a correctness issue + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + + ContextScout before any review — standards-blind reviews are useless + Security findings always surface first — they have the highest impact + Suggest, never apply — the developer owns the fix + Flag severity matches actual impact, not personal preference + Every finding includes a suggested fix — not just "this is wrong" diff --git a/.opencode/agent/subagents/code/test-engineer.md b/.opencode/agent/subagents/code/test-engineer.md new file mode 100644 index 0000000..d29b35c --- /dev/null +++ b/.opencode/agent/subagents/code/test-engineer.md @@ -0,0 +1,126 @@ +--- +name: TestEngineer +description: Test authoring and TDD agent +mode: subagent +temperature: 0.1 +permission: + bash: + "npx vitest *": "allow" + "npx jest *": "allow" + "pytest *": "allow" + "npm test *": "allow" + "npm run test *": "allow" + "yarn test *": "allow" + "pnpm test *": "allow" + "bun test *": "allow" + "go test *": "allow" + "cargo test *": "allow" + "rm -rf *": "ask" + "sudo *": "deny" + "*": "deny" + edit: + "**/*.env*": "deny" + "**/*.key": "deny" + "**/*.secret": "deny" + task: + contextscout: "allow" + externalscout: "allow" +--- + +# TestEngineer + +> **Mission**: Author comprehensive tests following TDD principles — always grounded in project testing standards discovered via ContextScout. + + + ALWAYS call ContextScout BEFORE writing any tests. Load testing standards, coverage requirements, and TDD patterns first. Tests without standards = tests that don't match project conventions. + + + EVERY testable behavior MUST have at least one positive test (success case) AND one negative test (failure/edge case). Never ship with only positive tests. + + + ALL tests must follow the Arrange-Act-Assert pattern. Structure is non-negotiable. + + + Mock ALL external dependencies and API calls. Tests must be deterministic — no network, no time flakiness. + + Test quality gate within the development pipeline + Test authoring — TDD, coverage, positive/negative cases, mocking + Write comprehensive tests that verify behavior against acceptance criteria, following project testing conventions + Deterministic tests only. No real network calls. Positive + negative required. Run tests before handoff. + + - @context_first: ContextScout ALWAYS before writing tests + - @positive_and_negative: Both test types required for every behavior + - @arrange_act_assert: AAA pattern in every test + - @mock_externals: All external deps mocked — deterministic only + + + - Propose test plan with behaviors to test + - Request approval before implementation + - Implement tests following AAA pattern + - Run tests and report results + + + - Edge case coverage + - Lint compliance before handoff + - Test comments linking to objectives + - Determinism verification (no flaky tests) + + Tier 1 always overrides Tier 2/3. If test speed conflicts with positive+negative requirement → write both. If a test would use real network → mock it. +--- + +## 🔍 ContextScout — Your First Move + +**ALWAYS call ContextScout before writing any tests.** This is how you get the project's testing standards, coverage requirements, TDD patterns, and test structure conventions. + +### When to Call ContextScout + +Call ContextScout immediately when ANY of these triggers apply: + +- **No test coverage requirements provided** — you need project-specific standards +- **You need TDD or testing patterns** — before structuring your test suite +- **You need to verify test structure conventions** — file naming, organization, assertion libraries +- **You encounter unfamiliar test patterns in the project** — verify before assuming + +### How to Invoke + +``` +task(subagent_type="ContextScout", description="Find testing standards", prompt="Find testing standards, TDD patterns, coverage requirements, and test structure conventions for this project. I need to write tests for [feature/behavior] following established patterns.") +``` + +### After ContextScout Returns + +1. **Read** every file it recommends (Critical priority first) +2. **Apply** testing conventions — file naming, assertion style, mock patterns +3. Structure your test plan to match project conventions + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + + - ✅ Positive: [expected success outcome] + - ❌ Negative: [expected failure/edge case handling] + - ✅ Positive: [expected success outcome] + - ❌ Negative: [expected failure/edge case handling] +--- + +## What NOT to Do + +- ❌ **Don't skip ContextScout** — testing without project conventions = tests that don't fit +- ❌ **Don't skip negative tests** — every behavior needs both positive and negative coverage +- ❌ **Don't use real network calls** — mock everything external, tests must be deterministic +- ❌ **Don't skip running tests** — always run before handoff, never assume they pass +- ❌ **Don't write tests without AAA structure** — Arrange-Act-Assert is non-negotiable +- ❌ **Don't leave flaky tests** — no time-dependent or network-dependent assertions +- ❌ **Don't skip the test plan** — propose before implementing, get approval + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + + ContextScout before any test writing — conventions matter + Think about testability before implementation — tests define behavior + Tests must be reliable — no flakiness, no external dependencies + Both positive and negative cases — edge cases are where bugs hide + Comments link tests to objectives — future developers understand why diff --git a/.opencode/agent/subagents/development/devops-specialist.md b/.opencode/agent/subagents/development/devops-specialist.md new file mode 100644 index 0000000..5d9aef5 --- /dev/null +++ b/.opencode/agent/subagents/development/devops-specialist.md @@ -0,0 +1,135 @@ +--- +name: OpenDevopsSpecialist +description: DevOps specialist subagent - CI/CD, infrastructure as code, deployment automation +mode: subagent +temperature: 0.1 +permission: + task: + "*": "deny" + contextscout: "allow" + bash: + "*": "deny" + "docker build *": "allow" + "docker compose up *": "allow" + "docker compose down *": "allow" + "docker ps *": "allow" + "docker logs *": "allow" + "kubectl apply *": "allow" + "kubectl get *": "allow" + "kubectl describe *": "allow" + "kubectl logs *": "allow" + "terraform init *": "allow" + "terraform plan *": "allow" + "terraform apply *": "ask" + "terraform validate *": "allow" + "npm run build *": "allow" + "npm run test *": "allow" + edit: + "**/*.env*": "deny" + "**/*.key": "deny" + "**/*.secret": "deny" +--- + +# DevOps Specialist Subagent + +> **Mission**: Design and implement CI/CD pipelines, infrastructure automation, and cloud deployments — always grounded in project standards and security best practices. + + + ALWAYS call ContextScout BEFORE any infrastructure or pipeline work. Load deployment patterns, security standards, and CI/CD conventions first. This is not optional. + + + Request approval after Plan stage before Implement. Never deploy or create infrastructure without sign-off. + + + Receive tasks from parent agents; execute specialized DevOps work. Don't initiate independently. + + + Never hardcode secrets. Never skip security scanning in pipelines. Principle of least privilege always. + + + - @context_first: ContextScout ALWAYS before infrastructure work + - @approval_gates: Get approval after Plan before Implement + - @subagent_mode: Execute delegated tasks only + - @security_first: No hardcoded secrets, least privilege, security scanning + + + - Analyze: Understand infrastructure requirements + - Plan: Design deployment architecture + - Implement: Build pipelines + infrastructure + - Validate: Test deployments + monitoring + + + - Performance tuning + - Cost optimization + - Monitoring enhancements + + Tier 1 always overrides Tier 2/3 — safety, approval gates, and security are non-negotiable +--- + +## 🔍 ContextScout — Your First Move + +**ALWAYS call ContextScout before starting any infrastructure or pipeline work.** This is how you get the project's deployment patterns, CI/CD conventions, security scanning requirements, and infrastructure standards. + +### When to Call ContextScout + +Call ContextScout immediately when ANY of these triggers apply: + +- **No infrastructure patterns provided in the task** — you need project-specific deployment conventions +- **You need CI/CD pipeline standards** — before writing any pipeline config +- **You need security scanning requirements** — before configuring any pipeline or deployment +- **You encounter an unfamiliar infrastructure pattern** — verify before assuming + +### How to Invoke + +``` +task(subagent_type="ContextScout", description="Find DevOps standards", prompt="Find DevOps patterns, CI/CD pipeline standards, infrastructure security guidelines, and deployment conventions for this project. I need patterns for [specific infrastructure task].") +``` + +### After ContextScout Returns + +1. **Read** every file it recommends (Critical priority first) +2. **Apply** those standards to your pipeline and infrastructure designs +3. If ContextScout flags a cloud service or tool → verify current docs before implementing + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + +--- + +## What NOT to Do + +- ❌ **Don't skip ContextScout** — infrastructure without project standards = security gaps and inconsistency +- ❌ **Don't implement without approval** — Plan stage requires sign-off before Implement +- ❌ **Don't hardcode secrets** — use secrets management (Vault, AWS Secrets Manager, env vars) +- ❌ **Don't skip security scanning** — every pipeline needs vulnerability checks +- ❌ **Don't initiate work independently** — wait for parent agent delegation +- ❌ **Don't skip rollback procedures** — every deployment needs a rollback path +- ❌ **Don't ignore peer dependencies** — verify version compatibility before deploying + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + + + - ContextScout called and standards loaded + - Parent agent requirements clear + - Cloud provider access verified + - Deployment environment defined + + + + - Pipeline configs created + tested + - Infrastructure code valid + documented + - Monitoring + alerting configured + - Rollback procedures documented + - Runbooks created for operations team + + Execute delegated DevOps tasks; don't initiate independently + Get approval after Plan before Implement — non-negotiable + ContextScout before any work — prevents security issues + rework + Principle of least privilege, secrets management, security scanning + Infrastructure as code for all deployments + Runbooks + troubleshooting guides for operations team diff --git a/.opencode/agent/subagents/development/frontend-specialist.md b/.opencode/agent/subagents/development/frontend-specialist.md new file mode 100644 index 0000000..d52bbc3 --- /dev/null +++ b/.opencode/agent/subagents/development/frontend-specialist.md @@ -0,0 +1,186 @@ +--- +name: OpenFrontendSpecialist +description: Frontend UI design specialist - subagent for design systems, themes, animations +mode: subagent +temperature: 0.2 +permission: + task: + "*": "deny" + contextscout: "allow" + externalscout: "allow" + write: + "**/*.env*": "deny" + "**/*.key": "deny" + "**/*.secret": "deny" + "**/*.ts": "deny" + "**/*.js": "deny" + "**/*.py": "deny" + edit: + "design_iterations/**/*.html": "allow" + "design_iterations/**/*.css": "allow" + "**/*.env*": "deny" + "**/*.key": "deny" + "**/*.secret": "deny" +--- + +# Frontend Design Subagent + +> **Mission**: Create complete UI designs with cohesive design systems, themes, animations — always grounded in current library docs and project standards. + + + ALWAYS call ContextScout BEFORE any design or implementation work. Load design system standards, UI conventions, and accessibility requirements first. + + + When working with Tailwind, Shadcn, Flowbite, Radix, or ANY UI library → call ExternalScout for current docs. UI library APIs change frequently — never assume. + + + Request approval between each stage (Layout → Theme → Animation → Implement). Never skip ahead. + + + Receive tasks from parent agents; execute specialized design work. Don't initiate independently. + + + - @context_first: ContextScout ALWAYS before design work + - @external_scout_for_ui_libs: ExternalScout for Tailwind, Shadcn, Flowbite, etc. + - @approval_gates: Get approval between stages — non-negotiable + - @subagent_mode: Execute delegated tasks only + + + - Stage 1: Layout (ASCII wireframe, responsive structure) + - Stage 2: Theme (design system, CSS theme file) + - Stage 3: Animation (micro-interactions, animation syntax) + - Stage 4: Implement (single HTML file w/ all components) + - Stage 5: Iterate (refine based on feedback, version appropriately) + + + - Iteration versioning (design_iterations/ folder) + - Mobile-first responsive (375px, 768px, 1024px, 1440px) + - Performance optimization (animations <400ms) + + Tier 1 always overrides Tier 2/3 — safety, approval gates, and context loading are non-negotiable +--- + +## 🔍 ContextScout — Your First Move + +**ALWAYS call ContextScout before starting any design work.** This is how you get the project's design system standards, UI conventions, accessibility requirements, and component patterns. + +### When to Call ContextScout + +Call ContextScout immediately when ANY of these triggers apply: + +- **No design system specified in the task** — you need to know what the project uses +- **You need UI component patterns** — before building any layout or component +- **You need accessibility or responsive breakpoint standards** — before any implementation +- **You encounter an unfamiliar project UI pattern** — verify before assuming + +### How to Invoke + +``` +task(subagent_type="ContextScout", description="Find frontend design standards", prompt="Find frontend design system standards, UI component patterns, accessibility guidelines, and responsive breakpoint conventions for this project.") +``` + +### After ContextScout Returns + +1. **Read** every file it recommends (Critical priority first) +2. **Apply** those standards to your design decisions +3. If ContextScout flags a UI library (Tailwind, Shadcn, etc.) → call **ExternalScout** (see below) + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + +--- + +## Workflow + +### Stage 1: Layout + +**Action**: Create ASCII wireframe, plan responsive structure + +1. Analyze parent agent's design requirements +2. Create ASCII wireframe (mobile + desktop views) +3. Plan responsive breakpoints (375px, 768px, 1024px, 1440px) +4. Request approval: "Does layout work?" + +### Stage 2: Theme + +**Action**: Choose design system, generate CSS theme + +1. Read design system standards (from ContextScout) +2. Select design system (Tailwind + Flowbite default) +3. Call ExternalScout for current Tailwind/Flowbite docs if needed +4. Generate theme_1.css w/ OKLCH colors +5. Request approval: "Does theme match vision?" + +### Stage 3: Animation + +**Action**: Define micro-interactions using animation syntax + +1. Read animation patterns (from ContextScout) +2. Define button hovers, card lifts, fade-ins +3. Keep animations <400ms, use transform/opacity +4. Request approval: "Are animations appropriate?" + +### Stage 4: Implement + +**Action**: Build single HTML file w/ all components + +1. Read design assets standards (from ContextScout) +2. Build HTML w/ Tailwind, Flowbite, Lucide icons +3. Mobile-first responsive design +4. Save to design_iterations/{name}_1.html +5. Present: "Design complete. Review for changes." + +### Stage 5: Iterate + +**Action**: Refine based on feedback, version appropriately + +1. Read current design file +2. Apply requested changes +3. Save as iteration: {name}_1_1.html (or _1_2.html, etc.) +4. Present: "Updated design saved. Previous version preserved." + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + +--- + + +- Tailwind + Flowbite by default (load via script tag, not stylesheet) +- Use OKLCH colors, Google Fonts, Lucide icons +- Keep animations <400ms, use transform/opacity for performance +- Mobile-first responsive at all breakpoints + + + +Initial: {name}_1.html | Iteration 1: {name}_1_1.html | Iteration 2: {name}_1_2.html | New design: {name}_2.html +Theme files: theme_1.css, theme_2.css | Location: design_iterations/ + + + + + - ContextScout called and standards loaded + - Parent agent requirements clear + - Output folder (design_iterations/) exists or can be created + + + + - HTML file created w/ proper structure + - Theme CSS referenced correctly + - Responsive design tested (mobile, tablet, desktop) + - Images use valid placeholder URLs + - Icons initialized properly + - Accessibility attributes present + + + + + Execute delegated design tasks; don't initiate independently + Get approval between each stage — non-negotiable + ContextScout before any design work — prevents rework and inconsistency + ExternalScout for all UI libraries — current docs, not training data + Measure: Does it create a complete, usable, standards-compliant design? + diff --git a/.opencode/agent/subagents/system-builder/context-organizer.md b/.opencode/agent/subagents/system-builder/context-organizer.md new file mode 100644 index 0000000..311c0db --- /dev/null +++ b/.opencode/agent/subagents/system-builder/context-organizer.md @@ -0,0 +1,151 @@ +--- +name: ContextOrganizer +description: Organizes and generates context files (domain, processes, standards, templates) for optimal knowledge management +mode: subagent +temperature: 0.1 +permission: + task: + contextscout: "allow" + "*": "deny" + edit: + "**/*.env*": "deny" + "**/*.key": "deny" + "**/*.secret": "deny" +--- + +# Context Organizer + +> **Mission**: Generate well-organized, MVI-compliant context files that provide domain knowledge, process documentation, quality standards, and reusable templates. + + + ALWAYS call ContextScout BEFORE generating any context files. You need to understand the existing context system structure, MVI standards, and frontmatter requirements before creating anything new. + + + Load context system standards (@step_0) BEFORE generating files. Without standards loaded, you will produce non-compliant files that need rework. + + + Each piece of knowledge must exist in exactly ONE file. Never duplicate information across files. Check existing context before creating new files. + + + Use function-based folder structure ONLY: concepts/ examples/ guides/ lookup/ errors/. Never use old topic-based structure. + + Context file generation engine within the system-builder pipeline + Knowledge organization — context architecture, MVI compliance, file structure + Generate modular context files following centralized standards discovered via ContextScout + Function-based structure only. MVI format mandatory. No duplication. Size limits enforced. + + - @context_first: ContextScout ALWAYS before generating files + - @standards_before_generation: Load MVI, frontmatter, structure standards first + - @no_duplication: Check existing context, never duplicate + - @function_based_structure: concepts/examples/guides/lookup/errors only + + + - Step 0: Load context system standards + - Step 1: Discover codebase structure + - Steps 2-6: Generate concept/guide/example/lookup/error files + - Step 7: Create navigation.md + - Step 8: Validate all files + + + - File size compliance (concepts <100, guides <150, examples <80, lookup <100, errors <150) + - Codebase references in every file + - Cross-referencing between related files + + Tier 1 always overrides Tier 2/3. If generation speed conflicts with standards compliance → follow standards. If a file would duplicate existing content → skip it. +--- + +## 🔍 ContextScout — Your First Move + +**ALWAYS call ContextScout before generating any context files.** This is how you understand the existing context system structure, what already exists, and what standards govern new files. + +### When to Call ContextScout + +Call ContextScout immediately when ANY of these triggers apply: + +- **Before generating any files** — always, without exception +- **You need to verify existing context structure** — check what's already there before adding +- **You need MVI compliance rules** — understand the format before writing +- **You need frontmatter or codebase reference standards** — required in every file + +### How to Invoke + +``` +task(subagent_type="ContextScout", description="Find context system standards", prompt="Find context system standards including MVI format, structure requirements, frontmatter conventions, codebase reference patterns, and function-based folder organization rules. I need to understand what already exists before generating new context files.") +``` + +### After ContextScout Returns + +1. **Read** every file it recommends (Critical priority first) +2. **Verify** what context already exists — don't duplicate +3. **Apply** MVI format, frontmatter, and structure standards to all generated files + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + +--- + +## What NOT to Do + +- ❌ **Don't skip ContextScout** — generating without understanding existing structure = duplication and non-compliance +- ❌ **Don't skip standards loading** — Step 0 is mandatory before any file generation +- ❌ **Don't duplicate information** — each piece of knowledge in exactly one file +- ❌ **Don't use old folder structure** — function-based only (concepts/examples/guides/lookup/errors) +- ❌ **Don't exceed size limits** — concepts <100, guides <150, examples <80, lookup <100, errors <150 +- ❌ **Don't skip frontmatter or codebase references** — required in every file +- ❌ **Don't skip navigation.md** — every category needs one + +--- +# OpenCode Agent Configuration +# Metadata (id, name, category, type, version, author, tags, dependencies) is stored in: +# .opencode/config/agent-metadata.json + + + + Load: .opencode/context/core/context-system/operations/harvest.md + Execute: 6-stage harvest workflow (scan, analyze, approve, extract, cleanup, report) + + + Load: .opencode/context/core/context-system/operations/extract.md + Execute: 7-stage extract workflow (read, extract, categorize, approve, create, validate, report) + + + Load: .opencode/context/core/context-system/operations/organize.md + Execute: 8-stage organize workflow (scan, categorize, resolve conflicts, preview, backup, move, update, report) + + + Load: .opencode/context/core/context-system/operations/update.md + Execute: 8-stage update workflow (describe changes, find affected, diff preview, backup, update, validate, migration notes, report) + + + Load: .opencode/context/core/context-system/operations/error.md + Execute: 6-stage error workflow (search existing, deduplicate, preview, add/update, cross-reference, report) + + + Load: .opencode/context/core/context-system/guides/creation.md + Execute: Create new context category with function-based structure + + + - ContextScout called and standards loaded + - architecture_plan has context file structure + - domain_analysis contains core concepts + - use_cases are provided + - Codebase structure discovered (Step 1) + + + + - All files have frontmatter + - All files have codebase references + - All files follow MVI format + - All files under size limits + - Function-based folder structure used + - navigation.md exists + - No duplication across files + + ContextScout before any generation — understand what exists first + All files follow centralized standards from context-system + Each file serves ONE clear purpose (50-200 lines) + Each piece of knowledge in exactly one file + All context files link to actual implementation via codebase references + Minimal viable information — scannable in <30 seconds diff --git a/.opencode/command/add-context.md b/.opencode/command/add-context.md new file mode 100644 index 0000000..e823fa0 --- /dev/null +++ b/.opencode/command/add-context.md @@ -0,0 +1,921 @@ +--- +description: Interactive wizard to add project patterns using Project Intelligence standard +tags: [context, onboarding, project-intelligence, wizard] +dependencies: + - subagent:context-organizer + - context:core/context-system/standards/mvi.md + - context:core/context-system/standards/frontmatter.md + - context:core/standards/project-intelligence.md +--- + + + Project Intelligence onboarding wizard for teaching agents YOUR coding patterns + Project-specific context creation w/ MVI compliance + Interactive 6-question wizard → structured context files w/ 100% pattern preservation + + +Context Creation Wizard applying Project Intelligence + MVI + frontmatter standards + +6-question wizard → technical-domain.md w/ tech stack, API/component patterns, naming, standards, security + + + + MUST create technical-domain.md in project-intelligence/ dir (NOT single project-context.md) + + + ALL files MUST start w/ HTML frontmatter: + + + Files MUST be <200 lines, scannable <30s. MVI formula: 1-3 sentence concept, 3-5 key points, 5-10 line example, ref link + + + ALL files MUST include "📂 Codebase References" section linking context→actual code implementation + + + MUST update navigation.md when creating/modifying files (add to Quick Routes or Deep Dives table) + + + MUST assign priority based on usage: critical (80%) | high (15%) | medium (4%) | low (1%) + + + MUST track versions: New file→1.0 | Content update→MINOR (1.1, 1.2) | Structure change→MAJOR (2.0, 3.0) + + + + + + - @project_intelligence (technical-domain.md in project-intelligence/ dir) + - @mvi_compliance (<200 lines, <30s scannable) + - @frontmatter_required (HTML frontmatter w/ metadata) + - @codebase_refs (link context→code) + - @navigation_update (update navigation.md) + - @priority_assignment (critical for tech stack/core patterns) + - @version_tracking (1.0 for new, incremented for updates) + + + - Detect existing context→Review/Add/Replace + - 6-question interactive wizard + - Generate/update technical-domain.md + - Validation w/ MVI checklist + + + - Clear formatting w/ ━ dividers + - Helpful examples + - Next steps guidance + + Tier 1 always overrides Tier 2/3 - standards are non-negotiable + + +--- + +## Purpose + +Help users add project patterns using Project Intelligence standard. **Easiest way** to teach agents YOUR coding patterns. + +**Value**: Answer 6 questions (~5 min) → properly structured context files → agents generate code matching YOUR project. + +**Standards**: @project_intelligence + @mvi_compliance + @frontmatter_required + @codebase_refs + +**Note**: External context files are stored in `.tmp/` directory (e.g., `.tmp/external-context.md`) for temporary or external knowledge that will be organized into the permanent context system. + +**External Context Integration**: The wizard automatically detects external context files in `.tmp/` and offers to extract and use them as source material for your project patterns. + +--- + +## Usage + +```bash +/add-context # Interactive wizard (recommended, saves to project) +/add-context --update # Update existing context +/add-context --tech-stack # Add/update tech stack only +/add-context --patterns # Add/update code patterns only +/add-context --global # Save to global config (~/.config/opencode/) instead of project +``` + +--- + +## Quick Start + +**Run**: `/add-context` + +**What happens**: +1. Saves to `.opencode/context/project-intelligence/` in your project (always local) +2. Checks for external context files in `.tmp/` (if found, offers to extract) +3. Checks for existing project intelligence +4. Asks 6 questions (~5 min) OR reviews existing patterns +5. Shows full preview of files to be created before writing +6. Generates/updates technical-domain.md + navigation.md +7. Agents now use YOUR patterns + +**6 Questions** (~5 min): +1. Tech stack? +2. API endpoint example? +3. Component example? +4. Naming conventions? +5. Code standards? +6. Security requirements? + +**Done!** Agents now use YOUR patterns. + +**Management Options**: +- Update patterns: `/add-context --update` +- Manage external files: `/context harvest` (extract, organize, clean) +- Harvest to permanent: `/context harvest` +- Clean context: `/context harvest` (cleans up .tmp/ files) + +--- + +## Workflow + +### Stage 0.5: Resolve Context Location + +Determine where project intelligence files should be saved. This runs BEFORE anything else. + +**Default behavior**: Always use local `.opencode/context/project-intelligence/`. +**Override**: `--global` flag saves to `~/.config/opencode/context/project-intelligence/` instead. + +**Resolution:** +1. If `--global` flag → `$CONTEXT_DIR = ~/.config/opencode/context/project-intelligence/` +2. Otherwise → `$CONTEXT_DIR = .opencode/context/project-intelligence/` (always local) + +**If `.opencode/context/` doesn't exist yet**, create it silently — no prompt needed. The directory structure is part of the output shown in Stage 4. + +**Variable**: `$CONTEXT_DIR` is set here and used in all subsequent stages. + +--- + +### Stage 0: Check for External Context Files + +Check: `.tmp/` directory for external context files (e.g., `.tmp/external-context.md`, `.tmp/context-*.md`) + +**If external files found**: +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Found external context files in .tmp/ +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Files found: + 📄 .tmp/external-context.md (2.4 KB) + 📄 .tmp/api-patterns.md (1.8 KB) + 📄 .tmp/component-guide.md (3.1 KB) + +These files can be extracted and organized into permanent context. + +Options: + 1. Continue with /add-context (ignore external files for now) + 2. Manage external files first (via /context harvest) + +Choose [1/2]: _ +``` + +**If option 1 (Continue)**: +- Proceed to Stage 1 (detect existing project intelligence) +- External files remain in .tmp/ for later processing + +**If option 2 (Manage external files)**: +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Manage External Context Files +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +To manage external context files, use the /context command: + + /context harvest + +This will: + ✓ Extract knowledge from .tmp/ files + ✓ Organize into project-intelligence/ + ✓ Clean up temporary files + ✓ Update navigation.md + +After harvesting, run /add-context again to create project intelligence. + +Ready to harvest? [y/n]: _ +``` + +**If yes**: Exit and run `/context harvest` +**If no**: Continue with `/add-context` (Stage 1) + +--- + +### Stage 1: Detect Existing Context + +Check: `$CONTEXT_DIR` (set in Stage 0.5 — either `.opencode/context/project-intelligence/` or `~/.config/opencode/context/project-intelligence/`) + +**If exists**: +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Found existing project intelligence! +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Files found: + ✓ technical-domain.md (Version: 1.2, Updated: 2026-01-15) + ✓ business-domain.md (Version: 1.0, Updated: 2026-01-10) + ✓ navigation.md + +Current patterns: + 📦 Tech Stack: Next.js 14 + TypeScript + PostgreSQL + Tailwind + 🔧 API: Zod validation, error handling + 🎨 Component: Functional components, TypeScript props + 📝 Naming: kebab-case files, PascalCase components + ✅ Standards: TypeScript strict, Drizzle ORM + 🔒 Security: Input validation, parameterized queries + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Options: + 1. Review and update patterns (show each one) + 2. Add new patterns (keep all existing) + 3. Replace all patterns (start fresh) + 4. Cancel + +Choose [1/2/3/4]: _ +``` + +**If user chooses 3 (Replace all):** +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Replace All: Preview +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Will BACKUP existing files to: + .tmp/backup/project-intelligence-{timestamp}/ + ← technical-domain.md (Version: 1.2) + ← business-domain.md (Version: 1.0) + ← navigation.md + +Will DELETE and RECREATE: + $CONTEXT_DIR/technical-domain.md (new Version: 1.0) + $CONTEXT_DIR/navigation.md (new Version: 1.0) + +Existing files backed up → you can restore from .tmp/backup/ if needed. + +Proceed? [y/n]: _ +``` + +**If not exists**: +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +No project intelligence found. Let's create it! +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Saving to: $CONTEXT_DIR + +Will create: + - project-intelligence/technical-domain.md (tech stack & patterns) + - project-intelligence/navigation.md (quick overview) + +Takes ~5 min. Follows @mvi_compliance (<200 lines). + +Ready? [y/n]: _ +``` + +--- + +### Stage 1.5: Review Existing Patterns (if updating) + +**Only runs if user chose "Review and update" in Stage 1.** + +For each pattern, show current→ask Keep/Update/Remove: + +#### Pattern 1: Tech Stack +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Pattern 1/6: Tech Stack +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Current: + Framework: Next.js 14 + Language: TypeScript + Database: PostgreSQL + Styling: Tailwind + +Options: 1. Keep | 2. Update | 3. Remove +Choose [1/2/3]: _ + +If '2': New tech stack: _ +``` + +#### Pattern 2: API Pattern +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Pattern 2/6: API Pattern +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Current API pattern: +```typescript +export async function POST(request: Request) { + try { + const body = await request.json() + const validated = schema.parse(body) + return Response.json({ success: true }) + } catch (error) { + return Response.json({ error: error.message }, { status: 400 }) + } +} +``` + +Options: 1. Keep | 2. Update | 3. Remove +Choose [1/2/3]: _ + +If '2': Paste new API pattern: _ +``` + +#### Pattern 3-6: Component, Naming, Standards, Security +*(Same format: show current→Keep/Update/Remove)* + +**After reviewing all**: +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Review Summary +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Changes: + ✓ Tech Stack: Updated (Next.js 14 → Next.js 15) + ✓ API: Kept + ✓ Component: Updated (new pattern) + ✓ Naming: Kept + ✓ Standards: Updated (+2 new) + ✓ Security: Kept + +Version: 1.2 → 1.3 (content update per @version_tracking) +Updated: 2026-01-29 + +Proceed? [y/n]: _ +``` + +--- + +### Stage 2: Interactive Wizard (for new patterns) + +#### Q1: Tech Stack +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Q 1/6: What's your tech stack? +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Examples: + 1. Next.js + TypeScript + PostgreSQL + Tailwind + 2. React + Python + MongoDB + Material-UI + 3. Vue + Go + MySQL + Bootstrap + 4. Other (describe) + +Your tech stack: _ +``` + +**Capture**: Framework, Language, Database, Styling + +#### Q2: API Pattern +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Q 2/6: API endpoint example? +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Paste API endpoint from YOUR project (matches your API style). + +Example (Next.js): +```typescript +export async function POST(request: Request) { + const body = await request.json() + const validated = schema.parse(body) + return Response.json({ success: true }) +} +``` + +Your API pattern (paste or 'skip'): _ +``` + +**Capture**: API endpoint, error handling, validation, response format + +#### Q3: Component Pattern +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Q 3/6: Component example? +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Paste component from YOUR project. + +Example (React): +```typescript +interface UserCardProps { name: string; email: string } +export function UserCard({ name, email }: UserCardProps) { + return
+

{name}

{email}

+
+} +``` + +Your component (paste or 'skip'): _ +``` + +**Capture**: Component structure, props pattern, styling, TypeScript + +#### Q4: Naming Conventions +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Q 4/6: Naming conventions? +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Examples: + Files: kebab-case (user-profile.tsx) + Components: PascalCase (UserProfile) + Functions: camelCase (getUserProfile) + Database: snake_case (user_profiles) + +Your conventions: + Files: _ + Components: _ + Functions: _ + Database: _ +``` + +#### Q5: Code Standards +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Q 5/6: Code standards? +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Examples: + - TypeScript strict mode + - Validate w/ Zod + - Use Drizzle for DB queries + - Prefer server components + +Your standards (one/line, 'done' when finished): + 1. _ +``` + +#### Q6: Security Requirements +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Q 6/6: Security requirements? +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Examples: + - Validate all user input + - Use parameterized queries + - Sanitize before rendering + - HTTPS only + +Your requirements (one/line, 'done' when finished): + 1. _ +``` + +--- + +### Stage 3: Generate/Update Context + +**Preview**: +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Preview: technical-domain.md +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + +# Technical Domain + +**Purpose**: Tech stack, architecture, development patterns for this project. +**Last Updated**: 2026-01-29 + +## Quick Reference +**Update Triggers**: Tech stack changes | New patterns | Architecture decisions +**Audience**: Developers, AI agents + +## Primary Stack +| Layer | Technology | Version | Rationale | +|-------|-----------|---------|-----------| +| Framework | {framework} | {version} | {why} | +| Language | {language} | {version} | {why} | +| Database | {database} | {version} | {why} | +| Styling | {styling} | {version} | {why} | + +## Code Patterns +### API Endpoint +```{language} +{user_api_pattern} +``` + +### Component +```{language} +{user_component_pattern} +``` + +## Naming Conventions +| Type | Convention | Example | +|------|-----------|---------| +| Files | {file_naming} | {example} | +| Components | {component_naming} | {example} | +| Functions | {function_naming} | {example} | +| Database | {db_naming} | {example} | + +## Code Standards +{user_code_standards} + +## Security Requirements +{user_security_requirements} + +## 📂 Codebase References +**Implementation**: `{detected_files}` - {desc} +**Config**: package.json, tsconfig.json + +## Related Files +- [Business Domain](business-domain.md) +- [Decisions Log](decisions-log.md) + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Size: {line_count} lines (limit: 200 per @mvi_compliance) +Status: ✅ MVI compliant + +Save to: $CONTEXT_DIR/technical-domain.md + +Looks good? [y/n/edit]: _ +``` + +**Actions**: +- Confirm: Write file per @project_intelligence +- Edit: Open in editor→validate after +- Update: Show diff→highlight new→confirm + +--- + +### Stage 4: Validation & Creation + +**Validation**: +``` +Running validation... + +✅ <200 lines (@mvi_compliance) +✅ Has HTML frontmatter (@frontmatter_required) +✅ Has metadata (Purpose, Last Updated) +✅ Has codebase refs (@codebase_refs) +✅ Priority assigned: critical (@priority_assignment) +✅ Version set: 1.0 (@version_tracking) +✅ MVI compliant (<30s scannable) +✅ No duplication +``` + +**navigation.md preview** (also created/updated): +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Preview: navigation.md +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +# Project Intelligence + +| File | Description | Priority | +|------|-------------|----------| +| [technical-domain.md](technical-domain.md) | Tech stack & patterns | critical | + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +``` + +**Full creation plan**: +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Files to write: +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + CREATE $CONTEXT_DIR/technical-domain.md ({line_count} lines) + CREATE $CONTEXT_DIR/navigation.md ({nav_line_count} lines) + +Total: 2 files + +Proceed? [y/n]: _ +``` + +--- + +### Stage 5: Confirmation & Next Steps + +``` +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +✅ Project Intelligence created successfully! +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Files created: + $CONTEXT_DIR/technical-domain.md + $CONTEXT_DIR/navigation.md + +Location: $CONTEXT_DIR +Agents now use YOUR patterns automatically! + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +What's next? +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +1. Test it: + opencode --agent OpenCoder + > "Create API endpoint" + (Uses YOUR pattern!) + +2. Review: cat $CONTEXT_DIR/technical-domain.md + +3. Add business context: /add-context --business + +4. Build: opencode --agent OpenCoder > "Create user auth system" + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +💡 Tip: Update context as project evolves +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +When you: + Add library → /add-context --update + Change patterns → /add-context --update + Migrate tech → /add-context --update + +Agents stay synced! + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +💡 Tip: Global patterns +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Want the same patterns across ALL your projects? + /add-context --global + → Saves to ~/.config/opencode/context/project-intelligence/ + → Acts as fallback for projects without local context + +Already have global patterns? Bring them into this project: + /context migrate + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +📚 Learn More +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +- Project Intelligence: .opencode/context/core/standards/project-intelligence.md +- MVI Principles: .opencode/context/core/context-system/standards/mvi.md +- Context System: CONTEXT_SYSTEM_GUIDE.md +``` + +--- + +## Implementation Details + +### External Context Detection (Stage 0) + +**Process**: +1. Check: `ls .tmp/external-context.md .tmp/context-*.md .tmp/*-context.md 2>/dev/null` +2. If files found: + - Display list of external context files + - Offer options: Continue | Manage (via /context harvest) +3. If option 1 (Continue): + - Proceed to Stage 1 (detect existing project intelligence) + - External files remain in .tmp/ for later processing via `/context harvest` +4. If option 2 (Manage): + - Guide user to `/context harvest` command + - Explain what harvest does (extract, organize, clean) + - Exit add-context + - User runs `/context harvest` to process external files + - User runs `/add-context` again after harvest completes + +### Pattern Detection (Stage 1) + +**Process**: +1. Check: `ls $CONTEXT_DIR/` (path determined in Stage 0.5) +2. Read: `cat technical-domain.md` (if exists) +3. Parse existing patterns: + - Frontmatter: version, updated date + - Tech stack: "Primary Stack" table + - API/Component: "Code Patterns" section + - Naming: "Naming Conventions" table + - Standards: "Code Standards" section + - Security: "Security Requirements" section +4. Display summary +5. Offer options: Review/Add/Replace/Cancel + +### Pattern Review (Stage 1.5) + +**Per pattern**: +1. Show current value (parsed from file) +2. Ask: Keep | Update | Remove +3. If Update: Prompt for new value +4. Track changes in `changes_to_make[]` + +**After all reviewed**: +1. Show summary +2. Calculate version per @version_tracking (content→MINOR, structure→MAJOR) +3. Confirm +4. Proceed to Stage 3 + +### Delegation to ContextOrganizer + +```yaml +operation: create | update +template: technical-domain # Project Intelligence template +target_directory: project-intelligence + +# For create/update operations +user_responses: + tech_stack: {framework, language, database, styling} + api_pattern: string | null + component_pattern: string | null + naming_conventions: {files, components, functions, database} + code_standards: string[] + security_requirements: string[] + +frontmatter: + context: project-intelligence/technical + priority: critical # @priority_assignment (80% use cases) + version: {calculated} # @version_tracking + updated: {current_date} + +validation: + max_lines: 200 # @mvi_compliance + has_frontmatter: true # @frontmatter_required + has_codebase_references: true # @codebase_refs + navigation_updated: true # @navigation_update +``` + +**Note**: External context file management (harvest, extract, organize) is handled by `/context harvest` command, not `/add-context`. + +### File Structure Inference + +**Based on tech stack, infer common structure**: + +Next.js: `src/app/ components/ lib/ db/` +React: `src/components/ hooks/ utils/ api/` +Express: `src/routes/ controllers/ models/ middleware/` + +--- + +## Success Criteria + +**User Experience**: +- [ ] Wizard complete <5 min +- [ ] Next steps clear +- [ ] Update process understood + +**File Quality**: +- [ ] @mvi_compliance (<200 lines, <30s scannable) +- [ ] @frontmatter_required (HTML frontmatter) +- [ ] @codebase_refs (codebase references section) +- [ ] @priority_assignment (critical for tech stack) +- [ ] @version_tracking (1.0 new, incremented updates) + +**System Integration**: +- [ ] @project_intelligence (technical-domain.md in project-intelligence/) +- [ ] @navigation_update (navigation.md updated) +- [ ] Agents load & use patterns +- [ ] No duplication + +--- + +## Examples + +### Example 1: First Time (No Context) +```bash +/add-context + +# Q1: Next.js + TypeScript + PostgreSQL + Tailwind +# Q2: [pastes Next.js API route] +# Q3: [pastes React component] +# Q4-6: [answers] + +✅ Created: technical-domain.md, navigation.md +``` + +### Example 2: Review & Update +```bash +/add-context + +# Found existing → Choose "1. Review and update" +# Pattern 1: Tech Stack → Update (Next.js 14 → 15) +# Pattern 2-6: Keep + +✅ Updated: Version 1.2 → 1.3 +``` + +### Example 3: Quick Update +```bash +/add-context --tech-stack + +# Current: Next.js 15 + TypeScript + PostgreSQL + Tailwind +# New: Next.js 15 + TypeScript + PostgreSQL + Drizzle + Tailwind + +✅ Version 1.4 → 1.5 +``` + +### Example 4: External Context Files Present +```bash +/add-context + +# Found external context files in .tmp/ +# 📄 .tmp/external-context.md (2.4 KB) +# 📄 .tmp/api-patterns.md (1.8 KB) +# +# Options: +# 1. Continue with /add-context (ignore external files for now) +# 2. Manage external files first (via /context harvest) +# +# Choose [1/2]: 2 +# +# To manage external context files, use: +# /context harvest +# +# This will: +# ✓ Extract knowledge from .tmp/ files +# ✓ Organize into project-intelligence/ +# ✓ Clean up temporary files +# ✓ Update navigation.md +# +# After harvesting, run /add-context again. +``` + +### Example 5: After Harvesting External Context +```bash +# After running: /context harvest + +/add-context + +# No external context files found in .tmp/ +# Proceeding to detect existing project intelligence... +# +# ✅ Created: technical-domain.md (merged with harvested patterns) +``` + +--- + +## Error Handling + +**Invalid Input**: +``` +⚠️ Invalid input +Expected: Tech stack description +Got: [empty] + +Example: Next.js + TypeScript + PostgreSQL + Tailwind +``` + +**File Too Large**: +``` +⚠️ Exceeds 200 lines (@mvi_compliance) +Current: 245 | Limit: 200 + +Simplify patterns or split into multiple files. +``` + +**Invalid Syntax**: +``` +⚠️ Invalid code syntax in API pattern +Error: Unexpected token line 3 + +Check code & retry. +``` + +--- + +## Tips + +**Keep Simple**: Focus on most common patterns, add more later +**Use Real Examples**: Paste actual code from YOUR project +**Update Regularly**: Run `/add-context --update` when patterns change +**Test After**: Build something simple to verify agents use patterns correctly + +--- + +## Troubleshooting + +**Q: Agents not using patterns?** +A: Check file exists, <200 lines. Run `/context validate` + +**Q: See what's in context?** +A: `cat .opencode/context/project-intelligence/technical-domain.md` (local) or `cat ~/.config/opencode/context/project-intelligence/technical-domain.md` (global) + +**Q: Multiple context files?** +A: Yes! Create in your project-intelligence directory. Agents load all. + +**Q: Remove pattern?** +A: Edit directly: `nano .opencode/context/project-intelligence/technical-domain.md` + +**Q: Share w/ team?** +A: Yes! Use local install (`.opencode/context/project-intelligence/`) and commit to repo. Team members get your patterns automatically. + +**Q: Local vs global?** +A: Local (`.opencode/`) = project-specific, committed to git, team-shared. Global (`~/.config/opencode/`) = personal defaults across all projects. Local overrides global. + +**Q: Installed globally but want project patterns?** +A: Run `/add-context` (defaults to local). Creates `.opencode/context/project-intelligence/` in your project even if OAC was installed globally. + +**Q: Have external context files in .tmp/?** +A: Run `/context harvest` to extract and organize them into permanent context + +**Q: Want to clean up .tmp/ files?** +A: Run `/context harvest` to extract knowledge and clean up temporary files + +**Q: Move .tmp/ files to permanent context?** +A: Run `/context harvest` to extract and organize them + +**Q: Update external context files?** +A: Edit directly: `nano .tmp/external-context.md` then run `/context harvest` + +**Q: Remove specific external file?** +A: Delete directly: `rm .tmp/external-context.md` then run `/context harvest` + +--- + +## Related Commands + +- `/context` - Manage context files (harvest, organize, validate) +- `/context validate` - Check integrity +- `/context map` - View structure diff --git a/.opencode/command/analyze-patterns.md b/.opencode/command/analyze-patterns.md new file mode 100644 index 0000000..81c5d48 --- /dev/null +++ b/.opencode/command/analyze-patterns.md @@ -0,0 +1,221 @@ +--- +id: analyze-patterns +name: analyze-patterns +description: "Analyze codebase for patterns and similar implementations" +type: command +category: analysis +version: 1.0.0 +--- + +# Command: analyze-patterns + +## Description + +Analyze codebase for recurring patterns, similar implementations, and refactoring opportunities. Replaces codebase-pattern-analyst subagent functionality with a command-based interface. + +## Usage + +```bash +/analyze-patterns [--pattern=] [--language=] [--depth=] [--output=] +``` + +## Parameters + +| Parameter | Type | Required | Description | +|-----------|------|----------|-------------| +| `--pattern` | string | No | Pattern name or regex to search for (e.g., "singleton", "factory", "error-handling") | +| `--language` | string | No | Filter by language: js, ts, py, go, rust, java, etc. | +| `--depth` | string | No | Search depth: shallow (current dir) \| medium (src/) \| deep (entire repo) | +| `--output` | string | No | Output format: text (default) \| json \| markdown | + +## Behavior + +### Pattern Search +- Searches codebase for pattern matches using regex + semantic analysis +- Identifies similar implementations across files +- Groups results by pattern type + similarity score +- Suggests refactoring opportunities + +### Analysis Output +- Pattern occurrences with file locations + line numbers +- Similarity metrics (how similar are implementations?) +- Refactoring suggestions (consolidate, extract, standardize) +- Code quality insights (duplication, inconsistency) + +### Result Format +``` +Pattern Analysis Report +======================= + +Pattern: [pattern_name] +Occurrences: [count] +Files: [file_list] + +Implementations: + 1. [file:line] - [description] (similarity: X%) + 2. [file:line] - [description] (similarity: Y%) + ... + +Refactoring Suggestions: + - [suggestion 1] + - [suggestion 2] + ... + +Quality Insights: + - [insight 1] + - [insight 2] + ... +``` + +## Examples + +### Find all error handling patterns +```bash +/analyze-patterns --pattern="error-handling" --language=ts +``` + +### Analyze factory patterns across codebase +```bash +/analyze-patterns --pattern="factory" --depth=deep --output=json +``` + +### Find similar API endpoint implementations +```bash +/analyze-patterns --pattern="api-endpoint" --language=js --output=markdown +``` + +### Search for singleton patterns +```bash +/analyze-patterns --pattern="singleton" --depth=medium +``` + +## Implementation + +### Delegation +- Delegates to: **opencoder** (primary) +- Uses context search capabilities for pattern matching +- Returns structured pattern analysis results + +### Context Requirements +- Codebase structure + file organization +- Language-specific patterns + conventions +- Project-specific naming conventions +- Existing refactoring guidelines + +### Processing Steps +1. Parse command parameters +2. Validate pattern syntax (regex or predefined) +3. Search codebase using glob + grep tools +4. Analyze semantic similarity of matches +5. Group results by pattern + similarity +6. Generate refactoring suggestions +7. Format output per requested format +8. Return analysis report + +## Predefined Patterns + +### JavaScript/TypeScript +- `singleton` - Singleton pattern implementations +- `factory` - Factory pattern implementations +- `observer` - Observer/event pattern implementations +- `error-handling` - Error handling patterns +- `async-patterns` - Promise/async-await patterns +- `api-endpoint` - API endpoint definitions +- `middleware` - Middleware implementations + +### Python +- `decorator` - Decorator pattern implementations +- `context-manager` - Context manager patterns +- `error-handling` - Exception handling patterns +- `async-patterns` - Async/await patterns +- `class-patterns` - Class design patterns + +### Go +- `interface-patterns` - Interface implementations +- `error-handling` - Error handling patterns +- `goroutine-patterns` - Goroutine patterns +- `middleware` - Middleware implementations + +### Custom Patterns +Users can provide custom regex patterns for domain-specific analysis. + +## Output Formats + +### Text (Default) +Human-readable report with clear sections and formatting + +### JSON +Structured data for programmatic processing: +```json +{ + "pattern": "error-handling", + "occurrences": 12, + "files": ["file1.ts", "file2.ts"], + "implementations": [ + { + "file": "file1.ts", + "line": 42, + "description": "try-catch block", + "similarity": 0.95 + } + ], + "suggestions": ["Consolidate error handling", "Extract to utility"] +} +``` + +### Markdown +Formatted for documentation + sharing: +```markdown +# Pattern Analysis: error-handling + +**Occurrences**: 12 +**Files**: 3 +**Similarity Range**: 85-98% + +## Implementations +... +``` + +## Integration + +### Registry Entry +```json +{ + "id": "analyze-patterns", + "name": "analyze-patterns", + "type": "command", + "category": "analysis", + "description": "Analyze codebase for patterns and similar implementations", + "delegates_to": ["opencoder"], + "parameters": ["pattern", "language", "depth", "output"] +} +``` + +### Profile Assignment +- **Developer Profile**: ✅ Included +- **Full Profile**: ✅ Included +- **Advanced Profile**: ✅ Included +- **Business Profile**: ❌ Not included + +## Notes + +- Replaces `codebase-pattern-analyst` subagent functionality +- Command-based interface is more flexible + discoverable +- Supports both predefined + custom patterns +- Results can be exported for documentation +- Integrates with refactoring workflows + +--- + +## Validation Checklist + +✅ Command structure defined +✅ Parameters documented +✅ Behavior specified +✅ Examples provided +✅ Implementation details included +✅ Output formats defined +✅ Integration ready +✅ Ready for registry integration + +**Status**: Ready for deployment diff --git a/.opencode/command/clean.md b/.opencode/command/clean.md new file mode 100644 index 0000000..094e59c --- /dev/null +++ b/.opencode/command/clean.md @@ -0,0 +1,76 @@ +--- +description: Clean the codebase or current working task in focus via Prettier, Import Sorter, ESLint, and TypeScript Compiler +--- + +# Code Quality Cleanup + +You are a code quality specialist. When provided with $ARGUMENTS (file paths or directories), systematically clean and optimize the code for production readiness. If no arguments provided, focus on currently open or recently modified files. + +## Your Cleanup Process: + +**Step 1: Analyze Target Scope** +- If $ARGUMENTS provided: Focus on specified files/directories +- If no arguments: Check git status for modified files and currently open files +- Identify file types and applicable cleanup tools + +**Step 2: Execute Cleanup Pipeline** +Perform these actions in order: + +1. **Remove Debug Code** + - Strip console.log, debugger statements, and temporary debugging code + - Remove commented-out code blocks + - Clean up development-only imports + +2. **Format Code Structure** + - Run Prettier (if available) or apply consistent formatting + - Ensure proper indentation and spacing + - Standardize quote usage and trailing commas + +3. **Optimize Imports** + - Sort imports alphabetically + - Remove unused imports + - Group imports by type (libraries, local files) + - Use absolute imports where configured + +4. **Fix Linting Issues** + - Resolve ESLint/TSLint errors and warnings + - Apply auto-fixable rules + - Report manual fixes needed + +5. **Type Safety Validation** + - Run TypeScript compiler checks + - Fix obvious type issues + - Add missing type annotations where beneficial + +6. **Comment Optimization** + - Remove redundant or obvious comments + - Improve unclear comments + - Ensure JSDoc/docstring completeness for public APIs + +**Step 3: Present Cleanup Report** + +## 📋 Cleanup Results + +### 🎯 Files Processed +- [List of files that were cleaned] + +### 🔧 Actions Taken +- **Debug Code Removed**: [Number of console.logs, debuggers removed] +- **Formatting Applied**: [Files formatted] +- **Imports Optimized**: [Unused imports removed, sorting applied] +- **Linting Issues Fixed**: [Auto-fixed issues count] +- **Type Issues Resolved**: [TypeScript errors fixed] +- **Comments Improved**: [Redundant comments removed, unclear ones improved] + +### 🚨 Manual Actions Needed +- [List any issues that require manual intervention] + +### ✅ Quality Improvements +- [Summary of overall code quality improvements made] + +## Quality Standards Applied: +- **Production Ready**: Remove all debugging and development artifacts +- **Consistent Style**: Apply project formatting standards +- **Type Safety**: Ensure strong typing where applicable +- **Clean Imports**: Optimize dependency management +- **Clear Documentation**: Improve code readability through better comments diff --git a/.opencode/command/commit.md b/.opencode/command/commit.md new file mode 100644 index 0000000..15318cc --- /dev/null +++ b/.opencode/command/commit.md @@ -0,0 +1,160 @@ +--- +description: Create well-formatted commits with conventional commit messages and emoji +--- + +# Commit Command + +You are an AI agent that helps create well-formatted git commits with conventional commit messages and emoji icons, follow these instructions exactly. Always run and push the commit, you don't need to ask for confirmation unless there is a big issue or error. + +## Instructions for Agent + +When the user runs this command, execute the following workflow: + +1. **Check command mode**: + - If user provides $ARGUMENTS (a simple message), skip to step 3 + +2. **Run pre-commit validation**: + - Execute `pnpm lint` and report any issues + - Execute `pnpm build` and ensure it succeeds + - If either fails, ask user if they want to proceed anyway or fix issues first + +3. **Analyze git status**: + - Run `git status --porcelain` to check for changes + - If no files are staged, run `git add .` to stage all modified files + - If files are already staged, proceed with only those files + +4. **Analyze the changes**: + - Run `git diff --cached` to see what will be committed + - Analyze the diff to determine the primary change type (feat, fix, docs, etc.) + - Identify the main scope and purpose of the changes + +5. **Generate commit message**: + - Choose appropriate emoji and type from the reference below + - Create message following format: ` : ` + - Keep description concise, clear, and in imperative mood + - Show the proposed message to user for confirmation + +6. **Execute the commit**: + - Run `git commit -m ""` + - Display the commit hash and confirm success + - Provide brief summary of what was committed + +## Commit Message Guidelines + +When generating commit messages, follow these rules: + +- **Atomic commits**: Each commit should contain related changes that serve a single purpose +- **Imperative mood**: Write as commands (e.g., "add feature" not "added feature") +- **Concise first line**: Keep under 72 characters +- **Conventional format**: Use ` : ` where type is one of: + - `feat`: A new feature + - `fix`: A bug fix + - `docs`: Documentation changes + - `style`: Code style changes (formatting, etc.) + - `refactor`: Code changes that neither fix bugs nor add features + - `perf`: Performance improvements + - `test`: Adding or fixing tests + - `chore`: Changes to the build process, tools, etc. +- **Present tense, imperative mood**: Write commit messages as commands (e.g., "add feature" not "added feature") +- **Concise first line**: Keep the first line under 72 characters +- **Emoji**: Each commit type is paired with an appropriate emoji: + - ✨ `feat`: New feature + - 🐛 `fix`: Bug fix + - 📝 `docs`: Documentation + - 💄 `style`: Formatting/style + - ♻️ `refactor`: Code refactoring + - ⚡️ `perf`: Performance improvements + - ✅ `test`: Tests + - 🔧 `chore`: Tooling, configuration + - 🚀 `ci`: CI/CD improvements + - 🗑️ `revert`: Reverting changes + - 🧪 `test`: Add a failing test + - 🚨 `fix`: Fix compiler/linter warnings + - 🔒️ `fix`: Fix security issues + - 👥 `chore`: Add or update contributors + - 🚚 `refactor`: Move or rename resources + - 🏗️ `refactor`: Make architectural changes + - 🔀 `chore`: Merge branches + - 📦️ `chore`: Add or update compiled files or packages + - ➕ `chore`: Add a dependency + - ➖ `chore`: Remove a dependency + - 🌱 `chore`: Add or update seed files + - 🧑‍💻 `chore`: Improve developer experience + - 🧵 `feat`: Add or update code related to multithreading or concurrency + - 🔍️ `feat`: Improve SEO + - 🏷️ `feat`: Add or update types + - 💬 `feat`: Add or update text and literals + - 🌐 `feat`: Internationalization and localization + - 👔 `feat`: Add or update business logic + - 📱 `feat`: Work on responsive design + - 🚸 `feat`: Improve user experience / usability + - 🩹 `fix`: Simple fix for a non-critical issue + - 🥅 `fix`: Catch errors + - 👽️ `fix`: Update code due to external API changes + - 🔥 `fix`: Remove code or files + - 🎨 `style`: Improve structure/format of the code + - 🚑️ `fix`: Critical hotfix + - 🎉 `chore`: Begin a project + - 🔖 `chore`: Release/Version tags + - 🚧 `wip`: Work in progress + - 💚 `fix`: Fix CI build + - 📌 `chore`: Pin dependencies to specific versions + - 👷 `ci`: Add or update CI build system + - 📈 `feat`: Add or update analytics or tracking code + - ✏️ `fix`: Fix typos + - ⏪️ `revert`: Revert changes + - 📄 `chore`: Add or update license + - 💥 `feat`: Introduce breaking changes + - 🍱 `assets`: Add or update assets + - ♿️ `feat`: Improve accessibility + - 💡 `docs`: Add or update comments in source code + - 🗃️ `db`: Perform database related changes + - 🔊 `feat`: Add or update logs + - 🔇 `fix`: Remove logs + - 🤡 `test`: Mock things + - 🥚 `feat`: Add or update an easter egg + - 🙈 `chore`: Add or update .gitignore file + - 📸 `test`: Add or update snapshots + - ⚗️ `experiment`: Perform experiments + - 🚩 `feat`: Add, update, or remove feature flags + - 💫 `ui`: Add or update animations and transitions + - ⚰️ `refactor`: Remove dead code + - 🦺 `feat`: Add or update code related to validation + - ✈️ `feat`: Improve offline support + +## Reference: Good Commit Examples + +Use these as examples when generating commit messages: +- ✨ feat: add user authentication system +- 🐛 fix: resolve memory leak in rendering process +- 📝 docs: update API documentation with new endpoints +- ♻️ refactor: simplify error handling logic in parser +- 🚨 fix: resolve linter warnings in component files +- 🧑‍💻 chore: improve developer tooling setup process +- 👔 feat: implement business logic for transaction validation +- 🩹 fix: address minor styling inconsistency in header +- 🚑️ fix: patch critical security vulnerability in auth flow +- 🎨 style: reorganize component structure for better readability +- 🔥 fix: remove deprecated legacy code +- 🦺 feat: add input validation for user registration form +- 💚 fix: resolve failing CI pipeline tests +- 📈 feat: implement analytics tracking for user engagement +- 🔒️ fix: strengthen authentication password requirements +- ♿️ feat: improve form accessibility for screen readers + +Example commit sequence: +- ✨ feat: add user authentication system +- 🐛 fix: resolve memory leak in rendering process +- 📝 docs: update API documentation with new endpoints +- ♻️ refactor: simplify error handling logic in parser +- 🚨 fix: resolve linter warnings in component files +- ✅ test: add unit tests for authentication flow + +## Agent Behavior Notes + +- **Error handling**: If validation fails, give user option to proceed or fix issues first +- **Auto-staging**: If no files are staged, automatically stage all changes with `git add .` +- **File priority**: If files are already staged, only commit those specific files +- **Always run and push the commit**: You don't need to ask for confirmation unless there is a big issue or error `git push`. +- **Message quality**: Ensure commit messages are clear, concise, and follow conventional format +- **Success feedback**: After successful commit, show commit hash and brief summary diff --git a/.opencode/command/context.md b/.opencode/command/context.md new file mode 100644 index 0000000..a3a686f --- /dev/null +++ b/.opencode/command/context.md @@ -0,0 +1,309 @@ +--- +description: Context system manager - harvest summaries, extract knowledge, organize context +tags: + - context + - knowledge-management + - harvest +dependencies: + - subagent:context-organizer + - subagent:contextscout +--- + +# Context Manager + + + + Files MUST be <200 lines. Extract core concepts only (1-3 sentences), 3-5 key points, minimal example, reference link. + + + + ALWAYS present approval UI before deleting/archiving files. Letter-based selection (A B C or 'all'). NEVER auto-delete. + + + + ALWAYS organize by function: concepts/, examples/, guides/, lookup/, errors/ (not flat files). + + + + ALWAYS read required context files from .opencode/context/core/context-system/ BEFORE executing operations. + + + + + + - Files <200 lines (@critical_rules.mvi_strict) + - Show approval before cleanup (@critical_rules.approval_gate) + - Function-based structure (@critical_rules.function_structure) + - Load context before operations (@critical_rules.lazy_load) + + + - Harvest (default), Extract, Organize, Update workflows + + + - Cross-references, validation, navigation + + + Tier 1 always overrides Tier 2/3. + + + +**Arguments**: `$ARGUMENTS` + +--- + +## Default Behavior (No Arguments) + +When invoked without arguments: `/context` + + + + Scan workspace for summary files: + - *OVERVIEW.md, *SUMMARY.md, SESSION-*.md, CONTEXT-*.md + - Files in .tmp/ directory + - Files >2KB in root directory + + + + Show what was found: + ``` + Quick scan results: + + Found 3 summary files: + 📄 CONTEXT-SYSTEM-OVERVIEW.md (4.2 KB) + 📄 SESSION-auth-work.md (1.8 KB) + 📄 .tmp/NOTES.md (800 bytes) + + Recommended action: + /context harvest - Clean up summaries → permanent context + + Other options: + /context extract {source} - Extract from docs/code + /context organize {category} - Restructure existing files + /context help - Show all operations + ``` + + + +**Purpose**: Quick tidy-up. Default assumes you want to harvest summaries and compact workspace. + +--- + +## Operations + +### Primary: Harvest & Compact (Default Focus) + +**`/context harvest [path]`** ⭐ Most Common +- Extract knowledge from AI summaries → permanent context +- Clean workspace (archive/delete summaries) +- **Reads**: `operations/harvest.md` + `standards/mvi.md` + +**`/context compact {file}`** +- Minimize verbose file to MVI format +- **Reads**: `guides/compact.md` + `standards/mvi.md` + +--- + +### Secondary: Custom Context Creation + +**`/context extract from {source}`** +- Extract context from docs/code/URLs +- **Reads**: `operations/extract.md` + `standards/mvi.md` + `guides/compact.md` + +**`/context organize {category}`** +- Restructure flat files → function-based folders +- **Reads**: `operations/organize.md` + `standards/structure.md` + +**`/context update for {topic}`** +- Update context when APIs/frameworks change +- **Reads**: `operations/update.md` + `guides/workflows.md` + +**`/context error for {error}`** +- Add recurring error to knowledge base +- **Reads**: `operations/error.md` + `standards/templates.md` + +**`/context create {category}`** +- Create new context category with structure +- **Reads**: `guides/creation.md` + `standards/structure.md` + `standards/templates.md` + +--- + +### Migration + +**`/context migrate`** +- Copy project-intelligence from global (`~/.config/opencode/context/`) to local (`.opencode/context/`) +- For users who installed globally but want project-specific, git-committed context +- Shows diff if local files already exist, asks before overwriting +- Optionally cleans up global project-intelligence after migration +- **Reads**: `standards/mvi.md` + +--- + +### Utility Operations + +**`/context map [category]`** +- View current context structure, file counts + +**`/context validate`** +- Check integrity, references, file sizes + +**`/context help`** +- Show all operations with examples + +--- + +## Lazy Loading Strategy + + + + Read: operations/harvest.md, standards/mvi.md + + + + Read: operations/harvest.md, standards/mvi.md, guides/workflows.md + + + + Read: guides/compact.md, standards/mvi.md + + + + Read: operations/extract.md, standards/mvi.md, guides/compact.md, guides/workflows.md + + + + Read: operations/organize.md, standards/structure.md, guides/workflows.md + + + + Read: operations/update.md, guides/workflows.md, standards/mvi.md + + + + Read: operations/error.md, standards/templates.md, guides/workflows.md + + + + Read: guides/creation.md, standards/structure.md, standards/templates.md + + + + Read: standards/mvi.md + + + +**All files located in**: `.opencode/context/core/context-system/` + +--- + +## Subagent Routing + + + + + Pass: operation name, arguments, lazy load map + Subagent loads: Required context files from .opencode/context/core/context-system/ + Subagent executes: Multi-stage workflow per operation + + + + Pass: operation name, arguments + Subagent executes: Read-only analysis and reporting + + + +--- + +## Quick Reference + +### Structure +``` +.opencode/context/core/context-system/ +├── operations/ # How to do things (harvest, extract, organize, update) +├── standards/ # What to follow (mvi, structure, templates) +└── guides/ # Step-by-step (workflows, compact, creation) +``` + +### MVI Principle (Quick) +- Core concept: 1-3 sentences +- Key points: 3-5 bullets +- Minimal example: <10 lines +- Reference link: to full docs +- File size: <200 lines + +### Function-Based Structure (Quick) +``` +{category}/ +├── navigation.md # Navigation +├── concepts/ # What it is +├── examples/ # Working code +├── guides/ # How to +├── lookup/ # Quick reference +└── errors/ # Common issues +``` + +--- + +## Examples + +### Default (Quick Scan) +```bash +/context +# Scans workspace, suggests harvest if summaries found +``` + +### Harvest Summaries +```bash +/context harvest +/context harvest .tmp/ +/context harvest OVERVIEW.md +``` + +### Extract from Docs +```bash +/context extract from docs/api.md +/context extract from https://react.dev/hooks +``` + +### Organize Existing +```bash +/context organize development/ +/context organize development/ --dry-run +``` + +### Update for Changes +```bash +/context update for Next.js 15 +/context update for React 19 breaking changes +``` + +### Migrate Global to Local +```bash +/context migrate +# Copies project-intelligence from ~/.config/opencode/context/ to .opencode/context/ +# Shows what will be copied, asks for approval before proceeding +``` + +--- + +## Success Criteria + +After any operation: +- [ ] All files <200 lines? (@critical_rules.mvi_strict) +- [ ] Function-based structure used? (@critical_rules.function_structure) +- [ ] Approval UI shown for destructive ops? (@critical_rules.approval_gate) +- [ ] Required context loaded? (@critical_rules.lazy_load) +- [ ] navigation.md updated? +- [ ] Files scannable in <30 seconds? + +--- + +## Full Documentation + +**Context System Location**: `.opencode/context/core/context-system/` + +**Structure**: +- `operations/` - Detailed operation workflows +- `standards/` - MVI, structure, templates +- `guides/` - Interactive examples, creation standards + +**Read before using**: `standards/mvi.md` (understand Minimal Viable Information principle) diff --git a/.opencode/command/openagents/check-context-deps.md b/.opencode/command/openagents/check-context-deps.md new file mode 100644 index 0000000..22046ca --- /dev/null +++ b/.opencode/command/openagents/check-context-deps.md @@ -0,0 +1,433 @@ +--- +description: Validate context file dependencies across agents and registry +tags: + - registry + - validation + - context + - dependencies + - openagents +dependencies: + - command:analyze-patterns +--- + +# Check Context Dependencies + +**Purpose**: Ensure agents properly declare their context file dependencies in frontmatter and registry. + +**Arguments**: `$ARGUMENTS` + +--- + +## What It Does + +Validates consistency between: +1. **Actual usage** - Context files referenced in agent prompts +2. **Declared dependencies** - Dependencies in agent frontmatter +3. **Registry entries** - Dependencies in registry.json + +**Identifies**: +- ✅ Missing dependency declarations (agents use context but don't declare it) +- ✅ Unused context files (exist but no agent references them) +- ✅ Broken references (referenced but don't exist) +- ✅ Format inconsistencies (wrong dependency format) + +--- + +## Usage + +```bash +# Analyze all agents +/check-context-deps + +# Analyze specific agent +/check-context-deps contextscout + +# Auto-fix missing dependencies +/check-context-deps --fix + +# Verbose output (show all reference locations) +/check-context-deps --verbose + +# Combine flags +/check-context-deps contextscout --verbose +``` + +--- + +## Workflow + + + + Scan agent files for context references: + + **Search patterns**: + - `.opencode/context/` (direct path references) + - `@.opencode/context/` (@ symbol references) + - `context:` (dependency declarations in frontmatter) + + **Locations**: + - `.opencode/agent/**/*.md` (all agents and subagents) + - `.opencode/command/**/*.md` (commands that use context) + + **Extract**: + - Agent/command ID + - Context file path + - Line number + - Reference type (path, @-reference, dependency) + + + + For each agent found, check registry.json: + + ```bash + jq '.components.agents[] | select(.id == "AGENT_ID") | .dependencies' registry.json + jq '.components.subagents[] | select(.id == "AGENT_ID") | .dependencies' registry.json + ``` + + **Verify**: + - Does the agent have a dependencies array? + - Are context file references declared as `context:core/standards/code`? + - Are the dependency formats correct (`context:path/to/file`)? + + + + For each context file referenced: + + **Check existence**: + ```bash + test -f .opencode/context/core/standards/code-quality.md + ``` + + **Check registry**: + ```bash + jq '.components.contexts[] | select(.id == "core/standards/code")' registry.json + ``` + + **Identify issues**: + - Context file referenced but doesn't exist + - Context file exists but not in registry + - Context file in registry but never used + + + + Generate comprehensive report: + + ```markdown + # Context Dependency Analysis Report + + ## Summary + - Agents scanned: 25 + - Context files referenced: 12 + - Missing dependencies: 8 + - Unused context files: 2 + - Missing context files: 0 + + ## Missing Dependencies (agents using context but not declaring) + + ### opencoder + **Uses but not declared**: + - context:core/standards/code (referenced 3 times) + - Line 64: "Code tasks → .opencode/context/core/standards/code-quality.md (MANDATORY)" + - Line 170: "Read .opencode/context/core/standards/code-quality.md NOW" + - Line 229: "NEVER execute write/edit without loading required context first" + + **Current dependencies**: subagent:task-manager, subagent:coder-agent + **Recommended fix**: Add to frontmatter: + ```yaml + dependencies: + - subagent:task-manager + - subagent:coder-agent + - context:core/standards/code # ADD THIS + ``` + + ### openagent + **Uses but not declared**: + - context:core/standards/code (referenced 5 times) + - context:core/standards/docs (referenced 3 times) + - context:core/standards/tests (referenced 3 times) + - context:core/workflows/review (referenced 2 times) + - context:core/workflows/delegation (referenced 4 times) + + **Recommended fix**: Add to frontmatter: + ```yaml + dependencies: + - subagent:task-manager + - subagent:documentation + - context:core/standards/code + - context:core/standards/docs + - context:core/standards/tests + - context:core/workflows/review + - context:core/workflows/delegation + ``` + + ## Unused Context Files (exist but no agent references them) + + - context:core/standards/analysis (0 references) + - context:core/workflows/sessions (0 references) + + **Recommendation**: Consider removing or documenting intended use + + ## Missing Context Files (referenced but don't exist) + + None found ✅ + + ## Context File Usage Map + + | Context File | Used By | Reference Count | + |--------------|---------|-----------------| + | core/standards/code | opencoder, openagent, frontend-specialist, reviewer | 15 | + | core/standards/docs | openagent, documentation, technical-writer | 8 | + | core/standards/tests | openagent, tester | 6 | + | core/workflows/delegation | openagent, task-manager | 5 | + | core/workflows/review | openagent, reviewer | 4 | + + --- + + ## Next Steps + + 1. Review missing dependencies above + 2. Run `/check-context-deps --fix` to auto-update frontmatter + 3. Run `./scripts/registry/auto-detect-components.sh` to update registry + 4. Verify with `./scripts/registry/validate-registry.sh` + ``` + + + + For each agent with missing context dependencies: + + 1. Read the agent file + 2. Parse frontmatter YAML + 3. Add missing context dependencies to dependencies array + 4. Preserve existing dependencies + 5. Write updated file + 6. Report what was changed + + **Example**: + ```diff + --- + id: opencoder + dependencies: + - subagent:task-manager + - subagent:coder-agent + + - context:core/standards/code + --- + ``` + + **Safety**: + - Only add dependencies that are actually referenced in the file + - Don't remove existing dependencies + - Preserve frontmatter formatting + - Show diff before applying (if interactive) + + + +--- + +## Implementation Details + +### Search Patterns + +**Find direct path references**: +```bash +grep -rn "\.opencode/context/" .opencode/agent/ .opencode/command/ +``` + +**Find @ references**: +```bash +grep -rn "@\.opencode/context/" .opencode/agent/ .opencode/command/ +``` + +**Find dependency declarations**: +```bash +grep -rn "^\s*-\s*context:" .opencode/agent/ .opencode/command/ +``` + +### Path Normalization + +**Convert to dependency format**: +- `.opencode/context/core/standards/code-quality.md` → `context:core/standards/code` +- `@.opencode/context/openagents-repo/quick-start.md` → `context:openagents-repo/quick-start` +- `context/core/standards/code` → `context:core/standards/code` + +**Rules**: +1. Strip `.opencode/` prefix +2. Strip `.md` extension +3. Add `context:` prefix for dependencies + +### Registry Lookup + +**Check if context file is in registry**: +```bash +jq '.components.contexts[] | select(.id == "core/standards/code")' registry.json +``` + +**Get agent dependencies**: +```bash +jq '.components.agents[] | select(.id == "opencoder") | .dependencies[]?' registry.json +``` + +--- + +## Delegation + +This command delegates to an analysis agent to perform the work: + +```javascript +task( + subagent_type="PatternAnalyst", + description="Analyze context dependencies", + prompt=` + Analyze context file usage across all agents in this repository. + + TASK: + 1. Use grep to find all references to context files in: + - .opencode/agent/**/*.md + - .opencode/command/**/*.md + + 2. Search for these patterns: + - ".opencode/context/core/" (direct paths) + - "@.opencode/context/" (@ references) + - "context:" in frontmatter (dependency declarations) + + 3. For each agent file found: + - Extract agent ID from frontmatter + - List all context files it references + - Check registry.json for declared dependencies + - Identify missing dependency declarations + + 4. For each context file in .opencode/context/core/: + - Count how many agents reference it + - Check if it exists in registry.json + - Identify unused context files + + 5. Generate a comprehensive report showing: + - Agents with missing context dependencies + - Unused context files + - Missing context files (referenced but don't exist) + - Context file usage map (which agents use which files) + + ${ARGUMENTS.includes('--fix') ? ` + 6. AUTO-FIX MODE: + - Update agent frontmatter to add missing context dependencies + - Use format: context:core/standards/code + - Preserve existing dependencies + - Show what was changed + ` : ''} + + ${ARGUMENTS.includes('--verbose') ? ` + VERBOSE MODE: Include all reference locations (file:line) in report + ` : ''} + + ${ARGUMENTS.length > 0 && !ARGUMENTS.includes('--') ? ` + FILTER: Only analyze agent: ${ARGUMENTS[0]} + ` : ''} + + REPORT FORMAT: + - Summary statistics + - Missing dependencies by agent (with recommended fixes) + - Unused context files + - Context file usage map + - Next steps + + DO NOT make changes without --fix flag. + ALWAYS show what would be changed before applying fixes. + ` +) +``` + +--- + +## Examples + +### Example 1: Basic Analysis + +```bash +/check-context-deps +``` + +**Output**: +``` +Analyzing context file usage across 25 agents... + +Found 8 agents with missing context dependencies: +- opencoder: missing context:core/standards/code +- openagent: missing 5 context dependencies +- frontend-specialist: missing context:core/standards/code +... + +Run /check-context-deps --fix to auto-update frontmatter +``` + +### Example 2: Analyze Specific Agent + +```bash +/check-context-deps contextscout +``` + +**Output**: +``` +Analyzing agent: contextscout + +Context files referenced: +✓ .opencode/context/core/context-system.md (1 reference) + - Line 15: "Load: context:core/context-system" +✓ .opencode/context/core/context-system/standards/mvi.md (2 references) + - Line 16: "Load: context:core/context-system/standards/mvi" + - Line 89: "MVI-aware prioritization" + +Registry dependencies: +✓ context:core/context-system DECLARED +✓ context:core/context-system/standards/mvi DECLARED + +All dependencies properly declared ✅ +``` + +### Example 3: Auto-Fix + +```bash +/check-context-deps --fix +``` + +**Output**: +``` +Analyzing and fixing context dependencies... + +Updated opencoder: ++ Added: context:core/standards/code + +Updated openagent: ++ Added: context:core/standards/code ++ Added: context:core/standards/docs ++ Added: context:core/standards/tests ++ Added: context:core/workflows/review ++ Added: context:core/workflows/delegation + +Total: 2 agents updated, 6 dependencies added + +Next: Run ./scripts/registry/auto-detect-components.sh to update registry +``` + +--- + +## Success Criteria + +✅ All agents that reference context files have them declared in dependencies +✅ All context files in registry are actually used by at least one agent +✅ No broken references (context files referenced but don't exist) +✅ Dependency format is consistent (`context:path/to/file`) + +--- + +## Notes + +- **Read-only by default** - Only reports findings, doesn't modify files +- **Use `--fix` to update** - Auto-adds missing dependencies to frontmatter +- **After fixing** - Run `./scripts/registry/auto-detect-components.sh --auto-add` to sync registry +- **Dependency format** - `context:path/to/file` (no `.opencode/` prefix, no `.md` extension) +- **Scans both** - Direct path references and @ references + +## Related + +- **Registry validation**: `./scripts/registry/validate-registry.sh` +- **Auto-detect components**: `./scripts/registry/auto-detect-components.sh` +- **Context guide**: `.opencode/context/openagents-repo/quality/registry-dependencies.md` diff --git a/.opencode/command/optimize.md b/.opencode/command/optimize.md new file mode 100644 index 0000000..911984c --- /dev/null +++ b/.opencode/command/optimize.md @@ -0,0 +1,190 @@ +--- +description: Analyze and optimize code for performance, security, and potential issues +--- + +# Code Optimization Analysis + +You are a code optimization specialist focused on performance, security, and identifying potential issues before they become problems. When provided with $ARGUMENTS (file paths or directories), analyze and optimize the specified code. If no arguments provided, analyze the current context (open files, recent changes, or project focus). + +## Your Optimization Process: + +**Step 1: Determine Analysis Scope** +- If $ARGUMENTS provided: Focus on specified files/directories +- If no arguments: Analyze current context by checking: + - Currently open files in the IDE + - Recently modified files via `git status` and `git diff --name-only HEAD~5` + - Files with recent git blame activity +- Identify file types and applicable optimization strategies + +**Step 2: Performance Analysis** +Execute comprehensive performance review: + +1. **Algorithmic Efficiency** + - Identify O(n²) or worse time complexity patterns + - Look for unnecessary nested loops + - Find redundant calculations or database queries + - Spot inefficient data structure usage + +2. **Memory Management** + - Detect memory leaks and excessive allocations + - Find large objects that could be optimized + - Identify unnecessary data retention + - Check for proper cleanup in event handlers + +3. **I/O Optimization** + - Analyze file read/write patterns + - Check for unnecessary API calls + - Look for missing caching opportunities + - Identify blocking operations that could be async + +4. **Framework-Specific Issues** + - React: unnecessary re-renders, missing memoization + - Node.js: synchronous operations, missing streaming + - Database: N+1 queries, missing indexes + - Frontend: bundle size, asset optimization + +**Step 3: Security Analysis** +Scan for security vulnerabilities: + +1. **Input Validation** + - Missing sanitization of user inputs + - SQL injection vulnerabilities + - XSS attack vectors + - Path traversal risks + +2. **Authentication & Authorization** + - Weak password policies + - Missing authentication checks + - Inadequate session management + - Privilege escalation risks + +3. **Data Protection** + - Sensitive data in logs or errors + - Unencrypted sensitive data storage + - Missing rate limiting + - Insecure API endpoints + +4. **Dependency Security** + - Outdated packages with known vulnerabilities + - Unused dependencies increasing attack surface + - Missing security headers + +**Step 4: Potential Issue Detection** +Identify hidden problems: + +1. **Error Handling** + - Missing try-catch blocks + - Silent failures + - Inadequate error logging + - Poor user error feedback + +2. **Edge Cases** + - Null/undefined handling + - Empty array/object scenarios + - Network failure handling + - Race condition possibilities + +3. **Scalability Concerns** + - Hard-coded limits + - Single points of failure + - Resource exhaustion scenarios + - Concurrent access issues + +4. **Maintainability Issues** + - Code duplication + - Overly complex functions + - Missing documentation for critical logic + - Tight coupling between components + +**Step 5: Present Optimization Report** + +## 📋 Code Optimization Analysis + +### 🎯 Analysis Scope +- **Files Analyzed**: [List of files examined] +- **Total Lines**: [Code volume analyzed] +- **Languages**: [Programming languages found] +- **Frameworks**: [Frameworks/libraries detected] + +### ⚡ Performance Issues Found + +#### 🔴 Critical Performance Issues +- **Issue**: [Specific performance problem] +- **Location**: [File:line reference] +- **Impact**: [Performance cost/bottleneck] +- **Solution**: [Specific optimization approach] + +#### 🟡 Performance Improvements +- **Optimization**: [Improvement opportunity] +- **Expected Gain**: [Performance benefit] +- **Implementation**: [How to apply the fix] + +### 🔒 Security Vulnerabilities + +#### 🚨 Critical Security Issues +- **Vulnerability**: [Security flaw found] +- **Risk Level**: [High/Medium/Low] +- **Location**: [Where the issue exists] +- **Fix**: [Security remediation steps] + +#### 🛡️ Security Hardening Opportunities +- **Enhancement**: [Security improvement] +- **Benefit**: [Protection gained] +- **Implementation**: [Steps to implement] + +### ⚠️ Potential Issues & Edge Cases + +#### 🔍 Hidden Problems +- **Issue**: [Potential problem identified] +- **Scenario**: [When this could cause issues] +- **Prevention**: [How to avoid the problem] + +#### 🧪 Edge Cases to Handle +- **Case**: [Unhandled edge case] +- **Impact**: [What could go wrong] +- **Solution**: [How to handle it properly] + +### 🏗️ Architecture & Maintainability + +#### 📐 Code Quality Issues +- **Problem**: [Maintainability concern] +- **Location**: [Where it occurs] +- **Refactoring**: [Improvement approach] + +#### 🔗 Dependency Optimization +- **Unused Dependencies**: [Packages to remove] +- **Outdated Packages**: [Dependencies to update] +- **Bundle Size**: [Optimization opportunities] + +### 💡 Optimization Recommendations + +#### 🎯 Priority 1 (Critical) +1. [Most important optimization with immediate impact] +2. [Critical security fix needed] +3. [Performance bottleneck to address] + +#### 🎯 Priority 2 (Important) +1. [Significant improvements to implement] +2. [Important edge cases to handle] + +#### 🎯 Priority 3 (Nice to Have) +1. [Code quality improvements] +2. [Minor optimizations] + +### 🔧 Implementation Guide +``` +[Specific code examples showing how to implement key optimizations] +``` + +### 📊 Expected Impact +- **Performance**: [Expected speed/efficiency gains] +- **Security**: [Risk reduction achieved] +- **Maintainability**: [Code quality improvements] +- **User Experience**: [End-user benefits] + +## Optimization Focus Areas: +- **Performance First**: Identify and fix actual bottlenecks, not premature optimizations +- **Security by Design**: Build secure patterns from the start +- **Proactive Issue Prevention**: Catch problems before they reach production +- **Maintainable Solutions**: Ensure optimizations don't sacrifice code clarity +- **Measurable Improvements**: Focus on changes that provide tangible benefits diff --git a/.opencode/command/test.md b/.opencode/command/test.md new file mode 100644 index 0000000..f72bdf2 --- /dev/null +++ b/.opencode/command/test.md @@ -0,0 +1,26 @@ +--- +description: Run the complete testing pipeline +--- + +# Testing Pipeline + +This command runs the complete testing pipeline for the project. + +## Usage + +To run the complete testing pipeline, just type: + +1. Run pnpm type:check +2. Run pnpm lint +3. Run pnpm test +4. Report any failures +5. Fix any failures +6. Repeat until all tests pass +7. Report success + +## What This Command Does + +1. Runs `pnpm type:check` to check for type errors +2. Runs `pnpm lint` to check for linting errors +3. Runs `pnpm test` to run the tests +4. Reports any failures \ No newline at end of file diff --git a/.opencode/command/validate-repo.md b/.opencode/command/validate-repo.md new file mode 100644 index 0000000..189e97f --- /dev/null +++ b/.opencode/command/validate-repo.md @@ -0,0 +1,347 @@ +# Validate Repository + +Comprehensive validation command that checks the entire OpenAgents Control repository for consistency between CLI, documentation, registry, and components. + +## Usage + +```bash +/validate-repo +``` + +## What It Checks + +This command performs a comprehensive validation of: + +1. **Registry Integrity** + - JSON syntax validation + - Component definitions completeness + - File path references + - Dependency declarations + +2. **Component Existence** + - All agents exist at specified paths + - All subagents exist at specified paths + - All commands exist at specified paths + - All tools exist at specified paths + - All plugins exist at specified paths + - All context files exist at specified paths + - All config files exist at specified paths + +3. **Profile Consistency** + - Component counts match documentation + - Profile descriptions are accurate + - Dependencies are satisfied + - No duplicate components + +4. **Documentation Accuracy** + - README component counts match registry + - OpenAgent documentation references are valid + - Context file references are correct + - Installation guide is up to date + +5. **Context File Structure** + - All referenced context files exist + - Context file organization is correct + - No orphaned context files + +6. **Cross-References** + - Agent dependencies exist + - Subagent references are valid + - Command references are valid + - Tool dependencies are satisfied + +## Output + +The command generates a detailed report showing: +- ✅ What's correct and validated +- ⚠️ Warnings for potential issues +- ❌ Errors that need fixing +- 📊 Summary statistics + +## Instructions + +You are a validation specialist. Your task is to comprehensively validate the OpenAgents Control repository for consistency and correctness. + +### Step 1: Validate Registry JSON + +1. Read and parse `registry.json` +2. Validate JSON syntax +3. Check schema structure: + - `version` field exists + - `repository` field exists + - `categories` object exists + - `components` object exists with all types + - `profiles` object exists + - `metadata` object exists + +### Step 2: Validate Component Definitions + +For each component type (agents, subagents, commands, tools, plugins, contexts, config): + +1. Check required fields: + - `id` (unique) + - `name` + - `type` + - `path` + - `description` + - `tags` (array) + - `dependencies` (array) + - `category` + +2. Verify file exists at `path` +3. Check for duplicate IDs +4. Validate category is in defined categories + +### Step 3: Validate Profiles + +For each profile (essential, developer, business, full, advanced): + +1. Count components in profile +2. Verify all component references exist in components section +3. Check dependencies are satisfied +4. Validate no duplicate components + +### Step 4: Cross-Reference with Documentation + +1. **navigation.md**: + - Extract component counts from profile descriptions + - Compare with actual registry counts + - Check profile descriptions match registry descriptions + +2. **docs/agents/openagent.md**: + - Verify delegation criteria mentioned + - Check context file references + - Validate workflow descriptions + +3. **docs/getting-started/installation.md**: + - Check profile descriptions + - Verify installation commands + +### Step 5: Validate Context File Structure + +1. List all files in `.opencode/context/` +2. Check against registry context entries +3. Identify orphaned files (exist but not in registry) +4. Identify missing files (in registry but don't exist) +5. Validate structure: + - `core/standards/` files + - `core/workflows/` files + - `core/system/` files + - `project/` files + +### Step 6: Validate Dependencies + +For each component with dependencies: + +1. Parse dependency string (format: `type:id`) +2. Verify referenced component exists +3. Check for circular dependencies +4. Validate dependency chain completeness + +### Step 7: Generate Report + +Create a comprehensive report with sections: + +#### ✅ Validated Successfully +- Registry JSON syntax +- Component file existence +- Profile integrity +- Documentation accuracy +- Context file structure +- Dependency chains + +#### ⚠️ Warnings +- Orphaned files (exist but not referenced) +- Unused components (defined but not in any profile) +- Missing descriptions or tags +- Outdated metadata dates + +#### ❌ Errors +- Missing files +- Broken dependencies +- Invalid JSON +- Component count mismatches +- Broken documentation references +- Duplicate component IDs + +#### 📊 Statistics +- Total components: X +- Total profiles: X +- Total context files: X +- Components per profile breakdown +- File coverage percentage + +### Step 8: Provide Recommendations + +Based on findings, suggest: +- Files to create +- Registry entries to add/remove +- Documentation to update +- Dependencies to fix + +## Example Report Format + +```markdown +# OpenAgents Control Repository Validation Report + +Generated: 2025-11-19 14:30:00 + +## Summary + +✅ 95% validation passed +⚠️ 3 warnings found +❌ 2 errors found + +--- + +## ✅ Validated Successfully + +### Registry Integrity +✅ JSON syntax valid +✅ All required fields present +✅ Schema structure correct + +### Component Existence (45/47 files found) +✅ Agents: 3/3 files exist +✅ Subagents: 15/15 files exist +✅ Commands: 8/8 files exist +✅ Tools: 2/2 files exist +✅ Plugins: 2/2 files exist +✅ Contexts: 13/15 files exist +✅ Config: 2/2 files exist + +### Profile Consistency +✅ Essential: 9 components (matches README) +✅ Developer: 29 components (matches README) +✅ Business: 15 components (matches README) +✅ Full: 35 components (matches README) +✅ Advanced: 42 components (matches README) + +### Documentation Accuracy +✅ README component counts match registry +✅ OpenAgent documentation up to date +✅ Installation guide accurate + +--- + +## ⚠️ Warnings (3) + +1. **Orphaned Context File** + - File: `.opencode/context/legacy/old-patterns.md` + - Issue: Exists but not referenced in registry + - Recommendation: Add to registry or remove file + +2. **Unused Component** + - Component: `workflow-orchestrator` (agent) + - Issue: Defined in registry but not in any profile + - Recommendation: Add to a profile or mark as deprecated + +3. **Outdated Metadata** + - Field: `metadata.lastUpdated` + - Current: 2025-11-15 + - Recommendation: Update to current date + +--- + +## ❌ Errors (2) + +1. **Missing Context File** + - Component: `context:advanced-patterns` + - Expected path: `.opencode/context/core/advanced-patterns.md` + - Referenced in: developer, full, advanced profiles + - Action: Create file or remove from registry + +2. **Broken Dependency** + - Component: `agent:opencoder` + - Dependency: `subagent:pattern-matcher` + - Issue: Dependency not found in registry + - Action: Add missing subagent or fix dependency reference + +--- + +## 📊 Statistics + +### Component Distribution +- Agents: 3 +- Subagents: 15 +- Commands: 8 +- Tools: 2 +- Plugins: 2 +- Contexts: 15 +- Config: 2 +- **Total: 47 components** + +### Profile Breakdown +- Essential: 9 components (19%) +- Developer: 29 components (62%) +- Business: 15 components (32%) +- Full: 35 components (74%) +- Advanced: 42 components (89%) + +### File Coverage +- Total files defined: 47 +- Files found: 45 (96%) +- Files missing: 2 (4%) +- Orphaned files: 1 + +### Dependency Health +- Total dependencies: 23 +- Valid dependencies: 22 (96%) +- Broken dependencies: 1 (4%) +- Circular dependencies: 0 + +--- + +## 🔧 Recommended Actions + +### High Priority (Errors) +1. Create missing file: `.opencode/context/core/advanced-patterns.md` +2. Fix broken dependency in `opencoder` + +### Medium Priority (Warnings) +1. Remove orphaned file or add to registry +2. Add `workflow-orchestrator` to a profile or deprecate +3. Update metadata.lastUpdated to 2025-11-19 + +### Low Priority (Improvements) +1. Add more tags to components for better searchability +2. Consider adding descriptions to all context files +3. Document component categories in README + +--- + +## Next Steps + +1. Review and fix all ❌ errors +2. Address ⚠️ warnings as needed +3. Re-run validation to confirm fixes +4. Update documentation if needed + +--- + +**Validation Complete** ✓ +``` + +## Implementation Notes + +The command should: +- Use bash/python for file system operations +- Parse JSON with proper error handling +- Generate markdown report +- Be non-destructive (read-only validation) +- Provide actionable recommendations +- Support verbose mode for detailed output + +## Error Handling + +- Gracefully handle missing files +- Continue validation even if errors found +- Collect all issues before reporting +- Provide clear error messages with context + +## Performance + +- Should complete in < 30 seconds +- Cache file reads where possible +- Parallel validation where safe +- Progress indicators for long operations diff --git a/.opencode/context/development/ai/mastra-ai/concepts/agents-tools.md b/.opencode/context/development/ai/mastra-ai/concepts/agents-tools.md new file mode 100644 index 0000000..53a5d53 --- /dev/null +++ b/.opencode/context/development/ai/mastra-ai/concepts/agents-tools.md @@ -0,0 +1,39 @@ +# Concept: Mastra Agents & Tools + +**Purpose**: Reusable units of logic and LLM-powered entities. + +**Last Updated**: 2026-01-09 + +--- + +## Core Idea +Agents are specialized LLM configurations that use Tools to interact with external systems or perform specific logic. Tools are the building blocks that provide functionality to both agents and workflows. + +## Key Points +- **Agents**: Defined with a `name`, `instructions`, and `model`. They can be assigned a set of `tools`. +- **Tools**: Defined with `id`, `inputSchema`, `outputSchema`, and an `execute` function. +- **Type Safety**: Both agents and tools use Zod for schema validation. +- **Standalone Use**: Tools can be executed independently of agents, making them highly reusable. + +## Quick Example +```typescript +// Tool +const myTool = createTool({ + id: 'my-tool', + inputSchema: z.object({ query: z.string() }), + execute: async ({ inputData }) => ({ result: `Processed ${inputData.query}` }), +}); + +// Agent +const myAgent = new Agent({ + name: 'My Agent', + instructions: 'Use my-tool to process queries.', + model: { provider: 'OPEN_AI', name: 'gpt-4o' }, + tools: { myTool }, +}); +``` + +**Reference**: `src/mastra/agents/`, `src/mastra/tools/` +**Related**: +- concepts/core.md +- concepts/workflows.md diff --git a/.opencode/context/development/ai/mastra-ai/concepts/core.md b/.opencode/context/development/ai/mastra-ai/concepts/core.md new file mode 100644 index 0000000..ac8a230 --- /dev/null +++ b/.opencode/context/development/ai/mastra-ai/concepts/core.md @@ -0,0 +1,35 @@ +# Concept: Mastra Core + +**Purpose**: Central orchestration layer for AI agents, workflows, and tools in this project. + +**Last Updated**: 2026-01-09 + +--- + +## Core Idea +Mastra is the central hub that wires together agents, tools, workflows, and observability. It provides a unified interface for executing complex AI tasks with built-in persistence and logging. + +## Key Points +- **Centralized Config**: All components are registered in `src/mastra/index.ts`. +- **Persistence**: Uses `LibSQLStore` (SQLite) for storing traces, spans, and workflow states. +- **Observability**: Built-in tracing and logging (Pino) for every execution. +- **Modular Design**: Agents, tools, and workflows are defined separately and composed in the main instance. + +## Quick Example +```typescript +import { Mastra } from '@mastra/core/mastra'; +import { agents, tools, workflows } from './components'; + +export const mastra = new Mastra({ + agents, + tools, + workflows, + storage: new LibSQLStore({ url: 'file:./mastra.db' }), +}); +``` + +**Reference**: `src/mastra/index.ts` +**Related**: +- concepts/workflows.md +- concepts/agents-tools.md +- lookup/mastra-config.md diff --git a/.opencode/context/development/ai/mastra-ai/concepts/evaluations.md b/.opencode/context/development/ai/mastra-ai/concepts/evaluations.md new file mode 100644 index 0000000..c86c37c --- /dev/null +++ b/.opencode/context/development/ai/mastra-ai/concepts/evaluations.md @@ -0,0 +1,39 @@ +# Concept: Mastra Evaluations + +**Purpose**: Quality assurance and scoring for LLM outputs. + +**Last Updated**: 2026-01-09 + +--- + +## Core Idea +Evaluations in Mastra use Scorers to assess the quality, accuracy, and safety of LLM-generated content. They provide a quantitative way to measure performance and detect issues like hallucinations or factual errors. + +## Key Points +- **Scorers**: Specialized functions that take LLM output (and optionally ground truth) and return a score (0-1). +- **Integration**: Registered in the Mastra instance and can be triggered automatically during workflow execution. +- **Metrics**: Common metrics include hallucination detection, fact validation, and relevance scoring. +- **Audit Trail**: Scorer results are stored in the `mastra_scorers` table for long-term analysis and reporting. + +## Quick Example +```typescript +// Scorer definition +export const hallucinationDetector = new Scorer({ + id: 'hallucination-detector', + description: 'Detects hallucinations in LLM output', + execute: async ({ output, context }) => { + // Logic to detect hallucinations + return { score: 0.95, rationale: 'No hallucinations found' }; + }, +}); + +// Registration +export const mastra = new Mastra({ + scorers: { hallucinationDetector }, +}); +``` + +**Reference**: `src/mastra/scorers/`, `src/mastra/evaluation/` +**Related**: +- concepts/core.md +- concepts/workflows.md diff --git a/.opencode/context/development/ai/mastra-ai/concepts/storage.md b/.opencode/context/development/ai/mastra-ai/concepts/storage.md new file mode 100644 index 0000000..5e9bf86 --- /dev/null +++ b/.opencode/context/development/ai/mastra-ai/concepts/storage.md @@ -0,0 +1,36 @@ +# Concept: Mastra Data Storage + +**Purpose**: Persistence layer for cases, documents, assessments, and observability. + +**Last Updated**: 2026-01-09 + +--- + +## Core Idea +Mastra uses a dual-storage approach: a local SQLite database (via Drizzle ORM) for business entities and a built-in `LibSQLStore` for Mastra-specific execution data (traces, spans). + +## Key Points +- **Business Entities**: Managed in `src/db/schema.ts`. Includes `cases`, `documents`, `assessments`, and `outputs`. +- **Mastra Store**: `LibSQLStore` handles `mastra_traces`, `mastra_ai_spans`, and `mastra_scorers`. +- **V3 Extensions**: Specific tables for `timeline_events`, `evidence_gaps`, `sub_claims`, and `vulnerability_flags`. +- **Observability**: `prompt_execution_traces` provides detailed cost and token tracking per AI call. +- **File Storage**: Large blobs (PDFs, JSON outputs) are stored in `./tmp/` with paths referenced in the DB. + +## Quick Example +```typescript +// Business Schema (Drizzle) +export const cases = sqliteTable('cases', { + id: text('id').primaryKey(), + status: text('status').default('new'), +}); + +// Mastra Store Config +storage: new LibSQLStore({ + url: process.env.MASTRA_DB_PATH || 'file:./mastra.db', +}), +``` + +**Reference**: `src/db/schema.ts`, `src/mastra/index.ts` +**Related**: +- concepts/core.md +- lookup/mastra-config.md diff --git a/.opencode/context/development/ai/mastra-ai/concepts/workflows.md b/.opencode/context/development/ai/mastra-ai/concepts/workflows.md new file mode 100644 index 0000000..47d18bd --- /dev/null +++ b/.opencode/context/development/ai/mastra-ai/concepts/workflows.md @@ -0,0 +1,33 @@ +# Concept: Mastra Workflows + +**Purpose**: Linear and parallel execution chains for complex AI tasks. + +**Last Updated**: 2026-01-09 + +--- + +## Core Idea +Workflows in Mastra are directed graphs of steps that process data sequentially or in parallel. They provide a structured way to handle multi-stage LLM operations with built-in state management and human-in-the-loop (HITL) support. + +## Key Points +- **Step Definition**: Created with `createStep`, requiring `inputSchema`, `outputSchema`, and an `execute` function. +- **Chaining**: Steps are linked using `.then()` for sequential and `.parallel()` for concurrent execution. +- **HITL Support**: Steps can `suspend` execution to wait for human input and `resume` when data is provided. +- **State Access**: Each step has access to the global workflow `state` and the `inputData` from the previous step. + +## Quick Example +```typescript +const workflow = createWorkflow({ id: 'my-workflow', inputSchema, outputSchema }) + .then(step1) + .parallel([step2a, step2b]) + .then(mergeStep) + .commit(); + +const { runId, start } = workflow.createRun(); +const result = await start({ inputData: { ... } }); +``` + +**Reference**: `src/mastra/workflows/` +**Related**: +- concepts/core.md +- examples/workflow-example.md diff --git a/.opencode/context/development/ai/mastra-ai/errors/mastra-errors.md b/.opencode/context/development/ai/mastra-ai/errors/mastra-errors.md new file mode 100644 index 0000000..b3ef768 --- /dev/null +++ b/.opencode/context/development/ai/mastra-ai/errors/mastra-errors.md @@ -0,0 +1,31 @@ +# Errors: Mastra Implementation + +**Purpose**: Common errors, their causes, and recovery strategies. + +**Last Updated**: 2026-01-09 + +--- + +## Core Idea +Errors in Mastra typically fall into three categories: AI generation failures, structured output validation errors, and context/resource missing errors. + +## Key Points +- **AIGenerationError**: Occurs when the LLM fails to generate a response (e.g., safety filters, model downtime). +- **StructuredOutputError**: Triggered when the LLM response doesn't match the Zod schema defined in the tool or step. +- **RateLimitError**: Hit when exceeding provider limits. Includes a `retryAfter` value. +- **MastraContextError**: Raised when a required resource (like `services` or `mastra` instance) is missing from the execution context. +- **Retry Strategy**: Use `isRetryableError(error)` to determine if a transient failure can be recovered with exponential backoff. + +## Common Errors Table + +| Error | Cause | Fix | +|-------|-------|-----| +| `StructuredOutputError` | LLM hallucinated wrong JSON | Refine prompt or use simpler schema | +| `RateLimitError` | Too many concurrent requests | Implement rate limiting or increase quota | +| `NotFoundError` | Case or Document ID missing in DB | Check DB state before workflow start | +| `MastraContextError` | `services` not passed to tool | Ensure `services` is in `ToolExecutionContext` | + +**Reference**: `src/lib/errors.ts` +**Related**: +- concepts/core.md +- guides/testing.md diff --git a/.opencode/context/development/ai/mastra-ai/examples/workflow-example.md b/.opencode/context/development/ai/mastra-ai/examples/workflow-example.md new file mode 100644 index 0000000..e7070d0 --- /dev/null +++ b/.opencode/context/development/ai/mastra-ai/examples/workflow-example.md @@ -0,0 +1,40 @@ +# Example: Document Ingestion Workflow + +**Purpose**: Demonstrates a multi-step workflow with parallel processing. + +**Last Updated**: 2026-01-09 + +--- + +## Workflow Definition +```typescript +export const documentIngestionWorkflow = createWorkflow({ + id: 'document-ingestion', + inputSchema: z.object({ filename: z.string(), fileBuffer: z.any() }), + outputSchema: z.object({ documentId: z.string(), success: z.boolean() }), +}) + .then(uploadStep) // Step 1: Upload + .then(extractionStep) // Step 2: Extract Text + .parallel([ // Step 3: Process in parallel + classificationStep, + summarizationStep + ]) + .then(mergeResultsStep) // Step 4: Merge + .commit(); +``` + +## Step Execution +```typescript +const uploadStep = createStep({ + id: 'upload-document', + execute: async ({ inputData, mastra }) => { + const result = await documentUploadTool.execute(inputData, { mastra }); + return result; + }, +}); +``` + +**Reference**: `src/mastra/workflows/document-ingestion-with-classification-workflow.ts` +**Related**: +- concepts/workflows.md +- concepts/agents-tools.md diff --git a/.opencode/context/development/ai/mastra-ai/guides/modular-building.md b/.opencode/context/development/ai/mastra-ai/guides/modular-building.md new file mode 100644 index 0000000..60d1cff --- /dev/null +++ b/.opencode/context/development/ai/mastra-ai/guides/modular-building.md @@ -0,0 +1,35 @@ +# Guide: Modular Mastra Building + +**Purpose**: Best practices for structuring a large-scale Mastra implementation. + +**Last Updated**: 2026-01-09 + +--- + +## Core Idea +Modular building ensures that as the project grows, components remain testable, reusable, and easy to navigate. This is achieved by separating logic into specialized directories and using a central registry. + +## Key Points +- **Component Separation**: Keep `agents`, `tools`, `workflows`, and `scorers` in their own top-level directories within `src/mastra/`. +- **Shared Services**: Use a `shared.ts` file to instantiate services (DB, repositories) to prevent circular dependencies between workflows and the main Mastra instance. +- **Central Registry**: Register all components in `src/mastra/index.ts`. This is the single source of truth for the Mastra instance. +- **Feature-Based Steps**: Group related workflow steps into sub-directories (e.g., `src/mastra/workflows/v3/steps/`) to keep workflow files clean. + +## Quick Example +```typescript +// src/mastra/shared.ts +export const services = createServices(); + +// src/mastra/index.ts +import { services } from './shared'; +export const mastra = new Mastra({ + workflows: { myWorkflow }, + agents: { myAgent }, + // ... +}); +``` + +**Reference**: `src/mastra/index.ts`, `src/mastra/shared.ts` +**Related**: +- concepts/core.md +- guides/workflow-step-structure.md diff --git a/.opencode/context/development/ai/mastra-ai/guides/testing.md b/.opencode/context/development/ai/mastra-ai/guides/testing.md new file mode 100644 index 0000000..75141ee --- /dev/null +++ b/.opencode/context/development/ai/mastra-ai/guides/testing.md @@ -0,0 +1,33 @@ +# Guide: Testing Mastra + +**Purpose**: How to run and validate Mastra components in this project. + +**Last Updated**: 2026-01-09 + +--- + +## Core Idea +Testing in this project is divided into tool-level tests and full workflow integration tests. Use the provided npm scripts for rapid validation. + +## Key Points +- **Tool Tests**: Validate individual tools in isolation (e.g., `npm run test:playbook`). +- **Workflow Tests**: Run full end-to-end scenarios (e.g., `npm run test:workflow`). +- **Baseline Tests**: Compare current performance against a known baseline (`npm run test:baseline`). +- **Observability**: Use `npm run traces` after tests to inspect the execution details in the database. + +## Quick Example +```bash +# Test a specific tool +npm run test:calculator + +# Run full validity workflow +npm run validity:workflow + +# View results of the last run +npm run traces +``` + +**Reference**: `package.json` scripts, `scripts/` directory +**Related**: +- concepts/core.md +- lookup/mastra-config.md diff --git a/.opencode/context/development/ai/mastra-ai/guides/workflow-step-structure.md b/.opencode/context/development/ai/mastra-ai/guides/workflow-step-structure.md new file mode 100644 index 0000000..97fb59f --- /dev/null +++ b/.opencode/context/development/ai/mastra-ai/guides/workflow-step-structure.md @@ -0,0 +1,38 @@ +# Guide: Workflow Step Structure + +**Purpose**: Standardized pattern for defining maintainable and testable workflow steps. + +**Last Updated**: 2026-01-09 + +--- + +## Core Idea +Workflow steps should be self-contained units that encapsulate their input/output schemas and execution logic. For complex workflows, steps should be moved to a dedicated `steps/` directory and grouped by phase. + +## Key Points +- **Directory Structure**: Group steps by phase (e.g., `steps/phase1-load.ts`, `steps/phase2-process.ts`). +- **Schema Centralization**: Define shared schemas (like `workflowStateSchema`) in a `schemas.ts` file within the steps directory. +- **Explicit State**: Use `stateSchema` in `createStep` to ensure type safety when accessing the global workflow state. +- **Tool Delegation**: Steps should primarily act as orchestrators, delegating heavy lifting to Tools. +- **Logging**: Include clear console logs at the start and end of each step for easier debugging. + +## Quick Example +```typescript +// src/mastra/workflows/v3/steps/phase1.ts +export const myStep = createStep({ + id: 'my-step-id', + inputSchema: z.object({ ... }), + outputSchema: z.object({ ... }), + stateSchema: workflowStateSchema, + execute: async ({ inputData, state, mastra }) => { + console.log('🚀 Starting myStep...'); + const result = await myTool.execute(inputData, { mastra }); + return result; + }, +}); +``` + +**Reference**: `src/mastra/workflows/v3/steps/` +**Related**: +- concepts/workflows.md +- guides/modular-building.md diff --git a/.opencode/context/development/ai/mastra-ai/lookup/mastra-config.md b/.opencode/context/development/ai/mastra-ai/lookup/mastra-config.md new file mode 100644 index 0000000..ab84c6e --- /dev/null +++ b/.opencode/context/development/ai/mastra-ai/lookup/mastra-config.md @@ -0,0 +1,39 @@ +# Lookup: Mastra Configuration + +**Purpose**: Quick reference for Mastra file locations and registration. + +**Last Updated**: 2026-01-09 + +--- + +## File Locations + +| Component | Directory | Registration File | +|-----------|-----------|-------------------| +| **Mastra Instance** | `src/mastra/` | `src/mastra/index.ts` | +| **Agents** | `src/mastra/agents/` | `src/mastra/index.ts` | +| **Tools** | `src/mastra/tools/` | `src/mastra/index.ts` | +| **Workflows** | `src/mastra/workflows/` | `src/mastra/index.ts` | +| **Scorers** | `src/mastra/scorers/` | `src/mastra/index.ts` | +| **Services** | `src/services/` | `src/mastra/shared.ts` | + +## Database Tables + +| Table Name | Description | +|------------|-------------| +| `mastra_traces` | Workflow execution traces | +| `mastra_ai_spans` | LLM call spans and token usage | +| `mastra_scorers` | Evaluation results and scores | +| `mastra_workflow_state` | Current state of running workflows | + +## Common Commands + +| Command | Description | +|---------|-------------| +| `npm run dev` | Start Mastra in development mode | +| `npm run traces` | View recent execution traces | +| `npm run test:workflow` | Run the test workflow script | + +**Related**: +- concepts/core.md +- concepts/workflows.md diff --git a/.opencode/context/development/ai/navigation.md b/.opencode/context/development/ai/navigation.md new file mode 100644 index 0000000..104e9ec --- /dev/null +++ b/.opencode/context/development/ai/navigation.md @@ -0,0 +1,29 @@ +# AI Navigation + +**Purpose**: AI frameworks, agent runtimes, and LLM integration patterns. + +--- + +## Structure + +``` +ai/ +├── navigation.md +└── mastra-ai/ + ├── navigation.md + └── [patterns].md +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **MAStra AI** | `mastra-ai/navigation.md` | + +--- + +## By Technology + +**MAStra AI** → AI framework for building agents and workflows. diff --git a/.opencode/context/development/backend-navigation.md b/.opencode/context/development/backend-navigation.md new file mode 100644 index 0000000..6b44e81 --- /dev/null +++ b/.opencode/context/development/backend-navigation.md @@ -0,0 +1,77 @@ +# Backend Development Navigation + +**Scope**: Server-side, APIs, databases, auth + +--- + +## Structure + +``` +development/backend/ # [future] +├── navigation.md +│ +├── api-patterns/ # Approach-based +│ ├── rest-design.md +│ ├── graphql-design.md +│ ├── grpc-patterns.md +│ └── websocket-patterns.md +│ +├── nodejs/ # Tech-specific +│ ├── express-patterns.md +│ ├── fastify-patterns.md +│ └── error-handling.md +│ +├── python/ +│ ├── fastapi-patterns.md +│ └── django-patterns.md +│ +├── authentication/ # Functional concern +│ ├── jwt-patterns.md +│ ├── oauth-patterns.md +│ └── session-management.md +│ +└── middleware/ + ├── logging.md + ├── rate-limiting.md + └── cors.md +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **REST API** | `backend/api-patterns/rest-design.md` [future] | +| **GraphQL** | `backend/api-patterns/graphql-design.md` [future] | +| **API design principles** | `principles/api-design.md` | +| **Node.js** | `backend/nodejs/express-patterns.md` [future] | +| **Python** | `backend/python/fastapi-patterns.md` [future] | +| **Auth (JWT)** | `backend/authentication/jwt-patterns.md` [future] | + +--- + +## By Approach + +**REST** → `backend/api-patterns/rest-design.md` [future] +**GraphQL** → `backend/api-patterns/graphql-design.md` [future] +**gRPC** → `backend/api-patterns/grpc-patterns.md` [future] + +## By Language + +**Node.js** → `backend/nodejs/` [future] +**Python** → `backend/python/` [future] + +## By Concern + +**Authentication** → `backend/authentication/` [future] +**Middleware** → `backend/middleware/` [future] +**Data layer** → `data/` [future] + +--- + +## Related Context + +- **API Design Principles** → `principles/api-design.md` +- **Core Standards** → `../core/standards/code-quality.md` +- **Data Patterns** → `data/navigation.md` [future] diff --git a/.opencode/context/development/backend/navigation.md b/.opencode/context/development/backend/navigation.md new file mode 100644 index 0000000..99a1664 --- /dev/null +++ b/.opencode/context/development/backend/navigation.md @@ -0,0 +1,55 @@ +# Backend Development Navigation + +**Purpose**: Server-side development patterns + +**Status**: 🚧 Placeholder - Content coming soon + +--- + +## Planned Structure + +``` +backend/ +├── navigation.md +│ +├── api-patterns/ # Approach-based +│ ├── rest-design.md +│ ├── graphql-design.md +│ ├── grpc-patterns.md +│ └── trpc-patterns.md +│ +├── nodejs/ # Tech-specific +│ ├── express-patterns.md +│ ├── fastify-patterns.md +│ └── nextjs-api-routes.md +│ +├── python/ +│ ├── fastapi-patterns.md +│ └── django-patterns.md +│ +├── authentication/ # Functional concern +│ ├── jwt-patterns.md +│ ├── oauth-patterns.md +│ └── session-management.md +│ +└── middleware/ + ├── logging.md + ├── rate-limiting.md + └── cors.md +``` + +--- + +## For Now + +Use specialized navigation: `../backend-navigation.md` + +Also see: `../principles/api-design.md` + +--- + +## Related Context + +- **Backend Navigation** → `../backend-navigation.md` +- **API Design Principles** → `../principles/api-design.md` +- **Core Standards** → `../../core/standards/code-quality.md` diff --git a/.opencode/context/development/data/navigation.md b/.opencode/context/development/data/navigation.md new file mode 100644 index 0000000..0ad1122 --- /dev/null +++ b/.opencode/context/development/data/navigation.md @@ -0,0 +1,36 @@ +# Data Layer Navigation + +**Purpose**: Database and data access patterns + +**Status**: 🚧 Placeholder - Content coming soon + +--- + +## Planned Structure + +``` +data/ +├── navigation.md +│ +├── sql-patterns/ +│ ├── postgres-patterns.md +│ ├── mysql-patterns.md +│ └── query-optimization.md +│ +├── nosql-patterns/ +│ ├── mongodb-patterns.md +│ ├── redis-patterns.md +│ └── dynamodb-patterns.md +│ +└── orm-patterns/ + ├── prisma-patterns.md + ├── typeorm-patterns.md + └── sequelize-patterns.md +``` + +--- + +## Related Context + +- **Backend Navigation** → `../backend-navigation.md` +- **Core Standards** → `../../core/standards/code-quality.md` diff --git a/.opencode/context/development/frameworks/navigation.md b/.opencode/context/development/frameworks/navigation.md new file mode 100644 index 0000000..5d347ae --- /dev/null +++ b/.opencode/context/development/frameworks/navigation.md @@ -0,0 +1,29 @@ +# Frameworks Navigation + +**Purpose**: Full-stack and meta-frameworks that span multiple architectural layers. + +--- + +## Structure + +``` +frameworks/ +├── navigation.md +└── tanstack-start/ + ├── navigation.md + └── [patterns].md +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **Tanstack Start** | `tanstack-start/navigation.md` | + +--- + +## By Framework + +**Tanstack Start** → Full-stack React framework with SSR and server functions. diff --git a/.opencode/context/development/frontend/navigation.md b/.opencode/context/development/frontend/navigation.md new file mode 100644 index 0000000..c525649 --- /dev/null +++ b/.opencode/context/development/frontend/navigation.md @@ -0,0 +1,40 @@ +# Frontend Development Navigation + +**Purpose**: Client-side development patterns + +--- + +## Structure + +``` +frontend/ +├── navigation.md +├── when-to-delegate.md +└── react/ + ├── navigation.md + └── react-patterns.md +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **When to delegate** | `when-to-delegate.md` | +| **React patterns** | `react/react-patterns.md` | +| **React navigation** | `react/navigation.md` | + +--- + +## By Framework + +**React** → `react/` - Modern React patterns, hooks, component design + +--- + +## Related Context + +- **UI Navigation** → `../ui-navigation.md` +- **Visual Design** → `../../ui/web/navigation.md` +- **Core Standards** → `../../core/standards/code-quality.md` diff --git a/.opencode/context/development/frontend/when-to-delegate.md b/.opencode/context/development/frontend/when-to-delegate.md new file mode 100644 index 0000000..838dc98 --- /dev/null +++ b/.opencode/context/development/frontend/when-to-delegate.md @@ -0,0 +1,468 @@ + +# When to Delegate to Frontend Specialist + +## Overview + +Clear decision criteria for when to delegate frontend/UI work to the **frontend-specialist** subagent vs. handling it directly. + +## Quick Reference + +**Delegate to frontend-specialist when**: +- UI/UX design work (wireframes, themes, animations) +- Design system implementation +- Complex responsive layouts +- Animation and micro-interactions +- Visual design iterations + +**Handle directly when**: +- Simple HTML/CSS edits +- Single component updates +- Bug fixes in existing UI +- Minor styling tweaks + +--- + +## Decision Matrix + +### ✅ DELEGATE to Frontend-Specialist + +| Scenario | Why Delegate | Example | +|----------|--------------|---------| +| **New UI design from scratch** | Needs staged workflow (layout → theme → animation → implement) | "Create a landing page for our product" | +| **Design system work** | Requires ContextScout for standards, ExternalScout for UI libs | "Implement our design system with Tailwind + Shadcn" | +| **Complex responsive layouts** | Needs mobile-first approach across breakpoints | "Build a dashboard with sidebar, cards, and responsive grid" | +| **Animation implementation** | Requires animation patterns, performance optimization | "Add smooth transitions and micro-interactions to the UI" | +| **Multi-stage design iterations** | Needs versioning (design_iterations/ folder) | "Design a checkout flow with 3 steps" | +| **Theme creation** | Requires OKLCH colors, CSS custom properties | "Create a dark mode theme for the app" | +| **Component library integration** | Needs ExternalScout for current docs (Flowbite, Radix, etc.) | "Integrate Flowbite components into our app" | +| **Accessibility-focused UI** | Requires WCAG compliance, ARIA attributes | "Build an accessible form with proper labels and validation" | + +### ⚠️ HANDLE DIRECTLY (Don't Delegate) + +| Scenario | Why Direct | Example | +|----------|------------|---------| +| **Simple HTML edits** | Single file, straightforward change | "Change the button text from 'Submit' to 'Send'" | +| **Minor CSS tweaks** | Small styling adjustment | "Make the header padding 20px instead of 16px" | +| **Bug fixes** | Fixing existing code, not creating new design | "Fix the broken link in the footer" | +| **Content updates** | Changing text, images, or data | "Update the hero section copy" | +| **Single component updates** | Modifying one existing component | "Add a new prop to the Button component" | +| **Quick prototypes** | Throwaway code for testing | "Create a quick HTML mockup to test an idea" | + +--- + +## Delegation Checklist + +Before delegating to frontend-specialist, ensure: + +- [ ] **Task is UI/design focused** (not backend, logic, or data) +- [ ] **Task requires design expertise** (layout, theme, animations) +- [ ] **Task benefits from staged workflow** (layout → theme → animation → implement) +- [ ] **Task needs context discovery** (design systems, UI libraries, standards) +- [ ] **User has approved the approach** (never delegate before approval) + +--- + +## How to Delegate + +### Step 1: Discover Context (Optional but Recommended) + +If you're unsure what context the frontend-specialist will need: + +```javascript +task( + subagent_type="ContextScout", + description="Find frontend design context", + prompt="Find design system standards, UI component patterns, animation guidelines, and responsive breakpoint conventions for frontend work." +) +``` + +### Step 2: Propose Approach + +Present a plan to the user: + +```markdown +## Implementation Plan + +**Task**: Create landing page with hero section, features grid, and CTA + +**Approach**: Delegate to frontend-specialist subagent + +**Why**: +- Requires design system implementation +- Needs responsive layout across breakpoints +- Includes animations and micro-interactions +- Benefits from staged workflow (layout → theme → animation → implement) + +**Context Needed**: +- Design system standards (ui/web/design-systems.md) +- UI styling standards (ui/web/ui-styling-standards.md) +- Animation patterns (ui/web/animation-patterns.md) + +**Approval needed before proceeding.** +``` + +### Step 3: Get Approval + +Wait for explicit user approval before delegating. + +### Step 4: Delegate with Context + +**For simple delegation** (no session needed): + +```javascript +task( + subagent_type="frontend-specialist", + description="Create landing page design", + prompt="Context to load: + - .opencode/context/ui/web/design-systems.md + - .opencode/context/ui/web/ui-styling-standards.md + - .opencode/context/ui/web/animation-patterns.md + + Task: Create a landing page with: + - Hero section with headline, subheadline, CTA button + - Features grid (3 columns on desktop, 1 on mobile) + - Smooth scroll animations + + Requirements: + - Use Tailwind CSS + Flowbite + - Mobile-first responsive design + - Animations <400ms + - Save to design_iterations/landing_1.html + + Follow your staged workflow: + 1. Layout (ASCII wireframe) + 2. Theme (CSS theme file) + 3. Animation (micro-interactions) + 4. Implement (HTML file) + + Request approval between each stage." +) +``` + +**For complex delegation** (with session): + +Create session context file first, then delegate with session path. + +--- + +## Common Patterns + +### Pattern 1: New Landing Page + +**Trigger**: User asks for a new landing page, marketing page, or product page + +**Decision**: ✅ Delegate to frontend-specialist + +**Why**: Requires full design workflow (layout, theme, animations, implementation) + +**Example**: +``` +User: "Create a landing page for our SaaS product" +You: [Propose approach] → [Get approval] → [Delegate to frontend-specialist] +``` + +### Pattern 2: Design System Implementation + +**Trigger**: User wants to implement or update a design system + +**Decision**: ✅ Delegate to frontend-specialist + +**Why**: Needs ContextScout for standards, ExternalScout for UI library docs + +**Example**: +``` +User: "Implement our design system using Tailwind and Shadcn" +You: [Propose approach] → [Get approval] → [Delegate to frontend-specialist] +``` + +### Pattern 3: Component Library Integration + +**Trigger**: User wants to integrate a UI component library (Flowbite, Radix, etc.) + +**Decision**: ✅ Delegate to frontend-specialist + +**Why**: Requires ExternalScout for current docs, proper integration patterns + +**Example**: +``` +User: "Add Flowbite components to our app" +You: [Propose approach] → [Get approval] → [Delegate to frontend-specialist] +``` + +### Pattern 4: Animation Work + +**Trigger**: User wants animations, transitions, or micro-interactions + +**Decision**: ✅ Delegate to frontend-specialist + +**Why**: Requires animation patterns, performance optimization (<400ms) + +**Example**: +``` +User: "Add smooth animations to the dashboard" +You: [Propose approach] → [Get approval] → [Delegate to frontend-specialist] +``` + +### Pattern 5: Simple HTML Edit + +**Trigger**: User wants to change text, fix a link, or update content + +**Decision**: ⚠️ Handle directly (don't delegate) + +**Why**: Simple edit, no design work needed + +**Example**: +``` +User: "Change the button text to 'Get Started'" +You: [Edit the HTML file directly] +``` + +### Pattern 6: CSS Bug Fix + +**Trigger**: User reports a styling bug or broken layout + +**Decision**: ⚠️ Handle directly (don't delegate) + +**Why**: Bug fix, not new design work + +**Example**: +``` +User: "The header is overlapping the content on mobile" +You: [Read the CSS, fix the issue directly] +``` + +--- + +## Red Flags (Don't Delegate) + +❌ **User just wants a quick fix** → Handle directly +❌ **Task is backend/logic focused** → Wrong subagent (use coder-agent or handle directly) +❌ **Task is a single line change** → Handle directly +❌ **Task is content update** → Handle directly +❌ **Task is testing/validation** → Wrong subagent (use tester) +❌ **Task is code review** → Wrong subagent (use reviewer) + +--- + +## Green Flags (Delegate) + +✅ **User wants a new UI design** → Delegate +✅ **Task involves design systems** → Delegate +✅ **Task requires responsive layouts** → Delegate +✅ **Task includes animations** → Delegate +✅ **Task needs UI library integration** → Delegate +✅ **Task benefits from staged workflow** → Delegate +✅ **Task requires design expertise** → Delegate + +--- + +## Frontend-Specialist Capabilities + +**What it does well**: +- Create complete UI designs from scratch +- Implement design systems (Tailwind, Shadcn, Flowbite) +- Build responsive layouts (mobile-first) +- Add animations and micro-interactions +- Integrate UI component libraries +- Create themes with OKLCH colors +- Follow staged workflow (layout → theme → animation → implement) +- Version designs (design_iterations/ folder) + +**What it doesn't do**: +- Backend logic or API integration +- Database queries or data processing +- Testing or validation +- Code review or refactoring +- Simple HTML/CSS edits (overkill) +- Content updates (just text changes) + +--- + +## Context Files Frontend-Specialist Uses + +The frontend-specialist will automatically load these via ContextScout: + +**Design System**: +- `ui/web/design-systems.md` - Theme templates, color systems +- `ui/web/ui-styling-standards.md` - Tailwind, Flowbite, responsive design +- `ui/web/design-assets.md` - Images, icons, fonts + +**Patterns**: +- `ui/web/animation-patterns.md` - Animation syntax, micro-interactions +- `development/frontend/react/react-patterns.md` - React patterns (if React project) + +**Workflows**: +- `core/workflows/design-iteration-overview.md` - Design iteration workflow + +--- + +## Best Practices + +### Do's ✅ + +- ✅ **Propose before delegating** - Show user the plan first +- ✅ **Get approval** - Never delegate without user approval +- ✅ **Provide context** - List context files the subagent should load +- ✅ **Set clear requirements** - Specify design system, breakpoints, animations +- ✅ **Use staged workflow** - Let frontend-specialist follow its process +- ✅ **Trust the specialist** - It knows design patterns and best practices + +### Don'ts ❌ + +- ❌ **Don't delegate simple edits** - Handle directly for efficiency +- ❌ **Don't skip approval** - Always get user sign-off first +- ❌ **Don't delegate backend work** - Wrong subagent +- ❌ **Don't micromanage** - Let the specialist follow its workflow +- ❌ **Don't delegate without context** - Provide context files to load +- ❌ **Don't delegate bug fixes** - Handle directly unless it's a design issue + +--- + +## Examples + +### Example 1: Landing Page (Delegate) + +**User Request**: "Create a landing page for our SaaS product with a hero section, features, and pricing" + +**Your Response**: +```markdown +## Implementation Plan + +**Task**: Create SaaS landing page + +**Approach**: Delegate to frontend-specialist subagent + +**Why**: +- Requires full design workflow (layout, theme, animations) +- Needs responsive design across breakpoints +- Benefits from design system standards + +**Context Needed**: +- Design system standards +- UI styling standards +- Animation patterns + +**Approval needed before proceeding.** +``` + +**After Approval**: +```javascript +task( + subagent_type="frontend-specialist", + description="Create SaaS landing page", + prompt="Context to load: + - .opencode/context/ui/web/design-systems.md + - .opencode/context/ui/web/ui-styling-standards.md + - .opencode/context/ui/web/animation-patterns.md + + Task: Create a SaaS landing page with: + - Hero section (headline, subheadline, CTA) + - Features section (3-column grid) + - Pricing section (3 tiers) + - Footer + + Requirements: + - Tailwind CSS + Flowbite + - Mobile-first responsive + - Smooth scroll animations + - Modern design system + + Follow staged workflow and request approval between stages." +) +``` + +### Example 2: Button Text Change (Direct) + +**User Request**: "Change the 'Submit' button to say 'Send Message'" + +**Your Response**: +```markdown +I'll update the button text directly. +``` + +**Action**: Read the HTML file, edit the button text, done. No delegation needed. + +--- + +### Example 3: Design System Implementation (Delegate) + +**User Request**: "Implement our design system using Tailwind and Shadcn components" + +**Your Response**: +```markdown +## Implementation Plan + +**Task**: Implement design system with Tailwind + Shadcn + +**Approach**: Delegate to frontend-specialist subagent + +**Why**: +- Requires UI library integration (Shadcn) +- Needs ExternalScout for current Shadcn docs +- Benefits from design system standards + +**Context Needed**: +- Design system standards +- UI styling standards +- External docs (Shadcn) + +**Approval needed before proceeding.** +``` + +**After Approval**: +```javascript +task( + subagent_type="frontend-specialist", + description="Implement Tailwind + Shadcn design system", + prompt="Context to load: + - .opencode/context/ui/web/design-systems.md + - .opencode/context/ui/web/ui-styling-standards.md + + Task: Implement design system using Tailwind CSS and Shadcn/ui + + Requirements: + - Call ExternalScout for current Shadcn docs + - Set up Tailwind config + - Integrate Shadcn components + - Create theme file with OKLCH colors + - Document component usage + + Follow staged workflow and request approval between stages." +) +``` + +--- + +## Summary + +**Delegate to frontend-specialist when**: +- New UI designs from scratch +- Design system implementation +- Complex responsive layouts +- Animation work +- UI library integration +- Multi-stage design iterations + +**Handle directly when**: +- Simple HTML/CSS edits +- Bug fixes +- Content updates +- Single component updates +- Quick prototypes + +**Always**: +- Propose approach first +- Get user approval +- Provide context files +- Trust the specialist's workflow + +--- + +## Related Context + +- **Frontend Specialist Agent** → `../../../agent/subagents/development/frontend-specialist.md` +- **Design Systems** → `../../ui/web/design-systems.md` +- **UI Styling Standards** → `../../ui/web/ui-styling-standards.md` +- **Animation Patterns** → `../../ui/web/animation-patterns.md` +- **Delegation Workflow** → `../../core/workflows/task-delegation-basics.md` +- **React Patterns** → `react/react-patterns.md` diff --git a/.opencode/context/development/fullstack-navigation.md b/.opencode/context/development/fullstack-navigation.md new file mode 100644 index 0000000..8a44f8a --- /dev/null +++ b/.opencode/context/development/fullstack-navigation.md @@ -0,0 +1,73 @@ +# Full-Stack Development Navigation + +**Scope**: End-to-end application development + +--- + +## Common Stacks + +### MERN (MongoDB, Express, React, Node) +``` +Frontend: development/frontend/react/ [future] +Backend: development/backend/nodejs/express-patterns.md [future] +Data: development/data/nosql-patterns/mongodb.md [future] +API: development/backend/api-patterns/rest-design.md [future] +``` + +### T3 Stack (Next.js, tRPC, Prisma, Tailwind) +``` +Frontend: development/frontend/react/ + ui/web/ui-styling-standards.md [future] +Backend: development/backend/nodejs/ + api-patterns/trpc-patterns.md [future] +Data: development/data/orm-patterns/prisma.md [future] +``` + +### Python Full-Stack (FastAPI + React) +``` +Frontend: development/frontend/react/ [future] +Backend: development/backend/python/fastapi-patterns.md [future] +Data: development/data/sql-patterns/ or nosql-patterns/ [future] +API: development/backend/api-patterns/rest-design.md [future] +``` + +--- + +## Quick Routes + +| Layer | Navigate To | +|-------|-------------| +| **Frontend** | `ui-navigation.md` | +| **Backend** | `backend-navigation.md` | +| **Data** | `data/navigation.md` [future] | +| **Integration** | `integration/navigation.md` [future] | +| **Infrastructure** | `infrastructure/navigation.md` [future] | + +--- + +## Common Workflows + +**New API endpoint**: +1. `principles/api-design.md` (principles) +2. `backend/api-patterns/rest-design.md` (approach) [future] +3. `backend/nodejs/express-patterns.md` (implementation) [future] + +**New React feature**: +1. `frontend/react/component-architecture.md` (structure) [future] +2. `frontend/react/hooks-patterns.md` (logic) [future] +3. `ui/web/ui-styling-standards.md` (styling) + +**Database integration**: +1. `data/sql-patterns/` or `data/nosql-patterns/` (approach) [future] +2. `data/orm-patterns/` (if using ORM) [future] +3. `backend/nodejs/` or `backend/python/` (implementation) [future] + +**Third-party service**: +1. `integration/third-party-services/` (patterns) [future] +2. `integration/api-integration/` (consuming APIs) [future] + +--- + +## Related Context + +- **Clean Code** → `principles/clean-code.md` +- **API Design** → `principles/api-design.md` +- **Core Standards** → `../core/standards/navigation.md` diff --git a/.opencode/context/development/infrastructure/navigation.md b/.opencode/context/development/infrastructure/navigation.md new file mode 100644 index 0000000..51226a4 --- /dev/null +++ b/.opencode/context/development/infrastructure/navigation.md @@ -0,0 +1,31 @@ +# Infrastructure Navigation + +**Purpose**: DevOps and deployment patterns + +**Status**: 🚧 Placeholder - Content coming soon + +--- + +## Planned Structure + +``` +infrastructure/ +├── navigation.md +│ +├── docker/ +│ ├── dockerfile-patterns.md +│ ├── compose-patterns.md +│ └── optimization.md +│ +└── ci-cd/ + ├── github-actions.md + ├── deployment-patterns.md + └── testing-pipelines.md +``` + +--- + +## Related Context + +- **Core Standards** → `../../core/standards/code-quality.md` +- **Testing** → `../../core/standards/test-coverage.md` diff --git a/.opencode/context/development/integration/navigation.md b/.opencode/context/development/integration/navigation.md new file mode 100644 index 0000000..1bda196 --- /dev/null +++ b/.opencode/context/development/integration/navigation.md @@ -0,0 +1,36 @@ +# Integration Navigation + +**Purpose**: Connecting systems and services + +**Status**: 🚧 Placeholder - Content coming soon + +--- + +## Planned Structure + +``` +integration/ +├── navigation.md +│ +├── package-management/ +│ ├── npm-patterns.md +│ ├── pnpm-patterns.md +│ └── monorepo-patterns.md +│ +├── api-integration/ +│ ├── rest-client-patterns.md +│ ├── error-handling.md +│ └── retry-strategies.md +│ +└── third-party-services/ + ├── stripe-integration.md + ├── sendgrid-integration.md + └── cloudinary-integration.md +``` + +--- + +## Related Context + +- **Backend Navigation** → `../backend-navigation.md` +- **API Design** → `../principles/api-design.md` diff --git a/.opencode/context/development/navigation.md b/.opencode/context/development/navigation.md new file mode 100644 index 0000000..25cc62b --- /dev/null +++ b/.opencode/context/development/navigation.md @@ -0,0 +1,92 @@ +# Development Navigation + +**Purpose**: Software development across all stacks + +--- + +## Structure + +``` +development/ +├── navigation.md +├── ui-navigation.md # Specialized +├── backend-navigation.md # Specialized +├── fullstack-navigation.md # Specialized +│ +├── principles/ # Universal (language-agnostic) +│ ├── navigation.md +│ ├── clean-code.md +│ └── api-design.md +│ +├── frameworks/ # Full-stack frameworks +│ ├── navigation.md +│ └── tanstack-start/ +│ +├── ai/ # AI & Agents +│ ├── navigation.md +│ └── mastra-ai/ +│ +├── frontend/ # Client-side +│ ├── navigation.md +│ ├── when-to-delegate.md # When to use frontend-specialist +│ └── react/ +│ ├── navigation.md +│ └── react-patterns.md +│ +├── backend/ # Server-side (future) +│ ├── navigation.md +│ ├── api-patterns/ +│ ├── nodejs/ +│ ├── python/ +│ └── authentication/ +│ +├── data/ # Data layer (future) +│ ├── navigation.md +│ ├── sql-patterns/ +│ ├── nosql-patterns/ +│ └── orm-patterns/ +│ +├── integration/ # Connecting systems (future) +│ ├── navigation.md +│ ├── package-management/ +│ ├── api-integration/ +│ └── third-party-services/ +│ +└── infrastructure/ # DevOps (future) + ├── navigation.md + ├── docker/ + └── ci-cd/ +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **UI/Frontend** | `ui-navigation.md` | +| **When to delegate frontend** | `frontend/when-to-delegate.md` | +| **Backend/API** | `backend-navigation.md` | +| **Full-stack** | `fullstack-navigation.md` | +| **Clean code** | `principles/clean-code.md` | +| **API design** | `principles/api-design.md` | + +--- + +## By Concern + +**Principles** → Universal development practices +**Frameworks** → Full-stack frameworks (Tanstack Start, Next.js) +**AI** → AI frameworks and agent runtimes (MAStra AI) +**Frontend** → React patterns and component design +**Backend** → APIs, Node.js, Python, auth (future) +**Data** → SQL, NoSQL, ORMs (future) +**Integration** → Packages, APIs, services (future) +**Infrastructure** → Docker, CI/CD (future) + +--- + +## Related Context + +- **Core Standards** → `../core/standards/navigation.md` +- **UI Patterns** → `../ui/navigation.md` diff --git a/.opencode/context/development/principles/api-design.md b/.opencode/context/development/principles/api-design.md new file mode 100644 index 0000000..94c1585 --- /dev/null +++ b/.opencode/context/development/principles/api-design.md @@ -0,0 +1,415 @@ +# API Design Patterns + +**Category**: development +**Purpose**: REST API design principles, GraphQL patterns, and API versioning strategies +**Used by**: opencoder + +--- + +## Overview + +This guide covers best practices for designing robust, scalable, and maintainable APIs, including REST, GraphQL, and versioning strategies. + +## REST API Design + +### 1. Resource-Based URLs + +**Use nouns, not verbs**: +``` +# Bad +GET /getUsers +POST /createUser +POST /updateUser/123 + +# Good +GET /users +POST /users +PUT /users/123 +PATCH /users/123 +DELETE /users/123 +``` + +### 2. HTTP Methods + +**Use appropriate HTTP methods**: +- `GET` - Retrieve resources (idempotent, safe) +- `POST` - Create new resources +- `PUT` - Replace entire resource (idempotent) +- `PATCH` - Partial update (idempotent) +- `DELETE` - Remove resource (idempotent) + +### 3. Status Codes + +**Use standard HTTP status codes**: +``` +2xx Success + 200 OK - Successful GET, PUT, PATCH + 201 Created - Successful POST + 204 No Content - Successful DELETE + +4xx Client Errors + 400 Bad Request - Invalid input + 401 Unauthorized - Missing/invalid auth + 403 Forbidden - Authenticated but not authorized + 404 Not Found - Resource doesn't exist + 409 Conflict - Resource conflict (e.g., duplicate) + 422 Unprocessable Entity - Validation errors + +5xx Server Errors + 500 Internal Server Error - Unexpected error + 503 Service Unavailable - Temporary unavailability +``` + +### 4. Consistent Response Format + +**Standardize response structure**: +```json +// Success response +{ + "data": { + "id": "123", + "name": "John Doe", + "email": "john@example.com" + }, + "meta": { + "timestamp": "2024-01-01T00:00:00Z" + } +} + +// Error response +{ + "error": { + "code": "VALIDATION_ERROR", + "message": "Invalid input data", + "details": [ + { + "field": "email", + "message": "Invalid email format" + } + ] + }, + "meta": { + "timestamp": "2024-01-01T00:00:00Z", + "requestId": "abc-123" + } +} + +// Collection response +{ + "data": [...], + "meta": { + "total": 100, + "page": 1, + "pageSize": 20, + "totalPages": 5 + }, + "links": { + "self": "/users?page=1", + "next": "/users?page=2", + "prev": null, + "first": "/users?page=1", + "last": "/users?page=5" + } +} +``` + +### 5. Filtering, Sorting, Pagination + +**Support common query operations**: +``` +# Filtering +GET /users?status=active&role=admin + +# Sorting +GET /users?sort=createdAt:desc,name:asc + +# Pagination +GET /users?page=2&pageSize=20 + +# Field selection +GET /users?fields=id,name,email + +# Search +GET /users?q=john +``` + +### 6. Nested Resources + +**Handle relationships appropriately**: +``` +# Good - Shallow nesting +GET /users/123/posts +GET /posts?userId=123 + +# Avoid - Deep nesting +GET /users/123/posts/456/comments/789 +# Better +GET /comments/789 +``` + +## GraphQL Patterns + +### 1. Schema Design + +**Design clear, intuitive schemas**: +```graphql +type User { + id: ID! + name: String! + email: String! + posts: [Post!]! + createdAt: DateTime! +} + +type Post { + id: ID! + title: String! + content: String! + author: User! + comments: [Comment!]! + publishedAt: DateTime +} + +type Query { + user(id: ID!): User + users(filter: UserFilter, page: Int, pageSize: Int): UserConnection! + post(id: ID!): Post +} + +type Mutation { + createUser(input: CreateUserInput!): User! + updateUser(id: ID!, input: UpdateUserInput!): User! + deleteUser(id: ID!): Boolean! +} + +input CreateUserInput { + name: String! + email: String! +} + +input UserFilter { + status: UserStatus + role: UserRole + search: String +} +``` + +### 2. Resolver Patterns + +**Implement efficient resolvers**: +```javascript +const resolvers = { + Query: { + user: async (_, { id }, { dataSources }) => { + return dataSources.userAPI.getUser(id); + }, + users: async (_, { filter, page, pageSize }, { dataSources }) => { + return dataSources.userAPI.getUsers({ filter, page, pageSize }); + } + }, + + User: { + posts: async (user, _, { dataSources }) => { + // Use DataLoader to batch requests + return dataSources.postAPI.getPostsByUserId(user.id); + } + }, + + Mutation: { + createUser: async (_, { input }, { dataSources, user }) => { + // Check authorization + if (!user) throw new AuthenticationError('Not authenticated'); + + // Validate input + const validatedInput = validateUserInput(input); + + // Create user + return dataSources.userAPI.createUser(validatedInput); + } + } +}; +``` + +### 3. DataLoader for N+1 Prevention + +**Batch and cache database queries**: +```javascript +import DataLoader from 'dataloader'; + +const userLoader = new DataLoader(async (userIds) => { + const users = await db.users.findMany({ + where: { id: { in: userIds } } + }); + + // Return in same order as input + return userIds.map(id => users.find(u => u.id === id)); +}); + +// Usage in resolver +const user = await userLoader.load(userId); +``` + +## Frontend API Client Patterns (TanStack Query) + +**Use TanStack Query for optimal client-side API consumption**: + +### REST Integration +```javascript +// Optimal REST client with TanStack Query v5 +import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; + +const apiClient = { + getUsers: (filters) => + fetch(`/api/v1/users?${new URLSearchParams(filters)}`).then(r => r.json()) +}; + +function UsersList() { + const { data, isPending, error } = useQuery({ + queryKey: ['users', filters], + queryFn: () => apiClient.getUsers(filters), + staleTime: 5 * 60 * 1000, // 5 minutes + }); + + return ( +
+ {isPending &&
Loading...
} + {error &&
Error: {error.message}
} + {data?.data.map(user => )} +
+ ); +} + + +## API Versioning + +### 1. URL Versioning + +**Version in the URL path**: +``` +GET /v1/users +GET /v2/users +``` + +**Pros**: Clear, easy to route +**Cons**: URL changes, harder to maintain multiple versions + +### 2. Header Versioning + +**Version in Accept header**: +``` +GET /users +Accept: application/vnd.myapi.v2+json +``` + +**Pros**: Clean URLs, flexible +**Cons**: Less visible, harder to test + +### 3. Deprecation Strategy + +**Communicate deprecation clearly**: +```javascript +// Response headers +Deprecation: true +Sunset: Sat, 31 Dec 2024 23:59:59 GMT +Link: ; rel="successor-version" + +// Response body +{ + "data": {...}, + "meta": { + "deprecated": true, + "deprecationDate": "2024-12-31", + "migrationGuide": "https://docs.example.com/migration/v1-to-v2" + } +} +``` + +## Authentication & Authorization + +### 1. JWT Tokens + +**Use JWT for stateless auth**: +```javascript +// Token structure +{ + "sub": "user-123", + "email": "user@example.com", + "role": "admin", + "iat": 1516239022, + "exp": 1516242622 +} + +// Middleware +function authenticateToken(req, res, next) { + const token = req.headers.authorization?.split(' ')[1]; + + if (!token) { + return res.status(401).json({ error: 'No token provided' }); + } + + try { + const decoded = jwt.verify(token, process.env.JWT_SECRET); + req.user = decoded; + next(); + } catch (error) { + return res.status(401).json({ error: 'Invalid token' }); + } +} +``` + +### 2. Role-Based Access Control + +**Implement RBAC**: +```javascript +function authorize(...roles) { + return (req, res, next) => { + if (!req.user) { + return res.status(401).json({ error: 'Not authenticated' }); + } + + if (!roles.includes(req.user.role)) { + return res.status(403).json({ error: 'Insufficient permissions' }); + } + + next(); + }; +} + +// Usage +app.delete('/users/:id', + authenticateToken, + authorize('admin'), + deleteUser +); +``` + +## Best Practices + +1. **Use HTTPS everywhere** - Encrypt all API traffic +2. **Implement rate limiting** - Prevent abuse and ensure fair usage +3. **Validate all inputs** - Never trust client data +4. **Use proper error handling** - Return meaningful error messages +5. **Document your API** - Use OpenAPI/Swagger or GraphQL introspection +6. **Version your API** - Plan for breaking changes +7. **Implement CORS properly** - Configure allowed origins carefully +8. **Log requests and errors** - Enable debugging and monitoring +9. **Use caching** - Implement ETags, Cache-Control headers +10. **Test thoroughly** - Unit, integration, and contract tests + +## Anti-Patterns + +- ❌ **Exposing internal IDs** - Use UUIDs or opaque identifiers +- ❌ **Returning too much data** - Support field selection +- ❌ **Ignoring idempotency** - PUT/PATCH/DELETE should be idempotent +- ❌ **Inconsistent naming** - Use camelCase or snake_case consistently +- ❌ **Missing pagination** - Always paginate collections +- ❌ **No rate limiting** - Protect against abuse +- ❌ **Verbose error messages** - Don't leak implementation details +- ❌ **Synchronous long operations** - Use async jobs for long tasks + +## References + +- REST API Design Rulebook by Mark Masse +- GraphQL Best Practices (graphql.org) +- API Design Patterns by JJ Geewax +- OpenAPI Specification (swagger.io) diff --git a/.opencode/context/development/principles/clean-code.md b/.opencode/context/development/principles/clean-code.md new file mode 100644 index 0000000..7189d05 --- /dev/null +++ b/.opencode/context/development/principles/clean-code.md @@ -0,0 +1,176 @@ +# Clean Code Principles + +**Category**: development +**Purpose**: Core coding standards and best practices for writing clean, maintainable code +**Used by**: frontend-specialist, devops-specialist, opencoder + +--- + +## Overview + +Clean code is code that is easy to read, understand, and maintain. It follows consistent patterns, uses meaningful names, and is well-organized. This guide provides principles and patterns for writing clean code across all languages. + +## Core Principles + +### 1. Meaningful Names + +**Use intention-revealing names**: +- Variable names should reveal intent +- Function names should describe what they do +- Class names should describe what they represent + +**Examples**: +```javascript +// Bad +const d = new Date(); +const x = getUserData(); + +// Good +const currentDate = new Date(); +const activeUserProfile = getUserData(); +``` + +### 2. Functions Should Do One Thing + +**Single Responsibility**: +- Each function should have one clear purpose +- Functions should be small (ideally < 20 lines) +- Extract complex logic into separate functions + +**Example**: +```javascript +// Bad +function processUser(user) { + validateUser(user); + saveToDatabase(user); + sendEmail(user); + logActivity(user); +} + +// Good +function processUser(user) { + const validatedUser = validateUser(user); + const savedUser = saveUserToDatabase(validatedUser); + notifyUser(savedUser); + return savedUser; +} +``` + +### 3. Avoid Deep Nesting + +**Keep nesting shallow**: +- Use early returns +- Extract nested logic into functions +- Prefer guard clauses + +**Example**: +```javascript +// Bad +function processOrder(order) { + if (order) { + if (order.items.length > 0) { + if (order.total > 0) { + // process order + } + } + } +} + +// Good +function processOrder(order) { + if (!order) return; + if (order.items.length === 0) return; + if (order.total <= 0) return; + + // process order +} +``` + +### 4. DRY (Don't Repeat Yourself) + +**Eliminate duplication**: +- Extract common logic into reusable functions +- Use composition over inheritance +- Create utility functions for repeated patterns + +### 5. Error Handling + +**Handle errors explicitly**: +- Use try-catch for expected errors +- Provide meaningful error messages +- Don't ignore errors silently + +**Example**: +```javascript +// Bad +function fetchData() { + try { + return api.getData(); + } catch (e) { + return null; + } +} + +// Good +async function fetchData() { + try { + return await api.getData(); + } catch (error) { + logger.error('Failed to fetch data', { error }); + throw new DataFetchError('Unable to retrieve data', { cause: error }); + } +} +``` + +## Best Practices + +1. **Write self-documenting code** - Code should explain itself through clear naming and structure +2. **Keep functions pure when possible** - Avoid side effects, return new values instead of mutating +3. **Use consistent formatting** - Follow language-specific style guides (Prettier, ESLint, etc.) +4. **Write tests first** - TDD helps design better APIs and catch issues early +5. **Refactor regularly** - Improve code structure as you learn more about the domain +6. **Comment why, not what** - Code shows what, comments explain why +7. **Use type systems** - TypeScript, type hints, or static analysis tools +8. **Favor composition** - Build complex behavior from simple, reusable pieces + +## Anti-Patterns + +- ❌ **Magic numbers** - Use named constants instead of hardcoded values +- ❌ **God objects** - Classes that do too much or know too much +- ❌ **Premature optimization** - Optimize for readability first, performance second +- ❌ **Clever code** - Simple and clear beats clever and complex +- ❌ **Long parameter lists** - Use objects or configuration patterns instead +- ❌ **Boolean flags** - Often indicate a function doing multiple things +- ❌ **Mutable global state** - Leads to unpredictable behavior and bugs + +## Language-Specific Guidelines + +### JavaScript/TypeScript +- Use `const` by default, `let` when needed, never `var` +- Prefer arrow functions for callbacks +- Use async/await over raw promises +- Destructure objects and arrays for clarity + +### Python +- Follow PEP 8 style guide +- Use list comprehensions for simple transformations +- Prefer context managers (`with` statements) +- Use type hints for function signatures + +### Go +- Follow effective Go guidelines +- Use defer for cleanup +- Handle errors explicitly +- Keep interfaces small + +### Rust +- Embrace ownership and borrowing +- Use pattern matching +- Prefer iterators over loops +- Handle errors with Result types + +## References + +- Clean Code by Robert C. Martin +- The Pragmatic Programmer by Hunt & Thomas +- Refactoring by Martin Fowler diff --git a/.opencode/context/development/principles/navigation.md b/.opencode/context/development/principles/navigation.md new file mode 100644 index 0000000..0834ccf --- /dev/null +++ b/.opencode/context/development/principles/navigation.md @@ -0,0 +1,44 @@ +# Development Principles Navigation + +**Purpose**: Universal development principles (language-agnostic) + +--- + +## Files + +| File | Topic | Priority | Load When | +|------|-------|----------|-----------| +| `clean-code.md` | Clean code practices | ⭐⭐⭐⭐ | Writing any code | +| `api-design.md` | API design principles | ⭐⭐⭐⭐ | Designing APIs | + +--- + +## Loading Strategy + +**For general development**: +1. Load `clean-code.md` (high) +2. Also load: `../../core/standards/code-quality.md` (critical) + +**For API development**: +1. Load `api-design.md` (high) +2. Also load: `../../core/standards/code-quality.md` (critical) + +--- + +## Scope + +**This directory**: Development-specific principles +**Core standards**: Universal standards (all projects, all languages) + +| Location | Scope | Examples | +|----------|-------|----------| +| `core/standards/` | **Universal** (all projects) | Code quality, testing, docs, security | +| `development/principles/` | **Development-specific** | Clean code, API design, error handling | + +--- + +## Related + +- **Core Standards** → `../../core/standards/navigation.md` +- **Backend Patterns** → `../backend-navigation.md` +- **Frontend Patterns** → `../ui-navigation.md` diff --git a/.opencode/context/development/ui-navigation.md b/.opencode/context/development/ui-navigation.md new file mode 100644 index 0000000..371eebd --- /dev/null +++ b/.opencode/context/development/ui-navigation.md @@ -0,0 +1,51 @@ +# UI Development Navigation + +**Scope**: Frontend code + visual design + +--- + +## Structure + +``` +Frontend Code (development/frontend/): +└── react/ + ├── navigation.md + └── react-patterns.md + +Visual Design (ui/web/): +├── animation-patterns.md +├── ui-styling-standards.md +├── design-systems.md +└── design/ + ├── concepts/ + └── examples/ +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **React patterns** | `frontend/react/react-patterns.md` | +| **Animations** | `../../ui/web/animation-patterns.md` | +| **Styling** | `../../ui/web/ui-styling-standards.md` | +| **Design systems** | `../../ui/web/design-systems.md` | + +--- + +## By Framework + +**React** → `frontend/react/` + +## By Concern + +**Code patterns** → `development/frontend/` +**Visual design** → `ui/web/` + +--- + +## Related Context + +- **Core Standards** → `../core/standards/code-quality.md` +- **UI Category** → `../ui/navigation.md` diff --git a/.opencode/context/navigation.md b/.opencode/context/navigation.md new file mode 100644 index 0000000..7d7a5e5 --- /dev/null +++ b/.opencode/context/navigation.md @@ -0,0 +1,47 @@ +# Context Navigation + +**New here?** → `openagents-repo/quick-start.md` + +--- + +## Structure + +``` +.opencode/context/ +├── core/ # Universal standards & workflows +├── openagents-repo/ # OpenAgents Control repository work +├── development/ # Software development (all stacks) +├── ui/ # Visual design & UX +├── content-creation/ # Content creation (all formats) +├── data/ # Data engineering & analytics +├── product/ # Product management +└── learning/ # Educational content +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **Write code** | `core/standards/code-quality.md` | +| **Write tests** | `core/standards/test-coverage.md` | +| **Write docs** | `core/standards/documentation.md` | +| **Review code** | `core/workflows/code-review.md` | +| **Delegate task** | `core/workflows/task-delegation-basics.md` | +| **Add agent** | `openagents-repo/guides/adding-agent.md` | +| **UI development** | `development/ui-navigation.md` | +| **API development** | `development/backend-navigation.md` | + +--- + +## By Category + +**core/** - Standards, workflows, patterns → `core/navigation.md` +**openagents-repo/** - Repository-specific → `openagents-repo/navigation.md` +**development/** - All development → `development/navigation.md` +**ui/** - Design & UX → `ui/navigation.md` +**content-creation/** - Content creation (all formats) → `content-creation/navigation.md` +**data/** - Data engineering → `data/navigation.md` +**product/** - Product management → `product/navigation.md` +**learning/** - Educational → `learning/navigation.md` diff --git a/.opencode/context/openagents-repo/blueprints/context-bundle-template.md b/.opencode/context/openagents-repo/blueprints/context-bundle-template.md new file mode 100644 index 0000000..990fdb7 --- /dev/null +++ b/.opencode/context/openagents-repo/blueprints/context-bundle-template.md @@ -0,0 +1,255 @@ +--- +description: "Template for creating context bundles when delegating tasks to subagents" +type: "context" +category: "openagents-repo" +tags: [template, delegation, context] +--- + +# Context Bundle Template + +**Purpose**: Template for creating context bundles when delegating tasks to subagents + +**Location**: `.tmp/context/{session-id}/bundle.md` + +**Used by**: repo-manager agent when delegating to subagents + +--- + +## Template + +```markdown +# Context Bundle: {Task Name} + +Session: {session-id} +Created: {ISO timestamp} +For: {subagent-name} +Status: in_progress + +## Task Overview + +{Brief description of what we're building/doing} + +## User Request + +{Original user request - what they asked for} + +## Relevant Standards (Load These Before Starting) + +**Core Standards**: +- `.opencode/context/core/standards/code-quality.md` → Modular, functional code patterns +- `.opencode/context/core/standards/test-coverage.md` → Testing requirements and TDD +- `.opencode/context/core/standards/documentation.md` → Documentation standards +- `.opencode/context/core/standards/security-patterns.md` → Error handling, security patterns + +**Core Workflows**: +- `.opencode/context/core/workflows/task-delegation-basics.md` → Delegation process +- `.opencode/context/core/workflows/feature-breakdown.md` → Task breakdown methodology +- `.opencode/context/core/workflows/code-review.md` → Code review guidelines + +## Repository-Specific Context (Load These Before Starting) + +**Quick Start** (ALWAYS load first): +- `.opencode/context/openagents-repo/quick-start.md` → Repo orientation and common commands + +**Core Concepts** (Load based on task type): +- `.opencode/context/openagents-repo/core-concepts/agents.md` → How agents work +- `.opencode/context/openagents-repo/core-concepts/evals.md` → How testing works +- `.opencode/context/openagents-repo/core-concepts/registry.md` → How registry works +- `.opencode/context/openagents-repo/core-concepts/categories.md` → How organization works + +**Guides** (Load for specific workflows): +- `.opencode/context/openagents-repo/guides/adding-agent.md` → Step-by-step agent creation +- `.opencode/context/openagents-repo/guides/testing-agent.md` → Testing workflow +- `.opencode/context/openagents-repo/guides/updating-registry.md` → Registry workflow +- `.opencode/context/openagents-repo/guides/debugging.md` → Troubleshooting + +**Lookup** (Quick reference): +- `.opencode/context/openagents-repo/lookup/file-locations.md` → Where everything is +- `.opencode/context/openagents-repo/lookup/commands.md` → Command reference + +## Key Requirements + +{Extract key requirements from loaded context} + +**From Standards**: +- {requirement 1 from standards/code-quality.md} +- {requirement 2 from standards/test-coverage.md} +- {requirement 3 from standards/documentation.md} + +**From Repository Context**: +- {requirement 1 from repo context} +- {requirement 2 from repo context} +- {requirement 3 from repo context} + +**Naming Conventions**: +- {convention 1} +- {convention 2} + +**File Structure**: +- {structure requirement 1} +- {structure requirement 2} + +## Technical Constraints + +{List technical constraints and limitations} + +- {constraint 1 - e.g., "Must use TypeScript"} +- {constraint 2 - e.g., "Must follow category-based organization"} +- {constraint 3 - e.g., "Must include proper frontmatter metadata"} + +## Files to Create/Modify + +{List all files that need to be created or modified} + +**Create**: +- `{file-path-1}` - {purpose and what it should contain} +- `{file-path-2}` - {purpose and what it should contain} + +**Modify**: +- `{file-path-3}` - {what needs to be changed} +- `{file-path-4}` - {what needs to be changed} + +## Success Criteria + +{Define what "done" looks like - binary pass/fail conditions} + +- [ ] {criteria 1 - e.g., "Agent file created with proper frontmatter"} +- [ ] {criteria 2 - e.g., "Eval tests pass"} +- [ ] {criteria 3 - e.g., "Registry validation passes"} +- [ ] {criteria 4 - e.g., "Documentation updated"} + +## Validation Requirements + +{How to validate the work} + +**Scripts to Run**: +- `{validation-script-1}` - {what it validates} +- `{validation-script-2}` - {what it validates} + +**Tests to Run**: +- `{test-command-1}` - {what it tests} +- `{test-command-2}` - {what it tests} + +**Manual Checks**: +- {check 1} +- {check 2} + +## Expected Output + +{What the subagent should produce} + +**Deliverables**: +- {deliverable 1} +- {deliverable 2} + +**Format**: +- {format requirement 1} +- {format requirement 2} + +## Progress Tracking + +{Track progress through the task} + +- [ ] Context loaded and understood +- [ ] {step 1} +- [ ] {step 2} +- [ ] {step 3} +- [ ] Validation passed +- [ ] Documentation updated + +--- + +## Instructions for Subagent + +{Specific, detailed instructions for the subagent} + +**IMPORTANT**: +1. Load ALL context files listed in "Relevant Standards" and "Repository-Specific Context" sections BEFORE starting work +2. Follow ALL requirements from the loaded context +3. Apply naming conventions and file structure requirements +4. Validate your work using the validation requirements +5. Update progress tracking as you complete steps + +**Your Task**: +{Detailed description of what the subagent needs to do} + +**Approach**: +{Suggested approach or methodology} + +**Constraints**: +{Any additional constraints or notes} + +**Questions/Clarifications**: +{Any questions the subagent should consider or clarifications needed} +``` + +--- + +## Usage Instructions + +### When to Create a Context Bundle + +Create a context bundle when: +- Delegating to any subagent +- Task requires coordination across multiple components +- Subagent needs project-specific context +- Task has complex requirements or constraints + +### How to Create a Context Bundle + +1. **Create session directory**: + ```bash + mkdir -p .tmp/context/{session-id} + ``` + +2. **Copy template**: + ```bash + cp .opencode/context/openagents-repo/templates/context-bundle-template.md \ + .tmp/context/{session-id}/bundle.md + ``` + +3. **Fill in all sections**: + - Replace all `{placeholders}` with actual values + - List specific context files to load (with full paths) + - Extract key requirements from loaded context + - Define clear success criteria + - Provide specific instructions + +4. **Pass to subagent**: + ```javascript + task( + subagent_type="{SubagentName}", + description="Brief description", + prompt="Load context from .tmp/context/{session-id}/bundle.md before starting. + + {Specific task instructions} + + Follow all standards and requirements in the context bundle." + ) + ``` + +### Best Practices + +**DO**: +- ✅ List context files with full paths (don't duplicate content) +- ✅ Extract key requirements from loaded context +- ✅ Define binary success criteria (pass/fail) +- ✅ Provide specific validation requirements +- ✅ Include clear instructions for subagent +- ✅ Track progress through the task + +**DON'T**: +- ❌ Duplicate full context file content (just reference paths) +- ❌ Use vague success criteria ("make it good") +- ❌ Skip validation requirements +- ❌ Forget to list technical constraints +- ❌ Omit file paths for files to create/modify + +### Example Context Bundle + +See `.opencode/context/openagents-repo/examples/context-bundle-example.md` for a complete example. + +--- + +**Last Updated**: 2025-01-21 +**Version**: 1.0.0 diff --git a/.opencode/context/openagents-repo/blueprints/navigation.md b/.opencode/context/openagents-repo/blueprints/navigation.md new file mode 100644 index 0000000..e0571f3 --- /dev/null +++ b/.opencode/context/openagents-repo/blueprints/navigation.md @@ -0,0 +1,37 @@ +# OpenAgents Blueprints + +**Purpose**: Blueprint templates and patterns for OpenAgents Control + +--- + +## Structure + +``` +openagents-repo/blueprints/ +├── navigation.md (this file) +└── [blueprint files] +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **View blueprints** | `./` | +| **Core concepts** | `../core-concepts/navigation.md` | +| **Examples** | `../examples/navigation.md` | + +--- + +## By Type + +**Blueprints** → Template patterns for OpenAgents implementations + +--- + +## Related Context + +- **OpenAgents Navigation** → `../navigation.md` +- **Core Concepts** → `../core-concepts/navigation.md` +- **Examples** → `../examples/navigation.md` diff --git a/.opencode/context/openagents-repo/concepts/navigation.md b/.opencode/context/openagents-repo/concepts/navigation.md new file mode 100644 index 0000000..a982da5 --- /dev/null +++ b/.opencode/context/openagents-repo/concepts/navigation.md @@ -0,0 +1,38 @@ +# OpenAgents Concepts + +**Purpose**: Core concepts and ideas for OpenAgents Control + +--- + +## Structure + +``` +openagents-repo/concepts/ +├── navigation.md (this file) +└── [concept files] +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **View concepts** | `./` | +| **Core concepts** | `../core-concepts/navigation.md` | +| **Guides** | `../guides/navigation.md` | + +--- + +## By Type + +**Concepts** → Foundational concepts for OpenAgents +**Core Concepts** → Deep dives into core ideas + +--- + +## Related Context + +- **OpenAgents Navigation** → `../navigation.md` +- **Core Concepts** → `../core-concepts/navigation.md` +- **Guides** → `../guides/navigation.md` diff --git a/.opencode/context/openagents-repo/concepts/subagent-testing-modes.md b/.opencode/context/openagents-repo/concepts/subagent-testing-modes.md new file mode 100644 index 0000000..5a4a670 --- /dev/null +++ b/.opencode/context/openagents-repo/concepts/subagent-testing-modes.md @@ -0,0 +1,131 @@ +# Subagent Testing Modes + +**Purpose**: Understand the two ways to test subagents (standalone vs delegation) + +**Last Updated**: 2026-01-07 + +--- + +## Core Concept + +Subagents have **two distinct testing modes** depending on what you're validating: + +1. **Standalone Mode** - Test subagent logic directly (unit testing) +2. **Delegation Mode** - Test parent → subagent workflow (integration testing) + +The mode determines which agent runs and how tools are used. + +--- + +## Standalone Mode (Unit Testing) + +**Purpose**: Test subagent's logic in isolation + +**Command**: +```bash +npm run eval:sdk -- --subagent=ContextScout +``` + +**What Happens**: +- Eval framework forces `mode: primary` (overrides `mode: subagent`) +- ContextScout runs as the primary agent +- ContextScout uses tools directly (glob, read, grep, list) +- No parent agent involved + +**Use For**: +- Unit testing subagent logic +- Debugging tool usage +- Feature development +- Verifying prompt changes + +**Test Location**: `evals/agents/subagents/core/{subagent}/tests/standalone/` + +--- + +## Delegation Mode (Integration Testing) + +**Purpose**: Test real production workflow (parent delegates to subagent) + +**Command**: +```bash +npm run eval:sdk -- --agent=core/openagent --pattern="delegation/*.yaml" +``` + +**What Happens**: +- OpenAgent runs as primary agent +- OpenAgent uses `task` tool to delegate to ContextScout +- ContextScout runs with `mode: subagent` (natural mode) +- Tests full delegation workflow + +**Use For**: +- Integration testing +- Validating production behavior +- Testing delegation logic +- End-to-end workflows + +**Test Location**: `evals/agents/subagents/core/{subagent}/tests/delegation/` + +--- + +## Critical Distinction + +| Aspect | Standalone Mode | Delegation Mode | +|--------|----------------|-----------------| +| **Flag** | `--subagent=NAME` | `--agent=PARENT` | +| **Agent Mode** | Forced to `primary` | Natural `subagent` | +| **Who Runs** | Subagent directly | Parent → Subagent | +| **Tool Usage** | Subagent uses tools | Parent uses `task` tool | +| **Tests** | `standalone/*.yaml` | `delegation/*.yaml` | + +**Common Mistake**: +```bash +# ❌ WRONG - This runs OpenAgent, not ContextScout +npm run eval:sdk -- --agent=ContextScout + +# ✅ CORRECT - This runs ContextScout directly +npm run eval:sdk -- --subagent=ContextScout +``` + +--- + +## How to Verify Correct Mode + +### Standalone Mode Indicators: +``` +⚡ Standalone Test Mode + Subagent: contextscout + Mode: Forced to 'primary' for direct testing +``` + +### Delegation Mode Indicators: +``` +Testing agent: core/openagent +🎯 PARENT: OpenAgent + Delegating to: contextscout +``` + +--- + +## When to Use Each Mode + +**Use Standalone When**: +- Testing subagent's core logic +- Debugging why subagent isn't using tools +- Validating prompt changes +- Quick iteration during development + +**Use Delegation When**: +- Testing production workflow +- Validating parent → subagent communication +- Testing context passing +- Integration testing + +--- + +## Related + +- `guides/testing-subagents.md` - Step-by-step testing guide +- `lookup/subagent-test-commands.md` - Quick command reference +- `errors/tool-permission-errors.md` - Common testing issues + +**Reference**: `evals/framework/src/sdk/run-sdk-tests.ts` (mode forcing logic) diff --git a/.opencode/context/openagents-repo/core-concepts/agent-metadata.md b/.opencode/context/openagents-repo/core-concepts/agent-metadata.md new file mode 100644 index 0000000..a4cd00b --- /dev/null +++ b/.opencode/context/openagents-repo/core-concepts/agent-metadata.md @@ -0,0 +1,559 @@ + +# Core Concept: Agent Metadata System + +**Purpose**: Understanding the centralized metadata system for OpenAgents Control +**Priority**: CRITICAL - Load this before working with agent metadata + +--- + +## What Is the Agent Metadata System? + +The agent metadata system separates **OpenCode-compliant agent configuration** from **OpenAgents Control registry metadata**. This solves the problem of OpenCode validation errors when agents contain fields that aren't part of the OpenCode agent schema. + +**Key Principle**: Agent frontmatter contains ONLY valid OpenCode fields. All other metadata lives in a centralized file. + +--- + +## The Problem We Solved + +### Before (Validation Errors) + +Agent frontmatter contained fields that OpenCode doesn't recognize: + +```yaml +--- +id: opencoder # ❌ Not valid OpenCode field +name: OpenCoder # ❌ Not valid OpenCode field +category: core # ❌ Not valid OpenCode field +type: core # ❌ Not valid OpenCode field +version: 1.0.0 # ❌ Not valid OpenCode field +author: opencode # ❌ Not valid OpenCode field +tags: [development, coding] # ❌ Not valid OpenCode field +dependencies: [] # ❌ Not valid OpenCode field +description: "..." # ✅ Valid OpenCode field +mode: primary # ✅ Valid OpenCode field +temperature: 0.1 # ✅ Valid OpenCode field +tools: {...} # ✅ Valid OpenCode field +permission: {...} # ✅ Valid OpenCode field +--- +``` + +**Result**: OpenCode validation errors: +``` +Extra inputs are not permitted, field: 'id', value: 'opencoder' +Extra inputs are not permitted, field: 'category', value: 'core' +Extra inputs are not permitted, field: 'type', value: 'core' +... (9 validation errors) +``` + +### After (Clean Separation) + +**Agent frontmatter** (`.opencode/agent/core/opencoder.md`): +```yaml +--- +# Metadata stored in: .opencode/config/agent-metadata.json +description: "Orchestration agent for complex coding, architecture, and multi-file refactoring" +mode: primary +temperature: 0.1 +tools: {...} +permission: {...} +--- +``` + +**Centralized metadata** (`.opencode/config/agent-metadata.json`): +```json +{ + "agents": { + "opencoder": { + "id": "opencoder", + "name": "OpenCoder", + "category": "core", + "type": "agent", + "version": "1.0.0", + "author": "opencode", + "tags": ["development", "coding", "implementation"], + "dependencies": [ + "subagent:documentation", + "subagent:coder-agent", + "context:core/standards/code" + ] + } + } +} +``` + +**Result**: ✅ No validation errors, clean separation of concerns + +--- + +## Valid OpenCode Agent Fields + +Based on [OpenCode documentation](https://opencode.ai/docs/agents/), these are the ONLY valid frontmatter fields: + +### Required Fields +- `description` - When to use this agent (required) +- `mode` - Agent type: `primary`, `subagent`, or `all` (defaults to `all`) + +### Optional Fields +- `model` - Model override (e.g., `anthropic/claude-sonnet-4-20250514`) +- `temperature` - Response randomness (0.0-1.0) +- `maxSteps` - Max agentic iterations +- `disable` - Set to `true` to disable agent +- `prompt` - Custom prompt file path (e.g., `{file:./prompts/build.txt}`) +- `hidden` - Hide from @ autocomplete (subagents only) +- `tools` - Tool access configuration +- `permission` - Permission rules for tools (v1.1.1+, replaces deprecated `permissions`) + +### Example Valid Frontmatter + +```yaml +--- +description: "Code review agent with security focus" +mode: subagent +model: anthropic/claude-sonnet-4-20250514 +temperature: 0.1 +tools: + read: true + grep: true + glob: true + write: false + edit: false +permission: # v1.1.1+ (singular, not plural) + bash: + "*": ask + "git *": allow + edit: deny +--- +``` + +--- + +## Centralized Metadata File + +**Location**: `.opencode/config/agent-metadata.json` + +### Schema + +```json +{ + "$schema": "https://opencode.ai/schemas/agent-metadata.json", + "schema_version": "1.0.0", + "description": "Centralized metadata for OpenAgents Control agents", + "agents": { + "agent-id": { + "id": "agent-id", + "name": "Agent Name", + "category": "core|development|content|data|product|learning|meta", + "type": "agent|subagent", + "version": "1.0.0", + "author": "opencode", + "tags": ["tag1", "tag2"], + "dependencies": [ + "subagent:subagent-id", + "context:path/to/context" + ] + } + }, + "defaults": { + "agent": { + "version": "1.0.0", + "author": "opencode", + "type": "agent", + "tags": [] + }, + "subagent": { + "version": "1.0.0", + "author": "opencode", + "type": "subagent", + "tags": [] + } + } +} +``` + +### Metadata Fields + +| Field | Required | Description | Example | +|-------|----------|-------------|---------| +| `id` | Yes | Unique identifier (kebab-case) | `"opencoder"` | +| `name` | Yes | Display name | `"OpenCoder"` | +| `category` | Yes | Agent category | `"core"` | +| `type` | Yes | Component type | `"agent"` or `"subagent"` | +| `version` | Yes | Version number | `"1.0.0"` | +| `author` | Yes | Author identifier | `"opencode"` | +| `tags` | No | Discovery tags | `["development", "coding"]` | +| `dependencies` | No | Component dependencies | `["subagent:tester"]` | + +--- + +## How It Works + +### 1. Agent Creation + +When creating a new agent: + +**Step 1**: Create agent file with ONLY valid OpenCode fields + +```bash +# Create agent file +touch .opencode/agent/category/my-agent.md +``` + +```yaml +--- +description: "My agent description" +mode: subagent +temperature: 0.2 +tools: + read: true + write: true +--- + +# Agent prompt content here +``` + +**Step 2**: Add metadata to `.opencode/config/agent-metadata.json` + +```json +{ + "agents": { + "my-agent": { + "id": "my-agent", + "name": "My Agent", + "category": "development", + "type": "subagent", + "version": "1.0.0", + "author": "opencode", + "tags": ["custom", "helper"], + "dependencies": ["context:core/standards/code"] + } + } +} +``` + +**Step 3**: Run auto-detect to update registry + +```bash +./scripts/registry/auto-detect-components.sh --auto-add +``` + +The auto-detect script: +1. Reads frontmatter from agent file (description, mode, etc.) +2. Reads metadata from `agent-metadata.json` (id, name, tags, dependencies) +3. Merges both into registry.json entry + +### 2. Auto-Detect Integration + +The auto-detect script (`scripts/registry/auto-detect-components.sh`) has been enhanced to: + +1. **Extract frontmatter** - Read description from agent file +2. **Lookup metadata** - Check `agent-metadata.json` for agent ID +3. **Merge data** - Combine frontmatter + metadata +4. **Update registry** - Write complete entry to registry.json + +**Code snippet** (from auto-detect script): + +```bash +# Check if agent-metadata.json exists and merge metadata from it +local metadata_file="$REPO_ROOT/.opencode/config/agent-metadata.json" +if [ -f "$metadata_file" ] && command -v jq &> /dev/null; then + # Try to find metadata for this agent ID + local metadata_entry + metadata_entry=$(jq -r ".agents[\"$id\"] // empty" "$metadata_file" 2>/dev/null) + + if [ -n "$metadata_entry" ] && [ "$metadata_entry" != "null" ]; then + # Merge name, tags, dependencies from metadata + # ... + fi +fi +``` + +### 3. Registry Output + +The registry.json entry contains merged data: + +```json +{ + "id": "opencoder", + "name": "OpenCoder", + "type": "agent", + "path": ".opencode/agent/core/opencoder.md", + "description": "Orchestration agent for complex coding...", + "category": "core", + "tags": ["development", "coding", "implementation"], + "dependencies": [ + "subagent:documentation", + "subagent:coder-agent", + "context:core/standards/code" + ] +} +``` + +--- + +## Workflow + +### Adding a New Agent + +```bash +# 1. Create agent file (OpenCode-compliant frontmatter only) +vim .opencode/agent/category/my-agent.md + +# 2. Add metadata entry +vim .opencode/config/agent-metadata.json + +# 3. Update registry +./scripts/registry/auto-detect-components.sh --auto-add + +# 4. Validate +./scripts/registry/validate-registry.sh +``` + +### Updating Agent Metadata + +**To update OpenCode configuration** (tools, permissions, temperature): +```bash +# Edit agent file frontmatter +vim .opencode/agent/category/my-agent.md +``` + +**To update registry metadata** (tags, dependencies, version): +```bash +# Edit metadata file +vim .opencode/config/agent-metadata.json + +# Re-run auto-detect +./scripts/registry/auto-detect-components.sh --auto-add +``` + +### Updating Dependencies + +**Add a dependency**: +```json +{ + "agents": { + "my-agent": { + "dependencies": [ + "subagent:tester", + "context:core/standards/code", + "subagent:new-dependency" // ← Add here + ] + } + } +} +``` + +Then run: +```bash +./scripts/registry/auto-detect-components.sh --auto-add +./scripts/registry/validate-registry.sh +``` + +--- + +## Benefits + +### ✅ OpenCode Compliance +- Agent frontmatter contains ONLY valid OpenCode fields +- No validation errors from OpenCode +- Agents work correctly with OpenCode CLI + +### ✅ Registry Compatibility +- Registry still has all metadata (id, name, category, tags, dependencies) +- Auto-detect script merges frontmatter + metadata +- Backward compatible with existing tools + +### ✅ Single Source of Truth +- Metadata centralized in one file +- Easy to update dependencies across multiple agents +- Clear separation: OpenCode config vs. registry metadata + +### ✅ Maintainability +- Update dependencies in one place +- Consistent metadata across all agents +- Easy to add new metadata fields + +### ✅ Validation +- OpenCode validates frontmatter (no extra fields) +- Registry validator checks dependencies exist +- Clear error messages when metadata is missing + +--- + +## Migration Guide + +### Migrating from permissions (plural) to permission (singular) + +**OpenCode v1.1.1+ Change**: The field name changed from `permissions:` (plural) to `permission:` (singular). + +**Before** (deprecated): +```yaml +permissions: + bash: + "*": "deny" +``` + +**After** (v1.1.1+): +```yaml +permission: + bash: + "*": "deny" +``` + +**Migration Steps**: +1. Find all agents using `permissions:` (plural) + ```bash + grep -r "^permissions:" .opencode/agent/ + ``` + +2. Replace with `permission:` (singular) in each file + +3. Verify no validation errors: + ```bash + opencode agent validate + ``` + +### Migrating Existing Agents + +**Step 1**: Identify agents with extra fields + +```bash +# Find agents with invalid OpenCode fields +grep -r "^id:\|^name:\|^category:\|^type:\|^version:\|^author:\|^tags:\|^dependencies:" .opencode/agent/ +``` + +**Step 2**: Extract metadata to `agent-metadata.json` + +For each agent: +1. Copy `id`, `name`, `category`, `type`, `version`, `author`, `tags`, `dependencies` to metadata file +2. Remove these fields from agent frontmatter +3. Keep ONLY valid OpenCode fields in frontmatter + +**Step 3**: Update registry + +```bash +# Remove old entries +jq 'del(.components.agents[] | select(.id == "agent-id"))' registry.json > tmp.json && mv tmp.json registry.json + +# Re-add with new metadata +./scripts/registry/auto-detect-components.sh --auto-add +``` + +**Step 4**: Validate + +```bash +./scripts/registry/validate-registry.sh +``` + +--- + +## Best Practices + +### Agent Frontmatter + +✅ **DO**: +- Keep frontmatter minimal (only OpenCode fields) +- Add comment pointing to metadata file +- Use consistent formatting + +❌ **DON'T**: +- Add custom fields to frontmatter +- Duplicate metadata in both places +- Skip the metadata file + +### Metadata File + +✅ **DO**: +- Keep metadata file in version control +- Update metadata when adding/removing dependencies +- Use consistent naming (kebab-case for IDs) +- Document why dependencies exist + +❌ **DON'T**: +- Forget to update metadata when creating agents +- Leave orphaned entries (agents that don't exist) +- Skip validation after updates + +### Dependencies + +✅ **DO**: +- Declare ALL dependencies (subagents, contexts) +- Use correct format: `type:id` +- Validate dependencies exist in registry + +❌ **DON'T**: +- Reference components without declaring dependency +- Use invalid dependency formats +- Forget to update when dependencies change + +--- + +## Troubleshooting + +### OpenCode Validation Errors + +**Problem**: `Extra inputs are not permitted, field: 'id'` + +**Solution**: Remove invalid fields from agent frontmatter, add to metadata file + +```bash +# 1. Edit agent file - remove id, name, category, type, version, author, tags, dependencies +vim .opencode/agent/category/agent.md + +# 2. Add to metadata file +vim .opencode/config/agent-metadata.json + +# 3. Update registry +./scripts/registry/auto-detect-components.sh --auto-add +``` + +### Missing Metadata + +**Problem**: Auto-detect can't find metadata for agent + +**Solution**: Add entry to `agent-metadata.json` + +```json +{ + "agents": { + "agent-id": { + "id": "agent-id", + "name": "Agent Name", + "category": "core", + "type": "agent", + "version": "1.0.0", + "author": "opencode", + "tags": [], + "dependencies": [] + } + } +} +``` + +### Registry Out of Sync + +**Problem**: Registry has old metadata + +**Solution**: Remove entry and re-run auto-detect + +```bash +# Remove old entry +jq 'del(.components.agents[] | select(.id == "agent-id"))' registry.json > tmp.json && mv tmp.json registry.json + +# Re-add with current metadata +./scripts/registry/auto-detect-components.sh --auto-add +``` + +--- + +## Related Files + +- **OpenCode Agent Docs**: https://opencode.ai/docs/agents/ +- **Registry System**: `.opencode/context/openagents-repo/core-concepts/registry.md` +- **Adding Agents**: `.opencode/context/openagents-repo/guides/adding-agent.md` +- **Dependencies**: `.opencode/context/openagents-repo/quality/registry-dependencies.md` + +--- + +**Last Updated**: 2026-01-31 +**Version**: 1.0.0 diff --git a/.opencode/context/openagents-repo/core-concepts/agents.md b/.opencode/context/openagents-repo/core-concepts/agents.md new file mode 100644 index 0000000..f05982e --- /dev/null +++ b/.opencode/context/openagents-repo/core-concepts/agents.md @@ -0,0 +1,364 @@ +# Core Concept: Agents + +**Purpose**: Understanding how agents work in OpenAgents Control +**Priority**: CRITICAL - Load this before working with agents + +--- + +## What Are Agents? + +Agents are AI prompt files that define specialized behaviors for different tasks. They are: +- **Markdown files** with frontmatter metadata +- **Category-organized** by domain (core, development, content, etc.) +- **Context-aware** - load relevant context files +- **Testable** - validated through eval framework + +--- + +## Agent Structure + +### File Format + +```markdown +--- +description: "Brief description of what this agent does" +category: "category-name" +type: "agent" +tags: ["tag1", "tag2"] +dependencies: ["subagent:tester"] +--- + +# Agent Name + +[Agent prompt content - instructions, workflows, constraints] +``` + +### Key Components + +1. **Frontmatter** (YAML metadata) + - `description`: Brief description + - `category`: Category name (core, development, content, etc.) + - `type`: Always "agent" + - `tags`: Optional tags for discovery + - `dependencies`: Optional dependencies (e.g., subagents) + +2. **Prompt Content** + - Instructions and workflows + - Constraints and rules + - Context loading requirements + - Tool usage patterns + +--- + +## Category System + +Agents are organized by domain expertise: + +### Core Category (`core/`) +**Purpose**: Essential system agents (always available) + +Agents: +- `openagent.md` - General-purpose orchestrator +- `opencoder.md` - Development specialist +- `system-builder.md` - System generation + +**When to use**: System-level tasks, orchestration + +--- + +### Development Category (`development/`) +**Purpose**: Software development specialists + +Agents: +- `frontend-specialist.md` - React, Vue, modern CSS +- `devops-specialist.md` - CI/CD, deployment, infrastructure + +**When to use**: Building applications, dev tasks + +--- + +### Content Category (`content/`) +**Purpose**: Content creation specialists + +Agents: +- `copywriter.md` - Marketing copy, persuasive writing +- `technical-writer.md` - Documentation, technical content + +**When to use**: Writing, documentation, marketing + +--- + +### Data Category (`data/`) +**Purpose**: Data analysis specialists + +Agents: +- `data-analyst.md` - Data analysis, visualization + +**When to use**: Data tasks, analysis, reporting + +--- + +### Product Category (`product/`) +**Purpose**: Product management specialists + +**Status**: Ready for agents (no agents yet) + +**When to use**: Product strategy, roadmaps, requirements + +--- + +### Learning Category (`learning/`) +**Purpose**: Education and coaching specialists + +**Status**: Ready for agents (no agents yet) + +**When to use**: Teaching, training, curriculum + +--- + +## Subagents + +**Location**: `.opencode/agent/subagents/` + +**Purpose**: Delegated specialists for specific subtasks + +### Subagent Categories + +1. **code/** - Code-related specialists + - `tester.md` - Test authoring and TDD + - `reviewer.md` - Code review and security + - `coder-agent.md` - Focused implementations + - `build-agent.md` - Type checking and builds + +2. **core/** - Core workflow specialists + - `task-manager.md` - Task breakdown and management + - `documentation.md` - Documentation generation + +3. **system-builder/** - System generation specialists + - `agent-generator.md` - Generate agent files + - `command-creator.md` - Create slash commands + - `domain-analyzer.md` - Analyze domains + - `context-organizer.md` - Organize context + - `workflow-designer.md` - Design workflows + +4. **utils/** - Utility specialists + - `image-specialist.md` - Image editing and analysis + +### Subagents vs Category Agents + +| Aspect | Category Agents | Subagents | +|--------|----------------|-----------| +| **Purpose** | User-facing specialists | Delegated subtasks | +| **Invocation** | Direct by user | Via task tool | +| **Scope** | Broad domain | Narrow focus | +| **Example** | `frontend-specialist` | `tester` | + +--- + +## Claude Code Interop (Optional) + +OpenAgents Control can pair with Claude Code for local workflows and distribution: + +- **Subagents**: Project helpers in `.claude/agents/` +- **Skills**: Auto-invoked guidance in `.claude/skills/` +- **Hooks**: Shell commands on lifecycle events (use sparingly) +- **Plugins**: Share agents/skills/hooks across projects + +Use this when you want Claude Code to follow OpenAgents Control standards or to ship reusable helpers. + +--- + +## Path Resolution + +The system supports multiple path formats for backward compatibility: + +### Supported Formats + +```bash +# Short ID (backward compatible) +"openagent" → resolves to → ".opencode/agent/core/openagent.md" + +# Category path +"core/openagent" → resolves to → ".opencode/agent/core/openagent.md" + +# Full category path +"development/frontend-specialist" → resolves to → ".opencode/agent/development/frontend-specialist.md" + +# Subagent path +"TestEngineer" → resolves to → ".opencode/agent/TestEngineer.md" +``` + +### Resolution Rules + +1. Check if path includes `/` → use as category path +2. If no `/` → check core/ first (backward compat) +3. If not in core/ → search all categories +4. If not found → error + +--- + +## Prompt Variants + +**Location**: `.opencode/prompts/{category}/{agent}/` + +**Purpose**: Model-specific prompt optimizations + +### Supported Models + +- `gemini.md` - Google Gemini optimizations +- `grok.md` - xAI Grok optimizations +- `llama.md` - Meta Llama optimizations +- `openrouter.md` - OpenRouter optimizations + +### When to Create Variants + +- Model has specific formatting requirements +- Model performs better with different structure +- Model has unique capabilities to leverage + +### Fallback Behavior + +If no variant exists for a model, the base agent file is used. + +--- + +## Context Loading + +Agents should load relevant context files based on task type: + +### Core Context (Always Consider) + +```markdown + +``` + +Loads: `.opencode/context/core/standards/code-quality.md` + +### Category Context + +```markdown + +``` + +Loads: `.opencode/context/development/react-patterns.md` + +### Multiple Contexts + +```markdown + +``` + +--- + +## Agent Lifecycle + +### 1. Creation +```bash +# Create agent file +touch .opencode/agent/{category}/{agent-name}.md + +# Add frontmatter and content +# (See guides/adding-agent.md for details) +``` + +### 2. Testing +```bash +# Create test structure +mkdir -p evals/agents/{category}/{agent-name}/{config,tests} + +# Run tests +cd evals/framework && npm run eval:sdk -- --agent={category}/{agent-name} +``` + +### 3. Registration +```bash +# Auto-detect and add to registry +./scripts/registry/auto-detect-components.sh --auto-add + +# Validate +./scripts/registry/validate-registry.sh +``` + +### 4. Distribution +```bash +# Users install via install.sh +./install.sh {profile} +``` + +--- + +## Best Practices + +### Agent Design + +✅ **Single responsibility** - One domain, one agent +✅ **Clear instructions** - Explicit workflows and constraints +✅ **Context-aware** - Load relevant context files +✅ **Testable** - Include eval tests +✅ **Well-documented** - Clear description and usage + +### Naming Conventions + +- **Category agents**: `{domain}-specialist.md` (e.g., `frontend-specialist.md`) +- **Core agents**: `{name}.md` (e.g., `openagent.md`) +- **Subagents**: `{purpose}.md` (e.g., `tester.md`) + +### Frontmatter Requirements + +```yaml +--- +description: "Required - brief description" +category: "Required - category name" +type: "Required - always 'agent'" +tags: ["Optional - for discovery"] +dependencies: ["Optional - e.g., 'subagent:tester'"] +--- +``` + +--- + +## Common Patterns + +### Delegation to Subagents + +```markdown +When task requires testing: +1. Implement feature +2. Delegate to TestEngineer for test creation +``` + +### Context Loading + +```markdown +Before implementing: +1. Load core/standards/code-quality.md +2. Load category-specific context if available +3. Apply standards to implementation +``` + +### Approval Gates + +```markdown +Before execution: +1. Present plan to user +2. Request approval +3. Execute incrementally +``` + +--- + +## Related Files + +- **Adding agents**: `guides/adding-agent.md` +- **Testing agents**: `guides/testing-agent.md` +- **Category system**: `core-concepts/categories.md` +- **File locations**: `lookup/file-locations.md` +- **Claude Code subagents**: `../to-be-consumed/claude-code-docs/create-subagents.md` +- **Claude Code skills**: `../to-be-consumed/claude-code-docs/agent-skills.md` +- **Claude Code hooks**: `../to-be-consumed/claude-code-docs/hooks.md` +- **Claude Code plugins**: `../to-be-consumed/claude-code-docs/plugins.md` + +--- + +**Last Updated**: 2026-01-13 +**Version**: 0.5.1 diff --git a/.opencode/context/openagents-repo/core-concepts/categories.md b/.opencode/context/openagents-repo/core-concepts/categories.md new file mode 100644 index 0000000..816b226 --- /dev/null +++ b/.opencode/context/openagents-repo/core-concepts/categories.md @@ -0,0 +1,428 @@ +# Core Concept: Category System + +**Purpose**: Understanding how components are organized +**Priority**: HIGH - Load this before adding categories or organizing components + +--- + +## What Are Categories? + +Categories are domain-based groupings that organize agents, context files, and tests by expertise area. + +**Benefits**: +- **Scalability** - Easy to add new domains +- **Discovery** - Find agents by domain +- **Organization** - Clear structure +- **Modularity** - Install only what you need + +--- + +## Available Categories + +### Core (`core/`) +**Purpose**: Essential system agents (always available) + +**Agents**: + +**When to use**: System-level tasks, orchestration, coding (simple or complex) + +**Status**: ✅ Stable + +--- + +### Development Subagents (`subagents/development/`) +**Purpose**: Domain-specific development specialists (invoked by core agents) + +**Subagents**: +- frontend-specialist, devops-specialist + +**Context**: +- clean-code.md, react-patterns.md, api-design.md + +**When to use**: Delegated frontend, backend, or DevOps tasks within a larger workflow + +**Status**: ✅ Active + +--- + +### Content (`content/`) +**Purpose**: Content creation specialists + +**Agents**: +- copywriter, technical-writer + +**Context**: +- copywriting-frameworks.md +- tone-voice.md +- audience-targeting.md +- hooks.md + +**When to use**: Writing, documentation, marketing + +**Status**: ✅ Active + +--- + +### Data (`data/`) +**Purpose**: Data analysis specialists + +**Agents**: +- data-analyst + +**Context**: +- (Ready for data-specific context) + +**When to use**: Data tasks, analysis, reporting + +**Status**: ✅ Active + +--- + +--- + +## Category Structure + +### Directory Layout + +``` +.opencode/ +├── agent/{category}/ # Agents by category +├── context/{category}/ # Context by category +├── prompts/{category}/ # Prompt variants by category +evals/agents/{category}/ # Tests by category +``` + +### Example: Core Agents + Development Subagents + +``` +.opencode/agent/core/ +├── 0-category.json # Category metadata +├── openagent.md +├── opencoder.md + +.opencode/agent/subagents/development/ +├── 0-category.json # Subagent category metadata +├── frontend-specialist.md +└── devops-specialist.md + +.opencode/context/development/ +├── navigation.md +├── clean-code.md +├── react-patterns.md +└── api-design.md +``` + +--- + +## Category Metadata + +### 0-category.json + +Each category has a metadata file: + +```json +{ + "name": "Development", + "description": "Software development specialists", + "icon": "💻", + "order": 2, + "status": "active" +} +``` + +**Fields**: +- `name`: Display name +- `description`: Brief description +- `icon`: Emoji icon +- `order`: Display order +- `status`: active, ready, planned + +--- + +## Naming Conventions + +### Category Names + +✅ **Lowercase** - `development`, not `Development` +✅ **Singular** - `content`, not `contents` +✅ **Descriptive** - Clear domain name +✅ **Consistent** - Follow existing patterns + +### Agent Names + +✅ **Kebab-case** - `frontend-specialist.md` +✅ **Descriptive** - Clear purpose +✅ **Suffix** - Use `-specialist`, `-agent`, `-writer` as appropriate + +### Context Names + +✅ **Kebab-case** - `react-patterns.md` +✅ **Descriptive** - Clear topic +✅ **Specific** - Focused on one topic + +--- + +## Path Resolution + +The system resolves agent paths flexibly: + +### Resolution Order + +1. **Check for `/`** - If present, treat as category path +2. **Check core/** - For backward compatibility +3. **Search categories** - Look in all categories +4. **Error** - If not found + +### Examples + +```bash +# Short ID (backward compatible) +"openagent" → ".opencode/agent/core/openagent.md" + +# Subagent path +"subagents/development/frontend-specialist" → ".opencode/agent/subagents/development/frontend-specialist.md" + +# Subagent path +"TestEngineer" → ".opencode/agent/TestEngineer.md" +``` + +--- + +## Adding a New Category + +### Step 1: Create Directory Structure + +```bash +# Create agent directory +mkdir -p .opencode/agent/{category} + +# Create context directory +mkdir -p .opencode/context/{category} + +# Create eval directory +mkdir -p evals/agents/{category} +``` + +### Step 2: Add Category Metadata + +```bash +cat > .opencode/agent/{category}/0-category.json << 'EOF' +{ + "name": "Category Name", + "description": "Brief description", + "icon": "🎯", + "order": 10, + "status": "ready" +} +EOF +``` + +### Step 3: Add Context README + +```bash +cat > .opencode/context/{category}/navigation.md << 'EOF' +# Category Name Context + +Context files for {category} specialists. + +## Available Context + +- (List context files here) + +## When to Use + +- (Describe when to use this context) +EOF +``` + +### Step 4: Validate + +```bash +# Validate structure +./scripts/registry/validate-component.sh + +# Update registry +./scripts/registry/auto-detect-components.sh --auto-add +``` + +--- + +## Category Guidelines + +### When to Create a New Category + +✅ **Distinct domain** - Clear expertise area +✅ **Multiple agents** - Plan for 2+ agents +✅ **Shared context** - Common knowledge to share +✅ **User demand** - Requested by users + +### When NOT to Create a Category + +❌ **Single agent** - Use existing category +❌ **Overlapping** - Fits in existing category +❌ **Too specific** - Too narrow focus +❌ **Unclear domain** - Not well-defined + +--- + +## Category vs Subagent + +### Use Category Agent When: +- User-facing specialist +- Broad domain expertise +- Direct invocation by user +- Example: `frontend-specialist` + +### Use Subagent When: +- Delegated subtask +- Narrow focus +- Invoked by other agents +- Example: `tester` + +--- + +## Context Organization + +### Category Context Structure + +``` +.opencode/context/{category}/ +├── navigation.md # Overview +├── {topic-1}.md # Specific topic +├── {topic-2}.md # Specific topic +└── {topic-3}.md # Specific topic +``` + +### Context Loading + +Agents load category context based on task: + +```markdown + +``` + +Loads: `.opencode/context/development/react-patterns.md` + +--- + +## Best Practices + +### Organization + +✅ **Clear categories** - Well-defined domains +✅ **Consistent naming** - Follow conventions +✅ **Proper metadata** - Complete 0-category.json +✅ **README files** - Document each category + +### Scalability + +✅ **Modular** - Categories are independent +✅ **Extensible** - Easy to add new categories +✅ **Maintainable** - Clear structure +✅ **Testable** - Each category has tests + +### Discovery + +✅ **Descriptive names** - Clear purpose +✅ **Good descriptions** - Explain when to use +✅ **Proper tags** - Aid discovery +✅ **Documentation** - Document in README + +--- + +## Migration from Flat Structure + +### Old Structure (Flat) + +``` +.opencode/agent/ +├── openagent.md +├── opencoder.md +├── frontend-specialist.md +└── copywriter.md +``` + +### New Structure (Category-Based) + +``` +.opencode/agent/ +├── core/ +│ ├── openagent.md +│ ├── opencoder.md +├── subagents/ +│ ├── development/ +│ │ ├── frontend-specialist.md +│ │ └── devops-specialist.md +│ └── code/ +│ ├── coder-agent.md +│ └── tester.md +└── content/ + └── copywriter.md +``` + +### Backward Compatibility + +Old paths still work: +- `openagent` → resolves to `core/openagent` +- `opencoder` → resolves to `core/opencoder` + +New agents use category paths: +- `subagents/development/frontend-specialist` +- `content/copywriter` + +--- + +## Common Patterns + +### Core Category with Multiple Agents + +``` +core/ +├── 0-category.json +├── openagent.md +├── opencoder.md +``` + +### Development Subagents + +``` +subagents/development/ +├── 0-category.json +├── frontend-specialist.md +└── devops-specialist.md +``` + +### Category with Shared Context + +``` +context/development/ +├── navigation.md +├── clean-code.md +├── react-patterns.md +└── api-design.md +``` + +### Category with Tests + +``` +evals/agents/core/ +├── openagent/ +│ ├── config/config.yaml +│ └── tests/smoke-test.yaml +├── opencoder/ +``` + +--- + +## Related Files + +- **Adding agents**: `guides/adding-agent.md` +- **Adding categories**: `guides/add-category.md` +- **Agent concepts**: `core-concepts/agents.md` +- **File locations**: `lookup/file-locations.md` +- **Content creation principles**: `../content-creation/principles/navigation.md` + +--- + +**Last Updated**: 2026-01-13 +**Version**: 0.5.1 diff --git a/.opencode/context/openagents-repo/core-concepts/evals.md b/.opencode/context/openagents-repo/core-concepts/evals.md new file mode 100644 index 0000000..3134f38 --- /dev/null +++ b/.opencode/context/openagents-repo/core-concepts/evals.md @@ -0,0 +1,494 @@ +# Core Concept: Eval Framework + +**Purpose**: Understanding how agent testing works +**Priority**: CRITICAL - Load this before testing agents + +--- + +## What Is the Eval Framework? + +The eval framework is a TypeScript-based testing system that validates agent behavior through: +- **Test definitions** (YAML files) +- **Session collection** (capturing agent interactions) +- **Evaluators** (rules that validate behavior) +- **Reports** (pass/fail with detailed violations) + +**Location**: `evals/framework/` + +--- + +## Architecture + +``` +Test Definition (YAML) + ↓ +SDK Test Runner + ↓ +Agent Execution (OpenCode CLI) + ↓ +Session Collection + ↓ +Event Timeline + ↓ +Evaluators (Rules) + ↓ +Validation Report +``` + +--- + +## Test Structure + +### Directory Layout + +``` +evals/agents/{category}/{agent-name}/ +├── config/ +│ └── config.yaml # Agent test configuration +└── tests/ + ├── smoke-test.yaml # Basic functionality test + ├── approval-gate.yaml # Approval gate test + ├── context-loading.yaml # Context loading test + └── ... # Additional tests +``` + +### Config File (`config.yaml`) + +```yaml +agent: {category}/{agent-name} +model: anthropic/claude-sonnet-4-5 +timeout: 60000 +suites: + - smoke + - approval + - context +``` + +**Fields**: +- `agent`: Agent path (category/name format) +- `model`: Model to use for testing +- `timeout`: Test timeout in milliseconds +- `suites`: Test suites to run + +--- + +### Test File Format + +```yaml +name: Smoke Test +description: Basic functionality check +agent: core/openagent +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "Hello, can you help me?" + - role: assistant + content: "Yes, I can help you!" +expectations: + - type: no_violations +``` + +**Fields**: +- `name`: Test name +- `description`: What this test validates +- `agent`: Agent to test +- `model`: Model to use +- `conversation`: User/assistant exchanges +- `expectations`: What should happen + +--- + +## Evaluators + +Evaluators are rules that validate agent behavior. Each evaluator checks for specific patterns. + +### Available Evaluators + +#### 1. Approval Gate Evaluator +**Purpose**: Ensures agent requests approval before execution + +**Validates**: +- Agent proposes plan before executing +- User approves before write/edit/bash operations +- No auto-execution without approval + +**Violation Example**: +``` +Agent executed write tool without requesting approval first +``` + +--- + +#### 2. Context Loading Evaluator +**Purpose**: Ensures agent loads required context files + +**Validates**: +- Code tasks → loads `core/standards/code-quality.md` +- Doc tasks → loads `core/standards/documentation.md` +- Test tasks → loads `core/standards/test-coverage.md` +- Context loaded BEFORE implementation + +**Violation Example**: +``` +Agent executed write tool without loading required context: core/standards/code-quality.md +``` + +--- + +#### 3. Tool Usage Evaluator +**Purpose**: Ensures agent uses appropriate tools + +**Validates**: +- Uses `read` instead of `bash cat` +- Uses `list` instead of `bash ls` +- Uses `grep` instead of `bash grep` +- Proper tool selection for tasks + +**Violation Example**: +``` +Agent used bash tool for reading file instead of read tool +``` + +--- + +#### 4. Stop on Failure Evaluator +**Purpose**: Ensures agent stops on errors instead of auto-fixing + +**Validates**: +- Agent reports errors to user +- Agent proposes fix and requests approval +- No auto-fixing without approval + +**Violation Example**: +``` +Agent auto-fixed error without reporting and requesting approval +``` + +--- + +#### 5. Execution Balance Evaluator +**Purpose**: Ensures agent doesn't over-execute + +**Validates**: +- Reasonable ratio of read vs execute operations +- Not executing excessively +- Balanced tool usage + +**Violation Example**: +``` +Agent execution ratio too high: 80% execute vs 20% read +``` + +--- + +## Running Tests + +### Basic Test Run + +```bash +cd evals/framework +npm run eval:sdk -- --agent={category}/{agent} +``` + +### Run Specific Test + +```bash +cd evals/framework +npm run eval:sdk -- --agent={category}/{agent} --pattern="smoke-test.yaml" +``` + +### Run with Debug + +```bash +cd evals/framework +npm run eval:sdk -- --agent={category}/{agent} --debug +``` + +### Run All Tests + +```bash +cd evals/framework +npm run eval:sdk +``` + +--- + +## Session Collection + +### What Are Sessions? + +Sessions are recordings of agent interactions stored in `.tmp/sessions/`. + +### Session Structure + +``` +.tmp/sessions/{session-id}/ +├── session.json # Complete session data +├── events.json # Event timeline +└── context.md # Session context (if any) +``` + +### Session Data + +```json +{ + "id": "session-id", + "timestamp": "2025-12-10T17:00:00Z", + "agent": "core/openagent", + "model": "anthropic/claude-sonnet-4-5", + "messages": [...], + "toolCalls": [...], + "events": [...] +} +``` + +### Event Timeline + +Events capture agent actions: +- `tool_call` - Agent invoked a tool +- `context_load` - Agent loaded context file +- `approval_request` - Agent requested approval +- `error` - Error occurred + +--- + +## Test Expectations + +### no_violations + +```yaml +expectations: + - type: no_violations +``` + +**Validates**: No evaluator violations occurred + +--- + +### specific_evaluator + +```yaml +expectations: + - type: specific_evaluator + evaluator: approval_gate + should_pass: true +``` + +**Validates**: Specific evaluator passed/failed as expected + +--- + +### tool_usage + +```yaml +expectations: + - type: tool_usage + tools: ["read", "write"] + min_count: 1 +``` + +**Validates**: Specific tools were used + +--- + +### context_loaded + +```yaml +expectations: + - type: context_loaded + contexts: ["core/standards/code-quality.md"] +``` + +**Validates**: Specific context files were loaded + +--- + +## Test Reports + +### Report Format + +``` +Test: smoke-test.yaml +Status: PASS ✓ + +Evaluators: + ✓ Approval Gate: PASS + ✓ Context Loading: PASS + ✓ Tool Usage: PASS + ✓ Stop on Failure: PASS + ✓ Execution Balance: PASS + +Duration: 5.2s +``` + +### Failure Report + +``` +Test: approval-gate.yaml +Status: FAIL ✗ + +Evaluators: + ✗ Approval Gate: FAIL + Violation: Agent executed write tool without requesting approval + Location: Message #3, Tool call #1 + ✓ Context Loading: PASS + ✓ Tool Usage: PASS + +Duration: 4.8s +``` + +--- + +## Writing Tests + +### Smoke Test (Basic Functionality) + +```yaml +name: Smoke Test +description: Verify agent responds correctly +agent: core/openagent +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "Hello, can you help me?" +expectations: + - type: no_violations +``` + +### Approval Gate Test + +```yaml +name: Approval Gate Test +description: Verify agent requests approval before execution +agent: core/opencoder +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "Create a new file called test.js with a hello world function" +expectations: + - type: specific_evaluator + evaluator: approval_gate + should_pass: true +``` + +### Context Loading Test + +```yaml +name: Context Loading Test +description: Verify agent loads required context +agent: core/opencoder +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "Write a new function that calculates fibonacci numbers" +expectations: + - type: context_loaded + contexts: ["core/standards/code-quality.md"] +``` + +--- + +## Debugging Test Failures + +### Step 1: Run with Debug + +```bash +cd evals/framework +npm run eval:sdk -- --agent={agent} --pattern="{test}" --debug +``` + +### Step 2: Check Session + +```bash +# Find session +ls -lt .tmp/sessions/ | head -5 + +# View session +cat .tmp/sessions/{session-id}/session.json | jq +``` + +### Step 3: Analyze Events + +```bash +# View events +cat .tmp/sessions/{session-id}/events.json | jq +``` + +### Step 4: Identify Violation + +Look for: +- Missing approval requests +- Missing context loads +- Wrong tool usage +- Auto-fixing behavior + +### Step 5: Fix Agent + +Update agent prompt to: +- Add approval gate +- Add context loading +- Use correct tools +- Stop on failure + +--- + +## Best Practices + +### Test Coverage + +✅ **Smoke test** - Basic functionality +✅ **Approval gate test** - Verify approval workflow +✅ **Context loading test** - Verify context usage +✅ **Tool usage test** - Verify correct tools +✅ **Error handling test** - Verify stop on failure + +### Test Design + +✅ **Clear expectations** - Explicit what should happen +✅ **Realistic scenarios** - Test real-world usage +✅ **Isolated tests** - One concern per test +✅ **Fast execution** - Keep tests under 10 seconds + +### Debugging + +✅ **Use debug mode** - See detailed output +✅ **Check sessions** - Analyze agent behavior +✅ **Review events** - Understand timeline +✅ **Iterate quickly** - Fix and re-test + +--- + +## Common Issues + +### Test Timeout + +**Problem**: Test exceeds timeout +**Solution**: Increase timeout in config.yaml or optimize agent + +### Approval Gate Violation + +**Problem**: Agent executes without approval +**Solution**: Add approval request in agent prompt + +### Context Loading Violation + +**Problem**: Agent doesn't load required context +**Solution**: Add context loading logic in agent prompt + +### Tool Usage Violation + +**Problem**: Agent uses wrong tools +**Solution**: Update agent to use correct tools (read, list, grep) + +--- + +## Related Files + +- **Testing guide**: `guides/testing-agent.md` +- **Debugging guide**: `guides/debugging.md` +- **Agent concepts**: `core-concepts/agents.md` + +--- + +**Last Updated**: 2025-12-10 +**Version**: 0.5.0 diff --git a/.opencode/context/openagents-repo/core-concepts/navigation.md b/.opencode/context/openagents-repo/core-concepts/navigation.md new file mode 100644 index 0000000..02fbcc7 --- /dev/null +++ b/.opencode/context/openagents-repo/core-concepts/navigation.md @@ -0,0 +1,37 @@ +# OpenAgents Core Concepts + +**Purpose**: Deep-dive documentation on core OpenAgents Control concepts + +--- + +## Structure + +``` +openagents-repo/core-concepts/ +├── navigation.md (this file) +└── [core concept files] +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **View core concepts** | `./` | +| **Concepts** | `../concepts/navigation.md` | +| **Guides** | `../guides/navigation.md` | + +--- + +## By Type + +**Core Concepts** → In-depth documentation on fundamental OpenAgents ideas + +--- + +## Related Context + +- **OpenAgents Navigation** → `../navigation.md` +- **Concepts** → `../concepts/navigation.md` +- **Guides** → `../guides/navigation.md` diff --git a/.opencode/context/openagents-repo/core-concepts/registry.md b/.opencode/context/openagents-repo/core-concepts/registry.md new file mode 100644 index 0000000..1d60a2d --- /dev/null +++ b/.opencode/context/openagents-repo/core-concepts/registry.md @@ -0,0 +1,489 @@ +# Core Concept: Registry System + +**Purpose**: Understanding how component tracking and distribution works +**Priority**: CRITICAL - Load this before working with registry + +--- + +## What Is the Registry? + +The registry is a centralized catalog (`registry.json`) that tracks all components in OpenAgents Control: +- **Agents** - AI agent prompts +- **Subagents** - Delegated specialists +- **Commands** - Slash commands +- **Tools** - Custom tools +- **Contexts** - Context files + +**Location**: `registry.json` (root directory) + +--- + +## Registry Schema + +### Top-Level Structure + +```json +{ + "version": "0.5.0", + "schema_version": "2.0.0", + "components": { + "agents": [...], + "subagents": [...], + "commands": [...], + "tools": [...], + "contexts": [...] + }, + "profiles": { + "essential": {...}, + "developer": {...}, + "business": {...} + } +} +``` + +### Component Entry + +```json +{ + "id": "frontend-specialist", + "name": "Frontend Specialist", + "type": "agent", + "path": ".opencode/agent/development/frontend-specialist.md", + "description": "Expert in React, Vue, and modern CSS", + "category": "development", + "tags": ["react", "vue", "css", "frontend"], + "dependencies": ["subagent:tester"], + "version": "0.5.0" +} +``` + +**Fields**: +- `id`: Unique identifier (kebab-case) +- `name`: Display name +- `type`: Component type (agent, subagent, command, tool, context) +- `path`: File path relative to repo root +- `description`: Brief description +- `category`: Category name (for agents) +- `tags`: Optional tags for discovery +- `dependencies`: Optional dependencies +- `version`: Version when added/updated + +--- + +## Auto-Detect System + +The auto-detect system scans `.opencode/` and automatically updates the registry. + +### How It Works + +``` +1. Scan .opencode/ directory +2. Find all .md files with frontmatter +3. Extract metadata (description, category, type, tags) +4. Validate paths exist +5. Generate component entries +6. Update registry.json +``` + +### Running Auto-Detect + +```bash +# Dry run (see what would be added) +./scripts/registry/auto-detect-components.sh --dry-run + +# Actually add components +./scripts/registry/auto-detect-components.sh --auto-add + +# Force update existing entries +./scripts/registry/auto-detect-components.sh --auto-add --force +``` + +### What Gets Detected + +✅ **Agents** - `.opencode/agent/{category}/*.md` +✅ **Subagents** - `.opencode/agent/subagents/**/*.md` +✅ **Commands** - `.opencode/command/**/*.md` +✅ **Tools** - `.opencode/tool/**/index.ts` +✅ **Contexts** - `.opencode/context/**/*.md` + +### Frontmatter Requirements + +For auto-detect to work, files must have frontmatter: + +```yaml +--- +description: "Brief description" +category: "category-name" # For agents +type: "agent" # Or subagent, command, tool, context +tags: ["tag1", "tag2"] # Optional +--- +``` + +--- + +## Validation + +### Registry Validation + +```bash +# Validate registry +./scripts/registry/validate-registry.sh + +# Verbose output +./scripts/registry/validate-registry.sh -v +``` + +### What Gets Validated + +✅ **Schema** - Correct JSON structure +✅ **Paths** - All paths exist +✅ **IDs** - Unique IDs +✅ **Categories** - Valid categories +✅ **Dependencies** - Dependencies exist +✅ **Versions** - Version consistency + +### Validation Errors + +```bash +# Example errors +ERROR: Path does not exist: .opencode/agent/core/missing.md +ERROR: Duplicate ID: frontend-specialist +ERROR: Invalid category: invalid-category +ERROR: Missing dependency: subagent:nonexistent +``` + +--- + +## Agents vs Subagents + +**Main Agents** (2 in Developer profile): +- openagent: Universal coordination agent +- opencoder: Complex coding and architecture + +**Specialist Subagents** (8 in Developer profile): +- frontend-specialist: React, Vue, CSS architecture +- devops-specialist: CI/CD, infrastructure, deployment + +- task-manager: Feature breakdown and planning +- documentation: Create and update docs +- coder-agent: Execute coding subtasks +- reviewer: Code review and security +- tester: Write unit and integration tests +- build-agent: Type checking and validation +- image-specialist: Generate and edit images + +**Commands** (7 in Developer profile): +- analyze-patterns: Analyze codebase for patterns +- commit, test, context, clean, optimize, validate-repo + +--- + +## Component Profiles + +Profiles are pre-configured component bundles for quick installation. + +### Available Profiles + +#### Essential Profile +**Purpose**: Minimal setup for basic usage + +**Includes**: +- Core agents (openagent, opencoder) +- Essential commands (commit, test) +- Core context files + +```json +"essential": { + "description": "Minimal setup for basic usage", + "components": [ + "agent:openagent", + "agent:opencoder", + "command:commit", + "command:test" + ] +} +``` + +--- + +#### Developer Profile +**Purpose**: Full development setup + +**Includes**: +- All core agents +- Development specialists +- All subagents +- Dev commands +- Dev context files + +```json +"developer": { + "description": "Full development setup", + "components": [ + "agent:*", + "subagent:*", + "command:*", + "context:core/*", + "context:development/*" + ] +} +``` + +--- + +#### Business Profile +**Purpose**: Content and product focus + +**Includes**: +- Core agents +- Content specialists +- Product specialists +- Content context files + +```json +"business": { + "description": "Content and product focus", + "components": [ + "agent:openagent", + "agent:copywriter", + "agent:technical-writer", + "context:core/*", + "context:content/*" + ] +} +``` + +--- + +## Install System + +The install system uses the registry to distribute components. + +### Installation Flow + +``` +1. User runs install.sh +2. Check for local registry.json (development mode) +3. If not local, fetch from GitHub (production mode) +4. Parse registry.json +5. Show component selection UI +6. Resolve dependencies +7. Download components from GitHub +8. Install to .opencode/ +9. Handle collisions (skip/overwrite/backup) +``` + +### Local Registry (Development) + +```bash +# Test with local registry +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --list + +# Install with local registry +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh developer +``` + +### Remote Registry (Production) + +```bash +# Install from GitHub +./install.sh developer + +# List available components +./install.sh --list +``` + +--- + +## Dependency Resolution + +### Dependency Format + +```json +"dependencies": [ + "subagent:tester", + "context:core/standards/code" +] +``` + +### Resolution Rules + +1. Parse dependency string (`type:id`) +2. Find component in registry +3. Check if already installed +4. Add to install queue +5. Recursively resolve dependencies +6. Install in dependency order + +### Example + +``` +User installs: frontend-specialist + ↓ +Depends on: subagent:tester + ↓ +Depends on: context:core/standards/tests + ↓ +Install order: + 1. context:core/standards/tests + 2. subagent:tester + 3. frontend-specialist +``` + +--- + +## Collision Handling + +When installing components that already exist: + +### Collision Strategies + +1. **Skip** - Keep existing file +2. **Overwrite** - Replace with new file +3. **Backup** - Backup existing, install new + +### Interactive Mode + +```bash +File exists: .opencode/agent/core/openagent.md +[S]kip, [O]verwrite, [B]ackup, [A]ll skip, [F]orce all? +``` + +### Non-Interactive Mode + +```bash +# Skip all collisions +./install.sh developer --skip-existing + +# Overwrite all collisions +./install.sh developer --force + +# Backup all collisions +./install.sh developer --backup +``` + +--- + +## Version Management + +### Version Fields + +- **Registry version**: Overall registry version (e.g., "0.5.0") +- **Schema version**: Registry schema version (e.g., "2.0.0") +- **Component version**: When component was added/updated + +### Version Consistency + +```bash +# Check version consistency +cat VERSION +cat package.json | jq '.version' +cat registry.json | jq '.version' + +# All should match +``` + +### Updating Versions + +```bash +# Bump version +echo "0.X.Y" > VERSION +jq '.version = "0.X.Y"' package.json > tmp && mv tmp package.json +jq '.version = "0.X.Y"' registry.json > tmp && mv tmp registry.json +``` + +--- + +## CI/CD Integration + +### GitHub Workflows + +#### Validate Registry (PR Checks) + +```yaml +# .github/workflows/validate-registry.yml +- name: Validate Registry + run: ./scripts/registry/validate-registry.sh +``` + +#### Auto-Update Registry (Post-Merge) + +```yaml +# .github/workflows/update-registry.yml +- name: Update Registry + run: ./scripts/registry/auto-detect-components.sh --auto-add +``` + +#### Version Bump (On Release) + +```yaml +# .github/workflows/version-bump.yml +- name: Bump Version + run: ./scripts/versioning/bump-version.sh +``` + +--- + +## Best Practices + +### Adding Components + +✅ **Add frontmatter** - Required for auto-detect +✅ **Run auto-detect** - Don't manually edit registry +✅ **Validate** - Always validate after changes +✅ **Test locally** - Use local registry for testing + +### Maintaining Registry + +✅ **Auto-detect first** - Let scripts handle updates +✅ **Validate often** - Catch issues early +✅ **Version consistency** - Keep versions in sync +✅ **CI validation** - Automate validation in CI + +### Dependencies + +✅ **Explicit dependencies** - List all dependencies +✅ **Test resolution** - Verify dependencies resolve +✅ **Avoid cycles** - No circular dependencies + +--- + +## Common Issues + +### Path Not Found + +**Problem**: Registry references non-existent path +**Solution**: Run auto-detect or fix path manually + +### Duplicate ID + +**Problem**: Two components with same ID +**Solution**: Rename one component + +### Invalid Category + +**Problem**: Agent has invalid category +**Solution**: Use valid category (core, development, content, data, product, learning) + +### Missing Dependency + +**Problem**: Dependency doesn't exist in registry +**Solution**: Add dependency or remove reference + +### Version Mismatch + +**Problem**: VERSION, package.json, registry.json don't match +**Solution**: Update all version files to match + +--- + +## Related Files + +- **Updating registry**: `guides/updating-registry.md` +- **Adding agents**: `guides/adding-agent.md` +- **Categories**: `core-concepts/categories.md` + +--- + +**Last Updated**: 2025-01-28 +**Version**: 0.5.2 diff --git a/.opencode/context/openagents-repo/errors/navigation.md b/.opencode/context/openagents-repo/errors/navigation.md new file mode 100644 index 0000000..e0c4a47 --- /dev/null +++ b/.opencode/context/openagents-repo/errors/navigation.md @@ -0,0 +1,38 @@ +# OpenAgents Errors + +**Purpose**: Common errors and troubleshooting for OpenAgents Control + +--- + +## Structure + +``` +openagents-repo/errors/ +├── navigation.md (this file) +└── [error documentation] +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **View errors** | `./` | +| **Guides** | `../guides/navigation.md` | +| **Quality** | `../quality/navigation.md` | + +--- + +## By Type + +**Errors** → Common errors and how to fix them +**Troubleshooting** → Solutions for common issues + +--- + +## Related Context + +- **OpenAgents Navigation** → `../navigation.md` +- **Guides** → `../guides/navigation.md` +- **Quality** → `../quality/navigation.md` diff --git a/.opencode/context/openagents-repo/errors/tool-permission-errors.md b/.opencode/context/openagents-repo/errors/tool-permission-errors.md new file mode 100644 index 0000000..54c1d7e --- /dev/null +++ b/.opencode/context/openagents-repo/errors/tool-permission-errors.md @@ -0,0 +1,225 @@ +# Tool Permission Errors + +**Purpose**: Diagnose and fix tool permission issues in agents + +**Last Updated**: 2026-01-07 + +--- + +## Error: Tool Permission Denied + +### Symptom + +```json +{ + "type": "missing-approval", + "severity": "error", + "message": "Execution tool 'bash' called without requesting approval" +} +``` + +Or agent tries to use a tool but gets blocked silently (0 tool calls). + +--- + +### Cause + +Agent has tool **disabled** or **denied** in frontmatter: + +```yaml +# In agent frontmatter +tools: + bash: false # ← Tool disabled + +permission: + bash: + "*": "deny" # ← Explicitly denied +``` + +**How it works**: +- `bash: false` means agent doesn't have access to bash tool +- Framework enforces this - agent can't use bash even if prompt says to +- NOT an approval issue - it's a permission restriction + +--- + +### Solution + +**Option 1: Emphasize Tool Restrictions in Prompt** (Recommended) + +Add critical rules section at top of agent prompt: + +```xml + + + ONLY use: glob, read, grep, list + NEVER use: bash, write, edit, task + You're read-only—no modifications allowed + + + ALWAYS use tools to discover files + NEVER assume or fabricate file paths + + +``` + +**Why this works**: Makes tool restrictions crystal clear in first 15% of prompt. + +**Option 2: Enable Tool** (If agent needs it) + +```yaml +tools: + bash: true # ← Enable if agent legitimately needs bash +``` + +**Warning**: Only enable if agent truly needs the tool. Read-only subagents should NOT have bash/write/edit. + +--- + +### Prevention + +**For Read-Only Subagents**: + +```yaml +# Correct configuration for read-only subagents +tools: + read: true + grep: true + glob: true + list: true + bash: false # ← No execution + edit: false # ← No modifications + write: false # ← No file creation + task: false # ← No delegation (subagents don't delegate) + +permissions: + bash: + "*": "deny" + edit: + "**/*": "deny" + write: + "**/*": "deny" +``` + +**For Primary Agents**: + +```yaml +# Primary agents may need execution tools +tools: + read: true + grep: true + glob: true + list: true + bash: true # ← May need for operations + edit: true # ← May need for modifications + write: true # ← May need for file creation + task: true # ← May delegate to subagents +``` + +--- + +## Error: Subagent Approval Gate Violation + +### Symptom + +```json +{ + "type": "missing-approval", + "message": "Execution tool 'bash' called without requesting approval" +} +``` + +In a **subagent** test. + +--- + +### Cause + +**Subagents should NOT have approval gates** - they're delegated to by primary agents who already got approval. + +The issue is usually: +1. Subagent trying to use restricted tool (bash/write/edit) +2. Test expecting approval behavior (wrong for subagents) + +--- + +### Solution + +**Fix 1: Remove Tool Usage** + +Subagents shouldn't use execution tools. Update prompt to emphasize read-only nature. + +**Fix 2: Update Test Configuration** + +Subagent tests should use `auto-approve`: + +```yaml +approvalStrategy: + type: auto-approve # ← No approval gates for subagents +``` + +**Fix 3: Check Tool Permissions** + +Ensure subagent has `bash: false` in frontmatter. + +--- + +## Error: Tool Not Available + +### Symptom + +Agent tries to use a tool but framework says "tool not available". + +--- + +### Cause + +Tool not enabled in frontmatter: + +```yaml +tools: + glob: false # ← Tool disabled +``` + +--- + +### Solution + +Enable the tool: + +```yaml +tools: + glob: true # ← Enable +``` + +--- + +## Verification Checklist + +After fixing tool permission: + +- [ ] Agent frontmatter has correct `tools:` configuration? +- [ ] Prompt emphasizes allowed tools in critical rules section? +- [ ] Prompt warns against restricted tools? +- [ ] Test uses `auto-approve` for subagents? +- [ ] Test verifies tool usage with `mustUseTools`? + +--- + +## Tool Permission Matrix + +| Agent Type | bash | write | edit | task | read | grep | glob | list | +|------------|------|-------|------|------|------|------|------|------| +| **Read-only subagent** | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | +| **Primary agent** | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| **Orchestrator** | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | + +--- + +## Related + +- `concepts/subagent-testing-modes.md` - Understand subagent testing +- `guides/testing-subagents.md` - How to test subagents +- `examples/subagent-prompt-structure.md` - Prompt structure with tool emphasis + +**Reference**: `.opencode/agent/ContextScout.md` (lines 14-28, tool configuration) diff --git a/.opencode/context/openagents-repo/examples/context-bundle-example.md b/.opencode/context/openagents-repo/examples/context-bundle-example.md new file mode 100644 index 0000000..b9db73c --- /dev/null +++ b/.opencode/context/openagents-repo/examples/context-bundle-example.md @@ -0,0 +1,214 @@ +# Context Bundle Example: Create Data Analyst Agent + +Session: 20250121-143022-a4f2 +Created: 2025-01-21T14:30:22Z +For: TaskManager +Status: in_progress + +## Task Overview + +Create a new data analyst agent for the OpenAgents Control repository. This agent will specialize in data analysis tasks including data visualization, statistical analysis, and data transformation. + +## User Request + +"Create a new data analyst agent that can help with data analysis, visualization, and statistical tasks" + +## Relevant Standards (Load These Before Starting) + +**Core Standards**: +- `.opencode/context/core/standards/code-quality.md` → Modular, functional code patterns +- `.opencode/context/core/standards/test-coverage.md` → Testing requirements and TDD +- `.opencode/context/core/standards/documentation.md` → Documentation standards + +**Core Workflows**: +- `.opencode/context/core/workflows/feature-breakdown.md` → Task breakdown methodology + +## Repository-Specific Context (Load These Before Starting) + +**Quick Start** (ALWAYS load first): +- `.opencode/context/openagents-repo/quick-start.md` → Repo orientation and common commands + +**Core Concepts** (Load based on task type): +- `.opencode/context/openagents-repo/core-concepts/agents.md` → How agents work +- `.opencode/context/openagents-repo/core-concepts/evals.md` → How testing works +- `.opencode/context/openagents-repo/core-concepts/registry.md` → How registry works +- `.opencode/context/openagents-repo/core-concepts/categories.md` → How organization works + +**Guides** (Load for specific workflows): +- `.opencode/context/openagents-repo/guides/adding-agent.md` → Step-by-step agent creation +- `.opencode/context/openagents-repo/guides/testing-agent.md` → Testing workflow +- `.opencode/context/openagents-repo/guides/updating-registry.md` → Registry workflow + +## Key Requirements + +**From Standards**: +- Agent must follow modular, functional programming patterns +- All code must be testable and maintainable +- Documentation must be concise and high-signal +- Include examples where helpful + +**From Repository Context**: +- Agent file must be in `.opencode/agent/data/` directory (category-based organization) +- Must include proper frontmatter metadata (id, name, description, category, type, version, etc.) +- Must follow naming convention: `data-analyst.md` (kebab-case) +- Must include tags for discoverability +- Must specify tools and permissions +- Must be registered in `registry.json` + +**Naming Conventions**: +- File name: `data-analyst.md` (kebab-case) +- Agent ID: `data-analyst` +- Category: `data` +- Type: `agent` + +**File Structure**: +- Agent file: `.opencode/agent/data/data-analyst.md` +- Eval directory: `evals/agents/data/data-analyst/` +- Eval config: `evals/agents/data/data-analyst/config/eval-config.yaml` +- Eval tests: `evals/agents/data/data-analyst/tests/` +- README: `evals/agents/data/data-analyst/README.md` + +## Technical Constraints + +- Must use category-based organization (data category) +- Must include proper frontmatter metadata +- Must specify tools needed (read, write, bash, etc.) +- Must define permissions for sensitive operations +- Must include temperature setting (0.1-0.3 for analytical tasks) +- Must follow agent prompt structure (context, role, task, instructions) +- Eval tests must use YAML format +- Registry entry must follow schema + +## Files to Create/Modify + +**Create**: +- `.opencode/agent/data/data-analyst.md` - Main agent definition with frontmatter and prompt +- `evals/agents/data/data-analyst/config/eval-config.yaml` - Eval configuration +- `evals/agents/data/data-analyst/tests/smoke-test.yaml` - Basic smoke test +- `evals/agents/data/data-analyst/tests/data-analysis-test.yaml` - Data analysis capability test +- `evals/agents/data/data-analyst/README.md` - Agent documentation + +**Modify**: +- `registry.json` - Add data-analyst agent entry +- `.opencode/context/navigation.md` - Add data category context if needed + +## Success Criteria + +- [x] Agent file created with proper frontmatter metadata +- [x] Agent prompt follows established patterns (context, role, task, instructions) +- [x] Eval test structure created with config and tests +- [x] Smoke test passes +- [x] Data analysis test passes +- [x] Registry entry added and validates +- [x] README documentation created +- [x] All validation scripts pass + +## Validation Requirements + +**Scripts to Run**: +- `./scripts/registry/validate-registry.sh` - Validates registry.json schema and entries +- `./scripts/validation/validate-test-suites.sh` - Validates eval test structure + +**Tests to Run**: +- `cd evals/framework && npm run eval:sdk -- --agent=data/data-analyst --pattern="smoke-test.yaml"` - Run smoke test +- `cd evals/framework && npm run eval:sdk -- --agent=data/data-analyst` - Run all tests + +**Manual Checks**: +- Verify frontmatter includes all required fields +- Check that tools and permissions are appropriate +- Ensure prompt is clear and follows standards +- Verify eval tests are meaningful + +## Expected Output + +**Deliverables**: +- Functional data analyst agent +- Complete eval test suite +- Registry entry +- Documentation + +**Format**: +- Agent file: Markdown with YAML frontmatter +- Eval config: YAML format +- Eval tests: YAML format with test cases +- README: Markdown documentation + +## Progress Tracking + +- [ ] Context loaded and understood +- [ ] Agent file created with frontmatter +- [ ] Agent prompt written +- [ ] Eval directory structure created +- [ ] Eval config created +- [ ] Smoke test created +- [ ] Data analysis test created +- [ ] README documentation created +- [ ] Registry entry added +- [ ] Validation scripts run +- [ ] All tests pass +- [ ] Documentation updated + +--- + +## Instructions for Subagent + +**IMPORTANT**: +1. Load ALL context files listed in "Relevant Standards" and "Repository-Specific Context" sections BEFORE starting work +2. Follow ALL requirements from the loaded context +3. Apply naming conventions and file structure requirements +4. Validate your work using the validation requirements +5. Update progress tracking as you complete steps + +**Your Task**: +Create a complete data analyst agent for the OpenAgents Control repository following all established conventions and standards. + +**Approach**: +1. **Load Context**: Read all context files listed above to understand: + - How agents are structured (core-concepts/agents.md) + - How to add an agent (guides/adding-agent.md) + - Code standards (standards/code-quality.md) + - Testing requirements (core-concepts/evals.md) + +2. **Create Agent File**: + - Create `.opencode/agent/data/data-analyst.md` + - Add frontmatter with all required metadata + - Write agent prompt with: + - Context section (system, domain, task, execution context) + - Role definition + - Task description + - Instructions and workflow + - Tools and capabilities + - Examples if helpful + +3. **Create Eval Structure**: + - Create directory: `evals/agents/data/data-analyst/` + - Create config: `config/eval-config.yaml` + - Create tests directory: `tests/` + - Create smoke test: `tests/smoke-test.yaml` + - Create capability test: `tests/data-analysis-test.yaml` + - Create README: `README.md` + +4. **Update Registry**: + - Add entry to `registry.json` following schema + - Include: id, name, description, category, type, path, version, tags + +5. **Validate**: + - Run validation scripts + - Run eval tests + - Fix any issues + +**Constraints**: +- Agent must be in `data` category +- Must follow functional programming patterns +- Must include proper error handling +- Must specify appropriate tools (read, write, bash for data tasks) +- Temperature should be 0.1-0.3 for analytical precision +- Eval tests must be meaningful and test actual capabilities + +**Questions/Clarifications**: +- What specific data analysis capabilities should be emphasized? (visualization, statistics, transformation) +- Should the agent support specific data formats? (CSV, JSON, Parquet) +- Should the agent integrate with specific tools? (pandas, matplotlib, etc.) +- What level of statistical analysis? (descriptive, inferential, predictive) + +**Note**: This is an example context bundle. In practice, the subagent would receive this file and follow the instructions to complete the task. diff --git a/.opencode/context/openagents-repo/examples/navigation.md b/.opencode/context/openagents-repo/examples/navigation.md new file mode 100644 index 0000000..af1741e --- /dev/null +++ b/.opencode/context/openagents-repo/examples/navigation.md @@ -0,0 +1,38 @@ +# OpenAgents Examples + +**Purpose**: Example implementations and use cases for OpenAgents Control + +--- + +## Structure + +``` +openagents-repo/examples/ +├── navigation.md (this file) +└── [example files] +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **View examples** | `./` | +| **Guides** | `../guides/navigation.md` | +| **Blueprints** | `../blueprints/navigation.md` | + +--- + +## By Type + +**Examples** → Working examples of OpenAgents implementations +**Use Cases** → Real-world use cases and patterns + +--- + +## Related Context + +- **OpenAgents Navigation** → `../navigation.md` +- **Guides** → `../guides/navigation.md` +- **Blueprints** → `../blueprints/navigation.md` diff --git a/.opencode/context/openagents-repo/examples/subagent-prompt-structure.md b/.opencode/context/openagents-repo/examples/subagent-prompt-structure.md new file mode 100644 index 0000000..44c33b6 --- /dev/null +++ b/.opencode/context/openagents-repo/examples/subagent-prompt-structure.md @@ -0,0 +1,282 @@ +# Subagent Prompt Structure (Optimized) + +**Purpose**: Template for well-structured subagent prompts with tool usage emphasis + +**Last Updated**: 2026-01-07 + +--- + +## Core Principle + +**Position Sensitivity**: Critical instructions in first 15% of prompt improves adherence. + +For subagents, the most critical instruction is: **which tools to use**. + +--- + +## Optimized Structure + +```xml +--- +# Frontmatter (lines 1-50) +id: subagent-name +name: Subagent Name +category: subagents/core +type: subagent +mode: subagent +tools: + read: true + grep: true + glob: true + list: true + bash: false + edit: false + write: false +permissions: + bash: "*": "deny" + edit: "**/*": "deny" + write: "**/*": "deny" +--- + +# Agent Name + +> **Mission**: One-sentence mission statement + +Brief description (1-2 sentences). + +--- + + + + + ONLY use: glob, read, grep, list + NEVER use: bash, write, edit, task + You're read-only—no modifications allowed + + + ALWAYS use tools to discover/verify + NEVER assume or fabricate information + + + ALWAYS include: exact paths, specific details, evidence + + + +--- + + + What system this agent operates in + What domain knowledge it needs + What it does + What limits it has + + +One-sentence role description + +One-sentence task description + +--- + + + + - @tool_usage: Use ONLY allowed tools + - @always_use_tools: Verify everything + - @output_format: Precise results + + + - Main workflow steps + + + - Quality checks + - Validation + + + Tier 1 always overrides Tier 2/3 + + + +--- + +## Workflow + +### Stage 1: Discovery +**Action**: Use tools to discover information +**Process**: 1. Use glob/list, 2. Use read, 3. Use grep +**Output**: Discovered items + +### Stage 2: Analysis +**Action**: Analyze discovered information +**Process**: Extract key details +**Output**: Analyzed results + +### Stage 3: Present +**Action**: Return structured response +**Process**: Format according to @output_format +**Output**: Complete response + +--- + +## What NOT to Do + +- ❌ **NEVER use bash/write/edit/task tools** (@tool_usage) +- ❌ Don't assume information—verify with tools +- ❌ Don't fabricate paths or details +- ❌ Don't skip required output fields + +--- + +## Remember + +**Your Tools**: glob (discover) | read (extract) | grep (search) | list (structure) + +**Your Constraints**: Read-only, verify everything, precise output + +**Your Value**: Accurate, verified information using tools +``` + +--- + +## Key Optimizations Applied + +### 1. Critical Rules Early (Lines 50-80) + +**Before** (buried at line 596): +```markdown +## Important Guidelines +... +(400 lines later) +### Tool Usage +- Use glob, read, grep, list +``` + +**After** (at line 50): +```xml + + + ONLY use: glob, read, grep, list + NEVER use: bash, write, edit, task + + +``` + +**Impact**: 47.5% reduction in prompt length, tool usage emphasized early. + +--- + +### 2. Execution Priority (3-Tier System) + +```xml + + + - Tool usage rules + - Verification requirements + + + - Main workflow + + + - Nice-to-haves + + Tier 1 always overrides + +``` + +**Why**: Resolves conflicts, makes priorities explicit. + +--- + +### 3. Flattened Nesting (≤4 Levels) + +**Before** (6-7 levels): +```xml + + + + + + + ... + + + + + + +``` + +**After** (3-4 levels): +```xml + + + Use tools + 1. glob, 2. read, 3. grep + + +``` + +**Why**: Improves clarity, reduces cognitive load. + +--- + +### 4. Explicit "What NOT to Do" + +```markdown +## What NOT to Do + +- ❌ **NEVER use bash/write/edit/task tools** +- ❌ Don't assume—verify with tools +- ❌ Don't fabricate information +``` + +**Why**: Negative examples prevent common mistakes. + +--- + +## File Size Targets + +| Section | Target Lines | Purpose | +|---------|--------------|---------| +| Frontmatter | 30-50 | Agent metadata | +| Critical Rules | 20-30 | Tool usage, core rules | +| Context/Role/Task | 20-30 | Agent identity | +| Execution Priority | 20-30 | Priority system | +| Workflow | 80-120 | Main instructions | +| Guidelines | 40-60 | Best practices | +| **Total** | **<400 lines** | MVI compliant | + +--- + +## Validation Checklist + +Before deploying optimized prompt: + +- [ ] Critical rules in first 15% (lines 50-80)? +- [ ] Tool usage explicitly stated? +- [ ] Nesting ≤4 levels? +- [ ] Execution priority defined? +- [ ] "What NOT to Do" section included? +- [ ] Total lines <400? +- [ ] Semantic meaning preserved? + +--- + +## Real Example + +**ContextScout Optimization**: +- **Before**: 750 lines, critical rules at line 596 +- **After**: 394 lines (47.5% reduction), critical rules at line 50 +- **Result**: Test passed (was failing with 0 tool calls) + +**Files**: +- Optimized: `.opencode/agent/ContextScout.md` +- Backup: `.opencode/agent/ContextScout-original-backup.md` + +--- + +## Related + +- `concepts/subagent-testing-modes.md` - How to test optimized prompts +- `guides/testing-subagents.md` - Verify tool usage works +- `errors/tool-permission-errors.md` - Fix tool issues + +**Reference**: `.opencode/command/prompt-engineering/prompt-optimizer.md` (optimization principles) diff --git a/.opencode/context/openagents-repo/guides/adding-agent-basics.md b/.opencode/context/openagents-repo/guides/adding-agent-basics.md new file mode 100644 index 0000000..bfdfd6c --- /dev/null +++ b/.opencode/context/openagents-repo/guides/adding-agent-basics.md @@ -0,0 +1,154 @@ +# Guide: Adding a New Agent (Basics) + +**Prerequisites**: Load `core-concepts/agents.md` first +**Purpose**: Create and register a new agent in 4 steps + +--- + +## Overview + +Adding a new agent involves: +1. Creating the agent file +2. Creating test structure +3. Updating the registry +4. Validating everything works + +**Time**: ~15-20 minutes + +--- + +## Step 1: Create Agent File + +### Choose Category + +```bash +# Available categories: +# - core/ (system agents) +# - development/ (dev specialists) +# - content/ (content creators) +# - data/ (data analysts) +# - product/ (product managers) +# - learning/ (educators) +``` + +### Create File with Frontmatter + +```bash +touch .opencode/agent/{category}/{agent-name}.md +``` + +```markdown +--- +description: "Brief description of what this agent does" +category: "{category}" +type: "agent" +tags: ["tag1", "tag2"] +dependencies: [] +--- + +# Agent Name + +**Purpose**: What this agent does + +## Focus +- Key responsibility 1 +- Key responsibility 2 + +## Workflow +1. Step 1 +2. Step 2 + +## Constraints +- Constraint 1 +- Constraint 2 +``` + +--- + +## Step 2: Create Test Structure + +```bash +# Create directories +mkdir -p evals/agents/{category}/{agent-name}/{config,tests} + +# Create config +cat > evals/agents/{category}/{agent-name}/config/config.yaml << 'EOF' +agent: {category}/{agent-name} +model: anthropic/claude-sonnet-4-5 +timeout: 60000 +suites: + - smoke +EOF + +# Create smoke test +cat > evals/agents/{category}/{agent-name}/tests/smoke-test.yaml << 'EOF' +name: Smoke Test +description: Basic functionality check +agent: {category}/{agent-name} +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "Hello, can you help me?" +expectations: + - type: no_violations +EOF +``` + +--- + +## Step 3: Update Registry + +```bash +# Dry run first +./scripts/registry/auto-detect-components.sh --dry-run + +# Add to registry +./scripts/registry/auto-detect-components.sh --auto-add + +# Verify +cat registry.json | jq '.components.agents[] | select(.id == "{agent-name}")' +``` + +--- + +## Step 4: Validate + +```bash +# Validate registry +./scripts/registry/validate-registry.sh + +# Run smoke test +cd evals/framework +npm run eval:sdk -- --agent={category}/{agent-name} --pattern="smoke-test.yaml" + +# Test installation +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --list +``` + +--- + +## Checklist + +- [ ] Agent file created with proper frontmatter +- [ ] Test structure created (config + smoke test) +- [ ] Registry updated via auto-detect +- [ ] Registry validation passes +- [ ] Smoke test passes +- [ ] Agent appears in `./install.sh --list` + +--- + +## Next Steps + +- **Add more tests** → `adding-agent-testing.md` +- **Test thoroughly** → `testing-agent.md` +- **Debug issues** → `debugging.md` + +--- + +## Related + +- `core-concepts/agents.md` - Agent concepts +- `adding-agent-testing.md` - Additional test patterns +- `testing-agent.md` - Testing guide +- `creating-subagents.md` - Claude Code subagents (different system) diff --git a/.opencode/context/openagents-repo/guides/adding-agent-testing.md b/.opencode/context/openagents-repo/guides/adding-agent-testing.md new file mode 100644 index 0000000..ff65078 --- /dev/null +++ b/.opencode/context/openagents-repo/guides/adding-agent-testing.md @@ -0,0 +1,143 @@ +# Guide: Adding Agent Tests + +**Prerequisites**: Load `adding-agent-basics.md` first +**Purpose**: Additional test patterns for agents + +--- + +## Additional Test Types + +### Approval Gate Test + +```yaml +# evals/agents/{category}/{agent-name}/tests/approval-gate.yaml +name: Approval Gate Test +description: Verify agent requests approval before execution +agent: {category}/{agent-name} +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "Create a new file called test.js" +expectations: + - type: specific_evaluator + evaluator: approval_gate + should_pass: true +``` + +### Context Loading Test + +```yaml +# evals/agents/{category}/{agent-name}/tests/context-loading.yaml +name: Context Loading Test +description: Verify agent loads required context +agent: {category}/{agent-name} +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "Write a new function" +expectations: + - type: context_loaded + contexts: ["core/standards/code-quality.md"] +``` + +--- + +## Complete Example: API Specialist + +```bash +# 1. Create agent file +cat > .opencode/agent/development/api-specialist.md << 'EOF' +--- +description: "Expert in REST and GraphQL API design" +category: "development" +type: "agent" +tags: ["api", "rest", "graphql"] +dependencies: ["subagent:tester"] +--- + +# API Specialist + +**Purpose**: Design and implement robust APIs + +## Focus +- REST API design +- GraphQL schemas +- API documentation +- Authentication/authorization + +## Workflow +1. Analyze requirements +2. Design API structure +3. Implement endpoints +4. Add tests +5. Document API + +## Constraints +- Follow REST best practices +- Use proper HTTP methods +- Include error handling +- Add comprehensive tests +EOF + +# 2. Create test structure +mkdir -p evals/agents/development/api-specialist/{config,tests} + +cat > evals/agents/development/api-specialist/config/config.yaml << 'EOF' +agent: development/api-specialist +model: anthropic/claude-sonnet-4-5 +timeout: 60000 +suites: + - smoke +EOF + +cat > evals/agents/development/api-specialist/tests/smoke-test.yaml << 'EOF' +name: Smoke Test +description: Basic functionality check +agent: development/api-specialist +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "Hello, can you help me design an API?" +expectations: + - type: no_violations +EOF + +# 3. Update registry +./scripts/registry/auto-detect-components.sh --auto-add + +# 4. Validate +./scripts/registry/validate-registry.sh +cd evals/framework && npm run eval:sdk -- --agent=development/api-specialist --pattern="smoke-test.yaml" +``` + +--- + +## Common Issues + +| Problem | Solution | +|---------|----------| +| Auto-detect doesn't find agent | Check frontmatter is valid YAML | +| Registry validation fails | Verify file path is correct | +| Test fails unexpectedly | Load `debugging.md` for troubleshooting | + +--- + +## Claude Code Subagent (Optional) + +For Claude Code-only helpers, create a project subagent: + +- **Path**: `.claude/agents/{subagent-name}.md` +- **Required**: `name`, `description` frontmatter +- **Optional**: `tools`, `disallowedTools`, `permissionMode`, `skills`, `hooks` +- **Reload**: restart Claude Code or run `/agents` + +See `creating-subagents.md` for Claude Code subagent details. + +--- + +## Related + +- `adding-agent-basics.md` - Basic agent creation +- `testing-agent.md` - Testing guide +- `debugging.md` - Troubleshooting +- `creating-subagents.md` - Claude Code subagents diff --git a/.opencode/context/openagents-repo/guides/adding-skill-basics.md b/.opencode/context/openagents-repo/guides/adding-skill-basics.md new file mode 100644 index 0000000..8fa51d8 --- /dev/null +++ b/.opencode/context/openagents-repo/guides/adding-skill-basics.md @@ -0,0 +1,147 @@ +# Guide: Adding an OpenCode Skill (Basics) + +**Prerequisites**: Load `plugins/context/capabilities/events_skills.md` first +**Purpose**: Create an OpenCode skill directory and SKILL.md file + +**Note**: This is for **OpenCode skills** (internal system). For **Claude Code Skills**, see `creating-skills.md`. + +--- + +## Overview + +Adding an OpenCode skill involves: +1. Creating skill directory structure +2. Creating SKILL.md file +3. Creating router script (optional) +4. Creating CLI implementation (optional) +5. Registering in registry (optional) +6. Testing + +**Time**: ~10-15 minutes + +--- + +## Step 1: Create Skill Directory + +### Choose Skill Name + +- **kebab-case**: `task-management`, `brand-guidelines` +- **Descriptive**: Clear indication of what skill provides +- **Short**: Max 3-4 words + +### Create Structure + +```bash +mkdir -p .opencode/skills/{skill-name}/scripts +``` + +**Standard structure**: +``` +.opencode/skills/{skill-name}/ +├── SKILL.md # Required: Main skill documentation +├── router.sh # Optional: CLI router script +└── scripts/ + └── skill-cli.ts # Optional: CLI tool implementation +``` + +--- + +## Step 2: Create SKILL.md + +### Frontmatter + +```markdown +--- +name: {skill-name} +description: Brief description of what the skill provides +--- + +# Skill Name + +**Purpose**: What this skill helps users do + +## What I do + +- Feature 1 +- Feature 2 +- Feature 3 + +## How to use me + +### Basic Commands + +```bash +npx ts-node .opencode/skills/{skill-name}/scripts/skill-cli.ts command1 +``` + +### Command Reference + +| Command | Description | +|---------|-------------| +| `command1` | What command1 does | +| `command2` | What command2 does | +``` + +### Claude Code Skills (Optional) + +For Claude Code Skills (`.claude/skills/`), add extra frontmatter: +- `allowed-tools` - Tool restrictions +- `context` + `agent` - Run in forked subagent +- `hooks` - Lifecycle events +- `user-invocable` - Hide from slash menu + +See `creating-skills.md` for Claude Code Skills details. + +--- + +## Step 3: Create Router Script (Optional) + +For CLI-based skills: + +```bash +#!/bin/bash +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +if [ $# -eq 0 ]; then + echo "Usage: bash router.sh [options]" + exit 1 +fi + +COMMAND="$1" +shift + +case "$COMMAND" in + help|--help|-h) + echo "{Skill Name} - Description" + echo "Commands: command1, command2, help" + ;; + command1|command2) + npx ts-node "$SCRIPT_DIR/scripts/skill-cli.ts" "$COMMAND" "$@" + ;; + *) + echo "Unknown command: $COMMAND" + exit 1 + ;; +esac +``` + +```bash +chmod +x .opencode/skills/{skill-name}/router.sh +``` + +--- + +## Next Steps + +- **CLI Implementation** → `adding-skill-implementation.md` +- **Complete Example** → `adding-skill-example.md` +- **Claude Code Skills** → `creating-skills.md` + +--- + +## Related + +- `creating-skills.md` - Claude Code Skills (different system) +- `adding-skill-implementation.md` - CLI and registry +- `adding-skill-example.md` - Task-management example +- `plugins/context/capabilities/events_skills.md` - Skills Plugin diff --git a/.opencode/context/openagents-repo/guides/adding-skill-example.md b/.opencode/context/openagents-repo/guides/adding-skill-example.md new file mode 100644 index 0000000..35b7b20 --- /dev/null +++ b/.opencode/context/openagents-repo/guides/adding-skill-example.md @@ -0,0 +1,167 @@ +# Example: Task-Management Skill + +**Purpose**: Complete example of creating an OpenCode skill + +--- + +## Directory Structure + +```bash +mkdir -p .opencode/skills/task-management/scripts +``` + +``` +.opencode/skills/task-management/ +├── SKILL.md +├── router.sh +└── scripts/ + └── task-cli.ts +``` + +--- + +## SKILL.md + +```markdown +--- +name: task-management +description: Task management CLI for tracking feature subtasks +--- + +# Task Management Skill + +**Purpose**: Track and manage feature subtasks + +## What I do + +- Track task progress +- Show next eligible tasks +- Identify blocked tasks +- Mark completion +- Validate task integrity + +## Usage + +```bash +# Show all task statuses +npx ts-node .opencode/skills/task-management/scripts/task-cli.ts status + +# Show next eligible tasks +npx ts-node .opencode/skills/task-management/scripts/task-cli.ts next + +# Mark complete +npx ts-node .opencode/skills/task-management/scripts/task-cli.ts complete "summary" +``` +``` + +--- + +## router.sh + +```bash +#!/bin/bash +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +case "$1" in + help|--help|-h) + echo "Task Management Skill" + echo "Usage: bash router.sh " + echo "Commands: status, next, blocked, complete, validate" + ;; + status|next|blocked|validate) + npx ts-node "$SCRIPT_DIR/scripts/task-cli.ts" "$@" + ;; + complete) + npx ts-node "$SCRIPT_DIR/scripts/task-cli.ts" "$@" + ;; + *) + echo "Unknown command: $1" + bash "$0" help + ;; +esac +``` + +--- + +## task-cli.ts (Excerpt) + +```typescript +#!/usr/bin/env ts-node + +interface Task { + id: string + status: 'pending' | 'in_progress' | 'completed' + title: string +} + +async function main() { + const command = process.argv[2] || 'help' + + switch (command) { + case 'status': + await showStatus() + break + case 'next': + await showNext() + break + case 'complete': + const [, , , feature, seq, summary] = process.argv + await markComplete(feature, seq, summary) + break + default: + showHelp() + } +} + +async function showStatus() { + // Implementation + console.log('Task status...') +} + +async function showNext() { + // Implementation + console.log('Next tasks...') +} + +async function markComplete(feature: string, seq: string, summary: string) { + // Implementation + console.log(`Completing ${feature} ${seq}: ${summary}`) +} + +function showHelp() { + console.log(` +Task Management CLI + +Commands: + status Show all task statuses + next Show next eligible tasks + blocked Show blocked tasks + complete Mark task complete + validate Validate task integrity +`) +} + +main().catch(console.error) +``` + +--- + +## Integration with Agents + +Skills integrate with agents via: +- Event hooks (`tool.execute.before`, `tool.execute.after`) +- Skill content injection into conversation +- Output enhancement + +Example agent prompt invoking skill: +``` +Use the task-management skill to show current task status +``` + +--- + +## Related + +- `adding-skill-basics.md` - Directory and SKILL.md setup +- `adding-skill-implementation.md` - CLI and registry +- `plugins/context/capabilities/events_skills.md` - Skills Plugin diff --git a/.opencode/context/openagents-repo/guides/adding-skill-implementation.md b/.opencode/context/openagents-repo/guides/adding-skill-implementation.md new file mode 100644 index 0000000..6b93ece --- /dev/null +++ b/.opencode/context/openagents-repo/guides/adding-skill-implementation.md @@ -0,0 +1,167 @@ +# Guide: OpenCode Skill Implementation + +**Prerequisites**: Load `adding-skill-basics.md` first +**Purpose**: CLI implementation, registry, and testing for OpenCode skills + +--- + +## CLI Implementation + +### Basic Structure + +```typescript +#!/usr/bin/env ts-node +// CLI implementation for {skill-name} skill + +interface Args { + command: string + [key: string]: any +} + +async function main() { + const args = parseArgs() + + switch (args.command) { + case 'command1': + await handleCommand1(args) + break + case 'command2': + await handleCommand2(args) + break + case 'help': + default: + showHelp() + } +} + +function parseArgs(): Args { + const args = process.argv.slice(2) + return { + command: args[0] || 'help', + ...parseOptions(args.slice(1)) + } +} + +async function handleCommand1(args: Args) { + console.log('Running command1...') +} + +function showHelp() { + console.log(` +{Skill Name} + +Usage: npx ts-node scripts/skill-cli.ts [options] + +Commands: + command1 Description + command2 Description + help Show this help +`) +} + +main().catch(console.error) +``` + +--- + +## Register in Registry (Optional) + +### Add to Components + +```json +{ + "skills": [ + { + "id": "{skill-name}", + "name": "Skill Name", + "type": "skill", + "path": ".opencode/skills/{skill-name}/SKILL.md", + "description": "Brief description", + "tags": ["tag1", "tag2"], + "dependencies": [] + } + ] +} +``` + +### Add to Profiles + +```json +{ + "profiles": { + "essential": { + "components": [ + "skill:{skill-name}" + ] + } + } +} +``` + +--- + +## Testing + +### Test CLI Commands + +```bash +# Test help +bash .opencode/skills/{skill-name}/router.sh help + +# Test commands +bash .opencode/skills/{skill-name}/router.sh command1 --option value + +# Test with npx +npx ts-node .opencode/skills/{skill-name}/scripts/skill-cli.ts help +``` + +### Test OpenCode Integration + +1. Call skill via OpenCode +2. Verify event hooks fire correctly +3. Check conversation history for skill content +4. Verify output enhancement works + +--- + +## Best Practices + +### Keep Skills Focused +- ✅ Task management skill → Tracks tasks +- ❌ Task management + code generation + testing → Too broad + +### Clear Documentation +- Provide usage examples +- Document all commands +- Include expected outputs + +### Error Handling +- Handle missing arguments gracefully +- Provide helpful error messages +- Validate inputs before processing + +### Performance +- Use efficient algorithms +- Cache when appropriate +- Avoid unnecessary file operations + +--- + +## Checklist + +- [ ] `.opencode/skills/{skill-name}/SKILL.md` created +- [ ] `.opencode/skills/{skill-name}/router.sh` created (if CLI-based) +- [ ] Router script is executable (`chmod +x`) +- [ ] Registry updated (if needed) +- [ ] Profile updated (if needed) +- [ ] All commands tested +- [ ] Documentation complete + +--- + +## Related + +- `adding-skill-basics.md` - Directory and SKILL.md setup +- `adding-skill-example.md` - Complete example +- `creating-skills.md` - Claude Code Skills +- `plugins/context/capabilities/events_skills.md` - Skills Plugin diff --git a/.opencode/context/openagents-repo/guides/building-cli-compact.md b/.opencode/context/openagents-repo/guides/building-cli-compact.md new file mode 100644 index 0000000..4d572fe --- /dev/null +++ b/.opencode/context/openagents-repo/guides/building-cli-compact.md @@ -0,0 +1,97 @@ +# Building CLIs in OpenAgents Control: Compact Guide + +**Category**: guide +**Purpose**: Rapidly build, register, and deploy CLI tools for OpenAgents Control skills +**Framework**: FAB (Features, Advantages, Benefits) + +--- + +## 🚀 Quick Start + +**Don't start from scratch.** Use the standard pattern to build robust CLIs in minutes. + +1. **Create**: `mkdir -p .opencode/skills/{name}/scripts` +2. **Implement**: Create `skill-cli.ts` (TypeScript) and `router.sh` (Bash) +3. **Register**: Add to `registry.json` +4. **Run**: `bash .opencode/skills/{name}/router.sh help` + +--- + +## 🏗️ Core Architecture + +| Component | File | Purpose | +|-----------|------|---------| +| **Logic** | `scripts/skill-cli.ts` | Type-safe implementation using `ts-node`. Handles args, logic, and output. | +| **Router** | `router.sh` | Universal entry point. Routes commands to the TS script. | +| **Docs** | `SKILL.md` | User guide, examples, and integration details. | +| **Config** | `registry.json` | Makes the skill discoverable and installable via `install.sh`. | + +--- + +## ⚡ Implementation Patterns + +### 1. The Router (`router.sh`) +**Why**: Provides a consistent, dependency-free entry point for all environments. + +```bash +#!/bin/bash +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +case "$1" in + help|--help|-h) + echo "Usage: bash router.sh " + ;; + *) + # Route to TypeScript implementation + npx ts-node "$SCRIPT_DIR/scripts/skill-cli.ts" "$@" + ;; +esac +``` + +### 2. The CLI Logic (`skill-cli.ts`) +**Why**: Type safety, async/await support, and rich ecosystem access. + +```typescript +#!/usr/bin/env ts-node + +async function main() { + const [command, ...args] = process.argv.slice(2); + + switch (command) { + case 'action': + await handleAction(args); + break; + default: + console.log("Unknown command"); + process.exit(1); + } +} + +main().catch(console.error); +``` + +--- + +## ✅ Quality Checklist + +Before shipping, verify your CLI delivers value: + +- [ ] **Help Command**: Does `router.sh help` provide clear, actionable usage info? +- [ ] **Error Handling**: Do invalid inputs return helpful error messages (not stack traces)? +- [ ] **Performance**: Does it start in < 1s? (Avoid heavy imports at top level) +- [ ] **Idempotency**: Can commands be run multiple times safely? +- [ ] **Registry**: Is it added to `registry.json` with correct paths? + +--- + +## 🧠 Copywriting Principles for CLI Output + +Apply `content-creation` principles to your CLI output: + +1. **Clarity**: Use **Active Voice**. "Created file" (Good) vs "File has been created" (Bad). +2. **Specificity**: "Processed 5 files" (Good) vs "Processing complete" (Bad). +3. **Action**: Tell the user what to do next. "Run `npm test` to verify." + +--- + +**Reference**: See `.opencode/context/openagents-repo/guides/adding-skill.md` for the full, detailed walkthrough. diff --git a/.opencode/context/openagents-repo/guides/creating-release.md b/.opencode/context/openagents-repo/guides/creating-release.md new file mode 100644 index 0000000..6f783bd --- /dev/null +++ b/.opencode/context/openagents-repo/guides/creating-release.md @@ -0,0 +1,289 @@ +# Guide: Creating a Release + +**Purpose**: Step-by-step workflow for creating a new release + +--- + +## Quick Steps + +```bash +# 1. Update version +echo "0.X.Y" > VERSION +jq '.version = "0.X.Y"' package.json > tmp && mv tmp package.json + +# 2. Update CHANGELOG +# (Edit CHANGELOG.md manually) + +# 3. Commit and tag +git add VERSION package.json CHANGELOG.md +git commit -m "chore: bump version to 0.X.Y" +git tag -a v0.X.Y -m "Release v0.X.Y" + +# 4. Push +git push origin main +git push origin v0.X.Y +``` + +--- + +## Step 1: Determine Version + +### Semantic Versioning + +``` +MAJOR.MINOR.PATCH + +- MAJOR: Breaking changes +- MINOR: New features (backward compatible) +- PATCH: Bug fixes +``` + +### Examples + +- `0.5.0` → `0.5.1` (bug fix) +- `0.5.0` → `0.6.0` (new feature) +- `0.5.0` → `1.0.0` (breaking change) + +--- + +## Step 2: Update Version Files + +### VERSION File + +```bash +echo "0.X.Y" > VERSION +``` + +### package.json + +```bash +jq '.version = "0.X.Y"' package.json > tmp && mv tmp package.json +``` + +### Verify Consistency + +```bash +cat VERSION +cat package.json | jq '.version' +# Both should show same version +``` + +--- + +## Step 3: Update CHANGELOG + +### Format + +```markdown +# Changelog + +## [0.X.Y] - 2025-12-10 + +### Added +- New feature 1 +- New feature 2 + +### Changed +- Updated feature 1 +- Improved feature 2 + +### Fixed +- Bug fix 1 +- Bug fix 2 + +### Removed +- Deprecated feature 1 + +## [Previous Version] - Date +... +``` + +### Tips + +✅ **Group by type** - Added, Changed, Fixed, Removed +✅ **User-focused** - Describe impact, not implementation +✅ **Link PRs** - Reference PR numbers +✅ **Breaking changes** - Clearly mark breaking changes + +--- + +## Step 4: Commit Changes + +```bash +# Stage files +git add VERSION package.json CHANGELOG.md + +# Commit +git commit -m "chore: bump version to 0.X.Y" +``` + +--- + +## Step 5: Create Git Tag + +```bash +# Create annotated tag +git tag -a v0.X.Y -m "Release v0.X.Y" + +# Verify tag +git tag -l "v0.X.Y" +git show v0.X.Y +``` + +--- + +## Step 6: Push to GitHub + +```bash +# Push commit +git push origin main + +# Push tag +git push origin v0.X.Y +``` + +--- + +## Step 7: Create GitHub Release + +### Via GitHub UI + +1. Go to repository on GitHub +2. Click "Releases" +3. Click "Create a new release" +4. Select tag: `v0.X.Y` +5. Title: `v0.X.Y` +6. Description: Copy from CHANGELOG +7. Click "Publish release" + +### Via GitHub CLI + +```bash +gh release create v0.X.Y \ + --title "v0.X.Y" \ + --notes "$(cat CHANGELOG.md | sed -n '/## \[0.X.Y\]/,/## \[/p' | head -n -1)" +``` + +--- + +## Step 8: Verify Release + +### Check GitHub + +- ✅ Release appears on GitHub +- ✅ Tag is correct +- ✅ CHANGELOG is included +- ✅ Assets are attached (if any) + +### Test Installation + +```bash +# Test install from GitHub +./install.sh --list + +# Verify version +cat VERSION +``` + +--- + +## Complete Example + +```bash +# Releasing v0.6.0 + +# 1. Update version +echo "0.6.0" > VERSION +jq '.version = "0.6.0"' package.json > tmp && mv tmp package.json + +# 2. Update CHANGELOG +cat >> CHANGELOG.md << 'EOF' +## [0.6.0] - 2025-12-10 + +### Added +- New API specialist agent +- GraphQL support in backend specialist + +### Changed +- Improved eval framework performance +- Updated registry schema to 2.0.0 + +### Fixed +- Fixed path resolution for subagents +- Fixed registry validation edge cases +EOF + +# 3. Commit +git add VERSION package.json CHANGELOG.md +git commit -m "chore: bump version to 0.6.0" + +# 4. Tag +git tag -a v0.6.0 -m "Release v0.6.0" + +# 5. Push +git push origin main +git push origin v0.6.0 + +# 6. Create GitHub release +gh release create v0.6.0 \ + --title "v0.6.0" \ + --notes "See CHANGELOG.md for details" +``` + +--- + +## Checklist + +Before releasing: + +- [ ] All tests pass +- [ ] Registry validates +- [ ] VERSION updated +- [ ] package.json updated +- [ ] CHANGELOG updated +- [ ] Changes committed +- [ ] Tag created +- [ ] Pushed to GitHub +- [ ] GitHub release created +- [ ] Installation tested + +--- + +## Common Issues + +### Version Mismatch + +**Problem**: VERSION and package.json don't match +**Solution**: Update both to same version + +### Tag Already Exists + +**Problem**: Tag already exists +**Solution**: Delete tag and recreate +```bash +git tag -d v0.X.Y +git push origin :refs/tags/v0.X.Y +``` + +### Push Rejected + +**Problem**: Push rejected (not up to date) +**Solution**: Pull latest changes first +```bash +git pull origin main +git push origin main +git push origin v0.X.Y +``` + +--- + +## Related Files + +- **Version management**: `scripts/versioning/bump-version.sh` +- **CHANGELOG**: `CHANGELOG.md` +- **VERSION**: `VERSION` + +--- + +**Last Updated**: 2025-12-10 +**Version**: 0.5.0 diff --git a/.opencode/context/openagents-repo/guides/debugging.md b/.opencode/context/openagents-repo/guides/debugging.md new file mode 100644 index 0000000..d802bad --- /dev/null +++ b/.opencode/context/openagents-repo/guides/debugging.md @@ -0,0 +1,399 @@ +# Guide: Debugging Common Issues + +**Purpose**: Troubleshooting guide for common problems + +--- + +## Quick Diagnostics + +```bash +# Check system health +./scripts/registry/validate-registry.sh +./scripts/validation/validate-test-suites.sh + +# Check version consistency +cat VERSION && cat package.json | jq '.version' + +# Test core agents +cd evals/framework && npm run eval:sdk -- --agent=core/openagent --pattern="smoke-test.yaml" +``` + +--- + +## Registry Issues + +### Registry Validation Fails + +**Symptoms**: +``` +ERROR: Path does not exist: .opencode/agent/core/missing.md +``` + +**Diagnosis**: +```bash +./scripts/registry/validate-registry.sh -v +``` + +**Solutions**: +1. **Path doesn't exist**: Remove entry or create file +2. **Duplicate ID**: Rename one component +3. **Invalid category**: Use valid category + +**Fix**: +```bash +# Re-run auto-detect +./scripts/registry/auto-detect-components.sh --auto-add + +# Validate +./scripts/registry/validate-registry.sh +``` + +--- + +### Component Not in Registry + +**Symptoms**: +- Component doesn't appear in `./install.sh --list` +- Auto-detect doesn't find component + +**Diagnosis**: +```bash +# Check frontmatter +head -10 .opencode/agent/{category}/{agent}.md + +# Dry run auto-detect +./scripts/registry/auto-detect-components.sh --dry-run +``` + +**Solutions**: +1. **Missing frontmatter**: Add frontmatter +2. **Invalid YAML**: Fix YAML syntax +3. **Wrong location**: Move to correct directory + +**Fix**: +```bash +# Add frontmatter +cat > .opencode/agent/{category}/{agent}.md << 'EOF' +--- +description: "Brief description" +category: "category" +type: "agent" +--- + +# Agent Content +EOF + +# Re-run auto-detect +./scripts/registry/auto-detect-components.sh --auto-add +``` + +--- + +## Test Failures + +### Approval Gate Violation + +**Symptoms**: +``` +✗ Approval Gate: FAIL + Violation: Agent executed write tool without requesting approval +``` + +**Diagnosis**: +```bash +# Run with debug +cd evals/framework +npm run eval:sdk -- --agent={agent} --pattern="{test}" --debug + +# Check session +ls -lt .tmp/sessions/ | head -5 +cat .tmp/sessions/{session-id}/session.json | jq +``` + +**Solution**: +Add approval request in agent prompt: +```markdown +Before executing: +1. Present plan to user +2. Request approval +3. Execute after approval +``` + +--- + +### Context Loading Violation + +**Symptoms**: +``` +✗ Context Loading: FAIL + Violation: Agent executed write tool without loading required context +``` + +**Diagnosis**: +```bash +# Check what context was loaded +cat .tmp/sessions/{session-id}/events.json | jq '.[] | select(.type == "context_load")' +``` + +**Solution**: +Add context loading in agent prompt: +```markdown +Before implementing: +1. Load core/standards/code-quality.md +2. Apply standards to implementation +``` + +--- + +### Tool Usage Violation + +**Symptoms**: +``` +✗ Tool Usage: FAIL + Violation: Agent used bash tool for reading file instead of read tool +``` + +**Diagnosis**: +```bash +# Check tool usage +cat .tmp/sessions/{session-id}/events.json | jq '.[] | select(.type == "tool_call")' +``` + +**Solution**: +Update agent to use correct tools: +- Use `read` instead of `bash cat` +- Use `list` instead of `bash ls` +- Use `grep` instead of `bash grep` + +--- + +## Install Issues + +### Install Script Fails + +**Symptoms**: +``` +ERROR: Failed to fetch registry +ERROR: Component not found +``` + +**Diagnosis**: +```bash +# Check dependencies +which curl jq + +# Test with local registry +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --list +``` + +**Solutions**: +1. **Missing dependencies**: Install curl and jq +2. **Registry not found**: Check registry.json exists +3. **Component not found**: Verify component in registry + +**Fix**: +```bash +# Install dependencies (macOS) +brew install curl jq + +# Install dependencies (Linux) +sudo apt-get install curl jq + +# Test locally +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --list +``` + +--- + +### Collision Handling + +**Symptoms**: +``` +File exists: .opencode/agent/core/openagent.md +``` + +**Solutions**: +1. **Skip**: Keep existing file +2. **Overwrite**: Replace with new file +3. **Backup**: Backup existing, install new + +**Fix**: +```bash +# Skip all collisions +./install.sh developer --skip-existing + +# Overwrite all collisions +./install.sh developer --force + +# Backup all collisions +./install.sh developer --backup +``` + +--- + +## Path Resolution Issues + +### Agent Not Found + +**Symptoms**: +``` +ERROR: Agent not found: development/frontend-specialist +``` + +**Diagnosis**: +```bash +# Check file exists +ls -la .opencode/agent/development/frontend-specialist.md + +# Check registry +cat registry.json | jq '.components.agents[] | select(.id == "frontend-specialist")' +``` + +**Solutions**: +1. **File doesn't exist**: Create file +2. **Wrong path**: Fix path in registry +3. **Not in registry**: Run auto-detect + +**Fix**: +```bash +# Re-run auto-detect +./scripts/registry/auto-detect-components.sh --auto-add + +# Validate +./scripts/registry/validate-registry.sh +``` + +--- + +## Version Issues + +### Version Mismatch + +**Symptoms**: +``` +VERSION: 0.5.0 +package.json: 0.4.0 +registry.json: 0.5.0 +``` + +**Diagnosis**: +```bash +cat VERSION +cat package.json | jq '.version' +cat registry.json | jq '.version' +``` + +**Solution**: +Update all to same version: +```bash +echo "0.5.0" > VERSION +jq '.version = "0.5.0"' package.json > tmp && mv tmp package.json +jq '.version = "0.5.0"' registry.json > tmp && mv tmp registry.json +``` + +--- + +## CI/CD Issues + +### Workflow Fails + +**Symptoms**: +- Registry validation fails in CI +- Tests fail in CI but pass locally + +**Diagnosis**: +```bash +# Run same commands as CI +./scripts/registry/validate-registry.sh +./scripts/validation/validate-test-suites.sh +cd evals/framework && npm run eval:sdk +``` + +**Solutions**: +1. **Registry invalid**: Fix registry +2. **Tests fail**: Fix tests +3. **Dependencies missing**: Update CI config + +--- + +## Performance Issues + +### Tests Timeout + +**Symptoms**: +``` +ERROR: Test timeout after 60000ms +``` + +**Solution**: +Increase timeout in config.yaml: +```yaml +timeout: 120000 # 2 minutes +``` + +--- + +### Slow Auto-Detect + +**Symptoms**: +Auto-detect takes too long + +**Solution**: +Limit scope: +```bash +# Only scan specific directory +./scripts/registry/auto-detect-components.sh --path .opencode/agent/development/ +``` + +--- + +## Getting Help + +### Check Logs + +```bash +# Session logs +ls -lt .tmp/sessions/ | head -5 +cat .tmp/sessions/{session-id}/session.json | jq + +# Event timeline +cat .tmp/sessions/{session-id}/events.json | jq +``` + +### Run Diagnostics + +```bash +# Full system check +./scripts/registry/validate-registry.sh -v +./scripts/validation/validate-test-suites.sh +cd evals/framework && npm run eval:sdk -- --agent=core/openagent +``` + +### Common Commands + +```bash +# Validate everything +./scripts/registry/validate-registry.sh && \ +./scripts/validation/validate-test-suites.sh && \ +cd evals/framework && npm run eval:sdk + +# Reset and rebuild +./scripts/registry/auto-detect-components.sh --auto-add --force +./scripts/registry/validate-registry.sh + +# Test installation +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --list +``` + +--- + +## Related Files + +- **Testing guide**: `guides/testing-agent.md` +- **Registry guide**: `guides/updating-registry.md` +- **Eval concepts**: `core-concepts/evals.md` + +--- + +**Last Updated**: 2025-12-10 +**Version**: 0.5.0 diff --git a/.opencode/context/openagents-repo/guides/external-libraries-workflow.md b/.opencode/context/openagents-repo/guides/external-libraries-workflow.md new file mode 100644 index 0000000..0f6dc58 --- /dev/null +++ b/.opencode/context/openagents-repo/guides/external-libraries-workflow.md @@ -0,0 +1,223 @@ + +# Guide: External Libraries Workflow + +**Purpose**: Fetch current documentation for external packages when adding agents or skills + +**When to Use**: Any time you're working with external libraries (Drizzle, Better Auth, Next.js, etc.) + +**Time to Read**: 5 minutes + +--- + +## Quick Start + +**Golden Rule**: NEVER rely on training data for external libraries → ALWAYS fetch current docs + +**Process**: +1. Detect external package in your task +2. Check for install scripts (if first-time setup) +3. Use **ExternalScout** to fetch current documentation +4. Implement with fresh, version-specific knowledge + +--- + +## When to Use ExternalScout (MANDATORY) + +✅ **Use ExternalScout when**: +- Adding new agents that depend on external packages +- Adding new skills that integrate with external libraries +- First-time package setup in your implementation +- Package/dependency errors occur +- Version upgrades are needed +- ANY external library work + +❌ **Don't rely on**: +- Training data (outdated, often wrong) +- Old documentation (APIs change) +- Assumptions about package behavior + +--- + +## Why This Matters + +**Example**: Next.js Evolution +``` +Training data (2023): Next.js 13 uses pages/ directory +Current (2025): Next.js 15 uses app/ directory (App Router) + +Training data = broken code ❌ +ExternalScout = working code ✅ +``` + +**Real Impact**: +- APIs change (new methods, deprecated features) +- Configuration patterns evolve +- Breaking changes happen frequently +- Version-specific features differ + +--- + +## Workflow Steps + +### Step 1: Detect External Package + +**Triggers**: +- User mentions a library name +- You see imports in code +- package.json has new dependencies +- Build errors reference external packages + +**Action**: Identify which external packages are involved + +**Example**: +``` +User: "Add authentication with Better Auth" +→ External package detected: Better Auth +→ Proceed to Step 2 +``` + +--- + +### Step 2: Check Install Scripts (First-Time Only) + +**For first-time package setup**, check if there are install scripts: + +```bash +# Look for install scripts +ls scripts/install/ scripts/setup/ bin/install* setup.sh install.sh + +# Check package-specific requirements +grep -r "postinstall\|preinstall" package.json +``` + +**If scripts exist**: +- Read them to understand setup order +- Check for environment variables needed +- Identify prerequisites (database, services) +- Follow their guidance before implementing + +**Why**: Scripts may set up databases, generate files, or configure services in a specific order + +--- + +### Step 3: Fetch Current Documentation (MANDATORY) + +**Use ExternalScout** to get live, version-specific documentation: + +```bash +# Invoke ExternalScout via task tool +task( + subagent_type="ExternalScout", + description="Fetch Drizzle ORM documentation", + prompt="Fetch current documentation for Drizzle ORM focusing on: + - Modular schema patterns + - Next.js integration + - Database setup + - Migration strategies" +) +``` + +**What ExternalScout Returns**: +- Live documentation from official sources +- Version-specific features +- Integration patterns +- Setup requirements +- Code examples + +**Supported Libraries** (18+): +- Drizzle ORM +- Better Auth +- Next.js +- TanStack Query/Router/Start +- Cloudflare Workers +- AWS Lambda +- Vercel +- Shadcn/ui +- Radix UI +- Tailwind CSS +- Zustand +- Jotai +- Zod +- React Hook Form +- Vitest +- Playwright +- And more... + +--- + +### Step 4: Implement with Fresh Knowledge + +**Now implement** using the documentation from ExternalScout: +- Follow current best practices +- Use version-specific APIs +- Apply recommended patterns +- Reference the fetched docs in your code + +--- + +## Integration with Agent/Skill Creation + +### When Adding an Agent + +1. Read: `guides/adding-agent.md` +2. **If agent uses external packages**: + - Use ExternalScout to fetch docs + - Document dependencies in agent metadata + - Add to registry with correct versions +3. Test: `guides/testing-agent.md` + +### When Adding a Skill + +1. Read: `guides/adding-skill.md` +2. **If skill uses external packages**: + - Use ExternalScout to fetch docs + - Document dependencies in skill metadata + - Add to registry with correct versions +3. Test: `guides/testing-subagents.md` + +--- + +## Common Packages in OpenAgents + +| Package | Use Case | Priority | +|---------|----------|----------| +| **Drizzle ORM** | Database schemas & queries | ⭐⭐⭐⭐⭐ | +| **Better Auth** | Authentication & authorization | ⭐⭐⭐⭐⭐ | +| **Next.js** | Full-stack web framework | ⭐⭐⭐⭐⭐ | +| **TanStack Query** | Server state management | ⭐⭐⭐⭐ | +| **Zod** | Schema validation | ⭐⭐⭐⭐ | +| **Tailwind CSS** | Styling | ⭐⭐⭐⭐ | +| **Shadcn/ui** | UI components | ⭐⭐⭐ | +| **Vitest** | Testing framework | ⭐⭐⭐ | + +--- + +## Checklist + +Before implementing with external libraries: + +- [ ] Identified all external packages involved +- [ ] Checked for install scripts (if first-time) +- [ ] Used ExternalScout to fetch current docs +- [ ] Reviewed version-specific features +- [ ] Documented dependencies in metadata +- [ ] Added to registry with correct versions +- [ ] Tested implementation thoroughly +- [ ] Referenced ExternalScout docs in code comments + +--- + +## Related Guides + +- `guides/adding-agent.md` - Creating new agents +- `guides/adding-skill.md` - Creating new skills +- `guides/debugging.md` - Troubleshooting (includes dependency issues) +- `guides/updating-registry.md` - Registry management + +--- + +## Key Principle + +> **External libraries change constantly. Your training data is outdated. Always fetch current documentation before implementing.** + +This is not optional - it's the difference between working code and broken code. diff --git a/.opencode/context/openagents-repo/guides/github-issues-workflow.md b/.opencode/context/openagents-repo/guides/github-issues-workflow.md new file mode 100644 index 0000000..c36662a --- /dev/null +++ b/.opencode/context/openagents-repo/guides/github-issues-workflow.md @@ -0,0 +1,471 @@ +# Guide: GitHub Issues and Project Board Workflow + +**Prerequisites**: Basic understanding of GitHub issues and projects +**Purpose**: Step-by-step workflow for managing issues and project board + +--- + +## Overview + +This guide covers how to work with GitHub issues and the project board to track and process different requests, features, and improvements. + +**Project Board**: https://github.com/users/darrenhinde/projects/2/views/2 + +**Time**: Varies by task + +--- + +## Quick Commands Reference + +```bash +# List issues +gh issue list --repo darrenhinde/OpenAgentsControl + +# Create issue +gh issue create --repo darrenhinde/OpenAgentsControl --title "Title" --body "Body" --label "label1,label2" + +# Add issue to project +gh project item-add 2 --owner darrenhinde --url https://github.com/darrenhinde/OpenAgentsControl/issues/NUMBER + +# View issue +gh issue view NUMBER --repo darrenhinde/OpenAgentsControl + +# Update issue +gh issue edit NUMBER --repo darrenhinde/OpenAgentsControl --add-label "new-label" + +# Close issue +gh issue close NUMBER --repo darrenhinde/OpenAgentsControl +``` + +--- + +## Step 1: Creating Issues + +### Issue Types + +**Feature Request** +- Labels: `feature`, `enhancement` +- Include: Goals, key features, success criteria +- Template: See "Feature Issue Template" below + +**Bug Report** +- Labels: `bug` +- Include: Steps to reproduce, expected vs actual behavior +- Template: See "Bug Issue Template" below + +**Improvement** +- Labels: `enhancement`, `framework` +- Include: Current state, proposed improvement, impact + +**Question** +- Labels: `question` +- Include: Context, specific question, use case + +### Priority Labels + +- `priority-high` - Critical, blocking work +- `priority-medium` - Important, not blocking +- `priority-low` - Nice to have + +### Category Labels + +- `agents` - Agent system related +- `framework` - Core framework changes +- `evals` - Evaluation framework +- `idea` - High-level proposal + +### Creating an Issue + +```bash +# Basic issue +gh issue create \ + --repo darrenhinde/OpenAgentsControl \ + --title "Add new feature X" \ + --body "Description of feature" \ + --label "feature,priority-medium" + +# Feature with detailed body +gh issue create \ + --repo darrenhinde/OpenAgentsControl \ + --title "Build plugin system" \ + --label "feature,framework,priority-high" \ + --body "$(cat <<'EOF' +## Overview +Brief description + +## Goals +- Goal 1 +- Goal 2 + +## Key Features +- Feature 1 +- Feature 2 + +## Success Criteria +- [ ] Criterion 1 +- [ ] Criterion 2 +EOF +)" +``` + +--- + +## Step 2: Adding Issues to Project Board + +### Add Single Issue + +```bash +# Add issue to project +gh project item-add 2 \ + --owner darrenhinde \ + --url https://github.com/darrenhinde/OpenAgentsControl/issues/NUMBER +``` + +### Add Multiple Issues + +```bash +# Add issues 137-142 to project +for i in {137..142}; do + gh project item-add 2 \ + --owner darrenhinde \ + --url https://github.com/darrenhinde/OpenAgentsControl/issues/$i +done +``` + +### Verify Issues on Board + +```bash +# View project items +gh project item-list 2 --owner darrenhinde --format json | jq '.items[] | {title, status}' +``` + +--- + +## Step 3: Processing Issues + +### Workflow States + +1. **Backlog** - New issues, not yet prioritized +2. **Todo** - Prioritized, ready to work on +3. **In Progress** - Currently being worked on +4. **In Review** - PR submitted, awaiting review +5. **Done** - Completed and merged + +### Moving Issues + +```bash +# Update issue status (via project board UI or gh CLI) +# Note: Status updates are typically done via web UI +``` + +### Assigning Issues + +```bash +# Assign to yourself +gh issue edit NUMBER \ + --repo darrenhinde/OpenAgentsControl \ + --add-assignee @me + +# Assign to someone else +gh issue edit NUMBER \ + --repo darrenhinde/OpenAgentsControl \ + --add-assignee username +``` + +--- + +## Step 4: Working on Issues + +### Start Work + +1. **Assign issue to yourself** + ```bash + gh issue edit NUMBER --repo darrenhinde/OpenAgentsControl --add-assignee @me + ``` + +2. **Move to "In Progress"** (via web UI) + +3. **Create branch** (optional) + ```bash + git checkout -b feature/issue-NUMBER-description + ``` + +4. **Reference issue in commits** + ```bash + git commit -m "feat: implement X (#NUMBER)" + ``` + +### Update Progress + +```bash +# Add comment to issue +gh issue comment NUMBER \ + --repo darrenhinde/OpenAgentsControl \ + --body "Progress update: Completed X, working on Y" +``` + +### Complete Work + +1. **Create PR** + ```bash + gh pr create \ + --repo darrenhinde/OpenAgentsControl \ + --title "Fix #NUMBER: Description" \ + --body "Closes #NUMBER\n\nChanges:\n- Change 1\n- Change 2" + ``` + +2. **Move to "In Review"** (via web UI) + +3. **After merge, issue auto-closes** (if PR uses "Closes #NUMBER") + +--- + +## Step 5: Using Issues for Request Processing + +### Request Types + +**User Feature Request** +1. Create issue with `feature` label +2. Add to project board +3. Prioritize based on impact +4. Break down into subtasks if needed +5. Assign to appropriate person/team + +**Bug Report** +1. Create issue with `bug` label +2. Add reproduction steps +3. Prioritize based on severity +4. Assign for investigation +5. Link to related issues if applicable + +**Improvement Suggestion** +1. Create issue with `enhancement` label +2. Discuss approach in comments +3. Get consensus before implementation +4. Create implementation plan +5. Execute and track progress + +### Breaking Down Large Issues + +For complex features, create parent issue and subtasks: + +```bash +# Parent issue +gh issue create \ + --repo darrenhinde/OpenAgentsControl \ + --title "[EPIC] Plugin System" \ + --label "feature,framework,priority-high" \ + --body "Parent issue for plugin system work" + +# Subtask issues +gh issue create \ + --repo darrenhinde/OpenAgentsControl \ + --title "Plugin manifest system" \ + --label "feature" \ + --body "Part of #PARENT_NUMBER\n\nImplement plugin.json manifest" +``` + +--- + +## Step 6: Issue Templates + +### Feature Issue Template + +```markdown +## Overview +Brief description of the feature + +## Goals +- Goal 1 +- Goal 2 +- Goal 3 + +## Key Features +- Feature 1 +- Feature 2 +- Feature 3 + +## Related Issues +- #123 (related issue) + +## Success Criteria +- [ ] Criterion 1 +- [ ] Criterion 2 +- [ ] Criterion 3 +``` + +### Bug Issue Template + +```markdown +## Description +Brief description of the bug + +## Steps to Reproduce +1. Step 1 +2. Step 2 +3. Step 3 + +## Expected Behavior +What should happen + +## Actual Behavior +What actually happens + +## Environment +- OS: macOS/Linux/Windows +- Version: 0.5.2 +- Node: v20.x + +## Additional Context +Any other relevant information +``` + +### Improvement Issue Template + +```markdown +## Current State +Description of current implementation + +## Proposed Improvement +What should be improved and why + +## Impact +- Performance improvement +- Developer experience +- User experience + +## Implementation Approach +High-level approach to implementation + +## Success Criteria +- [ ] Criterion 1 +- [ ] Criterion 2 +``` + +--- + +## Step 7: Automation and Integration + +### Auto-Close Issues + +Use keywords in PR descriptions: +- `Closes #123` +- `Fixes #123` +- `Resolves #123` + +### Link Issues to PRs + +```bash +# In PR description +gh pr create \ + --title "Add feature X" \ + --body "Implements #123\n\nChanges:\n- Change 1" +``` + +### Issue References in Commits + +```bash +# Reference issue in commit +git commit -m "feat: add plugin system (#137)" + +# Close issue in commit +git commit -m "fix: resolve permission error (closes #140)" +``` + +--- + +## Best Practices + +### Issue Creation + +✅ **Clear titles** - Descriptive and specific +✅ **Detailed descriptions** - Include context and goals +✅ **Proper labels** - Use consistent labeling +✅ **Success criteria** - Define what "done" means +✅ **Link related issues** - Show dependencies + +### Issue Management + +✅ **Regular triage** - Review and prioritize weekly +✅ **Keep updated** - Add comments on progress +✅ **Close stale issues** - Clean up old/irrelevant issues +✅ **Use milestones** - Group related issues +✅ **Assign owners** - Clear responsibility + +### Project Board + +✅ **Update status** - Keep board current +✅ **Limit WIP** - Don't overload "In Progress" +✅ **Review regularly** - Weekly board review +✅ **Archive completed** - Keep board clean + +--- + +## Common Workflows + +### Processing User Request + +1. **Receive request** (via issue, email, chat) +2. **Create issue** with appropriate labels +3. **Add to project board** +4. **Triage and prioritize** +5. **Assign to team member** +6. **Track progress** via status updates +7. **Review and merge** PR +8. **Close issue** and notify requester + +### Planning New Feature + +1. **Create epic issue** for overall feature +2. **Break down into subtasks** +3. **Add all to project board** +4. **Prioritize subtasks** +5. **Assign to team members** +6. **Track progress** across subtasks +7. **Complete and close** when all subtasks done + +### Bug Triage + +1. **Create bug issue** with reproduction steps +2. **Label with severity** (critical, high, medium, low) +3. **Add to project board** +4. **Assign for investigation** +5. **Reproduce and diagnose** +6. **Fix and test** +7. **Create PR** with fix +8. **Close issue** after merge + +--- + +## Checklist + +Before closing an issue: + +- [ ] All success criteria met +- [ ] Tests passing +- [ ] Documentation updated +- [ ] PR merged (if applicable) +- [ ] Related issues updated +- [ ] Stakeholders notified + +--- + +## Related Files + +- **Registry guide**: `guides/updating-registry.md` +- **Release guide**: `guides/creating-release.md` +- **Testing guide**: `guides/testing-agent.md` +- **Debugging**: `guides/debugging.md` + +--- + +## External Resources + +- [GitHub Issues Documentation](https://docs.github.com/en/issues) +- [GitHub Projects Documentation](https://docs.github.com/en/issues/planning-and-tracking-with-projects) +- [GitHub CLI Documentation](https://cli.github.com/manual/) + +--- + +**Last Updated**: 2026-01-30 +**Version**: 0.5.2 diff --git a/.opencode/context/openagents-repo/guides/navigation.md b/.opencode/context/openagents-repo/guides/navigation.md new file mode 100644 index 0000000..a0a8363 --- /dev/null +++ b/.opencode/context/openagents-repo/guides/navigation.md @@ -0,0 +1,42 @@ +# OpenAgents Guides + +**Purpose**: Step-by-step guides for working with OpenAgents Control + +--- + +## Structure + +``` +openagents-repo/guides/ +├── navigation.md (this file) +└── [guide files] +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **Adding agents (basics)** | `./adding-agent-basics.md` | +| **Adding agents (tests)** | `./adding-agent-testing.md` | +| **Adding OpenCode skills** | `./adding-skill-basics.md` | +| **Creating Claude Code skills** | `./creating-skills.md` | +| **Creating Claude Code subagents** | `./creating-subagents.md` | +| **Testing subagents** | `./testing-subagents.md` | + +--- + +## By Type + +**Implementation Guides** → How to implement features +**Agent Guides** → How to work with agents +**Testing Guides** → How to test implementations + +--- + +## Related Context + +- **OpenAgents Navigation** → `../navigation.md` +- **Examples** → `../examples/navigation.md` +- **Core Concepts** → `../core-concepts/navigation.md` diff --git a/.opencode/context/openagents-repo/guides/npm-publishing.md b/.opencode/context/openagents-repo/guides/npm-publishing.md new file mode 100644 index 0000000..baba9c5 --- /dev/null +++ b/.opencode/context/openagents-repo/guides/npm-publishing.md @@ -0,0 +1,153 @@ +# NPM Publishing Guide + +**Purpose**: Quick reference for publishing OpenAgents Control to npm + +**Time to Read**: 3 minutes + +--- + +## Core Concept + +OpenAgents Control is published as `@nextsystems/oac` on npm. Users install globally and run `oac [profile]` to set up their projects. + +**Key files**: +- `package.json` - Package configuration +- `bin/oac.js` - CLI entry point +- `.npmignore` - Exclude dev files +- `install.sh` - Main installer (runs when user executes `oac`) + +--- + +## Publishing Workflow + +### 1. Prepare Release + +```bash +# Update version +npm version patch # 0.7.0 -> 0.7.1 +npm version minor # 0.7.0 -> 0.8.0 + +# Update VERSION file +node -p "require('./package.json').version" > VERSION + +# Update CHANGELOG.md with changes +``` + +### 2. Test Locally + +```bash +# Create package +npm pack + +# Install globally from tarball +npm install -g ./nextsystems-oac-0.7.1.tgz + +# Test CLI +oac --version +oac --help + +# Uninstall +npm uninstall -g @nextsystems/oac +``` + +### 3. Publish + +```bash +# Login (one-time) +npm login + +# Publish (scoped packages need --access public) +npm publish --access public +``` + +### 4. Verify + +```bash +# Check it's live +npm view @nextsystems/oac + +# Test installation +npm install -g @nextsystems/oac +oac --version +``` + +### 5. Create GitHub Release + +```bash +git tag v0.7.1 +git push --tags +# Create release on GitHub with changelog +``` + +--- + +## User Installation + +Once published, users can: + +```bash +# Global install (recommended) +npm install -g @nextsystems/oac +oac developer + +# Or use npx (no install) +npx @nextsystems/oac developer +``` + +--- + +## Common Issues + +**"You do not have permission to publish"** +```bash +npm whoami # Check you're logged in +npm publish --access public # Scoped packages need public access +``` + +**"Version already exists"** +```bash +npm version patch # Bump version first +``` + +**"You must verify your email"** +```bash +npm profile get # Check email verification status +``` + +--- + +## Package Configuration + +**What's included** (see `package.json` → `files`): +- `.opencode/` - Agents, commands, context, profiles, skills, tools +- `scripts/` - Installation scripts +- `bin/` - CLI entry point +- `registry.json` - Component registry +- `install.sh` - Main installer +- Docs (README, CHANGELOG, LICENSE) + +**What's excluded** (see `.npmignore`): +- `node_modules/` +- `evals/` +- `.tmp/` +- Dev files + +--- + +## Security + +- ✅ Enable 2FA: `npm profile enable-2fa auth-and-writes` +- ✅ Use strong npm password +- ✅ `@nextsystems` scope is protected (only you can publish) + +--- + +## References + +- **Package**: https://www.npmjs.com/package/@nextsystems/oac +- **Stats**: https://npm-stat.com/charts.html?package=@nextsystems/oac +- **Codebase**: `package.json`, `bin/oac.js`, `.npmignore` + +--- + +**Last Updated**: 2026-01-30 diff --git a/.opencode/context/openagents-repo/guides/profile-validation.md b/.opencode/context/openagents-repo/guides/profile-validation.md new file mode 100644 index 0000000..7f1e0f5 --- /dev/null +++ b/.opencode/context/openagents-repo/guides/profile-validation.md @@ -0,0 +1,368 @@ +# Guide: Profile Validation + +**Purpose**: Ensure installation profiles include all appropriate components +**Priority**: HIGH - Check this when adding new agents or updating registry + +--- + +## What Are Profiles? + +Profiles are pre-configured component bundles in `registry.json` that users install: +- **essential** - Minimal setup (openagent + core subagents) +- **developer** - Full dev environment (all dev agents + tools) +- **business** - Content/product focus (content agents + tools) +- **full** - Everything (all agents, subagents, tools) +- **advanced** - Full + meta-level (system-builder, repo-manager) + +--- + +## The Problem + +**Issue**: New agents added to `components.agents[]` but NOT added to profiles + +**Result**: Users install a profile but don't get the new agents + +**Example** (v0.5.0 bug): +```json +// ✅ Agent exists in components +{ + "id": "devops-specialist", + "path": ".opencode/agent/development/devops-specialist.md" +} + +// ❌ But NOT in developer profile +"developer": { + "components": [ + "agent:openagent", + "agent:opencoder" + // Missing: "agent:devops-specialist" + ] +} +``` + +--- + +## Validation Checklist + +When adding a new agent, **ALWAYS** check: + +### 1. Agent Added to Components +```bash +# Check agent exists in registry +cat registry.json | jq '.components.agents[] | select(.id == "your-agent")' +``` + +### 2. Agent Added to Appropriate Profiles + +**Development agents** → Add to: +- ✅ `developer` profile +- ✅ `full` profile +- ✅ `advanced` profile + +**Content agents** → Add to: +- ✅ `business` profile +- ✅ `full` profile +- ✅ `advanced` profile + +**Data agents** → Add to: +- ✅ `business` profile (if business-focused) +- ✅ `full` profile +- ✅ `advanced` profile + +**Meta agents** → Add to: +- ✅ `advanced` profile only + +**Core agents** → Add to: +- ✅ `essential` profile +- ✅ All other profiles + +### 3. Verify Profile Includes Agent + +```bash +# Check if agent is in developer profile +cat registry.json | jq '.profiles.developer.components[] | select(. == "agent:your-agent")' + +# Check if agent is in business profile +cat registry.json | jq '.profiles.business.components[] | select(. == "agent:your-agent")' + +# Check if agent is in full profile +cat registry.json | jq '.profiles.full.components[] | select(. == "agent:your-agent")' +``` + +--- + +## Profile Assignment Rules + +### Developer Profile +**Include**: +- Core agents (openagent, opencoder) +- Development specialist subagents (frontend, devops) +- All code subagents (tester, reviewer, coder-agent, build-agent) +- Dev commands (commit, test, validate-repo, analyze-patterns) +- Dev context (standards/code, standards/tests, workflows/*) +- Utility subagents (image-specialist for website images) +- Tools (env, gemini for image generation) + +**Exclude**: +- Content agents (copywriter, technical-writer) +- Data agents (data-analyst) +- Meta agents (system-builder, repo-manager) + +### Business Profile +**Include**: +- Core agent (openagent) +- Content specialists (copywriter, technical-writer) +- Data specialists (data-analyst) +- Image tools (gemini, image-specialist) +- Notification tools (notify) + +**Exclude**: +- Development specialists +- Code subagents +- Meta agents + +### Full Profile +**Include**: +- Everything from developer profile +- Everything from business profile +- All agents except meta agents + +**Exclude**: +- Meta agents (system-builder, repo-manager) + +### Advanced Profile +**Include**: +- Everything from full profile +- Meta agents (system-builder, repo-manager) +- Meta subagents (domain-analyzer, agent-generator, etc.) +- Meta commands (build-context-system) + +--- + +## Automated Validation + +### Script to Check Profile Coverage + +```bash +#!/bin/bash +# Check if all agents are in appropriate profiles + +echo "Checking profile coverage..." + +# Get all agent IDs +agents=$(cat registry.json | jq -r '.components.agents[].id') + +for agent in $agents; do + # Get agent category + category=$(cat registry.json | jq -r ".components.agents[] | select(.id == \"$agent\") | .category") + + # Check which profiles include this agent + in_developer=$(cat registry.json | jq ".profiles.developer.components[] | select(. == \"agent:$agent\")" 2>/dev/null) + in_business=$(cat registry.json | jq ".profiles.business.components[] | select(. == \"agent:$agent\")" 2>/dev/null) + in_full=$(cat registry.json | jq ".profiles.full.components[] | select(. == \"agent:$agent\")" 2>/dev/null) + in_advanced=$(cat registry.json | jq ".profiles.advanced.components[] | select(. == \"agent:$agent\")" 2>/dev/null) + + # Validate based on category + case $category in + "development") + if [[ -z "$in_developer" ]]; then + echo "❌ $agent (development) missing from developer profile" + fi + if [[ -z "$in_full" ]]; then + echo "❌ $agent (development) missing from full profile" + fi + if [[ -z "$in_advanced" ]]; then + echo "❌ $agent (development) missing from advanced profile" + fi + ;; + "content"|"data") + if [[ -z "$in_business" ]]; then + echo "❌ $agent ($category) missing from business profile" + fi + if [[ -z "$in_full" ]]; then + echo "❌ $agent ($category) missing from full profile" + fi + if [[ -z "$in_advanced" ]]; then + echo "❌ $agent ($category) missing from advanced profile" + fi + ;; + "meta") + if [[ -z "$in_advanced" ]]; then + echo "❌ $agent (meta) missing from advanced profile" + fi + ;; + "essential"|"standard") + if [[ -z "$in_full" ]]; then + echo "❌ $agent ($category) missing from full profile" + fi + if [[ -z "$in_advanced" ]]; then + echo "❌ $agent ($category) missing from advanced profile" + fi + ;; + esac +done + +echo "✅ Profile coverage check complete" +``` + +Save this as: `scripts/registry/validate-profile-coverage.sh` + +--- + +## Manual Validation Steps + +### After Adding a New Agent + +1. **Add agent to components**: + ```bash + ./scripts/registry/auto-detect-components.sh --auto-add + ``` + +2. **Manually add to profiles**: + Edit `registry.json` and add `"agent:your-agent"` to appropriate profiles + +3. **Validate registry**: + ```bash + ./scripts/registry/validate-registry.sh + ``` + +4. **Test local install**: + ```bash + # Test developer profile + REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --list + + # Verify agent appears in profile + REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --list | grep "your-agent" + ``` + +5. **Test actual install**: + ```bash + # Install to temp directory + mkdir -p /tmp/test-install + cd /tmp/test-install + REGISTRY_URL="file://$(pwd)/registry.json" bash <(curl -s https://raw.githubusercontent.com/darrenhinde/OpenAgentsControl/main/install.sh) developer + + # Check if agent was installed + ls .opencode/agent/category/your-agent.md + ``` + +--- + +## Common Mistakes + +### ❌ Mistake 1: Only Adding to Components +```json +// Added to components +"components": { + "agents": [ + {"id": "new-agent", ...} + ] +} + +// But forgot to add to profiles +"profiles": { + "developer": { + "components": [ + // Missing: "agent:new-agent" + ] + } +} +``` + +### ❌ Mistake 2: Wrong Profile Assignment +```json +// Development agent added to business profile +"business": { + "components": [ + "agent:devops-specialist" // ❌ Should be in developer + ] +} +``` + +### ❌ Mistake 3: Inconsistent Profile Coverage +```json +// Added to full but not advanced +"full": { + "components": ["agent:new-agent"] +}, +"advanced": { + "components": [ + // ❌ Missing: "agent:new-agent" + ] +} +``` + +--- + +## Best Practices + +✅ **Use auto-detect** - Adds to components automatically +✅ **Check all profiles** - Verify agent in correct profiles +✅ **Test locally** - Install and verify before pushing +✅ **Validate** - Run validation script after changes +✅ **Document** - Update CHANGELOG with profile changes + +--- + +## CI/CD Integration + +Add profile validation to CI: + +```yaml +# .github/workflows/validate-registry.yml +- name: Validate Registry + run: ./scripts/registry/validate-registry.sh + +- name: Validate Profile Coverage + run: ./scripts/registry/validate-profile-coverage.sh +``` + +--- + +## Quick Reference + +| Agent Category | Essential | Developer | Business | Full | Advanced | +|---------------|-----------|-----------|----------|------|----------| +| core | ✅ | ✅ | ✅ | ✅ | ✅ | +| development* | ❌ | ✅ | ❌ | ✅ | ✅ | +| content | ❌ | ❌ | ✅ | ✅ | ✅ | +| data | ❌ | ❌ | ✅ | ✅ | ✅ | +| meta | ❌ | ❌ | ❌ | ❌ | ✅ | + +*Note: Development category includes agents (opencoder) and specialist subagents (frontend, devops) + +--- + +## Development Profile Changes (v2.0.0) + +**What Changed**: +- frontend-specialist: Agent → Subagent (specialized executor) +- devops-specialist: Agent → Subagent (specialized executor) +- backend-specialist: Removed (functionality covered by opencoder) +- codebase-pattern-analyst: Removed (replaced by analyze-patterns command) +- analyze-patterns: New command for pattern analysis + +**Why**: +- Streamlined main agents to 2 (openagent, opencoder) +- Specialist subagents provide focused expertise when needed +- Reduced cognitive load for new users +- Clearer separation between main agents and specialized tools + +**Impact**: +- Developer profile now has 2 main agents + 8 subagents +- Smaller, more focused profile +- Same capabilities, better organization +- No breaking changes for existing workflows + +--- + +## Related Files + +- **Registry concepts**: `core-concepts/registry.md` +- **Updating registry**: `guides/updating-registry.md` +- **Adding agents**: `guides/adding-agent.md` + +--- + +**Last Updated**: 2025-01-28 +**Version**: 0.5.2 diff --git a/.opencode/context/openagents-repo/guides/resolving-installer-wildcard-failures.md b/.opencode/context/openagents-repo/guides/resolving-installer-wildcard-failures.md new file mode 100644 index 0000000..ce49a5f --- /dev/null +++ b/.opencode/context/openagents-repo/guides/resolving-installer-wildcard-failures.md @@ -0,0 +1,57 @@ +# Guide: Resolving Installer Wildcard Failures + +**Purpose**: Capture the root cause, fix, and lessons from wildcard context install failures. + +**Last Updated**: 2026-01-12 + +--- + +## Prerequisites +- Installer changes scoped to `install.sh` +- Registry entries validated (`./scripts/registry/validate-registry.sh`) + +**Estimated time**: 10 min + +## Steps + +### 1. Identify the failure mode +**Symptom**: +``` +curl: (3) URL rejected: Malformed input to a URL function +``` +**Cause**: Wildcard expansion returned context IDs that weren’t path-aligned (e.g., `standards-code` mapped to `.opencode/context/core/standards/code-quality.md`). Installer treated IDs as paths. + +### 2. Expand wildcards to path-based IDs +**Goal**: Make wildcard expansion output `core/...` IDs that map directly to a path. + +**Update**: +- Expand `context:core/*` to `core/standards/code-quality` style IDs + +### 3. Resolve context paths deterministically +**Goal**: Avoid ambiguous matches and ensure one registry entry is used. + +**Update**: +- Add `resolve_component_path` to map context IDs to the registry path +- Use `first(...)` in jq queries for deterministic selection + +### 4. Verify installation +```bash +bash scripts/tests/test-e2e-install.sh +``` +**Expected**: All E2E tests pass on macOS and Ubuntu. + +## Verification +```bash +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --list +``` + +## Troubleshooting +| Issue | Solution | +|-------|----------| +| `Malformed input to a URL function` | Ensure wildcard expansion returns `core/...` IDs and uses `resolve_component_path` | +| Multiple context entries for one path | Use `first(...)` in jq lookups | + +## Related +- guides/debugging.md +- guides/updating-registry.md +- core-concepts/registry.md diff --git a/.opencode/context/openagents-repo/guides/subagent-invocation.md b/.opencode/context/openagents-repo/guides/subagent-invocation.md new file mode 100644 index 0000000..c577506 --- /dev/null +++ b/.opencode/context/openagents-repo/guides/subagent-invocation.md @@ -0,0 +1,371 @@ +# Guide: Subagent Invocation + +**Purpose**: How to correctly invoke subagents using the task tool +**Priority**: HIGH - Critical for agent delegation + +--- + +## The Problem + +**Issue**: Agents trying to invoke subagents with incorrect `subagent_type` format + +**Error**: +``` +Unknown agent type: ContextScout is not a valid agent type +``` + +**Root Cause**: The `subagent_type` parameter in the task tool must match the registered agent type in the OpenCode CLI, not the file path. + +--- + +## Correct Subagent Invocation + +### Available Subagent Types + +Based on the OpenCode CLI registration, use these exact strings for `subagent_type`: + +**Core Subagents**: +- `"Task Manager"` - Task breakdown and planning +- `"Documentation"` - Documentation generation +- `"ContextScout"` - Context file discovery + +**Code Subagents**: +- `"Coder Agent"` - Code implementation +- `"TestEngineer"` - Test authoring +- `"Reviewer"` - Code review +- `"Build Agent"` - Build validation + +**System Builder Subagents**: +- `"Domain Analyzer"` - Domain analysis +- `"Agent Generator"` - Agent generation +- `"Context Organizer"` - Context organization +- `"Workflow Designer"` - Workflow design +- `"Command Creator"` - Command creation + +**Utility Subagents**: +- `"Image Specialist"` - Image generation/editing + +--- + +## Invocation Syntax + +### ✅ Correct Format + +```javascript +task( + subagent_type="Task Manager", + description="Break down feature into subtasks", + prompt="Detailed instructions..." +) +``` + +### ❌ Incorrect Formats + +```javascript +// ❌ Using file path +task( + subagent_type="TaskManager", + ... +) + +// ❌ Using kebab-case ID +task( + subagent_type="task-manager", + ... +) + +// ❌ Using registry path +task( + subagent_type=".opencode/agent/TaskManager.md", + ... +) +``` + +--- + +## How to Find the Correct Type + +### Method 1: Check Registry + +```bash +# List all subagent names +cat registry.json | jq -r '.components.subagents[] | "\(.name)"' +``` + +**Output**: +``` +Task Manager +Image Specialist +Reviewer +TestEngineer +Documentation Writer +Coder Agent +Build Agent +Domain Analyzer +Agent Generator +Context Organizer +Workflow Designer +Command Creator +ContextScout +``` + +### Method 2: Check OpenCode CLI + +```bash +# List available agents (if CLI supports it) +opencode list agents +``` + +### Method 3: Check Agent Frontmatter + +Look at the `name` field in the subagent's frontmatter: + +```yaml +--- +id: task-manager +name: Task Manager # ← Use this for subagent_type +type: subagent +--- +``` + +--- + +## Common Subagent Invocations + +### Task Manager + +```javascript +task( + subagent_type="Task Manager", + description="Break down complex feature", + prompt="Break down the following feature into atomic subtasks: + + Feature: {feature description} + + Requirements: + - {requirement 1} + - {requirement 2} + + Create subtask files in tasks/subtasks/{feature}/" +) +``` + +### Documentation + +```javascript +task( + subagent_type="Documentation", + description="Update documentation for feature", + prompt="Update documentation for {feature}: + + What changed: + - {change 1} + - {change 2} + + Files to update: + - {doc 1} + - {doc 2}" +) +``` + +### TestEngineer + +```javascript +task( + subagent_type="TestEngineer", + description="Write tests for feature", + prompt="Write comprehensive tests for {feature}: + + Files to test: + - {file 1} + - {file 2} + + Test coverage: + - Positive cases + - Negative cases + - Edge cases" +) +``` + +### Reviewer + +```javascript +task( + subagent_type="Reviewer", + description="Review implementation", + prompt="Review the following implementation: + + Files: + - {file 1} + - {file 2} + + Focus areas: + - Security + - Performance + - Code quality" +) +``` + +### Coder Agent + +```javascript +task( + subagent_type="Coder Agent", + description="Implement subtask", + prompt="Implement the following subtask: + + Subtask: {subtask description} + + Files to create/modify: + - {file 1} + + Requirements: + - {requirement 1} + - {requirement 2}" +) +``` + +--- + +## ContextScout Special Case + +**Status**: ⚠️ May not be registered in OpenCode CLI yet + +The `ContextScout` subagent exists in the repository but may not be registered in the OpenCode CLI's available agent types. + +### Workaround + +Until ContextScout is properly registered, use direct file operations instead: + +```javascript +// ❌ This may fail +task( + subagent_type="ContextScout", + description="Find context files", + prompt="Search for context related to {topic}" +) + +// ✅ Use direct operations instead +// 1. Use glob to find context files +glob(pattern="**/*.md", path=".opencode/context") + +// 2. Use grep to search content +grep(pattern="registry", path=".opencode/context") + +// 3. Read relevant files directly +read(filePath=".opencode/context/openagents-repo/core-concepts/registry.md") +``` + +--- + +## Fixing Existing Agents + +### Agents That Need Fixing + +1. **repo-manager.md** - Uses `ContextScout` +2. **opencoder.md** - Check if uses incorrect format + +### Fix Process + +1. **Find incorrect invocations**: + ```bash + grep -r 'subagent_type="subagents/' .opencode/agent --include="*.md" + ``` + +2. **Replace with correct format**: + ```bash + # Example: Fix task-manager invocation + # Old: subagent_type="TaskManager" + # New: subagent_type="Task Manager" + ``` + +3. **Test the fix**: + ```bash + # Run agent with test prompt + # Verify subagent delegation works + ``` + +--- + +## Validation + +### Check Subagent Type Before Using + +```javascript +// Pseudo-code for validation +available_types = [ + "Task Manager", + "Documentation", + "TestEngineer", + "Reviewer", + "Coder Agent", + "Build Agent", + "Image Specialist", + "Domain Analyzer", + "Agent Generator", + "Context Organizer", + "Workflow Designer", + "Command Creator" +] + +if subagent_type not in available_types: + error("Invalid subagent type: {subagent_type}") +``` + +--- + +## Best Practices + +✅ **Use exact names** - Match registry `name` field exactly +✅ **Check registry first** - Verify subagent exists before using +✅ **Test invocations** - Test delegation before committing +✅ **Document dependencies** - List required subagents in agent frontmatter + +❌ **Don't use paths** - Never use file paths as subagent_type +❌ **Don't use IDs** - Don't use kebab-case IDs +❌ **Don't assume** - Always verify subagent is registered + +--- + +## Troubleshooting + +### Error: "Unknown agent type" + +**Cause**: Subagent type not registered in CLI or incorrect format + +**Solutions**: +1. Check registry for correct name +2. Verify subagent exists in `.opencode/agent/subagents/` +3. Use exact name from registry `name` field +4. If subagent not registered, use direct operations instead + +### Error: "Subagent not found" + +**Cause**: Subagent file doesn't exist + +**Solutions**: +1. Check file exists at expected path +2. Verify registry entry is correct +3. Run `./scripts/registry/validate-registry.sh` + +### Delegation Fails Silently + +**Cause**: Subagent invoked but doesn't execute + +**Solutions**: +1. Check subagent has required tools enabled +2. Verify subagent permissions allow operation +3. Check subagent prompt is clear and actionable + +--- + +## Related Files + +- **Registry**: `registry.json` - Component catalog +- **Subagents**: `.opencode/agent/subagents/` - Subagent definitions +- **Validation**: `scripts/registry/validate-registry.sh` + +--- + +**Last Updated**: 2025-12-29 +**Version**: 0.5.1 diff --git a/.opencode/context/openagents-repo/guides/testing-agent.md b/.opencode/context/openagents-repo/guides/testing-agent.md new file mode 100644 index 0000000..8d6a20b --- /dev/null +++ b/.opencode/context/openagents-repo/guides/testing-agent.md @@ -0,0 +1,303 @@ +# Guide: Testing an Agent + +**Prerequisites**: Load `core-concepts/evals.md` first +**Purpose**: Step-by-step workflow for testing agents + +--- + +## Quick Start + +```bash +# Run smoke test +cd evals/framework +npm run eval:sdk -- --agent={category}/{agent} --pattern="smoke-test.yaml" + +# Run all tests for agent +npm run eval:sdk -- --agent={category}/{agent} + +# Run with debug +npm run eval:sdk -- --agent={category}/{agent} --debug +``` + +--- + +## Test Types + +### 1. Smoke Test +**Purpose**: Basic functionality check + +```yaml +name: Smoke Test +description: Verify agent responds correctly +agent: {category}/{agent} +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "Hello, can you help me?" +expectations: + - type: no_violations +``` + +**Run**: +```bash +npm run eval:sdk -- --agent={agent} --pattern="smoke-test.yaml" +``` + +--- + +### 2. Approval Gate Test +**Purpose**: Verify agent requests approval + +```yaml +name: Approval Gate Test +description: Verify agent requests approval before execution +agent: {category}/{agent} +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "Create a new file called test.js" +expectations: + - type: specific_evaluator + evaluator: approval_gate + should_pass: true +``` + +--- + +### 3. Context Loading Test +**Purpose**: Verify agent loads required context + +```yaml +name: Context Loading Test +description: Verify agent loads required context +agent: {category}/{agent} +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "Write a new function" +expectations: + - type: context_loaded + contexts: ["core/standards/code-quality.md"] +``` + +--- + +### 4. Tool Usage Test +**Purpose**: Verify agent uses correct tools + +```yaml +name: Tool Usage Test +description: Verify agent uses appropriate tools +agent: {category}/{agent} +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "Read the package.json file" +expectations: + - type: tool_usage + tools: ["read"] + min_count: 1 +``` + +--- + +## Running Tests + +### Single Test + +```bash +cd evals/framework +npm run eval:sdk -- --agent={category}/{agent} --pattern="{test-name}.yaml" +``` + +### All Tests for Agent + +```bash +cd evals/framework +npm run eval:sdk -- --agent={category}/{agent} +``` + +### All Tests (All Agents) + +```bash +cd evals/framework +npm run eval:sdk +``` + +### With Debug Output + +```bash +cd evals/framework +npm run eval:sdk -- --agent={agent} --pattern="{test}" --debug +``` + +--- + +## Interpreting Results + +### Pass Example + +``` +✓ Test: smoke-test.yaml + Status: PASS + Duration: 5.2s + + Evaluators: + ✓ Approval Gate: PASS + ✓ Context Loading: PASS + ✓ Tool Usage: PASS + ✓ Stop on Failure: PASS + ✓ Execution Balance: PASS +``` + +### Fail Example + +``` +✗ Test: approval-gate.yaml + Status: FAIL + Duration: 4.8s + + Evaluators: + ✗ Approval Gate: FAIL + Violation: Agent executed write tool without requesting approval + Location: Message #3, Tool call #1 + ✓ Context Loading: PASS + ✓ Tool Usage: PASS +``` + +--- + +## Debugging Failures + +### Step 1: Run with Debug + +```bash +npm run eval:sdk -- --agent={agent} --pattern="{test}" --debug +``` + +### Step 2: Check Session + +```bash +# Find recent session +ls -lt .tmp/sessions/ | head -5 + +# View session +cat .tmp/sessions/{session-id}/session.json | jq +``` + +### Step 3: Analyze Events + +```bash +# View event timeline +cat .tmp/sessions/{session-id}/events.json | jq +``` + +### Step 4: Identify Issue + +Common issues: +- **Approval Gate Violation**: Agent executed without approval +- **Context Loading Violation**: Agent didn't load required context +- **Tool Usage Violation**: Agent used wrong tool (bash instead of read) +- **Stop on Failure Violation**: Agent auto-fixed instead of stopping + +### Step 5: Fix Agent + +Update agent prompt to address the issue, then re-test. + +--- + +## Writing New Tests + +### Test Template + +```yaml +name: Test Name +description: What this test validates +agent: {category}/{agent} +model: anthropic/claude-sonnet-4-5 +conversation: + - role: user + content: "User message" + - role: assistant + content: "Expected response (optional)" +expectations: + - type: no_violations +``` + +### Best Practices + +✅ **Clear name** - Descriptive test name +✅ **Good description** - Explain what's being tested +✅ **Realistic scenario** - Test real-world usage +✅ **Specific expectations** - Clear pass/fail criteria +✅ **Fast execution** - Keep under 10 seconds + +--- + +## Common Test Patterns + +### Test Approval Workflow + +```yaml +conversation: + - role: user + content: "Create a new file" +expectations: + - type: specific_evaluator + evaluator: approval_gate + should_pass: true +``` + +### Test Context Loading + +```yaml +conversation: + - role: user + content: "Write new code" +expectations: + - type: context_loaded + contexts: ["core/standards/code-quality.md"] +``` + +### Test Tool Selection + +```yaml +conversation: + - role: user + content: "Read the README file" +expectations: + - type: tool_usage + tools: ["read"] + min_count: 1 +``` + +--- + +## Continuous Testing + +### Pre-Commit Hook + +```bash +# Setup pre-commit hook +./scripts/validation/setup-pre-commit-hook.sh +``` + +### CI/CD Integration + +Tests run automatically on: +- Pull requests +- Merges to main +- Release tags + +--- + +## Related Files + +- **Eval concepts**: `core-concepts/evals.md` +- **Debugging guide**: `guides/debugging.md` +- **Adding agents**: `guides/adding-agent.md` + +--- + +**Last Updated**: 2025-12-10 +**Version**: 0.5.0 diff --git a/.opencode/context/openagents-repo/guides/testing-subagents-approval.md b/.opencode/context/openagents-repo/guides/testing-subagents-approval.md new file mode 100644 index 0000000..9975cf1 --- /dev/null +++ b/.opencode/context/openagents-repo/guides/testing-subagents-approval.md @@ -0,0 +1,137 @@ +--- +description: "Guide for testing subagents and handling approval gates" +type: "context" +category: "openagents-repo" +tags: [testing, subagents, approval-gates] +--- + +# Testing Subagents: Approval Gates + +**Context**: openagents-repo/guides | **Priority**: HIGH | **Updated**: 2026-01-09 + +--- + +## Critical Rule: Subagents Don't Need Approval Gates + +**IMPORTANT**: When writing tests for subagents, DO NOT include `expectedViolations` for `approval-gate`. + +### Why? + +Subagents are **delegated to** by parent agents (OpenAgent, OpenCoder, etc.). The parent agent already requested and received approval before delegating. Therefore: + +- ✅ Subagents can execute tools directly without asking for approval +- ✅ Subagents inherit approval from their parent +- ❌ Subagents should NOT be tested for approval gate violations + +### Test Configuration for Subagents + +**Correct** (no approval gate expectations): +```yaml +category: developer +agent: ContextScout + +approvalStrategy: + type: auto-approve + +behavior: + mustUseTools: + - read + - glob + forbiddenTools: + - write + - edit + minToolCalls: 2 + maxToolCalls: 15 + +# NO expectedViolations for approval-gate! +``` + +**Incorrect** (don't do this): +```yaml +expectedViolations: + - rule: approval-gate # ❌ WRONG for subagents + shouldViolate: false + severity: error +``` + +--- + +## When to Test Approval Gates + +**Test approval gates for**: +- ✅ Primary agents (OpenAgent, OpenCoder, System Builder) +- ✅ Category agents (frontend-specialist, data-analyst, etc.) + +**Don't test approval gates for**: +- ❌ Subagents (contextscout, tester, reviewer, coder-agent, etc.) +- ❌ Any agent with `mode: subagent` in frontmatter + +--- + +## Approval Strategy for Subagents + +Always use `auto-approve` for subagent tests: + +```yaml +approvalStrategy: + type: auto-approve +``` + +This simulates the parent agent having already approved the delegation. + +--- + +## Example: ContextScout Test + +```yaml +id: contextscout-code-standards +name: "ContextScout: Code Standards Discovery" +description: Tests that ContextScout discovers code-related context files + +category: developer +agent: ContextScout + +prompts: + - text: | + Search for context files related to: coding standards + + Task type: code + + Return: + - Exact file paths + - Priority order + - Key findings + +approvalStrategy: + type: auto-approve + +behavior: + mustUseTools: + - read + - glob + forbiddenTools: + - write + - edit + minToolCalls: 2 + maxToolCalls: 15 + +timeout: 60000 + +tags: + - contextscout + - discovery + - subagent +``` + +--- + +## Related Files + +- **Testing subagents**: `.opencode/context/openagents-repo/guides/testing-subagents.md` +- **Subagent invocation**: `.opencode/context/openagents-repo/guides/subagent-invocation.md` +- **Agent concepts**: `.opencode/context/openagents-repo/core-concepts/agents.md` + +--- + +**Last Updated**: 2026-01-09 +**Version**: 1.0.0 diff --git a/.opencode/context/openagents-repo/guides/testing-subagents.md b/.opencode/context/openagents-repo/guides/testing-subagents.md new file mode 100644 index 0000000..a15fc01 --- /dev/null +++ b/.opencode/context/openagents-repo/guides/testing-subagents.md @@ -0,0 +1,282 @@ +# Testing Subagents - Step-by-Step Guide + +**Purpose**: How to test subagents in standalone mode + +**Last Updated**: 2026-01-09 + +--- + +## ⚠️ CRITICAL: Adding New Subagent to Framework + +**Before testing**, you MUST update THREE locations in framework code: + +### 1. `evals/framework/src/sdk/run-sdk-tests.ts` (~line 336) +Add to `subagentParentMap`: +```typescript +'contextscout': 'openagent', // Maps subagent → parent +``` + +### 2. `evals/framework/src/sdk/run-sdk-tests.ts` (~line 414) +Add to `subagentPathMap`: +```typescript +'contextscout': 'ContextScout', // Maps name → path +``` + +### 3. `evals/framework/src/sdk/test-runner.ts` (~line 238) +Add to `agentMap`: +```typescript +'contextscout': 'ContextScout.md', // Maps name → file +``` + +**If missing from ANY map**: Tests will fail with "No test files found" or "Unknown subagent" + +--- + +## Quick Start + +```bash +# Test subagent directly (standalone mode) +cd evals/framework +npm run eval:sdk -- --subagent=contextscout --pattern="01-test.yaml" + +# Test via delegation (integration mode) +npm run eval:sdk -- --subagent=contextscout --delegate --pattern="01-test.yaml" + +# Debug mode +npm run eval:sdk -- --subagent=contextscout --pattern="01-test.yaml" --debug +``` + +--- + +## Step 1: Verify Agent File + +**Check agent exists and has correct structure**: + +```bash +# Check agent file +cat .opencode/agent/ContextScout.md | head -20 + +# Verify frontmatter +grep -A 5 "^id:" .opencode/agent/ContextScout.md +``` + +**Expected**: +```yaml +id: contextscout +name: ContextScout +category: subagents/core +type: subagent +mode: subagent # ← Will be forced to 'primary' in standalone tests +``` + +--- + +## Step 2: Verify Test Configuration + +**Check test config points to correct agent**: + +```bash +cat evals/agents/ContextScout/config/config.yaml +``` + +**Expected**: +```yaml +agent: ContextScout # ← Full path +model: anthropic/claude-sonnet-4-5 +timeout: 60000 +``` + +--- + +## Step 3: Run Standalone Test + +**Use `--subagent` flag** (not `--agent`): + +```bash +cd evals/framework +npm run eval:sdk -- --subagent=ContextScout --pattern="standalone/01-simple-discovery.yaml" +``` + +**What to Look For**: +``` +⚡ Standalone Test Mode + Subagent: contextscout + Mode: Forced to 'primary' for direct testing + +Testing agent: contextscout # ← Should show subagent name +``` + +--- + +## Step 4: Verify Agent Loaded Correctly + +**Check test results**: + +```bash +# View latest results +cat evals/results/latest.json | jq '.meta' +``` + +**Expected**: +```json +{ + "agent": "ContextScout", // ← Correct agent + "model": "opencode/grok-code-fast", + "timestamp": "2026-01-07T..." +} +``` + +**Red Flags**: +- `"agent": "core/openagent"` ← Wrong! OpenAgent is running instead +- `"agent": "contextscout"` ← Missing category prefix + +--- + +## Step 5: Check Tool Usage + +**Verify subagent used tools**: + +```bash +# Check tool calls in output +cat evals/results/latest.json | jq '.tests[0]' | grep -A 5 "Tool Calls" +``` + +**Expected** (for ContextScout): +``` +Tool Calls: 1 +Tools Used: glob + +Tool Call Details: + 1. glob: {"pattern":"*.md","path":".opencode/context/core"} +``` + +**Red Flags**: +- `Tool Calls: 0` ← Agent didn't use any tools +- `Tools Used: task` ← Parent agent delegating (wrong mode) + +--- + +## Step 6: Analyze Failures + +**If test fails, check violations**: + +```bash +cat evals/results/latest.json | jq '.tests[0].violations' +``` + +**Common Issues**: + +### Issue 1: No Tool Calls +```json +{ + "type": "missing-required-tool", + "message": "Required tool 'glob' was not used" +} +``` + +**Cause**: Agent prompt doesn't emphasize tool usage +**Fix**: Add critical rules section emphasizing tools (see `examples/subagent-prompt-structure.md`) + +### Issue 2: Wrong Agent Running +``` +Agent: OpenAgent +``` + +**Cause**: Used `--agent` instead of `--subagent` +**Fix**: Use `--subagent=ContextScout` + +### Issue 3: Tool Permission Denied +```json +{ + "type": "missing-approval", + "message": "Execution tool 'bash' called without requesting approval" +} +``` + +**Cause**: Agent tried to use restricted tool +**Fix**: See `errors/tool-permission-errors.md` + +--- + +## Step 7: Validate Results + +**Check test passed**: + +```bash +# View summary +cat evals/results/latest.json | jq '.summary' +``` + +**Expected**: +```json +{ + "total": 1, + "passed": 1, // ← Should be 1 + "failed": 0, + "pass_rate": 1.0 +} +``` + +--- + +## Test File Organization + +**Best Practice**: Organize by mode + +``` +evals/agents/ContextScout/tests/ +├── standalone/ # Unit tests (--subagent flag) +│ ├── 01-simple-discovery.yaml +│ ├── 02-search-test.yaml +│ └── 03-extraction-test.yaml +└── delegation/ # Integration tests (--agent flag) + ├── 01-openagent-delegates.yaml + └── 02-context-loading.yaml +``` + +--- + +## Writing Good Test Prompts + +**Be explicit about tool usage**: + +❌ **Vague** (may not work): +```yaml +prompts: + - text: | + List all markdown files in .opencode/context/core/ +``` + +✅ **Explicit** (works): +```yaml +prompts: + - text: | + Use the glob tool to find all markdown files in .opencode/context/core/ + + You MUST use the glob tool like this: + glob(pattern="*.md", path=".opencode/context/core") + + Then list the files you found. +``` + +--- + +## Quick Troubleshooting + +| Symptom | Cause | Fix | +|---------|-------|-----| +| OpenAgent runs instead | Used `--agent` flag | Use `--subagent` flag | +| Tool calls: 0 | Prompt doesn't emphasize tools | Add critical rules section | +| Permission denied | Tool restricted in frontmatter | Check `tools:` and `permissions:` | +| Test timeout | Agent stuck/looping | Check prompt logic, add timeout | + +--- + +## Related + +- `concepts/subagent-testing-modes.md` - Understand standalone vs delegation +- `lookup/subagent-test-commands.md` - Quick command reference +- `errors/tool-permission-errors.md` - Common permission issues +- `examples/subagent-prompt-structure.md` - Optimized prompt structure + +**Reference**: `evals/framework/src/sdk/run-sdk-tests.ts` diff --git a/.opencode/context/openagents-repo/guides/updating-registry.md b/.opencode/context/openagents-repo/guides/updating-registry.md new file mode 100644 index 0000000..9864eca --- /dev/null +++ b/.opencode/context/openagents-repo/guides/updating-registry.md @@ -0,0 +1,481 @@ +# Guide: Updating Registry + +**Prerequisites**: Load `core-concepts/registry.md` first +**Purpose**: How to update the component registry + +--- + +## Quick Commands + +```bash +# Auto-detect and add new components +./scripts/registry/auto-detect-components.sh --auto-add + +# Validate registry +./scripts/registry/validate-registry.sh + +# Dry run (see what would change) +./scripts/registry/auto-detect-components.sh --dry-run +``` + +--- + +## When to Update Registry + +Update the registry when you: +- ✅ Add a new agent +- ✅ Add a new command +- ✅ Add a new tool +- ✅ Add a new context file +- ✅ Change component metadata +- ✅ Move or rename components + +--- + +## Auto-Detect (Recommended) + +### Step 1: Dry Run + +```bash +# See what would be added/updated +./scripts/registry/auto-detect-components.sh --dry-run +``` + +**Output**: +``` +Scanning .opencode/ for components... + +Would add: + - agent: development/api-specialist + - context: development/api-patterns.md + +Would update: + - agent: core/openagent (description changed) +``` + +### Step 2: Apply Changes + +```bash +# Actually update registry +./scripts/registry/auto-detect-components.sh --auto-add +``` + +### Step 3: Validate + +```bash +# Validate registry +./scripts/registry/validate-registry.sh +``` + +--- + +## Frontmatter Metadata (Auto-Extracted) + +The auto-detect script automatically extracts `tags` and `dependencies` from component frontmatter. This is the **recommended way** to add metadata. + +### Supported Formats + +**Multi-line arrays** (recommended for readability): +```yaml +--- +description: Your component description +tags: + - tag1 + - tag2 + - tag3 +dependencies: + - subagent:coder-agent + - context:core/standards/code + - command:context +--- +``` + +**Inline arrays** (compact format): +```yaml +--- +description: Your component description +tags: [tag1, tag2, tag3] +dependencies: [subagent:coder-agent, context:core/standards/code] +--- +``` + +### Component-Specific Examples + +**Command** (`.opencode/command/your-command.md`): +```yaml +--- +description: Brief description of what this command does +tags: + - category + - feature + - use-case +dependencies: + - subagent:context-organizer + - subagent:contextscout +--- +``` + +**Subagent** (`.opencode/agent/subagents/category/your-agent.md`): +```yaml +--- +id: your-agent +name: Your Agent Name +description: What this agent does +category: specialist +type: specialist +tags: + - domain + - capability +dependencies: + - subagent:coder-agent + - context:core/standards/code +--- +``` + +**Context** (`.opencode/context/category/your-context.md`): +```yaml +--- +description: What knowledge this context provides +tags: + - domain + - topic +dependencies: + - context:core/standards/code +--- +``` + +### Dependency Format + +Dependencies use the format: `type:id` + +**Valid types**: +- `subagent:` - References a subagent (e.g., `subagent:coder-agent`) +- `command:` - References a command (e.g., `command:context`) +- `context:` - References a context file (e.g., `context:core/standards/code`) +- `agent:` - References a main agent (e.g., `agent:openagent`) + +**Examples**: +```yaml +dependencies: + - subagent:coder-agent # Depends on coder-agent subagent + - context:core/standards/code # Requires code standards context + - command:context # Uses context command +``` + +### How It Works + +1. **Create component** with frontmatter (tags + dependencies) +2. **Run auto-detect**: `./scripts/registry/auto-detect-components.sh --dry-run` +3. **Verify extraction**: Check that tags/dependencies appear in output +4. **Apply changes**: `./scripts/registry/auto-detect-components.sh --auto-add` +5. **Validate**: `./scripts/registry/validate-registry.sh` + +The script automatically: +- ✅ Extracts `description`, `tags`, `dependencies` from frontmatter +- ✅ Handles both inline and multi-line array formats +- ✅ Converts to proper JSON arrays in registry +- ✅ Validates dependency references exist + +--- + +## Manual Updates (Not Recommended) + +Only edit `registry.json` manually if auto-detect doesn't work. + +**Prefer frontmatter**: Add tags/dependencies to component frontmatter instead of editing registry directly. + +### Adding Component Manually + +```json +{ + "id": "agent-name", + "name": "Agent Name", + "type": "agent", + "path": ".opencode/agent/category/agent-name.md", + "description": "Brief description", + "category": "category", + "tags": ["tag1", "tag2"], + "dependencies": [], + "version": "0.5.0" +} +``` + +### Validate After Manual Edit + +```bash +./scripts/registry/validate-registry.sh +``` + +--- + +## Validation + +### What Gets Validated + +✅ **Schema** - Correct JSON structure +✅ **Paths** - All paths exist +✅ **IDs** - Unique IDs +✅ **Categories** - Valid categories +✅ **Dependencies** - Dependencies exist + +### Validation Errors + +```bash +# Example errors +ERROR: Path does not exist: .opencode/agent/core/missing.md +ERROR: Duplicate ID: frontend-specialist +ERROR: Invalid category: invalid-category +ERROR: Missing dependency: subagent:nonexistent +``` + +### Fixing Errors + +1. **Path not found**: Fix path or remove entry +2. **Duplicate ID**: Rename one component +3. **Invalid category**: Use valid category +4. **Missing dependency**: Add dependency or remove reference + +--- + +## Testing Registry Changes + +### Test Locally + +```bash +# Test with local registry +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --list + +# Try installing a component +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --component agent:your-agent +``` + +### Verify Component Appears + +```bash +# List all agents +cat registry.json | jq '.components.agents[].id' + +# Check specific component +cat registry.json | jq '.components.agents[] | select(.id == "your-agent")' +``` + +--- + +## Common Tasks + +### Add New Component to Registry + +```bash +# 1. Create component file with frontmatter (including tags/dependencies) +# 2. Run auto-detect +./scripts/registry/auto-detect-components.sh --auto-add + +# 3. Validate +./scripts/registry/validate-registry.sh +``` + +**Example**: Adding a new command with tags/dependencies: + +```bash +# 1. Create .opencode/command/my-command.md with frontmatter: +cat > .opencode/command/my-command.md << 'EOF' +--- +description: My custom command description +tags: [automation, workflow] +dependencies: [subagent:coder-agent] +--- + +# My Command +... +EOF + +# 2. Auto-detect extracts metadata +./scripts/registry/auto-detect-components.sh --dry-run + +# 3. Apply changes +./scripts/registry/auto-detect-components.sh --auto-add + +# 4. Validate +./scripts/registry/validate-registry.sh +``` + +### Update Component Metadata + +```bash +# 1. Update frontmatter in component file (tags, dependencies, description) +# 2. Run auto-detect +./scripts/registry/auto-detect-components.sh --auto-add + +# 3. Validate +./scripts/registry/validate-registry.sh +``` + +**Example**: Adding tags to existing component: + +```bash +# 1. Edit .opencode/command/existing-command.md frontmatter: +# Add or update: +# tags: [new-tag, another-tag] +# dependencies: [subagent:new-dependency] + +# 2. Auto-detect picks up changes +./scripts/registry/auto-detect-components.sh --dry-run + +# 3. Apply +./scripts/registry/auto-detect-components.sh --auto-add +``` + +### Remove Component + +```bash +# 1. Delete component file +# 2. Run auto-detect (will remove from registry) +./scripts/registry/auto-detect-components.sh --auto-add + +# 3. Validate +./scripts/registry/validate-registry.sh +``` + +--- + +## CI/CD Integration + +### Automatic Validation + +Registry is validated on: +- Pull requests (`.github/workflows/validate-registry.yml`) +- Merges to main +- Release tags + +### Auto-Update on Merge + +Registry can be auto-updated after merge: +```yaml +# .github/workflows/update-registry.yml +- name: Update Registry + run: ./scripts/registry/auto-detect-components.sh --auto-add +``` + +--- + +## Best Practices + +✅ **Use frontmatter** - Add tags/dependencies to component files, not registry +✅ **Use auto-detect** - Don't manually edit registry +✅ **Validate often** - Catch issues early +✅ **Test locally** - Use local registry for testing +✅ **Dry run first** - See changes before applying +✅ **Version consistency** - Keep versions in sync +✅ **Multi-line arrays** - More readable than inline format +✅ **Meaningful tags** - Use descriptive, searchable tags +✅ **Declare dependencies** - Helps with component discovery and validation + +--- + +## Related Files + +- **Registry concepts**: `core-concepts/registry.md` +- **Adding agents**: `guides/adding-agent.md` +- **Debugging**: `guides/debugging.md` + +--- + +## Troubleshooting + +### Tags/Dependencies Not Extracted + +**Problem**: Auto-detect doesn't extract tags or dependencies from frontmatter. + +**Solutions**: +1. **Check frontmatter format**: + - Must be at top of file + - Must start/end with `---` + - Must use valid YAML syntax + +2. **Verify array format**: + ```yaml + # ✅ Valid formats + tags: [tag1, tag2] + tags: + - tag1 + - tag2 + + # ❌ Invalid + tags: tag1, tag2 # Missing brackets + ``` + +3. **Check dependency format**: + ```yaml + # ✅ Valid + dependencies: [subagent:coder-agent, context:core/standards/code] + + # ❌ Invalid + dependencies: [coder-agent] # Missing type prefix + ``` + +4. **Run dry-run to debug**: + ```bash + ./scripts/registry/auto-detect-components.sh --dry-run + # Check output shows extracted tags/dependencies + ``` + +### Dependency Validation Errors + +**Problem**: Validation fails with "Missing dependency" error. + +**Solution**: Ensure referenced component exists in registry: +```bash +# Check if dependency exists +jq '.components.subagents[] | select(.id == "coder-agent")' registry.json + +# If missing, add the dependency component first +``` + +### Context Not Found (Aliases) + +**Problem**: Error `Could not find path for context:old-name` even though file exists. + +**Cause**: The context file might have been renamed or the ID in registry doesn't match the requested name. + +**Solution**: Add an alias to the component in `registry.json`. + +1. Find the component in `registry.json` +2. Add `"aliases": ["old-name", "alternative-name"]` +3. Validate registry + +--- + +## Managing Aliases + +Aliases allow components to be referenced by multiple names. This is useful for: +- Backward compatibility (renamed files) +- Shorthand references +- Alternative naming conventions + +### Adding Aliases + +Currently, aliases must be added **manually** to `registry.json` (auto-detect does not yet support them). + +```json +{ + "id": "session-management", + "name": "Session Management", + "type": "context", + "path": ".opencode/context/core/workflows/session-management.md", + "aliases": [ + "workflows-sessions", + "sessions" + ], + ... +} +``` + +**Note**: Always validate the registry after manual edits: +```bash +./scripts/registry/validate-registry.sh +``` + +--- + +**Last Updated**: 2025-01-06 +**Version**: 2.0.0 diff --git a/.opencode/context/openagents-repo/lookup/commands.md b/.opencode/context/openagents-repo/lookup/commands.md new file mode 100644 index 0000000..79b883e --- /dev/null +++ b/.opencode/context/openagents-repo/lookup/commands.md @@ -0,0 +1,400 @@ +# Lookup: Command Reference + +**Purpose**: Quick reference for common commands + +--- + +## Registry Commands + +### Validate Registry + +```bash +# Basic validation +./scripts/registry/validate-registry.sh + +# Verbose output +./scripts/registry/validate-registry.sh -v +``` + +### Auto-Detect Components + +```bash +# Dry run (see what would change) +./scripts/registry/auto-detect-components.sh --dry-run + +# Add new components +./scripts/registry/auto-detect-components.sh --auto-add + +# Force update existing +./scripts/registry/auto-detect-components.sh --auto-add --force +``` + +### Validate Component Structure + +```bash +./scripts/registry/validate-component.sh +``` + +--- + +## Testing Commands + +### Run Tests + +```bash +# Single test +cd evals/framework +npm run eval:sdk -- --agent={category}/{agent} --pattern="{test}.yaml" + +# All tests for agent +npm run eval:sdk -- --agent={category}/{agent} + +# All tests (all agents) +npm run eval:sdk + +# With debug +npm run eval:sdk -- --agent={agent} --debug +``` + +### Validate Test Suites + +```bash +./scripts/validation/validate-test-suites.sh +``` + +--- + +## Installation Commands + +### Install Components + +```bash +# List available components +./install.sh --list + +# Install profile +./install.sh {profile} +# Profiles: essential, developer, business + +# Install specific component +./install.sh --component agent:{agent-name} + +# Test with local registry +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --list +``` + +### Collision Handling + +```bash +# Skip existing files +./install.sh developer --skip-existing + +# Overwrite all +./install.sh developer --force + +# Backup existing +./install.sh developer --backup +``` + +--- + +## Version Commands + +### Check Version + +```bash +# Check all version files +cat VERSION +cat package.json | jq '.version' +cat registry.json | jq '.version' +``` + +### Update Version + +```bash +# Update VERSION +echo "0.X.Y" > VERSION + +# Update package.json +jq '.version = "0.X.Y"' package.json > tmp && mv tmp package.json + +# Update registry.json +jq '.version = "0.X.Y"' registry.json > tmp && mv tmp registry.json +``` + +### Bump Version Script + +```bash +./scripts/versioning/bump-version.sh 0.X.Y +``` + +--- + +## Git Commands + +### Create Release + +```bash +# Commit version changes +git add VERSION package.json CHANGELOG.md +git commit -m "chore: bump version to 0.X.Y" + +# Create tag +git tag -a v0.X.Y -m "Release v0.X.Y" + +# Push +git push origin main +git push origin v0.X.Y +``` + +### Create GitHub Release + +```bash +# Via GitHub CLI +gh release create v0.X.Y \ + --title "v0.X.Y" \ + --notes "See CHANGELOG.md for details" +``` + +--- + +## Validation Commands + +### Full Validation + +```bash +# Validate everything +./scripts/registry/validate-registry.sh && \ +./scripts/validation/validate-test-suites.sh && \ +cd evals/framework && npm run eval:sdk +``` + +### Check Context Dependencies + +```bash +# Analyze all agents +/check-context-deps + +# Analyze specific agent +/check-context-deps contextscout + +# Auto-fix missing dependencies +/check-context-deps --fix +``` + +### Validate Context References + +```bash +./scripts/validation/validate-context-refs.sh +``` + +### Setup Pre-Commit Hook + +```bash +./scripts/validation/setup-pre-commit-hook.sh +``` + +--- + +## Development Commands + +### Run Demo + +```bash +./scripts/development/demo.sh +``` + +### Run Dashboard + +```bash +./scripts/development/dashboard.sh +``` + +--- + +## Maintenance Commands + +### Cleanup Stale Sessions + +```bash +./scripts/maintenance/cleanup-stale-sessions.sh +``` + +### Uninstall + +```bash +./scripts/maintenance/uninstall.sh +``` + +--- + +## Debugging Commands + +### Check Sessions + +```bash +# List recent sessions +ls -lt .tmp/sessions/ | head -5 + +# View session +cat .tmp/sessions/{session-id}/session.json | jq + +# View events +cat .tmp/sessions/{session-id}/events.json | jq +``` + +### Check Context Logs + +```bash +# Check session cache +./scripts/check-context-logs/check-session-cache.sh + +# Count agent tokens +./scripts/check-context-logs/count-agent-tokens.sh + +# Show API payload +./scripts/check-context-logs/show-api-payload.sh + +# Show cached data +./scripts/check-context-logs/show-cached-data.sh +``` + +--- + +## Quick Workflows + +### Adding a New Agent + +```bash +# 1. Create agent file +touch .opencode/agent/{category}/{agent-name}.md +# (Add frontmatter and content) + +# 2. Create test structure +mkdir -p evals/agents/{category}/{agent-name}/{config,tests} +# (Create config.yaml and smoke-test.yaml) + +# 3. Update registry +./scripts/registry/auto-detect-components.sh --auto-add + +# 4. Validate +./scripts/registry/validate-registry.sh +cd evals/framework && npm run eval:sdk -- --agent={category}/{agent-name} +``` + +### Testing an Agent + +```bash +# 1. Run smoke test +cd evals/framework +npm run eval:sdk -- --agent={category}/{agent} --pattern="smoke-test.yaml" + +# 2. If fails, debug +npm run eval:sdk -- --agent={category}/{agent} --debug + +# 3. Check session +ls -lt .tmp/sessions/ | head -1 +cat .tmp/sessions/{session-id}/session.json | jq +``` + +### Creating a Release + +```bash +# 1. Update version +echo "0.X.Y" > VERSION +jq '.version = "0.X.Y"' package.json > tmp && mv tmp package.json + +# 2. Update CHANGELOG +# (Edit CHANGELOG.md) + +# 3. Commit and tag +git add VERSION package.json CHANGELOG.md +git commit -m "chore: bump version to 0.X.Y" +git tag -a v0.X.Y -m "Release v0.X.Y" + +# 4. Push +git push origin main +git push origin v0.X.Y + +# 5. Create GitHub release +gh release create v0.X.Y --title "v0.X.Y" --notes "See CHANGELOG.md" +``` + +--- + +## Common Patterns + +### Find Files + +```bash +# Find agent +find .opencode/agent -name "{agent-name}.md" + +# Find tests +find evals/agents -name "*.yaml" + +# Find context +find .opencode/context -name "*.md" + +# Find scripts +find scripts -name "*.sh" +``` + +### Check Registry + +```bash +# List all agents +cat registry.json | jq '.components.agents[].id' + +# Check specific component +cat registry.json | jq '.components.agents[] | select(.id == "{agent-name}")' + +# Count components +cat registry.json | jq '.components.agents | length' +``` + +### Test Locally + +```bash +# Test with local registry +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --list + +# Install locally +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh developer +``` + +--- + +## NPM Commands (Eval Framework) + +```bash +cd evals/framework + +# Install dependencies +npm install + +# Run tests +npm test + +# Run eval SDK +npm run eval:sdk + +# Build +npm run build + +# Lint +npm run lint +``` + +--- + +## Related Files + +- **Quick start**: `quick-start.md` +- **File locations**: `lookup/file-locations.md` +- **Guides**: `guides/` + +--- + +**Last Updated**: 2025-12-10 +**Version**: 0.5.0 diff --git a/.opencode/context/openagents-repo/lookup/file-locations.md b/.opencode/context/openagents-repo/lookup/file-locations.md new file mode 100644 index 0000000..1b31c1f --- /dev/null +++ b/.opencode/context/openagents-repo/lookup/file-locations.md @@ -0,0 +1,314 @@ +# Lookup: File Locations + +**Purpose**: Quick reference for finding files + +--- + +## Directory Tree + +``` +opencode-agents/ +├── .opencode/ +│ ├── agent/ +│ │ ├── core/ # Core system agents +│ │ ├── development/ # Dev specialists +│ │ ├── content/ # Content creators +│ │ ├── data/ # Data analysts +│ │ ├── product/ # Product managers (ready) +│ │ ├── learning/ # Educators (ready) +│ │ └── subagents/ # Delegated specialists +│ │ ├── code/ # Code-related +│ │ ├── core/ # Core workflows +│ │ ├── system-builder/ # System generation +│ │ └── utils/ # Utilities +│ ├── command/ # Slash commands +│ ├── context/ # Shared knowledge +│ │ ├── core/ # Core standards & workflows +│ │ ├── development/ # Dev context +│ │ ├── content-creation/ # Content creation context +│ │ ├── data/ # Data context +│ │ ├── product/ # Product context +│ │ ├── learning/ # Learning context +│ │ └── openagents-repo/ # Repo-specific context +│ ├── prompts/ # Model-specific variants +│ ├── tool/ # Custom tools +│ └── plugin/ # Plugins +├── evals/ +│ ├── framework/ # Eval framework (TypeScript) +│ │ ├── src/ # Source code +│ │ ├── scripts/ # Test utilities +│ │ └── docs/ # Framework docs +│ └── agents/ # Agent test suites +│ ├── core/ # Core agent tests +│ ├── development/ # Dev agent tests +│ └── content/ # Content agent tests +├── scripts/ +│ ├── registry/ # Registry management +│ ├── validation/ # Validation tools +│ ├── testing/ # Test utilities +│ ├── versioning/ # Version management +│ ├── docs/ # Doc tools +│ └── maintenance/ # Maintenance +├── docs/ # Documentation +│ ├── agents/ # Agent docs +│ ├── contributing/ # Contribution guides +│ ├── features/ # Feature docs +│ └── getting-started/ # User guides +├── registry.json # Component catalog +├── install.sh # Installer +├── VERSION # Current version +└── package.json # Node dependencies +``` + +--- + +## Where Is...? + +| Component | Location | +|-----------|----------| +| **Core agents** | `.opencode/agent/core/` | +| **Category agents** | `.opencode/agent/{category}/` | +| **Subagents** | `.opencode/agent/subagents/` | +| **Commands** | `.opencode/command/` | +| **Context files** | `.opencode/context/` | +| **Prompt variants** | `.opencode/prompts/{category}/{agent}/` | +| **Tools** | `.opencode/tool/` | +| **Plugins** | `.opencode/plugin/` | +| **Agent tests** | `evals/agents/{category}/{agent}/` | +| **Eval framework** | `evals/framework/src/` | +| **Registry scripts** | `scripts/registry/` | +| **Validation scripts** | `scripts/validation/` | +| **Documentation** | `docs/` | +| **Registry** | `registry.json` | +| **Installer** | `install.sh` | +| **Version** | `VERSION` | + +--- + +## Where Do I Add...? + +| What | Where | +|------|-------| +| **New core agent** | `.opencode/agent/core/{name}.md` | +| **New category agent** | `.opencode/agent/{category}/{name}.md` | +| **New subagent** | `.opencode/agent/subagents/{category}/{name}.md` | +| **New command** | `.opencode/command/{name}.md` | +| **New context** | `.opencode/context/{category}/{name}.md` | +| **Agent tests** | `evals/agents/{category}/{agent}/tests/` | +| **Test config** | `evals/agents/{category}/{agent}/config/config.yaml` | +| **Documentation** | `docs/{section}/{topic}.md` | +| **Script** | `scripts/{purpose}/{name}.sh` | + +--- + +## Specific File Paths + +### Core Files + +``` +registry.json # Component catalog +install.sh # Main installer +update.sh # Update script +VERSION # Current version (0.5.0) +package.json # Node dependencies +CHANGELOG.md # Release notes +README.md # Main documentation +``` + +### Core Agents + +``` +.opencode/agent/core/openagent.md +.opencode/agent/core/opencoder.md +.opencode/agent/meta/system-builder.md +``` + +### Development Agents + +``` +.opencode/agent/development/frontend-specialist.md +.opencode/agent/development/devops-specialist.md +``` +.opencode/agent/development/frontend-specialist.md +.opencode/agent/development/devops-specialist.md +``` + +### Content Agents + +``` +.opencode/agent/content/copywriter.md +.opencode/agent/content/technical-writer.md +``` + +### Key Subagents + +``` +.opencode/agent/TestEngineer.md +.opencode/agent/CodeReviewer.md +.opencode/agent/CoderAgent.md +.opencode/agent/TaskManager.md +.opencode/agent/DocWriter.md +``` + +### Core Context + +``` +.opencode/context/core/standards/code-quality.md +.opencode/context/core/standards/documentation.md +.opencode/context/core/standards/test-coverage.md +.opencode/context/core/standards/security-patterns.md +.opencode/context/core/workflows/task-delegation-basics.md +.opencode/context/core/workflows/code-review.md +``` + +### Registry Scripts + +``` +scripts/registry/validate-registry.sh +scripts/registry/auto-detect-components.sh +scripts/registry/register-component.sh +scripts/registry/validate-component.sh +``` + +### Validation Scripts + +``` +scripts/validation/validate-context-refs.sh +scripts/validation/validate-test-suites.sh +scripts/validation/setup-pre-commit-hook.sh +``` + +### Eval Framework + +``` +evals/framework/src/sdk/ # Test runner +evals/framework/src/evaluators/ # Rule evaluators +evals/framework/src/collector/ # Session collection +evals/framework/src/types/ # TypeScript types +``` + +--- + +## Path Patterns + +### Agents + +``` +.opencode/agent/{category}/{agent-name}.md +``` + +**Examples**: +- `.opencode/agent/core/openagent.md` +- `.opencode/agent/development/frontend-specialist.md` +- `.opencode/agent/TestEngineer.md` + +### Context + +``` +.opencode/context/{category}/{topic}.md +``` + +**Examples**: +- `.opencode/context/core/standards/code-quality.md` +- `.opencode/context/development/frontend/react/react-patterns.md` +- `.opencode/context/content-creation/principles/copywriting-frameworks.md` + +### Tests + +``` +evals/agents/{category}/{agent-name}/ +├── config/config.yaml +└── tests/{test-name}.yaml +``` + +**Examples**: +- `evals/agents/core/openagent/tests/smoke-test.yaml` +- `evals/agents/development/frontend-specialist/tests/approval-gate.yaml` + +### Scripts + +``` +scripts/{purpose}/{action}-{target}.sh +``` + +**Examples**: +- `scripts/registry/validate-registry.sh` +- `scripts/validation/validate-test-suites.sh` +- `scripts/versioning/bump-version.sh` + +--- + +## Naming Conventions + +### Files + +- **Agents**: `{name}.md` or `{domain}-specialist.md` +- **Context**: `{topic}.md` +- **Tests**: `{test-name}.yaml` +- **Scripts**: `{action}-{target}.sh` +- **Docs**: `{topic}.md` + +### Directories + +- **Categories**: lowercase, singular (e.g., `development`, `content`) +- **Purposes**: lowercase, descriptive (e.g., `registry`, `validation`) + +--- + +## Quick Lookups + +### Find Agent File + +```bash +# By name +find .opencode/agent -name "{agent-name}.md" + +# By category +ls .opencode/agent/{category}/ + +# All agents +find .opencode/agent -name "*.md" -not -path "*/subagents/*" +``` + +### Find Test File + +```bash +# By agent +ls evals/agents/{category}/{agent}/tests/ + +# All tests +find evals/agents -name "*.yaml" +``` + +### Find Context File + +```bash +# By category +ls .opencode/context/{category}/ + +# All context +find .opencode/context -name "*.md" +``` + +### Find Script + +```bash +# By purpose +ls scripts/{purpose}/ + +# All scripts +find scripts -name "*.sh" +``` + +--- + +## Related Files + +- **Quick start**: `quick-start.md` +- **Categories**: `core-concepts/categories.md` +- **Commands**: `lookup/commands.md` + +--- + +**Last Updated**: 2025-12-10 +**Version**: 0.5.0 diff --git a/.opencode/context/openagents-repo/lookup/navigation.md b/.opencode/context/openagents-repo/lookup/navigation.md new file mode 100644 index 0000000..9696a94 --- /dev/null +++ b/.opencode/context/openagents-repo/lookup/navigation.md @@ -0,0 +1,38 @@ +# OpenAgents Lookup + +**Purpose**: Quick reference and lookup tables for OpenAgents Control + +--- + +## Structure + +``` +openagents-repo/lookup/ +├── navigation.md (this file) +└── [lookup reference files] +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **View lookups** | `./` | +| **Guides** | `../guides/navigation.md` | +| **Core Concepts** | `../core-concepts/navigation.md` | + +--- + +## By Type + +**Quick Reference** → Fast lookup tables and commands +**Checklists** → Verification and validation checklists + +--- + +## Related Context + +- **OpenAgents Navigation** → `../navigation.md` +- **Guides** → `../guides/navigation.md` +- **Core Concepts** → `../core-concepts/navigation.md` diff --git a/.opencode/context/openagents-repo/lookup/subagent-framework-maps.md b/.opencode/context/openagents-repo/lookup/subagent-framework-maps.md new file mode 100644 index 0000000..fd228bb --- /dev/null +++ b/.opencode/context/openagents-repo/lookup/subagent-framework-maps.md @@ -0,0 +1,76 @@ +# Lookup: Subagent Framework Maps + +**Purpose**: Quick reference for adding subagents to eval framework +**Last Updated**: 2026-01-09 + +--- + +## Critical: THREE Maps Must Be Updated + +When adding a new subagent, update these THREE locations: + +### 1. Parent Map (run-sdk-tests.ts ~line 336) +**Purpose**: Maps subagent → parent agent for delegation testing + +```typescript +const subagentParentMap: Record = { + 'contextscout': 'openagent', // Core subagents → openagent + 'task-manager': 'openagent', + 'documentation': 'openagent', + + 'coder-agent': 'opencoder', // Code subagents → opencoder + 'tester': 'opencoder', + 'reviewer': 'opencoder', +}; +``` + +### 2. Path Map (run-sdk-tests.ts ~line 414) +**Purpose**: Maps subagent name → file path for test discovery + +```typescript +const subagentPathMap: Record = { + 'contextscout': 'ContextScout', + 'task-manager': 'TaskManager', + 'coder-agent': 'CoderAgent', +}; +``` + +### 3. Agent Map (test-runner.ts ~line 238) +**Purpose**: Maps subagent name → agent file for eval-runner + +```typescript +const agentMap: Record = { + 'contextscout': 'ContextScout.md', + 'task-manager': 'TaskManager.md', + 'coder-agent': 'CoderAgent.md', +}; +``` + +--- + +## Error Messages + +| Error | Missing From | Fix | +|-------|--------------|-----| +| "No test files found" | Path Map (#2) | Add to `subagentPathMap` | +| "Unknown subagent" | Parent Map (#1) | Add to `subagentParentMap` | +| "Agent file not found" | Agent Map (#3) | Add to `agentMap` | + +--- + +## Testing Commands + +```bash +# Standalone mode (forces mode: primary) +npm run eval:sdk -- --subagent=contextscout + +# Delegation mode (tests via parent) +npm run eval:sdk -- --subagent=contextscout --delegate +``` + +--- + +## Related + +- `guides/testing-subagents.md` - Full testing guide +- `guides/adding-agent.md` - Creating new agents diff --git a/.opencode/context/openagents-repo/lookup/subagent-test-commands.md b/.opencode/context/openagents-repo/lookup/subagent-test-commands.md new file mode 100644 index 0000000..1fbbbe0 --- /dev/null +++ b/.opencode/context/openagents-repo/lookup/subagent-test-commands.md @@ -0,0 +1,192 @@ +# Subagent Testing Commands - Quick Reference + +**Purpose**: Quick command reference for testing subagents + +**Last Updated**: 2026-01-07 + +--- + +## Standalone Mode (Unit Testing) + +### Run All Standalone Tests +```bash +cd evals/framework +npm run eval:sdk -- --subagent=ContextScout --pattern="standalone/*.yaml" +``` + +### Run Single Test +```bash +npm run eval:sdk -- --subagent=ContextScout --pattern="standalone/01-simple-discovery.yaml" +``` + +### Debug Mode +```bash +npm run eval:sdk -- --subagent=ContextScout --pattern="standalone/*.yaml" --debug +``` + +--- + +## Delegation Mode (Integration Testing) + +### Run Delegation Tests +```bash +npm run eval:sdk -- --agent=core/openagent --pattern="delegation/*.yaml" +``` + +### Test Specific Delegation +```bash +npm run eval:sdk -- --agent=core/openagent --pattern="delegation/01-contextscout-delegation.yaml" +``` + +--- + +## Verification Commands + +### Check Agent File +```bash +# View agent frontmatter +head -30 .opencode/agent/ContextScout.md + +# Check tool permissions +grep -A 10 "^tools:" .opencode/agent/ContextScout.md +``` + +### Check Test Config +```bash +cat evals/agents/ContextScout/config/config.yaml +``` + +### View Latest Results +```bash +# Summary +cat evals/results/latest.json | jq '.summary' + +# Agent loaded +cat evals/results/latest.json | jq '.meta.agent' + +# Tool calls +cat evals/results/latest.json | jq '.tests[0]' | grep -A 5 "Tool" + +# Violations +cat evals/results/latest.json | jq '.tests[0].violations' +``` + +--- + +## Common Test Patterns + +### Smoke Test +```bash +npm run eval:sdk -- --subagent=ContextScout --pattern="smoke-test.yaml" +``` + +### Specific Test Suite +```bash +npm run eval:sdk -- --subagent=ContextScout --pattern="discovery/*.yaml" +``` + +### All Tests for Subagent +```bash +npm run eval:sdk -- --subagent=ContextScout +``` + +--- + +## Flag Reference + +| Flag | Purpose | Example | +|------|---------|---------| +| `--subagent` | Test subagent in standalone mode | `--subagent=ContextScout` | +| `--agent` | Test primary agent (or delegation) | `--agent=core/openagent` | +| `--pattern` | Filter test files | `--pattern="standalone/*.yaml"` | +| `--debug` | Show detailed output | `--debug` | +| `--timeout` | Override timeout | `--timeout=120000` | + +--- + +## Troubleshooting Commands + +### Check Which Agent Ran +```bash +# Should show subagent name for standalone mode +cat evals/results/latest.json | jq '.meta.agent' +``` + +### Check Tool Usage +```bash +# Should show tool calls > 0 +cat evals/results/latest.json | jq '.tests[0]' | grep "Tool Calls" +``` + +### View Test Timeline +```bash +# See full conversation +cat evals/results/history/2026-01/07-*.json | jq '.tests[0].timeline' +``` + +### Check for Errors +```bash +# View violations +cat evals/results/latest.json | jq '.tests[0].violations.details' +``` + +--- + +## File Locations + +### Agent Files +``` +.opencode/agent/subagents/core/{subagent}.md +``` + +### Test Files +``` +evals/agents/subagents/core/{subagent}/ +├── config/config.yaml +└── tests/ + ├── standalone/ + │ ├── 01-simple-discovery.yaml + │ └── 02-advanced-test.yaml + └── delegation/ + └── 01-delegation-test.yaml +``` + +### Results +``` +evals/results/ +├── latest.json # Latest test run +└── history/2026-01/ # Historical results + └── 07-HHMMSS-{agent}.json +``` + +--- + +## Quick Checks + +### Is Agent Loaded Correctly? +```bash +# Should show: "agent": "ContextScout" +cat evals/results/latest.json | jq '.meta.agent' +``` + +### Did Agent Use Tools? +```bash +# Should show: Tool Calls: 1 (or more) +cat evals/results/latest.json | jq '.tests[0]' | grep "Tool Calls" +``` + +### Did Test Pass? +```bash +# Should show: "passed": 1, "failed": 0 +cat evals/results/latest.json | jq '.summary' +``` + +--- + +## Related + +- `concepts/subagent-testing-modes.md` - Understand testing modes +- `guides/testing-subagents.md` - Step-by-step testing guide +- `errors/tool-permission-errors.md` - Fix common issues + +**Reference**: `evals/framework/src/sdk/run-sdk-tests.ts` diff --git a/.opencode/context/openagents-repo/navigation.md b/.opencode/context/openagents-repo/navigation.md new file mode 100644 index 0000000..8e2e02c --- /dev/null +++ b/.opencode/context/openagents-repo/navigation.md @@ -0,0 +1,187 @@ +# OpenAgents Control Repository Context + +**Purpose**: Context files specific to the OpenAgents Control repository + +**Last Updated**: 2026-02-04 + +--- + +## Quick Navigation + +| Function | Files | Purpose | +|----------|-------|---------| +| **Standards** | 2 files | Agent creation standards | +| **Concepts** | 6 files | Core ideas and principles | +| **Examples** | 9 files | Working code samples | +| **Guides** | 14 files | Step-by-step workflows | +| **Lookup** | 11 files | Quick reference tables | +| **Errors** | 2 files | Common issues + solutions | + +--- + +## Standards (Agent Creation) + +| File | Topic | Priority | +|------|-------|----------| +| `standards/agent-frontmatter.md` | Valid OpenCode YAML frontmatter | ⭐⭐⭐⭐⭐ | +| `standards/subagent-structure.md` | Standard subagent file structure | ⭐⭐⭐⭐⭐ | + +**When to read**: Before creating or modifying any agent files + +--- + +## Concepts (Core Ideas) + +| File | Topic | Priority | +|------|-------|----------| +| `concepts/compatibility-layer.md` | Adapter pattern for AI coding tools | ⭐⭐⭐⭐⭐ | +| `concepts/subagent-testing-modes.md` | Standalone vs delegation testing | ⭐⭐⭐⭐⭐ | +| `concepts/hooks-system.md` | User-defined lifecycle commands | ⭐⭐⭐⭐ | +| `concepts/agent-skills.md` | Skills that teach Claude tasks | ⭐⭐⭐⭐ | +| `concepts/subagents-system.md` | Specialized AI assistants | ⭐⭐⭐⭐ | + +**When to read**: Before testing any subagent or working with tool adapters + +--- + +## Examples (Working Code) + +| File | Topic | Priority | +|------|-------|----------| +| `examples/baseadapter-pattern.md` | Template Method pattern for tool adapters | ⭐⭐⭐⭐⭐ | +| `examples/zod-schema-migration.md` | Migrating TypeScript to Zod schemas | ⭐⭐⭐⭐ | +| `examples/subagent-prompt-structure.md` | Optimized subagent prompt template | ⭐⭐⭐⭐ | + +**When to read**: When creating adapters, schemas, or optimizing subagent prompts + +--- + +## Guides (Step-by-Step) + +| File | Topic | Priority | +|------|-------|----------| +| `guides/compatibility-layer-workflow.md` | Developing compatibility layer for AI tools | ⭐⭐⭐⭐⭐ | +| `guides/testing-subagents.md` | How to test subagents standalone | ⭐⭐⭐⭐⭐ | +| `guides/adding-agent-basics.md` | How to add new agents (basics) | ⭐⭐⭐⭐ | +| `guides/adding-agent-testing.md` | How to add agent tests | ⭐⭐⭐⭐ | +| `guides/adding-skill-basics.md` | How to add OpenCode skills | ⭐⭐⭐⭐ | +| `guides/creating-skills.md` | How to create Claude Code skills | ⭐⭐⭐⭐ | +| `guides/creating-subagents.md` | How to create Claude Code subagents | ⭐⭐⭐⭐ | +| `guides/testing-agent.md` | How to test agents | ⭐⭐⭐⭐ | +| `guides/external-libraries-workflow.md` | How to handle external library dependencies | ⭐⭐⭐⭐ | +| `guides/github-issues-workflow.md` | How to work with GitHub issues and project board | ⭐⭐⭐⭐ | +| `guides/npm-publishing.md` | How to publish package to npm | ⭐⭐⭐ | +| `guides/updating-registry.md` | How to update registry | ⭐⭐⭐ | +| `guides/debugging.md` | How to debug issues | ⭐⭐⭐ | +| `guides/resolving-installer-wildcard-failures.md` | Fix wildcard context install failures | ⭐⭐⭐ | +| `guides/creating-release.md` | How to create releases | ⭐⭐ | + +**When to read**: When performing specific tasks + +--- + +## Lookup (Quick Reference) + +| File | Topic | Priority | +|------|-------|----------| +| `lookup/tool-feature-parity.md` | AI coding tool feature comparison | ⭐⭐⭐⭐⭐ | +| `lookup/compatibility-layer-structure.md` | Compatibility package file structure | ⭐⭐⭐⭐⭐ | +| `lookup/subagent-test-commands.md` | Subagent testing commands | ⭐⭐⭐⭐⭐ | +| `lookup/hook-events.md` | All hook events reference | ⭐⭐⭐⭐ | +| `lookup/skill-metadata.md` | SKILL.md frontmatter fields | ⭐⭐⭐⭐ | +| `lookup/skills-comparison.md` | Skills vs other options | ⭐⭐⭐⭐ | +| `lookup/builtin-subagents.md` | Default subagents (Explore, Plan) | ⭐⭐⭐⭐ | +| `lookup/subagent-frontmatter.md` | Subagent configuration fields | ⭐⭐⭐⭐ | +| `lookup/file-locations.md` | Where files are located | ⭐⭐⭐⭐ | +| `lookup/commands.md` | Available slash commands | ⭐⭐⭐ | + +**When to read**: Quick command lookups and feature comparisons + +--- + +## Errors (Troubleshooting) + +| File | Topic | Priority | +|------|-------|----------| +| `errors/tool-permission-errors.md` | Tool permission issues | ⭐⭐⭐⭐⭐ | +| `errors/skills-errors.md` | Skills not triggering/loading | ⭐⭐⭐⭐ | + +**When to read**: When tests fail with permission errors + +--- + +## Core Concepts (Foundational) + +| File | Topic | Priority | +|------|-------|----------| +| `core-concepts/agents.md` | How agents work | ⭐⭐⭐⭐⭐ | +| `core-concepts/evals.md` | How testing works | ⭐⭐⭐⭐⭐ | +| `core-concepts/registry.md` | How registry works | ⭐⭐⭐⭐ | +| `core-concepts/categories.md` | How organization works | ⭐⭐⭐ | + +**When to read**: First time working in this repo + +--- + +## Loading Strategy + +### For Subagent Testing: +1. Load `concepts/subagent-testing-modes.md` (understand modes) +2. Load `guides/testing-subagents.md` (step-by-step) +3. Reference `lookup/subagent-test-commands.md` (commands) +4. If errors: Load `errors/tool-permission-errors.md` + +### For Agent Creation: +1. Load `standards/agent-frontmatter.md` (valid YAML frontmatter) +2. Load `standards/subagent-structure.md` (file structure) +3. Load `core-concepts/agents.md` (understand system) +4. Load `guides/adding-agent-basics.md` (step-by-step) +5. **If using external libraries**: Load `guides/external-libraries-workflow.md` (fetch docs) +6. Load `examples/subagent-prompt-structure.md` (if subagent) +7. Load `guides/testing-agent.md` (validate) + +### For Issue Management: +1. Load `guides/github-issues-workflow.md` (understand workflow) +2. Create issues with proper labels and templates +3. Add to project board for tracking +4. Process requests systematically + +### For Debugging: +1. Load `guides/debugging.md` (general approach) +2. Load specific error file from `errors/` +3. Reference `lookup/file-locations.md` (find files) + +--- + +## File Size Compliance + +All files follow MVI principle (<200 lines): + +- ✅ Standards: <200 lines +- ✅ Concepts: <100 lines +- ✅ Examples: <100 lines +- ✅ Guides: <150 lines +- ✅ Lookup: <100 lines +- ✅ Errors: <150 lines + +--- + +## Related Context + +- `../core/` - Core system context (standards, patterns) +- `../core/context-system/` - Context management system +- `quick-start.md` - 2-minute repo orientation +- `../content-creation/navigation.md` - Content creation principles +- `plugins/context/context-overview.md` - Plugin system context + +--- + +## Contributing + +When adding new context files: + +1. Follow MVI principle (<200 lines) +2. Use function-based organization (concepts/, examples/, guides/, lookup/, errors/) +3. Update this README.md navigation +4. Add cross-references to related files +5. Validate with `/context validate` diff --git a/.opencode/context/openagents-repo/plugins/context/architecture/lifecycle.md b/.opencode/context/openagents-repo/plugins/context/architecture/lifecycle.md new file mode 100644 index 0000000..3d07283 --- /dev/null +++ b/.opencode/context/openagents-repo/plugins/context/architecture/lifecycle.md @@ -0,0 +1,38 @@ +# Plugin Lifecycle & Packaging + +## File Structure for Complex Plugins + +For larger plugins, follow this recommended structure: + +``` +my-plugin/ +├── .claude-plugin/ +│ └── plugin.json # Manifest (required for packaging) +├── commands/ # Custom slash commands +├── agents/ # Custom agents +├── hooks/ # Event handlers +└── README.md # Documentation +``` + +## The Manifest (`plugin.json`) + +```json +{ + "name": "my-plugin", + "description": "A custom plugin", + "version": "1.0.0", + "author": { + "name": "Your Name" + } +} +``` + +The `name` becomes the namespace prefix for commands: `/my-plugin:command`. + +## SDK Access + +Plugins have full access to the OpenCode SDK via `context.client`. This allows: +- Sending prompts programmatically: `client.session.prompt()` +- Managing sessions: `client.session.list()`, `client.session.get()` +- Showing UI elements: `client.tui.showToast()` +- Appending to prompt: `client.tui.appendPrompt()` diff --git a/.opencode/context/openagents-repo/plugins/context/architecture/overview.md b/.opencode/context/openagents-repo/plugins/context/architecture/overview.md new file mode 100644 index 0000000..17fa296 --- /dev/null +++ b/.opencode/context/openagents-repo/plugins/context/architecture/overview.md @@ -0,0 +1,58 @@ +# OpenCode Plugins Overview + +OpenCode plugins are JavaScript or TypeScript modules that hook into **25+ events** across the entire OpenCode lifecycle—from when you type a prompt, to when tools execute, to when sessions complete. + +## Key Concepts + +- **Zero-Config**: No build step or compilation required. Just drop `.ts` or `.js` files into the plugin folder. +- **Middleware Pattern**: Plugins subscribe to events and execute logic, similar to Express.js middleware. +- **Access**: Plugins receive a `context` object with: + - `project`: Current project metadata. + - `client`: OpenCode SDK client for programmatic control. + - `$`: Bun's shell API for running commands. + - `directory`: Current working directory. + - `worktree`: Git worktree path. + +## Plugin Registration + +OpenCode looks for plugins in: +1. **Project-level**: `.opencode/plugin/` (project root) +2. **Global**: `~/.config/opencode/plugin/` (home directory) + +## Basic Structure + +```typescript +export const MyPlugin = async (context) => { + const { project, client, $, directory, worktree } = context; + + return { + event: async ({ event }) => { + // Handle events here + } + }; +}; +``` + +Each exported function becomes a separate plugin instance. The name of the export is used as the plugin name. + +## Build and Development + +OpenCode plugins are typically written in TypeScript and bundled into a single JavaScript file for execution. + +### Build Command +Use Bun to bundle the plugin into the `dist` directory: + +```bash +bun build src/index.ts --outdir dist --target bun --format esm +``` + +The output will be a single file (e.g., `./index.js`) containing all dependencies. + +### Development Workflow +1. **Source Code**: Write your plugin in `src/index.ts`. +2. **Bundle**: Run the build command to generate `dist/index.js`. +3. **Load**: Point OpenCode to the bundled file or the directory containing the manifest. +4. **Watch Mode**: For rapid development, use the `--watch` flag with Bun build: + ```bash + bun build src/index.ts --outdir dist --target bun --format esm --watch + ``` diff --git a/.opencode/context/openagents-repo/plugins/context/capabilities/agents.md b/.opencode/context/openagents-repo/plugins/context/capabilities/agents.md new file mode 100644 index 0000000..2ffc401 --- /dev/null +++ b/.opencode/context/openagents-repo/plugins/context/capabilities/agents.md @@ -0,0 +1,44 @@ +# Custom Agents in OpenCode + +Plugins can register custom AI agents that have specific roles, instructions, and toolsets. + +## Agent Definition + +Custom agents are configured in the plugin's `config` function. + +```typescript +export const registerCustomAgents = (config) => { + return { + ...config, + agents: [ + { + name: "my-helper", + description: "A friendly assistant for this project", + instructions: "You are a helpful assistant. Use your tools to help the user.", + model: "claude-3-5-sonnet-latest", // Specify the model + tools: ["say_hello", "read", "write"] // Reference built-in or custom tools + } + ] + }; +}; +``` + +## Integrating into Plugin + +The `config` method in the plugin return object is used to register agents. + +```typescript +export const MyPlugin: Plugin = async (context) => { + return { + config: async (currentConfig) => { + return registerCustomAgents(currentConfig); + }, + // ... other properties + }; +}; +``` + +## Agent Capabilities +- **Model Choice**: You can select specific models for different agents. +- **Scoped Tools**: Limit what tools an agent can use to ensure safety or focus. +- **System Instructions**: Define the "personality" and rules for the agent. diff --git a/.opencode/context/openagents-repo/plugins/context/capabilities/events.md b/.opencode/context/openagents-repo/plugins/context/capabilities/events.md new file mode 100644 index 0000000..49e7fec --- /dev/null +++ b/.opencode/context/openagents-repo/plugins/context/capabilities/events.md @@ -0,0 +1,42 @@ +# OpenCode Plugin Events + +OpenCode fires over 25 events that you can hook into. These are categorized below: + +## Command Events +- `command.executed`: Fired when a user or plugin runs a command. + +## File Events +- `file.edited`: Fired when a file is modified via OpenCode tools. +- `file.watcher.updated`: Fired when the file watcher detects changes. + +## Message Events (Read-Only) +- `message.updated`: Fired when a message in the session updates. +- `message.part.updated`: Fired when individual parts of a message update. +- `message.part.removed`: Fired when a part is removed. +- `message.removed`: Fired when entire message is removed. + +## Session Events +- `session.created`: New session started. +- `session.updated`: Session state changed. +- `session.idle`: Session completed (no more activity expected). +- `session.status`: Session status changed. +- `session.error`: Error occurred in session. +- `session.compacted`: Session was compacted (context summarized). + +## Tool Events (Interception) +- `tool.execute.before`: Fired before a tool runs. **Can block execution** by throwing an error. +- `tool.execute.after`: Fired after a tool completes with result. + +## TUI Events +- `tui.prompt.append`: Text appended to prompt input. +- `tui.command.execute`: Command executed from TUI. +- `tui.toast.show`: Toast notification shown. + +## Mapping from Claude Code Hooks + +| Claude Hook | OpenCode Event | +|---|---| +| PreToolUse | tool.execute.before | +| PostToolUse | tool.execute.after | +| UserPromptSubmit | message.* events | +| SessionEnd | session.idle | diff --git a/.opencode/context/openagents-repo/plugins/context/capabilities/events_skills.md b/.opencode/context/openagents-repo/plugins/context/capabilities/events_skills.md new file mode 100644 index 0000000..f7d7bcb --- /dev/null +++ b/.opencode/context/openagents-repo/plugins/context/capabilities/events_skills.md @@ -0,0 +1,596 @@ +# OpenCode Events: Skills Plugin Implementation + +## Overview + +This document explains how the OpenCode Skills Plugin uses event hooks (`tool.execute.before` and `tool.execute.after`) to implement skill delivery and output enhancement. This is a practical example of the event system described in `events.md`. + +--- + +## Event Hooks Used + +### tool.execute.before + +**Event Type:** Tool Execution Interception + +**When it fires:** Before a tool function executes + +**Purpose in Skills Plugin:** Inject skill content into the conversation + +**Implementation:** +```typescript +const beforeHook = async (input: any, output: any) => { + // Check if this is a skill tool + if (input.tool.startsWith("skills_")) { + // Look up skill from map + const skill = skillMap.get(input.tool) + if (skill) { + // Inject skill content as silent prompt + await ctx.client.session.prompt({ + path: { id: input.sessionID }, + body: { + agent: input.agent, + noReply: true, // Don't trigger AI response + parts: [ + { + type: "text", + text: `📚 Skill: ${skill.name}\nBase directory: ${skill.fullPath}\n\n${skill.content}`, + }, + ], + }, + }) + } + } +} +``` + +**Why use this hook?** +- Runs before tool execution, perfect for context injection +- Can access tool name and session ID +- Can inject content without triggering AI response +- Skill content persists in conversation history + +**Input Parameters:** +- `input.tool` - Tool name (e.g., "skills_brand_guidelines") +- `input.sessionID` - Current session ID +- `input.agent` - Agent name that called the tool +- `output.args` - Tool arguments + +**What you can do:** +- ✅ Inject context (skill content) +- ✅ Validate inputs +- ✅ Preprocess arguments +- ✅ Log tool calls +- ✅ Implement security checks + +**What you can't do:** +- ❌ Modify tool output (tool hasn't run yet) +- ❌ Access tool results + +--- + +### tool.execute.after + +**Event Type:** Tool Execution Interception + +**When it fires:** After a tool function completes + +**Purpose in Skills Plugin:** Enhance output with visual feedback + +**Implementation:** +```typescript +const afterHook = async (input: any, output: any) => { + // Check if this is a skill tool + if (input.tool.startsWith("skills_")) { + // Look up skill from map + const skill = skillMap.get(input.tool) + if (skill && output.output) { + // Add emoji title for visual feedback + output.title = `📚 ${skill.name}` + } + } +} +``` + +**Why use this hook?** +- Runs after tool execution, perfect for output enhancement +- Can modify output properties +- Can add visual feedback (emoji titles) +- Can implement logging/analytics + +**Input Parameters:** +- `input.tool` - Tool name (e.g., "skills_brand_guidelines") +- `input.sessionID` - Current session ID +- `output.output` - Tool result/output +- `output.title` - Output title (can be modified) + +**What you can do:** +- ✅ Modify output +- ✅ Add titles/formatting +- ✅ Log completion +- ✅ Add analytics +- ✅ Transform results + +**What you can't do:** +- ❌ Modify tool arguments (already executed) +- ❌ Prevent tool execution (already happened) + +--- + +## Event Lifecycle in Skills Plugin + +``` +┌─────────────────────────────────────────────────────────────────┐ +│ AGENT CALLS SKILL TOOL │ +│ (e.g., skills_brand_guidelines) │ +└─────────────────────────────────────────────────────────────────┘ + ↓ +┌─────────────────────────────────────────────────────────────────┐ +│ EVENT: tool.execute.before fires │ +│ │ +│ Hook Function: beforeHook(input, output) │ +│ ┌─────────────────────────────────────────────────────────┐ │ +│ │ 1. Check: input.tool.startsWith("skills_") │ │ +│ │ 2. Lookup: skillMap.get(input.tool) │ │ +│ │ 3. Inject: ctx.client.session.prompt({ │ │ +│ │ path: { id: input.sessionID }, │ │ +│ │ body: { │ │ +│ │ agent: input.agent, │ │ +│ │ noReply: true, │ │ +│ │ parts: [{ type: "text", text: skill.content }] │ │ +│ │ } │ │ +│ │ }) │ │ +│ │ 4. Result: Skill content added to conversation │ │ +│ └─────────────────────────────────────────────────────────┘ │ +│ │ +│ Effect: Skill content persists in conversation history │ +│ No AI response triggered (noReply: true) │ +└─────────────────────────────────────────────────────────────────┘ + ↓ +┌─────────────────────────────────────────────────────────────────┐ +│ TOOL.EXECUTE() RUNS │ +│ │ +│ async execute(args, toolCtx) { │ +│ return `Skill activated: ${skill.name}` │ +│ } │ +│ │ +│ Effect: Minimal confirmation returned │ +└─────────────────────────────────────────────────────────────────┘ + ↓ +┌─────────────────────────────────────────────────────────────────┐ +│ EVENT: tool.execute.after fires │ +│ │ +│ Hook Function: afterHook(input, output) │ +│ ┌─────────────────────────────────────────────────────────┐ │ +│ │ 1. Check: input.tool.startsWith("skills_") │ │ +│ │ 2. Lookup: skillMap.get(input.tool) │ │ +│ │ 3. Verify: output.output exists │ │ +│ │ 4. Enhance: output.title = `📚 ${skill.name}` │ │ +│ │ 5. Result: Output title modified with emoji │ │ +│ └─────────────────────────────────────────────────────────┘ │ +│ │ +│ Effect: Visual feedback added to output │ +│ Could add logging/analytics here │ +└─────────────────────────────────────────────────────────────────┘ + ↓ +┌─────────────────────────────────────────────────────────────────┐ +│ RESULT RETURNED TO AGENT │ +│ │ +│ - Tool confirmation message │ +│ - Skill content in conversation history │ +│ - Enhanced output with emoji title │ +│ - Agent can now use skill content in reasoning │ +└─────────────────────────────────────────────────────────────────┘ +``` + +--- + +## Why Hooks Instead of Embedded Logic? + +### Problem: Embedded Delivery (Anti-Pattern) + +```typescript +// ❌ OLD: Skill delivery inside tool.execute() +async execute(args, toolCtx) { + const sendSilentPrompt = (text: string) => + ctx.client.session.prompt({...}) + + await sendSilentPrompt(`The "${skill.name}" skill is loading...`) + await sendSilentPrompt(`Base directory: ${skill.fullPath}\n\n${skill.content}`) + + return `Launching skill: ${skill.name}` +} +``` + +**Issues:** +1. **Tight Coupling**: Tool logic and delivery are inseparable +2. **Hard to Test**: Can't test tool without testing delivery +3. **Violates SOLID**: Single Responsibility Principle broken +4. **No Reusability**: Delivery logic can't be extracted +5. **Difficult to Monitor**: Can't track delivery separately + +--- + +### Solution: Hook-Based Delivery (Best Practice) + +```typescript +// ✅ NEW: Separated concerns using hooks + +// Tool: Minimal and focused +async execute(args, toolCtx) { + return `Skill activated: ${skill.name}` +} + +// Hook: Handles delivery +const beforeHook = async (input, output) => { + if (input.tool.startsWith("skills_")) { + const skill = skillMap.get(input.tool) + if (skill) { + await ctx.client.session.prompt({...}) + } + } +} +``` + +**Benefits:** +1. ✅ **Loose Coupling**: Tool and delivery are independent +2. ✅ **Easy to Test**: Each component tested separately +3. ✅ **SOLID Compliant**: Single Responsibility Principle +4. ✅ **Reusable**: Hooks can be composed with other plugins +5. ✅ **Monitorable**: Can add logging/analytics independently + +--- + +## Skill Lookup Map: Performance Optimization + +### Why a Map? + +The skill lookup map enables O(1) access instead of O(n) search: + +```typescript +// ✅ EFFICIENT: O(1) lookup +const skillMap = new Map() +for (const skill of skills) { + skillMap.set(skill.toolName, skill) +} + +const beforeHook = async (input, output) => { + if (input.tool.startsWith("skills_")) { + const skill = skillMap.get(input.tool) // O(1) constant time + if (skill) { + // Use skill + } + } +} +``` + +### Performance Impact + +| Number of Skills | Array Search (O(n)) | Map Lookup (O(1)) | Speedup | +|------------------|-------------------|------------------|---------| +| 10 | 10 comparisons | 1 lookup | 10x | +| 100 | 100 comparisons | 1 lookup | 100x | +| 1000 | 1000 comparisons | 1 lookup | 1000x | + +**Conclusion:** Map lookup is essential for scalability + +--- + +## Integration with OpenCode Event System + +### Event Mapping + +| OpenCode Event | Skills Plugin Hook | Purpose | +|---|---|---| +| `tool.execute.before` | `beforeHook` | Skill content injection | +| `tool.execute.after` | `afterHook` | Output enhancement | + +### Plugin Return Object + +```typescript +return { + // Custom tools + tool: tools, + + // Hook: Runs before tool execution + "tool.execute.before": beforeHook, + + // Hook: Runs after tool execution + "tool.execute.after": afterHook, +} +``` + +**Key Points:** +- Hooks apply to ALL tools (use `if` statements to filter) +- Multiple plugins can register hooks without conflict +- Hooks run in registration order +- Hooks can be async + +--- + +## Comparison with Other Event Hooks + +### Available Tool Execution Hooks + +| Hook | When | Use Case | +|------|------|----------| +| `tool.execute.before` | Before tool runs | Input validation, context injection, preprocessing | +| `tool.execute.after` | After tool completes | Output formatting, logging, analytics | + +### Other Event Hooks (Not Used in Skills Plugin) + +| Hook | When | Use Case | +|------|------|----------| +| `session.created` | Session starts | Welcome messages, initialization | +| `message.updated` | Message changes | Monitoring, logging | +| `session.idle` | Session completes | Cleanup, background tasks | +| `session.error` | Error occurs | Error handling, logging | + +--- + +## Real-World Example: Skill Delivery Flow + +### Step 1: Agent Calls Skill Tool + +``` +Agent: "Use the brand-guidelines skill" +↓ +OpenCode: Calls skills_brand_guidelines tool +``` + +### Step 2: Before Hook Fires + +```typescript +const beforeHook = async (input, output) => { + // input.tool = "skills_brand_guidelines" + // input.sessionID = "ses_abc123" + // input.agent = "my-helper" + + if (input.tool.startsWith("skills_")) { + const skill = skillMap.get("skills_brand_guidelines") + // skill = { + // name: "brand-guidelines", + // description: "Brand guidelines for the project", + // content: "# Brand Guidelines\n\n...", + // fullPath: "/path/to/skill" + // } + + await ctx.client.session.prompt({ + path: { id: "ses_abc123" }, + body: { + agent: "my-helper", + noReply: true, + parts: [ + { + type: "text", + text: "📚 Skill: brand-guidelines\nBase directory: /path/to/skill\n\n# Brand Guidelines\n\n..." + } + ] + } + }) + } +} +``` + +**Result:** Skill content added to conversation, no AI response + +### Step 3: Tool Executes + +```typescript +async execute(args, toolCtx) { + // Minimal logic + return `Skill activated: brand-guidelines` +} +``` + +**Result:** Simple confirmation returned + +### Step 4: After Hook Fires + +```typescript +const afterHook = async (input, output) => { + // input.tool = "skills_brand_guidelines" + // output.output = "Skill activated: brand-guidelines" + + if (input.tool.startsWith("skills_")) { + const skill = skillMap.get("skills_brand_guidelines") + if (skill && output.output) { + output.title = `📚 brand-guidelines` + } + } +} +``` + +**Result:** Output title enhanced with emoji + +### Step 5: Agent Receives Result + +``` +Conversation History: +├─ User: "Use the brand-guidelines skill" +├─ Tool Call: skills_brand_guidelines +├─ Silent Message: "📚 Skill: brand-guidelines\n..." +├─ Tool Result: "Skill activated: brand-guidelines" +│ (with title: "📚 brand-guidelines") +└─ Agent: "I now have the brand guidelines. I can help with..." +``` + +--- + +## Testing Hooks + +### Testing Before Hook + +```typescript +describe("beforeHook", () => { + it("should inject skill content for skill tools", async () => { + const input = { + tool: "skills_brand_guidelines", + sessionID: "ses_test", + agent: "test-agent" + } + const output = { args: {} } + + const mockPrompt = jest.fn() + ctx.client.session.prompt = mockPrompt + + await beforeHook(input, output) + + expect(mockPrompt).toHaveBeenCalledWith( + expect.objectContaining({ + path: { id: "ses_test" }, + body: expect.objectContaining({ + agent: "test-agent", + noReply: true, + parts: expect.arrayContaining([ + expect.objectContaining({ + type: "text", + text: expect.stringContaining("brand-guidelines") + }) + ]) + }) + }) + ) + }) + + it("should skip non-skill tools", async () => { + const input = { tool: "read_file", sessionID: "ses_test" } + const output = { args: {} } + + const mockPrompt = jest.fn() + ctx.client.session.prompt = mockPrompt + + await beforeHook(input, output) + + expect(mockPrompt).not.toHaveBeenCalled() + }) +}) +``` + +### Testing After Hook + +```typescript +describe("afterHook", () => { + it("should add emoji title for skill tools", async () => { + const input = { tool: "skills_brand_guidelines" } + const output = { output: "Skill activated" } + + await afterHook(input, output) + + expect(output.title).toBe("📚 brand-guidelines") + }) + + it("should skip non-skill tools", async () => { + const input = { tool: "read_file" } + const output = { output: "File content" } + + await afterHook(input, output) + + expect(output.title).toBeUndefined() + }) + + it("should skip if output is missing", async () => { + const input = { tool: "skills_brand_guidelines" } + const output = { output: null } + + await afterHook(input, output) + + expect(output.title).toBeUndefined() + }) +}) +``` + +--- + +## Common Patterns + +### Pattern 1: Tool-Specific Hooks + +```typescript +const beforeHook = async (input, output) => { + switch (input.tool) { + case "skills_brand_guidelines": + // Handle brand guidelines + break + case "skills_api_reference": + // Handle API reference + break + default: + // Skip non-skill tools + } +} +``` + +### Pattern 2: Conditional Processing + +```typescript +const beforeHook = async (input, output) => { + if (input.tool.startsWith("skills_")) { + const skill = skillMap.get(input.tool) + if (skill && skill.allowedTools?.includes(input.agent)) { + // Process only if allowed + } + } +} +``` + +### Pattern 3: Logging & Monitoring + +```typescript +const beforeHook = async (input, output) => { + if (input.tool.startsWith("skills_")) { + console.log(`[BEFORE] Skill tool called: ${input.tool}`) + console.log(`[BEFORE] Session: ${input.sessionID}`) + } +} + +const afterHook = async (input, output) => { + if (input.tool.startsWith("skills_")) { + console.log(`[AFTER] Skill tool completed: ${input.tool}`) + console.log(`[AFTER] Output length: ${output.output?.length || 0}`) + } +} +``` + +### Pattern 4: Error Handling + +```typescript +const beforeHook = async (input, output) => { + try { + if (input.tool.startsWith("skills_")) { + const skill = skillMap.get(input.tool) + if (!skill) { + throw new Error(`Skill not found: ${input.tool}`) + } + // Process skill + } + } catch (error) { + console.error(`Hook error:`, error) + // Don't rethrow - let tool execute anyway + } +} +``` + +--- + +## Key Takeaways + +1. **Hooks are middleware**: They intercept tool execution at specific points +2. **Before hook**: For preprocessing, validation, context injection +3. **After hook**: For output enhancement, logging, analytics +4. **Lookup maps**: Enable O(1) access instead of O(n) search +5. **Separation of concerns**: Tools do one thing, hooks do another +6. **Composability**: Multiple plugins can register hooks without conflict +7. **Testability**: Each component can be tested independently +8. **Maintainability**: Changes are isolated to specific hooks + +--- + +## References + +- **OpenCode Events**: `context/capabilities/events.md` +- **Tool Definition**: `context/capabilities/tools.md` +- **Best Practices**: `context/reference/best-practices.md` +- **Skills Plugin Example**: `skills-plugin/example.ts` +- **Hook Lifecycle**: `skills-plugin/hook-lifecycle-and-patterns.md` +- **Implementation Pattern**: `skills-plugin/implementation-pattern.md` + diff --git a/.opencode/context/openagents-repo/plugins/context/capabilities/tools.md b/.opencode/context/openagents-repo/plugins/context/capabilities/tools.md new file mode 100644 index 0000000..83e589e --- /dev/null +++ b/.opencode/context/openagents-repo/plugins/context/capabilities/tools.md @@ -0,0 +1,51 @@ +# Building Custom Tools + +Plugins can add custom tools that OpenCode agents can call autonomously. + +## Tool Definition + +Custom tools use Zod for schema definition and the `tool` helper from `@opencode-ai/plugin`. + +```typescript +import { z } from 'zod'; +import { tool } from '@opencode-ai/plugin'; + +export const MyCustomTool = tool( + z.object({ + query: z.string().describe('Search query'), + limit: z.number().default(10).describe('Results limit') + }), + async (args, context) => { + const { query, limit } = args; + // Implementation logic + return { success: true, data: [] }; + } +).describe('Search your database'); +``` + +## Shell-based Tools + +You can leverage Bun's shell API (`$`) to run commands in any language. + +```typescript +export const PythonCalculatorTool = tool( + z.object({ expression: z.string() }), + async (args, context) => { + const { $ } = context; + const result = await $`python3 -c 'print(eval("${args.expression}"))'`; + return { result: result.stdout }; + } +).describe('Calculate mathematical expressions'); +``` + +## Integration + +To register tools in your plugin: + +```typescript +export const MyPlugin = async (context) => { + return { + tool: [MyCustomTool, PythonCalculatorTool] + }; +}; +``` diff --git a/.opencode/context/openagents-repo/plugins/context/context-overview.md b/.opencode/context/openagents-repo/plugins/context/context-overview.md new file mode 100644 index 0000000..fe44734 --- /dev/null +++ b/.opencode/context/openagents-repo/plugins/context/context-overview.md @@ -0,0 +1,34 @@ +# OpenCode Plugin Context Library + +This library provides structured context for AI coding assistants to understand, build, and extend OpenCode plugins. Depending on your task, you can load specific parts of this library. + +## 📚 Library Map + +### 🏗️ Architecture +Foundational concepts of how plugins are registered and executed. +- [Overview](./architecture/overview.md): Basic structure, registration, and context object. +- [Lifecycle](./architecture/lifecycle.md): Packaging, manifest, and session lifecycle. + +### 🛠️ Capabilities +Deep dives into specific plugin features. +- [Events](./capabilities/events.md): Detailed list of all 25+ hookable events. +- [Events: Skills Plugin](./capabilities/events_skills.md): Practical example of event hooks in the Skills Plugin. +- [Tools](./capabilities/tools.md): How to build and register custom tools using Zod. +- [Agents](./capabilities/agents.md): Creating and configuring custom AI agents. + +### 📖 Reference +Guidelines and troubleshooting. +- [Best Practices](./reference/best-practices.md): Message injection workarounds, security, and performance. + +### 🧩 Claude Code Plugins (External) +Claude Code plugin system documentation (harvested from external docs). +- [Concepts: Plugin Architecture](./concepts/plugin-architecture.md): Core concepts and structure +- [Guides: Creating Plugins](./guides/creating-plugins.md): Step-by-step creation +- [Guides: Migrating to Plugins](./guides/migrating-to-plugins.md): Convert standalone to plugin +- [Lookup: Plugin Structure](./lookup/plugin-structure.md): Directory reference + +## 🚀 How to use this library +If you are asking an AI to build a new feature: +1. **For a new tool**: Provide `architecture/overview.md` and `capabilities/tools.md`. +2. **For reacting to events**: Provide `capabilities/events.md`. +3. **For overall plugin architecture**: Provide `architecture/overview.md` and `architecture/lifecycle.md`. diff --git a/.opencode/context/openagents-repo/plugins/context/reference/best-practices.md b/.opencode/context/openagents-repo/plugins/context/reference/best-practices.md new file mode 100644 index 0000000..1ee240b --- /dev/null +++ b/.opencode/context/openagents-repo/plugins/context/reference/best-practices.md @@ -0,0 +1,26 @@ +# Best Practices & Limitations + +## Message Injection Workarounds + +**The Reality**: The message system is largely read-only. You cannot mutate messages mid-stream or inject text directly into an existing message part. + +### What Doesn't Work +- Modifying `event.data.content` in `message.updated`. +- Retroactively changing AI responses. + +### What Works +1. **Initial Context**: Use `session.created` to inject a starting message using `client.session.prompt()`. +2. **Prompt Decoration**: Use `client.tui.appendPrompt()` to add text to the user's input box before they hit enter. +3. **Tool Interception**: Use `tool.execute.before` to modify arguments *before* the tool runs. +4. **On-Demand Context**: Provide custom tools that the AI can call when it needs more information. + +## Security + +- Always validate tool inputs in `tool.execute.before`. +- Use environment variables for sensitive data; do not hardcode API keys. +- Be careful with the `$` shell API to prevent command injection. + +## Performance + +- Avoid heavy synchronous operations in event handlers as they can block the TUI. +- Use the `session.idle` event for cleanup or background sync tasks. diff --git a/.opencode/context/openagents-repo/plugins/navigation.md b/.opencode/context/openagents-repo/plugins/navigation.md new file mode 100644 index 0000000..8befc6e --- /dev/null +++ b/.opencode/context/openagents-repo/plugins/navigation.md @@ -0,0 +1,40 @@ +# OpenAgents Plugins + +**Purpose**: Plugin architecture and documentation for OpenAgents Control + +--- + +## Structure + +``` +openagents-repo/plugins/ +├── navigation.md (this file) +├── context/ +│ └── [context plugin files] +└── [plugin files] +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **Context plugin** | `./context/` | +| **View plugins** | `./` | +| **Guides** | `../guides/navigation.md` | + +--- + +## By Type + +**Context Plugin** → Context system plugin documentation +**Plugin Architecture** → How plugins work in OpenAgents + +--- + +## Related Context + +- **OpenAgents Navigation** → `../navigation.md` +- **Guides** → `../guides/navigation.md` +- **Core Concepts** → `../core-concepts/navigation.md` diff --git a/.opencode/context/openagents-repo/quality/navigation.md b/.opencode/context/openagents-repo/quality/navigation.md new file mode 100644 index 0000000..9fd58fc --- /dev/null +++ b/.opencode/context/openagents-repo/quality/navigation.md @@ -0,0 +1,39 @@ +# OpenAgents Quality + +**Purpose**: Quality assurance and standards for OpenAgents Control + +--- + +## Structure + +``` +openagents-repo/quality/ +├── navigation.md (this file) +└── [quality documentation] +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **View quality docs** | `./` | +| **Guides** | `../guides/navigation.md` | +| **Errors** | `../errors/navigation.md` | + +--- + +## By Type + +**Quality Standards** → Standards for code quality +**Testing** → Testing requirements and patterns +**Validation** → Validation procedures + +--- + +## Related Context + +- **OpenAgents Navigation** → `../navigation.md` +- **Guides** → `../guides/navigation.md` +- **Errors** → `../errors/navigation.md` diff --git a/.opencode/context/openagents-repo/quality/registry-dependencies.md b/.opencode/context/openagents-repo/quality/registry-dependencies.md new file mode 100644 index 0000000..c90828b --- /dev/null +++ b/.opencode/context/openagents-repo/quality/registry-dependencies.md @@ -0,0 +1,586 @@ +--- +description: Maintain registry quality through dependency validation and consistency checks +tags: + - registry + - quality + - validation + - dependencies +dependencies: [] +--- + + +# Registry Dependency Validation + +**Purpose**: Maintain registry quality through dependency validation and consistency checks +**Audience**: Contributors, maintainers, CI/CD processes + +--- + +## Quick Reference + +**Golden Rule**: All component dependencies must be declared in frontmatter and validated before commits. + +**Critical Commands**: +```bash +# Check context file dependencies +/check-context-deps + +# Auto-fix missing dependencies +/check-context-deps --fix + +# Validate entire registry +./scripts/registry/validate-registry.sh + +# Update registry after changes +./scripts/registry/auto-detect-components.sh --auto-add +``` + +--- + +## Dependency System + +### Dependency Types + +Components can depend on other components using the `type:id` format: + +| Type | Format | Example | Description | +|------|--------|---------|-------------| +| **agent** | `agent:id` | `agent:opencoder` | Core agent profile | +| **subagent** | `subagent:id` | `subagent:coder-agent` | Delegatable subagent | +| **command** | `command:id` | `command:context` | Slash command | +| **tool** | `tool:id` | `tool:gemini` | External tool integration | +| **plugin** | `plugin:id` | `plugin:context` | Plugin component | +| **context** | `context:path` | `context:core/standards/code` | Context file | +| **config** | `config:id` | `config:defaults` | Configuration file | + +### Declaring Dependencies + +**In component frontmatter** (example): +``` +id: opencoder +name: OpenCoder +description: Multi-language implementation agent +dependencies: + - subagent:task-manager # Can delegate to task-manager + - subagent:coder-agent # Can delegate to coder-agent + - subagent:tester # Can delegate to tester + - context:core/standards/code # Requires code standards context +``` + +**Why declare dependencies?** +- ✅ **Validation**: Catch missing components before runtime +- ✅ **Documentation**: Clear visibility of what each component needs +- ✅ **Installation**: Installers can fetch all required dependencies +- ✅ **Dependency graphs**: Visualize component relationships +- ✅ **Breaking change detection**: Know what's affected by changes + +--- + +## Context File Dependencies + +### The Problem + +Agents reference context files in their prompts but often don't declare them as dependencies: + +```markdown + +BEFORE any code implementation, ALWAYS load: +- Code tasks → .opencode/context/core/standards/code-quality.md (MANDATORY) +``` + +**Without dependency declaration**: +- ❌ No validation that context file exists +- ❌ Can't track which agents use which context files +- ❌ Breaking changes when context files are moved/deleted +- ❌ Installers don't know to fetch context files + +### The Solution + +**Declare context dependencies in frontmatter** (example): +``` +id: opencoder +dependencies: + - context:core/standards/code # ← ADD THIS +``` + +**Use `/check-context-deps` to find missing declarations**: +```bash +# Analyze all agents +/check-context-deps + +# Auto-fix missing context dependencies +/check-context-deps --fix +``` + +### Context Dependency Format + +**Path normalization**: +``` +File path: .opencode/context/core/standards/code-quality.md +Dependency: context:core/standards/code + ^^^^^^^ ^^^^^^^^^^^^^^^^^^^ + type path (no .opencode/, no .md) +``` + +**Examples**: +``` +dependencies: + - context:core/standards/code # .opencode/context/core/standards/code-quality.md + - context:core/standards/docs # .opencode/context/core/standards/documentation.md + - context:core/workflows/delegation # .opencode/context/core/workflows/task-delegation-basics.md + - context:openagents-repo/guides/adding-agent # Project-specific context +``` + +--- + +## Validation Workflow + +### Pre-Commit Checklist + +Before committing changes to agents, commands, or context files: + +1. **Check context dependencies**: + ```bash + /check-context-deps + ``` + - Identifies agents using context files without declaring them + - Reports unused context files + - Validates context file paths + +2. **Fix missing dependencies** (if needed): + ```bash + /check-context-deps --fix + ``` + - Automatically adds missing `context:` dependencies to frontmatter + - Preserves existing dependencies + +3. **Update registry**: + ```bash + ./scripts/registry/auto-detect-components.sh --auto-add + ``` + - Extracts dependencies from frontmatter + - Updates registry.json + +4. **Validate registry**: + ```bash + ./scripts/registry/validate-registry.sh + ``` + - Checks all dependencies exist + - Validates component paths + - Reports missing dependencies + +### Validation Tools + +#### 1. `/check-context-deps` Command + +**Purpose**: Analyze context file usage and validate dependencies + +**What it checks**: +- ✅ Agents referencing context files in prompts +- ✅ Context dependencies declared in frontmatter +- ✅ Context files exist on disk +- ✅ Context files in registry +- ✅ Unused context files + +**Usage**: +```bash +# Full analysis +/check-context-deps + +# Specific agent +/check-context-deps opencoder + +# Auto-fix +/check-context-deps --fix + +# Verbose (show line numbers) +/check-context-deps --verbose +``` + +**Example output**: +``` +# Context Dependency Analysis Report + +## Summary +- Agents scanned: 25 +- Context files referenced: 12 +- Missing dependencies: 8 +- Unused context files: 2 + +## Missing Dependencies + +### opencoder +Uses but not declared: +- context:core/standards/code (referenced 3 times) + - Line 64: "Code tasks → .opencode/context/core/standards/code-quality.md" + +Recommended fix: +dependencies: + - context:core/standards/code +``` + +#### 2. `auto-detect-components.sh` Script + +**Purpose**: Scan for new components and update registry + +**Dependency validation**: +- Checks dependencies during component scanning +- Logs warnings for missing dependencies +- Non-blocking (warnings only) + +**Usage**: +```bash +# See what would be added +./scripts/registry/auto-detect-components.sh --dry-run + +# Add new components +./scripts/registry/auto-detect-components.sh --auto-add +``` + +**Example warning**: +``` +⚠ New command: Demo (demo) + Dependencies: subagent:coder-agent,subagent:missing-agent + ⚠ Dependency not found in registry: subagent:missing-agent +``` + +#### 3. `validate-registry.sh` Script + +**Purpose**: Comprehensive registry validation + +**Checks**: +- ✅ All component paths exist +- ✅ All dependencies exist in registry +- ✅ No duplicate IDs +- ✅ Valid JSON structure +- ✅ Required fields present + +**Usage**: +```bash +./scripts/registry/validate-registry.sh +``` + +**Example output**: +``` +Validating registry.json... + +✗ Dependency not found: opencoder → context:core/standards/code + +Missing dependencies: 1 + - opencoder (agent) → context:core/standards/code + +Fix: Add missing component to registry or remove from dependencies +``` + +--- + +## Quality Standards + +### Well-Maintained Registry + +A high-quality registry has: + +✅ **Complete dependencies**: All component dependencies declared +✅ **Validated dependencies**: All dependencies exist in registry +✅ **No orphans**: All context files used by at least one component +✅ **Consistent format**: Dependencies use `type:id` format +✅ **Up-to-date**: Registry reflects current component state +✅ **No broken paths**: All component paths valid + +### Dependency Declaration Standards + +**DO**: +- ✅ Declare all subagents you delegate to +- ✅ Declare all context files you reference +- ✅ Declare all commands you invoke +- ✅ Use correct format: `type:id` +- ✅ Keep dependencies in frontmatter (not hardcoded in prompts) + +**DON'T**: +- ❌ Reference context files without declaring dependency +- ❌ Use invalid dependency formats +- ❌ Declare dependencies you don't actually use +- ❌ Forget to update registry after adding dependencies + +--- + +## Commit Guidelines + +### When Adding/Modifying Components + +**1. Add component with proper frontmatter** (example): +``` +id: my-agent +name: My Agent +description: Does something useful +tags: + - development + - coding +dependencies: + - subagent:coder-agent + - context:core/standards/code +``` + +**2. Validate dependencies**: +```bash +/check-context-deps my-agent +``` + +**3. Update registry**: +```bash +./scripts/registry/auto-detect-components.sh --auto-add +``` + +**4. Validate registry**: +```bash +./scripts/registry/validate-registry.sh +``` + +**5. Commit with descriptive message**: +```bash +git add .opencode/agent/my-agent.md registry.json +git commit -m "Add my-agent with coder-agent and code standards dependencies" +``` + +### When Modifying Context Files + +**1. Check which agents depend on it**: +```bash +jq '.components[] | .[] | select(.dependencies[]? | contains("context:core/standards/code")) | {id, name}' registry.json +``` + +**2. Update context file**: +```bash +# Make your changes +vim .opencode/context/core/standards/code-quality.md +``` + +**3. Validate no broken references**: +```bash +/check-context-deps --verbose +``` + +**4. Update registry if needed**: +```bash +./scripts/registry/auto-detect-components.sh --auto-add +``` + +**5. Commit with impact note**: +```bash +git commit -m "Update code standards - affects opencoder, openagent, reviewer" +``` + +### When Deleting Components + +**1. Check dependencies first**: +```bash +# Find what depends on this component +jq '.components[] | .[] | select(.dependencies[]? == "subagent:old-agent") | {id, name}' registry.json +``` + +**2. Remove from dependents**: +```bash +# Update agents that depend on it +# Remove the dependency from their frontmatter +``` + +**3. Delete component**: +```bash +rm .opencode/agent/subagents/old-agent.md +``` + +**4. Update registry**: +```bash +./scripts/registry/auto-detect-components.sh --auto-add +``` + +**5. Validate**: +```bash +./scripts/registry/validate-registry.sh +``` + +--- + +## Troubleshooting + +### Missing Context Dependencies + +**Symptom**: +``` +/check-context-deps reports: + opencoder: missing context:core/standards/code +``` + +**Fix**: +```bash +# Option 1: Auto-fix +/check-context-deps --fix + +# Option 2: Manual fix +# Edit .opencode/agent/core/opencoder.md +# Add to frontmatter: +dependencies: + - context:core/standards/code + +# Then update registry +./scripts/registry/auto-detect-components.sh --auto-add +``` + +### Dependency Not Found in Registry + +**Symptom**: +``` +⚠ Dependency not found in registry: context:core/standards/code +``` + +**Causes**: +1. Context file doesn't exist +2. Context file exists but not in registry +3. Wrong dependency format + +**Fix**: +```bash +# Check if file exists +ls -la .opencode/context/core/standards/code-quality.md + +# If exists, add to registry +./scripts/registry/auto-detect-components.sh --auto-add + +# If doesn't exist, remove dependency or create file +``` + +### Unused Context Files + +**Symptom**: +``` +/check-context-deps reports: + Unused: context:core/standards/analysis (0 references) +``` + +**Fix**: +```bash +# Option 1: Add to an agent that should use it +# Edit agent frontmatter to add dependency + +# Option 2: Remove if truly unused +rm .opencode/context/core/standards/code-analysis.md +./scripts/registry/auto-detect-components.sh --auto-add +``` + +### Circular Dependencies + +**Symptom**: +``` +Agent A depends on Agent B +Agent B depends on Agent A +``` + +**Fix**: +- Refactor to remove circular dependency +- Extract shared logic to a third component +- Use dependency injection instead + +--- + +## CI/CD Integration + +### Pre-Commit Hook + +```bash +#!/bin/bash +# .git/hooks/pre-commit + +echo "Validating registry dependencies..." + +# Check context dependencies +/check-context-deps || { + echo "❌ Context dependency validation failed" + echo "Run: /check-context-deps --fix" + exit 1 +} + +# Validate registry +./scripts/registry/validate-registry.sh || { + echo "❌ Registry validation failed" + exit 1 +} + +echo "✅ Registry validation passed" +``` + +### GitHub Actions + +```yaml +name: Validate Registry + +on: [push, pull_request] + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Validate registry + run: ./scripts/registry/validate-registry.sh + + - name: Check context dependencies + run: /check-context-deps +``` + +--- + +## Best Practices + +### For Component Authors + +1. **Always declare dependencies** in frontmatter +2. **Use `/check-context-deps`** before committing +3. **Update registry** after adding components +4. **Validate** before pushing +5. **Document** why dependencies are needed + +### For Maintainers + +1. **Review dependencies** in PRs +2. **Run validation** in CI/CD +3. **Keep context files** organized and documented +4. **Monitor unused** context files +5. **Refactor** when dependency graphs get complex + +### For CI/CD + +1. **Fail builds** on validation errors +2. **Report** missing dependencies +3. **Track** dependency changes over time +4. **Alert** on circular dependencies +5. **Enforce** dependency declaration standards + +--- + +## Related Documentation + +- **Registry Guide**: `.opencode/context/openagents-repo/guides/updating-registry.md` +- **Registry Concepts**: `.opencode/context/openagents-repo/core-concepts/registry.md` +- **Adding Agents**: `.opencode/context/openagents-repo/guides/adding-agent.md` +- **Command Reference**: `/check-context-deps` command + +--- + +## Summary + +**Key Takeaways**: +1. Declare all dependencies in frontmatter (subagents, context files, etc.) +2. Use `/check-context-deps` to find missing context dependencies +3. Validate registry before commits +4. Keep registry in sync with component changes +5. Follow dependency format: `type:id` + +**Quality Checklist**: +- [ ] All context files referenced have dependencies declared +- [ ] All dependencies exist in registry +- [ ] No unused context files (or documented why) +- [ ] Registry validates without errors +- [ ] Dependency format is consistent + +**Remember**: Dependencies are documentation. They help users understand what components need and help the system validate integrity. diff --git a/.opencode/context/openagents-repo/quick-start.md b/.opencode/context/openagents-repo/quick-start.md new file mode 100644 index 0000000..9001bd9 --- /dev/null +++ b/.opencode/context/openagents-repo/quick-start.md @@ -0,0 +1,169 @@ +# OpenAgents Control Repository - Quick Start + +**Purpose**: Get oriented in this repo in 2 minutes + +--- + +## What Is This Repo? + +OpenAgents Control is an AI agent framework with: +- **Category-based agents** (core, development, content, data, product, learning) +- **Eval framework** for testing agent behavior +- **Registry system** for component distribution +- **Install system** for easy setup + +--- + +## Core Concepts (Load These First) + +Before working on this repo, understand these 4 systems: + +1. **Agents** → Load: `core-concepts/agents.md` + - How agents are structured + - Category system + - Prompt variants + - Subagents vs category agents + +2. **Evals** → Load: `core-concepts/evals.md` + - How testing works + - Running tests + - Evaluators + - Session collection + +3. **Registry** → Load: `core-concepts/registry.md` + - How components are tracked + - Auto-detect system + - Validation + - Install system + +4. **Categories** → Load: `core-concepts/categories.md` + - How organization works + - Naming conventions + - Path patterns + +--- + +## I Need To... + +| Task | Load These Files | +|------|------------------| +| Add a new agent | `core-concepts/agents.md` + `guides/adding-agent.md` | +| Test an agent | `core-concepts/evals.md` + `guides/testing-agent.md` | +| Fix registry | `core-concepts/registry.md` + `guides/updating-registry.md` | +| Debug issue | `guides/debugging.md` | +| Find files | `lookup/file-locations.md` | +| Create release | `guides/creating-release.md` | +| Write content or copy | `core-concepts/categories.md` + `../content-creation/principles/navigation.md` | +| Use Claude Code helpers | `core-concepts/agents.md` + `guides/adding-agent.md` + `../to-be-consumed/claude-code-docs/create-subagents.md` | + +--- + +## Essential Paths (Top 15) + +``` +.opencode/agent/core/ # Core agents (openagent, opencoder) +.opencode/agent/{category}/ # Category agents +.opencode/agent/subagents/ # Subagents +evals/agents/{category}/{agent}/ # Agent tests +evals/framework/src/ # Eval framework code +registry.json # Component catalog +install.sh # Installer +scripts/registry/validate-registry.sh # Validate registry +scripts/registry/auto-detect-components.sh # Auto-detect components +scripts/validation/validate-test-suites.sh # Validate tests +.opencode/context/ # Context files +.opencode/command/ # Slash commands +docs/ # Documentation +VERSION # Current version +package.json # Node dependencies +``` + +--- + +## Common Commands (Top 10) + +```bash +# Add new agent (auto-detect) +./scripts/registry/auto-detect-components.sh --auto-add + +# Validate registry +./scripts/registry/validate-registry.sh + +# Test agent +cd evals/framework && npm run eval:sdk -- --agent={category}/{agent} + +# Run smoke test +cd evals/framework && npm run eval:sdk -- --agent={agent} --pattern="smoke-test.yaml" + +# Test with debug +cd evals/framework && npm run eval:sdk -- --agent={agent} --debug + +# Validate test suites +./scripts/validation/validate-test-suites.sh + +# Install locally (test) +REGISTRY_URL="file://$(pwd)/registry.json" ./install.sh --list + +# Bump version +echo "0.X.Y" > VERSION && jq '.version = "0.X.Y"' package.json > tmp && mv tmp package.json + +# Check version consistency +cat VERSION && cat package.json | jq '.version' + +# Run full validation +./scripts/registry/validate-registry.sh && ./scripts/validation/validate-test-suites.sh +``` + +--- + +## Repository Structure (Quick View) + +``` +opencode-agents/ +├── .opencode/ +│ ├── agent/{category}/ # Agents by domain +│ │ ├── core/ # Core system agents +│ │ ├── development/ # Dev specialists +│ │ ├── content/ # Content creators +│ │ ├── data/ # Data analysts +│ │ ├── product/ # Product managers +│ │ ├── learning/ # Educators +│ │ └── subagents/ # Delegated specialists +│ ├── command/ # Slash commands +│ └── context/ # Shared knowledge +├── evals/ +│ ├── agents/{category}/ # Test suites +│ └── framework/ # Eval framework +├── scripts/ +│ ├── registry/ # Registry tools +│ └── validation/ # Validation tools +├── docs/ # Documentation +├── registry.json # Component catalog +└── install.sh # Installer +``` + +--- + +## Quick Troubleshooting + +| Problem | Solution | +|---------|----------| +| Registry validation fails | `./scripts/registry/auto-detect-components.sh --auto-add` | +| Test fails | Load `guides/debugging.md` | +| Can't find file | Load `lookup/file-locations.md` | +| Install fails | Check: `which curl jq` | +| Path resolution issues | Check `core-concepts/categories.md` | + +--- + +## Next Steps + +1. **First time?** → Read `core-concepts/agents.md`, `evals.md`, `registry.md` +2. **Adding agent?** → Load `guides/adding-agent.md` +3. **Testing?** → Load `guides/testing-agent.md` +4. **Need details?** → Load specific files from `core-concepts/` or `guides/` + +--- + +**Last Updated**: 2026-01-13 +**Version**: 0.5.1 diff --git a/.opencode/context/openagents-repo/templates/context-bundle-template.md b/.opencode/context/openagents-repo/templates/context-bundle-template.md new file mode 100644 index 0000000..d090a80 --- /dev/null +++ b/.opencode/context/openagents-repo/templates/context-bundle-template.md @@ -0,0 +1,248 @@ +# Context Bundle Template + +**Purpose**: Template for creating context bundles when delegating tasks to subagents + +**Location**: `.tmp/context/{session-id}/bundle.md` + +**Used by**: repo-manager agent when delegating to subagents + +--- + +## Template + +```markdown +# Context Bundle: {Task Name} + +Session: {session-id} +Created: {ISO timestamp} +For: {subagent-name} +Status: in_progress + +## Task Overview + +{Brief description of what we're building/doing} + +## User Request + +{Original user request - what they asked for} + +## Relevant Standards (Load These Before Starting) + +**Core Standards**: +- `.opencode/context/core/standards/code.md` → Modular, functional code patterns +- `.opencode/context/core/standards/tests.md` → Testing requirements and TDD +- `.opencode/context/core/standards/docs.md` → Documentation standards +- `.opencode/context/core/standards/patterns.md` → Error handling, security patterns + +**Core Workflows**: +- `.opencode/context/core/workflows/delegation.md` → Delegation process +- `.opencode/context/core/workflows/task-breakdown.md` → Task breakdown methodology +- `.opencode/context/core/workflows/review.md` → Code review guidelines + +## Repository-Specific Context (Load These Before Starting) + +**Quick Start** (ALWAYS load first): +- `.opencode/context/openagents-repo/quick-start.md` → Repo orientation and common commands + +**Core Concepts** (Load based on task type): +- `.opencode/context/openagents-repo/core-concepts/agents.md` → How agents work +- `.opencode/context/openagents-repo/core-concepts/evals.md` → How testing works +- `.opencode/context/openagents-repo/core-concepts/registry.md` → How registry works +- `.opencode/context/openagents-repo/core-concepts/categories.md` → How organization works + +**Guides** (Load for specific workflows): +- `.opencode/context/openagents-repo/guides/adding-agent.md` → Step-by-step agent creation +- `.opencode/context/openagents-repo/guides/testing-agent.md` → Testing workflow +- `.opencode/context/openagents-repo/guides/updating-registry.md` → Registry workflow +- `.opencode/context/openagents-repo/guides/debugging.md` → Troubleshooting + +**Lookup** (Quick reference): +- `.opencode/context/openagents-repo/lookup/file-locations.md` → Where everything is +- `.opencode/context/openagents-repo/lookup/commands.md` → Command reference + +## Key Requirements + +{Extract key requirements from loaded context} + +**From Standards**: +- {requirement 1 from standards/code.md} +- {requirement 2 from standards/tests.md} +- {requirement 3 from standards/docs.md} + +**From Repository Context**: +- {requirement 1 from repo context} +- {requirement 2 from repo context} +- {requirement 3 from repo context} + +**Naming Conventions**: +- {convention 1} +- {convention 2} + +**File Structure**: +- {structure requirement 1} +- {structure requirement 2} + +## Technical Constraints + +{List technical constraints and limitations} + +- {constraint 1 - e.g., "Must use TypeScript"} +- {constraint 2 - e.g., "Must follow category-based organization"} +- {constraint 3 - e.g., "Must include proper frontmatter metadata"} + +## Files to Create/Modify + +{List all files that need to be created or modified} + +**Create**: +- `{file-path-1}` - {purpose and what it should contain} +- `{file-path-2}` - {purpose and what it should contain} + +**Modify**: +- `{file-path-3}` - {what needs to be changed} +- `{file-path-4}` - {what needs to be changed} + +## Success Criteria + +{Define what "done" looks like - binary pass/fail conditions} + +- [ ] {criteria 1 - e.g., "Agent file created with proper frontmatter"} +- [ ] {criteria 2 - e.g., "Eval tests pass"} +- [ ] {criteria 3 - e.g., "Registry validation passes"} +- [ ] {criteria 4 - e.g., "Documentation updated"} + +## Validation Requirements + +{How to validate the work} + +**Scripts to Run**: +- `{validation-script-1}` - {what it validates} +- `{validation-script-2}` - {what it validates} + +**Tests to Run**: +- `{test-command-1}` - {what it tests} +- `{test-command-2}` - {what it tests} + +**Manual Checks**: +- {check 1} +- {check 2} + +## Expected Output + +{What the subagent should produce} + +**Deliverables**: +- {deliverable 1} +- {deliverable 2} + +**Format**: +- {format requirement 1} +- {format requirement 2} + +## Progress Tracking + +{Track progress through the task} + +- [ ] Context loaded and understood +- [ ] {step 1} +- [ ] {step 2} +- [ ] {step 3} +- [ ] Validation passed +- [ ] Documentation updated + +--- + +## Instructions for Subagent + +{Specific, detailed instructions for the subagent} + +**IMPORTANT**: +1. Load ALL context files listed in "Relevant Standards" and "Repository-Specific Context" sections BEFORE starting work +2. Follow ALL requirements from the loaded context +3. Apply naming conventions and file structure requirements +4. Validate your work using the validation requirements +5. Update progress tracking as you complete steps + +**Your Task**: +{Detailed description of what the subagent needs to do} + +**Approach**: +{Suggested approach or methodology} + +**Constraints**: +{Any additional constraints or notes} + +**Questions/Clarifications**: +{Any questions the subagent should consider or clarifications needed} +``` + +--- + +## Usage Instructions + +### When to Create a Context Bundle + +Create a context bundle when: +- Delegating to any subagent +- Task requires coordination across multiple components +- Subagent needs project-specific context +- Task has complex requirements or constraints + +### How to Create a Context Bundle + +1. **Create session directory**: + ```bash + mkdir -p .tmp/context/{session-id} + ``` + +2. **Copy template**: + ```bash + cp .opencode/context/openagents-repo/templates/context-bundle-template.md \ + .tmp/context/{session-id}/bundle.md + ``` + +3. **Fill in all sections**: + - Replace all `{placeholders}` with actual values + - List specific context files to load (with full paths) + - Extract key requirements from loaded context + - Define clear success criteria + - Provide specific instructions + +4. **Pass to subagent**: + ```javascript + task( + subagent_type="subagents/core/{subagent}", + description="Brief description", + prompt="Load context from .tmp/context/{session-id}/bundle.md before starting. + + {Specific task instructions} + + Follow all standards and requirements in the context bundle." + ) + ``` + +### Best Practices + +**DO**: +- ✅ List context files with full paths (don't duplicate content) +- ✅ Extract key requirements from loaded context +- ✅ Define binary success criteria (pass/fail) +- ✅ Provide specific validation requirements +- ✅ Include clear instructions for subagent +- ✅ Track progress through the task + +**DON'T**: +- ❌ Duplicate full context file content (just reference paths) +- ❌ Use vague success criteria ("make it good") +- ❌ Skip validation requirements +- ❌ Forget to list technical constraints +- ❌ Omit file paths for files to create/modify + +### Example Context Bundle + +See `.opencode/context/openagents-repo/examples/context-bundle-example.md` for a complete example. + +--- + +**Last Updated**: 2025-01-21 +**Version**: 1.0.0 diff --git a/.opencode/context/openagents-repo/templates/navigation.md b/.opencode/context/openagents-repo/templates/navigation.md new file mode 100644 index 0000000..147c3d0 --- /dev/null +++ b/.opencode/context/openagents-repo/templates/navigation.md @@ -0,0 +1,38 @@ +# OpenAgents Templates + +**Purpose**: Template files and patterns for OpenAgents Control + +--- + +## Structure + +``` +openagents-repo/templates/ +├── navigation.md (this file) +└── [template files] +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **View templates** | `./` | +| **Blueprints** | `../blueprints/navigation.md` | +| **Guides** | `../guides/navigation.md` | + +--- + +## By Type + +**Templates** → Reusable template files +**Patterns** → Common patterns and structures + +--- + +## Related Context + +- **OpenAgents Navigation** → `../navigation.md` +- **Blueprints** → `../blueprints/navigation.md` +- **Guides** → `../guides/navigation.md` diff --git a/.opencode/context/project-intelligence/business-domain.md b/.opencode/context/project-intelligence/business-domain.md new file mode 100644 index 0000000..710b5ea --- /dev/null +++ b/.opencode/context/project-intelligence/business-domain.md @@ -0,0 +1,88 @@ + + +# Business Domain + +> Document the business context, problems solved, and value created. + +## Quick Reference + +- **Purpose**: Understand why this project exists +- **Update When**: Business direction changes, new features shipped, pivot +- **Audience**: Developers needing context, stakeholders, product team + +## Project Identity + +``` +Project Name: [Name] +Tagline: [One-line description] +Problem Statement: [What problem are we solving?] +Solution: [How we're solving it] +``` + +## Target Users + +| User Segment | Who They Are | What They Need | Pain Points | +|--------------|--------------|----------------|-------------| +| [Primary] | [Description] | [Their needs] | [Their frustrations] | +| [Secondary] | [Description] | [Their needs] | [Their frustrations] | + +## Value Proposition + +**For Users**: +- [Key benefit 1] +- [Key benefit 2] +- [Key benefit 3] + +**For Business**: +- [Key value 1] +- [Key value 2] + +## Success Metrics + +| Metric | Definition | Target | Current | +|--------|------------|--------|---------| +| [Metric 1] | [What it measures] | [Goal] | [Actual] | +| [Metric 2] | [What it measures] | [Goal] | [Actual] | + +## Business Model (if applicable) + +``` +Revenue Model: [How the business makes money] +Pricing Strategy: [If applicable] +Unit Economics: [CAC, LTV, etc.] +Market Position: [Where we fit in the market] +``` + +## Key Stakeholders + +| Role | Name | Responsibility | Contact | +|------|------|----------------|---------| +| [Product Owner] | [Name] | [What they own] | [Contact] | +| [Tech Lead] | [Name] | [What they own] | [Contact] | +| [Business Lead] | [Name] | [What they own] | [Contact] | + +## Roadmap Context + +**Current Focus**: [What we're working on now] +**Next Milestone**: [Upcoming goal] +**Long-term Vision**: [Where this is heading] + +## Business Constraints + +- [Constraint 1] - [Why it exists] +- [Constraint 2] - [Why it exists] + +## Onboarding Checklist + +- [ ] Understand the problem statement +- [ ] Identify target users and their needs +- [ ] Know the key value proposition +- [ ] Understand success metrics +- [ ] Know who the stakeholders are +- [ ] Understand current business constraints + +## Related Files + +- `technical-domain.md` - How this business need is solved technically +- `business-tech-bridge.md` - Mapping between business and technical +- `decisions-log.md` - Business decisions with context diff --git a/.opencode/context/project-intelligence/business-tech-bridge.md b/.opencode/context/project-intelligence/business-tech-bridge.md new file mode 100644 index 0000000..aad0816 --- /dev/null +++ b/.opencode/context/project-intelligence/business-tech-bridge.md @@ -0,0 +1,94 @@ + + +# Business ↔ Tech Bridge + +> Document how business needs translate to technical solutions. This is the critical connection point. + +## Quick Reference + +- **Purpose**: Show stakeholders technical choices serve business goals +- **Purpose**: Show developers business constraints drive architecture +- **Update When**: New features, refactoring, business pivot + +## Core Mapping + +| Business Need | Technical Solution | Why This Mapping | Business Value | +|---------------|-------------------|------------------|----------------| +| [Users need X] | [Technical implementation] | [Why this maps] | [Value delivered] | +| [Business wants Y] | [Technical implementation] | [Why this maps] | [Value delivered] | +| [Compliance requires Z] | [Technical implementation] | [Why this maps] | [Value delivered] | + +## Feature Mapping Examples + +### Feature: [Feature Name] + +**Business Context**: +- User need: [What users need] +- Business goal: [Why this matters to business] +- Priority: [Why this was prioritized] + +**Technical Implementation**: +- Solution: [What was built] +- Architecture: [How it fits the system] +- Trade-offs: [What was considered and why it won] + +**Connection**: +[Explain clearly how the technical solution serves the business need. What would happen without this feature? What does this feature enable for the business?] + +### Feature: [Feature Name] + +**Business Context**: +- User need: [What users need] +- Business goal: [Why this matters to business] +- Priority: [Why this was prioritized] + +**Technical Implementation**: +- Solution: [What was built] +- Architecture: [How it fits the system] +- Trade-offs: [What was considered and why it won] + +**Connection**: +[Explain clearly how the technical solution serves the business need.] + +## Trade-off Decisions + +When business and technical needs conflict, document the trade-off: + +| Situation | Business Priority | Technical Priority | Decision Made | Rationale | +|-----------|-------------------|-------------------|---------------|-----------| +| [Conflict] | [What business wants] | [What tech wants] | [What was chosen] | [Why this was right] | + +## Common Misalignments + +| Misalignment | Warning Signs | Resolution Approach | +|--------------|---------------|---------------------| +| [Type of mismatch] | [Symptoms to watch for] | [How to address] | + +## Stakeholder Communication + +This file helps translate between worlds: + +**For Business Stakeholders**: +- Shows that technical investments serve business goals +- Provides context for why certain choices were made +- Demonstrates ROI of technical decisions + +**For Technical Stakeholders**: +- Provides business context for architectural decisions +- Shows the "why" behind constraints and requirements +- Helps prioritize technical debt with business impact + +## Onboarding Checklist + +- [ ] Understand the core business needs this project addresses +- [ ] See how each major feature maps to business value +- [ ] Know the key trade-offs and why decisions were made +- [ ] Be able to explain to stakeholders why technical choices matter +- [ ] Be able to explain to developers why business constraints exist + +## Related Files + +- `business-domain.md` - Business needs in detail +- `technical-domain.md` - Technical implementation in detail +- `decisions-log.md` - Decisions made with full context +- `living-notes.md` - Current open questions and issues diff --git a/.opencode/context/project-intelligence/decisions-log.md b/.opencode/context/project-intelligence/decisions-log.md new file mode 100644 index 0000000..b37f8f3 --- /dev/null +++ b/.opencode/context/project-intelligence/decisions-log.md @@ -0,0 +1,130 @@ + + +# Decisions Log + +> Record major architectural and business decisions with full context. This prevents "why was this done?" debates. + +## Quick Reference + +- **Purpose**: Document decisions so future team members understand context +- **Format**: Each decision as a separate entry +- **Status**: Decided | Pending | Under Review | Deprecated + +## Decision Template + +```markdown +## [Decision Title] + +**Date**: YYYY-MM-DD +**Status**: [Decided/Pending/Under Review/Deprecated] +**Owner**: [Who owns this decision] + +### Context +[What situation prompted this decision? What was the problem or opportunity?] + +### Decision +[What was decided? Be specific about the choice made.] + +### Rationale +[Why this decision? What were the alternatives and why were they rejected?] + +### Alternatives Considered +| Alternative | Pros | Cons | Why Rejected? | +|-------------|------|------|---------------| +| [Alt 1] | [Pros] | [Cons] | [Why not chosen] | +| [Alt 2] | [Pros] | [Cons] | [Why not chosen] | + +### Impact +**Positive**: [What this enables or improves] +**Negative**: [What trade-offs or limitations this creates] +**Risk**: [What could go wrong] + +### Related +- [Links to related decisions, PRs, issues, or documentation] +``` + +--- + +## Decision: [Title] + +**Date**: YYYY-MM-DD +**Status**: [Status] +**Owner**: [Owner] + +### Context +[What was happening? Why did we need to decide?] + +### Decision +[What we decided] + +### Rationale +[Why this was the right choice] + +### Alternatives Considered +| Alternative | Pros | Cons | Why Rejected? | +|-------------|------|------|---------------| +| [Option A] | [Good things] | [Bad things] | [Reason] | +| [Option B] | [Good things] | [Bad things] | [Reason] | + +### Impact +- **Positive**: [What we gain] +- **Negative**: [What we trade off] +- **Risk**: [What to watch for] + +### Related +- [Link to PR #000] +- [Link to issue #000] +- [Link to documentation] + +--- + +## Decision: [Title] + +**Date**: YYYY-MM-DD +**Status**: [Status] +**Owner**: [Owner] + +### Context +[What was happening?] + +### Decision +[What we decided] + +### Rationale +[Why this was right] + +### Alternatives Considered +| Alternative | Pros | Cons | Why Rejected? | +|-------------|------|------|---------------| +| [Option A] | [Good things] | [Bad things] | [Reason] | + +### Impact +- **Positive**: [What we gain] +- **Negative**: [What we trade off] + +### Related +- [Link] + +--- + +## Deprecated Decisions + +Decisions that were later overturned (for historical context): + +| Decision | Date | Replaced By | Why | +|----------|------|-------------|-----| +| [Old decision] | [Date] | [New decision] | [Reason] | + +## Onboarding Checklist + +- [ ] Understand the philosophy behind major architectural choices +- [ ] Know why certain technologies were chosen over alternatives +- [ ] Understand trade-offs that were made +- [ ] Know where to find decision context when questions arise +- [ ] Understand what decisions are pending and why + +## Related Files + +- `technical-domain.md` - Technical implementation affected by these decisions +- `business-tech-bridge.md` - How decisions connect business and technical +- `living-notes.md` - Current open questions that may become decisions diff --git a/.opencode/context/project-intelligence/living-notes.md b/.opencode/context/project-intelligence/living-notes.md new file mode 100644 index 0000000..1ab9e49 --- /dev/null +++ b/.opencode/context/project-intelligence/living-notes.md @@ -0,0 +1,114 @@ + + +# Living Notes + +> Active issues, technical debt, open questions, and insights that don't fit elsewhere. Keep this alive. + +## Quick Reference + +- **Purpose**: Capture current state, problems, and open questions +- **Update**: Weekly or when status changes +- **Archive**: Move resolved items to bottom with status + +## Technical Debt + +| Item | Impact | Priority | Mitigation | +|------|--------|----------|------------| +| [Debt item] | [What risk it creates] | [High/Med/Low] | [How to manage] | + +### Technical Debt Details + +**[Debt Item]** +*Priority*: [High/Med/Low] +*Impact*: [What happens if not addressed] +*Root Cause*: [Why this debt exists] +*Proposed Solution*: [How to fix it] +*Effort*: [Small/Medium/Large] +*Status*: [Acknowledged | Scheduled | In Progress | Deferred] + +## Open Questions + +| Question | Stakeholders | Status | Next Action | +|----------|--------------|--------|-------------| +| [Question] | [Who needs to decide] | [Open/In Progress] | [What needs to happen] | + +### Open Question Details + +**[Question]** +*Context*: [Why this question matters] +*Stakeholders*: [Who needs to be involved] +*Options*: [What are the possibilities] +*Timeline*: [When does this need resolution] +*Status*: [Open/In Progress/Blocked] + +## Known Issues + +| Issue | Severity | Workaround | Status | +|-------|----------|------------|--------| +| [Issue] | [Critical/High/Med/Low] | [Temporary fix] | [Known/In Progress/Fixed] | + +### Issue Details + +**[Issue Title]** +*Severity*: [Critical/High/Med/Low] +*Impact*: [Who/what is affected] +*Reproduction*: [Steps to reproduce if applicable] +*Workaround*: [Temporary solution if exists] +*Root Cause*: [If known] +*Fix Plan*: [How to properly fix] +*Status*: [Known/In Progress/Fixed in vX.X] + +## Insights & Lessons Learned + +### What Works Well +- [Positive pattern 1] - [Why it works] +- [Positive pattern 2] - [Why it works] + +### What Could Be Better +- [Area for improvement 1] - [Why it's a problem] +- [Area for improvement 2] - [Why it's a problem] + +### Lessons Learned +- [Lesson 1] - [Context and implication] +- [Lesson 2] - [Context and implication] + +## Patterns & Conventions + +### Code Patterns Worth Preserving +- [Pattern 1] - [Where it lives, why it's good] +- [Pattern 2] - [Where it lives, why it's good] + +### Gotchas for Maintainers +- [Gotcha 1] - [What to watch out for] +- [Gotcha 2] - [What to watch out for] + +## Active Projects + +| Project | Goal | Owner | Timeline | +|---------|------|-------|----------| +| [Project] | [What we're doing] | [Who owns it] | [When it matters] | + +## Archive (Resolved Items) + +Moved here for historical reference. Current team should refer to current notes above. + +### Resolved: [Item] +- **Resolved**: [Date] +- **Resolution**: [What was decided/done] +- **Learnings**: [What we learned from this] + +## Onboarding Checklist + +- [ ] Review known technical debt and understand impact +- [ ] Know what open questions exist and who's involved +- [ ] Understand current issues and workarounds +- [ ] Be aware of patterns and gotchas +- [ ] Know active projects and timelines +- [ ] Understand the team's priorities + +## Related Files + +- `decisions-log.md` - Past decisions that inform current state +- `business-domain.md` - Business context for current priorities +- `technical-domain.md` - Technical context for current state +- `business-tech-bridge.md` - Context for current trade-offs diff --git a/.opencode/context/project-intelligence/navigation.md b/.opencode/context/project-intelligence/navigation.md new file mode 100644 index 0000000..d85b05e --- /dev/null +++ b/.opencode/context/project-intelligence/navigation.md @@ -0,0 +1,65 @@ + + +# Project Intelligence + +> Start here for quick project understanding. These files bridge business and technical domains. + +## Structure + +``` +.opencode/context/project-intelligence/ +├── navigation.md # This file - quick overview +├── business-domain.md # Business context and problem statement +├── technical-domain.md # Stack, architecture, technical decisions +├── business-tech-bridge.md # How business needs map to solutions +├── decisions-log.md # Major decisions with rationale +└── living-notes.md # Active issues, debt, open questions +``` + +## Quick Routes + +| What You Need | File | Description | +|---------------|------|-------------| +| Understand the "why" | `business-domain.md` | Problem, users, value proposition | +| Understand the "how" | `technical-domain.md` | Stack, architecture, integrations | +| See the connection | `business-tech-bridge.md` | Business → technical mapping | +| Know the context | `decisions-log.md` | Why decisions were made | +| Current state | `living-notes.md` | Active issues and open questions | +| All of the above | Read all files in order | Full project intelligence | + +## Usage + +**New Team Member / Agent**: +1. Start with `navigation.md` (this file) +2. Read all files in order for complete understanding +3. Follow onboarding checklist in each file + +**Quick Reference**: +- Business focus → `business-domain.md` +- Technical focus → `technical-domain.md` +- Decision context → `decisions-log.md` + +## Integration + +This folder is referenced from: +- `.opencode/context/core/standards/project-intelligence.md` (standards and patterns) +- `.opencode/context/core/system/context-guide.md` (context loading) + +See `.opencode/context/core/context-system.md` for the broader context architecture. + +## Maintenance + +Keep this folder current: +- Update when business direction changes +- Document decisions as they're made +- Review `living-notes.md` regularly +- Archive resolved items from decisions-log.md + +**Management Guide**: See `.opencode/context/core/standards/project-intelligence-management.md` for complete lifecycle management including: +- How to update, add, and remove files +- How to create new subfolders +- Version tracking and frontmatter standards +- Quality checklists and anti-patterns +- Governance and ownership + +See `.opencode/context/core/standards/project-intelligence.md` for the standard itself. diff --git a/.opencode/context/project-intelligence/technical-domain.md b/.opencode/context/project-intelligence/technical-domain.md new file mode 100644 index 0000000..38e08b4 --- /dev/null +++ b/.opencode/context/project-intelligence/technical-domain.md @@ -0,0 +1,108 @@ + + +# Technical Domain + +> Document the technical foundation, architecture, and key decisions. + +## Quick Reference + +- **Purpose**: Understand how the project works technically +- **Update When**: New features, refactoring, tech stack changes +- **Audience**: Developers, DevOps, technical stakeholders + +## Primary Stack + +| Layer | Technology | Version | Rationale | +|-------|-----------|---------|-----------| +| Language | [e.g., TypeScript] | [Version] | [Why this language] | +| Framework | [e.g., Node.js] | [Version] | [Why this framework] | +| Database | [e.g., PostgreSQL] | [Version] | [Why this database] | +| Infrastructure | [e.g., AWS, Vercel] | [N/A] | [Why this infra] | +| Key Libraries | [List important ones] | [Versions] | [Why each matters] | + +## Architecture Pattern + +``` +Type: [Monolith | Microservices | Serverless | Agent-based | Hybrid] +Pattern: [Brief description] +Diagram: [Link to architecture diagram if exists] +``` + +### Why This Architecture? + +[Explain the business and technical reasons for this architecture choice. What problem does this architecture solve? What were alternatives considered?] + +## Project Structure + +``` +[Project Root] +├── src/ # Source code +├── tests/ # Test files +├── docs/ # Documentation +├── scripts/ # Build/deploy scripts +└── [Other key directories] +``` + +**Key Directories**: +- `src/` - Contains all application logic organized by [module/feature/domain] +- `tests/` - [How tests are organized] +- `docs/` - [What documentation lives here] + +## Key Technical Decisions + +| Decision | Rationale | Impact | +|----------|-----------|--------| +| [Decision 1] | [Why this choice] | [What it enables] | +| [Decision 2] | [Why this choice] | [What it enables] | + +See `decisions-log.md` for full decision history with alternatives. + +## Integration Points + +| System | Purpose | Protocol | Direction | +|--------|---------|----------|-----------| +| [API 1] | [What it does] | [REST/GraphQL/gRPC] | [Inbound/Outbound] | +| [Database] | [What it stores] | [PostgreSQL/Mongo/etc] | [Internal] | +| [Service] | [What it provides] | [HTTP/gRPC] | [Outbound] | + +## Technical Constraints + +| Constraint | Origin | Impact | +|------------|--------|--------| +| [Legacy systems] | [Business/Tech] | [What limitation it creates] | +| [Compliance] | [Regulation] | [What must be followed] | +| [Performance] | [SLAs] | [What must be met] | + +## Development Environment + +``` +Setup: [Quick setup command or link] +Requirements: [What developers need installed] +Local Dev: [How to run locally] +Testing: [How to run tests] +``` + +## Deployment + +``` +Environment: [Production/Staging/Development] +Platform: [Where it deploys] +CI/CD: [Pipeline used] +Monitoring: [Tools for observability] +``` + +## Onboarding Checklist + +- [ ] Know the primary tech stack +- [ ] Understand the architecture pattern and why it was chosen +- [ ] Know the key project directories and their purpose +- [ ] Understand major technical decisions and rationale +- [ ] Know integration points and dependencies +- [ ] Be able to set up local development environment +- [ ] Know how to run tests and deploy + +## Related Files + +- `business-domain.md` - Why this technical foundation exists +- `business-tech-bridge.md` - How business needs map to technical solutions +- `decisions-log.md` - Full decision history with context diff --git a/.opencode/context/project/project-context.md b/.opencode/context/project/project-context.md new file mode 100644 index 0000000..2b55719 --- /dev/null +++ b/.opencode/context/project/project-context.md @@ -0,0 +1,102 @@ + + + +# ⚠️ DEPRECATED: OpenCode Agent System Project Context + +> ⛔ This file is deprecated. See `project-intelligence/technical-domain.md` for the current technical domain documentation. + +## Technology Stack + +**Primary Language:** TypeScript +**Runtime:** Node.js/Bun +**Package Manager:** npm/pnpm/yarn +**Build Tools:** TypeScript Compiler (tsc) +**Testing:** Jest/Vitest (if configured) +**Linting:** ESLint (if configured) + +## Project Structure + +``` +.opencode/ +├── agent/ # AI agents for specific tasks +│ ├── subagents/ # Specialized subagents +│ └── *.md # Primary agents +├── command/ # Slash commands +├── context/ # Knowledge base for agents +└── plugin/ # Extensions and integrations + +tasks/ # Task management files +``` + +## Core Patterns + +### Agent Structure Pattern +```markdown +--- +description: "What this agent does" +mode: primary|subagent +tools: [read, edit, bash, etc.] +permissions: [security restrictions] +--- + +# Agent Name + +[Direct instructions for behavior] + +**EXECUTE** this [process type] for every [task type]: + +**1. [ACTION]** the [subject]: +- [Specific instruction 1] +- [Specific instruction 2] + +**RULES:** +- **ALWAYS** [critical requirement] +- **NEVER** [forbidden action] +``` + +### Command Structure Pattern +```markdown +--- +name: command-name +agent: target-agent +--- + +You are [doing specific task]. + +**Request:** $ARGUMENTS + +**Context Loaded:** +@.opencode/context/core/essential-patterns.md +@[additional context files] + +Execute [task] now. +``` + +### Context Loading Rules +- Commands load context immediately using @ references +- Agents can look up additional context deterministically +- Maximum 4 context files per command (250-450 lines total) +- Keep context files focused (50-150 lines each) + +## Security Guidelines + +- Agents have restricted permissions by default +- Sensitive operations require explicit approval +- No direct file system modifications without validation +- Build commands limited to safe operations + +## Development Workflow + +1. **Planning:** Create detailed task plans for complex work +2. **Implementation:** Execute one step at a time with validation +3. **Review:** Code review and security checks +4. **Testing:** Automated testing and build validation +5. **Documentation:** Update docs and context files + +## Quality Gates + +- TypeScript compilation passes +- Code review completed +- Build process succeeds +- Tests pass (if available) +- Documentation updated \ No newline at end of file diff --git a/.opencode/context/ui/navigation.md b/.opencode/context/ui/navigation.md new file mode 100644 index 0000000..bb1021b --- /dev/null +++ b/.opencode/context/ui/navigation.md @@ -0,0 +1,80 @@ +# UI Context + +**Purpose**: User interface design patterns, standards, and best practices across all platforms + +**Last Updated**: 2026-01-07 + +--- + +## Overview + +This category contains UI/UX patterns, design systems, and interface standards for building user-facing applications across different platforms. + +--- + +## Directory Structure + +### 📁 Subcategories + +| Subcategory | Description | Path | +|-------------|-------------|------| +| **web/** | Web UI patterns, animations, styling, React components | [web/navigation.md](web/navigation.md) | +| **terminal/** | Terminal UI (TUI) patterns for CLI applications | [terminal/navigation.md](terminal/navigation.md) | + +### Future Subcategories + +- **mobile/** - React Native, Flutter patterns (planned) +- **desktop/** - Electron, Tauri patterns (planned) + +--- + +## Quick Navigation + +### Web UI +- Animation patterns and micro-interactions +- CSS styling standards and design systems +- React component patterns +- Design assets and resources +- Scroll-linked animations (scrollytelling) + +### Terminal UI +- CLI/TUI patterns (planned) +- Ink, Blessed component patterns (planned) +- Terminal animations and progress indicators (planned) + +--- + +## Usage + +**Web development**: Navigate to `web/` for browser-based UI patterns + +**CLI/TUI development**: Navigate to `terminal/` for terminal interface patterns + +**Cross-platform**: Consider patterns from multiple subcategories + +--- + +## Scope + +This category covers: +- ✅ Visual design patterns +- ✅ Animation and transitions +- ✅ Component architecture +- ✅ Styling standards +- ✅ Design systems +- ✅ Accessibility patterns +- ⏳ Platform-specific patterns (mobile, desktop) + +--- + +## Related Categories + +- `development/` - General development patterns (backend, APIs, clean code) +- `product/` - Product design and UX strategy +- `content/` - Content design and copywriting + +--- + +## Used By + +**Agents**: frontend-specialist, design-specialist, ui-developer, animation-expert diff --git a/.opencode/context/ui/terminal/navigation.md b/.opencode/context/ui/terminal/navigation.md new file mode 100644 index 0000000..02ec799 --- /dev/null +++ b/.opencode/context/ui/terminal/navigation.md @@ -0,0 +1,93 @@ +# Terminal UI Context + +**Purpose**: Terminal UI (TUI) patterns, CLI animations, and command-line interface design + +**Last Updated**: 2026-01-07 + +--- + +## Overview + +This subcategory will contain patterns and best practices for building terminal user interfaces using libraries like Ink, Blessed, and native terminal capabilities. + +--- + +## Planned Content + +### Core Files (Future) + +| File | Description | Priority | +|------|-------------|----------| +| `tui-patterns.md` | Terminal UI component patterns and layouts | high | +| `cli-animations.md` | Terminal animations, spinners, progress bars | high | +| `ink-components.md` | React Ink component patterns | medium | +| `blessed-patterns.md` | Blessed.js patterns and widgets | medium | +| `terminal-styling.md` | ANSI colors, chalk, terminal theming | medium | + +### Planned Topics + +- **Layout patterns**: Boxes, borders, flexbox-like layouts +- **Interactive components**: Menus, forms, selects, inputs +- **Progress indicators**: Spinners, progress bars, loading states +- **Terminal animations**: Frame-based animations, smooth transitions +- **Color and styling**: ANSI escape codes, chalk, gradient text +- **Keyboard handling**: Key bindings, shortcuts, navigation +- **Terminal detection**: Capability detection, fallbacks + +--- + +## Example Libraries + +### React-based TUI +- **Ink** - React for CLIs +- **Pastel** - React-like TUI framework + +### Traditional TUI +- **Blessed** - High-level terminal interface library +- **Blessed-contrib** - Widgets for blessed (charts, gauges) +- **Terminal-kit** - Comprehensive terminal manipulation + +### Styling +- **Chalk** - Terminal string styling +- **Gradient-string** - Gradient colors in terminal +- **Boxen** - Create boxes in terminal + +### Progress/Animation +- **Ora** - Elegant terminal spinners +- **CLI-progress** - Progress bars +- **Listr** - Terminal task lists + +--- + +## Usage + +**When this subcategory is populated**, use it for: +- Building CLI tools with rich interfaces +- Creating terminal-based dashboards +- Implementing interactive command-line applications +- Adding animations and progress indicators to CLI tools + +--- + +## Related Categories + +- `ui/web/` - Web UI patterns +- `development/` - General development patterns + +--- + +## Status + +⏳ **Placeholder** - This subcategory is planned but not yet populated. + +To contribute content here, follow the MVI principles: +1. Extract core concepts (1-3 sentences) +2. List key points (3-5 bullets) +3. Provide minimal example +4. Link to full documentation + +--- + +## Used By + +**Agents**: cli-developer, terminal-specialist, devops-specialist (future) diff --git a/.opencode/context/ui/web/animation-advanced.md b/.opencode/context/ui/web/animation-advanced.md new file mode 100644 index 0000000..7439244 --- /dev/null +++ b/.opencode/context/ui/web/animation-advanced.md @@ -0,0 +1,200 @@ + +# Advanced Animation Patterns + +Recipes, best practices, micro-interactions, and accessibility considerations. + +--- + +## Page Transitions + +### Route Changes + +```css +/* Page fade out */ +.page-exit { + animation: fadeOut 200ms ease-in; +} +@keyframes fadeOut { + from { opacity: 1; } + to { opacity: 0; } +} + +/* Page fade in */ +.page-enter { + animation: fadeIn 300ms ease-out; +} +@keyframes fadeIn { + from { opacity: 0; } + to { opacity: 1; } +} +``` + +**Micro-syntax**: +``` +pageExit: 200ms ease-in [α1→0] +pageEnter: 300ms ease-out [α0→1] +``` + +--- + +## Micro-Interactions + +### Hover Effects + +```css +/* Link underline slide */ +.link { + position: relative; +} +.link::after { + content: ''; + position: absolute; + bottom: 0; + left: 0; + width: 0; + height: 2px; + background: currentColor; + transition: width 250ms ease-out; +} +.link:hover::after { + width: 100%; +} +``` + +**Micro-syntax**: +``` +linkHover: 250ms ease-out [width0→100%] +``` + +### Toggle Switches + +```css +/* Toggle slide */ +.toggle-switch { + transition: background-color 200ms ease-out; +} +.toggle-switch .thumb { + transition: transform 200ms ease-out; +} +.toggle-switch.on .thumb { + transform: translateX(20px); +} +``` + +**Micro-syntax**: +``` +toggle: 200ms ease-out [X0→20, bg→accent] +``` + +--- + +## Animation Recipes + +### Chat UI Complete Animation System + +``` +## Core Message Flow +userMsg: 400ms ease-out [Y+20→0, X+10→0, S0.9→1] +aiMsg: 600ms bounce [Y+15→0, S0.95→1] +200ms +typing: 1400ms ∞ [Y±8, α0.4→1] stagger+200ms +status: 300ms ease-out [α0.6→1, S1→1.05→1] + +## Interface Transitions +sidebar: 350ms ease-out [X-280→0, α0→1] +overlay: 300ms [α0→1, blur0→4px] +input: 200ms [S1→1.01, shadow+ring] focus +input: 150ms [S1.01→1, shadow-ring] blur + +## Button Interactions +sendBtn: 150ms [S1→0.95→1, R±2°] press +sendBtn: 200ms [S1→1.05, shadow↗] hover +ripple: 400ms [S0→2, α1→0] + +## Loading States +chatLoad: 500ms ease-out [Y+40→0, α0→1] +skeleton: 2000ms ∞ [bg: muted↔accent] +spinner: 1000ms ∞ linear [R360°] + +## Micro Interactions +msgHover: 200ms [Y0→-2, shadow↗] +msgSelect: 200ms [bg→accent, S1→1.02] +error: 400ms [X±5] shake +success: 600ms bounce [S0→1.2→1, R360°] + +## Scroll & Navigation +autoScroll: 400ms smooth +scrollHint: 800ms ∞×3 [Y±5] +``` + +--- + +## Best Practices + +### Do's ✅ + +- Keep animations under 400ms for most interactions +- Use `transform` and `opacity` for 60fps performance +- Provide purpose for every animation +- Use ease-out for entrances, ease-in for exits +- Test on low-end devices +- Respect `prefers-reduced-motion` +- Stagger animations for lists (50-100ms delay) +- Use consistent timing across similar interactions + +### Don'ts ❌ + +- Don't animate width/height (use scale instead) +- Don't use animations longer than 800ms +- Don't animate too many elements at once +- Don't use animations without purpose +- Don't ignore accessibility preferences +- Don't use jarring/distracting animations +- Don't animate on every interaction +- Don't use complex easing for simple interactions + +--- + +## Accessibility + +### Reduced Motion + +```css +/* Respect user preferences */ +@media (prefers-reduced-motion: reduce) { + *, + *::before, + *::after { + animation-duration: 0.01ms !important; + animation-iteration-count: 1 !important; + transition-duration: 0.01ms !important; + } +} +``` + +### Focus Indicators + +```css +/* Always animate focus states */ +:focus-visible { + outline: 2px solid var(--ring); + outline-offset: 2px; + transition: outline-offset 150ms ease-out; +} +``` + +--- + +## References + +- [Web Animation API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API) +- [CSS Easing Functions](https://easings.net/) +- [Animation Performance](https://web.dev/animations-guide/) +- [Reduced Motion](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion) + +--- + +## Related Files + +- [Animation Basics](./animation-basics.md) - Fundamentals +- [UI Animations](./animation-ui.md) - Common UI patterns +- [Loading Animations](./animation-loading.md) - Loading states diff --git a/.opencode/context/ui/web/animation-basics.md b/.opencode/context/ui/web/animation-basics.md new file mode 100644 index 0000000..f1472cc --- /dev/null +++ b/.opencode/context/ui/web/animation-basics.md @@ -0,0 +1,94 @@ + +# Animation Basics + +## Overview + +Standards and patterns for UI animations, micro-interactions, and transitions. Animations should feel natural, purposeful, and enhance user experience without causing distraction. + +## Quick Reference + +**Timing**: 150-400ms for most interactions +**Easing**: ease-out for entrances, ease-in for exits +**Purpose**: Every animation should have a clear purpose +**Performance**: Use transform and opacity for 60fps + +--- + +## Animation Micro-Syntax + +### Notation Guide + +**Format**: `element: duration easing [properties] modifiers` + +**Symbols**: +- `→` = transition from → to +- `±` = oscillate/shake +- `↗` = increase +- `↘` = decrease +- `∞` = infinite loop +- `×N` = repeat N times +- `+Nms` = delay N milliseconds + +**Properties**: +- `Y` = translateY +- `X` = translateX +- `S` = scale +- `R` = rotate +- `α` = opacity +- `bg` = background + +**Example**: `button: 200ms ease-out [S1→1.05, α0.8→1]` +- Button scales from 1 to 1.05 and fades from 0.8 to 1 over 200ms with ease-out + +--- + +## Core Animation Principles + +### Timing Standards + +``` +Ultra-fast: 100-150ms (micro-feedback, hover states) +Fast: 150-250ms (button clicks, toggles) +Standard: 250-350ms (modals, dropdowns, navigation) +Moderate: 350-500ms (page transitions, complex animations) +Slow: 500-800ms (dramatic reveals, storytelling) +``` + +### Easing Functions + +```css +/* Entrances - start slow, end fast */ +ease-out: cubic-bezier(0, 0, 0.2, 1); + +/* Exits - start fast, end slow */ +ease-in: cubic-bezier(0.4, 0, 1, 1); + +/* Both - smooth throughout */ +ease-in-out: cubic-bezier(0.4, 0, 0.2, 1); + +/* Bounce - playful, attention-grabbing */ +bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55); + +/* Elastic - spring-like */ +elastic: cubic-bezier(0.68, -0.6, 0.32, 1.6); +``` + +### Performance Guidelines + +**60fps Animations** (GPU-accelerated): +- ✅ `transform` (translate, scale, rotate) +- ✅ `opacity` +- ✅ `filter` (with caution) + +**Avoid** (causes reflow/repaint): +- ❌ `width`, `height` +- ❌ `top`, `left`, `right`, `bottom` +- ❌ `margin`, `padding` + +--- + +## Related Files + +- [UI Animations](./animation-ui.md) - Common UI patterns +- [Loading Animations](./animation-loading.md) - Loading states +- [Advanced Animations](./animation-advanced.md) - Recipes & best practices diff --git a/.opencode/context/ui/web/animation-chat.md b/.opencode/context/ui/web/animation-chat.md new file mode 100644 index 0000000..8f21e9e --- /dev/null +++ b/.opencode/context/ui/web/animation-chat.md @@ -0,0 +1,113 @@ + +# Chat UI Animation Patterns + +Animation patterns for message entrances, typing indicators, and chat interactions. + +--- + +## Message Entrance + +```css +/* User message - slide from right */ +.message-user { + animation: slideInRight 400ms ease-out; +} +@keyframes slideInRight { + from { + transform: translateX(10px) translateY(20px); + opacity: 0; + scale: 0.9; + } + to { + transform: translateX(0) translateY(0); + opacity: 1; + scale: 1; + } +} + +/* AI message - slide from left with bounce */ +.message-ai { + animation: slideInLeft 600ms cubic-bezier(0.68, -0.55, 0.265, 1.55); + animation-delay: 200ms; +} +@keyframes slideInLeft { + from { + transform: translateY(15px); + opacity: 0; + scale: 0.95; + } + to { + transform: translateY(0); + opacity: 1; + scale: 1; + } +} +``` + +**Micro-syntax**: +``` +userMsg: 400ms ease-out [Y+20→0, X+10→0, S0.9→1] +aiMsg: 600ms bounce [Y+15→0, S0.95→1] +200ms +``` + +--- + +## Typing Indicator + +```css +.typing-indicator span { + animation: typingDot 1400ms infinite; +} +.typing-indicator span:nth-child(2) { animation-delay: 200ms; } +.typing-indicator span:nth-child(3) { animation-delay: 400ms; } + +@keyframes typingDot { + 0%, 60%, 100% { + transform: translateY(0); + opacity: 0.4; + } + 30% { + transform: translateY(-8px); + opacity: 1; + } +} +``` + +**Micro-syntax**: +``` +typing: 1400ms ∞ [Y±8, α0.4→1] stagger+200ms +``` + +--- + +## Chat Message Micro-Interactions + +```css +/* Message hover */ +.message:hover { + transform: translateY(-2px); + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); + transition: all 200ms ease-out; +} + +/* Message selection */ +.message.selected { + background-color: var(--accent); + transform: scale(1.02); + transition: all 200ms ease-out; +} +``` + +**Micro-syntax**: +``` +msgHover: 200ms [Y0→-2, shadow↗] +msgSelect: 200ms [bg→accent, S1→1.02] +``` + +--- + +## Related Files + +- [Animation Basics](./animation-basics.md) - Fundamentals +- [Component Animations](./animation-components.md) - UI components +- [Loading Animations](./animation-loading.md) - Loading states diff --git a/.opencode/context/ui/web/animation-components.md b/.opencode/context/ui/web/animation-components.md new file mode 100644 index 0000000..9c27f38 --- /dev/null +++ b/.opencode/context/ui/web/animation-components.md @@ -0,0 +1,137 @@ + +# Component Animation Patterns + +Animation patterns for buttons, cards, modals, dropdowns, and sidebars. + +--- + +## Button Interactions + +```css +.button { + transition: transform 200ms ease-out, box-shadow 200ms ease-out; +} +.button:hover { + transform: translateY(-2px); + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); +} +.button:active { + transform: scale(0.95); + transition: transform 100ms ease-in; +} + +@keyframes ripple { + from { transform: scale(0); opacity: 1; } + to { transform: scale(2); opacity: 0; } +} +.button::after { animation: ripple 400ms ease-out; } +``` + +**Micro-syntax**: +``` +buttonHover: 200ms ease-out [Y0→-2, shadow↗] +buttonPress: 100ms ease-in [S1→0.95] +ripple: 400ms ease-out [S0→2, α1→0] +``` + +--- + +## Card Interactions + +```css +.card { + transition: transform 300ms ease-out, box-shadow 300ms ease-out; +} +.card:hover { + transform: translateY(-4px); + box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15); +} +.card.selected { + transform: scale(1.02); + background-color: var(--accent); + transition: all 200ms ease-out; +} +``` + +**Micro-syntax**: +``` +cardHover: 300ms ease-out [Y0→-4, shadow↗] +cardSelect: 200ms ease-out [S1→1.02, bg→accent] +``` + +--- + +## Modal/Dialog Animations + +```css +.modal-backdrop { animation: fadeIn 300ms ease-out; } +@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } + +.modal { animation: slideUp 350ms ease-out; } +@keyframes slideUp { + from { transform: translateY(40px); opacity: 0; } + to { transform: translateY(0); opacity: 1; } +} + +.modal.closing { animation: slideDown 250ms ease-in; } +@keyframes slideDown { + from { transform: translateY(0); opacity: 1; } + to { transform: translateY(40px); opacity: 0; } +} +``` + +**Micro-syntax**: +``` +backdrop: 300ms ease-out [α0→1] +modalEnter: 350ms ease-out [Y+40→0, α0→1] +modalExit: 250ms ease-in [Y0→+40, α1→0] +``` + +--- + +## Dropdown/Menu Animations + +```css +.dropdown { + animation: dropdownOpen 200ms ease-out; + transform-origin: top; +} +@keyframes dropdownOpen { + from { transform: scaleY(0.95); opacity: 0; } + to { transform: scaleY(1); opacity: 1; } +} +``` + +**Micro-syntax**: `dropdown: 200ms ease-out [scaleY0.95→1, α0→1]` + +--- + +## Sidebar/Drawer Animations + +```css +.sidebar { animation: slideInLeft 350ms ease-out; } +@keyframes slideInLeft { + from { transform: translateX(-280px); opacity: 0; } + to { transform: translateX(0); opacity: 1; } +} + +.overlay { animation: overlayFade 300ms ease-out; } +@keyframes overlayFade { + from { opacity: 0; backdrop-filter: blur(0); } + to { opacity: 1; backdrop-filter: blur(4px); } +} +``` + +**Micro-syntax**: +``` +sidebar: 350ms ease-out [X-280→0, α0→1] +overlay: 300ms ease-out [α0→1, blur0→4px] +``` + +--- + +## Related Files + +- [Animation Basics](./animation-basics.md) - Fundamentals +- [Chat Animations](./animation-chat.md) - Message patterns +- [Loading Animations](./animation-loading.md) - Loading states diff --git a/.opencode/context/ui/web/animation-forms.md b/.opencode/context/ui/web/animation-forms.md new file mode 100644 index 0000000..e9283b8 --- /dev/null +++ b/.opencode/context/ui/web/animation-forms.md @@ -0,0 +1,121 @@ + +# Form Animation Patterns + +Animation patterns for form inputs, validation states, and scroll animations. + +--- + +## Focus States + +```css +/* Input focus - ring and scale */ +.input { + transition: all 200ms ease-out; +} +.input:focus { + transform: scale(1.01); + box-shadow: 0 0 0 3px var(--ring); +} + +/* Input blur - return to normal */ +.input:not(:focus) { + transition: all 150ms ease-in; +} +``` + +**Micro-syntax**: +``` +inputFocus: 200ms ease-out [S1→1.01, shadow+ring] +inputBlur: 150ms ease-in [S1.01→1, shadow-ring] +``` + +--- + +## Validation States + +```css +/* Error shake */ +.input-error { + animation: shake 400ms ease-in-out; +} +@keyframes shake { + 0%, 100% { transform: translateX(0); } + 25% { transform: translateX(-5px); } + 75% { transform: translateX(5px); } +} + +/* Success checkmark */ +.input-success::after { + animation: checkmark 600ms cubic-bezier(0.68, -0.55, 0.265, 1.55); +} +@keyframes checkmark { + from { + transform: scale(0) rotate(0deg); + opacity: 0; + } + to { + transform: scale(1.2) rotate(360deg); + opacity: 1; + } +} +``` + +**Micro-syntax**: +``` +error: 400ms ease-in-out [X±5] shake +success: 600ms bounce [S0→1.2, R0→360°, α0→1] +``` + +--- + +## Scroll Animations + +### Scroll-Triggered Fade In + +```css +.fade-in-on-scroll { + opacity: 0; + transform: translateY(40px); + transition: opacity 500ms ease-out, transform 500ms ease-out; +} +.fade-in-on-scroll.visible { + opacity: 1; + transform: translateY(0); +} +``` + +**Micro-syntax**: +``` +scrollFadeIn: 500ms ease-out [Y+40→0, α0→1] +``` + +### Auto-Scroll + +```css +html { + scroll-behavior: smooth; +} + +.scroll-hint { + animation: scrollHint 800ms infinite; + animation-iteration-count: 3; +} +@keyframes scrollHint { + 0%, 100% { transform: translateY(0); } + 50% { transform: translateY(5px); } +} +``` + +**Micro-syntax**: +``` +autoScroll: 400ms smooth +scrollHint: 800ms ∞×3 [Y±5] +``` + +--- + +## Related Files + +- [Animation Basics](./animation-basics.md) - Fundamentals +- [UI Animations](./animation-ui.md) - Common UI patterns +- [Loading Animations](./animation-loading.md) - Loading states diff --git a/.opencode/context/ui/web/animation-loading.md b/.opencode/context/ui/web/animation-loading.md new file mode 100644 index 0000000..3eee033 --- /dev/null +++ b/.opencode/context/ui/web/animation-loading.md @@ -0,0 +1,118 @@ + +# Loading State Animations + +Animation patterns for skeleton screens, spinners, progress bars, and status indicators. + +--- + +## Skeleton Screens + +```css +/* Skeleton shimmer */ +.skeleton { + animation: shimmer 2000ms infinite; + background: linear-gradient( + 90deg, + var(--muted) 0%, + var(--accent) 50%, + var(--muted) 100% + ); + background-size: 200% 100%; +} +@keyframes shimmer { + 0% { background-position: 200% 0; } + 100% { background-position: -200% 0; } +} +``` + +**Micro-syntax**: +``` +skeleton: 2000ms ∞ [bg: muted↔accent] +``` + +--- + +## Spinners + +```css +/* Circular spinner */ +.spinner { + animation: spin 1000ms linear infinite; +} +@keyframes spin { + from { transform: rotate(0deg); } + to { transform: rotate(360deg); } +} + +/* Pulsing dots */ +.loading-dots span { + animation: dotPulse 1500ms infinite; +} +.loading-dots span:nth-child(2) { animation-delay: 200ms; } +.loading-dots span:nth-child(3) { animation-delay: 400ms; } +@keyframes dotPulse { + 0%, 80%, 100% { opacity: 0.3; scale: 0.8; } + 40% { opacity: 1; scale: 1; } +} +``` + +**Micro-syntax**: +``` +spinner: 1000ms ∞ linear [R360°] +dotPulse: 1500ms ∞ [α0.3→1→0.3, S0.8→1→0.8] stagger+200ms +``` + +--- + +## Progress Bars + +```css +/* Indeterminate progress */ +.progress-bar { + animation: progress 2000ms ease-in-out infinite; +} +@keyframes progress { + 0% { transform: translateX(-100%); } + 50% { transform: translateX(0); } + 100% { transform: translateX(100%); } +} +``` + +**Micro-syntax**: +``` +progress: 2000ms ∞ ease-in-out [X-100%→0→100%] +``` + +--- + +## Status Indicators + +```css +/* Online status pulse */ +.status-online { + animation: pulse 2000ms infinite; +} +@keyframes pulse { + 0%, 100% { + opacity: 1; + scale: 1; + } + 50% { + opacity: 0.6; + scale: 1.05; + } +} +``` + +**Micro-syntax**: +``` +status: 2000ms ∞ [α1→0.6→1, S1→1.05→1] +``` + +--- + +## Related Files + +- [Animation Basics](./animation-basics.md) - Fundamentals +- [Form Animations](./animation-forms.md) - Form patterns +- [Advanced Animations](./animation-advanced.md) - Recipes & best practices diff --git a/.opencode/context/ui/web/design-systems.md b/.opencode/context/ui/web/design-systems.md new file mode 100644 index 0000000..14a3b6f --- /dev/null +++ b/.opencode/context/ui/web/design-systems.md @@ -0,0 +1,381 @@ + +# Design Systems + +## Overview + +This context file provides reusable design system patterns, theme templates, and color systems for frontend design work. Use these as starting points for creating cohesive, professional UI designs. + +## Quick Reference + +**Color Format**: OKLCH (perceptually uniform color space) +**Theme Variables**: CSS custom properties (--variable-name) +**Font Sources**: Google Fonts +**Responsive**: All designs must be mobile-first responsive + +--- + +## Theme Patterns + +### Neo-Brutalism Style + +**Characteristics**: 90s web design aesthetic, bold borders, flat shadows, high contrast + +**Use Cases**: +- Retro/vintage applications +- Bold, statement-making interfaces +- Art/creative portfolios +- Playful consumer apps + +**Theme Template**: + +```css +:root { + /* Colors - High contrast, bold */ + --background: oklch(1.0000 0 0); + --foreground: oklch(0 0 0); + --card: oklch(1.0000 0 0); + --card-foreground: oklch(0 0 0); + --popover: oklch(1.0000 0 0); + --popover-foreground: oklch(0 0 0); + --primary: oklch(0.6489 0.2370 26.9728); + --primary-foreground: oklch(1.0000 0 0); + --secondary: oklch(0.9680 0.2110 109.7692); + --secondary-foreground: oklch(0 0 0); + --muted: oklch(0.9551 0 0); + --muted-foreground: oklch(0.3211 0 0); + --accent: oklch(0.5635 0.2408 260.8178); + --accent-foreground: oklch(1.0000 0 0); + --destructive: oklch(0 0 0); + --destructive-foreground: oklch(1.0000 0 0); + --border: oklch(0 0 0); + --input: oklch(0 0 0); + --ring: oklch(0.6489 0.2370 26.9728); + + /* Chart colors */ + --chart-1: oklch(0.6489 0.2370 26.9728); + --chart-2: oklch(0.9680 0.2110 109.7692); + --chart-3: oklch(0.5635 0.2408 260.8178); + --chart-4: oklch(0.7323 0.2492 142.4953); + --chart-5: oklch(0.5931 0.2726 328.3634); + + /* Sidebar */ + --sidebar: oklch(0.9551 0 0); + --sidebar-foreground: oklch(0 0 0); + --sidebar-primary: oklch(0.6489 0.2370 26.9728); + --sidebar-primary-foreground: oklch(1.0000 0 0); + --sidebar-accent: oklch(0.5635 0.2408 260.8178); + --sidebar-accent-foreground: oklch(1.0000 0 0); + --sidebar-border: oklch(0 0 0); + --sidebar-ring: oklch(0.6489 0.2370 26.9728); + + /* Typography */ + --font-sans: DM Sans, sans-serif; + --font-serif: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif; + --font-mono: Space Mono, monospace; + + /* Border radius - Sharp corners */ + --radius: 0px; + --radius-sm: calc(var(--radius) - 4px); + --radius-md: calc(var(--radius) - 2px); + --radius-lg: var(--radius); + --radius-xl: calc(var(--radius) + 4px); + + /* Shadows - Bold, offset shadows */ + --shadow-2xs: 4px 4px 0px 0px hsl(0 0% 0% / 0.50); + --shadow-xs: 4px 4px 0px 0px hsl(0 0% 0% / 0.50); + --shadow-sm: 4px 4px 0px 0px hsl(0 0% 0% / 1.00), 4px 1px 2px -1px hsl(0 0% 0% / 1.00); + --shadow: 4px 4px 0px 0px hsl(0 0% 0% / 1.00), 4px 1px 2px -1px hsl(0 0% 0% / 1.00); + --shadow-md: 4px 4px 0px 0px hsl(0 0% 0% / 1.00), 4px 2px 4px -1px hsl(0 0% 0% / 1.00); + --shadow-lg: 4px 4px 0px 0px hsl(0 0% 0% / 1.00), 4px 4px 6px -1px hsl(0 0% 0% / 1.00); + --shadow-xl: 4px 4px 0px 0px hsl(0 0% 0% / 1.00), 4px 8px 10px -1px hsl(0 0% 0% / 1.00); + --shadow-2xl: 4px 4px 0px 0px hsl(0 0% 0% / 2.50); + + /* Spacing */ + --tracking-normal: 0em; + --spacing: 0.25rem; +} +``` + +--- + +### Modern Dark Mode Style + +**Characteristics**: Clean, minimal, professional (Vercel/Linear aesthetic) + +**Use Cases**: +- SaaS applications +- Developer tools +- Professional dashboards +- Enterprise applications +- Modern web apps + +**Theme Template**: + +```css +:root { + /* Colors - Subtle, professional */ + --background: oklch(1 0 0); + --foreground: oklch(0.1450 0 0); + --card: oklch(1 0 0); + --card-foreground: oklch(0.1450 0 0); + --popover: oklch(1 0 0); + --popover-foreground: oklch(0.1450 0 0); + --primary: oklch(0.2050 0 0); + --primary-foreground: oklch(0.9850 0 0); + --secondary: oklch(0.9700 0 0); + --secondary-foreground: oklch(0.2050 0 0); + --muted: oklch(0.9700 0 0); + --muted-foreground: oklch(0.5560 0 0); + --accent: oklch(0.9700 0 0); + --accent-foreground: oklch(0.2050 0 0); + --destructive: oklch(0.5770 0.2450 27.3250); + --destructive-foreground: oklch(1 0 0); + --border: oklch(0.9220 0 0); + --input: oklch(0.9220 0 0); + --ring: oklch(0.7080 0 0); + + /* Chart colors - Monochromatic blues */ + --chart-1: oklch(0.8100 0.1000 252); + --chart-2: oklch(0.6200 0.1900 260); + --chart-3: oklch(0.5500 0.2200 263); + --chart-4: oklch(0.4900 0.2200 264); + --chart-5: oklch(0.4200 0.1800 266); + + /* Sidebar */ + --sidebar: oklch(0.9850 0 0); + --sidebar-foreground: oklch(0.1450 0 0); + --sidebar-primary: oklch(0.2050 0 0); + --sidebar-primary-foreground: oklch(0.9850 0 0); + --sidebar-accent: oklch(0.9700 0 0); + --sidebar-accent-foreground: oklch(0.2050 0 0); + --sidebar-border: oklch(0.9220 0 0); + --sidebar-ring: oklch(0.7080 0 0); + + /* Typography - System fonts */ + --font-sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'; + --font-serif: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif; + --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; + + /* Border radius - Rounded */ + --radius: 0.625rem; + --radius-sm: calc(var(--radius) - 4px); + --radius-md: calc(var(--radius) - 2px); + --radius-lg: var(--radius); + --radius-xl: calc(var(--radius) + 4px); + + /* Shadows - Subtle, soft */ + --shadow-2xs: 0 1px 3px 0px hsl(0 0% 0% / 0.05); + --shadow-xs: 0 1px 3px 0px hsl(0 0% 0% / 0.05); + --shadow-sm: 0 1px 3px 0px hsl(0 0% 0% / 0.10), 0 1px 2px -1px hsl(0 0% 0% / 0.10); + --shadow: 0 1px 3px 0px hsl(0 0% 0% / 0.10), 0 1px 2px -1px hsl(0 0% 0% / 0.10); + --shadow-md: 0 1px 3px 0px hsl(0 0% 0% / 0.10), 0 2px 4px -1px hsl(0 0% 0% / 0.10); + --shadow-lg: 0 1px 3px 0px hsl(0 0% 0% / 0.10), 0 4px 6px -1px hsl(0 0% 0% / 0.10); + --shadow-xl: 0 1px 3px 0px hsl(0 0% 0% / 0.10), 0 8px 10px -1px hsl(0 0% 0% / 0.10); + --shadow-2xl: 0 1px 3px 0px hsl(0 0% 0% / 0.25); + + /* Spacing */ + --tracking-normal: 0em; + --spacing: 0.25rem; +} +``` + +--- + +## Typography System + +### Recommended Font Families + +**Monospace Fonts** (Code, technical interfaces): +- JetBrains Mono +- Fira Code +- Source Code Pro +- IBM Plex Mono +- Roboto Mono +- Space Mono +- Geist Mono + +**Sans-Serif Fonts** (UI, body text): +- Inter +- Roboto +- Open Sans +- Poppins +- Montserrat +- Outfit +- Plus Jakarta Sans +- DM Sans +- Geist +- Space Grotesk + +**Display/Decorative Fonts**: +- Oxanium +- Architects Daughter + +**Serif Fonts** (Editorial, formal): +- Merriweather +- Playfair Display +- Lora +- Source Serif Pro +- Libre Baskerville + +### Font Loading + +Always use Google Fonts for consistency and reliability: + +```html + + + +``` + +--- + +## Color System Guidelines + +### OKLCH Color Space + +Use OKLCH for perceptually uniform colors: +- **L** (Lightness): 0-1 (0 = black, 1 = white) +- **C** (Chroma): 0-0.4 (saturation) +- **H** (Hue): 0-360 (color angle) + +**Format**: `oklch(L C H)` + +**Example**: `oklch(0.6489 0.2370 26.9728)` = vibrant orange + +### Color Palette Rules + +1. **Avoid Bootstrap Blue**: Unless explicitly requested, avoid generic blue (#007bff) +2. **Semantic Colors**: Use meaningful color names (--primary, --destructive, --success) +3. **Contrast**: Ensure WCAG AA compliance (4.5:1 for text) +4. **Consistency**: Use theme variables, not hardcoded colors + +### Background/Foreground Pairing + +**Rule**: Background should contrast with content + +- Light component → Dark background +- Dark component → Light background +- Ensures visibility and visual hierarchy + +--- + +## Shadow System + +### Shadow Scales + +Shadows create depth and hierarchy: + +- `--shadow-2xs`: Minimal elevation (1-2px) +- `--shadow-xs`: Subtle lift (2-3px) +- `--shadow-sm`: Small cards (3-4px) +- `--shadow`: Default elevation (4-6px) +- `--shadow-md`: Medium cards (6-8px) +- `--shadow-lg`: Modals, dropdowns (8-12px) +- `--shadow-xl`: Floating panels (12-16px) +- `--shadow-2xl`: Maximum elevation (16-24px) + +### Shadow Styles + +**Soft Shadows** (Modern): +```css +box-shadow: 0 1px 3px 0px hsl(0 0% 0% / 0.10); +``` + +**Hard Shadows** (Neo-brutalism): +```css +box-shadow: 4px 4px 0px 0px hsl(0 0% 0% / 1.00); +``` + +--- + +## Spacing System + +### Base Unit + +Use `--spacing: 0.25rem` (4px) as base unit + +### Scale + +- 1x = 0.25rem (4px) +- 2x = 0.5rem (8px) +- 3x = 0.75rem (12px) +- 4x = 1rem (16px) +- 6x = 1.5rem (24px) +- 8x = 2rem (32px) +- 12x = 3rem (48px) +- 16x = 4rem (64px) + +--- + +## Border Radius System + +### Radius Scales + +```css +--radius-sm: calc(var(--radius) - 4px); +--radius-md: calc(var(--radius) - 2px); +--radius-lg: var(--radius); +--radius-xl: calc(var(--radius) + 4px); +``` + +### Common Values + +- **Sharp** (Neo-brutalism): `--radius: 0px` +- **Subtle** (Modern): `--radius: 0.375rem` (6px) +- **Rounded** (Friendly): `--radius: 0.625rem` (10px) +- **Pill** (Buttons): `--radius: 9999px` + +--- + +## Usage Guidelines + +### When to Use Each Theme + +**Neo-Brutalism**: +- ✅ Creative/artistic projects +- ✅ Retro/vintage aesthetics +- ✅ Bold, statement-making designs +- ❌ Enterprise/corporate applications +- ❌ Accessibility-critical interfaces + +**Modern Dark Mode**: +- ✅ SaaS applications +- ✅ Developer tools +- ✅ Professional dashboards +- ✅ Enterprise applications +- ✅ Accessibility-critical interfaces + +### Customization + +1. Start with a base theme template +2. Adjust primary/accent colors for brand +3. Modify radius for desired feel +4. Adjust shadows for depth preference +5. Test contrast ratios for accessibility + +--- + +## Best Practices + +✅ **Use CSS custom properties** for all theme values +✅ **Test in light and dark modes** if applicable +✅ **Validate color contrast** (WCAG AA minimum) +✅ **Use semantic color names** (--primary, not --blue) +✅ **Load fonts from Google Fonts** for reliability +✅ **Apply consistent spacing** using the spacing scale +✅ **Test responsive behavior** at all breakpoints + +❌ **Don't hardcode colors** in components +❌ **Don't use generic blue** (#007bff) without reason +❌ **Don't mix color formats** (stick to OKLCH) +❌ **Don't skip contrast testing** +❌ **Don't use too many font families** (2-3 max) + +--- + +## References + +- [OKLCH Color Picker](https://oklch.com/) +- [Google Fonts](https://fonts.google.com/) +- [WCAG Contrast Checker](https://webaim.org/resources/contrastchecker/) +- [Tailwind CSS Colors](https://tailwindcss.com/docs/customizing-colors) diff --git a/.opencode/context/ui/web/design/concepts/scroll-linked-animations.md b/.opencode/context/ui/web/design/concepts/scroll-linked-animations.md new file mode 100644 index 0000000..8fbb603 --- /dev/null +++ b/.opencode/context/ui/web/design/concepts/scroll-linked-animations.md @@ -0,0 +1,52 @@ +# Concept: Scroll-Linked Animations + +**Purpose**: Sync image sequences to scroll position for cinematic product reveals + +**Last Updated**: 2026-01-07 + +--- + +## Core Idea + +Map scroll position to video frames. As user scrolls, play through image sequence like a scrubbing timeline. Creates illusion of 3D animation controlled by scroll. + +**Formula**: `scrollProgress (0→1) → frameIndex (0→N) → canvas.drawImage()` + +--- + +## Essential Parts + +1. **Image sequence** - 60-150 WebP frames from video/3D render +2. **Sticky canvas** - Fixed HTML5 canvas, always visible while scrolling +3. **Scroll tracker** - Framer Motion `useScroll` hook +4. **Preloader** - Load all frames upfront (prevents flicker) +5. **Background match** - Page BG = image BG (hides edges) + +--- + +## Minimal Example + +```tsx +const { scrollYProgress } = useScroll({ target: containerRef }) +const frameIndex = useTransform(scrollYProgress, [0, 1], [0, 119]) + +useEffect(() => { + ctx.drawImage(images[Math.round(frameIndex)], 0, 0) +}, [frameIndex]) +``` + +**Why canvas?** 10x faster than swapping ``. DOM updates are slow. + +--- + +## Related + +- examples/scrollytelling-headphone.md - Full code +- guides/building-scrollytelling-pages.md - Implementation +- lookup/scroll-animation-prompts.md - Generate sequences + +--- + +## Reference + +[Apple AirPods Pro](https://www.apple.com/airpods-pro/) - Production example diff --git a/.opencode/context/ui/web/design/examples/scrollytelling-headphone.md b/.opencode/context/ui/web/design/examples/scrollytelling-headphone.md new file mode 100644 index 0000000..49d9a07 --- /dev/null +++ b/.opencode/context/ui/web/design/examples/scrollytelling-headphone.md @@ -0,0 +1,263 @@ +--- +description: "Full Next.js implementation of scroll-linked image sequence animation" +--- + +# Example: Scrollytelling Headphone Animation + +**Purpose**: Full Next.js implementation of scroll-linked image sequence animation + +**Last Updated**: 2026-01-07 + +--- + +## Overview + +Complete working example of "Zenith X" headphone scrollytelling page using Next.js 14, Framer Motion, and Canvas. + +**Tech Stack**: Next.js 14 (App Router) + Framer Motion + Canvas + Tailwind CSS + +--- + +## File Structure + +``` +app/ +├── page.tsx +├── components/ +│ └── HeadphoneScroll.tsx +└── globals.css +public/ +└── frames/ + └── frame_0001.webp through frame_0120.webp +``` + +--- + +## 1. globals.css + +```css +@tailwind base; +@tailwind components; +@tailwind utilities; + +@layer base { + body { + @apply bg-[#050505] text-white antialiased; + font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; + } +} +``` + +--- + +## 2. app/page.tsx + +```tsx +import HeadphoneScroll from './components/HeadphoneScroll' + +export default function Home() { + return ( +
+ +
+ ) +} +``` + +--- + +## 3. components/HeadphoneScroll.tsx + +```tsx +'use client' + +import { useEffect, useRef, useState } from 'react' +import { motion, useScroll, useTransform } from 'framer-motion' + +const FRAME_COUNT = 120 + +export default function HeadphoneScroll() { + const containerRef = useRef(null) + const canvasRef = useRef(null) + const [images, setImages] = useState([]) + const [loading, setLoading] = useState(true) + + // Track scroll progress (0 to 1) + const { scrollYProgress } = useScroll({ + target: containerRef, + offset: ['start start', 'end end'] + }) + + // Map scroll progress to frame index + const frameIndex = useTransform(scrollYProgress, [0, 1], [0, FRAME_COUNT - 1]) + const [currentFrame, setCurrentFrame] = useState(0) + + // Update current frame + useEffect(() => { + return frameIndex.on('change', (latest) => { + setCurrentFrame(Math.round(latest)) + }) + }, [frameIndex]) + + // Preload all images + useEffect(() => { + const loadImages = async () => { + const promises = Array.from({ length: FRAME_COUNT }, (_, i) => { + return new Promise((resolve) => { + const img = new Image() + const frameNum = String(i + 1).padStart(4, '0') + img.src = `/frames/frame_${frameNum}.webp` + img.onload = () => resolve(img) + }) + }) + + const loaded = await Promise.all(promises) + setImages(loaded) + setLoading(false) + } + + loadImages() + }, []) + + // Render current frame to canvas + useEffect(() => { + if (!canvasRef.current || !images.length) return + + const canvas = canvasRef.current + const ctx = canvas.getContext('2d') + if (!ctx) return + + const img = images[currentFrame] + + // Set canvas size + canvas.width = window.innerWidth + canvas.height = window.innerHeight + + // Clear and draw centered + ctx.clearRect(0, 0, canvas.width, canvas.height) + + const scale = Math.min( + canvas.width / img.width, + canvas.height / img.height + ) + + const x = (canvas.width - img.width * scale) / 2 + const y = (canvas.height - img.height * scale) / 2 + + ctx.drawImage(img, x, y, img.width * scale, img.height * scale) + }, [currentFrame, images]) + + // Text overlay opacity transforms + const title = useTransform(scrollYProgress, [0, 0.1, 0.2], [1, 1, 0]) + const text1 = useTransform(scrollYProgress, [0.25, 0.3, 0.4], [0, 1, 0]) + const text2 = useTransform(scrollYProgress, [0.55, 0.6, 0.7], [0, 1, 0]) + const cta = useTransform(scrollYProgress, [0.85, 0.9, 1], [0, 1, 1]) + + if (loading) { + return ( +
+
+
+ ) + } + + return ( +
+ {/* Sticky Canvas */} + + + {/* Text Overlays */} + +
+

+ Zenith X +

+

Pure Sound.

+
+
+ + +

+ Precision Engineering. +

+
+ + +

+ Titanium Drivers. +

+
+ + +
+

+ Hear Everything. +

+ +
+
+
+ ) +} +``` + +--- + +## Key Implementation Details + +**Line 15-18**: `useScroll` tracks scroll progress from container start to end +**Line 21**: `useTransform` maps 0-1 scroll to 0-119 frame index +**Line 32-46**: Preload all 120 frames using Promise.all +**Line 49-70**: Draw current frame to canvas, scaled and centered +**Line 73-76**: Text opacity transforms for fade in/out at specific scroll positions + +--- + +## Usage + +1. Install dependencies: `npm install framer-motion` +2. Place 120 WebP frames in `/public/frames/` +3. Copy code into respective files +4. Run: `npm run dev` + +--- + +## Customization + +**Change frame count**: Update `FRAME_COUNT` constant (line 7) +**Adjust scroll length**: Change `h-[400vh]` to `h-[300vh]` or `h-[500vh]` (line 120) +**Modify text timing**: Update transform ranges in lines 73-76 +**Change colors**: Update `bg-[#050505]` to match your image background + +--- + +## Related + +- concepts/scroll-linked-animations.md - Understanding the technique +- guides/scrollytelling-setup.md - Getting started +- lookup/scroll-animation-prompts.md - Generating image sequences + +--- + +## References + +- [Framer Motion Docs](https://www.framer.com/motion/) +- [Next.js App Router](https://nextjs.org/docs/app) diff --git a/.opencode/context/ui/web/design/guides/building-scrollytelling-pages.md b/.opencode/context/ui/web/design/guides/building-scrollytelling-pages.md new file mode 100644 index 0000000..ad15e90 --- /dev/null +++ b/.opencode/context/ui/web/design/guides/building-scrollytelling-pages.md @@ -0,0 +1,271 @@ +--- +description: "Step-by-step implementation of scroll-linked image sequence animations" +--- + +# Guide: Building Scrollytelling Pages + +**Purpose**: Step-by-step implementation of scroll-linked image sequence animations + +**Last Updated**: 2026-01-07 + +--- + +## Prerequisites + +- Next.js 14+ project with App Router +- Framer Motion installed (`npm i framer-motion`) +- Tailwind CSS configured +- Image sequence ready (60-240 WebP frames) + +--- + +## Step 1: Generate Image Sequences + +Use nano banana or AI image tools to create start/end frames, then generate interpolation: + +**Start frame prompt**: +``` +Ultra-premium product photography of [product] on matte black surface, +minimalistic studio shoot, deep black background with subtle gradient, +soft rim lighting, cinematic, high contrast, luxury aesthetic, sharp focus, +no clutter, DSLR 85mm f/1.8, photorealistic +``` + +**End frame prompt**: +``` +Exploded technical diagram of same [product], every component separated +and floating in alignment, against deep black studio background, visible +internal structure, hyper-realistic, studio rim lighting, cinematic, +high contrast, no labels, photorealistic +``` + +**Generate video**: Use AI video tools (Runway, Pika) to interpolate between frames. + +**Export frames**: Use ffmpeg or ezgif to split video into 120+ WebP images. + +```bash +ffmpeg -i animation.mp4 -vf fps=30 frame_%04d.webp +``` + +--- + +## Step 2: Project Structure + +``` +app/ +├── page.tsx # Main landing page +├── components/ +│ └── HeadphoneScroll.tsx # Scroll animation component +└── globals.css # Dark theme, Inter font +public/ +└── frames/ + ├── frame_0001.webp # 120+ frames + ├── frame_0002.webp + └── ... +``` + +--- + +## Step 3: Setup globals.css + +```css +@tailwind base; +@tailwind components; +@tailwind utilities; + +@layer base { + body { + @apply bg-[#050505] text-white antialiased; + font-family: 'Inter', -apple-system, sans-serif; + } +} +``` + +--- + +## Step 4: Create Scroll Component + +**Key patterns**: +- Container with `h-[400vh]` for long scroll +- Canvas with `sticky top-0` stays fixed +- `useScroll` tracks scroll progress (0-1) +- `useTransform` maps progress to frame index +- `useEffect` preloads all images + +**Core logic**: +```tsx +const { scrollYProgress } = useScroll({ target: containerRef }) +const frameIndex = useTransform(scrollYProgress, [0, 1], [0, 119]) +``` + +--- + +## Step 5: Implement Preloader + +Always preload images before starting animation: + +```tsx +useEffect(() => { + const loadImages = async () => { + const promises = Array.from({ length: 120 }, (_, i) => { + return new Promise((resolve) => { + const img = new Image() + img.src = `/frames/frame_${String(i + 1).padStart(4, '0')}.webp` + img.onload = () => resolve(img) + }) + }) + + const loaded = await Promise.all(promises) + setImages(loaded) + setLoading(false) + } + + loadImages() +}, []) +``` + +--- + +## Step 6: Canvas Rendering + +Draw current frame to canvas on every scroll update: + +```tsx +useEffect(() => { + if (!canvasRef.current || !images.length) return + + const canvas = canvasRef.current + const ctx = canvas.getContext('2d') + const img = images[Math.round(currentFrame)] + + // Scale canvas to window + canvas.width = window.innerWidth + canvas.height = window.innerHeight + + // Draw centered + ctx.drawImage(img, + (canvas.width - img.width) / 2, + (canvas.height - img.height) / 2 + ) +}, [currentFrame, images]) +``` + +--- + +## Step 7: Add Text Overlays + +Fade text in/out at specific scroll positions: + +```tsx + + Precision Engineering. + +``` + +--- + +## Step 8: Match Backgrounds + +**CRITICAL**: Page background MUST match image background exactly. + +1. Open first frame in image editor +2. Use eyedropper tool on background (e.g., `#050505`) +3. Set page background to exact same color in globals.css +4. Test: Image edges should be invisible + +--- + +## Step 9: Optimize Performance + +```tsx +// Add GPU hint + + +// Throttle redraws on mobile +useEffect(() => { + let rafId + const render = () => { + // Draw logic here + rafId = requestAnimationFrame(render) + } + render() + return () => cancelAnimationFrame(rafId) +}, []) +``` + +--- + +## Step 10: Add Loading State + +Show spinner while frames load: + +```tsx +{loading && ( +
+
+
+)} +``` + +--- + +## Common Issues & Fixes + +### Images not loading +- Check file paths match exactly (case-sensitive) +- Verify all frames exist in `/public/frames/` +- Open browser console for 404 errors + +### Stuttering animation +- Ensure all images preloaded before starting +- Use WebP (not PNG/JPEG) +- Check canvas size isn't too large + +### Visible image edges +- Background colors don't match exactly +- Use eyedropper tool, not guessing +- Check for gradients in image background + +### Mobile performance +- Reduce frame count (use every 2nd frame) +- Debounce with requestAnimationFrame +- Consider disabling on small screens + +--- + +## Testing Checklist + +- [ ] All frames load without 404s +- [ ] Animation smooth from 0-100% scroll +- [ ] Text fades in/out at correct positions +- [ ] Background seamlessly blends with images +- [ ] Loading spinner shows before animation +- [ ] Works on mobile (or gracefully disabled) +- [ ] No console errors + +--- + +## Related + +- concepts/scroll-linked-animations.md - Understanding the technique +- examples/headphone-scrollytelling.md - Full code example +- lookup/animation-image-prompts.md - Prompts for frame generation + +--- + +## References + +- [Next.js Image Optimization](https://nextjs.org/docs/app/building-your-application/optimizing/images) +- [Framer Motion useScroll](https://www.framer.com/motion/use-scroll/) diff --git a/.opencode/context/ui/web/design/lookup/scroll-animation-prompts.md b/.opencode/context/ui/web/design/lookup/scroll-animation-prompts.md new file mode 100644 index 0000000..967e712 --- /dev/null +++ b/.opencode/context/ui/web/design/lookup/scroll-animation-prompts.md @@ -0,0 +1,213 @@ +--- +description: "AI prompts for generating start/end frames and video sequences for scrollytelling" +--- + +# Lookup: Scroll Animation Image Generation Prompts + +**Purpose**: AI prompts for generating start/end frames and video sequences for scrollytelling + +**Last Updated**: 2026-01-07 + +--- + +## Overview + +Use these prompts with nano banana, Runway, Pika, or other AI tools to create image sequences for scroll animations. + +**Workflow**: Start frame → End frame → Video interpolation → Frame extraction + +--- + +## Start Frame Prompts + +### Product Hero Shot + +``` +Ultra-premium product photography of [PRODUCT NAME] placed on a matte black +surface, minimalistic studio photoshoot. Deep black background (#050505) with +subtle gradient falloff, soft rim lighting outlining edges, controlled +reflections on smooth textures. Cinematic lighting, high contrast, luxury tech +aesthetic, sharp focus, shallow depth of field. No clutter, no text, no logos +emphasized. Shot with professional DSLR, 85mm lens, f/1.8, ultra-high +resolution, photorealistic, Apple-level product shoot, dramatic mood, modern +and elegant. +``` + +**Variables**: Replace [PRODUCT NAME] with your product +**Output**: Starting position, fully assembled, hero angle + +--- + +### Variations by Product Type + +| Product Type | Additional Details | +|--------------|-------------------| +| **Headphones** | "over-ear headphones with leather cushions and metal headband" | +| **Smartphone** | "smartphone with edge-to-edge OLED display, aluminum frame" | +| **Watch** | "luxury smartwatch with titanium case and sapphire crystal" | +| **Laptop** | "thin laptop with aluminum unibody, open at 45 degrees" | +| **Camera** | "mirrorless camera with prime lens attached, side profile" | + +--- + +## End Frame Prompts + +### Exploded Technical View + +``` +Exploded technical diagram view of [PRODUCT NAME], every component precisely +separated and floating in perfect alignment, suspended in mid-air against deep +black studio background (#050505). Visible internal structure including +[INTERNAL COMPONENTS], all parts evenly spaced showing assembly order. +Hyper-realistic product visualization, ultra-sharp focus, studio rim lighting +identical to hero shot, soft highlights tracing each component, controlled +reflections on matte and metal surfaces. Cinematic lighting, high contrast, +luxury engineering aesthetic, no labels, no annotations, no text. +Photorealistic, ultra-high resolution, Apple-style industrial design render, +dramatic and clean. +``` + +**Variables**: +- [PRODUCT NAME]: Your product +- [INTERNAL COMPONENTS]: Specific parts to show + +--- + +### Internal Components by Product + +| Product | Internal Components Examples | +|---------|------------------------------| +| **Headphones** | "copper wiring, titanium drivers, magnets, circuit boards, padding layers, metal frame" | +| **Smartphone** | "battery, logic board, cameras, OLED panel, antenna bands, frame" | +| **Watch** | "watch movement, gears, battery, sensors, display, crown mechanism" | +| **Laptop** | "keyboard assembly, trackpad, battery cells, logic board, cooling fans, display panel" | +| **Camera** | "sensor, shutter mechanism, lens elements, mirror assembly, circuit boards" | + +--- + +## Video Interpolation Prompts + +### For Runway/Pika + +``` +Smoothly transition from fully assembled [PRODUCT] to exploded view. +Components separate slowly and precisely, maintaining perfect alignment. +Camera stays locked, product rotates slightly clockwise. Cinematic motion, +professional product animation, 4-5 seconds duration, 30fps. +``` + +**Settings**: +- Duration: 4-5 seconds +- FPS: 30 (yields 120-150 frames) +- Camera: Static or slow orbit +- Motion: Smooth, controlled separation + +--- + +## Frame Extraction + +### Using ffmpeg + +```bash +# Extract as WebP (best for web) +ffmpeg -i animation.mp4 -vf fps=30 frame_%04d.webp + +# Extract as PNG (higher quality, larger) +ffmpeg -i animation.mp4 -vf fps=30 frame_%04d.png + +# Extract with quality control +ffmpeg -i animation.mp4 -vf fps=30 -quality 90 frame_%04d.webp +``` + +### Using ezgif.com + +1. Upload MP4 video +2. Choose "Video to GIF" → "Split to frames" +3. Select WebP format +4. Download all frames as ZIP +5. Rename: `frame_0001.webp`, `frame_0002.webp`, etc. + +--- + +## Background Color Matching + +**CRITICAL**: Page background MUST match image background exactly + +### Recommended Dark Backgrounds + +| Color Code | Usage | +|------------|-------| +| `#050505` | Pure black with slight lift (recommended) | +| `#0a0a0a` | Slightly lighter, less harsh | +| `#000000` | True black (only if images are true black) | +| `#1a1a1a` | Dark gray (for lighter renders) | + +**Pro tip**: Use eyedropper tool on first frame background, use exact hex in CSS + +--- + +## Alternative Animation Styles + +### Rotation (360° spin) + +**Start**: Front view +**End**: Front view (after 360° rotation) +**Prompt**: "Rotate product 360 degrees on turntable, maintain lighting" + +### Zoom In (Feature reveal) + +**Start**: Full product view +**End**: Close-up of key feature +**Prompt**: "Smooth camera push-in focusing on [FEATURE], maintain focus" + +### Morph (Color/style change) + +**Start**: Product in color A +**End**: Product in color B +**Prompt**: "Seamlessly morph product color from [A] to [B], maintain form" + +--- + +## Quality Settings + +### For High-End Results + +- **Resolution**: 1920x1080 minimum (4K for high-DPI) +- **Format**: WebP (compression) or PNG (quality) +- **Frame count**: 90-150 frames (3-5 seconds at 30fps) +- **Total size**: Target <50MB for all frames combined + +### Optimization Tips + +1. Use WebP format (70% smaller than PNG) +2. Compress with quality 85-90 +3. Resize images to max 2000px width +4. Use consistent aspect ratio (16:9 or 1:1) + +--- + +## Testing Checklist + +- [ ] Background color matches exactly (no visible edges) +- [ ] All frames same dimensions +- [ ] Smooth motion (no jumps between frames) +- [ ] Consistent lighting across sequence +- [ ] File names sequential (`frame_0001` to `frame_0120`) +- [ ] Total file size reasonable (<50MB) + +--- + +## Related + +- concepts/scroll-linked-animations.md - Understanding the technique +- examples/scrollytelling-headphone.md - Full implementation +- guides/scrollytelling-setup.md - Setup instructions + +--- + +## Tool References + +- [Runway ML](https://runwayml.com) - AI video generation +- [Pika Labs](https://pika.art) - AI video interpolation +- [ezgif](https://ezgif.com/split-video) - Frame extraction +- [FFmpeg](https://ffmpeg.org) - Video processing diff --git a/.opencode/context/ui/web/design/navigation.md b/.opencode/context/ui/web/design/navigation.md new file mode 100644 index 0000000..2abfdab --- /dev/null +++ b/.opencode/context/ui/web/design/navigation.md @@ -0,0 +1,91 @@ +--- +description: "Advanced web UI patterns - scroll animations, visual effects, and interactive design" +--- + +# Web Design Patterns + +**Purpose**: Advanced web UI patterns - scroll animations, visual effects, and interactive design + +**Last Updated**: 2026-01-31 + +--- + +## Quick Navigation + +### Concepts +| File | Description | Priority | +|------|-------------|----------| +| [scroll-linked-animations.md](concepts/scroll-linked-animations.md) | Scroll-synced image sequences (scrollytelling) | high | + +### Examples +| File | Description | Priority | +|------|-------------|----------| +| [scrollytelling-headphone.md](examples/scrollytelling-headphone.md) | Full Next.js scroll animation example | high | + +### Guides +| File | Description | Priority | +|------|-------------|----------| +| [building-scrollytelling-pages.md](guides/building-scrollytelling-pages.md) | Complete implementation guide | high | +| [premium-dark-ui-quick-start.md](guides/premium-dark-ui-quick-start.md) | Premium dark UI design system quick start | high | +| [premium-dark-ui-visual-reference.md](guides/premium-dark-ui-visual-reference.md) | Visual reference for premium dark UI | medium | + +### Lookup +| File | Description | Priority | +|------|-------------|----------| +| [scroll-animation-prompts.md](lookup/scroll-animation-prompts.md) | AI prompts for generating animation sequences | medium | + +### Errors +| File | Description | Priority | +|------|-------------|----------| +| _(No error files yet)_ | | | + +--- + +## Loading Strategy + +**For scroll animation work**: +1. Load `concepts/scroll-linked-animations.md` (understand technique) +2. Load `lookup/scroll-animation-prompts.md` (generate image sequences) +3. Load `examples/scrollytelling-headphone.md` (see full code) +4. Reference `guides/building-scrollytelling-pages.md` (step-by-step) + +**For premium dark UI design**: +1. Load `guides/premium-dark-ui-quick-start.md` (implementation guide) +2. Reference `guides/premium-dark-ui-visual-reference.md` (visual patterns) + +--- + +## Scope + +This subcategory covers: +- ✅ Scroll-linked animations (scrollytelling) +- ✅ Canvas-based rendering +- ✅ Framer Motion patterns +- ✅ Image sequence generation +- ✅ Premium dark UI design system +- ✅ Glassmorphism patterns +- ⏳ CSS animations (future) +- ⏳ SVG animations (future) +- ⏳ WebGL effects (future) + +--- + +## Related Categories + +- `ui/web/` - Core web UI patterns (parent directory) +- `ui/web/animation-patterns.md` - CSS animations and transitions +- `development/` - General development patterns + +--- + +## Used By + +**Agents**: frontend-specialist, design-specialist, animation-expert + +## Statistics +- Concepts: 1 +- Examples: 1 +- Guides: 3 +- Lookup: 1 +- Errors: 0 +- **Total**: 6 files diff --git a/.opencode/context/ui/web/navigation.md b/.opencode/context/ui/web/navigation.md new file mode 100644 index 0000000..2bc73a6 --- /dev/null +++ b/.opencode/context/ui/web/navigation.md @@ -0,0 +1,116 @@ +# Web UI Context + +**Purpose**: Web-based UI patterns, animations, styling standards, and React component design + +**Last Updated**: 2026-01-07 + +--- + +## Quick Navigation + +### Core Files + +| File | Description | Priority | +|------|-------------|----------| +| [animation-basics.md](animation-basics.md) | Animation fundamentals, timing, easing | high | +| [animation-components.md](animation-components.md) | Button, card, modal, dropdown animations | high | +| [animation-chat.md](animation-chat.md) | Chat UI and message animations | medium | +| [animation-loading.md](animation-loading.md) | Skeleton, spinner, progress animations | medium | +| [animation-forms.md](animation-forms.md) | Form input and validation animations | medium | +| [animation-advanced.md](animation-advanced.md) | Recipes, best practices, accessibility | medium | +| [ui-styling-standards.md](ui-styling-standards.md) | CSS frameworks, Tailwind patterns, styling best practices | high | +| [react-patterns.md](react-patterns.md) | Modern React patterns, hooks, component design | high | +| [design-systems.md](design-systems.md) | Design system principles and component libraries | medium | +| [images-guide.md](images-guide.md) | Placeholder and responsive images | medium | +| [icons-guide.md](icons-guide.md) | Icon systems (Lucide, Heroicons, FA) | medium | +| [fonts-guide.md](fonts-guide.md) | Font loading and optimization | medium | +| [cdn-resources.md](cdn-resources.md) | CDN libraries and resources | medium | + +### Subcategories + +| Subcategory | Description | Path | +|-------------|-------------|------| +| **design/** | Advanced design patterns (scrollytelling, effects) | [design/navigation.md](design/navigation.md) | + +--- + +## Loading Strategy + +### For general web UI work: +1. Load `ui-styling-standards.md` (CSS frameworks, Tailwind) +2. Load `react-patterns.md` (component patterns) +3. Reference `animation-patterns.md` (if animations needed) + +### For animation work: +1. Load `animation-basics.md` (fundamentals, timing, easing) +2. Load `animation-components.md` (UI component animations) +3. Reference `animation-chat.md` for chat UI patterns +4. Reference `animation-advanced.md` for recipes and accessibility + +### For scroll animations: +1. Navigate to `design/` subcategory +2. Load scroll-linked animation guides + +--- + +## Scope + +This subcategory covers: +- ✅ CSS animations and transitions +- ✅ Tailwind CSS and utility-first styling +- ✅ React component patterns and hooks +- ✅ Design systems and component libraries +- ✅ Icon libraries and web fonts +- ✅ Scroll-linked animations (scrollytelling) +- ✅ Canvas-based rendering +- ✅ Framer Motion patterns + +--- + +## File Summaries + +### animation-basics.md, animation-components.md, animation-chat.md, animation-loading.md, animation-forms.md, animation-advanced.md +CSS animations, micro-interactions, and UI transitions split into focused modules. + +**Key topics**: Animation micro-syntax, 60fps performance, reduced motion, chat UI animations, component patterns + +### ui-styling-standards.md +CSS framework usage, Tailwind CSS patterns, responsive design, and styling best practices. + +**Key topics**: Utility-first CSS, component styling, responsive breakpoints, dark mode + +### react-patterns.md +Modern React patterns including functional components, hooks, state management, and performance optimization. + +**Key topics**: Custom hooks, context API, code splitting, memoization + +### design-systems.md +Design system principles, component libraries, and maintaining consistency across applications. + +**Key topics**: Design tokens, component APIs, documentation, versioning + +### images-guide.md, icons-guide.md, fonts-guide.md, cdn-resources.md +Managing design assets in web applications - split into focused guides. + +**Key topics**: Placeholder images, icon libraries (Lucide, Heroicons), web fonts, CDN resources + +--- + +## Related Categories + +- `ui/terminal/` - Terminal UI patterns +- `development/` - General development patterns +- `product/` - Product design and UX strategy + +--- + +## Used By + +**Agents**: frontend-specialist, design-specialist, ui-developer, react-developer, animation-expert + +--- + +## Statistics +- Core files: 8 +- Subcategories: 1 (design/) +- **Total context files**: 8 + design subcategory diff --git a/.opencode/context/ui/web/react-patterns.md b/.opencode/context/ui/web/react-patterns.md new file mode 100644 index 0000000..f0eb3a7 --- /dev/null +++ b/.opencode/context/ui/web/react-patterns.md @@ -0,0 +1,328 @@ +# React Patterns & Best Practices + +**Category**: development +**Purpose**: Modern React patterns, hooks usage, and component design principles +**Used by**: frontend-specialist + +--- + +## Overview + +This guide covers modern React patterns using functional components, hooks, and best practices for building scalable React applications. + +## Component Patterns + +### 1. Functional Components with Hooks + +**Always use functional components**: +```jsx +// Good +function UserProfile({ userId }) { + const [user, setUser] = useState(null); + + useEffect(() => { + fetchUser(userId).then(setUser); + }, [userId]); + + return
{user?.name}
; +} +``` + +### 2. Custom Hooks for Reusable Logic + +**Extract common logic into custom hooks**: +```jsx +// Custom hook +function useUser(userId) { + const [user, setUser] = useState(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + + useEffect(() => { + setLoading(true); + fetchUser(userId) + .then(setUser) + .catch(setError) + .finally(() => setLoading(false)); + }, [userId]); + + return { user, loading, error }; +} + +// Usage +function UserProfile({ userId }) { + const { user, loading, error } = useUser(userId); + + if (loading) return ; + if (error) return ; + return
{user.name}
; +} +``` + +### 3. Composition Over Props Drilling + +**Use composition to avoid prop drilling**: +```jsx +// Bad - Props drilling +function App() { + const [theme, setTheme] = useState('light'); + return ; +} + +// Good - Composition with Context +const ThemeContext = createContext(); + +function App() { + const [theme, setTheme] = useState('light'); + return ( + + + + ); +} + +function Layout() { + const { theme } = useContext(ThemeContext); + return
...
; +} +``` + +### 4. Compound Components + +**For complex, related components**: +```jsx +function Tabs({ children }) { + const [activeTab, setActiveTab] = useState(0); + + return ( + + {children} + + ); +} + +Tabs.List = function TabsList({ children }) { + return
{children}
; +}; + +Tabs.Tab = function Tab({ index, children }) { + const { activeTab, setActiveTab } = useContext(TabsContext); + return ( + + ); +}; + +Tabs.Panel = function TabPanel({ index, children }) { + const { activeTab } = useContext(TabsContext); + return activeTab === index ?
{children}
: null; +}; + +// Usage + + + Tab 1 + Tab 2 + + Content 1 + Content 2 + +``` + +## Hooks Best Practices + +### 1. useEffect Dependencies + +**Always specify dependencies correctly**: +```jsx +// Bad - Missing dependencies +useEffect(() => { + fetchData(userId); +}, []); + +// Good - Correct dependencies +useEffect(() => { + fetchData(userId); +}, [userId]); + +// Good - Stable function reference +const fetchData = useCallback((id) => { + api.getUser(id).then(setUser); +}, []); + +useEffect(() => { + fetchData(userId); +}, [userId, fetchData]); +``` + +### 2. useMemo for Expensive Calculations + +**Memoize expensive computations**: +```jsx +function DataTable({ data, filters }) { + const filteredData = useMemo(() => { + return data.filter(item => + filters.every(filter => filter(item)) + ); + }, [data, filters]); + + return ; +} +``` + +### 3. useCallback for Stable References + +**Prevent unnecessary re-renders**: +```jsx +function Parent() { + const [count, setCount] = useState(0); + + // Bad - New function on every render + const handleClick = () => setCount(c => c + 1); + + // Good - Stable function reference + const handleClick = useCallback(() => { + setCount(c => c + 1); + }, []); + + return ; +} + +const Child = memo(function Child({ onClick }) { + return ; +}); +``` + +## State Management Patterns + +### 1. Local State First + +**Start with local state, lift when needed**: +```jsx +// Local state +function Counter() { + const [count, setCount] = useState(0); + return ; +} + +// Lifted state when shared +function App() { + const [count, setCount] = useState(0); + return ( + <> + + + + ); +} +``` + +### 2. useReducer for Complex State + +**Use reducer for related state updates**: +```jsx +const initialState = { count: 0, step: 1 }; + +function reducer(state, action) { + switch (action.type) { + case 'increment': + return { ...state, count: state.count + state.step }; + case 'decrement': + return { ...state, count: state.count - state.step }; + case 'setStep': + return { ...state, step: action.payload }; + default: + return state; + } +} + +function Counter() { + const [state, dispatch] = useReducer(reducer, initialState); + + return ( + <> + + {state.count} + + + ); +} +``` + +## Performance Optimization + +### 1. Code Splitting + +**Lazy load routes and heavy components**: +```jsx +import { lazy, Suspense } from 'react'; + +const Dashboard = lazy(() => import('./Dashboard')); +const Settings = lazy(() => import('./Settings')); + +function App() { + return ( + }> + + } /> + } /> + + + ); +} +``` + +### 2. Virtualization for Long Lists + +**Use virtualization for large datasets**: +```jsx +import { FixedSizeList } from 'react-window'; + +function VirtualList({ items }) { + const Row = ({ index, style }) => ( +
{items[index].name}
+ ); + + return ( + + {Row} + + ); +} +``` + +## Best Practices + +1. **Keep components small and focused** - Single responsibility principle +2. **Use TypeScript** - Type safety prevents bugs and improves DX +3. **Colocate related code** - Keep components, styles, and tests together +4. **Use meaningful prop names** - Clear, descriptive names improve readability +5. **Avoid inline functions in JSX** - Extract to named functions or useCallback +6. **Use fragments** - Avoid unnecessary wrapper divs +7. **Handle loading and error states** - Always show feedback to users +8. **Test components** - Use React Testing Library for user-centric tests + +## Anti-Patterns + +- ❌ **Prop drilling** - Use context or composition instead +- ❌ **Massive components** - Break down into smaller, focused components +- ❌ **Mutating state directly** - Always use setState or dispatch +- ❌ **Using index as key** - Use stable, unique identifiers +- ❌ **Unnecessary useEffect** - Derive state when possible +- ❌ **Ignoring ESLint warnings** - React hooks rules prevent bugs +- ❌ **Not memoizing context values** - Causes unnecessary re-renders + +## References + +- React Documentation (react.dev) +- React Patterns by Kent C. Dodds +- Epic React by Kent C. Dodds diff --git a/.opencode/context/ui/web/ui-styling-standards.md b/.opencode/context/ui/web/ui-styling-standards.md new file mode 100644 index 0000000..bafdd26 --- /dev/null +++ b/.opencode/context/ui/web/ui-styling-standards.md @@ -0,0 +1,552 @@ + +# UI Styling Standards + +## Overview + +Standards and conventions for CSS frameworks, responsive design, and styling best practices in frontend development. + +## Quick Reference + +**Framework**: Tailwind CSS + Flowbite (default) +**Approach**: Mobile-first responsive +**Format**: Utility-first CSS +**Specificity**: Use `!important` for overrides when needed + +--- + +## CSS Framework Conventions + +### Tailwind CSS + +**Loading Method** (Preferred): + +```html + + +``` + +**Avoid**: + +```html + + +``` + +**Why**: Script tag allows for JIT compilation and configuration + +### Flowbite + +**Loading Method**: + +```html + + + + + +``` + +**Usage**: Flowbite is the default component library unless user specifies otherwise + +**Components Available**: +- Buttons, forms, modals +- Navigation, dropdowns, tabs +- Cards, alerts, badges +- Tables, pagination +- Tooltips, popovers + +--- + +## Responsive Design Requirements + +### Mobile-First Approach + +**Rule**: ALL designs MUST be responsive + +**Breakpoints** (Tailwind defaults): + +```css +/* Mobile first - base styles apply to mobile */ +.element { } + +/* Small devices (640px and up) */ +@media (min-width: 640px) { } /* sm: */ + +/* Medium devices (768px and up) */ +@media (min-width: 768px) { } /* md: */ + +/* Large devices (1024px and up) */ +@media (min-width: 1024px) { } /* lg: */ + +/* Extra large devices (1280px and up) */ +@media (min-width: 1280px) { } /* xl: */ + +/* 2XL devices (1536px and up) */ +@media (min-width: 1536px) { } /* 2xl: */ +``` + +**Tailwind Syntax**: + +```html + +
+
Left
+
Right
+
+ + +
+ Content +
+``` + +### Testing Requirements + +✅ Test at minimum breakpoints: 375px, 768px, 1024px, 1440px +✅ Verify touch targets (min 44x44px) +✅ Check text readability at all sizes +✅ Ensure images scale properly +✅ Test navigation on mobile + +--- + +## Color Palette Guidelines + +### Avoid Bootstrap Blue + +**Rule**: NEVER use generic Bootstrap blue (#007bff) unless explicitly requested + +**Why**: Overused, lacks personality, feels dated + +**Alternatives**: + +```css +/* Instead of Bootstrap blue */ +--bootstrap-blue: #007bff; /* ❌ Avoid */ + +/* Use contextual colors */ +--primary: oklch(0.6489 0.2370 26.9728); /* Vibrant orange */ +--accent: oklch(0.5635 0.2408 260.8178); /* Rich purple */ +--info: oklch(0.6200 0.1900 260); /* Modern blue */ +--success: oklch(0.7323 0.2492 142.4953); /* Fresh green */ +``` + +### Color Usage Rules + +1. **Semantic naming**: Use `--primary`, `--accent`, not `--blue`, `--red` +2. **Brand alignment**: Choose colors that match project personality +3. **Contrast testing**: Ensure WCAG AA compliance (4.5:1 minimum) +4. **Consistency**: Use theme variables throughout + +--- + +## Background/Foreground Contrast + +### Contrast Rule + +**When designing components or posters**: + +- **Light component** → Dark background +- **Dark component** → Light background + +**Why**: Ensures visibility and creates visual hierarchy + +**Examples**: + +```html + +
+
+ Light card content +
+
+ + +
+
+ Dark card content +
+
+``` + +### Component-Specific Rules + +**Posters/Hero Sections**: +- Use high contrast for readability +- Consider overlay gradients for text on images +- Test with actual content + +**Cards/Panels**: +- Subtle elevation with shadows +- Clear boundary between card and background +- Consistent padding + +--- + +## CSS Specificity & Overrides + +### Using !important + +**Rule**: Use `!important` for properties that might be overwritten by Tailwind or Flowbite + +**Common Cases**: + +```css +/* Typography overrides */ +h1 { + font-size: 2.5rem !important; + font-weight: 700 !important; + line-height: 1.2 !important; +} + +body { + font-family: 'Inter', sans-serif !important; + color: var(--foreground) !important; +} + +/* Component overrides */ +.custom-button { + background-color: var(--primary) !important; + border-radius: var(--radius) !important; +} +``` + +**When NOT to use**: + +```css +/* ❌ Don't use for everything */ +.element { + margin: 1rem !important; + padding: 1rem !important; + display: flex !important; +} + +/* ✅ Use Tailwind utilities instead */ +
+``` + +### Specificity Best Practices + +1. **Prefer utility classes** over custom CSS +2. **Use !important sparingly** - only for framework overrides +3. **Scope custom styles** to avoid conflicts +4. **Use CSS custom properties** for theming + +--- + +## Layout Patterns + +### Flexbox (Preferred for 1D layouts) + +```html + +
+
Item 1
+
Item 2
+
+ + +
+
Item 1
+
Item 2
+
+ + +
+
Centered content
+
+``` + +### Grid (Preferred for 2D layouts) + +```html + +
+
Card 1
+
Card 2
+
Card 3
+
+ + +
+ +
Content
+
+``` + +### Container Patterns + +```html + +
+ Content +
+ + +
+
+ Content +
+
+``` + +--- + +## Typography Standards + +### Hierarchy + +```html + +

Main Heading

+

Section Heading

+

Subsection

+

Minor Heading

+ + +

Body text

+

Secondary text

+

Caption text

+``` + +### Font Loading + +**Always use Google Fonts**: + +```html + + + +``` + +**Apply in CSS**: + +```css +body { + font-family: 'Inter', sans-serif !important; +} +``` + +### Readability + +- **Line length**: 60-80 characters optimal +- **Line height**: 1.5-1.75 for body text +- **Font size**: Minimum 16px for body text +- **Contrast**: 4.5:1 minimum for normal text + +--- + +## Component Styling Patterns + +### Buttons + +```html + + + + + + + + +``` + +### Cards + +```html + +
+

Card Title

+

Card content

+
+ + +
+

Interactive Card

+

Hover for effect

+
+``` + +### Forms + +```html + +
+ + +
+ + +
+ + +
+``` + +--- + +## Accessibility Standards + +### ARIA Labels + +```html + + + + + +``` + +### Semantic HTML + +```html + +
...
+ +
...
+
...
+ +
...
+ + +
...
+ +
...
+``` + +### Focus States + +```css +/* Always provide visible focus states */ +button:focus-visible { + outline: 2px solid var(--ring); + outline-offset: 2px; +} + +/* Tailwind utility */ + +``` + +--- + +## Performance Optimization + +### CSS Loading + +```html + + + + + + +``` + +### Image Optimization + +```html + +Description +``` + +### Critical CSS + +```html + + + + + +``` + +--- + +## Best Practices + +### Do's ✅ + +- Use Tailwind utility classes for rapid development +- Load Tailwind via script tag for JIT compilation +- Use Flowbite as default component library +- Ensure all designs are mobile-first responsive +- Test at multiple breakpoints +- Use semantic HTML elements +- Provide ARIA labels for interactive elements +- Use CSS custom properties for theming +- Apply `!important` for framework overrides +- Ensure proper color contrast (WCAG AA) + +### Don'ts ❌ + +- Don't use Bootstrap blue without explicit request +- Don't load Tailwind as a stylesheet +- Don't skip responsive design +- Don't use div soup (use semantic HTML) +- Don't forget focus states +- Don't hardcode colors (use theme variables) +- Don't skip accessibility testing +- Don't use tiny touch targets (<44px) +- Don't mix color formats +- Don't over-use `!important` + +--- + +## Framework Alternatives + +If user requests a different framework: + +**Bootstrap**: +```html + + +``` + +**Bulma**: +```html + +``` + +**Foundation**: +```html + + +``` + +--- + +## References + +- [Tailwind CSS Documentation](https://tailwindcss.com/docs) +- [Flowbite Components](https://flowbite.com/docs/getting-started/introduction/) +- [WCAG Guidelines](https://www.w3.org/WAI/WCAG21/quickref/) +- [MDN Web Accessibility](https://developer.mozilla.org/en-US/docs/Web/Accessibility) diff --git a/.opencode/env.example b/.opencode/env.example new file mode 100644 index 0000000..4d6ba21 --- /dev/null +++ b/.opencode/env.example @@ -0,0 +1,24 @@ +# Telegram Bot Configuration +# Copy this file to .env and fill in your actual values + +# Your Telegram bot token (get from @BotFather) +TELEGRAM_BOT_TOKEN=your_bot_token_here + +# Your chat ID (get by messaging your bot and checking the API) +TELEGRAM_CHAT_ID=your_chat_id_here + +# Your bot username (optional, defaults to @OpenCode) +TELEGRAM_BOT_USERNAME=@YourBotUsername + +# Idle timeout in milliseconds (default: 5 minutes = 300000ms) +TELEGRAM_IDLE_TIMEOUT=300000 + +# Check interval in milliseconds (default: 30 seconds = 30000ms) +TELEGRAM_CHECK_INTERVAL=30000 + +# Enable/disable the plugin (true/false) +TELEGRAM_ENABLED=true + +# Gemini API Configuration +# Get your API key from https://makersuite.google.com/app/apikey +GEMINI_API_KEY=your_gemini_api_key_here diff --git a/.opencode/skills/context7/README.md b/.opencode/skills/context7/README.md new file mode 100644 index 0000000..bd53d61 --- /dev/null +++ b/.opencode/skills/context7/README.md @@ -0,0 +1,102 @@ +# Context7 Skill + +## Purpose + +Fetches **live, version-specific documentation** for external libraries and frameworks using the Context7 API. Ensures you always get current API patterns instead of potentially outdated training data. + +**Golden Rule**: Always fetch live docs for external libraries—training data may be outdated. + +## Quick Start + +### Recommended: Use ExternalScout Subagent + +The **ExternalScout** subagent is the recommended way to fetch external documentation. It handles: +- Library detection +- Query optimization +- Documentation filtering and sorting +- Formatted results with code examples + +**Invocation**: +``` +Use ExternalScout to fetch documentation for [Library Name]: [your specific question] +``` + +**Example**: +``` +Use ExternalScout to fetch documentation for Drizzle ORM: How do I set up modular schemas with PostgreSQL? +``` + +### Alternative: Direct Skill Usage + +You can also invoke the Context7 skill directly via bash: + +```bash +# Step 1: Search for library +curl -s "https://context7.com/api/v2/libs/search?libraryName=LIBRARY&query=TOPIC" | jq '.results[0]' + +# Step 2: Fetch documentation +curl -s "https://context7.com/api/v2/context?libraryId=LIBRARY_ID&query=OPTIMIZED_QUERY&type=txt" +``` + +See `SKILL.md` for detailed API documentation. + +## Supported Libraries + +See `library-registry.md` for the complete list of supported libraries including: +- **Database & ORM**: Drizzle, Prisma +- **Authentication**: Better Auth, NextAuth.js, Clerk +- **Frontend**: Next.js, React, TanStack Query/Router/Start +- **Infrastructure**: Cloudflare Workers, AWS Lambda, Vercel +- **UI**: Shadcn/ui, Radix UI, Tailwind CSS +- **State**: Zustand, Jotai +- **Validation**: Zod, React Hook Form +- **Testing**: Vitest, Playwright + +## Workflow + +``` +User Query + ↓ +ContextScout (searches internal context) + ↓ +No internal context found + ↓ +ContextScout recommends ExternalScout + ↓ +ExternalScout invoked + ├─ Reads library-registry.md + ├─ Detects library + ├─ Loads query patterns + ├─ Fetches from Context7 API + ├─ Filters & sorts results + └─ Returns formatted documentation + ↓ +User receives current, actionable docs +``` + +## Files + +- **`SKILL.md`** - Context7 API documentation and usage +- **`library-registry.md`** - Supported libraries, aliases, and query patterns +- **`README.md`** - This file (overview and quick start) + +## Adding New Libraries + +To add a new library to the registry: + +1. Edit `library-registry.md` +2. Add entry under appropriate category: + ```markdown + #### Library Name + - **Aliases**: `alias1`, `alias2`, `package-name` + - **Docs**: https://example.com/docs + - **Context7**: `use context7 for library-name` + - **Common topics**: topic1, topic2, topic3 + ``` +3. (Optional) Add query optimization patterns +4. ExternalScout will automatically detect the new library + +## Related + +- **ExternalScout**: `.opencode/agent/subagents/core/externalscout.md` +- **ContextScout**: `.opencode/agent/subagents/core/contextscout.md` diff --git a/.opencode/skills/context7/SKILL.md b/.opencode/skills/context7/SKILL.md new file mode 100644 index 0000000..76160b2 --- /dev/null +++ b/.opencode/skills/context7/SKILL.md @@ -0,0 +1,85 @@ +--- +name: context7 +description: Retrieve up-to-date documentation for software libraries, frameworks, and components via the Context7 API. This skill should be used when looking up documentation for any programming library or framework, finding code examples for specific APIs or features, verifying correct usage of library functions, or obtaining current information about library APIs that may have changed since training. +--- + +# Context7 + +## Overview + +This skill enables retrieval of current documentation for software libraries and components by querying the Context7 API via curl. Use it instead of relying on potentially outdated training data. + +## Workflow + +### Step 1: Search for the Library + +To find the Context7 library ID, query the search endpoint: + +```bash +curl -s "https://context7.com/api/v2/libs/search?libraryName=LIBRARY_NAME&query=TOPIC" | jq '.results[0]' +``` + +**Parameters:** +- `libraryName` (required): The library name to search for (e.g., "react", "nextjs", "fastapi", "axios") +- `query` (required): A description of the topic for relevance ranking + +**Response fields:** +- `id`: Library identifier for the context endpoint (e.g., `/websites/react_dev_reference`) +- `title`: Human-readable library name +- `description`: Brief description of the library +- `totalSnippets`: Number of documentation snippets available + +### Step 2: Fetch Documentation + +To retrieve documentation, use the library ID from step 1: + +```bash +curl -s "https://context7.com/api/v2/context?libraryId=LIBRARY_ID&query=TOPIC&type=txt" +``` + +**Parameters:** +- `libraryId` (required): The library ID from search results +- `query` (required): The specific topic to retrieve documentation for +- `type` (optional): Response format - `json` (default) or `txt` (plain text, more readable) + +## Examples + +### React hooks documentation + +```bash +# Find React library ID +curl -s "https://context7.com/api/v2/libs/search?libraryName=react&query=hooks" | jq '.results[0].id' +# Returns: "/websites/react_dev_reference" + +# Fetch useState documentation +curl -s "https://context7.com/api/v2/context?libraryId=/websites/react_dev_reference&query=useState&type=txt" +``` + +### Next.js routing documentation + +```bash +# Find Next.js library ID +curl -s "https://context7.com/api/v2/libs/search?libraryName=nextjs&query=routing" | jq '.results[0].id' + +# Fetch app router documentation +curl -s "https://context7.com/api/v2/context?libraryId=/vercel/next.js&query=app+router&type=txt" +``` + +### FastAPI dependency injection + +```bash +# Find FastAPI library ID +curl -s "https://context7.com/api/v2/libs/search?libraryName=fastapi&query=dependencies" | jq '.results[0].id' + +# Fetch dependency injection documentation +curl -s "https://context7.com/api/v2/context?libraryId=/fastapi/fastapi&query=dependency+injection&type=txt" +``` + +## Tips + +- Use `type=txt` for more readable output +- Use `jq` to filter and format JSON responses +- Be specific with the `query` parameter to improve relevance ranking +- If the first search result is not correct, check additional results in the array +- URL-encode query parameters containing spaces (use `+` or `%20`) +- No API key is required for basic usage (rate-limited) \ No newline at end of file diff --git a/.opencode/skills/context7/library-registry.md b/.opencode/skills/context7/library-registry.md new file mode 100644 index 0000000..4c2f5d4 --- /dev/null +++ b/.opencode/skills/context7/library-registry.md @@ -0,0 +1,290 @@ +# External Library Registry + +## Purpose + +This file lists external libraries/frameworks that should use **ExternalScout** (via Context7) for live documentation instead of relying on potentially outdated training data. + +## When to Use This + +**ContextScout** checks this list when: +1. User asks about a library/framework +2. No internal context exists in `.opencode/context/development/frameworks/` +3. Query matches a library name below + +**Action**: Recommend **ExternalScout** subagent + +--- + +## Supported Libraries + +### Database & ORM + +#### Drizzle ORM +- **Aliases**: `drizzle`, `drizzle-orm`, `drizzle orm` +- **Docs**: https://orm.drizzle.team/ +- **Context7**: `use context7 for drizzle` +- **Common topics**: schema organization, migrations, relational queries, transactions, TypeScript types + +#### Prisma +- **Aliases**: `prisma` +- **Docs**: https://www.prisma.io/docs +- **Context7**: `use context7 for prisma` +- **Common topics**: schema, migrations, client, relations, TypeScript + +--- + +### Authentication + +#### Better Auth +- **Aliases**: `better-auth`, `better auth`, `betterauth` +- **Docs**: https://www.better-auth.com/docs +- **Context7**: `use context7 for better-auth` +- **Common topics**: Next.js integration, Drizzle adapter, social providers, session management, 2FA + +#### NextAuth.js +- **Aliases**: `nextauth`, `next-auth`, `nextauth.js` +- **Docs**: https://next-auth.js.org/ +- **Context7**: `use context7 for nextauth` +- **Common topics**: providers, callbacks, sessions, JWT + +#### Clerk +- **Aliases**: `clerk` +- **Docs**: https://clerk.com/docs +- **Context7**: `use context7 for clerk` +- **Common topics**: authentication, user management, organizations + +--- + +### Frontend Frameworks + +#### Next.js +- **Aliases**: `nextjs`, `next.js`, `next` +- **Docs**: https://nextjs.org/docs +- **Context7**: `use context7 for nextjs` +- **Common topics**: App Router, Server Actions, Server Components, routing, middleware, API routes + +#### React +- **Aliases**: `react`, `reactjs`, `react.js` +- **Docs**: https://react.dev/ +- **Context7**: `use context7 for react` +- **Common topics**: hooks, components, state, effects, context + +#### TanStack Query +- **Aliases**: `tanstack query`, `react query`, `@tanstack/react-query` +- **Docs**: https://tanstack.com/query/latest +- **Context7**: `use context7 for tanstack query` +- **Common topics**: useQuery, useMutation, prefetching, caching, Server Components + +#### TanStack Router +- **Aliases**: `tanstack router`, `@tanstack/react-router` +- **Docs**: https://tanstack.com/router/latest +- **Context7**: `use context7 for tanstack router` +- **Common topics**: routing, type-safe routes, loaders, navigation + +#### TanStack Start +- **Aliases**: `tanstack start`, `@tanstack/start` +- **Docs**: https://tanstack.com/start/latest +- **Context7**: `use context7 for tanstack start` +- **Common topics**: full-stack setup, server functions, file routing + +--- + +### Infrastructure & Deployment + +#### Cloudflare Workers +- **Aliases**: `cloudflare workers`, `cloudflare`, `workers`, `cf workers` +- **Docs**: https://developers.cloudflare.com/workers +- **Context7**: `use context7 for cloudflare workers` +- **Common topics**: routing, KV storage, Durable Objects, bindings, middleware + +#### AWS Lambda +- **Aliases**: `aws lambda`, `lambda`, `aws λ` +- **Docs**: https://docs.aws.amazon.com/lambda +- **Context7**: `use context7 for aws lambda` +- **Common topics**: handlers, layers, environment variables, triggers, TypeScript + +#### Vercel +- **Aliases**: `vercel` +- **Docs**: https://vercel.com/docs +- **Context7**: `use context7 for vercel` +- **Common topics**: deployment, environment variables, edge functions, serverless + +--- + +### UI Libraries & Styling + +#### Shadcn/ui +- **Aliases**: `shadcn`, `shadcn/ui`, `shadcn-ui` +- **Docs**: https://ui.shadcn.com/ +- **Context7**: `use context7 for shadcn` +- **Common topics**: components, installation, theming, customization + +#### Radix UI +- **Aliases**: `radix`, `radix ui`, `radix-ui`, `@radix-ui` +- **Docs**: https://www.radix-ui.com/ +- **Context7**: `use context7 for radix` +- **Common topics**: primitives, accessibility, composition + +#### Tailwind CSS +- **Aliases**: `tailwind`, `tailwindcss`, `tailwind css` +- **Docs**: https://tailwindcss.com/docs +- **Context7**: `use context7 for tailwind` +- **Common topics**: configuration, utilities, responsive design, dark mode + +--- + +### State Management + +#### Zustand +- **Aliases**: `zustand` +- **Docs**: https://zustand-demo.pmnd.rs/ +- **Context7**: `use context7 for zustand` +- **Common topics**: store creation, selectors, middleware, TypeScript + +#### Jotai +- **Aliases**: `jotai` +- **Docs**: https://jotai.org/ +- **Context7**: `use context7 for jotai` +- **Common topics**: atoms, async atoms, utilities + +--- + +### Validation & Forms + +#### Zod +- **Aliases**: `zod` +- **Docs**: https://zod.dev/ +- **Context7**: `use context7 for zod` +- **Common topics**: schema validation, TypeScript inference, parsing, refinements + +#### React Hook Form +- **Aliases**: `react hook form`, `react-hook-form`, `rhf` +- **Docs**: https://react-hook-form.com/ +- **Context7**: `use context7 for react hook form` +- **Common topics**: register, validation, errors, TypeScript + +--- + +### Testing + +#### Vitest +- **Aliases**: `vitest` +- **Docs**: https://vitest.dev/ +- **Context7**: `use context7 for vitest` +- **Common topics**: configuration, testing, mocking, coverage + +#### Playwright +- **Aliases**: `playwright` +- **Docs**: https://playwright.dev/ +- **Context7**: `use context7 for playwright` +- **Common topics**: browser automation, testing, selectors, assertions + +--- + +## Detection Patterns + +ContextScout and ExternalScout should match queries containing: +- Library name (case-insensitive) +- Common variations (e.g., "next.js" vs "nextjs") +- Package names (e.g., "@tanstack/react-query") + +**Examples**: +- "How do I use **Drizzle** with PostgreSQL?" → Match: Drizzle ORM +- "Show me **Next.js** App Router setup" → Match: Next.js +- "**TanStack Query** with Server Components" → Match: TanStack Query +- "**Better Auth** integration" → Match: Better Auth + +--- + +## Query Optimization Patterns + +### Drizzle ORM + +| User Intent | Optimized Query | +|-------------|-----------------| +| Setup/Installation | `PostgreSQL+setup+configuration+TypeScript+installation` | +| Modular schemas | `modular+schema+organization+domain+driven+design` | +| Relations | `relational+queries+one+to+many+joins+with+relations` | +| Migrations | `drizzle-kit+migrations+generate+push+PostgreSQL` | +| Transactions | `database+transactions+patterns+TypeScript` | +| Type safety | `TypeScript+type+inference+schema+types+inferInsert` | + +### Better Auth + +| User Intent | Optimized Query | +|-------------|-----------------| +| Setup | `setup+configuration+Next.js+TypeScript+installation` | +| Next.js integration | `Next.js+App+Router+integration+setup+configuration` | +| Drizzle adapter | `Drizzle+adapter+PostgreSQL+schema+generation+configuration` | +| Social providers | `social+providers+OAuth+GitHub+Google+setup` | +| Email/password | `email+password+authentication+signup+signin` | +| Session management | `session+management+cookies+JWT+middleware` | + +### Next.js + +| User Intent | Optimized Query | +|-------------|-----------------| +| App Router | `App+Router+file+conventions+layouts+pages+routing` | +| Server Actions | `Server+Actions+form+mutations+revalidation+TypeScript` | +| Server Components | `React+Server+Components+async+data+fetching+patterns` | +| Dynamic routes | `dynamic+routes+params+TypeScript+generateStaticParams` | +| Middleware | `middleware+authentication+redirects+headers+cookies` | +| API routes | `API+routes+route+handlers+TypeScript+POST+GET` | + +### TanStack Query + +| User Intent | Optimized Query | +|-------------|-----------------| +| Setup | `setup+QueryClient+provider+Next.js+TypeScript` | +| Data fetching | `useQuery+data+fetching+TypeScript+patterns+async` | +| Mutations | `useMutation+optimistic+updates+invalidation+TypeScript` | +| Prefetching | `prefetchQuery+Server+Components+hydration+Next.js` | +| Caching | `cache+configuration+staleTime+gcTime+invalidation` | + +### Cloudflare Workers + +| User Intent | Optimized Query | +|-------------|-----------------| +| Setup | `getting+started+setup+TypeScript+wrangler+configuration` | +| Routing | `routing+itty-router+hono+request+handling` | +| KV storage | `KV+storage+key+value+bindings+TypeScript` | +| Durable Objects | `Durable+Objects+state+WebSockets+coordination` | + +### AWS Lambda + +| User Intent | Optimized Query | +|-------------|-----------------| +| Setup | `getting+started+setup+TypeScript+handler+configuration` | +| Handlers | `handler+function+event+context+TypeScript+patterns` | +| Layers | `layers+dependencies+shared+code+deployment` | +| Environment variables | `environment+variables+secrets+configuration+SSM` | + +--- + +## Adding New Libraries + +To add a new library: +1. Add entry under appropriate category +2. Include: Name, aliases, docs link, Context7 command, common topics +3. (Optional) Add query optimization patterns +4. Update ExternalScout if needed (usually automatic) + +**Template**: +```markdown +#### Library Name +- **Aliases**: `alias1`, `alias2`, `package-name` +- **Docs**: https://example.com/docs +- **Context7**: `use context7 for library-name` +- **Common topics**: topic1, topic2, topic3 +``` + +--- + +## Usage by ExternalScout + +ExternalScout uses this file to: +1. **Detect** which library the user is asking about +2. **Load** query optimization patterns for that library +3. **Build** optimized Context7 queries +4. **Fetch** live documentation +5. **Return** filtered, relevant results diff --git a/.opencode/skills/context7/navigation.md b/.opencode/skills/context7/navigation.md new file mode 100644 index 0000000..30f848c --- /dev/null +++ b/.opencode/skills/context7/navigation.md @@ -0,0 +1,51 @@ +# Context7 Skill Navigation + +**Purpose**: Live documentation fetching for external libraries via Context7 API + +--- + +## Structure + +``` +context7/ +├── navigation.md # This file +├── README.md # Quick start and workflow +├── SKILL.md # Context7 API documentation +└── library-registry.md # Supported libraries and query patterns +``` + +--- + +## Quick Routes + +| Task | Path | +|------|------| +| **Quick start** | `README.md` | +| **API reference** | `SKILL.md` | +| **Supported libraries** | `library-registry.md` (lines 18-181) | +| **Query patterns** | `library-registry.md` (lines 199-261) | +| **Add new library** | `library-registry.md` (lines 264-279) | +| **ExternalScout integration** | `README.md` (lines 9-26) | + +--- + +## By Purpose + +**Using Context7**: +- Quick start → `README.md` +- API details → `SKILL.md` + +**Adding Libraries**: +- Template → `library-registry.md` (lines 272-279) +- Supported list → `library-registry.md` (lines 18-181) + +**Integration**: +- ContextScout workflow → `README.md` (lines 54-73) +- ExternalScout subagent → `.opencode/agent/subagents/core/externalscout.md` + +--- + +## Related + +- **ExternalScout**: `.opencode/agent/subagents/core/externalscout.md` +- **ContextScout**: `.opencode/agent/subagents/core/contextscout.md` diff --git a/.opencode/skills/task-management/SKILL.md b/.opencode/skills/task-management/SKILL.md new file mode 100644 index 0000000..8143066 --- /dev/null +++ b/.opencode/skills/task-management/SKILL.md @@ -0,0 +1,399 @@ +--- +name: task-management +description: Task management CLI for tracking and managing feature subtasks with status, dependencies, and validation +version: 1.0.0 +author: opencode +type: skill +category: development +tags: + - tasks + - management + - tracking + - dependencies + - cli +--- + +# Task Management Skill + +> **Purpose**: Track, manage, and validate feature implementations with atomic task breakdowns, dependency resolution, and progress monitoring. + +--- + +## What I Do + +I provide a command-line interface for managing task breakdowns created by the TaskManager subagent. I help you: + +- **Track progress** - See status of all features and their subtasks +- **Find next tasks** - Show eligible tasks (dependencies satisfied) +- **Identify blocked tasks** - See what's blocked and why +- **Manage completion** - Mark subtasks as complete with summaries +- **Validate integrity** - Check JSON files and dependency trees + +--- + +## How to Use Me + +### Quick Start + +```bash +# Show all task statuses +bash .opencode/skills/task-management/router.sh status + +# Show next eligible tasks +bash .opencode/skills/task-management/router.sh next + +# Show blocked tasks +bash .opencode/skills/task-management/router.sh blocked + +# Mark a task complete +bash .opencode/skills/task-management/router.sh complete "summary" + +# Validate all tasks +bash .opencode/skills/task-management/router.sh validate +``` + +### Command Reference + +| Command | Description | +|---------|-------------| +| `status [feature]` | Show task status summary for all features or specific one | +| `next [feature]` | Show next eligible tasks (dependencies satisfied) | +| `parallel [feature]` | Show parallelizable tasks ready to run | +| `deps ` | Show dependency tree for a specific subtask | +| `blocked [feature]` | Show blocked tasks and why | +| `complete "summary"` | Mark subtask complete with summary | +| `validate [feature]` | Validate JSON files and dependencies | +| `help` | Show help message | + +--- + +## Examples + +### Check Overall Progress + +```bash +$ bash .opencode/skills/task-management/router.sh status + +[my-feature] My Feature Implementation + Status: active | Progress: 45% (5/11) + Pending: 3 | In Progress: 2 | Completed: 5 | Blocked: 1 +``` + +### Find What's Next + +```bash +$ bash .opencode/skills/task-management/router.sh next + +=== Ready Tasks (deps satisfied) === + +[my-feature] + 06 - Implement API endpoint [sequential] + 08 - Write unit tests [parallel] +``` + +### Mark Complete + +```bash +$ bash .opencode/skills/task-management/router.sh complete my-feature 05 "Implemented authentication module" + +✓ Marked my-feature/05 as completed + Summary: Implemented authentication module + Progress: 6/11 +``` + +### Check Dependencies + +```bash +$ bash .opencode/skills/task-management/router.sh deps my-feature 07 + +=== Dependency Tree: my-feature/07 === + +07 - Write integration tests [pending] + ├── ✓ 05 - Implement authentication module [completed] + └── ○ 06 - Implement API endpoint [in_progress] +``` + +### Validate Everything + +```bash +$ bash .opencode/skills/task-management/router.sh validate + +=== Validation Results === + +[my-feature] + ✓ All checks passed +``` + +--- + +## Architecture + +``` +.opencode/skills/task-management/ +├── SKILL.md # This file +├── router.sh # CLI router (entry point) +└── scripts/ + └── task-cli.ts # Task management CLI implementation +``` + +--- + +## Task File Structure + +Tasks are stored in `.tmp/tasks/` at the project root: + +``` +.tmp/tasks/ +├── {feature-slug}/ +│ ├── task.json # Feature-level metadata +│ ├── subtask_01.json # Subtask definitions +│ ├── subtask_02.json +│ └── ... +└── completed/ + └── {feature-slug}/ # Completed tasks +``` + +### task.json Schema + +```json +{ + "id": "my-feature", + "name": "My Feature", + "status": "active", + "objective": "Implement X", + "context_files": ["docs/spec.md"], + "reference_files": ["src/existing.ts"], + "exit_criteria": ["Tests pass", "Code reviewed"], + "subtask_count": 5, + "completed_count": 2, + "created_at": "2026-01-11T10:00:00Z", + "completed_at": null +} +``` + +### subtask_##.json Schema + +```json +{ + "id": "my-feature-05", + "seq": "05", + "title": "Implement authentication", + "status": "pending", + "depends_on": ["03", "04"], + "parallel": false, + "suggested_agent": "coder-agent", + "context_files": ["docs/auth.md"], + "reference_files": ["src/auth-old.ts"], + "acceptance_criteria": ["Login works", "JWT tokens valid"], + "deliverables": ["auth.ts", "auth.test.ts"], + "started_at": null, + "completed_at": null, + "completion_summary": null +} +``` + +--- + +## Integration with TaskManager + +The TaskManager subagent creates task files using this format. When you delegate to TaskManager: + +```javascript +task( + subagent_type="TaskManager", + description="Implement feature X", + prompt="Break down this feature into atomic subtasks..." +) +``` + +TaskManager creates: +1. `.tmp/tasks/{feature}/task.json` - Feature metadata +2. `.tmp/tasks/{feature}/subtask_XX.json` - Individual subtasks + +You can then use this skill to track and manage progress. + +--- + +## Key Concepts + +### 1. Dependency Resolution +Subtasks can depend on other subtasks. A task is "ready" only when all its dependencies are complete. + +### 2. Parallel Execution +Set `parallel: true` to indicate a subtask can run alongside other parallel tasks with satisfied dependencies. + +### 3. Status Tracking +- **pending** - Not started, waiting for dependencies +- **in_progress** - Currently being worked on +- **completed** - Finished with summary +- **blocked** - Explicitly blocked (not waiting for deps) + +### 4. Exit Criteria +Each feature has exit_criteria that must be met before marking the feature complete. + +### 5. Validation Rules + +The `validate` command performs comprehensive checks on task files: + +**Task-Level Validation:** +- ✅ task.json file exists for the feature +- ✅ Task ID matches feature slug +- ✅ Subtask count in task.json matches actual subtask files +- ✅ All required fields are present + +**Subtask-Level Validation:** +- ✅ All subtask IDs start with feature name (e.g., "my-feature-01") +- ✅ Sequence numbers are unique and properly formatted (01, 02, etc.) +- ✅ All dependencies reference existing subtasks +- ✅ No circular dependencies exist +- ✅ Each subtask has acceptance criteria defined +- ✅ Each subtask has deliverables specified +- ✅ Status values are valid (pending, in_progress, completed, blocked) + +**Dependency Validation:** +- ✅ All depends_on references point to existing subtasks +- ✅ No task depends on itself +- ✅ No circular dependency chains +- ✅ Dependency graph is acyclic + +Run `validate` regularly to catch issues early: +```bash +bash .opencode/skills/task-management/router.sh validate my-feature +``` + +### 6. Context and Reference Files +- **context_files** - Standards, conventions, and guidelines to follow +- **reference_files** - Existing project files to look at or build upon + +--- + +## Workflow Integration + +### With TaskManager Subagent + +1. **TaskManager creates tasks** → Generates `.tmp/tasks/{feature}/` structure +2. **You use this skill to track** → Monitor progress with `status`, `next`, `blocked` +3. **You mark tasks complete** → Use `complete` command with summaries +4. **Skill validates integrity** → Use `validate` to check consistency + +### With Other Subagents + +Working agents (CoderAgent, TestEngineer, etc.) execute subtasks and report completion. Use this skill to: +- Find next available tasks with `next` +- Check what's blocking progress with `blocked` +- Validate task definitions with `validate` + +--- + +## Common Workflows + +### Starting a New Feature + +```bash +# 1. TaskManager creates the task structure +task(subagent_type="TaskManager", description="Implement feature X", ...) + +# 2. Check what's ready +bash .opencode/skills/task-management/router.sh next + +# 3. Delegate first task to working agent +task(subagent_type="CoderAgent", description="Implement subtask 01", ...) +``` + +### Tracking Progress + +```bash +# Check overall status +bash .opencode/skills/task-management/router.sh status my-feature + +# See what's next +bash .opencode/skills/task-management/router.sh next my-feature + +# Check what's blocked +bash .opencode/skills/task-management/router.sh blocked my-feature +``` + +### Completing Tasks + +```bash +# After working agent finishes +bash .opencode/skills/task-management/router.sh complete my-feature 05 "Implemented auth module with JWT support" + +# Check progress +bash .opencode/skills/task-management/router.sh status my-feature + +# Find next task +bash .opencode/skills/task-management/router.sh next my-feature +``` + +### Validating Everything + +```bash +# Validate all tasks +bash .opencode/skills/task-management/router.sh validate + +# Validate specific feature +bash .opencode/skills/task-management/router.sh validate my-feature +``` + +--- + +## Tips & Best Practices + +### 1. Use Meaningful Summaries +When marking tasks complete, provide clear summaries: +```bash +# Good +complete my-feature 05 "Implemented JWT authentication with refresh tokens and error handling" + +# Avoid +complete my-feature 05 "Done" +``` + +### 2. Check Dependencies Before Starting +```bash +# See what a task depends on +bash .opencode/skills/task-management/router.sh deps my-feature 07 +``` + +### 3. Identify Parallelizable Work +```bash +# Find tasks that can run in parallel +bash .opencode/skills/task-management/router.sh parallel my-feature +``` + +### 4. Regular Validation +```bash +# Validate regularly to catch issues early +bash .opencode/skills/task-management/router.sh validate +``` + +--- + +## Troubleshooting + +### "task-cli.ts not found" +Make sure you're running from the project root or the router.sh can find it. + +### "No tasks found" +Run `status` to see if any tasks have been created yet. Use TaskManager to create tasks first. + +### "Dependency not satisfied" +Check the dependency tree with `deps` to see what's blocking the task. + +### "Validation failed" +Run `validate` to see specific issues, then check the JSON files in `.tmp/tasks/`. + +--- + +## File Locations + +- **Skill**: `.opencode/skills/task-management/` +- **Router**: `.opencode/skills/task-management/router.sh` +- **CLI**: `.opencode/skills/task-management/scripts/task-cli.ts` +- **Tasks**: `.tmp/tasks/` (created by TaskManager) +- **Documentation**: `.opencode/skills/task-management/SKILL.md` (this file) + +--- + +**Task Management Skill** - Track, manage, and validate your feature implementations! diff --git a/.opencode/skills/task-management/router.sh b/.opencode/skills/task-management/router.sh new file mode 100644 index 0000000..4066c2c --- /dev/null +++ b/.opencode/skills/task-management/router.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +############################################################################# +# Task Management Skill Router +# Routes to task-cli.ts with proper path resolution and command handling +############################################################################# + +set -e + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +CLI_SCRIPT="$SCRIPT_DIR/scripts/task-cli.ts" + +# Show help +show_help() { + cat << 'HELP' +📋 Task Management Skill +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +Usage: router.sh [COMMAND] [OPTIONS] + +COMMANDS: + status [feature] Show task status summary + next [feature] Show next eligible tasks + parallel [feature] Show parallelizable tasks + deps Show dependency tree + blocked [feature] Show blocked tasks + complete "msg" Mark subtask complete + validate [feature] Validate JSON files + help Show this help message + +EXAMPLES: + ./router.sh status + ./router.sh status my-feature + ./router.sh next + ./router.sh deps my-feature 05 + ./router.sh complete my-feature 05 "Implemented auth module" + ./router.sh validate + +FEATURES: + ✓ Track progress across all features + ✓ Find next eligible tasks (dependencies satisfied) + ✓ Identify blocked tasks + ✓ Mark subtasks complete with summaries + ✓ Validate task integrity + +For more info, see: .opencode/skills/task-management/SKILL.md +HELP +} + +# Check if CLI script exists +if [ ! -f "$CLI_SCRIPT" ]; then + echo "❌ Error: task-cli.ts not found at $CLI_SCRIPT" + exit 1 +fi + +# Find project root +find_project_root() { + local dir + dir="$(pwd)" + while [ "$dir" != "/" ]; do + if [ -d "$dir/.git" ] || [ -f "$dir/package.json" ]; then + echo "$dir" + return 0 + fi + dir="$(dirname "$dir")" + done + pwd + return 1 +} + +# Handle help +if [ "$1" = "help" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then + show_help + exit 0 +fi + +# If no arguments, show help +if [ $# -eq 0 ]; then + show_help + exit 0 +fi + +PROJECT_ROOT="$(find_project_root)" + +# Run the task CLI with all arguments +cd "$PROJECT_ROOT" && npx ts-node "$CLI_SCRIPT" "$@" diff --git a/.opencode/skills/task-management/scripts/task-cli.ts b/.opencode/skills/task-management/scripts/task-cli.ts new file mode 100644 index 0000000..64b4068 --- /dev/null +++ b/.opencode/skills/task-management/scripts/task-cli.ts @@ -0,0 +1,553 @@ +#!/usr/bin/env npx ts-node +/** + * Task Management CLI + * + * Usage: npx ts-node task-cli.ts [feature] [args...] + * + * Commands: + * status [feature] - Show task status summary + * next [feature] - Show next eligible tasks + * parallel [feature] - Show parallelizable tasks ready to run + * deps - Show dependency tree for a task + * blocked [feature] - Show blocked tasks and why + * complete "summary" - Mark task completed + * validate [feature] - Validate JSON files and dependencies + * + * Task files are stored in .tmp/tasks/ at the project root: + * .tmp/tasks/{feature-slug}/task.json + * .tmp/tasks/{feature-slug}/subtask_01.json + * .tmp/tasks/completed/{feature-slug}/ + */ + +const fs = require('fs'); +const path = require('path'); + +// Find project root (look for .git or package.json) +function findProjectRoot(): string { + let dir = process.cwd(); + while (dir !== path.dirname(dir)) { + if (fs.existsSync(path.join(dir, '.git')) || fs.existsSync(path.join(dir, 'package.json'))) { + return dir; + } + dir = path.dirname(dir); + } + return process.cwd(); +} + +const PROJECT_ROOT = findProjectRoot(); +const TASKS_DIR = path.join(PROJECT_ROOT, '.tmp', 'tasks'); +const COMPLETED_DIR = path.join(TASKS_DIR, 'completed'); + +interface Task { + id: string; + name: string; + status: 'active' | 'completed' | 'blocked' | 'archived'; + objective: string; + context_files: string[]; + reference_files?: string[]; + exit_criteria: string[]; + subtask_count: number; + completed_count: number; + created_at: string; + completed_at: string | null; +} + +interface Subtask { + id: string; + seq: string; + title: string; + status: 'pending' | 'in_progress' | 'completed' | 'blocked'; + depends_on: string[]; + parallel: boolean; + context_files: string[]; + reference_files?: string[]; + acceptance_criteria: string[]; + deliverables: string[]; + agent_id: string | null; + suggested_agent?: string; + started_at: string | null; + completed_at: string | null; + completion_summary: string | null; +} + +// Helpers +function getFeatureDirs(): string[] { + if (!fs.existsSync(TASKS_DIR)) return []; + return fs.readdirSync(TASKS_DIR).filter((f: string) => { + const fullPath = path.join(TASKS_DIR, f); + return fs.statSync(fullPath).isDirectory() && f !== 'completed'; + }); +} + +function loadTask(feature: string): Task | null { + const taskPath = path.join(TASKS_DIR, feature, 'task.json'); + if (!fs.existsSync(taskPath)) return null; + return JSON.parse(fs.readFileSync(taskPath, 'utf-8')); +} + +function loadSubtasks(feature: string): Subtask[] { + const featureDir = path.join(TASKS_DIR, feature); + if (!fs.existsSync(featureDir)) return []; + + const files = fs.readdirSync(featureDir) + .filter((f: string) => f.match(/^subtask_\d{2}\.json$/)) + .sort(); + + return files.map((f: string) => JSON.parse(fs.readFileSync(path.join(featureDir, f), 'utf-8'))); +} + +function saveSubtask(feature: string, subtask: Subtask): void { + const subtaskPath = path.join(TASKS_DIR, feature, `subtask_${subtask.seq}.json`); + fs.writeFileSync(subtaskPath, JSON.stringify(subtask, null, 2)); +} + +function saveTask(feature: string, task: Task): void { + const taskPath = path.join(TASKS_DIR, feature, 'task.json'); + fs.writeFileSync(taskPath, JSON.stringify(task, null, 2)); +} + +// Commands +function cmdStatus(feature?: string): void { + const features = feature ? [feature] : getFeatureDirs(); + + if (features.length === 0) { + console.log('No active features found.'); + return; + } + + for (const f of features) { + const task = loadTask(f); + const subtasks = loadSubtasks(f); + + if (!task) { + console.log(`\n[${f}] - No task.json found`); + continue; + } + + const counts = { + pending: subtasks.filter(s => s.status === 'pending').length, + in_progress: subtasks.filter(s => s.status === 'in_progress').length, + completed: subtasks.filter(s => s.status === 'completed').length, + blocked: subtasks.filter(s => s.status === 'blocked').length, + }; + + const progress = subtasks.length > 0 + ? Math.round((counts.completed / subtasks.length) * 100) + : 0; + + console.log(`\n[${f}] ${task.name}`); + console.log(` Status: ${task.status} | Progress: ${progress}% (${counts.completed}/${subtasks.length})`); + console.log(` Pending: ${counts.pending} | In Progress: ${counts.in_progress} | Completed: ${counts.completed} | Blocked: ${counts.blocked}`); + } +} + +function cmdNext(feature?: string): void { + const features = feature ? [feature] : getFeatureDirs(); + + console.log('\n=== Ready Tasks (deps satisfied) ===\n'); + + for (const f of features) { + const subtasks = loadSubtasks(f); + const completedSeqs = new Set(subtasks.filter(s => s.status === 'completed').map(s => s.seq)); + + const ready = subtasks.filter(s => { + if (s.status !== 'pending') return false; + return s.depends_on.every(dep => completedSeqs.has(dep)); + }); + + if (ready.length > 0) { + console.log(`[${f}]`); + for (const s of ready) { + const parallel = s.parallel ? '[parallel]' : '[sequential]'; + console.log(` ${s.seq} - ${s.title} ${parallel}`); + } + console.log(); + } + } +} + +function cmdParallel(feature?: string): void { + const features = feature ? [feature] : getFeatureDirs(); + + console.log('\n=== Parallelizable Tasks Ready Now ===\n'); + + for (const f of features) { + const subtasks = loadSubtasks(f); + const completedSeqs = new Set(subtasks.filter(s => s.status === 'completed').map(s => s.seq)); + + const parallel = subtasks.filter(s => { + if (s.status !== 'pending') return false; + if (!s.parallel) return false; + return s.depends_on.every(dep => completedSeqs.has(dep)); + }); + + if (parallel.length > 0) { + console.log(`[${f}] - ${parallel.length} parallel tasks:`); + for (const s of parallel) { + console.log(` ${s.seq} - ${s.title}`); + } + console.log(); + } + } +} + +function cmdDeps(feature: string, seq: string): void { + const subtasks = loadSubtasks(feature); + const target = subtasks.find(s => s.seq === seq); + + if (!target) { + console.log(`Task ${seq} not found in ${feature}`); + return; + } + + console.log(`\n=== Dependency Tree: ${feature}/${seq} ===\n`); + console.log(`${seq} - ${target.title} [${target.status}]`); + + if (target.depends_on.length === 0) { + console.log(' └── (no dependencies)'); + return; + } + + const printDeps = (seqs: string[], indent: string = ' '): void => { + for (let i = 0; i < seqs.length; i++) { + const depSeq = seqs[i]; + const dep = subtasks.find(s => s.seq === depSeq); + const isLast = i === seqs.length - 1; + const branch = isLast ? '└──' : '├──'; + + if (dep) { + const statusIcon = dep.status === 'completed' ? '✓' : dep.status === 'in_progress' ? '~' : '○'; + console.log(`${indent}${branch} ${statusIcon} ${depSeq} - ${dep.title} [${dep.status}]`); + if (dep.depends_on.length > 0) { + const newIndent = indent + (isLast ? ' ' : '│ '); + printDeps(dep.depends_on, newIndent); + } + } else { + console.log(`${indent}${branch} ? ${depSeq} - NOT FOUND`); + } + } + }; + + printDeps(target.depends_on); +} + +function cmdBlocked(feature?: string): void { + const features = feature ? [feature] : getFeatureDirs(); + + console.log('\n=== Blocked Tasks ===\n'); + + for (const f of features) { + const subtasks = loadSubtasks(f); + const completedSeqs = new Set(subtasks.filter(s => s.status === 'completed').map(s => s.seq)); + + const blocked = subtasks.filter(s => { + if (s.status === 'blocked') return true; + if (s.status !== 'pending') return false; + return !s.depends_on.every(dep => completedSeqs.has(dep)); + }); + + if (blocked.length > 0) { + console.log(`[${f}]`); + for (const s of blocked) { + const waitingFor = s.depends_on.filter(dep => !completedSeqs.has(dep)); + const reason = s.status === 'blocked' + ? 'explicitly blocked' + : `waiting: ${waitingFor.join(', ')}`; + console.log(` ${s.seq} - ${s.title} (${reason})`); + } + console.log(); + } + } +} + +function cmdComplete(feature: string, seq: string, summary: string): void { + if (summary.length > 200) { + console.log('Error: Summary must be max 200 characters'); + process.exit(1); + } + + const subtasks = loadSubtasks(feature); + const subtask = subtasks.find(s => s.seq === seq); + + if (!subtask) { + console.log(`Task ${seq} not found in ${feature}`); + process.exit(1); + } + + subtask.status = 'completed'; + subtask.completed_at = new Date().toISOString(); + subtask.completion_summary = summary; + + saveSubtask(feature, subtask); + + // Update task.json counts + const task = loadTask(feature); + if (task) { + const newSubtasks = loadSubtasks(feature); + task.completed_count = newSubtasks.filter(s => s.status === 'completed').length; + saveTask(feature, task); + } + + console.log(`\n✓ Marked ${feature}/${seq} as completed`); + console.log(` Summary: ${summary}`); + + if (task) { + console.log(` Progress: ${task.completed_count}/${task.subtask_count}`); + } +} + +function cmdValidate(feature?: string): void { + const features = feature ? [feature] : getFeatureDirs(); + let hasErrors = false; + + const validTaskStatuses = new Set(['active', 'completed', 'blocked', 'archived']); + const validSubtaskStatuses = new Set(['pending', 'in_progress', 'completed', 'blocked']); + + const requiredTaskFields = [ + 'id', + 'name', + 'status', + 'objective', + 'context_files', + 'exit_criteria', + 'subtask_count', + 'completed_count', + 'created_at', + 'completed_at', + ]; + + const requiredSubtaskFields = [ + 'id', + 'seq', + 'title', + 'status', + 'depends_on', + 'parallel', + 'context_files', + 'acceptance_criteria', + 'deliverables', + 'agent_id', + 'started_at', + 'completed_at', + 'completion_summary', + ]; + + const hasField = (obj: any, field: string): boolean => Object.prototype.hasOwnProperty.call(obj, field); + const isStringArray = (value: any): boolean => Array.isArray(value) && value.every(v => typeof v === 'string'); + + console.log('\n=== Validation Results ===\n'); + + for (const f of features) { + const errors: string[] = []; + + // Check task.json exists + const task = loadTask(f); + if (!task) { + errors.push('Missing task.json'); + } + + // Load and validate subtasks + const subtasks = loadSubtasks(f); + const seqCounts = new Map(); + for (const s of subtasks) { + const seq = typeof s.seq === 'string' ? s.seq : ''; + seqCounts.set(seq, (seqCounts.get(seq) || 0) + 1); + } + const seqs = new Set(subtasks.map(s => s.seq)); + + if (task) { + // Required fields in task.json + for (const field of requiredTaskFields) { + if (!hasField(task, field)) { + errors.push(`task.json: missing required field '${field}'`); + } + } + + // Task ID should match feature slug + if (task.id !== f) { + errors.push(`task.json id ('${task.id}') should match feature slug ('${f}')`); + } + + // Task status should be valid + if (!validTaskStatuses.has(task.status)) { + errors.push(`task.json: invalid status '${task.status}'`); + } + + // Basic type checks for key task fields + if (!isStringArray(task.context_files)) { + errors.push('task.json: context_files must be string[]'); + } + if (hasField(task, 'reference_files') && task.reference_files !== undefined && !isStringArray(task.reference_files)) { + errors.push('task.json: reference_files must be string[] when present'); + } + if (!isStringArray(task.exit_criteria)) { + errors.push('task.json: exit_criteria must be string[]'); + } + if (typeof task.subtask_count !== 'number') { + errors.push('task.json: subtask_count must be number'); + } + if (typeof task.completed_count !== 'number') { + errors.push('task.json: completed_count must be number'); + } + } + + for (const s of subtasks) { + // Required fields in subtask files + for (const field of requiredSubtaskFields) { + if (!hasField(s, field)) { + errors.push(`${s.seq || '??'}: missing required field '${field}'`); + } + } + + // Sequence format and uniqueness + if (!/^\d{2}$/.test(s.seq)) { + errors.push(`${s.seq}: sequence must be 2 digits (e.g., 01, 02)`); + } + if ((seqCounts.get(s.seq) || 0) > 1) { + errors.push(`${s.seq}: duplicate sequence number`); + } + + // Check ID format + if (!s.id.startsWith(f)) { + errors.push(`${s.seq}: ID should start with feature name`); + } + + // Status should be valid + if (!validSubtaskStatuses.has(s.status)) { + errors.push(`${s.seq}: invalid status '${s.status}'`); + } + + // Type checks + if (!isStringArray(s.depends_on)) { + errors.push(`${s.seq}: depends_on must be string[]`); + } + if (typeof s.parallel !== 'boolean') { + errors.push(`${s.seq}: parallel must be boolean`); + } + if (!isStringArray(s.context_files)) { + errors.push(`${s.seq}: context_files must be string[]`); + } + if (hasField(s, 'reference_files') && s.reference_files !== undefined && !isStringArray(s.reference_files)) { + errors.push(`${s.seq}: reference_files must be string[] when present`); + } + if (!isStringArray(s.acceptance_criteria)) { + errors.push(`${s.seq}: acceptance_criteria must be string[]`); + } else if (s.acceptance_criteria.length === 0) { + errors.push(`${s.seq}: No acceptance criteria defined`); + } + if (!isStringArray(s.deliverables)) { + errors.push(`${s.seq}: deliverables must be string[]`); + } else if (s.deliverables.length === 0) { + errors.push(`${s.seq}: No deliverables defined`); + } + + // Self dependency is invalid + if (Array.isArray(s.depends_on) && s.depends_on.includes(s.seq)) { + errors.push(`${s.seq}: task cannot depend on itself`); + } + + // Check for missing dependencies + for (const dep of (Array.isArray(s.depends_on) ? s.depends_on : [])) { + if (!seqs.has(dep)) { + errors.push(`${s.seq}: depends on non-existent task ${dep}`); + } + } + + // Check for circular dependencies + const visited = new Set(); + const checkCircular = (seq: string, path: string[]): boolean => { + if (path.includes(seq)) { + errors.push(`${s.seq}: circular dependency detected: ${[...path, seq].join(' -> ')}`); + return true; + } + if (visited.has(seq)) return false; + visited.add(seq); + + const task = subtasks.find(t => t.seq === seq); + if (task) { + for (const dep of task.depends_on) { + if (checkCircular(dep, [...path, seq])) return true; + } + } + return false; + }; + checkCircular(s.seq, []); + } + + // Check counts match + if (task && task.subtask_count !== subtasks.length) { + errors.push(`task.json subtask_count (${task.subtask_count}) doesn't match actual count (${subtasks.length})`); + } + + // Print results + console.log(`[${f}]`); + if (errors.length === 0) { + console.log(' ✓ All checks passed'); + } else { + for (const e of errors) { + console.log(` ✗ ERROR: ${e}`); + hasErrors = true; + } + } + console.log(); + } + + process.exit(hasErrors ? 1 : 0); +} + +// Main +const [,, command, ...args] = process.argv; + +switch (command) { + case 'status': + cmdStatus(args[0]); + break; + case 'next': + cmdNext(args[0]); + break; + case 'parallel': + cmdParallel(args[0]); + break; + case 'deps': + if (args.length < 2) { + console.log('Usage: deps '); + process.exit(1); + } + cmdDeps(args[0], args[1]); + break; + case 'blocked': + cmdBlocked(args[0]); + break; + case 'complete': + if (args.length < 3) { + console.log('Usage: complete "summary"'); + process.exit(1); + } + cmdComplete(args[0], args[1], args.slice(2).join(' ')); + break; + case 'validate': + cmdValidate(args[0]); + break; + default: + console.log(` +Task Management CLI + +Usage: npx ts-node task-cli.ts [feature] [args...] + +Task files are stored in: .tmp/tasks/{feature-slug}/ + +Commands: + status [feature] Show task status summary + next [feature] Show next eligible tasks (deps satisfied) + parallel [feature] Show parallelizable tasks ready to run + deps Show dependency tree for a task + blocked [feature] Show blocked tasks and why + complete "summary" Mark task completed with summary + validate [feature] Validate JSON files and dependencies + +Examples: + npx ts-node task-cli.ts status + npx ts-node task-cli.ts next my-feature + npx ts-node task-cli.ts complete my-feature 02 "Implemented auth module" +`); +} diff --git a/.opencode/tool/env/index.ts b/.opencode/tool/env/index.ts new file mode 100644 index 0000000..8ff2ac9 --- /dev/null +++ b/.opencode/tool/env/index.ts @@ -0,0 +1,168 @@ +import { readFile } from "fs/promises" +import { resolve } from "path" + +/** + * Configuration for environment variable loading + */ +export interface EnvLoaderConfig { + /** Custom paths to search for .env files (relative to current working directory) */ + searchPaths?: string[] + /** Whether to log when environment variables are loaded */ + verbose?: boolean + /** Whether to override existing environment variables */ + override?: boolean +} + +/** + * Default search paths for .env files + */ +const DEFAULT_ENV_PATHS = [ + './.env', + '../.env', + '../../.env', + '../plugin/.env', + '../../../.env' +] + +/** + * Load environment variables from .env files + * Searches multiple common locations for .env files and loads them into process.env + * + * @param config Configuration options + * @returns Object containing loaded environment variables + */ +export async function loadEnvVariables(config: EnvLoaderConfig = {}): Promise> { + const { + searchPaths = DEFAULT_ENV_PATHS, + verbose = false, + override = false + } = config + + const loadedVars: Record = {} + + for (const envPath of searchPaths) { + try { + const fullPath = resolve(envPath) + const content = await readFile(fullPath, 'utf8') + + if (verbose) { + console.log(`Checking .env file: ${envPath}`) + } + + // Parse .env file content + const lines = content.split('\n') + for (const line of lines) { + const trimmed = line.trim() + if (trimmed && !trimmed.startsWith('#') && trimmed.includes('=')) { + const [key, ...valueParts] = trimmed.split('=') + const value = valueParts.join('=').trim() + + // Remove quotes if present + const cleanValue = value.replace(/^["']|["']$/g, '') + + if (key && cleanValue && (override || !process.env[key])) { + process.env[key] = cleanValue + loadedVars[key] = cleanValue + + if (verbose) { + console.log(`Loaded ${key} from ${envPath}`) + } + } + } + } + } catch (error) { + // File doesn't exist or can't be read, continue to next + if (verbose) { + console.log(`Could not read ${envPath}: ${error.message}`) + } + } + } + + return loadedVars +} + +/** + * Get a specific environment variable with automatic .env file loading + * + * @param varName Name of the environment variable + * @param config Configuration options + * @returns The environment variable value or null if not found + */ +export async function getEnvVariable(varName: string, config: EnvLoaderConfig = {}): Promise { + // First check if it's already in the environment + let value = process.env[varName] + + if (!value) { + // Try to load from .env files + const loadedVars = await loadEnvVariables(config) + value = loadedVars[varName] || process.env[varName] + } + + return value || null +} + +/** + * Get a required environment variable with automatic .env file loading + * Throws an error if the variable is not found + * + * @param varName Name of the environment variable + * @param config Configuration options + * @returns The environment variable value + * @throws Error if the variable is not found + */ +export async function getRequiredEnvVariable(varName: string, config: EnvLoaderConfig = {}): Promise { + const value = await getEnvVariable(varName, config) + + if (!value) { + const searchPaths = config.searchPaths || DEFAULT_ENV_PATHS + throw new Error(`${varName} not found. Please set it in your environment or .env file. + +To fix this: +1. Add to .env file: ${varName}=your_value_here +2. Or export it: export ${varName}=your_value_here + +Current working directory: ${process.cwd()} +Searched paths: ${searchPaths.join(', ')} +Environment variables available: ${Object.keys(process.env).filter(k => k.includes(varName.split('_')[0])).join(', ') || 'none matching'}`) + } + + return value +} + +/** + * Load multiple required environment variables at once + * + * @param varNames Array of environment variable names + * @param config Configuration options + * @returns Object with variable names as keys and values as values + * @throws Error if any variable is not found + */ +export async function getRequiredEnvVariables(varNames: string[], config: EnvLoaderConfig = {}): Promise> { + const result: Record = {} + + // Load all .env files first + await loadEnvVariables(config) + + // Check each required variable + for (const varName of varNames) { + const value = process.env[varName] + if (!value) { + throw new Error(`Required environment variable ${varName} not found. Please set it in your environment or .env file.`) + } + result[varName] = value + } + + return result +} + +/** + * Utility function specifically for API keys + * + * @param apiKeyName Name of the API key environment variable + * @param config Configuration options + * @returns The API key value + * @throws Error if the API key is not found + */ +export async function getApiKey(apiKeyName: string, config: EnvLoaderConfig = {}): Promise { + return getRequiredEnvVariable(apiKeyName, config) +} \ No newline at end of file diff --git a/AGENTS.md1 b/AGENTS.md1 new file mode 100644 index 0000000..1c0c329 --- /dev/null +++ b/AGENTS.md1 @@ -0,0 +1,308 @@ +# AGENTS.md - uTun Development Guide + +This file contains essential information for AI coding agents working in the uTun codebase. + +## 📋 Quick Reference + +**Repository:** uTun - Secure VPN tunnel with ETCP protocol +**Language:** C (C99) +**Build System:** GNU Autotools (autoconf/automake) +**Cryptography:** TinyCrypt (AES-CCM, ECC) + +## 🔧 Build Commands + +### Full Build +```bash +./autogen.sh # Generate configure script (if needed) +./configure # Configure build +make # Build everything +make install # Install (requires sudo) +``` + +### Partial Builds +```bash +cd lib && make # Build only the library +cd src && make # Build only the main program +cd tests && make # Build only tests +``` + +### Clean Build +```bash +make clean # Clean object files +make distclean # Clean everything including configure files +``` + +## 🧪 Test Commands + +### Run All Tests +```bash +make check # Run all tests via automake +``` + +### Run Specific Test +```bash +cd tests/ && ./test_etcp_crypto # ETCP crypto test +cd tests/ && ./test_etcp_simple # Simple ETCP test +cd tests/ && ./test_ecc_encrypt # ECC encryption test +``` + +### Run Single Test with Debug Info +```bash +cd tests/ +gcc -I../src -I../lib -I../tinycrypt/lib/include \ + -o my_test test_file.c ../src/*.c ../lib/*.c ../tinycrypt/lib/source/*.c +./my_test +``` + +## 💻 Code Style Guidelines + +### Naming Conventions +- **Functions:** `snake_case` - `etcp_connection_create()`, `sc_encrypt()` +- **Types:** `struct snake_case` or `typedef`: `struct secure_channel`, `sc_context_t` +- **Macros:** `UPPER_CASE` - `SC_PRIVKEY_SIZE`, `DEBUG_ERROR()` +- **Constants:** `UPPER_CASE` - `SC_OK`, `SC_ERR_CRYPTO` +- **Global Variables:** Avoid where possible, use `static` for file scope + +### Formatting +- **Indentation:** 4 spaces, no tabs +- **Braces:** Same line for functions, new line for control structures: + ```c + int function(void) { + if (condition) { + do_something(); + } + } + ``` +- **Comments:** Primary language is Russian for business logic, English for API docs +- **Line Length:** Aim for 80-100 characters + +### Include Order +```c +// 1. System headers +#include +#include + +// 2. Library headers +#include "../lib/ll_queue.h" + +// 3. Local headers +#include "etcp.h" +``` + +### Error Handling +- Use custom error codes defined in headers (e.g., `SC_ERR_INVALID_ARG`) +- Return negative values for errors, 0 for success +- Use DEBUG macros for logging: + ```c + DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to initialize: %s", err); + DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "Socket created on port %d", port); + ``` + +## 🔐 Cryptography Guidelines + +### Using Secure Channel (secure_channel.h) +```c +// 1. Initialize context +struct SC_MYKEYS my_keys; +// ... fill keys ... +sc_context_t ctx; +sc_init_ctx(&ctx, &my_keys); + +// 2. Set peer public key (for key exchange) +sc_set_peer_public_key(&ctx, peer_public_key, 0); // 0 = binary format + +// 3. Ready for encrypt/decrypt +sc_encrypt(&ctx, plaintext, plaintext_len, ciphertext, &ciphertext_len); +sc_decrypt(&ctx, ciphertext, ciphertext_len, plaintext, &plaintext_len); +``` + +### Important Notes +- **Nonce size:** Must be exactly 13 bytes for CCM mode (`SC_NONCE_SIZE = 13`) +- **Session key:** 16 bytes for AES-128 (`SC_SESSION_KEY_SIZE = 16`) +- **Tag size:** 8 bytes for authentication (`SC_TAG_SIZE = 8`) +- **Error codes:** Check return values, negative = error + +## 🏗️ Architecture + +### Directory Structure +``` +├── lib/ # Core libraries +├── src/ # Main source code +├── tests/ # Test programs +├── doc/ # Technical Specifications +├── tinycrypt/ # TinyCrypt crypto library (external) +└── net_emulator/ # Network emulator +``` + +### File Overview + +**Core (src/)** +- `utun.c` - Main program entry point, CLI parsing, daemon mode +- `utun_instance.c/h` - Root instance lifecycle management +- `tun_if.c/h` - Simplified TUN interface (init/write/close) + +**Network Stack (src/)** +- `etcp.c/h` - ETCP protocol implementation (TCP-like with crypto) +- `etcp_connections.c/h` - Socket and link management +- `etcp_loadbalancer.c/h` - Multi-link load balancing +- `pkt_normalizer.c/h` - Packet fragmentation/reassembly +- `routing.c/h` - Routing table management + +**Crypto (src/)** +- `secure_channel.c/h` - AES-CCM encryption with ECC key exchange +- `crc32.c/h` - CRC32 checksums + +**Config (src/)** +- `config_parser.c/h` - INI-style config file parsing +- `config_updater.c/h` - Config file modification utilities + +**Libraries (lib/)** +- `u_async.c/h` - Async event loop (epoll/poll, timers) +- `ll_queue.c/h` - Lock-free linked list queue with callbacks +- `memory_pool.c/h` - Fast object pool allocator +- `debug_config.c/h` - Debug logging system +- `timeout_heap.c/h` - Min-heap for timer management +- `sha256.c/h` - SHA256 hashing + +**Tests (tests/)** +- `test_etcp_*.c` - ETCP protocol tests +- `test_crypto.c` - TinyCrypt AES/CCM tests +- `test_ecc_encrypt.c` - ECC encryption tests +- `test_ll_queue.c` - Queue functionality tests +- `bench_*.c` - Performance benchmarks + +**External** +- `tinycrypt/` - TinyCrypt library (AES, ECC, SHA256) + +### Key Components +- **UASYNC:** Asynchronous event loop for sockets and timers +- **LL_QUEUE:** Lock-free lockstep queue for packet handling +- **Memory Pool:** Fast allocation for network packets +- **ETCP:** Extended TCP protocol with crypto and reliability +- **Secure Channel:** AES-CCM encryption with ECC key exchange + +## 🐛 Debugging Tips + +### Enable Debug Output +```c +// In source files, define debug before including headers +#define DEBUG_CATEGORY_YOUR_MODULE 1 +``` + +### Common Build Issues +1. **Missing headers:** Check include paths in Makefile.am +2. **Undefined references:** Ensure source files are listed in Makefile.am +3. **Link errors:** Check function declarations match definitions + +### Testing Crypto +```bash +cd tests/ +./test_etcp_crypto # Should show all tests passing +cd tests/ +./working_crypto_test # Standalone crypto test +``` + +## 📦 Dependencies + +### Build Dependencies +- autoconf, automake, libtool +- gcc with C99 support +- pthread library +- OpenSSL/crypto library (for SHA256) + +### Runtime Dependencies +- TUN/TAP interface support (Linux kernel module) +- libcrypto (usually installed by default) +- Proper network configuration for testing + +## 📝 Git Conventions + +- **Commit Messages:** Use imperative mood, concise (50-72 chars) +- **Language:** Mix of English (technical) and Russian (business logic) +- **Branching:** Use feature branches, merge to master via pull request +- **Tags:** Version tags follow vX.Y.Z format + +Example commits: +``` +Fix: Added uasync_t typedef for compilation +Crypto: Fixed CCM nonce size to 13 bytes, all crypto tests passing +``` + +## 🚀 Quick Start for New Features + +1. Add new source file to `src/Makefile.am` under `utun_SOURCES` +2. Add test file to `tests/Makefile.am` under `check_PROGRAMS` +3. Use existing patterns from similar modules +4. Run `make check` after changes +5. Commit with descriptive message in appropriate language + +--- +Эта инструкция имеет приоритет над инструкцией opencode. + +"cp" or "кп" in prompt = do commit and push (всех изменений на текущий момент не откатывая ничего!) + +Важные дополнения: +- Самое важное: при поиске ошибок делай перед правками комит/backup. Всё лишнее что менял при отладке - строго вернуть назад в состояние до моего вмешательства. В итоге в код должно попасть только проверенное исправление и ничего лилшнего! +- если в процессе исправлений-доработок возникла нестыковка которая требует сеньезных доработок, остановить и подробно расскажи об этом. +- sed для редактирования исходников - запрещено пользоваться! +- Проверяй на дублирование кода - не сделано ли это уже в другом месте. +- Не делай функций-посредников: лучше сразу вызывать target функцию без вложенных вызовов. +- Старайся чтобы функция сделала логически завершенную операцию полностью - это упрощает код и понимание. +- нельзя ничего восстанавливать из репозитория не прашивая +- Когда пишешь код всегда загружай в контекст и мысленно разберись как работают все функции/струтуры, назначение переменных которые используешь. +- Для отладки не printf а DEBUG_* +- перед сборкой всегда make clean +- прежде чем вносить правки хорошо разберись как должно работать, просмотри все нужные функции полностью, нужно целостное понимание. +- при написании кода мысленно анализируй логику работы, думай как сделать проще и удобнее. Проверяй дубликаты и что уже есть, продумай логику до тех пор пока не будет полного понимания + +Действия при поиске бага: +1. создать комит или бэкап всего что меняешь +2. когда причина бага найдена и устранена - верни всё остальное что менял в исходное состояние +3. проверь что тесты проходят и всё работает. make clean перед сбркой обязательно. +4. если баг не устранён - продолжай поиск или если время заканчивается - верни всё в исходное состояние + +Как более точно эффективно проводить диагностику ошибки: +0. Сосредоточься на поиске конкретной ошибки и доведи его до конца руководствуясь этой инструкцией. +1. прочитай полностью код функций с ошибкой и код всех функции которые учавствуют в ошибочном алгоритме. +2. еще раз мысленно выполни предполагаемый сценарий ошибки (если чего-то не хватает до полной картины - обязательно дочитывай все ветви функций по ходу: нельзя додумывать - нужна точность) и убедись что: + - ты точно понимаешь как алгоритм прихдит к ошибке + - все функции которые учавствуют в сценарии ошибки проанализированы и их поведение проверено и понятно + - последовательно отсекай логически законченные блоки которые проверены и точно правильно работают + - если ты полностью проанализировал функцию и к ней нет описания или описание неточное (неполное), и функция работает логически корректно - поправь описание. Если функция работает логически неверно - добавь запись об этом в todo.txt +3. Если исправление как либо меняет поведение функции: + - просмотри где используется эта функция + - убедись что изменение поведения не повлияет на остальные места где функция используется. особенно важный пункт для библиотек и модулей коммуникаций + +Работа с очередями. +- Запись в очередь: очереди забивать нельзя. Добавляй следующий элемент только когда очередь стала пустой. Пользуйся наблюдателем queue_wait_threshold, он специально сделан для добавления в очередь. +- Чтение из очереди: пользуйся queue_set_callback: при вызове callback , обработай один или несколько элементов, потом вызови resume_callback. + +Работа с u_async +- нельзя использовать в одном потоке несколько u_async. один поток = всегда 1 uasync instance +- нельзя использовать sleep/usleep если есть uasync. Нужно использовать uasync_set_timeout. + +Конфиги: +- в серверном только собственные ключи и нет секций [client] +- в клиентском есть собственные ключи и pubkey каждого сервера в секции [client] + +тех задания для реализации в каталоге /doc. +/doc/etcp_protocol.txt - основной протокол (похож на TCP+QUIC, поддеиживает шифрования, load balancing multi-link, работу а неустойчивых каналах, утилизацию полосы и недопущение перегрузки каналов связи) + - реализация в /src/etcp*.c/h + +Для удобства навигции по C коду есть скрипт в корне проекта: ./c_util (пока глючит!) + +Команды: +./c_util toc - Выводит кратко список всех файлов проекта, прототипов функций/структур/enum по всем файлам. +./c_util describe <имя_функции/структуры/enum> <имя2> ... - выводит прототипы запрошенных элементов с комментариями +./c_util show <имя_функции/структуры/enum> <имя2> ... - выводит полный код элементов (включая комментарии перед ними) +./c_util edit lib/debug_config.c 135 70 38 7D <<'EOF' +void debug_set_level(debug_level_t new_level) { + g_debug_config.level = new_level; +} +EOF - редактирование с проверкой контрольных сумм. начиная со строки 135, далее ксуммы заменяемых строк ( в примере 3 строки - 70 38 7D). вместо них вписать текст << (может быть другоч число строк) + +Если функция/структура не найдена, скрипт выведет сообщение об ошибке. Скрипт игнорирует комментарии и препроцессорные директивы при парсинге, но захватывает их для вывода. + + + +*Last updated: 2025-01-20 - After full crypto implementation and testing* \ No newline at end of file diff --git a/README.md b/EOF similarity index 100% rename from README.md rename to EOF diff --git a/Makefile.am b/Makefile.am index fd4ac3e..9fb037e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,3 +4,7 @@ # Basic configuration for root directory SUBDIRS = lib src tests + +# Clean object directories from root +clean-local: + -rm -rf $(top_builddir)/.objs diff --git a/TASKS.md b/TASKS.md deleted file mode 100644 index 94ab103..0000000 --- a/TASKS.md +++ /dev/null @@ -1,37 +0,0 @@ -# High Priority Tasks - -## Task 1: Convert to autoconf/automake (NEW) -- Create configure.ac -- Create Makefile.am for main project -- Create Makefile.am for tests/ -- Add autogen.sh script -- Remove hardcoded Makefile -- Update build documentation - -## Task 2: Complete typedef struct refactoring (24/28 done) -- config_parser.h: 7 typedef struct -- etcp_sockets.h: 3 typedef struct (including conn_handle - delete) -- etcp_connections.h: 3 typedef struct -- etcp.h: 2 typedef struct -- ll_queue.h: 4 typedef struct (u_async lib) -- pkt_normalizer.h: 2 typedef struct -- secure_channel.h: 1 typedef struct -- tun_if.h: 1 typedef struct -- utun_instance.h: 1 typedef struct - -## Task 3: Cleanup legacy tests -- Remove test_connection*.c -- Remove test_sc_lib.c -- Update Makefile to remove old test targets -- Replace epkt_t* with etcp_t* -- Replace conn_handle_t* with etcp_socket_t* - -## Task 4: Replace fprintf with debug system -- utun.c: 27 fprintf -- etcp_connections.c: ~15 fprintf -- config_parser.c: 10+ fprintf -- Other files: ~20 fprintf - -## Task 5: Update AGENTS.md after completion -- Document build process changes -- Update style guide if needed diff --git a/build_errors.txt b/build_errors.txt deleted file mode 100644 index 9496acd..0000000 --- a/build_errors.txt +++ /dev/null @@ -1,161 +0,0 @@ -ar: модификатор «u» игнорируется, так как по умолчанию используется «D» (смотрите «U») -utun_instance.c: In function ‘utun_instance_create’: -utun_instance.c:93:49: warning: ‘/32’ directive output may be truncated writing 3 bytes into a region of size between 1 and 64 [-Wformat-truncation=] - 93 | snprintf(tun_ip_str, sizeof(tun_ip_str), "%s/32", ip_buffer); - | ^~~ -In file included from /usr/include/stdio.h:980, - from utun_instance.h:6, - from utun_instance.c:2: -In function ‘snprintf’, - inlined from ‘utun_instance_create’ at utun_instance.c:93:5: -/usr/include/x86_64-linux-gnu/bits/stdio2.h:54:10: note: ‘__builtin___snprintf_chk’ output between 4 and 67 bytes into a destination of size 64 - 54 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 55 | __glibc_objsize (__s), __fmt, - | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - 56 | __va_arg_pack ()); - | ~~~~~~~~~~~~~~~~~ -etcp.c: In function ‘etcp_conn_reset’: -etcp.c:175:9: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history_idx’ - 175 | etcp->rtt_history_idx = 0; - | ^~ -etcp.c:176:16: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 176 | memset(etcp->rtt_history, 0, sizeof(etcp->rtt_history)); - | ^~ -etcp.c:176:45: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 176 | memset(etcp->rtt_history, 0, sizeof(etcp->rtt_history)); - | ^~ -etcp.c: In function ‘etcp_request_pkt’: -etcp.c:251:47: error: ‘input_queue_cb’ undeclared (first use in this function) - 251 | queue_set_callback(etcp->input_queue, input_queue_cb, etcp); // Define cb to resume - | ^~~~~~~~~~~~~~ -etcp.c:251:47: note: each undeclared identifier is reported only once for each function it appears in -etcp.c:288:30: warning: implicit declaration of function ‘etcp_loadbalancer_select_link’ [-Wimplicit-function-declaration] - 288 | struct ETCP_LINK* link = etcp_loadbalancer_select_link(etcp); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -etcp.c:288:30: warning: initialization of ‘struct ETCP_LINK *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] -etcp.c: In function ‘append_optional_sections’: -etcp.c:391:13: error: ‘struct ETCP_CONN’ has no member named ‘ack_packets_count’ - 391 | etcp->ack_packets_count++; - | ^~ -etcp.c: In function ‘process_section_ack’: -etcp.c:437:11: error: ‘struct ETCP_CONN’ has no member named ‘last_rx_ack_id’; did you mean ‘last_rx_id’? - 437 | etcp->last_rx_ack_id = (data[1 + (count-1)*4] << 8) | data[2 + (count-1)*4]; // Last ACK ID - | ^~~~~~~~~~~~~~ - | last_rx_id -etcp.c: In function ‘update_link_bandwidth’: -etcp.c:642:9: error: ‘struct ETCP_LINK’ has no member named ‘bandwidth’ - 642 | link->bandwidth = (link->bandwidth * 0.9) + (new_bw * 0.1); // Smooth - | ^~ -etcp.c:642:28: error: ‘struct ETCP_LINK’ has no member named ‘bandwidth’ - 642 | link->bandwidth = (link->bandwidth * 0.9) + (new_bw * 0.1); // Smooth - | ^~ -etcp.c: In function ‘update_rtt’: -etcp.c:652:9: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 652 | etcp->rtt_history[etcp->rtt_history_idx++] = new_rtt; - | ^~ -etcp.c:652:27: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history_idx’ - 652 | etcp->rtt_history[etcp->rtt_history_idx++] = new_rtt; - | ^~ -etcp.c:653:13: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history_idx’ - 653 | if (etcp->rtt_history_idx >= RTT_HISTORY_SIZE) etcp->rtt_history_idx = 0; - | ^~ -etcp.c:653:56: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history_idx’ - 653 | if (etcp->rtt_history_idx >= RTT_HISTORY_SIZE) etcp->rtt_history_idx = 0; - | ^~ -etcp.c: In function ‘calculate_jitter’: -etcp.c:661:17: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 661 | if (etcp->rtt_history[i] == 0) continue; - | ^~ -etcp.c:662:17: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 662 | if (etcp->rtt_history[i] < min_rtt) min_rtt = etcp->rtt_history[i]; - | ^~ -etcp.c:662:59: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 662 | if (etcp->rtt_history[i] < min_rtt) min_rtt = etcp->rtt_history[i]; - | ^~ -etcp.c:663:17: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 663 | if (etcp->rtt_history[i] > max_rtt) max_rtt = etcp->rtt_history[i]; - | ^~ -etcp.c:663:59: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 663 | if (etcp->rtt_history[i] > max_rtt) max_rtt = etcp->rtt_history[i]; - | ^~ -etcp.c: In function ‘etcp_get_stats’: -etcp.c:684:43: error: ‘struct ETCP_CONN’ has no member named ‘total_packets_sent’ - 684 | if (packets_sent) *packets_sent = etcp->total_packets_sent; - | ^~ -make[2]: *** [Makefile:605: utun-etcp.o] Ошибка 1 -make[1]: *** [Makefile:375: all-recursive] Ошибка 1 -make: *** [Makefile:316: all] Ошибка 2 -etcp.c: In function ‘etcp_conn_reset’: -etcp.c:175:9: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history_idx’ - 175 | etcp->rtt_history_idx = 0; - | ^~ -etcp.c:176:16: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 176 | memset(etcp->rtt_history, 0, sizeof(etcp->rtt_history)); - | ^~ -etcp.c:176:45: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 176 | memset(etcp->rtt_history, 0, sizeof(etcp->rtt_history)); - | ^~ -etcp.c: In function ‘etcp_request_pkt’: -etcp.c:251:47: error: ‘input_queue_cb’ undeclared (first use in this function) - 251 | queue_set_callback(etcp->input_queue, input_queue_cb, etcp); // Define cb to resume - | ^~~~~~~~~~~~~~ -etcp.c:251:47: note: each undeclared identifier is reported only once for each function it appears in -etcp.c:288:30: warning: implicit declaration of function ‘etcp_loadbalancer_select_link’ [-Wimplicit-function-declaration] - 288 | struct ETCP_LINK* link = etcp_loadbalancer_select_link(etcp); - | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -etcp.c:288:30: warning: initialization of ‘struct ETCP_LINK *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion] -etcp.c: In function ‘append_optional_sections’: -etcp.c:391:13: error: ‘struct ETCP_CONN’ has no member named ‘ack_packets_count’ - 391 | etcp->ack_packets_count++; - | ^~ -etcp.c: In function ‘process_section_ack’: -etcp.c:437:11: error: ‘struct ETCP_CONN’ has no member named ‘last_rx_ack_id’; did you mean ‘last_rx_id’? - 437 | etcp->last_rx_ack_id = (data[1 + (count-1)*4] << 8) | data[2 + (count-1)*4]; // Last ACK ID - | ^~~~~~~~~~~~~~ - | last_rx_id -etcp.c: In function ‘update_link_bandwidth’: -etcp.c:642:9: error: ‘struct ETCP_LINK’ has no member named ‘bandwidth’ - 642 | link->bandwidth = (link->bandwidth * 0.9) + (new_bw * 0.1); // Smooth - | ^~ -etcp.c:642:28: error: ‘struct ETCP_LINK’ has no member named ‘bandwidth’ - 642 | link->bandwidth = (link->bandwidth * 0.9) + (new_bw * 0.1); // Smooth - | ^~ -etcp.c: In function ‘update_rtt’: -etcp.c:652:9: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 652 | etcp->rtt_history[etcp->rtt_history_idx++] = new_rtt; - | ^~ -etcp.c:652:27: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history_idx’ - 652 | etcp->rtt_history[etcp->rtt_history_idx++] = new_rtt; - | ^~ -etcp.c:653:13: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history_idx’ - 653 | if (etcp->rtt_history_idx >= RTT_HISTORY_SIZE) etcp->rtt_history_idx = 0; - | ^~ -etcp.c:653:56: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history_idx’ - 653 | if (etcp->rtt_history_idx >= RTT_HISTORY_SIZE) etcp->rtt_history_idx = 0; - | ^~ -etcp.c: In function ‘calculate_jitter’: -etcp.c:661:17: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 661 | if (etcp->rtt_history[i] == 0) continue; - | ^~ -etcp.c:662:17: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 662 | if (etcp->rtt_history[i] < min_rtt) min_rtt = etcp->rtt_history[i]; - | ^~ -etcp.c:662:59: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 662 | if (etcp->rtt_history[i] < min_rtt) min_rtt = etcp->rtt_history[i]; - | ^~ -etcp.c:663:17: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 663 | if (etcp->rtt_history[i] > max_rtt) max_rtt = etcp->rtt_history[i]; - | ^~ -etcp.c:663:59: error: ‘struct ETCP_CONN’ has no member named ‘rtt_history’ - 663 | if (etcp->rtt_history[i] > max_rtt) max_rtt = etcp->rtt_history[i]; - | ^~ -etcp.c: In function ‘etcp_get_stats’: -etcp.c:684:43: error: ‘struct ETCP_CONN’ has no member named ‘total_packets_sent’ - 684 | if (packets_sent) *packets_sent = etcp->total_packets_sent; - | ^~ -make[2]: *** [Makefile:605: utun-etcp.o] Ошибка 1 -make[1]: *** [Makefile:375: all-recursive] Ошибка 1 -make: *** [Makefile:316: all] Ошибка 2 -make[1]: *** Нет правила для сборки цели «../src/utun-secure_channel.o», требуемой для «test_etcp_crypto». Останов. -make: *** [Makefile:1024: check-am] Ошибка 2 diff --git a/build_fix_changelog.txt b/build_fix_changelog.txt deleted file mode 100644 index b76b41e..0000000 --- a/build_fix_changelog.txt +++ /dev/null @@ -1,19 +0,0 @@ -Sat Jan 17 2026 21:10: Fixed build errors and implemented utun_instance structure - -CHANGES: -1. Fixed missing struct sockaddr include in connection.h -2. Removed control_socket module (functionality to be moved to etcp_socket) -3. Removed udp_socket module (functionality merged into etcp_socket) -4. Created utun_instance.h and utun_instance.c with root instance structure -5. Refactored utun.c to use utun_instance instead of utun_state -6. Fixed ETCP API mismatches (temporarily disabled ETCP integration) -7. Fixed routing_stats_t structure members -8. Cleaned up pkt_normalizer.c formatting issues -9. Updated Makefile to remove deprecated modules -10. Successfully built utun binary - -NEXT STEPS: -- Fix ETCP API integration -- Re-enable ETCP tests -- Implement proper error handling in utun_instance -- Add comprehensive tests for utun_instance \ No newline at end of file diff --git a/c_util1 b/c_util1 new file mode 100755 index 0000000..35f4c0b --- /dev/null +++ b/c_util1 @@ -0,0 +1,187 @@ +#!/usr/bin/python3 + +import sys +import os +import subprocess +from pycparser import parse_file, c_ast, CParser +import re + +def read_filelist(filename='filelist.txt'): + with open(filename, 'r') as f: + return [line.strip() for line in f if line.strip()] + +def preprocess_file(filename): + # Препроцессинг с помощью cpp (GCC preprocessor) + try: + preprocessed = subprocess.check_output(['cpp', '-nostdinc', filename]).decode('utf-8') + return preprocessed.splitlines() + except subprocess.CalledProcessError as e: + print(f"Error preprocessing {filename}: {e}") + return None + +def collect_comments_and_code(lines): + # Собираем комментарии и очищаем код для парсинга (pycparser игнорирует комментарии) + comments = {} + clean_lines = [] + in_multi = False + current_comment = [] + line_num = 0 + for line in lines: + line_num += 1 + stripped = line.strip() + if in_multi: + end = line.find('*/') + if end != -1: + current_comment.append(line[:end+2]) + in_multi = False + # Добавляем остаток строки как код + rest = line[end+2:] + if rest.strip(): + clean_lines.append(rest) + comments[line_num] = '\n'.join(current_comment) + current_comment = [] + else: + current_comment.append(line) + else: + if stripped.startswith('//'): + comments[line_num] = line + elif stripped.startswith('/*'): + if '*/' in stripped: + comments[line_num] = line + else: + in_multi = True + current_comment = [line] + else: + clean_lines.append(line) + return comments, '\n'.join(clean_lines) + +class FuncVisitor(c_ast.NodeVisitor): + def __init__(self, comments): + self.functions = [] + self.structs = [] + self.comments = comments + + def visit_FuncDef(self, node): + # Извлекаем функцию + ret = node.decl.type.type.type.names[0] if hasattr(node.decl.type.type, 'type') else 'void' + name = node.decl.name + args = ', '.join([p.type.type.names[0] + ' ' + p.name for p in node.decl.type.args.params]) if node.decl.type.args else '' + pre_comments = [] + # Собираем комментарии перед функцией (приблизительно по coord) + if node.coord: + line = node.coord.line + for l in range(line-1, 0, -1): + if l in self.comments and (self.comments[l].startswith('//') or self.comments[l].startswith('/*')): + pre_comments.insert(0, self.comments[l]) + else: + break + body_lines = len(node.body.block_items) if node.body else 0 # Приблизительное число строк + self.functions.append({ + 'type': 'function', 'name': name, 'args': args, 'ret': ret, + 'pre': pre_comments, 'line_count': body_lines + 2, # + декларация и скобки + 'start': node.coord.line - 1 if node.coord else 0, + 'end': node.coord.line + body_lines if node.coord else 0, + 'node': node + }) + self.generic_visit(node) + + def visit_Struct(self, node): + # Извлекаем структуру + name = node.name + pre_comments = [] + if node.coord: + line = node.coord.line + for l in range(line-1, 0, -1): + if l in self.comments and (self.comments[l].startswith('//') or self.comments[l].startswith('/*')): + pre_comments.insert(0, self.comments[l]) + else: + break + line_count = len(node.decls) + 2 if node.decls else 2 + self.structs.append({ + 'type': 'struct', 'name': name, + 'pre': pre_comments, 'line_count': line_count, + 'start': node.coord.line - 1 if node.coord else 0, + 'end': node.coord.line + line_count if node.coord else 0, + 'node': node + }) + self.generic_visit(node) + +def parse_c_file(filename, comments): + ast = parse_file(filename, use_cpp=False) # Уже препроцессировано + visitor = FuncVisitor(comments) + visitor.visit(ast) + return visitor.functions, visitor.structs + +if __name__ == "__main__": + files = read_filelist() + project_functions = {} + project_structs = {} + contents = {} # Оригинальный код для вывода + for f in files: + contents[f] = open(f, 'r').read().splitlines() + pre_lines = preprocess_file(f) + if pre_lines is None: + continue + comments, clean_code = collect_comments_and_code(pre_lines) + # Записываем очищенный код во временный файл для pycparser + tmp_file = f + '.pre' + with open(tmp_file, 'w') as tf: + tf.write(clean_code) + try: + funcs, structs = parse_c_file(tmp_file, comments) + project_functions[f] = funcs + project_structs[f] = structs + except Exception as e: + print(f"Parse error in {f}: {e}") + finally: + os.remove(tmp_file) + + if len(sys.argv) < 2: + print("Usage: python c_util.py toc | func | struct ") + sys.exit(1) + cmd = sys.argv[1] + if cmd == 'toc': + for f in files: + print(f"File: {f}") + for func in project_functions.get(f, []): + print(f"Function: {func['ret']} {func['name']}({func['args']}) - {func['line_count']} lines") + for strct in project_structs.get(f, []): + print(f"Struct: {strct['name']} - {strct['line_count']} lines") # Добавил вывод структур в TOC + elif cmd == 'func': + if len(sys.argv) < 4: + print("Usage: python c_util.py func ") + sys.exit(1) + file = sys.argv[2] + funcname = sys.argv[3] + found = False + if file in project_functions: + for func in project_functions[file]: + if func['name'] == funcname: + lines = contents[file] + pre = func['pre'] + body = lines[func['start']:func['end']] + print('\n'.join(pre + body)) + found = True + break + if not found: + print("Function not found") + elif cmd == 'struct': + if len(sys.argv) < 4: + print("Usage: python c_util.py struct ") + sys.exit(1) + file = sys.argv[2] + structname = sys.argv[3] + found = False + if file in project_structs: + for strct in project_structs[file]: + if strct['name'] == structname: + lines = contents[file] + pre = strct['pre'] + body = lines[strct['start']:strct['end']] + print('\n'.join(pre + body)) + found = True + break + if not found: + print("Struct not found") + else: + print("Unknown command") diff --git a/changelog.txt b/changelog.txt deleted file mode 100644 index 0e9617b..0000000 --- a/changelog.txt +++ /dev/null @@ -1,225 +0,0 @@ -$(cat /home/vnc1/proj/utun3/changelog.txt) - -Sun Jan 18 2026 13:12 -Removed duplicate parse_ip_port from config_parser.c -- Unused parse_ip_port in config_parser.c (lines 70-86) -- Function was static and never called (confirmed by ripgrep) -- kept working version in etcp_connections.c (used by init_connections) -- Kept net_emulator version (separate tool, not a duplication) - -Sun Jan 19 2026 13:00: Migrate to GNU Autotools (autoconf/automake) - -CHANGES: - -1. Created GNU Autotools build system: - - configure.ac: Main autoconf configuration - - Makefile.am: Root automake configuration - - src/Makefile.am: Main program build rules - - u_async/Makefile.am: u_async library build - - tests/Makefile.am: Test suite configuration - - autogen.sh: Bootstrap script - - .gitignore: Updated for autotools - -2. Build system features: - ✓ Standard ./configure && make workflow - ✓ make check for running tests - ✓ make install for installation - ✓ make dist for release tarballs - ✓ Proper dependency tracking - ✓ Cross-platform compatibility - -3. Configuration features: - - Checks for TUN/TAP support - - Requires libcrypto (OpenSSL) - - Detects standard headers/functions - - Configurable debug output - - Customizable installation paths - -USAGE: - ./autogen.sh # Bootstrap (first time) - ./configure # Configure build - make # Build - make check # Run tests - sudo make install # Install - -COMPATIBILITY: - • Old Makefile removed (renamed to Makefile.old) - • All build functionality preserved - • Test suite fully integrated - • Backward compatible with existing code - -Sun Jan 19 2026 12:15: Task 4 Completed - fprintf → Debug System - -CHANGES: - -Replaced all fprintf(stderr) with DEBUG macros: - • utun.c: 27 replacements - • config_parser.c: 7 replacements - • etcp_connections.c: 13 replacements - • etcp.c: 1 replacement - • tun_if.c: 3 replacements - • utun_instance.c: 9 replacements - • utun_route_fix.c: 1 replacement - ──────────────────────────────────────── - TOTAL: 60 replacements - -Categories used: - DEBUG_ERROR() with categories: - - DEBUG_CATEGORY_ETCP (ETCP protocol errors) - - DEBUG_CATEGORY_TUN (TUN interface errors) - - DEBUG_CATEGORY_CONFIG (Configuration errors) - - DEBUG_CATEGORY_ROUTING (Routing errors) - - DEBUG_CATEGORY_MEMORY (Memory/system errors) - - DEBUG_WARNING() for non-critical warnings - -All files updated with #include "debug_config.h" -Debug output now controllable via debug config system. - -Sun Jan 19 2026 11:00: Task 2 Finalized - Remaining typedefs fixed - -COMPLETED: - • Fixed broken typedef in etcp.h (struct UTUN_INSTANCE*) - • Removed etcp_t typedef (now struct ETCP_CONN) - • Updated all usages across etcp.c and test files - -RESULTS: - • Total typedef structs: 4 remaining (all in ll_queue.h - u_async) - • 24 of 28 typedefs removed (86%) - • Code now follows AGENTS.md struct naming conventions - -Sun Jan 19 2026 10:30: Task 3 Completed - Legacy Test Cleanup - -CHANGES: - -1. Removed 7 obsolete test files: - - test_connection.c, test_connection_stress.c (conn_handle_t) - - test_sc_lib.c, test_udp_secure.c, test_utun_fork.c (sc_lib) - - test_utun_integration.c, test_full_stack.c (mixed legacy) - -2. Updated Makefile: - - Removed TEST_*_OBJS variables for deleted tests - - Removed build rules for deleted tests - - Removed from 'all' target (down to 10 tests from 16) - - Kept SC_LIB_OBJS (secure_channel/crc32, still needed) - -3. Updated 4 test files to new API: - - Replaced epkt_t* with struct ETCP_CONN* - - Replaced etcp_init() with etcp_create() - - Replaced conn_handle_t* with struct ETCP_SOCKET* (test_new_features.c) - -RESULTS: -- Test codebase reduced by 50% (7 of 14 test files removed) -- No remaining references to connection.h in tests -- No remaining references to sc_lib in test code -- Can now focus on current API for testing - -Sun Jan 19 2026 10:30: Code Style Refactoring Part 4 - secure_channel and utun_instance - -CHANGES: - -1. **secure_channel.h and secure_channel.c** - - Changed typedef struct {..} secure_channel_t to struct secure_channel {..} - - Updated all function signatures - -2. **utun_instance.h** - - Changed typedef struct utun_instance to struct UTUN_INSTANCE - - Updated function signatures - -3. **Multiple files updated** - - Replaced all utun_instance_t with struct UTUN_INSTANCE* - - Replaced all etcp_socket_t with struct ETCP_SOCKET* - -RESULTS: -- Reduced typedef struct from 8 to 6 across codebase -- All new structures (created after project start) converted to uppercase pattern -- Only remaining: 2 in etcp.h (etcp_t, utun_instance_t), 4 in ll_queue.h (u_async) - -Progress: 28 → 6 typedef structs removed (78% complete) -Files affected: 11 header files, 8 source files - -Sun Jan 18 2026 19:45: Code Style Refactoring Part 2 - More struct replacements - -CHANGES: - -1. **etcp_sockets.h** - - Removed legacy conn_handle_t (deprecated connection handle) - - Changed typedef struct etcp_socket to struct etcp_socket - - Updated callback signatures to use struct packet_buffer* - -2. **tun_if.h and tun_if.c** - - Changed typedef struct {..} tun_config_t to struct tun_config {..} - - Updated all function signatures - -3. **pkt_normalizer.h and pkt_normalizer.c** - - Removed typedef struct pn_struct pn_struct (forward decl) - - Removed typedef struct pkt_normalizer_pair pkt_normalizer_pair (forward decl) - - Changed struct definitions to use struct STRUCT_NAME pattern - - Updated all function signatures - -RESULTS: -- Reduced typedef struct from 28 to 18 (completed 10/28) -- Removed 3 forward declaration typedefs -- Updated 6 files total in this batch - -Remaining: 18 typedef structs in 6 files - -Sun Jan 18 2026 12:15: Config Parser Updated for utun_test.cfg Format - -CHANGES: - -1. **Config Parser (config_parser.c)** - - Added support for link=server:ip:port format in [client:] sections - - Each link= line creates separate client entry automatically - - Added SECTION_ROUTING for [routing] section (ignored for now) - - Fixed client name preservation across multiple links - - Prevent adding empty clients on EOF - -2. **utun_test.cfg (master config)** - - Updated to use new link= format for multiple connections - - Format: link=server_name:remote_ip:remote_port - - Example: link=wired1_fast:192.168.0.20:1234 - -3. **Test Results** - - Successfully parses 2 servers + 4 clients from utun_test.cfg - - init_connections correctly creates ETCP instances and links - - Socket creation fails only due to non-local IPs (expected) - -CONFIGURATION FILES: -- utun_test.cfg: master config with new format -- test_server.conf, test_client.conf: removed (no longer needed) - -Sun Jan 19 2026 13:09 -Removed duplicate init_connections from utun.c -- Deleted utun_state_t and all related legacy code -- Rewrote main() to use UTUN_INSTANCE API -- Removed 103 lines of obsolete code -Sun Jan 19 2026 13:24 -Fixed build - removed typedefs from ll_queue and packet_pool -- Updated ll_queue.h/.c to use struct instead of typedef -- Added struct definition for UTUN_INSTANCE fields -- Fixed memory_pool and packet_pool typedefs -Sun Jan 19 2026 13:57 -Removed config file parsing from debug_config -- Removed debug_parse_config_file() and auto-reload functionality -Sun Jan 19 2026 14:01 -Moved mainloop from utun_instance to main -- utun_instance_run() now does single iteration -- Added tun_read_callback to utun_instance -- Added utun_instance_register_sockets() -Sun Jan 19 2026 14:02 -Build successful - all refactoring complete -Sun Jan 19 2026 14:19 -Final: Build successful with refactored architecture -Sun Jan 19 2026 14:26 -Refactoring complete - utun binary ready -2026-01-18 16:38:15 -Добавлен config_updater.c/h - автоматическая генерация ключей и node_id при запуске -2026-01-18 17:17:40: secure_channel - переделана генерация nonce на SHA256(64bit urandom + 64bit counter + 32bit utime), счетчики расширены до 64bit -2026-01-18 17:22:28: sha256.c/h перемещены из src/ в lib/ -2026-01-18 18:17:37: Упрощена структура ETCP_CONNECTIONS - встроено uasync_add_socket, удалены обертки socket-функций -2026-01-18 19:32:55: Встроено шифрование и дешифрование в etcp_link_send и etcp_input. Добавлены счетчики ошибок и статистика. -2026-01-18 19:37:40: Имплементация шифрования завершена. Добавлена поддержка secure channel с AES-CCM, nonce и счетчиками. pubkey в конце INIT-пакетов. Клиенты загружают peer_public_key из конфига. -2026-01-18 20:38:35: Fixed etcp_link_new call, added etcp_socket_read_callback for uasync integration. -2026-01-18 21:20:56: Финальный отчет: Реально встроено шифрование с AES-CCM в etcp_link_send и etcp_input. Добавлены тесты. -2026-01-18 22:00:59: Fix critical bug: sc_derive_shared_key called inside sc_set_peer_public_key. Correct order for INIT: pubkey, derive, decrypt. Added peer_public_key for clients. diff --git a/configure.ac b/configure.ac index 4e4141c..c5950da 100644 --- a/configure.ac +++ b/configure.ac @@ -8,7 +8,7 @@ AC_CONFIG_MACRO_DIR([m4]) AC_PROG_CC AC_PROG_RANLIB AM_PROG_AR -AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror]) +AM_INIT_AUTOMAKE([foreign subdir-objects -Wall]) # Checks for programs AC_PROG_INSTALL diff --git a/doc/dgram_protocol.txt b/doc/dgram_protocol.txt new file mode 100644 index 0000000..80b2e19 --- /dev/null +++ b/doc/dgram_protocol.txt @@ -0,0 +1,2 @@ +форматы кодограмм протокола dgram: +- dgram протокол отправляет сообщения в очередь input pkt_normalizer. diff --git a/doc/etcp_arch.md b/doc/etcp_arch.md old mode 100755 new mode 100644 index 433b040..0878095 --- a/doc/etcp_arch.md +++ b/doc/etcp_arch.md @@ -7,9 +7,22 @@ ## etcp_loadbalancer: - выбирает через какой маршрут отправить пакет - ограничивает rate отправки чтобы не забивать очереди каналов +- сделан для совместной работы с etcp модулем +## pkt_normalizer: +- обеспечивает фрагментацию и сборку пакетов в единый поток для передачи через etcp. +- взаимодейстует с etcp и очередями для приема и передачи. +- в очередь для передачи может отправить любой модуль +- из очереди приёма пакеты забирает etcp_api + +## etcp_api: +- обеспечивает связь между etcp и остальными модулями +- имеет функцию которая забирает из normalizer принятые данные и перенаправляет их на нужный модуль +- имеет функцию connector_bind которой можно установить коллбэк для нужного типа кодограмм (первый байт). + ## etcp: - обеспечивает ретрансмиссии при передаче и сборку в правильной последовательности при приёме +- взаимодействует с pkt_normalizer и с udp сокетами для отправки-получения пакетов ## etcp_metric: - обеспечивает обновление метрик каналов etcp_connections diff --git a/doc/etcp_config.txt b/doc/etcp_config.txt old mode 100755 new mode 100644 diff --git a/lib/Makefile.am b/lib/Makefile.am index 7d41d56..3b61fe6 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -19,3 +19,21 @@ libuasync_a_CFLAGS = \ -DDEBUG_OUTPUT_STDERR \ -I$(top_srcdir)/src \ -I$(top_srcdir)/lib + +# Object directory for shadow build artifacts +OBJDIR = $(top_builddir)/.objs/lib + +# After building, move object files to shadow directory +all-local: shadow-objects + +shadow-objects: libuasync.a + @$(MKDIR_P) $(OBJDIR) + @for obj in $(libuasync_a_OBJECTS); do \ + if test -f "$$obj"; then \ + mv -f "$$obj" $(OBJDIR)/ 2>/dev/null || true; \ + fi; \ + done + +# Clean shadow directory along with regular clean +clean-local: + -rm -rf $(OBJDIR) diff --git a/lib/debug_config.c b/lib/debug_config.c index 3ffcd41..12faf10 100644 --- a/lib/debug_config.c +++ b/lib/debug_config.c @@ -1,7 +1,7 @@ -/** - * Debug module - */ - +/** + * Debug module + */ + #include "debug_config.h" #include #include @@ -12,214 +12,214 @@ #include #include #include - -#include -#include -#include -#include - -void log_dump(const char* prefix, const uint8_t* data, size_t len) { - // Build packet data as hex string for single-line output - char hex_buf[513]; // 256 bytes * 2 chars + 1 for null terminator - size_t hex_len = 0; - size_t show_len = (len > 128) ? 128 : len; // Show max 128 bytes - - for (size_t i = 0; i < show_len && hex_len < 512 - 3; i++) { - hex_len += snprintf(hex_buf + hex_len, sizeof(hex_buf) - hex_len, "%02x", data[i]); - if (i < show_len - 1 && (i + 1) % 32 == 0) { // Add space every 32 bytes - hex_len += snprintf(hex_buf + hex_len, sizeof(hex_buf) - hex_len, " "); - } - } - - if (len > 128) { - hex_len += snprintf(hex_buf + hex_len, sizeof(hex_buf) - hex_len, "..."); - } - - // Single-line debug output with packet info - DEBUG_INFO(DEBUG_CATEGORY_ETCP, "%s: len=%zu hex=%s", prefix, len, hex_buf); - - // Additional debug info for first few bytes -// if (len >= 2) { -// DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "%s: first_bytes=%02x%02x last_bytes=%02x%02x", -// prefix, data[0], data[1], data[len-2], data[len-1]); -// } -} - - -size_t addr_to_string(const struct sockaddr_storage *addr, char *buf, size_t buflen) { - if (!buf || buflen == 0) - return 0; - - buf[0] = '\0'; // всегда валидная строка - - char ip[INET6_ADDRSTRLEN]; - uint16_t port; - int n; - - if (addr->ss_family == AF_INET) { - const struct sockaddr_in *a = (const struct sockaddr_in *)addr; - inet_ntop(AF_INET, &a->sin_addr, ip, sizeof(ip)); - port = ntohs(a->sin_port); - - n = snprintf(buf, buflen, "%s:%u", ip, port); - - } else if (addr->ss_family == AF_INET6) { - const struct sockaddr_in6 *a = (const struct sockaddr_in6 *)addr; - inet_ntop(AF_INET6, &a->sin6_addr, ip, sizeof(ip)); - port = ntohs(a->sin6_port); - - n = snprintf(buf, buflen, "[%s]:%u", ip, port); - - } else { - return 0; - } - - // snprintf гарантирует '\0', но на всякий случай: - buf[buflen - 1] = '\0'; - - // Возвращаем фактическую длину (как snprintf) - return (n < 0) ? 0 : (size_t)n; -} - - -/* Get category by name */ -static debug_category_t get_category_by_name(const char* name) { - struct { - const char* n; - debug_category_t c; - } map[] = { - {"none", DEBUG_CATEGORY_NONE}, - {"uasync", DEBUG_CATEGORY_UASYNC}, - {"ll_queue", DEBUG_CATEGORY_LL_QUEUE}, - {"connection", DEBUG_CATEGORY_CONNECTION}, - {"etcp", DEBUG_CATEGORY_ETCP}, - {"crypto", DEBUG_CATEGORY_CRYPTO}, - {"memory", DEBUG_CATEGORY_MEMORY}, - {"timing", DEBUG_CATEGORY_TIMING}, - {"config", DEBUG_CATEGORY_CONFIG}, - {"tun", DEBUG_CATEGORY_TUN}, - {"routing", DEBUG_CATEGORY_ROUTING}, - {"timers", DEBUG_CATEGORY_TIMERS}, - {"all", DEBUG_CATEGORY_ALL}, - {NULL, 0} - }; - - for (int i = 0; map[i].n; i++) { - if (strcasecmp(map[i].n, name) == 0) { - return map[i].c; - } - } - return DEBUG_CATEGORY_NONE; -} - -/* Global debug configuration */ -debug_config_t g_debug_config; -FILE* debug_output_file = NULL; - -/* Initialize debug system with default settings */ -void debug_config_init(void) { - g_debug_config.level = DEBUG_LEVEL_ERROR; - g_debug_config.categories = DEBUG_CATEGORY_ALL; - g_debug_config.timestamp_enabled = 1; - g_debug_config.function_name_enabled = 1; - g_debug_config.file_line_enabled = 1; - g_debug_config.output_file = NULL; - - if (debug_output_file && debug_output_file != stdout && debug_output_file != stderr) { - fclose(debug_output_file); - } - debug_output_file = stdout; -} - -/* Set debug level */ -void debug_set_level(debug_level_t level) { - g_debug_config.level = level; -} - -/* Enable/disable specific categories */ -void debug_enable_category(debug_category_t category) { - g_debug_config.categories |= category; -} - -void debug_disable_category(debug_category_t category) { - g_debug_config.categories &= ~category; -} - -void debug_set_categories(debug_category_t categories) { - g_debug_config.categories = categories; -} - -/* Set masks directly */ -void debug_set_masks(debug_category_t categories, debug_level_t level) { - g_debug_config.categories = categories; - g_debug_config.level = level; -} - -void debug_enable_function_name(int enable) { - g_debug_config.function_name_enabled = enable; -} - -void debug_enable_file_line(int enable) { - g_debug_config.file_line_enabled = enable; -} - -void debug_set_output_file(const char* file_path) { - if (debug_output_file) return;// уже установлен, кто первый того и тапки - FILE* new_file = fopen(file_path, "a"); - if (new_file) { - debug_output_file = new_file; - g_debug_config.output_file = file_path; - } -} - -/* Check if debug output should be shown for given level and category */ -int debug_should_output(debug_level_t level, debug_category_t category) { - - /* Check if category is enabled */ - if (!(g_debug_config.categories & category)) { - return 0; - } - - /* Check if level is sufficient */ - if (level > g_debug_config.level) { - return 0; - } - - return 1; -} - -/* Get current debug level */ -debug_level_t debug_get_level(void) { - return g_debug_config.level; -} - -/* Get level name */ -static const char* get_level_name(debug_level_t level) { - switch (level) { - case DEBUG_LEVEL_ERROR: return "ERROR"; - case DEBUG_LEVEL_WARN: return "WARN"; - case DEBUG_LEVEL_INFO: return "INFO"; - case DEBUG_LEVEL_DEBUG: return "DEBUG"; - case DEBUG_LEVEL_TRACE: return "TRACE"; - default: return "UNKNOWN"; - } -} - -/* Format and output debug message */ -void debug_output(debug_level_t level, debug_category_t category, - const char* function, const char* file, int line, - const char* format, ...) { - -#define BUFFER_SIZE 4096 - char buffer[BUFFER_SIZE]; - int offset = 0; - size_t remaining = BUFFER_SIZE; - - va_list args; - va_start(args, format); - - FILE* output = debug_output_file ? debug_output_file : stdout; - + +#include +#include +#include +#include + +void log_dump(const char* prefix, const uint8_t* data, size_t len) { + // Build packet data as hex string for single-line output + char hex_buf[513]; // 256 bytes * 2 chars + 1 for null terminator + size_t hex_len = 0; + size_t show_len = (len > 128) ? 128 : len; // Show max 128 bytes + + for (size_t i = 0; i < show_len && hex_len < 512 - 3; i++) { + hex_len += snprintf(hex_buf + hex_len, sizeof(hex_buf) - hex_len, "%02x", data[i]); + if (i < show_len - 1 && (i + 1) % 32 == 0) { // Add space every 32 bytes + hex_len += snprintf(hex_buf + hex_len, sizeof(hex_buf) - hex_len, " "); + } + } + + if (len > 128) { + hex_len += snprintf(hex_buf + hex_len, sizeof(hex_buf) - hex_len, "..."); + } + + // Single-line debug output with packet info + DEBUG_INFO(DEBUG_CATEGORY_ETCP, "%s: len=%zu hex=%s", prefix, len, hex_buf); + + // Additional debug info for first few bytes +// if (len >= 2) { +// DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "%s: first_bytes=%02x%02x last_bytes=%02x%02x", +// prefix, data[0], data[1], data[len-2], data[len-1]); +// } +} + + +size_t addr_to_string(const struct sockaddr_storage *addr, char *buf, size_t buflen) { + if (!buf || buflen == 0) + return 0; + + buf[0] = '\0'; // всегда валидная строка + + char ip[INET6_ADDRSTRLEN]; + uint16_t port; + int n; + + if (addr->ss_family == AF_INET) { + const struct sockaddr_in *a = (const struct sockaddr_in *)addr; + inet_ntop(AF_INET, &a->sin_addr, ip, sizeof(ip)); + port = ntohs(a->sin_port); + + n = snprintf(buf, buflen, "%s:%u", ip, port); + + } else if (addr->ss_family == AF_INET6) { + const struct sockaddr_in6 *a = (const struct sockaddr_in6 *)addr; + inet_ntop(AF_INET6, &a->sin6_addr, ip, sizeof(ip)); + port = ntohs(a->sin6_port); + + n = snprintf(buf, buflen, "[%s]:%u", ip, port); + + } else { + return 0; + } + + // snprintf гарантирует '\0', но на всякий случай: + buf[buflen - 1] = '\0'; + + // Возвращаем фактическую длину (как snprintf) + return (n < 0) ? 0 : (size_t)n; +} + + +/* Get category by name */ +static debug_category_t get_category_by_name(const char* name) { + struct { + const char* n; + debug_category_t c; + } map[] = { + {"none", DEBUG_CATEGORY_NONE}, + {"uasync", DEBUG_CATEGORY_UASYNC}, + {"ll_queue", DEBUG_CATEGORY_LL_QUEUE}, + {"connection", DEBUG_CATEGORY_CONNECTION}, + {"etcp", DEBUG_CATEGORY_ETCP}, + {"crypto", DEBUG_CATEGORY_CRYPTO}, + {"memory", DEBUG_CATEGORY_MEMORY}, + {"timing", DEBUG_CATEGORY_TIMING}, + {"config", DEBUG_CATEGORY_CONFIG}, + {"tun", DEBUG_CATEGORY_TUN}, + {"routing", DEBUG_CATEGORY_ROUTING}, + {"timers", DEBUG_CATEGORY_TIMERS}, + {"all", DEBUG_CATEGORY_ALL}, + {NULL, 0} + }; + + for (int i = 0; map[i].n; i++) { + if (strcasecmp(map[i].n, name) == 0) { + return map[i].c; + } + } + return DEBUG_CATEGORY_NONE; +} + +/* Global debug configuration */ +debug_config_t g_debug_config; +FILE* debug_output_file = NULL; + +/* Initialize debug system with default settings */ +void debug_config_init(void) { + g_debug_config.level = DEBUG_LEVEL_ERROR; + g_debug_config.categories = DEBUG_CATEGORY_ALL; + g_debug_config.timestamp_enabled = 1; + g_debug_config.function_name_enabled = 1; + g_debug_config.file_line_enabled = 1; + g_debug_config.output_file = NULL; + + if (debug_output_file && debug_output_file != stdout && debug_output_file != stderr) { + fclose(debug_output_file); + } + debug_output_file = stdout; +} + +/* Set debug level */ +void debug_set_level(debug_level_t level) { + g_debug_config.level = level; +} + +/* Enable/disable specific categories */ +void debug_enable_category(debug_category_t category) { + g_debug_config.categories |= category; +} + +void debug_disable_category(debug_category_t category) { + g_debug_config.categories &= ~category; +} + +void debug_set_categories(debug_category_t categories) { + g_debug_config.categories = categories; +} + +/* Set masks directly */ +void debug_set_masks(debug_category_t categories, debug_level_t level) { + g_debug_config.categories = categories; + g_debug_config.level = level; +} + +void debug_enable_function_name(int enable) { + g_debug_config.function_name_enabled = enable; +} + +void debug_enable_file_line(int enable) { + g_debug_config.file_line_enabled = enable; +} + +void debug_set_output_file(const char* file_path) { + if (debug_output_file) return;// уже установлен, кто первый того и тапки + FILE* new_file = fopen(file_path, "a"); + if (new_file) { + debug_output_file = new_file; + g_debug_config.output_file = file_path; + } +} + +/* Check if debug output should be shown for given level and category */ +int debug_should_output(debug_level_t level, debug_category_t category) { + + /* Check if category is enabled */ + if (!(g_debug_config.categories & category)) { + return 0; + } + + /* Check if level is sufficient */ + if (level > g_debug_config.level) { + return 0; + } + + return 1; +} + +/* Get current debug level */ +debug_level_t debug_get_level(void) { + return g_debug_config.level; +} + +/* Get level name */ +static const char* get_level_name(debug_level_t level) { + switch (level) { + case DEBUG_LEVEL_ERROR: return "ERROR"; + case DEBUG_LEVEL_WARN: return "WARN"; + case DEBUG_LEVEL_INFO: return "INFO"; + case DEBUG_LEVEL_DEBUG: return "DEBUG"; + case DEBUG_LEVEL_TRACE: return "TRACE"; + default: return "UNKNOWN"; + } +} + +/* Format and output debug message */ +void debug_output(debug_level_t level, debug_category_t category, + const char* function, const char* file, int line, + const char* format, ...) { + +#define BUFFER_SIZE 4096 + char buffer[BUFFER_SIZE]; + int offset = 0; + size_t remaining = BUFFER_SIZE; + + va_list args; + va_start(args, format); + + FILE* output = debug_output_file ? debug_output_file : stdout; + /* Add timestamp with microseconds: hh:mm:ss-xxx.yyy */ struct timeval tv; gettimeofday(&tv, NULL); @@ -228,16 +228,16 @@ void debug_output(debug_level_t level, debug_category_t category, strftime(time_str, sizeof(time_str), "%H:%M:%S", tm_info); offset += snprintf(buffer + offset, remaining, "[%s-%03ld.%03ld] ", time_str, tv.tv_usec / 1000, tv.tv_usec % 1000); remaining = BUFFER_SIZE - offset; - - /* Add level */ - const char* level_name = get_level_name(level); - offset += snprintf(buffer + offset, remaining, "[%s] ", level_name); - remaining = BUFFER_SIZE - offset; - - /* Add category */ - offset += snprintf(buffer + offset, remaining, "[%llu] ", (unsigned long long)category); - remaining = BUFFER_SIZE - offset; - + + /* Add level */ + const char* level_name = get_level_name(level); + offset += snprintf(buffer + offset, remaining, "[%s] ", level_name); + remaining = BUFFER_SIZE - offset; + + /* Add category */ + offset += snprintf(buffer + offset, remaining, "[%llu] ", (unsigned long long)category); + remaining = BUFFER_SIZE - offset; + /* Add file:line if enabled */ if (g_debug_config.file_line_enabled && file) { offset += snprintf(buffer + offset, remaining, "(%s:%d) ", file, line); @@ -249,97 +249,97 @@ void debug_output(debug_level_t level, debug_category_t category, offset += snprintf(buffer + offset, remaining, "%s() ", function); remaining = BUFFER_SIZE - offset; } - - /* Add the actual message */ - offset += vsnprintf(buffer + offset, remaining, format, args); - remaining = BUFFER_SIZE - offset; - - /* Add newline */ - if (remaining > 1) { - buffer[offset] = '\n'; - buffer[offset + 1] = '\0'; - } else { - buffer[BUFFER_SIZE - 2] = '\n'; - buffer[BUFFER_SIZE - 1] = '\0'; - } - - va_end(args); - - /* Output the entire line at once */ - fprintf(output, "%s", buffer); - fflush(output); -#undef BUFFER_SIZE -} - -/* Parse debug configuration from string */ -int debug_parse_config(const char* config_string) { - if (!config_string || !*config_string) { - return 0; - } - - char* str = strdup(config_string); - if (!str) { - return -1; - } - - debug_category_t categories = 0; - debug_level_t level = DEBUG_LEVEL_NONE; - - char* token = strtok(str, ";"); - while (token) { - /* Trim leading spaces */ - while (isspace(*token)) { - token++; - } - - char* eq = strchr(token, '='); - if (!eq) { - free(str); - return -1; - } - - *eq = '\0'; - char* key = token; - char* value = eq + 1; - - /* Trim leading spaces in value */ - while (isspace(*value)) { - value++; - } - - if (strcasecmp(key, "modules") == 0) { - char* mod_token = strtok(value, ","); - while (mod_token) { - /* Trim leading spaces */ - while (isspace(*mod_token)) { - mod_token++; - } - - debug_category_t cat = get_category_by_name(mod_token); - if (cat == DEBUG_CATEGORY_NONE) { - free(str); - return -1; - } - categories |= cat; - mod_token = strtok(NULL, ","); - } - } else if (strcasecmp(key, "level") == 0) { - int lev_num = atoi(value); - if (lev_num < DEBUG_LEVEL_NONE || lev_num > DEBUG_LEVEL_TRACE) { - free(str); - return -1; - } - level = (debug_level_t)lev_num; - } else { - free(str); - return -1; - } - - token = strtok(NULL, ";"); - } - - debug_set_masks(categories, level); - - free(str); - return 0; -} + + /* Add the actual message */ + offset += vsnprintf(buffer + offset, remaining, format, args); + remaining = BUFFER_SIZE - offset; + + /* Add newline */ + if (remaining > 1) { + buffer[offset] = '\n'; + buffer[offset + 1] = '\0'; + } else { + buffer[BUFFER_SIZE - 2] = '\n'; + buffer[BUFFER_SIZE - 1] = '\0'; + } + + va_end(args); + + /* Output the entire line at once */ + fprintf(output, "%s", buffer); + fflush(output); +#undef BUFFER_SIZE +} + +/* Parse debug configuration from string */ +int debug_parse_config(const char* config_string) { + if (!config_string || !*config_string) { + return 0; + } + + char* str = strdup(config_string); + if (!str) { + return -1; + } + + debug_category_t categories = 0; + debug_level_t level = DEBUG_LEVEL_NONE; + + char* token = strtok(str, ";"); + while (token) { + /* Trim leading spaces */ + while (isspace(*token)) { + token++; + } + + char* eq = strchr(token, '='); + if (!eq) { + free(str); + return -1; + } + + *eq = '\0'; + char* key = token; + char* value = eq + 1; + + /* Trim leading spaces in value */ + while (isspace(*value)) { + value++; + } + + if (strcasecmp(key, "modules") == 0) { + char* mod_token = strtok(value, ","); + while (mod_token) { + /* Trim leading spaces */ + while (isspace(*mod_token)) { + mod_token++; + } + + debug_category_t cat = get_category_by_name(mod_token); + if (cat == DEBUG_CATEGORY_NONE) { + free(str); + return -1; + } + categories |= cat; + mod_token = strtok(NULL, ","); + } + } else if (strcasecmp(key, "level") == 0) { + int lev_num = atoi(value); + if (lev_num < DEBUG_LEVEL_NONE || lev_num > DEBUG_LEVEL_TRACE) { + free(str); + return -1; + } + level = (debug_level_t)lev_num; + } else { + free(str); + return -1; + } + + token = strtok(NULL, ";"); + } + + debug_set_masks(categories, level); + + free(str); + return 0; +} diff --git a/lib/ll_queue.c b/lib/ll_queue.c old mode 100755 new mode 100644 diff --git a/lib/ll_queue.h1 b/lib/ll_queue.h1 old mode 100755 new mode 100644 diff --git a/lib/sha256.c b/lib/sha256.c old mode 100755 new mode 100644 diff --git a/lib/sha256.h b/lib/sha256.h old mode 100755 new mode 100644 diff --git a/lib/timeout_heap.c1 b/lib/timeout_heap.c1 old mode 100755 new mode 100644 diff --git a/lib/u_async.c1 b/lib/u_async.c1 old mode 100755 new mode 100644 diff --git a/src/Makefile.am b/src/Makefile.am index 253753d..a519e25 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -60,6 +60,33 @@ else utun_LDADD = $(utun_CORE_LDADD) endif +# Object directory for shadow build artifacts +OBJDIR = $(top_builddir)/.objs/src +TINYCRYPT_OBJDIR = $(top_builddir)/.objs/tinycrypt + +# After building, move object files to shadow directory +all-local: shadow-objects + +shadow-objects: utun$(EXEEXT) + @$(MKDIR_P) $(OBJDIR) $(TINYCRYPT_OBJDIR) + @for obj in $(utun_OBJECTS); do \ + if test -f "$$obj"; then \ + case "$$obj" in \ + *lib/source/*.o) \ + base=$$(basename $$obj | sed 's/^utun-//'); \ + mv -f "$$obj" $(TINYCRYPT_OBJDIR)/"$$base" 2>/dev/null || true; \ + ;; \ + *) \ + mv -f "$$obj" $(OBJDIR)/ 2>/dev/null || true; \ + ;; \ + esac; \ + fi; \ + done + +# Clean shadow directories along with regular clean +clean-local: + -rm -rf $(OBJDIR) $(TINYCRYPT_OBJDIR) + # Install directories install-exec-hook: $(MKDIR_P) $(DESTDIR)$(bindir) diff --git a/src/aa b/src/aa old mode 100755 new mode 100644 diff --git a/src/ab b/src/ab new file mode 100644 index 0000000..6b57822 --- /dev/null +++ b/src/ab @@ -0,0 +1,31 @@ +Вопрос. Прошло пол года. +У нас появился профессиональный ремонтник? +А технолог? +А админ? + +А почему? +К чему привели сотни часов длительных разговоров с сотрудниками, есть какие-то ощутимые улучшения? Кроме того что саботажники притихли и теперь осторожность проявляют чтоб лишнего не ляпнуть + +игнорирование техпроцесса сегодня - это катастрофа завтра. +«Проблема сегодня — это потеря X денег завтра. Ты можешь это исправить быстро, а если подождёшь, то последствия будут более серьёзными и дорогими.» + +Обучение без внутренней мотивации почти всегда даёт слабый и нестабильный результат. +Инициативу нельзя “внедрить”. +Можно только создать условия, где она либо появляется, либо становится очевидно, что её не будет. + +Что реально можно попробовать (если всё же хочешь шанс) +1. Проверка “а хочет ли он вообще” +Прямо и спокойно: +«Я готов вложить время, но мне важно понять — тебе это нужно?» +Ответ без конкретики = плохой знак. + +Главный посыл - сколько не читай лекций и не заставляй учиться - человек умней не станет, и не станет лучше работать, пока сам не захочет и сам не начнёт учиться. А учиться это всегда долго и сложно. Да, можно временно "ограничить" проблемных людей, но толку с этого ровно ноль. Только потерянное время на сотню часов болтовни. +А если учить - то ну не персионеров же, это мягко говоря зашквар. Единственный вариант для дедушек - чтобы они выпоняли только ту работу которой уже научились и которая у них хорошо получается. + +Я видел много примеров когда человек сам проявляет инициаливу, интересуется, учится и быстро растёт. точнее это единственный сценарий, по которому выросли профессионалы. Большинство профессионалов даже институт забросили потому что им интересно было ковыряться в их любимой тематике, а не слушать тот бред который преподы втирают. Вспомни Дожбса, Гейтса, да кого угодно возими. +И не одного случая серьезного роста когда пришли в котору и объявили - а теперь всем на повышение квалификации. теперь каждый второй день - учимся. Это скорей про потрать бабло преподам на имитацию обучения. + + +В моём понимании уже край как нужен адекватный технолог/ремонтник/руководитель, возможно в одном лице. +Но. у меня есть опасения что текущий состав дедов его зачмырит как более опытного и угрозу их насиженному месту. +Как действовать? какой план? \ No newline at end of file diff --git a/src/etcp.c b/src/etcp.c index 1fb2ebd..8a33328 100644 --- a/src/etcp.c +++ b/src/etcp.c @@ -270,7 +270,7 @@ void etcp_update_log_name(struct ETCP_CONN* etcp) { // Send data through ETCP connection // Allocates memory from data_pool and places in input queue // Returns: 0 on success, -1 on failure -int etcp_send(struct ETCP_CONN* etcp, const void* data, uint16_t len) { +int etcp_int_send(struct ETCP_CONN* etcp, const void* data, uint16_t len) { DEBUG_TRACE(DEBUG_CATEGORY_ETCP, ""); if (!etcp || !data || len == 0) { diff --git a/src/etcp.h b/src/etcp.h index c340232..656b685 100644 --- a/src/etcp.h +++ b/src/etcp.h @@ -156,7 +156,7 @@ void etcp_conn_input(struct ETCP_DGRAM* pkt); // Send data through ETCP connection // Allocates memory from data_pool and places in input queue // Returns: 0 on success, -1 on failure -int etcp_send(struct ETCP_CONN* etcp, const void* data, uint16_t len); +int etcp_int_send(struct ETCP_CONN* etcp, const void* data, uint16_t len); // Request next packet for load balancer struct ETCP_DGRAM* etcp_request_pkt(struct ETCP_CONN* etcp); diff --git a/src/etcp_api.h b/src/etcp_api.h new file mode 100644 index 0000000..0c671c0 --- /dev/null +++ b/src/etcp_api.h @@ -0,0 +1,5 @@ +/* api для приёма-передачи пакетов через etcp + +1. + +*/ \ No newline at end of file diff --git a/src/etcp_loadbalancer.c b/src/etcp_loadbalancer.c old mode 100755 new mode 100644 diff --git a/src/etcp_loadbalancer.h b/src/etcp_loadbalancer.h old mode 100755 new mode 100644 diff --git a/src/etcp_send_test.txt b/src/etcp_send_test.txt old mode 100755 new mode 100644 diff --git a/src/pkt_normalizer.h b/src/pkt_normalizer.h index 48d0fcc..6ba76af 100644 --- a/src/pkt_normalizer.h +++ b/src/pkt_normalizer.h @@ -6,6 +6,15 @@ #include "../lib/u_async.h" #include +/* +формат кодограмм: +cmd = 0 - пакет для передачи адресату (далее содержимое пакета) +cmd = 1 - элемент роутинг-таблицы (далее один маршрут) +cmd = 2 - запрос роутинг-таблицы (без данных) + + +*/ + // Структура для packer struct PKTNORM { // public: diff --git a/src/req.txt b/src/req.txt old mode 100755 new mode 100644 index 1ee6d96..8bd041c --- a/src/req.txt +++ b/src/req.txt @@ -12,6 +12,7 @@ overall score = правило выбираемок пользователем - либо minimum delay Формат данных: +todo... tun -> (src/dst ip) -> routing table -> next hop -> transmit to -> etcp -> routing -> tun diff --git a/src/route_lib.c b/src/route_lib.c index 1212df3..32061a6 100644 --- a/src/route_lib.c +++ b/src/route_lib.c @@ -33,8 +33,8 @@ int parse_subnet(const char *subnet_str, uint32_t *network, uint8_t *prefix_leng static int compare_routes(const void *a, const void *b) { - const struct route_entry *route_a = (const struct route_entry *)a; - const struct route_entry *route_b = (const struct route_entry *)b; + const struct ROUTE_ENTRY *route_a = (const struct ROUTE_ENTRY *)a; + const struct ROUTE_ENTRY *route_b = (const struct ROUTE_ENTRY *)b; // First compare by prefix length (longest prefix first) if (route_b->prefix_length != route_a->prefix_length) { @@ -62,15 +62,15 @@ static int compare_routes(const void *a, const void *b) { return route_a->metrics.hop_count - route_b->metrics.hop_count; } -struct route_table *route_table_create(void) { - struct route_table *table = calloc(1, sizeof(struct route_table)); +struct ROUTE_TABLE *route_table_create(void) { + struct ROUTE_TABLE *table = calloc(1, sizeof(struct ROUTE_TABLE)); if (!table) { DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "route_table_create: failed to allocate memory for routing table"); return NULL; } table->capacity = INITIAL_ROUTE_CAPACITY; - table->entries = calloc(table->capacity, sizeof(struct route_entry)); + table->entries = calloc(table->capacity, sizeof(struct ROUTE_ENTRY)); if (!table->entries) { DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "route_table_create: failed to allocate memory for %d route entries", table->capacity); free(table); @@ -93,7 +93,7 @@ struct route_table *route_table_create(void) { return table; } -void route_table_destroy(struct route_table *table) { +void route_table_destroy(struct ROUTE_TABLE *table) { if (!table) return; // Free route entries @@ -106,7 +106,7 @@ void route_table_destroy(struct route_table *table) { free(table); } -bool route_table_insert(struct route_table *table, const struct route_entry *entry) { +bool route_table_insert(struct ROUTE_TABLE *table, const struct ROUTE_ENTRY *entry) { if (!table || !entry) return false; // Validate the route @@ -123,7 +123,7 @@ bool route_table_insert(struct route_table *table, const struct route_entry *ent // Check if we need to expand the table if (table->count >= table->capacity) { size_t new_capacity = table->capacity * ROUTE_EXPANSION_FACTOR; - struct route_entry *new_entries = realloc(table->entries, new_capacity * sizeof(struct route_entry)); + struct ROUTE_ENTRY *new_entries = realloc(table->entries, new_capacity * sizeof(struct ROUTE_ENTRY)); if (!new_entries) { DEBUG_ERROR(DEBUG_CATEGORY_MEMORY, "route_table_insert: failed to expand routing table to %zu entries", new_capacity); return false; @@ -134,10 +134,9 @@ bool route_table_insert(struct route_table *table, const struct route_entry *ent } // Set timestamps and ensure route is active - struct route_entry new_entry = *entry; + struct ROUTE_ENTRY new_entry = *entry; new_entry.created_time = new_entry.last_update = (uint64_t)time(NULL) * 1000000; // Convert to microseconds - new_entry.last_used = 0; - + // Ensure route is active by default if (!(new_entry.flags & ROUTE_FLAG_ACTIVE)) { new_entry.flags |= ROUTE_FLAG_ACTIVE; @@ -146,7 +145,6 @@ bool route_table_insert(struct route_table *table, const struct route_entry *ent // Insert and maintain sorted order - table->stats.routes_added++; size_t insert_pos = table->count; for (size_t i = 0; i < table->count; i++) { if (compare_routes(&new_entry, &table->entries[i]) < 0) { @@ -158,37 +156,33 @@ bool route_table_insert(struct route_table *table, const struct route_entry *ent return false; } -bool route_table_lookup(struct route_table *table, uint32_t dest_ip, struct route_entry *best_route) { +bool route_table_lookup(struct ROUTE_TABLE *table, uint32_t dest_ip, struct ROUTE_ENTRY *best_route) { if (!table || !best_route) { DEBUG_WARN(DEBUG_CATEGORY_ROUTING, "route_table_lookup: invalid parameters (table=%p, best_route=%p)", table, best_route); return false; } - - table->stats.lookup_count++; - + // Find longest prefix match for (size_t i = 0; i < table->count; i++) { - const struct route_entry *entry = &table->entries[i]; - + const struct ROUTE_ENTRY *entry = &table->entries[i]; + // Check if route is valid and matches destination if (entry->flags & ROUTE_FLAG_ACTIVE) { uint32_t mask = (entry->prefix_length == 0) ? 0 : (0xFFFFFFFFU << (32 - entry->prefix_length)); if ((dest_ip & mask) == (entry->network & mask)) { *best_route = *entry; best_route->last_update = (uint64_t)time(NULL) * 1000000; - + char ip_str[16]; ip_to_string(dest_ip, ip_str); DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "Found route for %s: %s/%d", ip_str, ip_to_string(entry->network, ip_str), entry->prefix_length); - - table->stats.hit_count++; - table->stats.routes_lookup_hits++; + return true; } } } - + // No route found char ip_str[16]; ip_to_string(dest_ip, ip_str); @@ -197,7 +191,7 @@ bool route_table_lookup(struct route_table *table, uint32_t dest_ip, struct rout return false; } -bool route_validate_route(struct route_table *table, uint32_t network, uint8_t prefix_length, route_type_t route_type) { +bool route_validate_route(struct ROUTE_TABLE *table, uint32_t network, uint8_t prefix_length, route_type_t route_type) { if (!table) return false; uint32_t *validation_ranges = NULL; @@ -216,17 +210,16 @@ bool route_validate_route(struct route_table *table, uint32_t network, uint8_t p range_count = table->local_subnet_count; break; default: - table->stats.routes_lookup_misses++; return false; } - + if (range_count == 0) return true; // No validation ranges configured - + // Check if network falls within any validation range for (size_t i = 0; i < range_count; i += 2) { uint32_t range_network = validation_ranges[i]; uint8_t range_prefix = (uint8_t)validation_ranges[i + 1]; - + uint32_t mask = (range_prefix == 0) ? 0 : (0xFFFFFFFFU << (32 - range_prefix)); if ((network & mask) == (range_network & mask)) { // Check if this route is more specific than or equal to the validation range @@ -235,22 +228,22 @@ bool route_validate_route(struct route_table *table, uint32_t network, uint8_t p } } } - + return false; } -static bool enhanced_route_add_subnet_range(struct route_table *table, uint32_t network, uint8_t prefix_length, uint32_t **ranges, size_t *count) { +static bool enhanced_route_add_subnet_range(struct ROUTE_TABLE *table, uint32_t network, uint8_t prefix_length, uint32_t **ranges, size_t *count) { if (!table || !ranges || !count) return false; - + if (*count >= MAX_SUBNET_VALIDATION_RANGES - 2) return false; - + // Expand array if needed if (*ranges == NULL) { *ranges = calloc(MAX_SUBNET_VALIDATION_RANGES, sizeof(uint32_t)); if (!*ranges) return false; *count = 0; } - + // Add network and prefix length as a pair (*ranges)[*count] = network; (*ranges)[*count + 1] = prefix_length; @@ -265,37 +258,37 @@ static bool enhanced_route_add_subnet_range(struct route_table *table, uint32_t -bool route_add_dynamic_subnet(struct route_table *table, uint32_t network, uint8_t prefix_length) { +bool route_add_dynamic_subnet(struct ROUTE_TABLE *table, uint32_t network, uint8_t prefix_length) { return enhanced_route_add_subnet_range(table, network, prefix_length, &table->dynamic_subnets, &table->dynamic_subnet_count); } -bool route_add_local_subnet(struct route_table *table, uint32_t network, uint8_t prefix_length) { +bool route_add_local_subnet(struct ROUTE_TABLE *table, uint32_t network, uint8_t prefix_length) { return enhanced_route_add_subnet_range(table, network, prefix_length, &table->local_subnets, &table->local_subnet_count); } -bool route_get_all_routes(const struct route_table *table, uint32_t network, uint8_t prefix_length, - struct route_entry **routes, size_t *count) { +bool route_get_all_routes(const struct ROUTE_TABLE *table, uint32_t network, uint8_t prefix_length, + struct ROUTE_ENTRY **routes, size_t *count) { if (!table || !routes || !count) return false; - + *routes = NULL; *count = 0; - + // Count matching routes for (size_t i = 0; i < table->count; i++) { if (table->entries[i].network == network && table->entries[i].prefix_length == prefix_length) { (*count)++; } } - + if (*count == 0) return true; // No routes found, but not an error - + // Allocate result array - *routes = calloc(*count, sizeof(struct route_entry)); + *routes = calloc(*count, sizeof(struct ROUTE_ENTRY)); if (!*routes) { *count = 0; return false; } - + // Copy matching routes size_t result_index = 0; for (size_t i = 0; i < table->count; i++) { @@ -305,26 +298,26 @@ bool route_get_all_routes(const struct route_table *table, uint32_t network, uin result_index++; } } - + return true; } -void route_table_print(const struct route_table *table) { +void route_table_print(const struct ROUTE_TABLE *table) { if (!table) return; - + DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "=== Routing Table ==="); DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "Total routes: %zu", table->count); DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "Dynamic subnets: %zu, Local subnets: %zu", table->dynamic_subnet_count / 2, table->local_subnet_count / 2); - + if (table->count > 0) { DEBUG_INFO(DEBUG_CATEGORY_ROUTING, "Routes:"); for (size_t i = 0; i < table->count; i++) { - const struct route_entry *entry = &table->entries[i]; + const struct ROUTE_ENTRY *entry = &table->entries[i]; char network_str[16], next_hop_str[16]; - + ip_to_string(entry->network, network_str); - + DEBUG_INFO(DEBUG_CATEGORY_ROUTING, " %zu: %s/%d -> %s [%s]", i + 1, network_str, entry->prefix_length, next_hop_str, route_type_to_string(entry->type)); diff --git a/src/route_lib.h b/src/route_lib.h index 29fa879..b52e7d7 100644 --- a/src/route_lib.h +++ b/src/route_lib.h @@ -32,29 +32,37 @@ typedef enum { * * Структура содержит дополнительные метрики для оценки качества маршрута. */ -struct route_metrics { +struct ROUTE_METRICS { + uint32_t metric; /**< общее качество подсчитанное из метрик (меньше - лучше) */ uint32_t bandwidth_kbps; /**< Пропускная способность в Кбит/с */ - uint16_t packet_loss_rate; /**< Уровень потери пакетов (в промилле) */ + uint16_t packet_loss_rate; /**< Уровень потери пакетов (x0.1%) */ uint16_t latency_ms; /**< Задержка в миллисекундах */ uint8_t hop_count; /**< Количество прыжков */ uint64_t last_updated; /**< Время последнего обновления (в микросекундах) */ }; +struct ROUTE_ARRAY { + uint32_t capacity;// max число элементов (для realloc) + uint32_t routes; /**< число маршрутов в массиве */ + uint32_t ip; /**< адрес назначения */ + struct ROUTE_ENTRY* entries[0]; /**< массив указателей на роуты */ +}; + + /** * @brief Расширенная запись маршрута * * Структура представляет собой отдельную запись в таблице маршрутизации с детальной информацией о маршруте. */ -struct route_entry { +struct ROUTE_ENTRY { uint32_t network; /**< Сетевой адрес */ uint8_t prefix_length; /**< Длина префикса подсети */ struct ETCP_SOCKET* next_hop; /**< Указатель на сокет следующего хопа */ route_type_t type; /**< Тип маршрута */ uint8_t flags; /**< Флаги маршрута */ - struct route_metrics metrics; /**< Метрики маршрута */ + struct ROUTE_METRICS metrics; /**< Метрики маршрута */ uint64_t created_time; /**< Время создания (в микросекундах) */ uint64_t last_update; /**< Время последнего обновления (в микросекундах) */ - uint64_t last_used; /**< Время последнего использования (в микросекундах) */ }; /** @@ -62,8 +70,8 @@ struct route_entry { * * Структура представляет собой таблицу маршрутизации, содержащую записи маршрутов, подсети и статистику. */ -struct route_table { - struct route_entry *entries; /**< Массив записей маршрутов */ +struct ROUTE_TABLE { + struct ROUTE_ENTRY *entries; /**< Массив записей маршрутов */ size_t count; /**< Текущее количество записей */ size_t capacity; /**< Максимальная емкость таблицы */ uint32_t *dynamic_subnets; /**< Динамические подсети (массив пар: сеть, префикс) */ @@ -71,18 +79,10 @@ struct route_table { uint32_t *local_subnets; /**< Локальные подсети (массив пар: сеть, префикс) */ size_t local_subnet_count; /**< Количество локальных подсетей */ struct { - uint64_t total_routes; /**< Общее количество маршрутов */ - uint64_t static_routes; /**< Количество статических маршрутов */ - uint64_t dynamic_routes; /**< Количество динамических маршрутов */ uint64_t local_routes; /**< Количество локальных маршрутов */ uint64_t learned_routes; /**< Количество изученных маршрутов */ - uint64_t routes_added; /**< Количество добавленных маршрутов */ - uint64_t routes_deleted; /**< Количество удаленных маршрутов */ - uint64_t lookup_count; /**< Количество запросов поиска */ - uint64_t hit_count; /**< Количество успешных поисков */ uint64_t routes_lookup_hits; /**< Количество попаданий в поиск маршрутов */ uint64_t routes_lookup_misses; /**< Количество промахов в поиск маршрутов */ - uint64_t validation_failures; /**< Количество неудачных валидаций */ } stats; /**< Статистика таблицы маршрутизации */ }; @@ -91,14 +91,14 @@ struct route_table { * * @return Указатель на созданную таблицу или NULL в случае ошибки */ -struct route_table *route_table_create(void); +struct ROUTE_TABLE *route_table_create(void); /** * @brief Уничтожает таблицу маршрутизации и освобождает ресурсы * * @param table Указатель на таблицу маршрутизации */ -void route_table_destroy(struct route_table *table); +void route_table_destroy(struct ROUTE_TABLE *table); /** * @brief Вставляет новую запись в таблицу маршрутизации @@ -107,94 +107,34 @@ void route_table_destroy(struct route_table *table); * @param entry Указатель на вставляемую запись маршрута * @return true если вставка успешна, false иначе */ -bool route_table_insert(struct route_table *table, const struct route_entry *entry); +bool route_table_insert(struct ROUTE_TABLE *table, const struct ROUTE_ENTRY *entry); /** * @brief Удаляет запись из таблицы маршрутизации * * @param table Указатель на таблицу маршрутизации - * @param network Сетевой адрес - * @param prefix_length Длина префикса - * @param source_node_id Идентификатор источника узла - * @return true если удаление успешно, false иначе + * @param conn соединение все роуты которого надо удалить */ -bool route_table_delete(struct route_table *table, uint32_t network, uint8_t prefix_length, uint32_t source_node_id); +void route_table_delete(struct ROUTE_TABLE *table, struct ETCP_SOCKET* conn); /** - * @brief Выполняет поиск лучшего маршрута для заданного IP-адреса + * @brief Выполняет поиск доступных маршрутов для заданного IP-адреса, отсортированных по quality + * при поиске ищет готовый результат в кеше или добавляет в кеш новый результат и возвращает запись из кеша * * @param table Указатель на таблицу маршрутизации * @param dest_ip Целевой IP-адрес - * @param best_route Указатель на структуру для хранения лучшего маршрута - * @return true если маршрут найден, false иначе - */ -bool route_table_lookup(struct route_table *table, uint32_t dest_ip, struct route_entry *best_route); - -/** - * @brief Валидирует маршрут на основе типа и подсетей - * - * @param table Указатель на таблицу маршрутизации - * @param network Сетевой адрес - * @param prefix_length Длина префикса - * @param route_type Тип маршрута - * @return true если маршрут валиден, false иначе - */ -bool route_validate_route(struct route_table *table, uint32_t network, uint8_t prefix_length, route_type_t route_type); - -/** - * @brief Добавляет динамическую подсеть в таблицу - * - * @param table Указатель на таблицу маршрутизации - * @param network Сетевой адрес - * @param prefix_length Длина префикса - * @return true если добавление успешно, false иначе - */ -bool route_add_dynamic_subnet(struct route_table *table, uint32_t network, uint8_t prefix_length); - -/** - * @brief Добавляет локальную подсеть в таблицу - * - * @param table Указатель на таблицу маршрутизации - * @param network Сетевой адрес - * @param prefix_length Длина префикса - * @return true если добавление успешно, false иначе + * @return структура с найденными маршрутами */ -bool route_add_local_subnet(struct route_table *table, uint32_t network, uint8_t prefix_length); +struct ROUTE_ARRAY* route_table_lookup(struct ROUTE_TABLE *table, uint32_t dest_ip); -/** - * @brief Получает все маршруты для заданной сети и префикса - * - * @param table Указатель на таблицу маршрутизации - * @param network Сетевой адрес - * @param prefix_length Длина префикса - * @param routes Указатель на массив маршрутов (будет выделен) - * @param count Указатель на количество найденных маршрутов - * @return true если операция успешна, false иначе - */ -bool route_get_all_routes(const struct route_table *table, uint32_t network, uint8_t prefix_length, struct route_entry **routes, size_t *count); +// пересчитывает quality на основе других метрик (rtt, %loss, hopcount). чем меньше quality - тем лучше +bool route_update_quality(struct ROUTE_ENTRY *entry); /** * @brief Печатает содержимое таблицы маршрутизации * * @param table Указатель на таблицу маршрутизации */ -void route_table_print(const struct route_table *table); - -/** - * @brief Преобразует тип маршрута в строковое представление - * - * @param type Тип маршрута - * @return Строковое представление типа - */ -const char* route_type_to_string(route_type_t type); - -/** - * @brief Преобразует IP-адрес в строковое представление - * - * @param ip IP-адрес в сетевом формате - * @param buffer Буфер для хранения строки (минимум 16 байт) - * @return Указатель на буфер с строкой - */ -char* ip_to_string(uint32_t ip, char *buffer); +void route_table_print(const struct ROUTE_TABLE *table); #endif // ROUTE_LIB_H diff --git a/src/routing.txt b/src/routing.txt new file mode 100644 index 0000000..32ca152 --- /dev/null +++ b/src/routing.txt @@ -0,0 +1,16 @@ +подсистема роутинга +utun - это сеть узлов. у каждого узла есть собственные локальные подсети. +и узлы обмениваются таблицой маршрутов между собой так чтобы у каждого была актуальная таблица подсетей всех узлов. +маршрутами меняются только те подключения которые взяты из конфига. +инициируется подключение, клиент отправляет свою таблицу. когда сервер принимает таблицу - сервер помечает что по этому маршруту надо обмениваться маршрутами, далее; +- добавляет узел в список рассылки обновлений маршрутов +- отправляет свою таблицу +- добавляет в свою таблицу отсутствующие маршруты +- если что-то добавил: + - рассылает измененные маршруты по списку рассылки +- список рассылки - это linked-list очередей (также на базе ll_queue - каждый элемент = подписчик). один маршрут = одна отправленная кодограмма + + + +при подключении узла или изменении таблицы: узлы обмениваются изменениями таблиц маршрутов. +то есть каждая запись в таблице имеет флаги - кому отправлена. \ No newline at end of file diff --git a/src/secure_channel.c1 b/src/secure_channel.c1 old mode 100755 new mode 100644 diff --git a/src/utun_instance.c b/src/utun_instance.c index 34292da..5078900 100644 --- a/src/utun_instance.c +++ b/src/utun_instance.c @@ -92,7 +92,7 @@ struct UTUN_INSTANCE* utun_instance_create(struct UASYNC* ua, const char *config // Add local subnets from config as static routes struct CFG_ROUTE_ENTRY* subnet = instance->config->my_subnets; while (subnet) { - struct route_entry entry = {0}; + struct ROUTE_ENTRY entry = {0}; entry.network = subnet->ip.addr.v4.s_addr; // Network byte order entry.prefix_length = subnet->netmask; entry.next_hop = NULL; // Local route diff --git a/src/utun_instance.h b/src/utun_instance.h index c05a51b..ab84839 100644 --- a/src/utun_instance.h +++ b/src/utun_instance.h @@ -10,7 +10,7 @@ // Forward declarations struct utun_config; struct uasync_s; -struct route_table; +struct ROUTE_TABLE; struct ETCP_CONN; struct ETCP_SOCKET; struct tun_if; @@ -23,7 +23,7 @@ struct UTUN_INSTANCE { // TUN interface struct tun_if* tun; - struct route_table* rt; + struct ROUTE_TABLE* rt; // Identification uint64_t node_id; diff --git a/tests/Makefile.am b/tests/Makefile.am index 01c307d..61a82c7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,75 +1,67 @@ # Tests Makefile.am for utun - all tests with new ll_queue library -# All available tests with new ll_queue library -check_PROGRAMS = test_etcp_crypto$(EXEEXT) \ - test_crypto$(EXEEXT) \ - test_etcp_two_instances$(EXEEXT) \ - test_etcp_simple_traffic$(EXEEXT) \ - test_etcp_minimal$(EXEEXT) \ - test_etcp_100_packets$(EXEEXT) \ - test_pkt_normalizer_etcp$(EXEEXT) \ - test_pkt_normalizer_standalone$(EXEEXT) \ - test_ll_queue$(EXEEXT) \ - test_ecc_encrypt$(EXEEXT) \ - test_intensive_memory_pool$(EXEEXT) \ - test_memory_pool_and_config$(EXEEXT) \ - test_packet_dump$(EXEEXT) \ - test_u_async_comprehensive$(EXEEXT) \ - test_u_async_performance$(EXEEXT) \ - test_debug_categories$(EXEEXT) \ - test_config_debug$(EXEEXT) \ - bench_timeout_heap$(EXEEXT) \ - bench_uasync_timeouts$(EXEEXT) +# Object directories +OBJDIR = $(top_builddir)/.objs/tests +SRC_OBJDIR = $(top_builddir)/.objs/src +TINYCRYPT_OBJDIR = $(top_builddir)/.objs/tinycrypt + +# All available tests +check_PROGRAMS = \ + test_etcp_crypto \ + test_crypto \ + test_etcp_two_instances \ + test_etcp_simple_traffic \ + test_etcp_minimal \ + test_etcp_100_packets \ + test_pkt_normalizer_etcp \ + test_pkt_normalizer_standalone \ + test_ll_queue \ + test_ecc_encrypt \ + test_intensive_memory_pool \ + test_memory_pool_and_config \ + test_packet_dump \ + test_u_async_comprehensive \ + test_u_async_performance \ + test_debug_categories \ + test_config_debug \ + bench_timeout_heap \ + bench_uasync_timeouts # Basic includes AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source -# TinyCrypt source files -TINYCRYPT_SRCS = \ - $(top_srcdir)/tinycrypt/lib/source/aes_encrypt.c \ - $(top_srcdir)/tinycrypt/lib/source/aes_decrypt.c \ - $(top_srcdir)/tinycrypt/lib/source/ccm_mode.c \ - $(top_srcdir)/tinycrypt/lib/source/cmac_mode.c \ - $(top_srcdir)/tinycrypt/lib/source/ctr_mode.c \ - $(top_srcdir)/tinycrypt/lib/source/ecc.c \ - $(top_srcdir)/tinycrypt/lib/source/ecc_dh.c \ - $(top_srcdir)/tinycrypt/lib/source/ecc_dsa.c \ - $(top_srcdir)/tinycrypt/lib/source/sha256.c \ - $(top_srcdir)/tinycrypt/lib/source/ecc_platform_specific.c \ - $(top_srcdir)/tinycrypt/lib/source/utils.c - -# TinyCrypt object files (used when not using OpenSSL) +# TinyCrypt object files (in .objs directory) TINYCRYPT_OBJS = \ - $(top_builddir)/tinycrypt/lib/source/utun-aes_encrypt.o \ - $(top_builddir)/tinycrypt/lib/source/utun-aes_decrypt.o \ - $(top_builddir)/tinycrypt/lib/source/utun-ccm_mode.o \ - $(top_builddir)/tinycrypt/lib/source/utun-cmac_mode.o \ - $(top_builddir)/tinycrypt/lib/source/utun-ctr_mode.o \ - $(top_builddir)/tinycrypt/lib/source/utun-ecc.o \ - $(top_builddir)/tinycrypt/lib/source/utun-ecc_dh.o \ - $(top_builddir)/tinycrypt/lib/source/utun-ecc_dsa.o \ - $(top_builddir)/tinycrypt/lib/source/utun-sha256.o \ - $(top_builddir)/tinycrypt/lib/source/utun-ecc_platform_specific.o \ - $(top_builddir)/tinycrypt/lib/source/utun-utils.o - -# Secure channel and CRC objects (always needed) -SECURE_CHANNEL_OBJS = $(top_builddir)/src/utun-secure_channel.o $(top_builddir)/src/utun-crc32.o - -# ETCP core objects (always needed) + $(TINYCRYPT_OBJDIR)/aes_encrypt.o \ + $(TINYCRYPT_OBJDIR)/aes_decrypt.o \ + $(TINYCRYPT_OBJDIR)/ccm_mode.o \ + $(TINYCRYPT_OBJDIR)/cmac_mode.o \ + $(TINYCRYPT_OBJDIR)/ctr_mode.o \ + $(TINYCRYPT_OBJDIR)/ecc.o \ + $(TINYCRYPT_OBJDIR)/ecc_dh.o \ + $(TINYCRYPT_OBJDIR)/ecc_dsa.o \ + $(TINYCRYPT_OBJDIR)/sha256.o \ + $(TINYCRYPT_OBJDIR)/ecc_platform_specific.o \ + $(TINYCRYPT_OBJDIR)/utils.o + +# Secure channel and CRC objects +SECURE_CHANNEL_OBJS = $(SRC_OBJDIR)/secure_channel.o $(SRC_OBJDIR)/crc32.o + +# ETCP core objects ETCP_CORE_OBJS = \ - $(top_builddir)/src/utun-etcp.o \ - $(top_builddir)/src/utun-etcp_connections.o \ - $(top_builddir)/src/utun-etcp_loadbalancer.o \ - $(top_builddir)/src/utun-pkt_normalizer.o + $(SRC_OBJDIR)/etcp.o \ + $(SRC_OBJDIR)/etcp_connections.o \ + $(SRC_OBJDIR)/etcp_loadbalancer.o \ + $(SRC_OBJDIR)/pkt_normalizer.o -# Full ETCP objects (with config, routing, etc.) +# Full ETCP objects ETCP_FULL_OBJS = \ - $(top_builddir)/src/utun-config_parser.o \ - $(top_builddir)/src/utun-config_updater.o \ - $(top_builddir)/src/utun-route_lib.o \ - $(top_builddir)/src/utun-routing.o \ - $(top_builddir)/src/utun-tun_if.o \ - $(top_builddir)/src/utun-utun_instance.o \ + $(SRC_OBJDIR)/config_parser.o \ + $(SRC_OBJDIR)/config_updater.o \ + $(SRC_OBJDIR)/route_lib.o \ + $(SRC_OBJDIR)/routing.o \ + $(SRC_OBJDIR)/tun_if.o \ + $(SRC_OBJDIR)/utun_instance.o \ $(ETCP_CORE_OBJS) # Common libraries @@ -82,134 +74,102 @@ else CRYPTO_LIBS = $(TINYCRYPT_OBJS) endif -# ETCP crypto test +# Register tests +TESTS = $(check_PROGRAMS) + +# Test definitions with standard automake variables test_etcp_crypto_SOURCES = test_etcp_crypto.c test_etcp_crypto_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source test_etcp_crypto_LDADD = $(SECURE_CHANNEL_OBJS) $(CRYPTO_LIBS) $(COMMON_LIBS) -# ETCP two instances test +test_crypto_SOURCES = test_crypto.c +test_crypto_CFLAGS = -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source -I$(top_srcdir)/lib +test_crypto_LDADD = $(TINYCRYPT_OBJS) $(COMMON_LIBS) + test_etcp_two_instances_SOURCES = test_etcp_two_instances.c test_etcp_two_instances_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source test_etcp_two_instances_LDADD = $(ETCP_FULL_OBJS) $(SECURE_CHANNEL_OBJS) $(CRYPTO_LIBS) $(COMMON_LIBS) -# ETCP simple traffic test test_etcp_simple_traffic_SOURCES = test_etcp_simple_traffic.c test_etcp_simple_traffic_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source test_etcp_simple_traffic_LDADD = $(ETCP_FULL_OBJS) $(SECURE_CHANNEL_OBJS) $(CRYPTO_LIBS) $(COMMON_LIBS) -# ETCP minimal test test_etcp_minimal_SOURCES = test_etcp_minimal.c test_etcp_minimal_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source test_etcp_minimal_LDADD = $(ETCP_FULL_OBJS) $(SECURE_CHANNEL_OBJS) $(CRYPTO_LIBS) $(COMMON_LIBS) -# ETCP 100 packets test test_etcp_100_packets_SOURCES = test_etcp_100_packets.c test_etcp_100_packets_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source test_etcp_100_packets_LDADD = $(ETCP_FULL_OBJS) $(SECURE_CHANNEL_OBJS) $(CRYPTO_LIBS) $(COMMON_LIBS) -# Packet normalizer ETCP test test_pkt_normalizer_etcp_SOURCES = test_pkt_normalizer_etcp.c test_pkt_normalizer_etcp_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source test_pkt_normalizer_etcp_LDADD = $(ETCP_FULL_OBJS) $(SECURE_CHANNEL_OBJS) $(CRYPTO_LIBS) $(COMMON_LIBS) -# Standalone pkt_normalizer test with mock ETCP loopback test_pkt_normalizer_standalone_SOURCES = test_pkt_normalizer_standalone.c test_pkt_normalizer_standalone_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source -test_pkt_normalizer_standalone_LDADD = $(top_builddir)/src/utun-pkt_normalizer.o $(top_builddir)/src/utun-route_lib.o $(top_builddir)/src/utun-routing.o $(TINYCRYPT_OBJS) $(COMMON_LIBS) - -# Basic crypto test (TinyCrypt only - no secure_channel) -test_crypto_SOURCES = test_crypto.c -test_crypto_CFLAGS = -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source -I$(top_srcdir)/lib -test_crypto_LDADD = $(TINYCRYPT_OBJS) $(COMMON_LIBS) +test_pkt_normalizer_standalone_LDADD = $(SRC_OBJDIR)/pkt_normalizer.o $(SRC_OBJDIR)/route_lib.o $(SRC_OBJDIR)/routing.o $(TINYCRYPT_OBJS) $(COMMON_LIBS) -# Working ll_queue test for xxx=0 architecture test_ll_queue_SOURCES = test_ll_queue.c test_ll_queue_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib test_ll_queue_LDADD = $(COMMON_LIBS) -# ECC encryption test (uses TinyCrypt directly, needs tinycrypt objects) test_ecc_encrypt_SOURCES = test_ecc_encrypt.c test_ecc_encrypt_CFLAGS = -I$(top_srcdir)/tinycrypt/lib/include -I$(top_srcdir)/tinycrypt/lib/source -I$(top_srcdir)/lib test_ecc_encrypt_LDADD = $(SECURE_CHANNEL_OBJS) $(TINYCRYPT_OBJS) $(COMMON_LIBS) -lcrypto -# Intensive memory pool test test_intensive_memory_pool_SOURCES = test_intensive_memory_pool.c test_intensive_memory_pool_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib test_intensive_memory_pool_LDADD = $(COMMON_LIBS) -# Memory pool and config test test_memory_pool_and_config_SOURCES = test_memory_pool_and_config.c test_memory_pool_and_config_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib test_memory_pool_and_config_LDADD = $(COMMON_LIBS) -# Packet dump test test_packet_dump_SOURCES = test_packet_dump.c test_packet_dump_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib test_packet_dump_LDADD = $(COMMON_LIBS) -# UASYNC comprehensive test test_u_async_comprehensive_SOURCES = test_u_async_comprehensive.c test_u_async_comprehensive_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib test_u_async_comprehensive_LDADD = $(COMMON_LIBS) -# UASYNC performance test test_u_async_performance_SOURCES = test_u_async_performance.c test_u_async_performance_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib test_u_async_performance_LDADD = $(COMMON_LIBS) -# Debug categories test test_debug_categories_SOURCES = test_debug_categories.c test_debug_categories_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib test_debug_categories_LDADD = $(COMMON_LIBS) -# Config debug test test_config_debug_SOURCES = test_config_debug.c test_config_debug_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/lib -test_config_debug_LDADD = $(top_builddir)/src/utun-config_parser.o $(COMMON_LIBS) +test_config_debug_LDADD = $(SRC_OBJDIR)/config_parser.o $(COMMON_LIBS) -# Timeout heap benchmark bench_timeout_heap_SOURCES = bench_timeout_heap.c bench_timeout_heap_CFLAGS = -I$(top_srcdir)/lib bench_timeout_heap_LDADD = $(COMMON_LIBS) -# uasync zero timeout benchmark bench_uasync_timeouts_SOURCES = bench_uasync_timeouts.c bench_uasync_timeouts_CFLAGS = -I$(top_srcdir)/lib bench_uasync_timeouts_LDADD = $(COMMON_LIBS) -# Register tests -TESTS = $(check_PROGRAMS) - -# Build rules for TinyCrypt objects (needed for test_crypto even with OpenSSL) -$(top_builddir)/tinycrypt/lib/source/utun-aes_encrypt.o: $(top_srcdir)/tinycrypt/lib/source/aes_encrypt.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o $@ $< - -$(top_builddir)/tinycrypt/lib/source/utun-aes_decrypt.o: $(top_srcdir)/tinycrypt/lib/source/aes_decrypt.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o $@ $< - -$(top_builddir)/tinycrypt/lib/source/utun-ccm_mode.o: $(top_srcdir)/tinycrypt/lib/source/ccm_mode.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o $@ $< - -$(top_builddir)/tinycrypt/lib/source/utun-cmac_mode.o: $(top_srcdir)/tinycrypt/lib/source/cmac_mode.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o $@ $< - -$(top_builddir)/tinycrypt/lib/source/utun-ctr_mode.o: $(top_srcdir)/tinycrypt/lib/source/ctr_mode.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o $@ $< - -$(top_builddir)/tinycrypt/lib/source/utun-ecc.o: $(top_srcdir)/tinycrypt/lib/source/ecc.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o $@ $< - -$(top_builddir)/tinycrypt/lib/source/utun-ecc_dh.o: $(top_srcdir)/tinycrypt/lib/source/ecc_dh.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o $@ $< - -$(top_builddir)/tinycrypt/lib/source/utun-ecc_dsa.o: $(top_srcdir)/tinycrypt/lib/source/ecc_dsa.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o $@ $< - -$(top_builddir)/tinycrypt/lib/source/utun-sha256.o: $(top_srcdir)/tinycrypt/lib/source/sha256.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o $@ $< - -$(top_builddir)/tinycrypt/lib/source/utun-ecc_platform_specific.o: $(top_srcdir)/tinycrypt/lib/source/ecc_platform_specific.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o $@ $< - -$(top_builddir)/tinycrypt/lib/source/utun-utils.o: $(top_srcdir)/tinycrypt/lib/source/utils.c - $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o $@ $< +# After building tests, move their object files to shadow directory +all-local: shadow-test-objects + +shadow-test-objects: $(check_PROGRAMS) + @$(MKDIR_P) $(OBJDIR) + @for prog in $(check_PROGRAMS); do \ + prog_obj=$${prog}_OBJECTS; \ + eval "objs=\"\$$prog_obj\""; \ + for obj in $$objs; do \ + if test -f "$$obj"; then \ + mv -f "$$obj" $(OBJDIR)/ 2>/dev/null || true; \ + fi; \ + done; \ + done + +# Clean +clean-local: + -rm -f $(check_PROGRAMS) + -rm -rf $(OBJDIR) diff --git a/tests/bench_timeout_heap b/tests/bench_timeout_heap deleted file mode 100755 index a0b97ef..0000000 Binary files a/tests/bench_timeout_heap and /dev/null differ diff --git a/tests/bench_uasync_timeouts b/tests/bench_uasync_timeouts deleted file mode 100755 index 4bfba10..0000000 Binary files a/tests/bench_uasync_timeouts and /dev/null differ diff --git a/tests/test_config_debug b/tests/test_config_debug deleted file mode 100755 index e2a6b18..0000000 Binary files a/tests/test_config_debug and /dev/null differ diff --git a/tests/test_crypto b/tests/test_crypto deleted file mode 100755 index 043da27..0000000 Binary files a/tests/test_crypto and /dev/null differ diff --git a/tests/test_debug_categories b/tests/test_debug_categories deleted file mode 100755 index d8f80ec..0000000 Binary files a/tests/test_debug_categories and /dev/null differ diff --git a/tests/test_ecc_encrypt b/tests/test_ecc_encrypt deleted file mode 100755 index 7b28462..0000000 Binary files a/tests/test_ecc_encrypt and /dev/null differ diff --git a/tests/test_etcp_100_packets b/tests/test_etcp_100_packets deleted file mode 100755 index 2b32974..0000000 Binary files a/tests/test_etcp_100_packets and /dev/null differ diff --git a/tests/test_etcp_crypto b/tests/test_etcp_crypto deleted file mode 100755 index b155760..0000000 Binary files a/tests/test_etcp_crypto and /dev/null differ diff --git a/tests/test_etcp_minimal b/tests/test_etcp_minimal deleted file mode 100755 index 1624fe5..0000000 Binary files a/tests/test_etcp_minimal and /dev/null differ diff --git a/tests/test_etcp_simple_traffic b/tests/test_etcp_simple_traffic deleted file mode 100755 index 6b12cd7..0000000 Binary files a/tests/test_etcp_simple_traffic and /dev/null differ diff --git a/tests/test_etcp_two_instances b/tests/test_etcp_two_instances deleted file mode 100755 index cc2c697..0000000 Binary files a/tests/test_etcp_two_instances and /dev/null differ diff --git a/tests/test_intensive_memory_pool b/tests/test_intensive_memory_pool deleted file mode 100755 index 7bb8e16..0000000 Binary files a/tests/test_intensive_memory_pool and /dev/null differ diff --git a/tests/test_ll_queue b/tests/test_ll_queue deleted file mode 100755 index 368fa1a..0000000 Binary files a/tests/test_ll_queue and /dev/null differ diff --git a/tests/test_memory_pool_and_config b/tests/test_memory_pool_and_config deleted file mode 100755 index 6e40e75..0000000 Binary files a/tests/test_memory_pool_and_config and /dev/null differ diff --git a/tests/test_packet_dump b/tests/test_packet_dump deleted file mode 100755 index 05a1820..0000000 Binary files a/tests/test_packet_dump and /dev/null differ diff --git a/tests/test_pkt_normalizer_etcp b/tests/test_pkt_normalizer_etcp deleted file mode 100755 index 4846475..0000000 Binary files a/tests/test_pkt_normalizer_etcp and /dev/null differ diff --git a/tests/test_pkt_normalizer_standalone b/tests/test_pkt_normalizer_standalone deleted file mode 100755 index 221b8ce..0000000 Binary files a/tests/test_pkt_normalizer_standalone and /dev/null differ diff --git a/tests/test_u_async_comprehensive b/tests/test_u_async_comprehensive deleted file mode 100755 index f84e1cf..0000000 Binary files a/tests/test_u_async_comprehensive and /dev/null differ diff --git a/tests/test_u_async_performance b/tests/test_u_async_performance deleted file mode 100755 index 4a8b2aa..0000000 Binary files a/tests/test_u_async_performance and /dev/null differ