feat: implement parallel agent execution and unified agent registry

- Fix streaming JSON parsing issues (buffer processing on stream end)
- Increase max_tokens for tool-enabled requests (16384)
- Add parallel tool execution for task_agent, read, glob, grep (up to 3 concurrent)
- Register task_agent tool with queue system and concurrency control
- Add session-based isolation with parentSessionId tracking
- Create unified agent registry mapping agents from:
  - OpenCode (7 agents: build, plan, explore, general, etc.)
  - Claude Code (12 agents: code-explorer, code-architect, etc.)
  - Cursor (3 agents: pair-programmer, cli, chat)
  - CodeTyper native (6 agents)
- Add agent/skill creation system with LLM-based generation
- Store custom agents in .codetyper/agents/*.md
- Store custom skills in .codetyper/skills/*/SKILL.md
This commit is contained in:
2026-02-05 18:35:23 -05:00
parent ad514a920c
commit e2cb41f8d3
11 changed files with 1826 additions and 59 deletions

View File

@@ -0,0 +1,286 @@
/**
* Agent and Skill Templates
*
* Templates for creating new agents and skills in .codetyper/ directories.
* Based on patterns from claude-code and opencode.
*/
/**
* Valid agent colors with semantic meaning
*/
export const AGENT_COLORS = {
blue: "Analysis, review, code inspection",
cyan: "Analysis, review, code inspection",
green: "Success, generation, creation",
yellow: "Validation, caution, verification",
red: "Security, critical issues",
magenta: "Transformation, creative tasks",
white: "Neutral, general purpose",
gray: "Internal, utility",
} as const;
/**
* Valid model options
*/
export const AGENT_MODELS = {
inherit: "Uses parent model (recommended)",
sonnet: "Claude Sonnet (balanced, default)",
opus: "Claude Opus (most capable)",
haiku: "Claude Haiku (fast, cheap)",
"gpt-4o": "GPT-4o (OpenAI balanced)",
"gpt-4o-mini": "GPT-4o Mini (OpenAI fast)",
} as const;
/**
* Agent frontmatter template
*/
export const AGENT_FRONTMATTER_TEMPLATE = `---
name: {{name}}
description: {{description}}
model: {{model}}
color: {{color}}
tools: [{{tools}}]
---
`;
/**
* Agent markdown template
*/
export const AGENT_MARKDOWN_TEMPLATE = `---
name: {{name}}
description: Use this agent when {{trigger_description}}. Examples: {{examples}}
model: {{model}}
color: {{color}}
{{#if tools}}
tools: [{{tools}}]
{{/if}}
---
# {{display_name}}
{{system_prompt}}
## Core Process
{{process_steps}}
## Output Format
{{output_format}}
## Rules
{{rules}}
`;
/**
* Skill frontmatter template
*/
export const SKILL_FRONTMATTER_TEMPLATE = `---
name: {{name}}
description: {{description}}
version: 0.1.0
---
`;
/**
* Skill markdown template
*/
export const SKILL_MARKDOWN_TEMPLATE = `---
name: {{name}}
description: This skill should be used when {{trigger_description}}.
version: 0.1.0
---
# {{display_name}}
## Overview
{{overview}}
## When to Use
{{when_to_use}}
## How to Use
{{how_to_use}}
## Examples
{{examples}}
## Best Practices
{{best_practices}}
`;
/**
* Default tools by agent type
*/
export const DEFAULT_TOOLS_BY_TYPE = {
explore: ["glob", "grep", "read"],
review: ["glob", "grep", "read"],
implement: ["glob", "grep", "read", "write", "edit", "bash"],
test: ["glob", "grep", "read", "write", "edit", "bash"],
refactor: ["glob", "grep", "read", "write", "edit"],
plan: ["glob", "grep", "read"],
security: ["glob", "grep", "read"],
documentation: ["glob", "grep", "read", "write"],
general: ["glob", "grep", "read", "write", "edit", "bash", "web_search", "web_fetch"],
} as const;
/**
* Agent creation prompt for LLM
*/
export const AGENT_CREATION_PROMPT = `You are an agent configuration generator. Create a high-quality agent definition based on the user's description.
## Output Format
Generate a complete agent markdown file with:
1. **Frontmatter** (YAML between ---):
- name: lowercase, hyphens only, 3-50 chars (e.g., "code-reviewer", "api-docs-writer")
- description: Must start with "Use this agent when..." and include 2-4 <example> blocks
- model: inherit (recommended) | sonnet | opus | haiku | gpt-4o | gpt-4o-mini
- color: blue | cyan | green | yellow | magenta | red (match semantic meaning)
- tools: array of tool names (optional, omit for full access)
2. **System Prompt** (markdown body):
- Clear role definition
- Core process steps
- Output format specification
- Rules and constraints
## Example
\`\`\`markdown
---
name: code-reviewer
description: Use this agent when the user asks to "review code", "check for bugs", "find issues", or wants code quality feedback. <example>Context: User wants code reviewed\nuser: "Review this function for bugs"\nassistant: "I'll use the code-reviewer agent to analyze the code."\n</example>
model: inherit
color: red
tools: ["glob", "grep", "read"]
---
# Code Reviewer
You are a senior code reviewer who identifies bugs, logic errors, and quality issues.
## Core Process
1. Read the code thoroughly
2. Check for common bug patterns
3. Analyze logic flow
4. Review error handling
5. Check for security issues
## Output Format
- **Issues Found:** List with severity, location, description
- **Suggestions:** Improvement recommendations
- **Summary:** Overall assessment
## Rules
- Never modify files
- Focus on actionable feedback
- Prioritize by severity
\`\`\`
## User's Description
{{description}}
Generate the complete agent markdown file:`;
/**
* Skill creation prompt for LLM
*/
export const SKILL_CREATION_PROMPT = `You are a skill documentation generator. Create educational skill documentation based on the user's description.
## Output Format
Generate a complete skill SKILL.md file with:
1. **Frontmatter** (YAML between ---):
- name: Display name with spaces
- description: Trigger phrases when this skill should be used
- version: 0.1.0
2. **Content** (markdown body):
- Overview section
- When to Use section
- How to Use section with examples
- Best Practices section
## Example
\`\`\`markdown
---
name: Git Workflow
description: This skill should be used when the user asks about "git commands", "branching strategy", "commit messages", "pull requests", or needs guidance on git workflows and best practices.
version: 0.1.0
---
# Git Workflow
## Overview
This skill covers git best practices for development workflows.
## When to Use
- Setting up a new git repository
- Creating feature branches
- Writing commit messages
- Managing pull requests
## How to Use
### Creating a Feature Branch
\`\`\`bash
git checkout -b feature/my-feature
\`\`\`
### Commit Message Format
\`\`\`
type(scope): description
[optional body]
[optional footer]
\`\`\`
## Best Practices
1. Use descriptive branch names
2. Keep commits atomic
3. Write clear commit messages
4. Review before merging
\`\`\`
## User's Description
{{description}}
Generate the complete skill SKILL.md file:`;
/**
* Directories for agents and skills
*/
export const CODETYPER_DIRS = {
agents: ".codetyper/agents",
skills: ".codetyper/skills",
plugins: ".codetyper/plugins",
} as const;
/**
* File patterns for discovery
*/
export const DISCOVERY_PATTERNS = {
agents: "**/*.md",
skills: "**/SKILL.md",
} as const;

View File

@@ -0,0 +1,665 @@
/**
* Unified Agent Registry
*
* Maps agents/skills from different AI coding tools:
* - Claude Code
* - OpenCode
* - Cursor
* - CodeTyper native
*
* This registry enables CodeTyper to use agent patterns from all tools.
*/
import type { AgentDefinition } from "@/types/agent-definition";
/**
* Agent tier determines model selection and capabilities
*/
export type AgentTier = "fast" | "balanced" | "thorough" | "reasoning";
/**
* Agent mode determines when/how the agent can be invoked
*/
export type AgentMode = "primary" | "subagent" | "all";
/**
* Source tool that defined this agent pattern
*/
export type AgentSource =
| "claude-code"
| "opencode"
| "cursor"
| "codetyper"
| "github-copilot";
/**
* Unified agent definition that can represent agents from any tool
*/
export interface UnifiedAgentDefinition {
/** Unique agent identifier */
id: string;
/** Display name */
name: string;
/** Description of agent capabilities */
description: string;
/** Source tool this agent pattern comes from */
source: AgentSource;
/** Agent tier for model selection */
tier: AgentTier;
/** Agent mode (primary, subagent, or both) */
mode: AgentMode;
/** Tools this agent has access to */
tools: string[];
/** Tools explicitly denied */
deniedTools?: string[];
/** Maximum iterations/turns */
maxTurns: number;
/** Custom system prompt */
systemPrompt?: string;
/** Temperature for model (0.0-1.0) */
temperature?: number;
/** Whether agent is visible in UI */
hidden?: boolean;
/** Color for UI display */
color?: string;
/** Tags for categorization */
tags: string[];
}
// =============================================================================
// OpenCode Agents
// =============================================================================
export const OPENCODE_AGENTS: UnifiedAgentDefinition[] = [
{
id: "opencode-build",
name: "Build",
description:
"The default agent. Executes tools based on configured permissions. Full code generation and modification capabilities.",
source: "opencode",
tier: "balanced",
mode: "primary",
tools: [
"bash",
"read",
"glob",
"grep",
"edit",
"write",
"web_fetch",
"web_search",
"task_agent",
"todo_read",
"todo_write",
"apply_patch",
],
maxTurns: 50,
tags: ["code-generation", "editing", "general-purpose"],
},
{
id: "opencode-plan",
name: "Plan",
description:
"Plan mode. Disallows all edit tools. Use for planning and research without file modifications.",
source: "opencode",
tier: "balanced",
mode: "primary",
tools: ["bash", "read", "glob", "grep", "web_fetch", "web_search"],
deniedTools: ["edit", "write", "apply_patch"],
maxTurns: 30,
tags: ["planning", "research", "read-only"],
},
{
id: "opencode-explore",
name: "Explore",
description:
"Fast agent specialized for exploring codebases. Use for finding files by patterns, searching code for keywords, or answering questions about the codebase. Supports thoroughness levels: quick, medium, very thorough.",
source: "opencode",
tier: "fast",
mode: "subagent",
tools: ["grep", "glob", "read", "bash", "web_fetch", "web_search"],
deniedTools: ["edit", "write", "apply_patch", "task_agent"],
maxTurns: 15,
tags: ["exploration", "search", "codebase-analysis"],
},
{
id: "opencode-general",
name: "General",
description:
"General-purpose agent for researching complex questions and executing multi-step tasks. Use to execute multiple units of work in parallel.",
source: "opencode",
tier: "balanced",
mode: "subagent",
tools: [
"bash",
"read",
"glob",
"grep",
"edit",
"write",
"web_fetch",
"web_search",
"task_agent",
"apply_patch",
],
deniedTools: ["todo_read", "todo_write"],
maxTurns: 25,
tags: ["general-purpose", "parallel", "research"],
},
{
id: "opencode-title",
name: "Title Generator",
description: "Session title generator. Internal use only.",
source: "opencode",
tier: "fast",
mode: "primary",
tools: [],
maxTurns: 1,
temperature: 0.5,
hidden: true,
tags: ["internal", "utility"],
},
{
id: "opencode-summary",
name: "Summary",
description: "Conversation summarizer. Internal use only.",
source: "opencode",
tier: "fast",
mode: "primary",
tools: [],
maxTurns: 1,
hidden: true,
tags: ["internal", "utility"],
},
{
id: "opencode-compaction",
name: "Compaction",
description: "Internal message compaction agent.",
source: "opencode",
tier: "fast",
mode: "primary",
tools: [],
maxTurns: 1,
hidden: true,
tags: ["internal", "utility"],
},
];
// =============================================================================
// Claude Code Agents
// =============================================================================
export const CLAUDE_CODE_AGENTS: UnifiedAgentDefinition[] = [
// Feature-Dev Plugin Agents
{
id: "claude-code-explorer",
name: "Code Explorer",
description:
"Deeply analyzes existing codebase features by tracing execution paths, mapping architecture layers, understanding patterns and abstractions, and documenting dependencies.",
source: "claude-code",
tier: "balanced",
mode: "subagent",
tools: [
"glob",
"grep",
"read",
"web_fetch",
"web_search",
"todo_write",
],
deniedTools: ["edit", "write", "bash"],
maxTurns: 15,
color: "yellow",
tags: ["exploration", "analysis", "feature-dev"],
},
{
id: "claude-code-architect",
name: "Code Architect",
description:
"Designs feature architectures by analyzing existing codebase patterns and conventions, providing comprehensive implementation blueprints with specific files to create/modify.",
source: "claude-code",
tier: "balanced",
mode: "subagent",
tools: [
"glob",
"grep",
"read",
"web_fetch",
"web_search",
"todo_write",
],
deniedTools: ["edit", "write", "bash"],
maxTurns: 15,
color: "green",
tags: ["architecture", "design", "feature-dev"],
},
{
id: "claude-code-reviewer",
name: "Code Reviewer",
description:
"Reviews code for bugs, logic errors, security vulnerabilities, code quality issues, and adherence to project conventions using confidence-based filtering.",
source: "claude-code",
tier: "balanced",
mode: "subagent",
tools: ["glob", "grep", "read", "web_fetch", "web_search"],
deniedTools: ["edit", "write", "bash"],
maxTurns: 10,
color: "red",
tags: ["review", "quality", "security"],
},
// PR Review Toolkit Agents
{
id: "claude-pr-reviewer",
name: "PR Reviewer",
description:
"Reviews code for adherence to project guidelines, style guides, and best practices using confidence-based scoring.",
source: "claude-code",
tier: "thorough",
mode: "subagent",
tools: ["glob", "grep", "read"],
maxTurns: 10,
color: "green",
tags: ["pr-review", "quality"],
},
{
id: "claude-code-simplifier",
name: "Code Simplifier",
description:
"Simplifies code for clarity, consistency, and maintainability while preserving all functionality.",
source: "claude-code",
tier: "thorough",
mode: "subagent",
tools: ["glob", "grep", "read", "edit", "write"],
maxTurns: 15,
tags: ["refactoring", "simplification"],
},
{
id: "claude-comment-analyzer",
name: "Comment Analyzer",
description:
"Analyzes code comments for accuracy, completeness, and long-term maintainability.",
source: "claude-code",
tier: "balanced",
mode: "subagent",
tools: ["glob", "grep", "read"],
maxTurns: 10,
color: "green",
tags: ["documentation", "comments", "quality"],
},
{
id: "claude-test-analyzer",
name: "Test Analyzer",
description:
"Reviews code for test coverage quality and completeness, focusing on behavioral coverage.",
source: "claude-code",
tier: "balanced",
mode: "subagent",
tools: ["glob", "grep", "read"],
maxTurns: 10,
color: "cyan",
tags: ["testing", "coverage", "quality"],
},
{
id: "claude-silent-failure-hunter",
name: "Silent Failure Hunter",
description:
"Identifies silent failures, inadequate error handling, and inappropriate fallback behavior.",
source: "claude-code",
tier: "balanced",
mode: "subagent",
tools: ["glob", "grep", "read"],
maxTurns: 10,
color: "yellow",
tags: ["error-handling", "reliability", "quality"],
},
{
id: "claude-type-analyzer",
name: "Type Design Analyzer",
description:
"Analyzes type design for encapsulation quality, invariant expression, and practical usefulness.",
source: "claude-code",
tier: "balanced",
mode: "subagent",
tools: ["glob", "grep", "read"],
maxTurns: 10,
color: "pink",
tags: ["types", "design", "quality"],
},
// Plugin Dev Agents
{
id: "claude-agent-creator",
name: "Agent Creator",
description:
"Creates high-performance agent configurations from user requirements.",
source: "claude-code",
tier: "balanced",
mode: "subagent",
tools: ["write", "read"],
maxTurns: 10,
color: "magenta",
tags: ["meta", "agent-creation"],
},
{
id: "claude-plugin-validator",
name: "Plugin Validator",
description:
"Validates plugin structure, configuration, and components including manifests and hooks.",
source: "claude-code",
tier: "balanced",
mode: "subagent",
tools: ["read", "grep", "glob", "bash"],
maxTurns: 10,
color: "yellow",
tags: ["validation", "plugins"],
},
{
id: "claude-skill-reviewer",
name: "Skill Reviewer",
description:
"Reviews and improves skills for maximum effectiveness and reliability.",
source: "claude-code",
tier: "balanced",
mode: "subagent",
tools: ["read", "grep", "glob"],
maxTurns: 10,
color: "cyan",
tags: ["review", "skills"],
},
];
// =============================================================================
// Cursor Agents
// =============================================================================
export const CURSOR_AGENTS: UnifiedAgentDefinition[] = [
{
id: "cursor-pair-programmer",
name: "Pair Programmer",
description:
"Default Cursor agent with pair-level context awareness. Automatic context attachment for open files, cursor position, edit history, and linter errors.",
source: "cursor",
tier: "balanced",
mode: "primary",
tools: [
"glob",
"grep",
"read",
"edit",
"write",
"bash",
"web_search",
],
maxTurns: 50,
tags: ["general-purpose", "pair-programming"],
systemPrompt: `You are a pair programmer. Keep going until the query is completely resolved.
Use codebase_search (semantic) as the primary exploration tool.
Maximize parallel tool calls where possible.
Never output code unless requested - use edit tools instead.`,
},
{
id: "cursor-cli",
name: "CLI Agent",
description:
"Interactive CLI agent for software engineering tasks. Uses Grep as main exploration tool with status updates and flow-based execution.",
source: "cursor",
tier: "balanced",
mode: "primary",
tools: [
"glob",
"grep",
"read",
"edit",
"write",
"bash",
"web_search",
],
maxTurns: 50,
tags: ["cli", "terminal", "interactive"],
systemPrompt: `You are an interactive CLI tool for software engineering tasks.
Flow: Goal detection → Discovery → Tool batching → Summary
Primary Tool: Grep (fast exact matching)
Provide status updates and concise summaries.`,
},
{
id: "cursor-chat",
name: "Chat",
description:
"Conversational coding assistant focused on question answering. Only edits if certain user wants edits.",
source: "cursor",
tier: "balanced",
mode: "primary",
tools: ["glob", "grep", "read", "web_search"],
deniedTools: ["edit", "write"],
maxTurns: 20,
tags: ["chat", "q&a", "conversational"],
},
];
// =============================================================================
// CodeTyper Native Agents
// =============================================================================
export const CODETYPER_AGENTS: UnifiedAgentDefinition[] = [
{
id: "codetyper-explore",
name: "Explore",
description: "Fast codebase exploration agent (read-only).",
source: "codetyper",
tier: "fast",
mode: "subagent",
tools: ["glob", "grep", "read"],
deniedTools: ["edit", "write", "bash"],
maxTurns: 10,
tags: ["exploration", "search"],
},
{
id: "codetyper-implement",
name: "Implement",
description: "Code writing and modification agent.",
source: "codetyper",
tier: "balanced",
mode: "subagent",
tools: ["glob", "grep", "read", "write", "edit", "bash"],
maxTurns: 20,
tags: ["implementation", "coding"],
},
{
id: "codetyper-test",
name: "Test",
description: "Test creation and execution agent.",
source: "codetyper",
tier: "balanced",
mode: "subagent",
tools: ["glob", "grep", "read", "write", "edit", "bash"],
maxTurns: 15,
tags: ["testing", "quality"],
},
{
id: "codetyper-review",
name: "Review",
description: "Code review and suggestions agent.",
source: "codetyper",
tier: "balanced",
mode: "subagent",
tools: ["glob", "grep", "read"],
deniedTools: ["edit", "write", "bash"],
maxTurns: 10,
tags: ["review", "quality"],
},
{
id: "codetyper-refactor",
name: "Refactor",
description: "Code refactoring and improvement agent.",
source: "codetyper",
tier: "thorough",
mode: "subagent",
tools: ["glob", "grep", "read", "write", "edit"],
maxTurns: 25,
tags: ["refactoring", "improvement"],
},
{
id: "codetyper-plan",
name: "Plan",
description: "Planning and architecture design agent.",
source: "codetyper",
tier: "thorough",
mode: "subagent",
tools: ["glob", "grep", "read"],
deniedTools: ["edit", "write", "bash"],
maxTurns: 15,
tags: ["planning", "architecture"],
},
];
// =============================================================================
// Combined Registry
// =============================================================================
/**
* All agents from all sources
*/
export const UNIFIED_AGENT_REGISTRY: UnifiedAgentDefinition[] = [
...OPENCODE_AGENTS,
...CLAUDE_CODE_AGENTS,
...CURSOR_AGENTS,
...CODETYPER_AGENTS,
];
/**
* Get agent by ID
*/
export const getAgentById = (
id: string,
): UnifiedAgentDefinition | undefined => {
return UNIFIED_AGENT_REGISTRY.find((a) => a.id === id);
};
/**
* Get agents by source
*/
export const getAgentsBySource = (
source: AgentSource,
): UnifiedAgentDefinition[] => {
return UNIFIED_AGENT_REGISTRY.filter((a) => a.source === source);
};
/**
* Get agents by tier
*/
export const getAgentsByTier = (
tier: AgentTier,
): UnifiedAgentDefinition[] => {
return UNIFIED_AGENT_REGISTRY.filter((a) => a.tier === tier);
};
/**
* Get agents by mode
*/
export const getAgentsByMode = (
mode: AgentMode,
): UnifiedAgentDefinition[] => {
return UNIFIED_AGENT_REGISTRY.filter(
(a) => a.mode === mode || a.mode === "all",
);
};
/**
* Get agents by tag
*/
export const getAgentsByTag = (tag: string): UnifiedAgentDefinition[] => {
return UNIFIED_AGENT_REGISTRY.filter((a) => a.tags.includes(tag));
};
/**
* Get visible agents only
*/
export const getVisibleAgents = (): UnifiedAgentDefinition[] => {
return UNIFIED_AGENT_REGISTRY.filter((a) => !a.hidden);
};
/**
* Get subagents only (for task_agent tool)
*/
export const getSubagents = (): UnifiedAgentDefinition[] => {
return UNIFIED_AGENT_REGISTRY.filter(
(a) => (a.mode === "subagent" || a.mode === "all") && !a.hidden,
);
};
/**
* Map unified tier to internal tier (internal doesn't have "reasoning")
*/
const mapTier = (tier: AgentTier): "fast" | "balanced" | "thorough" => {
const tierMap: Record<AgentTier, "fast" | "balanced" | "thorough"> = {
fast: "fast",
balanced: "balanced",
thorough: "thorough",
reasoning: "thorough", // Map reasoning to thorough
};
return tierMap[tier];
};
/**
* Map unified color to internal color
*/
const mapColor = (
color?: string,
): "red" | "green" | "blue" | "yellow" | "cyan" | "magenta" | "white" | "gray" => {
const validColors = new Set([
"red",
"green",
"blue",
"yellow",
"cyan",
"magenta",
"white",
"gray",
]);
if (color && validColors.has(color)) {
return color as "red" | "green" | "blue" | "yellow" | "cyan" | "magenta" | "white" | "gray";
}
return "cyan";
};
/**
* Convert unified agent to internal AgentDefinition format
*/
export const toAgentDefinition = (
agent: UnifiedAgentDefinition,
): AgentDefinition => ({
name: agent.id,
description: agent.description,
tools: agent.tools,
tier: mapTier(agent.tier),
color: mapColor(agent.color),
maxTurns: agent.maxTurns,
systemPrompt: agent.systemPrompt,
});
/**
* Summary statistics
*/
export const REGISTRY_STATS = {
total: UNIFIED_AGENT_REGISTRY.length,
bySource: {
opencode: OPENCODE_AGENTS.length,
"claude-code": CLAUDE_CODE_AGENTS.length,
cursor: CURSOR_AGENTS.length,
codetyper: CODETYPER_AGENTS.length,
},
byTier: {
fast: UNIFIED_AGENT_REGISTRY.filter((a) => a.tier === "fast").length,
balanced: UNIFIED_AGENT_REGISTRY.filter((a) => a.tier === "balanced")
.length,
thorough: UNIFIED_AGENT_REGISTRY.filter((a) => a.tier === "thorough")
.length,
reasoning: UNIFIED_AGENT_REGISTRY.filter((a) => a.tier === "reasoning")
.length,
},
byMode: {
primary: UNIFIED_AGENT_REGISTRY.filter((a) => a.mode === "primary").length,
subagent: UNIFIED_AGENT_REGISTRY.filter((a) => a.mode === "subagent")
.length,
all: UNIFIED_AGENT_REGISTRY.filter((a) => a.mode === "all").length,
},
};