refactor: migrate plugin structure from .claude-plugin to project root

Restructure plugin to follow Claude Code official documentation:
- Move TypeScript files from .claude-plugin/* to project root
- Create Markdown command files in commands/
- Update plugin.json to reference ./commands/*.md
- Add comprehensive plugin installation guide

Changes:
- Commands: pm.md, research.md, index-repo.md (new Markdown format)
- TypeScript: pm/, research/, index/ moved to root
- Hooks: hooks/hooks.json moved to root
- Documentation: PLUGIN_INSTALL.md, updated CLAUDE.md, Makefile

Note: This commit represents transition state. Original TypeScript-based
execution system was replaced with Markdown commands. Further redesign
needed to properly integrate Skills and Hooks per official docs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
kazuki
2025-10-21 16:37:35 +09:00
parent fbc74e4670
commit c91a3a4805
16 changed files with 1795 additions and 331 deletions

171
pm/confidence.ts Normal file
View File

@@ -0,0 +1,171 @@
/**
* Confidence Check - Pre-implementation confidence assessment
*
* Prevents wrong-direction execution by assessing confidence BEFORE starting.
* Requires ≥90% confidence to proceed with implementation.
*
* Test Results (2025-10-21):
* - Precision: 1.000 (no false positives)
* - Recall: 1.000 (no false negatives)
* - 8/8 test cases passed
*/
export interface Context {
task?: string;
duplicate_check_complete?: boolean;
architecture_check_complete?: boolean;
official_docs_verified?: boolean;
oss_reference_complete?: boolean;
root_cause_identified?: boolean;
confidence_checks?: string[];
[key: string]: any;
}
/**
* Assess confidence level (0.0 - 1.0)
*
* Investigation Phase Checks:
* 1. No duplicate implementations? (25%)
* 2. Architecture compliance? (25%)
* 3. Official documentation verified? (20%)
* 4. Working OSS implementations referenced? (15%)
* 5. Root cause identified? (15%)
*
* @param context - Task context with investigation flags
* @returns Confidence score (0.0 = no confidence, 1.0 = absolute certainty)
*/
export async function confidenceCheck(context: Context): Promise<number> {
let score = 0.0;
const checks: string[] = [];
// Check 1: No duplicate implementations (25%)
if (noDuplicates(context)) {
score += 0.25;
checks.push("✅ No duplicate implementations found");
} else {
checks.push("❌ Check for existing implementations first");
}
// Check 2: Architecture compliance (25%)
if (architectureCompliant(context)) {
score += 0.25;
checks.push("✅ Uses existing tech stack (e.g., Supabase)");
} else {
checks.push("❌ Verify architecture compliance (avoid reinventing)");
}
// Check 3: Official documentation verified (20%)
if (hasOfficialDocs(context)) {
score += 0.2;
checks.push("✅ Official documentation verified");
} else {
checks.push("❌ Read official docs first");
}
// Check 4: Working OSS implementations referenced (15%)
if (hasOssReference(context)) {
score += 0.15;
checks.push("✅ Working OSS implementation found");
} else {
checks.push("❌ Search for OSS implementations");
}
// Check 5: Root cause identified (15%)
if (rootCauseIdentified(context)) {
score += 0.15;
checks.push("✅ Root cause identified");
} else {
checks.push("❌ Continue investigation to identify root cause");
}
// Store check results
context.confidence_checks = checks;
// Display checks
console.log("📋 Confidence Checks:");
checks.forEach(check => console.log(` ${check}`));
console.log("");
return score;
}
/**
* Check for duplicate implementations
*
* Before implementing, verify:
* - No existing similar functions/modules (Glob/Grep)
* - No helper functions that solve the same problem
* - No libraries that provide this functionality
*/
function noDuplicates(context: Context): boolean {
return context.duplicate_check_complete ?? false;
}
/**
* Check architecture compliance
*
* Verify solution uses existing tech stack:
* - Supabase project → Use Supabase APIs (not custom API)
* - Next.js project → Use Next.js patterns (not custom routing)
* - Turborepo → Use workspace patterns (not manual scripts)
*/
function architectureCompliant(context: Context): boolean {
return context.architecture_check_complete ?? false;
}
/**
* Check if official documentation verified
*
* For testing: uses context flag 'official_docs_verified'
* For production: checks for README.md, CLAUDE.md, docs/ directory
*/
function hasOfficialDocs(context: Context): boolean {
// Check context flag (for testing and runtime)
if ('official_docs_verified' in context) {
return context.official_docs_verified ?? false;
}
// Fallback: check for documentation files (production)
// This would require filesystem access in Node.js
return false;
}
/**
* Check if working OSS implementations referenced
*
* Search for:
* - Similar open-source solutions
* - Reference implementations in popular projects
* - Community best practices
*/
function hasOssReference(context: Context): boolean {
return context.oss_reference_complete ?? false;
}
/**
* Check if root cause is identified with high certainty
*
* Verify:
* - Problem source pinpointed (not guessing)
* - Solution addresses root cause (not symptoms)
* - Fix verified against official docs/OSS patterns
*/
function rootCauseIdentified(context: Context): boolean {
return context.root_cause_identified ?? false;
}
/**
* Get recommended action based on confidence level
*
* @param confidence - Confidence score (0.0 - 1.0)
* @returns Recommended action
*/
export function getRecommendation(confidence: number): string {
if (confidence >= 0.9) {
return "✅ High confidence (≥90%) - Proceed with implementation";
} else if (confidence >= 0.7) {
return "⚠️ Medium confidence (70-89%) - Continue investigation, DO NOT implement yet";
} else {
return "❌ Low confidence (<70%) - STOP and continue investigation loop";
}
}

159
pm/index.ts Normal file
View File

@@ -0,0 +1,159 @@
/**
* PM Agent - Project Manager with Confidence-Driven Workflow
*
* Auto-executes on session start via hooks/hooks.json
* Orchestrates sub-agents with 90% confidence threshold
*/
import { execSync } from 'child_process';
import { confidenceCheck } from './confidence';
interface SessionContext {
gitStatus: string;
tokenBudget: number;
projectRoot: string;
}
/**
* Session Start Protocol
* Auto-executes when Claude Code starts
*/
export async function sessionStart(): Promise<void> {
console.log("🚀 PM Agent activated");
// 1. Check git status
const gitStatus = checkGitStatus();
console.log(`📊 Git: ${gitStatus}`);
// 2. Token budget check (from Claude Code UI)
console.log("💡 Check token budget with /context");
// 3. Ready
console.log("✅ PM Agent ready to accept tasks");
console.log("");
console.log("**Core Capabilities**:");
console.log("- 🔍 Pre-implementation confidence check (≥90% required)");
console.log("- ⚡ Parallel investigation and execution");
console.log("- 📊 Token-budget-aware operations");
console.log("");
console.log("**Usage**: Assign tasks directly - PM Agent will orchestrate");
}
/**
* Check git repository status
*/
function checkGitStatus(): string {
try {
const status = execSync('git status --porcelain', { encoding: 'utf-8' });
if (!status.trim()) {
return 'clean';
}
const lines = status.trim().split('\n').length;
return `${lines} file(s) modified`;
} catch {
return 'not a git repo';
}
}
/**
* Main task handler
* Called when user assigns a task
*/
export async function handleTask(task: string): Promise<void> {
console.log(`📝 Task received: ${task}`);
console.log("");
// Start confidence-driven workflow
await confidenceDrivenWorkflow(task);
}
/**
* Confidence-Driven Workflow
*
* 1. Investigation phase (loop until 90% confident)
* 2. Confidence check
* 3. Implementation (only when ≥90%)
*/
async function confidenceDrivenWorkflow(task: string): Promise<void> {
let confidence = 0;
let iteration = 0;
const MAX_ITERATIONS = 10;
console.log("🔍 Starting investigation phase...");
console.log("");
while (confidence < 0.9 && iteration < MAX_ITERATIONS) {
iteration++;
console.log(`🔄 Investigation iteration ${iteration}...`);
// Investigation actions (delegated to sub-agents)
const context = await investigate(task);
// Self-evaluate confidence
confidence = await confidenceCheck(context);
console.log(`📊 Confidence: ${(confidence * 100).toFixed(0)}%`);
if (confidence < 0.9) {
console.log("⚠️ Confidence < 90% - Continue investigation");
console.log("");
}
}
if (confidence >= 0.9) {
console.log("✅ High confidence (≥90%) - Proceeding to implementation");
console.log("");
// Implementation phase
await implement(task);
} else {
console.log("❌ Max iterations reached - Request user clarification");
}
}
/**
* Investigation phase
* Delegates to sub-agents: research, index, grep, etc.
*/
async function investigate(task: string): Promise<any> {
// This will be orchestrated by Claude using:
// - /research for web research
// - /index-repo for codebase structure
// - Glob/Grep for code search
// - WebFetch for official docs
return {
task,
duplicate_check_complete: false,
architecture_check_complete: false,
official_docs_verified: false,
oss_reference_complete: false,
root_cause_identified: false
};
}
/**
* Implementation phase
* Only executed when confidence ≥ 90%
*/
async function implement(task: string): Promise<void> {
console.log(`🚀 Implementing: ${task}`);
// Actual implementation delegated to Claude
}
/**
* Memory Management (Mindbase MCP integration)
* Zero-footprint: No auto-load, explicit load/save only
*/
export const memory = {
load: async () => {
console.log("💾 Use /sc:load to load context from Mindbase MCP");
},
save: async () => {
console.log("💾 Use /sc:save to persist session to Mindbase MCP");
}
};
// Auto-execute on session start
if (require.main === module) {
sessionStart();
}

18
pm/package.json Normal file
View File

@@ -0,0 +1,18 @@
{
"name": "@pm-agent/core",
"version": "1.0.0",
"description": "PM Agent - Project Manager with 90% confidence checks",
"main": "index.ts",
"scripts": {
"test": "jest",
"build": "tsc"
},
"dependencies": {},
"devDependencies": {
"@types/node": "^20.0.0",
"typescript": "^5.0.0"
},
"engines": {
"node": ">=18.0.0"
}
}