feat: add /api and /resume commands for remote management#227
feat: add /api and /resume commands for remote management#227changqingyu wants to merge 2 commits into
Conversation
When Claude API quota is exhausted, users can now switch endpoints directly from Feishu without SSH access. Supports multiple saved configurations with connectivity validation and persistence. - `/api set <name> <url> <token>` adds/updates with auto-validation - `/api switch <name|index>` switches active config by name or index - `/api list` / `/api current` / `/api delete <name>` for management - New ApiConfigManager class persists to ~/.claude/metabot-apis.json - Auto-syncs active config to ~/.claude/settings.json env block - Injects ANTHROPIC_BASE_URL / ANTHROPIC_AUTH_TOKEN into Claude subprocess via createSpawnFn extraEnv parameter - Singleton pattern shared between executor and command handler - Retry logic (3 attempts) for first-time connection warmup Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
…ssions from Feishu
Users can now enumerate and resume local CLI sessions directly from
Feishu, continuing unfinished tasks with full conversation context.
Leverages the Agent SDK's listSessions() and query({ resume }) APIs.
- `/resume` lists recent sessions (title, branch, age, file size)
- `/resume <n>` resumes by index from the displayed list
- `/resume <id>` resumes by session ID prefix (8+ chars)
- ClaudeExecutor.listHistorySessions() wraps SDK listSessions()
- SessionManager.setSession() writes sessionId + workingDirectory
- CommandHandler caches session list per chat (5 min TTL)
- Validates original working directory, falls back to default
- Adds `session_resumed` audit event type
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Thanks for the substantial PR. A few observations from a triage pass — leaving as comments rather than approving since this adds two new top-level command surfaces and persists API credentials to disk:
Leaving final review to maintainers. |
|
Thanks for the contribution — both 1. Security: stop syncing tokens to
|
Summary
/apicommand: remotely switch Claude API endpoints from Feishu when quota is exhausted. Supports multiple saved configurations with connectivity validation and persistence (~/.claude/metabot-apis.json)./resumecommand: enumerate and resume local Claude Code CLI sessions from Feishu, continuing unfinished tasks with full conversation context via the Agent SDK'slistSessions()API.Changes
src/engines/claude/api-config-manager.ts— CRUD, validation, persistence for API configssrc/engines/claude/executor.ts— inject API config env vars into subprocess +listHistorySessions()static methodsrc/engines/claude/session-manager.ts—setSession()for restoring CLI sessionssrc/bridge/command-handler.ts—/apiand/resumecommand handlerssrc/engines/claude/index.ts+src/engines/index.ts— re-exportssrc/utils/audit-logger.ts—session_resumedevent typeTest plan
/api set test https://api.example.com sk-xxx— validates and saves/api list— shows saved configs with index/api switch 1— switches by index/api current— displays active config/api delete test— removes config/resume— lists local CLI sessions/resume 1— resumes first sessionnpm run buildpasses (excluding pre-existing kimi SDK issue)npm test— 207 tests pass🤖 Generated with Claude Code