Skip to content

Commit 3199249

Browse files
committed
feat(mcp-server): add activate tool and promote Teams as primary execution strategy
- Add activate handler: one-shot entry point combining rule loading, primary agent resolution, specialist recommendation, and prompt generation in a single call (~70% token reduction vs parse_mode) - Promote Claude native Teams from experimental to auto-enabled in Claude Code environments (claude-native source detection) - Deprecate context-document, briefing, resume, analyze_task tools with Claude Code Memory migration guidance - Remove EXPERIMENTAL label from discussion handler, guide toward activate + Teams for real specialist debate - Rewrite tool-priority.md with 3-layer hierarchy: Claude Code Native > codingbuddy > OMC - Simplify custom-instructions.md: 4 MANDATORY rules → 2 + native feature mapping table - Add activate + Teams guide to claude-code.md adapter - 26 new tests for activate handler, 4 for Teams auto-detection
1 parent e4c4fd1 commit 3199249

17 files changed

Lines changed: 896 additions & 176 deletions

.claude/rules/custom-instructions.md

Lines changed: 30 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -123,125 +123,50 @@ Even if plan separates TDD into individual steps (e.g., Step 1: Write test, Step
123123

124124
<CODINGBUDDY_CRITICAL_RULE>
125125

126-
**When user message starts with PLAN, ACT, EVAL, or AUTO keyword (or localized: Korean 계획/실행/평가/자동, Japanese 計画/実行/評価/自動, Chinese 计划/执行/评估/自动, Spanish PLANIFICAR/ACTUAR/EVALUAR/AUTOMÁTICO):**
126+
**When user message starts with PLAN, ACT, EVAL, or AUTO keyword (or localized equivalents):**
127127

128-
1. **IMMEDIATELY** call `parse_mode` MCP tool with the user's prompt
129-
2. Follow the returned `instructions` **EXACTLY**
130-
3. Apply the returned `rules` as context
131-
4. If `warnings` are present, inform the user
132-
133-
**This is MANDATORY, not optional.**
134-
135-
Failure to call `parse_mode` when these keywords are present will result in:
136-
- Missed critical checklists (Devil's Advocate Analysis, Impact Radius Analysis)
137-
- Incomplete evaluations
138-
- Quality issues not caught before deployment
139-
140-
**Red Flags** (STOP if you think these):
141-
| Thought | Reality |
142-
|---------|---------|
143-
| "I can handle EVAL myself" | NO. Call parse_mode FIRST. |
144-
| "The rules are similar anyway" | NO. Each mode has specific checklists. |
145-
| "I'll save a tool call" | NO. parse_mode MUST be called FIRST. |
146-
| "I already know what to do" | NO. Rules may have been updated. |
128+
1. Call `activate` MCP tool with the user's prompt (preferred in Claude Code)
129+
2. **Fallback**: Call `parse_mode` if `activate` is unavailable
130+
3. Follow the returned `rules` as context
131+
4. Use returned `specialists` to run a council via Claude native Teams
147132

148133
</CODINGBUDDY_CRITICAL_RULE>
149134

150-
Examples:
151-
- `PLAN design auth feature`**immediately** call parse_mode → work in PLAN mode
152-
- `AUTO implement user dashboard`**immediately** call parse_mode → autonomous PLAN→ACT→EVAL cycle
153-
154-
## 🔴 MANDATORY: Parallel Specialist Agent Execution
155-
156-
<PARALLEL_EXECUTION_MANDATORY_RULE>
157-
158-
**When `parse_mode` returns `dispatchReady`, use it directly with the Task tool — no extra calls needed.**
159-
160-
**Outer Transport Selection (before dispatch):**
161-
- [ ] Check `availableStrategies` in `parse_mode` response (outer transport options)
162-
- [ ] If `["subagent", "taskmaestro"]` → AskUserQuestion to choose outer strategy
163-
- [ ] If `taskmaestroInstallHint` present and user wants taskmaestro → guide installation
164-
- [ ] Pass chosen strategy to `dispatch_agents(executionStrategy: ...)`
165-
- [ ] Teams (inner coordination, experimental) may be used within a session if APIs are available
166-
167-
**Quick Checklist (Auto-Dispatch - Preferred):**
168-
- [ ] Check `dispatchReady` in `parse_mode` response
169-
- [ ] Use `dispatchReady.primaryAgent.dispatchParams` with Task tool
170-
- [ ] Use `dispatchReady.parallelAgents[].dispatchParams` with Task tool (`run_in_background: true`)
171-
- [ ] Collect results with `TaskOutput`
172-
- [ ] Summarize all findings
173-
174-
**Fallback (if `dispatchReady` is not present):**
175-
- [ ] Call `dispatch_agents` or `prepare_parallel_agents` with recommended specialists
176-
- [ ] Execute each agent via Task tool (`subagent_type: "general-purpose"`, `run_in_background: true`)
177-
- [ ] Display activation status
178-
- [ ] Collect results with `TaskOutput`
179-
- [ ] Summarize all findings
180-
181-
**Mode-specific Specialists:**
182-
183-
| Mode | Specialists |
184-
|------|-------------|
185-
| **PLAN** | 🏛️ architecture, 🧪 test-strategy, 📨 event-architecture, 🔗 integration, 📊 observability, 🔄 migration |
186-
| **ACT** | 📏 code-quality, 🧪 test-strategy, 📨 event-architecture, 🔗 integration |
187-
| **EVAL** | 🔒 security, ♿ accessibility, ⚡ performance, 📏 code-quality, 📨 event-architecture, 🔗 integration, 📊 observability, 🔄 migration |
188-
| **AUTO** | 🏛️ architecture, 🧪 test-strategy, 🔒 security, 📏 code-quality, 📨 event-architecture, 🔗 integration, 📊 observability, 🔄 migration |
189-
190-
> **Note:** SubAgent and TaskMaestro are **outer transport** strategies (one per invocation, user choice).
191-
> Teams is an **inner coordination** layer (experimental) that can optionally run within either outer strategy.
192-
> See the [Execution Model](../../packages/rules/.ai-rules/adapters/claude-code.md#execution-model-outer-transport-vs-inner-coordination) for details.
193-
194-
**📖 Full Guide:** [Parallel Specialist Agents Execution](../../packages/rules/.ai-rules/adapters/claude-code.md#parallel-specialist-agents-execution)
195-
196-
</PARALLEL_EXECUTION_MANDATORY_RULE>
197-
198-
## 🔴 MANDATORY: Auto-Dispatch Enforcement
199-
200-
<AUTO_DISPATCH_ENFORCEMENT_RULE>
201-
202-
**When `parse_mode` returns `dispatch="auto"`, you MUST dispatch all recommended specialists. No exceptions.**
203-
204-
### Core Rule
205-
206-
If the `parse_mode` response contains `dispatch="auto"` or `dispatchReady` with specialist agents:
207-
1. **MUST** dispatch every listed specialist — skipping any is a protocol violation
208-
2. Use the selected **outer transport** (SubAgent or TaskMaestro) to dispatch specialists
209-
3. **Optionally** use Teams as inner coordination within a session (experimental, requires runtime API availability)
210-
4. **Report results** via the dispatch mechanism (TaskOutput for SubAgent, SendMessage for Teams)
211-
212-
### Red Flags (STOP if you think these)
213-
214-
| Thought | Reality |
215-
|---------|---------|
216-
| "I can handle this analysis myself" | NO. Specialists have domain expertise you lack. Dispatch them. |
217-
| "It's just a small change, no need for specialists" | NO. dispatch="auto" means the system determined specialists are needed. |
218-
| "I'll save time by skipping dispatch" | NO. Skipping specialists causes missed issues that cost more time later. |
219-
| "The specialists will just repeat what I already know" | NO. Specialists catch domain-specific issues you would miss. |
220-
| "I'll dispatch them later after I look at the code" | NO. Dispatch IMMEDIATELY when dispatch="auto" is returned. |
135+
## 🔴 MANDATORY: Specialist Council Execution
221136

222-
</AUTO_DISPATCH_ENFORCEMENT_RULE>
137+
<SPECIALIST_COUNCIL_RULE>
223138

224-
## 🔴 MANDATORY: Context Document Management
139+
**When `activate` returns specialists, run them as a council via Claude native Teams.**
225140

226-
<CONTEXT_DOCUMENT_RULE>
141+
### Workflow
227142

228-
**Fixed file `docs/codingbuddy/context.md` persists PLAN → ACT → EVAL context across context compaction.**
143+
1. Call `activate({ prompt })` → get rules, primaryAgent, specialists
144+
2. Create a Claude native Team with the returned specialists as teammates
145+
3. Each specialist independently analyzes the task
146+
4. Specialists cross-review each other's findings
147+
5. Collect consensus: approve | concern | reject
148+
6. Summarize all findings to user
229149

230-
### How It Works
150+
### Fallback (non-Teams environments)
231151

232-
`parse_mode` **automatically** manages the context document:
152+
If Teams is not available, dispatch specialists as parallel subagents:
153+
- Use `Agent` tool with `run_in_background: true` for each specialist
154+
- Collect results and synthesize
233155

234-
- **PLAN/AUTO mode**: Resets (deletes and recreates) the context document
235-
- **ACT/EVAL mode**: Appends a new section to the existing document
156+
</SPECIALIST_COUNCIL_RULE>
236157

237-
### Required Workflow
158+
## Claude Code Native Feature Mapping
238159

239-
**In ALL modes:**
240-
1. `parse_mode` automatically reads/creates context
241-
2. Review `contextDocument` for previous decisions and notes
242-
3. Before completing: `update_context` to persist current work
160+
Use Claude Code native features instead of codingbuddy equivalents:
243161

244-
</CONTEXT_DOCUMENT_RULE>
162+
| Need | Native Feature | Instead of |
163+
|------|----------------|------------|
164+
| Cross-session context | **Claude Code Memory** | `update_context` / `create_briefing` / `resume_session` |
165+
| Specialist debate | **Claude native Teams** | `dispatch_agents` subagent strategy |
166+
| Task exploration | **/dream** | `analyze_task` |
167+
| Planning with approval | **EnterPlanMode** | `parse_mode` planning stage |
168+
| Repeated execution | **/loop** | AUTO mode repetition |
169+
| Clarification | **AskUserQuestion** | clarification gate |
245170

246171
## Claude Code Specific
247172

@@ -250,7 +175,6 @@ If the `parse_mode` response contains `dispatch="auto"` or `dispatchReady` with
250175
- Provide clear, actionable feedback
251176
- Reference project context from `packages/rules/.ai-rules/rules/project.md`
252177
- Follow PLAN → ACT → EVAL workflow when appropriate
253-
- Use AUTO mode for autonomous quality-driven development cycles
254178

255179
## Full Documentation
256180

.claude/rules/tool-priority.md

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,79 @@
1-
# Tool Priority: codingbuddy vs oh-my-claudecode (OMC)
1+
# Tool Priority: Claude Code Native > codingbuddy > OMC
22

33
## Core Principle
44

5-
**codingbuddy FIRST** — Use codingbuddy tools for all workflow management, agent dispatch, and quality control.
6-
**OMC for unique features only** — Use OMC tools when they provide capabilities codingbuddy does not.
5+
1. **Claude Code native FIRST** — Memory, Teams, Plan mode, /dream, /loop handle orchestration natively
6+
2. **codingbuddy for unique value** — Rules, agents, checklists, quality reports are codingbuddy's core
7+
3. **OMC for dev tools** — LSP, AST grep, REPL, git-master when needed
78

89
---
910

10-
## codingbuddy FIRST
11+
## Layer 1: Claude Code Native (highest priority)
1112

12-
Always reach for these codingbuddy tools before any OMC equivalent:
13+
These features are built into Claude Code and should be used instead of codingbuddy equivalents:
14+
15+
| Native Feature | Purpose | Replaces |
16+
|----------------|---------|----------|
17+
| **Claude Code Memory** | Cross-session context persistence | `update_context`, `create_briefing`, `resume_session` |
18+
| **Claude native Teams** | Run specialist agents as teammates for real-time debate | `dispatch_agents` subagent strategy |
19+
| **EnterPlanMode** | Structured planning with user approval | `parse_mode` planning stage routing |
20+
| **/dream** | Autonomous task exploration and analysis | `analyze_task` |
21+
| **/loop** | Recurring execution on interval | `parse_mode` AUTO mode repetition |
22+
| **AskUserQuestion** | Clarification from user | `parse_mode` clarification gate |
23+
24+
---
25+
26+
## Layer 2: codingbuddy (unique value)
27+
28+
Use codingbuddy tools for capabilities Claude Code does not provide natively:
1329

1430
| Tool | Purpose |
1531
|------|---------|
16-
| `parse_mode` | Mode management (PLAN/ACT/EVAL/AUTO), agent activation, context init |
17-
| `dispatch_agents` | Agent dispatch with Task tool-ready params |
18-
| `analyze_task` | Pre-planning task analysis, risk assessment, specialist recommendations |
19-
| `update_context` | Context persistence across PLAN → ACT → EVAL modes |
20-
| `generate_checklist` | Contextual checklists (security, a11y, performance, testing) |
32+
| `activate` | **One-shot entry point**: rules + primary agent + specialists + discussion format |
33+
| `parse_mode` | Legacy mode entry (for non-Claude Code hosts: Cursor, Codex, etc.) |
2134
| `search_rules` | Query project rules and guidelines |
2235
| `get_agent_details` | Agent profile and expertise lookup |
36+
| `generate_checklist` | Contextual checklists (security, a11y, performance, testing) |
2337
| `get_project_config` | Tech stack, architecture, language settings |
24-
| `prepare_parallel_agents` | Ready-to-use prompts for parallel specialist agents |
2538
| `pr_quality_report` | Run specialist agents on changed files for PR quality |
26-
| `create_briefing` | Capture session state for cross-session recovery |
27-
| `resume_session` | Load previous session briefing |
2839
| `get_rule_impact_report` | Rule effectiveness analytics |
2940

3041
---
3142

32-
## OMC Only
43+
## Layer 3: OMC (dev tools)
3344

34-
Use these OMC tools when the capability is not available in codingbuddy:
45+
Use OMC tools for capabilities neither Claude Code nor codingbuddy provide:
3546

3647
| Tool / Skill | Purpose |
3748
|--------------|---------|
3849
| LSP tools (`lsp_hover`, `lsp_goto_definition`, `lsp_find_references`, etc.) | Language server protocol — type info, definitions, references |
3950
| AST grep (`ast_grep_search`, `ast_grep_replace`) | Structural code search and refactoring |
4051
| Python REPL (`python_repl`) | Interactive data analysis and computation |
41-
| State tools (`state_read`, `state_write`, `state_clear`) | Mode state persistence for autopilot/ralph/ultrawork |
42-
| Notepad tools (`notepad_read`, `notepad_write_*`) | Session notes and compaction-resilient memory |
43-
| Project memory (`project_memory_*`) | Long-term project knowledge persistence |
4452
| `/git-master` | Atomic commits, rebasing, history management |
4553
| `/build-fix` | Build and TypeScript error resolution |
4654
| `/deepsearch` | Thorough multi-pass codebase search |
47-
| `/team`, `/swarm` | Multi-agent coordination with shared task lists |
48-
| `/ultrawork`, `/autopilot`, `/ralph` | Autonomous execution loops |
49-
| `/pipeline` | Sequential/branching agent workflows |
5055

5156
---
5257

53-
## Overlap Matrix
54-
55-
When both tools could apply, codingbuddy wins:
58+
## Quick Decision Matrix
5659

5760
| Use Case | Use This | Not This |
5861
|----------|----------|----------|
59-
| Starting PLAN/ACT/EVAL mode | `parse_mode` | OMC mode state tools |
60-
| Dispatching specialist agents | `dispatch_agents` | OMC `/team` or `/swarm` |
61-
| Code/security review | codingbuddy `search_rules` + specialists | OMC `/code-review`, `/security-review` |
62-
| Context across sessions | `update_context` | OMC notepad/project memory |
63-
| Task analysis before planning | `analyze_task` | Ad-hoc OMC tools |
64-
| Checklists (security, a11y) | `generate_checklist` | Manual OMC review |
62+
| Starting a workflow | `activate` | `parse_mode` (in Claude Code) |
63+
| Running specialist council | Claude native Teams | subagent dispatch |
64+
| Cross-session context | Claude Code Memory | `update_context` / `create_briefing` |
65+
| Task analysis | `/dream` | `analyze_task` |
66+
| Repeated execution | `/loop` | AUTO mode cycle |
67+
| Clarification | AskUserQuestion | clarification gate |
68+
| Rules & checklists | codingbuddy `search_rules`, `generate_checklist` ||
69+
| Code review quality | codingbuddy `pr_quality_report` | OMC `/code-review` |
70+
| Type info & references | OMC LSP tools ||
6571

6672
---
6773

6874
## Decision Rationale
6975

70-
- codingbuddy tools are project-aware and integrate with the PLAN/ACT/EVAL workflow
71-
- OMC tools are general-purpose developer tools without project context
72-
- Using codingbuddy first ensures consistent quality gates and audit trail via `docs/codingbuddy/context.md`
73-
- OMC's unique capabilities (LSP, AST, REPL) complement codingbuddy; they do not replace it
76+
- Claude Code native features handle orchestration (memory, teams, planning, loops) better than MCP tools
77+
- codingbuddy's unique value is **rules, agents, and checklists** — domain knowledge, not orchestration
78+
- OMC's unique value is **dev tooling** (LSP, AST, REPL) — code intelligence, not workflow
79+
- `parse_mode` remains available for backward compatibility with non-Claude Code hosts

apps/mcp-server/src/agent/teams-capability.service.spec.ts

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,28 @@ import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
22
import { TeamsCapabilityService } from './teams-capability.service';
33
import type { ConfigService } from '../config/config.service';
44

5-
function createMockConfigService(experimental?: { teamsCoordination?: boolean }): ConfigService {
5+
function createMockConfigService(
6+
experimental?: { teamsCoordination?: boolean },
7+
clientName?: string,
8+
): ConfigService {
69
return {
710
getSettings: vi.fn().mockResolvedValue({ experimental }),
11+
getClientName: vi.fn().mockReturnValue(clientName),
812
} as unknown as ConfigService;
913
}
1014

1115
describe('TeamsCapabilityService', () => {
1216
let originalEnv: string | undefined;
17+
let originalClaudeCode: string | undefined;
18+
let originalClaudeEntrypoint: string | undefined;
1319

1420
beforeEach(() => {
1521
originalEnv = process.env.CODINGBUDDY_TEAMS_ENABLED;
22+
originalClaudeCode = process.env.CLAUDE_CODE;
23+
originalClaudeEntrypoint = process.env.CLAUDE_CODE_ENTRYPOINT;
1624
delete process.env.CODINGBUDDY_TEAMS_ENABLED;
25+
delete process.env.CLAUDE_CODE;
26+
delete process.env.CLAUDE_CODE_ENTRYPOINT;
1727
});
1828

1929
afterEach(() => {
@@ -22,6 +32,16 @@ describe('TeamsCapabilityService', () => {
2232
} else {
2333
delete process.env.CODINGBUDDY_TEAMS_ENABLED;
2434
}
35+
if (originalClaudeCode !== undefined) {
36+
process.env.CLAUDE_CODE = originalClaudeCode;
37+
} else {
38+
delete process.env.CLAUDE_CODE;
39+
}
40+
if (originalClaudeEntrypoint !== undefined) {
41+
process.env.CLAUDE_CODE_ENTRYPOINT = originalClaudeEntrypoint;
42+
} else {
43+
delete process.env.CLAUDE_CODE_ENTRYPOINT;
44+
}
2545
});
2646

2747
describe('getStatus', () => {
@@ -125,6 +145,43 @@ describe('TeamsCapabilityService', () => {
125145
});
126146
});
127147

148+
describe('Claude Code auto-detection', () => {
149+
it('should auto-enable when CLAUDE_CODE=1 is set', async () => {
150+
process.env.CLAUDE_CODE = '1';
151+
const service = new TeamsCapabilityService(createMockConfigService());
152+
const status = await service.getStatus();
153+
154+
expect(status.available).toBe(true);
155+
expect(status.source).toBe('claude-native');
156+
expect(status.reason).toContain('Claude Code');
157+
});
158+
159+
it('should auto-enable when CLAUDE_CODE_ENTRYPOINT is set', async () => {
160+
process.env.CLAUDE_CODE_ENTRYPOINT = '/some/path';
161+
const service = new TeamsCapabilityService(createMockConfigService());
162+
const status = await service.getStatus();
163+
164+
expect(status.available).toBe(true);
165+
expect(status.source).toBe('claude-native');
166+
});
167+
168+
it('should auto-enable when clientName is claude-code', async () => {
169+
const service = new TeamsCapabilityService(createMockConfigService(undefined, 'claude-code'));
170+
const status = await service.getStatus();
171+
172+
expect(status.available).toBe(true);
173+
expect(status.source).toBe('claude-native');
174+
});
175+
176+
it('should not auto-enable for other clients', async () => {
177+
const service = new TeamsCapabilityService(createMockConfigService(undefined, 'cursor'));
178+
const status = await service.getStatus();
179+
180+
expect(status.available).toBe(false);
181+
expect(status.source).toBe('default');
182+
});
183+
});
184+
128185
describe('readEnvFlag', () => {
129186
it('should return undefined when env var is not set', () => {
130187
const service = new TeamsCapabilityService(createMockConfigService());
@@ -166,7 +223,7 @@ describe('TeamsCapabilityService', () => {
166223
expect(status).toHaveProperty('source');
167224
expect(typeof status.available).toBe('boolean');
168225
expect(typeof status.reason).toBe('string');
169-
expect(['config', 'environment', 'default']).toContain(status.source);
226+
expect(['config', 'environment', 'claude-native', 'default']).toContain(status.source);
170227
});
171228
});
172229
});

0 commit comments

Comments
 (0)