2026-02-08 17:09:12 +09:00
|
|
|
# AGENTS KNOWLEDGE BASE
|
|
|
|
|
|
|
|
|
|
## OVERVIEW
|
|
|
|
|
|
2026-02-09 14:29:53 +09:00
|
|
|
Main plugin entry point and orchestration layer. Plugin initialization, hook registration, tool composition, and lifecycle management.
|
2026-02-08 17:09:12 +09:00
|
|
|
|
|
|
|
|
**Core Responsibilities:**
|
2026-02-09 14:29:53 +09:00
|
|
|
- Plugin initialization via `OhMyOpenCodePlugin()` factory
|
|
|
|
|
- Hook registration: `createCoreHooks()`, `createContinuationHooks()`, `createSkillHooks()`
|
|
|
|
|
- Tool composition with filtering
|
|
|
|
|
- Background agent management via `BackgroundManager`
|
|
|
|
|
- MCP lifecycle via `SkillMcpManager`
|
2026-02-08 17:09:12 +09:00
|
|
|
|
|
|
|
|
## STRUCTURE
|
|
|
|
|
```
|
|
|
|
|
src/
|
2026-02-09 14:29:53 +09:00
|
|
|
├── index.ts # Main plugin entry (999 lines)
|
|
|
|
|
├── create-hooks.ts # Hook coordination: core, continuation, skill
|
|
|
|
|
├── plugin-config.ts # Config loading orchestration
|
|
|
|
|
├── plugin-state.ts # Model cache state
|
|
|
|
|
├── agents/ # 11 AI agents (20 files) - see agents/AGENTS.md
|
|
|
|
|
├── cli/ # CLI installer, doctor (100+ files) - see cli/AGENTS.md
|
|
|
|
|
├── config/ # Zod schema (21 files) - see config/AGENTS.md
|
|
|
|
|
├── features/ # Background agents, skills, commands (17 dirs) - see features/AGENTS.md
|
|
|
|
|
├── hooks/ # 40+ lifecycle hooks (30+ dirs) - see hooks/AGENTS.md
|
|
|
|
|
├── mcp/ # Built-in MCPs (8 files) - see mcp/AGENTS.md
|
|
|
|
|
├── plugin/ # Plugin SDK types
|
|
|
|
|
├── plugin-handlers/ # Plugin config loading (5 files) - see plugin-handlers/AGENTS.md
|
|
|
|
|
├── shared/ # Cross-cutting utilities (84 files) - see shared/AGENTS.md
|
|
|
|
|
└── tools/ # 25+ tools (14 dirs) - see tools/AGENTS.md
|
2026-02-08 17:09:12 +09:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## KEY COMPONENTS
|
|
|
|
|
|
|
|
|
|
**Plugin Initialization:**
|
2026-02-09 14:29:53 +09:00
|
|
|
- `OhMyOpenCodePlugin()`: Main plugin factory
|
2026-02-08 17:09:12 +09:00
|
|
|
- Configuration loading via `loadPluginConfig()`
|
|
|
|
|
- Hook registration with safe creation patterns
|
|
|
|
|
- Tool composition and disabled tool filtering
|
|
|
|
|
|
|
|
|
|
**Lifecycle Management:**
|
|
|
|
|
- 40+ hooks: session recovery, continuation enforcers, compaction, context injection
|
|
|
|
|
- Background agent coordination via `BackgroundManager`
|
|
|
|
|
- Tmux session management for multi-pane workflows
|
|
|
|
|
- MCP server lifecycle via `SkillMcpManager`
|
|
|
|
|
|
|
|
|
|
**Tool Ecosystem:**
|
|
|
|
|
- 25+ tools: LSP, AST-grep, delegation, background tasks, skills
|
|
|
|
|
- Tool filtering based on agent permissions and user config
|
|
|
|
|
- Metadata restoration for tool outputs
|
|
|
|
|
|
2026-02-09 14:29:53 +09:00
|
|
|
## HOOK REGISTRATION
|
2026-02-08 17:09:12 +09:00
|
|
|
|
|
|
|
|
**Safe Hook Creation:**
|
|
|
|
|
```typescript
|
|
|
|
|
const hook = isHookEnabled("hook-name")
|
|
|
|
|
? safeCreateHook("hook-name", () => createHookFactory(ctx), { enabled: safeHookEnabled })
|
|
|
|
|
: null;
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Hook Categories:**
|
|
|
|
|
- **Session Management**: recovery, notification, compaction
|
|
|
|
|
- **Continuation**: todo/task enforcers, stop guards
|
|
|
|
|
- **Context**: injection, rules, directory content
|
2026-02-09 14:29:53 +09:00
|
|
|
- **Tool Enhancement**: output truncation, error recovery
|
2026-02-08 17:09:12 +09:00
|
|
|
- **Agent Coordination**: usage reminders, babysitting, delegation
|
|
|
|
|
|
|
|
|
|
## TOOL COMPOSITION
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
const allTools: Record<string, ToolDefinition> = {
|
2026-02-09 14:29:53 +09:00
|
|
|
...builtinTools,
|
|
|
|
|
...createGrepTools(ctx),
|
|
|
|
|
...createAstGrepTools(ctx),
|
|
|
|
|
task: delegateTask,
|
|
|
|
|
skill: skillTool,
|
2026-02-08 17:09:12 +09:00
|
|
|
};
|
|
|
|
|
```
|
|
|
|
|
|
2026-02-09 14:29:53 +09:00
|
|
|
**Filtering:** Agent permissions, user `disabled_tools`, session state.
|
2026-02-08 17:09:12 +09:00
|
|
|
|
2026-02-09 14:29:53 +09:00
|
|
|
## LIFECYCLE FLOW
|
2026-02-08 17:09:12 +09:00
|
|
|
|
|
|
|
|
1. User message triggers agent selection
|
|
|
|
|
2. Model/variant resolution applied
|
|
|
|
|
3. Tools execute with hook interception
|
|
|
|
|
4. Continuation enforcers monitor completion
|
|
|
|
|
5. Session compaction preserves context
|