# AI Code Inspection Guide - Whale Town Game Server ## โš ๏ธ ๐Ÿšจ CRITICAL: MANDATORY PRE-EXECUTION REQUIREMENTS ๐Ÿšจ โš ๏ธ **๏ฟฝ AI MUST READ THIS SECTION FIRST - EXECUTION WITHOUT COMPLETING THESE STEPS IS STRICTLY FORBIDDEN ๐Ÿ”ด** **โ›” STOP! Before executing ANY step (including Step 1), you MUST complete ALL items in this section! โ›”** --- ## ๐ŸŽฏ Pre-execution Setup (MANDATORY - CANNOT BE SKIPPED) ### ๐Ÿš€ User Information Setup (STEP 0 - MUST EXECUTE FIRST) **โš ๏ธ CRITICAL: Before starting any inspection steps (including Step 1), MUST run the user information script:** ```bash # Enter AI-reading directory cd docs/ai-reading # Run user information setup script node tools/setup-user-info.js ``` **๐Ÿšจ VERIFICATION CHECKPOINT:** - [ ] Have you executed `node tools/setup-user-info.js`? - [ ] Does `docs/ai-reading/me.config.json` file exist? - [ ] Have you read and confirmed the user's date and name from the config file? **โ›” IF ANY CHECKBOX ABOVE IS UNCHECKED, YOU CANNOT PROCEED TO STEP 1! โ›”** #### Script Functions - Automatically get current date (YYYY-MM-DD format) - Check if config file exists or date matches - Prompt for username/nickname input if needed - Save to `me.config.json` file for AI inspection steps #### Config File Format ```json { "date": "2026-01-13", "name": "Developer Name" } ``` ### ๐Ÿ“‹ Using Config in AI Inspection Steps When AI executes inspection steps, get user info from config file: ```javascript // Read config file const fs = require('fs'); const config = JSON.parse(fs.readFileSync('docs/ai-reading/me.config.json', 'utf-8')); // Get user information const userDate = config.date; // e.g.: "2026-01-13" const userName = config.name; // e.g.: "John" // Use for modification records and @author fields const modifyRecord = `- ${userDate}: Code standard optimization - Clean unused imports (Modified by: ${userName})`; ``` ### ๐Ÿ—๏ธ Project Characteristics (MUST UNDERSTAND BEFORE STEP 1) **โš ๏ธ AI MUST read and understand these characteristics BEFORE executing Step 1:** This project is a **NestJS Game Server** with the following features: - **Dual-mode Architecture**: Supports both database and memory modes - **Real-time Communication**: WebSocket-based real-time bidirectional communication - **Property Testing**: Admin modules use fast-check for randomized testing - **Layered Architecture**: Core layer (technical implementation) + Business layer (business logic) **๐Ÿšจ VERIFICATION CHECKPOINT:** - [ ] Have you read and understood the project is a NestJS Game Server? - [ ] Have you understood the dual-mode architecture? - [ ] Have you understood the WebSocket real-time communication feature? - [ ] Have you understood the property testing requirements? - [ ] Have you understood the layered architecture? **โ›” IF ANY CHECKBOX ABOVE IS UNCHECKED, YOU CANNOT PROCEED TO STEP 1! โ›”** --- ## ๐Ÿšจ FINAL PRE-EXECUTION CHECKLIST (MUST COMPLETE BEFORE STEP 1) ๐Ÿšจ **Before proceeding to Step 1, AI MUST confirm ALL of the following:** ### โœ… Mandatory Completion Checklist: - [ ] โœ… Executed `node tools/setup-user-info.js` script - [ ] โœ… Confirmed `me.config.json` file exists and contains valid date and name - [ ] โœ… Read and stored user's date from config file - [ ] โœ… Read and stored user's name from config file - [ ] โœ… Understood this is a NestJS Game Server project - [ ] โœ… Understood the dual-mode architecture (database + memory) - [ ] โœ… Understood the WebSocket real-time communication feature - [ ] โœ… Understood the property testing requirements - [ ] โœ… Understood the layered architecture (Core + Business) - [ ] โœ… Read and understood the execution principles below ### ๐Ÿ”ด CRITICAL RULE: **IF ANY ITEM IN THE CHECKLIST ABOVE IS NOT COMPLETED, AI IS ABSOLUTELY FORBIDDEN FROM EXECUTING STEP 1 OR ANY OTHER STEPS!** **AI MUST explicitly confirm completion of ALL checklist items before proceeding to Step 1!** --- ## ๐Ÿ”„ Execution Principles ### ๐Ÿšจ Mid-step Start Requirements (Important) **If AI starts execution from any intermediate step (not starting from step 1), must first complete the following preparation:** #### ๐Ÿ“‹ Mandatory Information Collection Before executing any intermediate step, AI must: 1. **Collect user current date**: For modification records and timestamp updates 2. **Collect user name**: For @author field handling and modification records 3. **Confirm project characteristics**: Identify NestJS game server project features #### ๐Ÿ” Global Context Acquisition AI must first understand: - **Project Architecture**: Dual-mode architecture (database+memory), layered structure (Core+Business) - **Tech Stack**: NestJS, WebSocket, Jest testing, fast-check property testing - **File Structure**: Overall file organization of current project - **Existing Standards**: Established naming, commenting, testing standards in project #### ๐ŸŽฏ Execution Flow Constraints ``` Mid-step Start Request โ†“ ๐Ÿšจ Mandatory User Info Collection (date, name) โ†“ ๐Ÿšจ Mandatory Project Characteristics & Context Identification โ†“ ๐Ÿšจ Mandatory Understanding of Target Step Requirements โ†“ Start Executing Specified Step ``` **โš ๏ธ Violation Handling: If AI skips information collection and directly executes intermediate steps, user should require AI to restart and complete preparation work.** ### โš ๏ธ Mandatory Requirements - **Step-by-step Execution**: Execute one step at a time, strictly no step skipping or merging - **Wait for Confirmation**: Must wait for user confirmation after each step before proceeding - **Modification Verification**: Must re-execute current step after any file modification - **๐Ÿ”ฅ Must Re-execute Current Step After Modification**: If any modification behavior occurs during current step (file modification, renaming, moving, etc.), AI must immediately re-execute the complete check of that step, cannot directly proceed to next step - **Re-check After Problem Fix**: If current step has problems requiring modification, AI must re-execute the step after solving problems to ensure no other issues are missed - **User Info Usage**: All date fields use user-provided real dates, @author fields handled correctly ### ๐ŸŽฏ Execution Flow ``` User Requests Code Inspection โ†“ ๐Ÿšจ MANDATORY: Execute node tools/setup-user-info.js โ†“ ๐Ÿšจ MANDATORY: Verify me.config.json exists โ†“ ๐Ÿšจ MANDATORY: Read and Store User Info (date, name) โ†“ ๐Ÿšจ MANDATORY: Understand Project Characteristics โ†“ ๐Ÿšจ MANDATORY: Complete Pre-execution Checklist โ†“ ๐Ÿšจ MANDATORY: Explicitly Confirm ALL Checklist Items Completed โ†“ โ›” CHECKPOINT: Cannot proceed without completing above steps โ›” โ†“ Execute Step 1 โ†’ Provide Report โ†’ Wait for Confirmation โ†“ [If Modification Occurs] โ†’ ๐Ÿ”ฅ Immediately Re-execute Step 1 โ†’ Verification Report โ†’ Wait for Confirmation โ†“ Execute Step 2 โ†’ Provide Report โ†’ Wait for Confirmation โ†“ [If Modification Occurs] โ†’ ๐Ÿ”ฅ Immediately Re-execute Step 2 โ†’ Verification Report โ†’ Wait for Confirmation โ†“ Execute Step 3 โ†’ Provide Report โ†’ Wait for Confirmation โ†“ [If Modification Occurs] โ†’ ๐Ÿ”ฅ Immediately Re-execute Step 3 โ†’ Verification Report โ†’ Wait for Confirmation โ†“ Execute Step 4 โ†’ Provide Report โ†’ Wait for Confirmation โ†“ [If Modification Occurs] โ†’ ๐Ÿ”ฅ Immediately Re-execute Step 4 โ†’ Verification Report โ†’ Wait for Confirmation โ†“ Execute Step 5 โ†’ Provide Report โ†’ Wait for Confirmation โ†“ [If Modification Occurs] โ†’ ๐Ÿ”ฅ Immediately Re-execute Step 5 โ†’ Verification Report โ†’ Wait for Confirmation โ†“ Execute Step 6 โ†’ Provide Report โ†’ Wait for Confirmation โ†“ [If Modification Occurs] โ†’ ๐Ÿ”ฅ Immediately Re-execute Step 6 โ†’ Verification Report โ†’ Wait for Confirmation โ†“ Execute Step 7 โ†’ Provide Report โ†’ Wait for Confirmation โ†“ [If Modification Occurs] โ†’ ๐Ÿ”ฅ Immediately Re-execute Step 7 โ†’ Verification Report โ†’ Wait for Confirmation โš ๏ธ Key Rule: After any modification behavior in any step, must immediately re-execute that step! ``` ## ๐Ÿ“š Step Execution Guide **๐Ÿšจ REMINDER: Before executing Step 1, ensure you have completed ALL items in the "FINAL PRE-EXECUTION CHECKLIST" above! ๐Ÿšจ** ### Step 1: Naming Convention Check **โš ๏ธ BEFORE STARTING STEP 1, AI MUST:** 1. โœ… Confirm `node tools/setup-user-info.js` has been executed 2. โœ… Confirm user date and name have been read from `me.config.json` 3. โœ… Confirm project characteristics have been understood 4. โœ… Explicitly state: "Pre-execution checklist completed, now starting Step 1" **ONLY AFTER EXPLICIT CONFIRMATION CAN STEP 1 BEGIN!** --- **Read when executing:** `step1-naming-convention.md` **Focus on:** Folder structure flattening, game server special file types **After completion:** Provide inspection report, wait for user confirmation ### Step 2: Comment Standard Check **Read when executing:** `step2-comment-standard.md` **Focus on:** @author field handling, modification record updates, timestamp rules **After completion:** Provide inspection report, wait for user confirmation ### Step 3: Code Quality Check **Read when executing:** `step3-code-quality.md` **Focus on:** TODO item handling, unused code cleanup **After completion:** Provide inspection report, wait for user confirmation ### Step 4: Architecture Layer Check **Read when executing:** `step4-architecture-layer.md` **Focus on:** Core layer naming standards, dependency relationship checks **After completion:** Provide inspection report, wait for user confirmation ### Step 5: Test Coverage Check **Read when executing:** `step5-test-coverage.md` **Focus on:** Strict one-to-one test mapping, test file locations, test execution verification **After completion:** Provide inspection report, wait for user confirmation #### ๐Ÿงช Test File Debugging Standards **When debugging test files, must follow this workflow:** 1. **Read jest.config.js Configuration** - Check jest.config.js to understand test environment configuration - Confirm testRegex patterns and file matching rules - Understand moduleNameMapper and other configuration items 2. **Use Existing Test Commands in package.json** - **Forbidden to customize jest commands**: Must use test commands defined in package.json scripts - **Common Test Commands**: - `npm run test` - Run all tests - `npm run test:unit` - Run unit tests (.spec.ts files) - `npm run test:integration` - Run integration tests (.integration.spec.ts files) - `npm run test:e2e` - Run end-to-end tests (.e2e.spec.ts files) - `npm run test:watch` - Run tests in watch mode - `npm run test:cov` - Run tests and generate coverage report - `npm run test:debug` - Run tests in debug mode - `npm run test:isolated` - Run tests in isolation 3. **Specific Module Test Commands** - **Zulip Module Tests**: - `npm run test:zulip` - Run all Zulip-related tests - `npm run test:zulip:unit` - Run Zulip unit tests - `npm run test:zulip:integration` - Run Zulip integration tests - `npm run test:zulip:e2e` - Run Zulip end-to-end tests - `npm run test:zulip:performance` - Run Zulip performance tests 4. **Test Execution Verification Workflow** ``` Discover Test Issue โ†’ Read jest.config.js โ†’ Choose Appropriate npm run test:xxx Command โ†’ Execute Test โ†’ Analyze Results โ†’ Fix Issues โ†’ Re-execute Test ``` 5. **Test Command Selection Principles** - **Single File Test**: Use `npm run test -- file_path` - **Specific Type Test**: Use corresponding test:xxx command - **Debug Test**: Prioritize `npm run test:debug` - **CI/CD Environment**: Use `npm run test:isolated` ### Step 6: Function Documentation Generation **Read when executing:** `step6-documentation.md` **Focus on:** API interface documentation, WebSocket event documentation **After completion:** Provide inspection report, wait for user confirmation ### Step 7: Code Commit **Read when executing:** `step7-code-commit.md` **Focus on:** Git change detection, branch management, commit message standards, merge document generation **๐Ÿšจ Important Principle:** Regardless of when or what type of changes were made, if Git detects changes, provide commit service **After completion:** Provide commit report, generate merge document ## ๐Ÿ“‹ Unified Report Template Use this template for reporting after each step completion: ``` ## Step X: [Step Name] Inspection Report ### ๐Ÿ” Inspection Results [List of discovered issues] ### ๐Ÿ› ๏ธ Correction Plan [Specific correction suggestions] ### โœ… Completion Status - Check Item 1 โœ“/โœ— - Check Item 2 โœ“/โœ— **Please confirm correction plan, proceed to next step after confirmation** ``` ## ๐Ÿšจ Global Constraints ### ๐Ÿ“ File Modification Record Standards (Important) **After each modification execution, file headers need to update modification records and related information** #### Modification Type Definitions - `Code Standard Optimization` - Naming standards, comment standards, code cleanup, etc. - `Feature Addition` - Adding new features or methods - `Feature Modification` - Modifying existing feature implementations - `Bug Fix` - Fixing code defects - `Performance Optimization` - Improving code performance - `Refactoring` - Code structure adjustment but functionality unchanged #### Modification Record Format Requirements ```typescript /** * Recent Modifications: * - [User Date]: Code Standard Optimization - Clean unused imports (Modified by: [User Name]) * - 2024-01-06: Bug Fix - Fix email validation logic error (Modified by: Li Si) * - 2024-01-05: Feature Addition - Add user verification code login feature (Modified by: Wang Wu) * * @author [Processed Author Name] * @version x.x.x * @since [Creation Date] * @lastModified [User Date] */ ``` #### ๐Ÿ”ข Recent Modification Record Quantity Limit - **Maximum 5 Records**: Recent modification records keep maximum of 5 latest records - **Auto-delete When Exceeded**: When adding new modification records, if exceeding 5, automatically delete oldest records - **Maintain Time Order**: Records arranged in reverse chronological order, newest at top - **Complete Record Retention**: Each record must include complete date, modification type, description and modifier information #### Version Number Increment Rules - **Patch Version +1**: Code standard optimization, bug fixes (1.0.0 โ†’ 1.0.1) - **Minor Version +1**: Feature addition, feature modification (1.0.1 โ†’ 1.1.0) - **Major Version +1**: Refactoring, architecture changes (1.1.0 โ†’ 2.0.0) #### Time Update Rules - **Check Only No Modification**: If only checking without actually modifying file content, **do not update** @lastModified field - **Update Only on Actual Modification**: Only update @lastModified field and add modification records when actually modifying file content - **Git Change Detection**: Check if files have actual changes through `git status` and `git diff`, only add modification records and update timestamps when git shows files are modified #### ๐Ÿšจ Important Emphasis: Pure Check Steps Do Not Update Modification Records **When AI executes code inspection steps, if code already meets standards and needs no modification, then:** - **Forbidden to Add Modification Records**: Do not add records like "AI code inspection step X: XXX check and optimization" - **Forbidden to Update Timestamps**: Do not update @lastModified field - **Forbidden to Increment Version Numbers**: Do not modify @version field - **Only add modification records when actually modifying code content, comment content, structure, etc.** **Wrong Example**: ```typescript // โŒ Wrong: Only checked without modification but added modification record /** * Recent Modifications: * - 2026-01-12: Code Standard Optimization - AI code inspection step 2: Comment standard check and optimization (Modified by: moyin) // This is wrong! * - 2026-01-07: Feature Addition - Add user verification feature (Modified by: Zhang San) */ ``` **Correct Example**: ```typescript // โœ… Correct: Check found compliance with standards, do not add modification records /** * Recent Modifications: * - 2026-01-07: Feature Addition - Add user verification feature (Modified by: Zhang San) // Keep original records unchanged */ ``` ### @author Field Handling Standards - **Retention Principle**: Human names must be retained, cannot be arbitrarily modified - **AI Identifier Replacement**: Only AI identifiers (kiro, ChatGPT, Claude, AI, etc.) can be replaced with user names - **Judgment Example**: `@author kiro` โ†’ Can replace, `@author Zhang San` โ†’ Must retain ### Game Server Special Requirements - **WebSocket Files**: Gateway files must have complete connection and message processing tests - **Dual-mode Services**: Both memory services and database services need complete test coverage - **Property Testing**: Admin modules use fast-check for property testing - **Test Separation**: Strictly distinguish unit tests, integration tests, E2E tests, performance tests ## ๐Ÿ”ง Modification Verification Process ### ๐Ÿ”ฅ Immediately Re-execute Rule After Modification (Important) **After any modification behavior occurs in any step, AI must immediately re-execute that step, cannot directly proceed to next step!** #### Modification Behaviors Include But Not Limited To: - File content modification (code, comments, configuration, etc.) - File renaming - File moving - File deletion - New file creation - Folder structure adjustment #### Mandatory Execution Process: ``` Step Execution โ†’ Discover Issues โ†’ Execute Modifications โ†’ ๐Ÿ”ฅ Immediately Re-execute That Step โ†’ Verify No Omissions โ†’ User Confirmation โ†’ Next Step ``` ### Re-check Process After Problem Fix When issues are discovered and modifications made in any step, must follow this process: 1. **Execute Modification Operations** - Make specific modifications based on discovered issues - Ensure modification content is accurate - **Update file header modification records, version numbers and @lastModified fields** 2. **๐Ÿ”ฅ Immediately Re-execute Current Step** - **Cannot skip this step!** - Complete re-execution of all check items for that step - Cannot only check modified parts, must comprehensively re-check 3. **Provide Verification Report** - Confirm previously discovered issues are resolved - Confirm no new issues introduced - Confirm no other issues omitted 4. **Wait for User Confirmation** - Provide complete verification report - Wait for user confirmation before proceeding to next step ### Verification Report Template ``` ## Step X: Modification Verification Report ### ๐Ÿ”ง Executed Modification Operations - Modification Type: [File modification/renaming/moving/deletion, etc.] - Modification Content: [Specific modification description] - Affected Files: [List of affected files] ### ๐Ÿ“ Updated Modification Records - Added Modification Record: [User Date]: [Modification Type] - [Modification Content] (Modified by: [User Name]) - Updated Version Number: [Old Version] โ†’ [New Version] - Updated Timestamp: @lastModified [User Date] ### ๐Ÿ” Re-executed Step X Complete Check Results [Complete re-execution results of all check items for that step] ### โœ… Verification Status - Original Issues Resolved โœ“ - Modification Records Updated โœ“ - No New Issues Introduced โœ“ - No Other Issues Omitted โœ“ - Step X Check Completely Passed โœ“ **๐Ÿ”ฅ Important: This step has completed modification and re-verification, please confirm before proceeding to next step** ``` ### Importance of Re-checking - **Ensure Completeness**: Avoid omitting other issues during modification process - **Prevent New Issues**: Ensure modifications do not introduce new problems - **Maintain Quality**: Each step reaches complete inspection standards - **Maintain Consistency**: Ensure rigor throughout entire inspection process - **๐Ÿ”ฅ Mandatory Execution**: Cannot skip this step after modifications ## โšก Key Success Factors - **Strict Step-by-step Execution**: No step skipping, no merged execution - **๐Ÿ”ฅ Immediately Re-execute After Modification**: Must immediately re-execute current step after any modification behavior, cannot directly proceed to next step - **Must Re-check After Problem Fix**: Must re-execute entire step after file modification to ensure no omissions - **Must Update Modification Records**: Must update file header modification records, version numbers and timestamps after each file modification - **Real Modification Verification**: Verify modification effects through tools - **Accurate User Info Usage**: Correctly apply date and name information - **Project Characteristic Adaptation**: Optimize inspections for game server characteristics - **Complete Report Provision**: Provide detailed inspection reports for each step --- ## ๐Ÿ”ด FINAL WARNING ๐Ÿ”ด **โš ๏ธ AI EXECUTION REQUIREMENTS SUMMARY:** 1. **STEP 0 (MANDATORY)**: Execute `node tools/setup-user-info.js` 2. **STEP 0.1 (MANDATORY)**: Verify `me.config.json` exists and read user info 3. **STEP 0.2 (MANDATORY)**: Understand project characteristics 4. **STEP 0.3 (MANDATORY)**: Complete and explicitly confirm pre-execution checklist 5. **ONLY THEN**: Begin Step 1 **๐Ÿšจ VIOLATION CONSEQUENCES:** - If AI skips Step 0 and directly executes Step 1, user MUST stop AI and require restart - If AI does not explicitly confirm checklist completion, user MUST stop AI and require confirmation - If AI does not read user info from config file, all subsequent steps are INVALID **โœ… CORRECT EXECUTION START:** ``` AI: "I will now begin the code inspection process. Step 0 - Pre-execution Setup: 1. โœ… Executing user information setup script... Command: cd docs/ai-reading && node tools/setup-user-info.js 2. โœ… Verifying me.config.json exists... File found: docs/ai-reading/me.config.json 3. โœ… Reading user information... User Date: 2026-01-19 User Name: [Name from config] 4. โœ… Understanding project characteristics... - NestJS Game Server โœ“ - Dual-mode Architecture โœ“ - WebSocket Communication โœ“ - Property Testing โœ“ - Layered Architecture โœ“ 5. โœ… Pre-execution checklist completed! All mandatory pre-execution requirements have been satisfied. Now proceeding to Step 1: Naming Convention Check..." ``` **โ›” INCORRECT EXECUTION START (FORBIDDEN):** ``` AI: "I will start with Step 1: Naming Convention Check..." โŒ WRONG! AI: "Let me check the naming conventions..." โŒ WRONG! AI: "Starting code inspection..." โŒ WRONG! ``` --- **๐ŸŽฏ Remember: Step 0 is NOT optional - it is MANDATORY before ANY other step!**