From ad9d3f94e046998bc53ad812dd53ea2c6ab86e43 Mon Sep 17 00:00:00 2001 From: catlog22 Date: Tue, 17 Mar 2026 23:03:20 +0800 Subject: [PATCH] feat: add MCP server for semantic code search with FastMCP integration --- .claude/skills/wf-composer/SKILL.md | 153 + .claude/skills/wf-composer/phases/01-parse.md | 93 + .../skills/wf-composer/phases/02-resolve.md | 89 + .../skills/wf-composer/phases/03-enrich.md | 104 + .../skills/wf-composer/phases/04-confirm.md | 97 + .../skills/wf-composer/phases/05-persist.md | 107 + .../skills/wf-composer/specs/node-catalog.md | 96 + .../wf-composer/specs/template-schema.md | 202 ++ .claude/skills/wf-player/SKILL.md | 151 + .claude/skills/wf-player/phases/01-load.md | 92 + .../skills/wf-player/phases/02-instantiate.md | 110 + .claude/skills/wf-player/phases/03-execute.md | 211 ++ .../skills/wf-player/phases/04-complete.md | 93 + .../skills/wf-player/specs/node-executor.md | 187 ++ .../skills/wf-player/specs/state-schema.md | 136 + .../components/codexlens/AdvancedTab.test.tsx | 154 - .../src/components/codexlens/AdvancedTab.tsx | 704 ----- .../src/components/codexlens/CcwToolsCard.tsx | 153 - .../components/codexlens/FileWatcherCard.tsx | 135 - .../src/components/codexlens/GpuSelector.tsx | 293 -- .../components/codexlens/IndexOperations.tsx | 286 -- .../codexlens/InstallProgressOverlay.tsx | 256 -- .../components/codexlens/LspServerCard.tsx | 157 - .../src/components/codexlens/ModelCard.tsx | 234 -- .../components/codexlens/ModelSelectField.tsx | 195 -- .../components/codexlens/ModelsTab.test.tsx | 405 --- .../src/components/codexlens/ModelsTab.tsx | 309 -- .../components/codexlens/OverviewTab.test.tsx | 276 -- .../src/components/codexlens/OverviewTab.tsx | 184 -- .../codexlens/SchemaFormRenderer.tsx | 286 -- .../src/components/codexlens/SearchTab.tsx | 445 --- .../codexlens/SemanticInstallDialog.tsx | 205 -- .../components/codexlens/SettingsTab.test.tsx | 431 --- .../src/components/codexlens/SettingsTab.tsx | 276 -- .../src/components/codexlens/envVarSchema.ts | 389 --- ccw/frontend/src/hooks/index.ts | 83 +- ccw/frontend/src/hooks/useCodexLens.test.tsx | 418 --- ccw/frontend/src/hooks/useCodexLens.ts | 1789 ------------ ccw/frontend/src/hooks/useV2SearchManager.ts | 159 + ccw/frontend/src/lib/api.ts | 1014 +------ ccw/frontend/src/locales/en/codexlens.json | 406 +-- ccw/frontend/src/locales/en/navigation.json | 2 +- ccw/frontend/src/locales/zh/codexlens.json | 406 +-- ccw/frontend/src/locales/zh/navigation.json | 2 +- .../src/pages/CodexLensManagerPage.test.tsx | 481 +-- .../src/pages/CodexLensManagerPage.tsx | 410 +-- ccw/frontend/src/test/i18n.tsx | 380 +-- ccw/frontend/src/types/codexlens.ts | 63 - ccw/src/core/memory-embedder-bridge.ts | 367 +-- ccw/src/core/routes/codexlens-routes.ts | 23 - ccw/src/core/routes/codexlens/README.md | 37 - .../core/routes/codexlens/config-handlers.ts | 1448 --------- .../core/routes/codexlens/index-handlers.ts | 459 --- .../routes/codexlens/semantic-handlers.ts | 1289 --------- ccw/src/core/routes/codexlens/utils.ts | 96 - .../core/routes/codexlens/watcher-handlers.ts | 322 --- ccw/src/core/routes/litellm-api-routes.ts | 249 +- ccw/src/core/routes/status-routes.ts | 29 +- ccw/src/core/server.ts | 29 - ccw/src/core/unified-vector-index.ts | 418 +-- ccw/src/tools/codex-lens-lsp.ts | 405 --- ccw/src/tools/codex-lens.ts | 2576 +---------------- ccw/src/tools/index.ts | 4 +- ccw/src/tools/litellm-client.ts | 244 +- ccw/src/utils/codexlens-path.ts | 54 - ccw/src/utils/package-discovery.ts | 327 --- ccw/src/utils/python-utils.ts | 269 -- ccw/src/utils/uv-manager.ts | 902 ------ .../codex-lens-bootstrap-pip-missing.test.js | 120 - ccw/tests/codex-lens-uv-install.test.ts | 372 --- ccw/tests/codexlens-path.test.js | 66 - ccw/tests/uv-manager-codexlens-python.test.js | 121 - ccw/tests/uv-manager.test.ts | 414 --- codex-lens-v2/.gitignore | 32 + codex-lens-v2/README.md | 296 +- .../codexlens_search-0.2.0-py3-none-any.whl | Bin 30402 -> 0 bytes .../dist/codexlens_search-0.2.0.tar.gz | Bin 31214 -> 0 bytes codex-lens-v2/pyproject.toml | 34 +- codex-lens-v2/src/codexlens_search/bridge.py | 80 +- .../src/codexlens_search/mcp_server.py | 367 +++ 80 files changed, 3427 insertions(+), 21329 deletions(-) create mode 100644 .claude/skills/wf-composer/SKILL.md create mode 100644 .claude/skills/wf-composer/phases/01-parse.md create mode 100644 .claude/skills/wf-composer/phases/02-resolve.md create mode 100644 .claude/skills/wf-composer/phases/03-enrich.md create mode 100644 .claude/skills/wf-composer/phases/04-confirm.md create mode 100644 .claude/skills/wf-composer/phases/05-persist.md create mode 100644 .claude/skills/wf-composer/specs/node-catalog.md create mode 100644 .claude/skills/wf-composer/specs/template-schema.md create mode 100644 .claude/skills/wf-player/SKILL.md create mode 100644 .claude/skills/wf-player/phases/01-load.md create mode 100644 .claude/skills/wf-player/phases/02-instantiate.md create mode 100644 .claude/skills/wf-player/phases/03-execute.md create mode 100644 .claude/skills/wf-player/phases/04-complete.md create mode 100644 .claude/skills/wf-player/specs/node-executor.md create mode 100644 .claude/skills/wf-player/specs/state-schema.md delete mode 100644 ccw/frontend/src/components/codexlens/AdvancedTab.test.tsx delete mode 100644 ccw/frontend/src/components/codexlens/AdvancedTab.tsx delete mode 100644 ccw/frontend/src/components/codexlens/CcwToolsCard.tsx delete mode 100644 ccw/frontend/src/components/codexlens/FileWatcherCard.tsx delete mode 100644 ccw/frontend/src/components/codexlens/GpuSelector.tsx delete mode 100644 ccw/frontend/src/components/codexlens/IndexOperations.tsx delete mode 100644 ccw/frontend/src/components/codexlens/InstallProgressOverlay.tsx delete mode 100644 ccw/frontend/src/components/codexlens/LspServerCard.tsx delete mode 100644 ccw/frontend/src/components/codexlens/ModelCard.tsx delete mode 100644 ccw/frontend/src/components/codexlens/ModelSelectField.tsx delete mode 100644 ccw/frontend/src/components/codexlens/ModelsTab.test.tsx delete mode 100644 ccw/frontend/src/components/codexlens/ModelsTab.tsx delete mode 100644 ccw/frontend/src/components/codexlens/OverviewTab.test.tsx delete mode 100644 ccw/frontend/src/components/codexlens/OverviewTab.tsx delete mode 100644 ccw/frontend/src/components/codexlens/SchemaFormRenderer.tsx delete mode 100644 ccw/frontend/src/components/codexlens/SearchTab.tsx delete mode 100644 ccw/frontend/src/components/codexlens/SemanticInstallDialog.tsx delete mode 100644 ccw/frontend/src/components/codexlens/SettingsTab.test.tsx delete mode 100644 ccw/frontend/src/components/codexlens/SettingsTab.tsx delete mode 100644 ccw/frontend/src/components/codexlens/envVarSchema.ts delete mode 100644 ccw/frontend/src/hooks/useCodexLens.test.tsx delete mode 100644 ccw/frontend/src/hooks/useCodexLens.ts create mode 100644 ccw/frontend/src/hooks/useV2SearchManager.ts delete mode 100644 ccw/frontend/src/types/codexlens.ts delete mode 100644 ccw/src/core/routes/codexlens-routes.ts delete mode 100644 ccw/src/core/routes/codexlens/README.md delete mode 100644 ccw/src/core/routes/codexlens/config-handlers.ts delete mode 100644 ccw/src/core/routes/codexlens/index-handlers.ts delete mode 100644 ccw/src/core/routes/codexlens/semantic-handlers.ts delete mode 100644 ccw/src/core/routes/codexlens/utils.ts delete mode 100644 ccw/src/core/routes/codexlens/watcher-handlers.ts delete mode 100644 ccw/src/tools/codex-lens-lsp.ts delete mode 100644 ccw/src/utils/package-discovery.ts delete mode 100644 ccw/src/utils/python-utils.ts delete mode 100644 ccw/src/utils/uv-manager.ts delete mode 100644 ccw/tests/codex-lens-bootstrap-pip-missing.test.js delete mode 100644 ccw/tests/codex-lens-uv-install.test.ts delete mode 100644 ccw/tests/codexlens-path.test.js delete mode 100644 ccw/tests/uv-manager-codexlens-python.test.js delete mode 100644 ccw/tests/uv-manager.test.ts delete mode 100644 codex-lens-v2/dist/codexlens_search-0.2.0-py3-none-any.whl delete mode 100644 codex-lens-v2/dist/codexlens_search-0.2.0.tar.gz create mode 100644 codex-lens-v2/src/codexlens_search/mcp_server.py diff --git a/.claude/skills/wf-composer/SKILL.md b/.claude/skills/wf-composer/SKILL.md new file mode 100644 index 00000000..7a3b9a74 --- /dev/null +++ b/.claude/skills/wf-composer/SKILL.md @@ -0,0 +1,153 @@ +--- +name: wf-composer +description: Semantic workflow composer — parse natural language workflow description into a DAG of skill/CLI/agent nodes, auto-inject checkpoint save nodes, confirm with user, persist as reusable JSON template. Triggers on "wf-composer " or "/wf-composer". +argument-hint: "[workflow description]" +allowed-tools: Agent(*), AskUserQuestion(*), Read(*), Write(*), Edit(*), Bash(*), Glob(*), Grep(*) +--- + +# Workflow Design + +Parse user's semantic workflow description → decompose into nodes → map to executors → auto-inject checkpoints → confirm pipeline → save as reusable `workflow-template.json`. + +## Architecture + +``` +User describes workflow in natural language + -> Phase 1: Parse — extract intent steps + variables + -> Phase 2: Resolve — map each step to executor (skill/cli/agent/command) + -> Phase 3: Enrich — inject checkpoint nodes, set DAG edges + -> Phase 4: Confirm — visualize pipeline, user approval/edit + -> Phase 5: Persist — save .workflow/templates/.json +``` + +## Shared Constants + +| Constant | Value | +|----------|-------| +| Session prefix | `WFD` | +| Template dir | `.workflow/templates/` | +| Template ID format | `wft--` | +| Node ID format | `N-` (e.g. N-001), `CP-` for checkpoints | +| Max nodes | 20 | + +## Entry Router + +Parse `$ARGUMENTS`. + +| Detection | Condition | Handler | +|-----------|-----------|---------| +| Resume design | `--resume` flag or existing WFD session | -> Phase 0: Resume | +| Edit template | `--edit ` flag | -> Phase 0: Load + Edit | +| New design | Default | -> Phase 1: Parse | + +## Phase 0: Resume / Edit (optional) + +**Resume design session**: +1. Scan `.workflow/templates/design-drafts/WFD-*.json` for in-progress designs +2. Multiple found → AskUserQuestion for selection +3. Load draft → skip to last incomplete phase + +**Edit existing template**: +1. Load template from `--edit` path +2. Show current pipeline visualization +3. AskUserQuestion: which nodes to modify/add/remove +4. Re-enter at Phase 3 (Enrich) with edits applied + +--- + +## Phase 1: Parse + +Read `phases/01-parse.md` and execute. + +**Objective**: Extract structured semantic steps + context variables from natural language. + +**Success**: `design-session/intent.json` written with: steps[], variables[], task_type, complexity. + +--- + +## Phase 2: Resolve + +Read `phases/02-resolve.md` and execute. + +**Objective**: Map each intent step to a concrete executor node. + +**Executor types**: +- `skill` — invoke via `Skill(skill=..., args=...)` +- `cli` — invoke via `ccw cli -p "..." --tool ... --mode ...` +- `command` — invoke via `Skill(skill="", args=...)` +- `agent` — invoke via `Agent(subagent_type=..., prompt=...)` +- `checkpoint` — state save + optional user pause + +**Success**: `design-session/nodes.json` written with resolved executor for each step. + +--- + +## Phase 3: Enrich + +Read `phases/03-enrich.md` and execute. + +**Objective**: Build DAG edges, auto-inject checkpoints at phase boundaries, validate port compatibility. + +**Checkpoint injection rules**: +- After every `skill` → `skill` transition that crosses a semantic phase boundary +- Before any long-running `agent` spawn +- After any node that produces a persistent artifact (plan, spec, analysis) +- At user-defined breakpoints (if any) + +**Success**: `design-session/dag.json` with nodes[], edges[], checkpoints[], context_schema{}. + +--- + +## Phase 4: Confirm + +Read `phases/04-confirm.md` and execute. + +**Objective**: Visualize the pipeline, present to user, incorporate edits. + +**Display format**: +``` +Pipeline: +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +N-001 [skill] workflow-lite-plan "{goal}" + | +CP-01 [checkpoint] After Plan auto-continue + | +N-002 [skill] workflow-test-fix "--session N-001" + | +CP-02 [checkpoint] After Tests pause-for-user +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Variables: goal (required) +Checkpoints: 2 (1 auto, 1 pause) +``` + +AskUserQuestion: +- Confirm & Save +- Edit node (select node ID) +- Add node after (select position) +- Remove node (select node ID) +- Rename template + +**Success**: User confirmed pipeline. Final dag.json ready. + +--- + +## Phase 5: Persist + +Read `phases/05-persist.md` and execute. + +**Objective**: Assemble final template JSON, write to template library, output summary. + +**Output**: +- `.workflow/templates/.json` — the reusable template +- Console summary with template path + usage command + +**Success**: Template saved. User shown: `Skill(skill="wf-player", args="")` + +--- + +## Specs Reference + +| Spec | Purpose | +|------|---------| +| [specs/node-catalog.md](specs/node-catalog.md) | Available executors, port definitions, arg templates | +| [specs/template-schema.md](specs/template-schema.md) | Full JSON template schema | diff --git a/.claude/skills/wf-composer/phases/01-parse.md b/.claude/skills/wf-composer/phases/01-parse.md new file mode 100644 index 00000000..c5e09634 --- /dev/null +++ b/.claude/skills/wf-composer/phases/01-parse.md @@ -0,0 +1,93 @@ +# Phase 1: Parse — Semantic Intent Extraction + +## Objective + +Extract structured semantic steps and context variables from the user's natural language workflow description. + +## Workflow + +### Step 1.1 — Read Input + +Parse `$ARGUMENTS` as the workflow description. If empty or ambiguous, AskUserQuestion: +- "Describe the workflow you want to automate. Include: what steps to run, in what order, and what varies each time (inputs)." + +### Step 1.2 — Extract Steps + +Scan the description for sequential actions. Each action becomes a candidate node. + +**Signal patterns** (not exhaustive — apply NL understanding): + +| Signal | Candidate Node Type | +|--------|---------------------| +| "analyze", "review", "explore" | analysis step (cli --mode analysis) | +| "plan", "design", "spec" | planning step (skill: workflow-lite-plan / workflow-plan) | +| "implement", "build", "code", "fix", "refactor" | execution step (skill: workflow-execute) | +| "test", "validate", "verify" | testing step (skill: workflow-test-fix) | +| "brainstorm", "ideate" | brainstorm step (skill: brainstorm / brainstorm-with-file) | +| "review code", "code review" | review step (skill: review-cycle) | +| "save", "checkpoint", "pause" | explicit checkpoint node | +| "spawn agent", "delegate", "subagent" | agent node | +| "then", "next", "after", "finally" | sequential edge signal | +| "parallel", "simultaneously", "at the same time" | parallel edge signal | + +### Step 1.3 — Extract Variables + +Identify inputs that vary per run. These become `context_schema` entries. + +**Variable detection**: +- Direct mentions: "the goal", "the target", "my task", "user-provided X" +- Parameterized slots: `{goal}`, `[feature]`, `` patterns in the description +- Implicit from task type: any "feature/bugfix/topic" is `goal` + +For each variable: assign name, type (string|path|boolean), required flag, description. + +### Step 1.4 — Detect Task Type + +Use ccw-coordinator task detection logic to classify the overall workflow: + +``` +bugfix | feature | tdd | review | brainstorm | spec-driven | roadmap | +refactor | integration-test | greenfield | quick-task | custom +``` + +`custom` = user describes a non-standard combination. + +### Step 1.5 — Complexity Assessment + +Count nodes, detect parallel tracks, identify dependencies: +- `simple` = 1-3 nodes, linear +- `medium` = 4-7 nodes, at most 1 parallel track +- `complex` = 8+ nodes or multiple parallel tracks + +### Step 1.6 — Write Output + +Create session dir: `.workflow/templates/design-drafts/WFD--/` + +Write `intent.json`: +```json +{ + "session_id": "WFD--", + "raw_description": "", + "task_type": "", + "complexity": "simple|medium|complex", + "steps": [ + { + "seq": 1, + "description": "", + "type_hint": "analysis|planning|execution|testing|review|checkpoint|agent|cli", + "parallel_with": null, + "variables": ["goal"] + } + ], + "variables": { + "goal": { "type": "string", "required": true, "description": "" } + }, + "created_at": "" +} +``` + +## Success Criteria + +- `intent.json` exists with at least 1 step +- All referenced variables extracted to `variables` map +- task_type and complexity assigned diff --git a/.claude/skills/wf-composer/phases/02-resolve.md b/.claude/skills/wf-composer/phases/02-resolve.md new file mode 100644 index 00000000..4d3b4dac --- /dev/null +++ b/.claude/skills/wf-composer/phases/02-resolve.md @@ -0,0 +1,89 @@ +# Phase 2: Resolve — Map Steps to Executor Nodes + +## Objective + +Map each intent step from `intent.json` into a concrete executor node with assigned type, executor, and arg template. + +## Workflow + +### Step 2.1 — Load Intent + +Read `design-session/intent.json`. Load steps[], variables{}. + +### Step 2.2 — Map Each Step to Executor + +For each step, determine the executor node using the Node Catalog (`specs/node-catalog.md`). + +**Resolution algorithm**: +1. Match `type_hint` to executor candidates in catalog +2. If multiple candidates, select by semantic fit to step description +3. If no catalog match, emit `cli` node with inferred `--rule` and `--mode` + +**Node type assignment**: + +| Step type_hint | Default executor type | Default executor | +|----------------|----------------------|------------------| +| `planning` | skill | `workflow-lite-plan` (simple/medium) or `workflow-plan` (complex) | +| `execution` | skill | `workflow-execute` | +| `testing` | skill | `workflow-test-fix` | +| `review` | skill | `review-cycle` | +| `brainstorm` | skill | `brainstorm` | +| `analysis` | cli | `ccw cli --tool gemini --mode analysis` | +| `spec` | skill | `spec-generator` | +| `tdd` | skill | `workflow-tdd-plan` | +| `refactor` | command | `workflow:refactor-cycle` | +| `integration-test` | command | `workflow:integration-test-cycle` | +| `agent` | agent | (infer subagent_type from description) | +| `checkpoint` | checkpoint | — | + +### Step 2.3 — Build Arg Templates + +For each node, build `args_template` by substituting variable references: + +``` +skill node: args_template = `{goal}` (or `--session {prev_session}`) +cli node: args_template = `PURPOSE: {goal}\nTASK: ...\nMODE: analysis\nCONTEXT: @**/*` +agent node: args_template = `{goal}\nContext: {prev_output}` +``` + +**Context injection rules**: +- Planning nodes that follow analysis: inject `--context {prev_output_path}` +- Execution nodes that follow planning: inject `--resume-session {prev_session_id}` +- Testing nodes that follow execution: inject `--session {prev_session_id}` + +Use `{prev_session_id}` and `{prev_output_path}` as runtime-resolved references — the executor will substitute these from node state at run time. + +### Step 2.4 — Assign Parallel Groups + +For steps with `parallel_with` set: +- Assign same `parallel_group` string to both nodes +- Parallel nodes share no data dependency (each gets same input) + +### Step 2.5 — Write Output + +Write `design-session/nodes.json`: +```json +{ + "session_id": "", + "nodes": [ + { + "id": "N-001", + "seq": 1, + "name": "", + "type": "skill|cli|command|agent|checkpoint", + "executor": "", + "args_template": "