feat: add ask_chatgpt tool handler

This commit is contained in:
2026-06-12 07:43:20 +01:00
parent 3f6eec38e2
commit 3eedcfa559
5 changed files with 486 additions and 3 deletions
+15
View File
@@ -299,6 +299,21 @@ All six prompt builders are implemented and tested:
- No OpenAI API calls from the builders.
- No file loading, logging, or context budget within the builders.
### Task 4.1 - ask_chatgpt MCP tool handler
Create `src/tools/ask-chatgpt.js` and `test/tools/ask-chatgpt.test.js`.
**Requirements:**
- Export `handleAskChatGpt(input, deps)` as standalone dependency-injected function.
- Execution order: validateToolInput → loadConfig → checkContextBudget → buildAskChatGptPrompt → createOpenAIClient → sendOpenAIResponse.
- Inject only 3 external deps: `loadConfig`, `createOpenAIClient`, `sendOpenAIResponse`. Internal utilities imported directly.
- If budget check fails (`ok: false`), immediately return that result — do not call buildAskChatGptPrompt or create client.
- All paths return structured `{ ok, answer|error, warnings }` — never throws to caller.
- OpenAI errors pass through `String(err)` unchanged (no wrapping/reformatting).
- 27 orchestration-only tests covering: success path, validation failure, config failure, budget failure, client creation failure, OpenAI failure, dependency call order, error handling for null/string throws, warning propagation, result shape, and short-circuit behavior.
Status: ✅ Complete
---
Phase 2 complete. Phase 3 complete. Phase 4 next: Tool Handlers.