fix: smart enhancement dispatcher — Gemini/API mode + root/Docker detection

Fixes issues #289 and #286 (agent switching and Docker/root failures).

enhance_command.py (new smart dispatcher):
- Routes skill-seekers enhance to API mode (Gemini/OpenAI/Claude API)
  when an API key is available, or LOCAL mode (Claude Code CLI) otherwise
- Decision priority: --target flag > config default_agent > auto-detect
  from env vars (ANTHROPIC_API_KEY → claude, GOOGLE_API_KEY → gemini,
  OPENAI_API_KEY → openai) > LOCAL fallback
- Blocks LOCAL mode when running as root (Docker/VPS) with clear error
  message + API mode instructions
- Supports --dry-run, --target, --api-key as first-class flags

arguments/enhance.py:
- Added --target, --api-key, --dry-run, --interactive-enhancement to
  ENHANCE_ARGUMENTS (shared by unified CLI parser and standalone entry point)

enhance_skill_local.py:
- Error output no longer truncated at 200 chars (shows up to 20 lines)
- Detects root/permission errors in stderr and prints actionable hint

config_manager.py:
- Added default_agent field to DEFAULT_CONFIG ai_enhancement section
- Added get_default_agent() and set_default_agent() methods

main.py:
- enhance command routed to enhance_command (was enhance_skill_local)
- _handle_analyze_command uses smart dispatcher for post-analysis enhancement

pyproject.toml:
- skill-seekers-enhance entry point updated to enhance_command:main

Tests: 1977 passed, 0 failed (28 new tests in test_enhance_command.py)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
yusyus
2026-02-22 01:26:19 +03:00
parent 2e2941e0d4
commit fee89d5897
8 changed files with 750 additions and 13 deletions

View File

@@ -889,7 +889,22 @@ rm {prompt_file}
else:
print(f"{self.agent_display} returned error (exit code: {result.returncode})")
if result.stderr:
print(f" Error: {result.stderr[:200]}")
stderr_lines = result.stderr.strip().split("\n")
for line in stderr_lines[:20]:
print(f" | {line}")
if len(stderr_lines) > 20:
print(f" ... ({len(stderr_lines) - 20} more lines)")
# Hint for root/permission errors
stderr_lower = result.stderr.lower()
if result.returncode in (1, 126) and (
"root" in stderr_lower or "permission" in stderr_lower
):
print()
print(" ⚠️ This looks like a root/permission error.")
print(" Claude Code CLI refuses to run as root (security policy).")
print(" Use API mode instead:")
print(" export ANTHROPIC_API_KEY=sk-ant-...")
print(f" skill-seekers enhance {self.skill_dir} --target claude")
return False
except subprocess.TimeoutExpired: