test(cli): batch 105 (25 files)

This commit is contained in:
YeonGyu-Kim
2026-05-30 19:12:48 +09:00
parent e9c9142afe
commit 93e1daed4e
28 changed files with 2835 additions and 457 deletions
@@ -1,305 +0,0 @@
export const INIT_DEEP_TEMPLATE = `# /init-deep
Generate hierarchical AGENTS.md files. Root + complexity-scored subdirectories.
## Usage
\`\`\`
/init-deep # Update mode: modify existing + create new where warranted
/init-deep --create-new # Read existing → remove all → regenerate from scratch
/init-deep --max-depth=2 # Limit directory depth (default: 3)
\`\`\`
---
## Workflow (High-Level)
1. **Discovery + Analysis** (concurrent)
- Fire background explore agents immediately
- Main session: bash structure + LSP codemap + read existing AGENTS.md
2. **Score & Decide** - Determine AGENTS.md locations from merged findings
3. **Generate** - Root first, then subdirs in parallel
4. **Review** - Deduplicate, trim, validate
<critical>
**TodoWrite ALL phases. Mark in_progress → completed in real-time.**
\`\`\`
TodoWrite([
{ id: "discovery", content: "Fire explore agents + LSP codemap + read existing", status: "pending", priority: "high" },
{ id: "scoring", content: "Score directories, determine locations", status: "pending", priority: "high" },
{ id: "generate", content: "Generate AGENTS.md files (root + subdirs)", status: "pending", priority: "high" },
{ id: "review", content: "Deduplicate, validate, trim", status: "pending", priority: "medium" }
])
\`\`\`
</critical>
---
## Phase 1: Discovery + Analysis (Concurrent)
**Mark "discovery" as in_progress.**
### Fire Background Explore Agents IMMEDIATELY
Don't wait-these run async while main session works.
\`\`\`
// Fire all at once, collect results later
task(subagent_type="explore", load_skills=[], description="Explore project structure", run_in_background=true, prompt="Project structure: PREDICT standard patterns for detected language → REPORT deviations only")
task(subagent_type="explore", load_skills=[], description="Find entry points", run_in_background=true, prompt="Entry points: FIND main files → REPORT non-standard organization")
task(subagent_type="explore", load_skills=[], description="Find conventions", run_in_background=true, prompt="Conventions: FIND config files (.eslintrc, pyproject.toml, .editorconfig) → REPORT project-specific rules")
task(subagent_type="explore", load_skills=[], description="Find anti-patterns", run_in_background=true, prompt="Anti-patterns: FIND 'DO NOT', 'NEVER', 'ALWAYS', 'DEPRECATED' comments → LIST forbidden patterns")
task(subagent_type="explore", load_skills=[], description="Explore build/CI", run_in_background=true, prompt="Build/CI: FIND .github/workflows, Makefile → REPORT non-standard patterns")
task(subagent_type="explore", load_skills=[], description="Find test patterns", run_in_background=true, prompt="Test patterns: FIND test configs, test structure → REPORT unique conventions")
\`\`\`
<dynamic-agents>
**DYNAMIC AGENT SPAWNING**: After bash analysis, spawn ADDITIONAL explore agents based on project scale:
| Factor | Threshold | Additional Agents |
|--------|-----------|-------------------|
| **Total files** | >100 | +1 per 100 files |
| **Total lines** | >10k | +1 per 10k lines |
| **Directory depth** | ≥4 | +2 for deep exploration |
| **Large files (>500 lines)** | >10 files | +1 for complexity hotspots |
| **Monorepo** | detected | +1 per package/workspace |
| **Multiple languages** | >1 | +1 per language |
\`\`\`bash
# Measure project scale first
total_files=$(find . -type f -not -path '*/node_modules/*' -not -path '*/.git/*' | wc -l)
total_lines=$(find . -type f \\( -name "*.ts" -o -name "*.py" -o -name "*.go" \\) -not -path '*/node_modules/*' -exec wc -l {} + 2>/dev/null | tail -1 | awk '{print $1}')
large_files=$(find . -type f \\( -name "*.ts" -o -name "*.py" \\) -not -path '*/node_modules/*' -exec wc -l {} + 2>/dev/null | awk '$1 > 500 {count++} END {print count+0}')
max_depth=$(find . -type d -not -path '*/node_modules/*' -not -path '*/.git/*' | awk -F/ '{print NF}' | sort -rn | head -1)
\`\`\`
Example spawning:
\`\`\`
// 500 files, 50k lines, depth 6, 15 large files → spawn 5+5+2+1 = 13 additional agents
task(subagent_type="explore", load_skills=[], description="Analyze large files", run_in_background=true, prompt="Large file analysis: FIND files >500 lines, REPORT complexity hotspots")
task(subagent_type="explore", load_skills=[], description="Explore deep modules", run_in_background=true, prompt="Deep modules at depth 4+: FIND hidden patterns, internal conventions")
task(subagent_type="explore", load_skills=[], description="Find shared utilities", run_in_background=true, prompt="Cross-cutting concerns: FIND shared utilities across directories")
// ... more based on calculation
\`\`\`
</dynamic-agents>
### Main Session: Concurrent Analysis
**While background agents run**, main session does:
#### 1. Bash Structural Analysis
\`\`\`bash
# Directory depth + file counts
find . -type d -not -path '*/\\.*' -not -path '*/node_modules/*' -not -path '*/venv/*' -not -path '*/dist/*' -not -path '*/build/*' | awk -F/ '{print NF-1}' | sort -n | uniq -c
# Files per directory (top 30)
find . -type f -not -path '*/\\.*' -not -path '*/node_modules/*' | sed 's|/[^/]*$||' | sort | uniq -c | sort -rn | head -30
# Code concentration by extension
find . -type f \\( -name "*.py" -o -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.go" -o -name "*.rs" \\) -not -path '*/node_modules/*' | sed 's|/[^/]*$||' | sort | uniq -c | sort -rn | head -20
# Existing AGENTS.md / CLAUDE.md
find . -type f \\( -name "AGENTS.md" -o -name "CLAUDE.md" \\) -not -path '*/node_modules/*' 2>/dev/null
\`\`\`
#### 2. Read Existing AGENTS.md
\`\`\`
For each existing file found:
Read(filePath=file)
Extract: key insights, conventions, anti-patterns
Store in EXISTING_AGENTS map
\`\`\`
If \`--create-new\`: Read all existing first (preserve context) → then delete all → regenerate.
#### 3. LSP Codemap (if available)
\`\`\`
LspServers() # Check availability
# Entry points (parallel)
LspDocumentSymbols(filePath="src/index.ts")
LspDocumentSymbols(filePath="main.py")
# Key symbols (parallel)
LspWorkspaceSymbols(filePath=".", query="class")
LspWorkspaceSymbols(filePath=".", query="interface")
LspWorkspaceSymbols(filePath=".", query="function")
# Centrality for top exports
LspFindReferences(filePath="...", line=X, character=Y)
\`\`\`
**LSP Fallback**: If unavailable, rely on explore agents + AST-grep.
### Collect Background Results
\`\`\`
// After main session analysis done, collect all task results
for each background task ID (\`bg_...\`): background_output(task_id="bg_...")
\`\`\`
**Merge: bash + LSP + existing + explore findings. Mark "discovery" as completed.**
---
## Phase 2: Scoring & Location Decision
**Mark "scoring" as in_progress.**
### Scoring Matrix
| Factor | Weight | High Threshold | Source |
|--------|--------|----------------|--------|
| File count | 3x | >20 | bash |
| Subdir count | 2x | >5 | bash |
| Code ratio | 2x | >70% | bash |
| Unique patterns | 1x | Has own config | explore |
| Module boundary | 2x | Has index.ts/__init__.py | bash |
| Symbol density | 2x | >30 symbols | LSP |
| Export count | 2x | >10 exports | LSP |
| Reference centrality | 3x | >20 refs | LSP |
### Decision Rules
| Score | Action |
|-------|--------|
| **Root (.)** | ALWAYS create |
| **>15** | Create AGENTS.md |
| **8-15** | Create if distinct domain |
| **<8** | Skip (parent covers) |
### Output
\`\`\`
AGENTS_LOCATIONS = [
{ path: ".", type: "root" },
{ path: "src/hooks", score: 18, reason: "high complexity" },
{ path: "src/api", score: 12, reason: "distinct domain" }
]
\`\`\`
**Mark "scoring" as completed.**
---
## Phase 3: Generate AGENTS.md
**Mark "generate" as in_progress.**
<critical>
**File Writing Rule**: If AGENTS.md already exists at the target path → use \`Edit\` tool. If it does NOT exist → use \`Write\` tool.
NEVER use Write to overwrite an existing file. ALWAYS check existence first via \`Read\` or discovery results.
</critical>
### Root AGENTS.md (Full Treatment)
\`\`\`markdown
# PROJECT KNOWLEDGE BASE
**Generated:** {TIMESTAMP}
**Commit:** {SHORT_SHA}
**Branch:** {BRANCH}
## OVERVIEW
{1-2 sentences: what + core stack}
## STRUCTURE
\\\`\\\`\\\`
{root}/
├── {dir}/ # {non-obvious purpose only}
└── {entry}
\\\`\\\`\\\`
## WHERE TO LOOK
| Task | Location | Notes |
|------|----------|-------|
## CODE MAP
{From LSP - skip if unavailable or project <10 files}
| Symbol | Type | Location | Refs | Role |
|--------|------|----------|------|------|
## CONVENTIONS
{ONLY deviations from standard}
## ANTI-PATTERNS (THIS PROJECT)
{Explicitly forbidden here}
## UNIQUE STYLES
{Project-specific}
## COMMANDS
\\\`\\\`\\\`bash
{dev/test/build}
\\\`\\\`\\\`
## NOTES
{Gotchas}
\`\`\`
**Quality gates**: 50-150 lines, no generic advice, no obvious info.
### Subdirectory AGENTS.md (Parallel)
Launch writing tasks for each location:
\`\`\`
for loc in AGENTS_LOCATIONS (except root):
task(category="writing", load_skills=[], run_in_background=false, description="Generate AGENTS.md", prompt=\\\`
Generate AGENTS.md for: \${loc.path}
- Reason: \${loc.reason}
- 30-80 lines max
- NEVER repeat parent content
- Sections: OVERVIEW (1 line), STRUCTURE (if >5 subdirs), WHERE TO LOOK, CONVENTIONS (if different), ANTI-PATTERNS
\\\`)
\`\`\`
**Wait for all. Mark "generate" as completed.**
---
## Phase 4: Review & Deduplicate
**Mark "review" as in_progress.**
For each generated file:
- Remove generic advice
- Remove parent duplicates
- Trim to size limits
- Verify telegraphic style
**Mark "review" as completed.**
---
## Final Report
\`\`\`
=== init-deep Complete ===
Mode: {update | create-new}
Files:
[OK] ./AGENTS.md (root, {N} lines)
[OK] ./src/hooks/AGENTS.md ({N} lines)
Dirs Analyzed: {N}
AGENTS.md Created: {N}
AGENTS.md Updated: {N}
Hierarchy:
./AGENTS.md
└── src/hooks/AGENTS.md
\`\`\`
---
## Anti-Patterns
- **Static agent count**: MUST vary agents based on project size/depth
- **Sequential execution**: MUST parallel (explore + LSP concurrent)
- **Ignoring existing**: ALWAYS read existing first, even with --create-new
- **Over-documenting**: Not every dir needs AGENTS.md
- **Redundancy**: Child never repeats parent
- **Generic content**: Remove anything that applies to ALL projects
- **Verbose style**: Telegraphic or die`
@@ -1,145 +0,0 @@
import type { BuiltinSkill } from "../types"
export const aiSlopRemoverSkill: BuiltinSkill = {
name: "ai-slop-remover",
description:
"Removes AI-generated code smells from a SINGLE file while preserving functionality. For multiple files, call in PARALLEL per file.",
template: `You are an expert code refactorer specializing in removing AI-generated "slop" patterns while STRICTLY preserving functionality.
**INPUT**: Exactly ONE file path. If multiple paths provided, REJECT and instruct to call this agent in parallel.
---
## DETECTION CRITERIA (Specific)
### 1. Obvious Comments (EXCLUDE: BDD comments like #given, #when, #then, #when/then)
**REMOVE**:
- Comments restating the code: \`x += 1 # increment x\`
- Docstrings on trivial methods: \`"""Returns the name."""\` for \`def get_name(): return self.name\`
- Section dividers: \`# ===== HELPER FUNCTIONS =====\`
- Commented-out code blocks
- \`# TODO: future enhancement\` without concrete plan
- \`# Note: this is important\` without explaining WHY
**KEEP**:
- Comments explaining WHY (business logic, edge cases, workarounds)
- Links to issues/tickets: \`# See SPR-1234\`
- Non-obvious algorithm explanations
- Regex explanations
- Matches to existing code style
### 2. Over-Defensive Code
**REMOVE**:
- Null checks for values that CANNOT be None (e.g., Django request in view)
- \`if x is not None and x.attr is not None:\` when x is guaranteed
- Try-except around code that can't raise (e.g., dict literal access)
- \`isinstance()\` checks for statically typed parameters
- Default values for required parameters: \`def foo(x: str = "")\` when empty string is invalid
- Backward-compat shims: \`_old_name = new_name # deprecated\`
- \`# removed\` or \`# deleted\` comments for removed code
- Re-exports of unused items
- Verbose, duplicated, or redundant code / test cases
**KEEP**:
- Validation at system boundaries (user input, external API responses)
- Error handling for I/O operations
- Null checks for nullable DB fields
- assertions in test code to matching type expectations
### 3. Spaghetti Nesting (2+ levels deep)
**REFACTOR**:
- Nested if-else chains -> early returns / guard clauses
- \`if x: if y: if z:\` -> \`if not x: return\` / \`if not y: return\`
- Nested loops with conditionals -> extract to helper OR use comprehensions
- Complex ternary \`a if b else (c if d else e)\` -> explicit if-else
---
## PROCESS
### Step 1: Read & Analyze
Read the file. Identify ALL slop instances with line numbers.
### Step 2: Deep Consideration (CRITICAL)
For EACH identified issue, think:
- **Functionality Impact**: Will removing this change behavior? If ANY doubt, SKIP.
- **Test Coverage**: Are there tests that might break? If uncertain, SKIP.
- **Context Dependency**: Is this "slop" actually necessary for this specific codebase? (e.g., defensive code for known flaky external API)
- **Readability Trade-off**: Will removal make code LESS readable? If yes, SKIP.
**RULE**: When in doubt, DO NOT CHANGE. False negatives are better than breaking code.
### Step 3: Execute Changes
Make changes using Edit tool. One logical change at a time.
### Step 4: Detailed Report
**OUTPUT FORMAT**:
\`\`\`
## AI Slop Removed: {filename}
### Analysis Summary
- Total issues found: N
- Issues fixed: M
- Issues skipped (safety): K
### Changes Made
#### Change 1: [Category] Line X-Y
**Before**: [original code snippet]
**After**: [modified code snippet]
**Why this is slop**: [Explain why this pattern is problematic]
**Why safe to remove**: [Explain why functionality is preserved]
**Impact**: None - purely cosmetic improvement
---
### Skipped Issues (Preserved for Safety)
#### Skipped 1: Line X
**Reason**: [Why you chose not to change this]
### Summary
- Removed N obvious comments
- Simplified M defensive patterns
- Flattened K nested structures
- Preserved L patterns that looked like slop but serve purpose
\`\`\`
---
## SAFETY RULES
1. **NEVER remove error handling for I/O, network, or file operations**
2. **NEVER simplify validation for user input or external data**
3. **NEVER change public API signatures**
4. **NEVER remove type hints (even redundant-looking ones)**
5. **If a pattern appears in multiple places, it might be intentional - ASK before bulk removal**
6. **Preserve all BDD test comments (#given, #when, #then)**
When finished, your report should be detailed enough that a reviewer can understand EXACTLY what changed and feel confident the changes are safe.
---
## WHEN NO SLOP FOUND
If the file is clean, report:
\`\`\`
## AI Slop Analysis: {filename}
### Result: No AI Slop Detected
This file is clean. Here's why:
**Comments**: N comments found, all explain WHY not WHAT
**Defensive Code**: Null checks present are appropriate (e.g., checks external API response)
**Code Structure**: Maximum nesting depth acceptable, early returns used appropriately
**Conclusion**: This code appears to be human-written or well-reviewed AI code. No changes needed.
\`\`\``,
}