From 732ec85e07ad891ff201f09beaa7240d05b7f8ce Mon Sep 17 00:00:00 2001 From: justsisyphus Date: Mon, 19 Jan 2026 20:18:26 +0900 Subject: [PATCH] mcp --- AGENTS.md | 10 ++-- src/hooks/claude-code-hooks/AGENTS.md | 70 +++++++++++++++++++++++++++ src/mcp/AGENTS.md | 70 +++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 src/hooks/claude-code-hooks/AGENTS.md create mode 100644 src/mcp/AGENTS.md diff --git a/AGENTS.md b/AGENTS.md index f31141989..e6faf11f0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,7 +1,7 @@ # PROJECT KNOWLEDGE BASE -**Generated:** 2026-01-17T21:55:00+09:00 -**Commit:** 255f535a +**Generated:** 2026-01-19T18:10:00+09:00 +**Commit:** 45660940 **Branch:** dev ## OVERVIEW @@ -69,7 +69,7 @@ oh-my-opencode/ - **Build**: `bun build` (ESM) + `tsc --emitDeclarationOnly` - **Exports**: Barrel pattern in index.ts; explicit named exports - **Naming**: kebab-case directories, `createXXXHook`/`createXXXTool` factories -- **Testing**: BDD comments `#given/#when/#then`, 84 test files +- **Testing**: BDD comments `#given/#when/#then`, 83 test files - **Temperature**: 0.1 for code agents, max 0.3 ## ANTI-PATTERNS (THIS PROJECT) @@ -123,7 +123,7 @@ bun run typecheck # Type check bun run build # ESM + declarations + schema bun run rebuild # Clean + Build bun run build:schema # Schema only -bun test # Run tests (84 test files) +bun test # Run tests (83 test files) ``` ## DEPLOYMENT @@ -172,7 +172,7 @@ Three-tier MCP system: ## NOTES -- **Testing**: Bun native test (`bun test`), BDD-style, 84 test files +- **Testing**: Bun native test (`bun test`), BDD-style, 83 test files - **OpenCode**: Requires >= 1.0.150 - **Multi-lang docs**: README.md (EN), README.ko.md (KO), README.ja.md (JA), README.zh-cn.md (ZH-CN) - **Config**: `~/.config/opencode/oh-my-opencode.json` (user) or `.opencode/oh-my-opencode.json` (project) diff --git a/src/hooks/claude-code-hooks/AGENTS.md b/src/hooks/claude-code-hooks/AGENTS.md new file mode 100644 index 000000000..1bb52a012 --- /dev/null +++ b/src/hooks/claude-code-hooks/AGENTS.md @@ -0,0 +1,70 @@ +# CLAUDE CODE HOOKS COMPATIBILITY LAYER + +## OVERVIEW + +Full Claude Code settings.json hook compatibility. Executes user-defined hooks at 5 lifecycle events: PreToolUse, PostToolUse, UserPromptSubmit, Stop, PreCompact. + +## STRUCTURE + +``` +claude-code-hooks/ +├── index.ts # Main factory (401 lines) - createClaudeCodeHooksHook() +├── config.ts # Loads ~/.claude/settings.json +├── config-loader.ts # Extended config from multiple sources +├── pre-tool-use.ts # PreToolUse hook executor (172 lines) +├── post-tool-use.ts # PostToolUse hook executor (199 lines) +├── user-prompt-submit.ts # UserPromptSubmit hook executor +├── stop.ts # Stop hook executor (session idle) +├── pre-compact.ts # PreCompact hook executor (context compaction) +├── transcript.ts # Tool use recording (252 lines) +├── tool-input-cache.ts # Caches tool inputs between pre/post +├── types.ts # Hook types, context interfaces +├── todo.ts # Todo JSON parsing fix +└── plugin-config.ts # Plugin config access +``` + +## HOOK LIFECYCLE + +| Event | When | Can Block | Context Fields | +|-------|------|-----------|----------------| +| **PreToolUse** | Before tool | Yes | sessionId, toolName, toolInput, cwd | +| **PostToolUse** | After tool | Warn only | + toolOutput, transcriptPath | +| **UserPromptSubmit** | On user message | Yes | sessionId, prompt, parts, cwd | +| **Stop** | Session idle | inject_prompt | sessionId, parentSessionId | +| **PreCompact** | Before summarize | No | sessionId, cwd | + +## CONFIG SOURCES + +Priority (highest first): +1. `.claude/settings.json` (project) +2. `~/.claude/settings.json` (user) + +```json +{ + "hooks": { + "PreToolUse": [{ "matcher": "Edit", "command": "./check.sh" }], + "PostToolUse": [{ "command": "post-hook.sh $TOOL_NAME" }] + } +} +``` + +## HOOK EXECUTION + +1. User-defined hooks loaded from settings.json +2. Matchers filter by tool name (supports wildcards) +3. Commands executed via subprocess with environment: + - `$SESSION_ID`, `$TOOL_NAME`, `$TOOL_INPUT`, `$CWD` +4. Exit codes: 0=pass, 1=warn, 2=block + +## KEY PATTERNS + +- **Session tracking**: `Map` for first-message, error, interrupt +- **Input caching**: Tool inputs cached pre→post via `tool-input-cache.ts` +- **Transcript recording**: All tool uses logged for debugging +- **Todowrite fix**: Parses string todos to array (line 174-196) + +## ANTI-PATTERNS + +- **Heavy PreToolUse logic**: Runs before EVERY tool call +- **Blocking non-critical**: Use warnings in PostToolUse instead +- **Missing error handling**: Always wrap subprocess calls diff --git a/src/mcp/AGENTS.md b/src/mcp/AGENTS.md new file mode 100644 index 000000000..72974e933 --- /dev/null +++ b/src/mcp/AGENTS.md @@ -0,0 +1,70 @@ +# BUILT-IN MCP CONFIGURATIONS + +## OVERVIEW + +3 remote MCP servers for web search, documentation, and code search. All use HTTP/SSE transport, no OAuth. + +## STRUCTURE + +``` +mcp/ +├── index.ts # createBuiltinMcps() factory +├── websearch.ts # Exa AI web search +├── context7.ts # Library documentation +├── grep-app.ts # GitHub code search +├── types.ts # McpNameSchema +└── index.test.ts # Tests +``` + +## MCP SERVERS + +| Name | URL | Purpose | Auth | +|------|-----|---------|------| +| **websearch** | `mcp.exa.ai` | Real-time web search | `EXA_API_KEY` header | +| **context7** | `mcp.context7.com` | Official library docs | None | +| **grep_app** | `mcp.grep.app` | GitHub code search | None | + +## CONFIG PATTERN + +All MCPs follow identical structure: +```typescript +export const mcp_name = { + type: "remote" as const, + url: "https://...", + enabled: true, + oauth: false as const, // Explicit disable + headers?: { ... }, // Optional auth +} +``` + +## USAGE + +```typescript +import { createBuiltinMcps } from "./mcp" + +// Enable all +const mcps = createBuiltinMcps() + +// Disable specific +const mcps = createBuiltinMcps(["websearch"]) +``` + +## HOW TO ADD + +1. Create `src/mcp/my-mcp.ts`: + ```typescript + export const my_mcp = { + type: "remote" as const, + url: "https://mcp.example.com", + enabled: true, + oauth: false as const, + } + ``` +2. Add to `allBuiltinMcps` in `index.ts` +3. Add to `McpNameSchema` in `types.ts` + +## NOTES + +- **Remote only**: All built-in MCPs use HTTP/SSE, no stdio +- **Disable config**: User can disable via `disabled_mcps: ["name"]` +- **Exa requires key**: Set `EXA_API_KEY` env var for websearch