# Tasks: 簡化專案保留並優化Answer工具
**Input**: Design documents from `/specs/002-tools-answer/`
**Prerequisites**: plan.md (required), spec.md (required for user stories), research.md, data-model.md, contracts/
**Tests**: Tests are not explicitly requested in the specification, focusing on implementation tasks.
**Organization**: Tasks are grouped by user story to enable independent implementation and testing of each story.
## Format: `[ID] [P?] [Story] Description`
- **[P]**: Can run in parallel (different files, no dependencies)
- **[Story]**: Which user story this task belongs to (e.g., US1, US2, US3)
- Include exact file paths in descriptions
## Path Conventions
- **Single project**: `src/`, `tests/` at repository root
- Based on plan.md structure: Node.js 18+ (ESM) single project
## Phase 1: Setup (Shared Infrastructure)
**Purpose**: Project initialization and tool cleanup preparation
- [x] T001 Create backup of current server.mjs as server.mjs.backup
- [x] T002 [P] Document current tool list and verify current functionality works
- [x] T003 [P] Setup performance baseline measurement for load time and memory usage
---
## Phase 2: Foundational (Blocking Prerequisites)
**Purpose**: Core preparation that MUST be complete before ANY user story can be implemented
**⚠️ CRITICAL**: No user story work can begin until this phase is complete
- [x] T004 Analyze dependencies of answer tool to identify required services
- [x] T005 [P] Verify answerService.mjs dependencies (searchService, checklistService, commandExtractService)
- [x] T006 [P] Verify core modules are intact (chunk.mjs, score.mjs, risk-classify.mjs, etc.)
- [x] T007 Create removal plan mapping for non-answer tools and their test files
- [x] T008 Setup monitoring infrastructure for query matching rate tracking
**Checkpoint**: Foundation ready - user story implementation can now begin in parallel
---
## Phase 3: User Story 1 - 精簡工具集(僅保留Answer) (Priority: P1) 🎯 MVP
**Goal**: Remove all non-answer MCP tools while preserving answer functionality
**Independent Test**: Start MCP server and verify only rb.answer tool is available, all other tools return "tool not found" errors
### Implementation for User Story 1
- [x] T009 [P] [US1] Remove src/mcp/tools/search.mjs
- [x] T010 [P] [US1] Remove src/mcp/tools/read.mjs
- [x] T011 [P] [US1] Remove src/mcp/tools/checklist.mjs
- [x] T012 [P] [US1] Remove src/mcp/tools/commands.mjs
- [x] T013 [P] [US1] Remove src/mcp/tools/handoff.mjs
- [x] T014 [P] [US1] Remove src/mcp/tools/postmortem.mjs
- [x] T015 [P] [US1] Remove src/services/handoffService.mjs
- [x] T016 [P] [US1] Remove src/services/postmortemService.mjs
- [x] T017 [US1] Update server.mjs to remove non-answer tool imports and registrations
- [x] T018 [US1] Remove tool creation calls for search, read, checklist, commands, handoff, postmortem from server.mjs
- [x] T019 [P] [US1] Remove tests/integration/us1-search-basic.spec.mjs
- [x] T020 [P] [US1] Remove tests/integration/us1-tools.spec.mjs (if contains non-answer tools)
- [x] T021 [P] [US1] Remove tests/integration/us3-tools.spec.mjs
- [x] T022 [P] [US1] Remove tests/unit/services/handoff.spec.mjs
- [x] T023 [P] [US1] Remove tests/unit/services/postmortem.spec.mjs
- [x] T024 [US1] Update server.mjs error handling to only initialize answer-related services
- [x] T025 [US1] Verify answer tool functionality is preserved after removals
**Checkpoint**: At this point, only rb.answer tool should be available and fully functional
---
## Phase 4: User Story 2 - 增強問答體驗 (Priority: P1)
**Goal**: Improve answer quality with better accuracy and relevance focusing on question intent matching
**Independent Test**: Input same questions and compare answer quality, format clarity and citation accuracy before/after optimization
### Implementation for User Story 2
- [x] T026 [P] [US2] Enhance src/services/answerService.mjs to improve question intent understanding
- [x] T027 [P] [US2] Optimize src/core/score.mjs to prioritize accuracy and relevance over speed
- [x] T028 [US2] Update answerService.mjs to implement clarification suggestions for ambiguous questions
- [x] T029 [US2] Enhance multi-source integration in answerService.mjs with source priority indication
- [x] T030 [US2] Improve structured step presentation in answer responses
- [x] T031 [US2] Add better risk warning formatting in src/mcp/tools/answer.mjs
- [x] T032 [US2] Implement no-results handling with search suggestions in answerService.mjs
- [x] T033 [US2] Enhance citation relevance scoring in searchService.mjs for better source selection
- [x] T034 [US2] Add query matching rate tracking to src/mcp/tools/answer.mjs logger calls
**Checkpoint**: Answer quality should be significantly improved with better question understanding and responses
---
## Phase 5: User Story 3 - 改善回應格式與可讀性 (Priority: P2)
**Goal**: Improve answer response formatting for better readability and structure
**Independent Test**: Send different types of questions and verify answer format consistency and readability
### Implementation for User Story 3
- [x] T035 [P] [US3] Enhance answer response structure in src/mcp/tools/answer.mjs for consistent formatting
- [x] T036 [P] [US3] Improve risk operation highlighting and rollback procedure reminders in response formatting
- [x] T037 [US3] Add clear step numbering and validation points for multi-step procedures
- [x] T038 [US3] Enhance summary section clarity in LLM-generated responses
- [x] T039 [US3] Improve metadata presentation for better user understanding
- [x] T040 [US3] Add structured headings and sections to answer output format
- [x] T041 [US3] Optimize offline mode message formatting for better user guidance
**Checkpoint**: All answer responses should have consistent, clear, and well-structured formatting
---
## Phase 6: User Story 4 - 效能優化與響應速度 (Priority: P3)
**Goal**: Improve answer tool response speed especially for emergency situations
**Independent Test**: Execute same queries multiple times and measure average response time and 95th percentile response times
### Implementation for User Story 4
- [x] T042 [P] [US4] Optimize query processing pipeline in answerService.mjs for standard queries
- [x] T043 [P] [US4] Implement query caching optimization for frequently asked questions
- [x] T044 [US4] Add response time prioritization logic favoring standard queries over complex ones
- [x] T045 [US4] Optimize index loading and search algorithms in searchService.mjs
- [x] T046 [US4] Implement connection pooling and resource management for concurrent queries
- [x] T047 [US4] Add performance monitoring and alerting for response time tracking
- [x] T048 [US4] Optimize memory usage patterns in core processing functions
- [x] T049 [US4] Implement graceful degradation under high load conditions
**Checkpoint**: All response time targets should be consistently met with stable performance
---
## Phase 7: Polish & Cross-Cutting Concerns
**Purpose**: Improvements that affect multiple user stories and final integration
- [ ] T050 [P] Update README.md to reflect simplified tool set and new capabilities
- [ ] T051 [P] Update quickstart.md with new usage examples and migration guide
- [ ] T052 [P] Validate all clarification requirements are implemented correctly
- [ ] T053 [P] Verify all success criteria measurements are achievable
- [ ] T054 Performance benchmarking to confirm 50% load time reduction and 30% memory reduction
- [ ] T055 [P] Update package.json scripts and documentation as needed
- [ ] T056 API compatibility validation ensuring no breaking changes to answer tool interface
- [ ] T057 Run integration tests to ensure answer tool works in all specified modes (online/offline/degraded)
---
## Dependencies & Execution Order
### Phase Dependencies
- **Setup (Phase 1)**: No dependencies - can start immediately
- **Foundational (Phase 2)**: Depends on Setup completion - BLOCKS all user stories
- **User Stories (Phase 3-6)**: All depend on Foundational phase completion
- User stories can then proceed in priority order (US1 → US2 → US3 → US4)
- US1 must complete before others due to tool removal dependencies
- **Polish (Phase 7)**: Depends on all user stories being complete
### User Story Dependencies
- **User Story 1 (P1)**: Must complete FIRST - removes tools and modifies server structure
- **User Story 2 (P1)**: Depends on US1 completion - enhances remaining answer tool
- **User Story 3 (P2)**: Depends on US2 completion - formats enhanced answers
- **User Story 4 (P3)**: Depends on US1-3 completion - optimizes final functionality
### Within Each User Story
- File removals marked [P] can run in parallel within US1
- Service enhancements can run in parallel where they affect different files
- Server.mjs changes must be sequential to avoid conflicts
- Testing and validation tasks should run after implementation tasks
### Parallel Opportunities
- All Setup tasks marked [P] can run in parallel
- All Foundational tasks marked [P] can run in parallel (within Phase 2)
- File removal tasks in US1 can run in parallel
- Enhancement tasks affecting different files can run in parallel within US2-4
- Documentation and validation tasks can run in parallel in Polish phase
---
## Parallel Example: User Story 1
```bash
# Launch all file removals together:
Task: "Remove src/mcp/tools/search.mjs"
Task: "Remove src/mcp/tools/read.mjs"
Task: "Remove src/mcp/tools/checklist.mjs"
Task: "Remove src/mcp/tools/commands.mjs"
Task: "Remove src/mcp/tools/handoff.mjs"
Task: "Remove src/mcp/tools/postmortem.mjs"
Task: "Remove src/services/handoffService.mjs"
Task: "Remove src/services/postmortemService.mjs"
# Launch all test file removals together:
Task: "Remove tests/integration/us1-search-basic.spec.mjs"
Task: "Remove tests/integration/us3-tools.spec.mjs"
Task: "Remove tests/unit/services/handoff.spec.mjs"
Task: "Remove tests/unit/services/postmortem.spec.mjs"
```
---
## Implementation Strategy
### MVP First (User Story 1 Only)
1. Complete Phase 1: Setup
2. Complete Phase 2: Foundational (CRITICAL - blocks all stories)
3. Complete Phase 3: User Story 1 (tool removal)
4. **STOP and VALIDATE**: Test that only rb.answer works
5. Measure performance improvements (load time, memory usage)
### Incremental Delivery
1. Complete Setup + Foundational → Foundation ready
2. Add User Story 1 → Test tool removal → Deploy/Demo (Simplified system!)
3. Add User Story 2 → Test answer improvements → Deploy/Demo
4. Add User Story 3 → Test formatting improvements → Deploy/Demo
5. Add User Story 4 → Test performance improvements → Deploy/Demo
6. Each story adds value while maintaining system stability
### Sequential Strategy (Recommended)
Due to interdependencies, implement user stories sequentially:
1. Team completes Setup + Foundational together
2. Complete US1 (tool removal) - REQUIRED FIRST
3. Complete US2 (answer enhancement) - builds on simplified system
4. Complete US3 (formatting) - enhances improved answers
5. Complete US4 (performance) - optimizes complete system
---
## Notes
- [P] tasks = different files, no dependencies
- [Story] label maps task to specific user story for traceability
- US1 must complete first due to structural changes
- Preserve all answer tool functionality during removals
- Monitor performance improvements at each phase
- Validate API compatibility throughout implementation
- Commit after each task or logical group for rollback capability
- US1 is the critical MVP - system is functional after this phase