# Implementation Plan: 簡化專案保留並優化Answer工具
**Branch**: `002-tools-answer` | **Date**: 2025-10-13 | **Spec**: [spec.md](spec.md)
**Input**: Feature specification from `/specs/002-tools-answer/spec.md`
**Note**: This template is filled in by the `/speckit.plan` command. See `.specify/templates/commands/plan.md` for the execution workflow.
## Summary
簡化OnCall Runbook MCP伺服器,移除所有非MCP工具(search, read, checklist, commands, handoff, postmortem),僅保留並優化rb.answer工具。優化焦點於提升答案準確性和相關性,保持LLM降級機制,提供基本搜尋結果和格式化引用。
## Technical Context
<!--
ACTION REQUIRED: Replace the content in this section with the technical details
for the project. The structure here is presented in advisory capacity to guide
the iteration process.
-->
**Language/Version**: Node.js 18+ (ESM)
**Primary Dependencies**: 無新增,維持現有架構
**Storage**: Markdown files (維持現有runbook格式)
**Testing**: 維持現有測試架構 (integration/unit tests)
**Target Platform**: Cross-platform (Windows, Linux, macOS)
**Project Type**: Single project (MCP server simplification)
**Performance Goals**: 3秒標準查詢,5秒複雜查詢,50%載入時間減少
**Constraints**: 離線優先,30%記憶體減少,保持API相容性
**Scale/Scope**: 減少系統複雜性,從7個工具簡化為1個核心工具
## Constitution Check
*GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.*
**P1: Source-of-Truth compliance** ✅ PASS
- No changes to frontmatter schema or required fields
- Maintains existing runbook format and citation system
**P2: Deterministic retrieval** ✅ PASS
- Scoring algorithm remains unchanged
- Only removes non-answer tools, core search logic preserved
**P3: Risk annotation impacts** ✅ PASS
- Risk classification system maintained in answer tool
- Command pattern extraction unchanged
**P4: Offline behavior defined** ✅ PASS
- Degraded output clearly defined: basic search results + formatted citations
- No LLM dependency for core functionality
**P5: Pure function coverage** ✅ PASS
- Existing unit tests for core functions maintained
- No new pure functions introduced, only removal of unused tools
- Target unit test files: core/*.spec.mjs, services/answer-*.spec.mjs maintained
**Performance Impact** ✅ PASS
- Expected 50% improvement in load time due to tool removal
- 30% memory reduction from simplified architecture
- Well within constitution performance targets
**Freshness handling** ✅ PASS
- No changes to threshold logic or freshness validation
- Maintains existing stale content warnings
## Project Structure
### Documentation (this feature)
```
specs/[###-feature]/
├── plan.md # This file (/speckit.plan command output)
├── research.md # Phase 0 output (/speckit.plan command)
├── data-model.md # Phase 1 output (/speckit.plan command)
├── quickstart.md # Phase 1 output (/speckit.plan command)
├── contracts/ # Phase 1 output (/speckit.plan command)
└── tasks.md # Phase 2 output (/speckit.tasks command - NOT created by /speckit.plan)
```
### Source Code (repository root)
```
src/
├── adapters/
│ ├── config.mjs # 保持不變
│ ├── fsio.mjs # 保持不變
│ └── llmAdapter.mjs # 保持不變
├── core/
│ ├── chunk.mjs # 保持不變
│ ├── constants.mjs # 保持不變
│ ├── freshness.mjs # 保持不變
│ ├── risk-classify.mjs # 保持不變
│ ├── risk-dictionary.json # 保持不變
│ ├── score.mjs # 保持不變
│ ├── severity.mjs # 保持不變
│ └── tokenize.mjs # 保持不變
├── mcp/
│ └── tools/
│ └── answer.mjs # 保留並優化
├── services/
│ ├── answerService.mjs # 保持不變
│ ├── checklistService.mjs # 保持不變(answer依賴)
│ ├── commandExtractService.mjs # 保持不變(answer依賴)
│ ├── indexer.mjs # 保持不變
│ └── searchService.mjs # 保持不變(answer依賴)
└── utils/
├── errors.mjs # 保持不變
├── logger.mjs # 保持不變
├── tokenizationCache.mjs # 保持不變
└── validation.mjs # 保持不變
tests/
├── integration/
│ ├── foundation.spec.mjs # 保持不變
│ ├── us2-answer-llm-off.spec.mjs # 保持不變
│ ├── us2-answer-llm-off.spec.mjs # 保持不變
│ └── us2-complete.spec.mjs # 保持不變
└── unit/
├── core/ # 保持不變
├── services/
│ ├── answer-aggregate.spec.mjs # 保持不變
│ ├── checklist.spec.mjs # 保持不變(answer依賴)
│ ├── citation-format.spec.mjs # 保持不變
│ └── commands-extract.spec.mjs # 保持不變(answer依賴)
└── utils/ # 保持不變
# 將被移除的檔案:
# src/mcp/tools/search.mjs ❌ 移除
# src/mcp/tools/read.mjs ❌ 移除
# src/mcp/tools/checklist.mjs ❌ 移除
# src/mcp/tools/commands.mjs ❌ 移除
# src/mcp/tools/handoff.mjs ❌ 移除
# src/mcp/tools/postmortem.mjs ❌ 移除
# src/services/handoffService.mjs ❌ 移除
# src/services/postmortemService.mjs ❌ 移除
# 相關的integration和unit測試 ❌ 移除
```
**Structure Decision**: 保持現有單一專案結構,移除非answer工具相關檔案。核心邏輯、適配器和answer工具依賴的服務保持不變,確保answer工具完整功能。主要變更為server.mjs中移除非答案工具的初始化和註冊。
## Complexity Tracking
*Fill ONLY if Constitution Check has violations that must be justified*
| Violation | Why Needed | Simpler Alternative Rejected Because |
|-----------|------------|-------------------------------------|
| [e.g., 4th project] | [current need] | [why 3 projects insufficient] |
| [e.g., Repository pattern] | [specific problem] | [why direct DB access insufficient] |