|
| 1 | +# **Gemini Project Guidelines** |
| 2 | + |
| 3 | +This document outlines the development and build rules specific to this project, intended for the Gemini agent. All development must strictly adhere to these principles to ensure the project's long-term quality, security, and maintainability. |
| 4 | + |
| 5 | +For a detailed history of development and key decisions, please refer to the Development Log. |
| 6 | +For future development plans and roadmap, please refer to the Development Plan. |
| 7 | + |
| 8 | +## **I. Core Philosophy & Overarching Principles** |
| 9 | + |
| 10 | +*(哲学と最優先事項)* |
| 11 | + |
| 12 | +These are the absolute, non-negotiable principles that guide all other decisions. |
| 13 | +(これらは他のすべての決定を導く、絶対的で交渉の余地のない原則です。) |
| 14 | + |
| 15 | +### **I-1. Security First Principle (セキュリティ第一原則)** |
| 16 | + |
| 17 | +* Security is the highest priority, overriding all other considerations such as functionality or performance. All code, dependencies, and configurations must be reviewed for potential security vulnerabilities before being committed. |
| 18 | +* Never trust user input, including environment variables. All external inputs must be validated and sanitized to prevent injection attacks. |
| 19 | +* Sensitive information (API keys, credentials) must never be hardcoded or stored in insecure locations. Configuration files containing sensitive information must be stored with restrictive permissions (e.g., 0600 for files, 0700 for directories). |
| 20 | + |
| 21 | +### **I-2. Testability First Principle (テスト容易性第一の原則)** |
| 22 | + |
| 23 | +* Prioritize practical "testability" over theoretical "beauty" in design. If a design pattern makes unit testing significantly difficult (e.g., self-registration via init()), it is forbidden. |
| 24 | +* Always ask, "How will I test this code?" Code that cannot be answered should not be written. Easily testable code is inherently loosely coupled and easy to understand. |
| 25 | + |
| 26 | +## **II. Design & Implementation Principles** |
| 27 | + |
| 28 | +*(設計と実装の原則)* |
| 29 | + |
| 30 | +These principles govern how code should be designed and written. |
| 31 | +(これらはコードをどのように設計し、書くべきかを規定する原則です。) |
| 32 | + |
| 33 | +### **II-1. Explicit is Better than Implicit (暗黙的な挙動の禁止)** |
| 34 | + |
| 35 | +* Forbid "magical" implementations like changing global state in init() or behavior that changes merely by importing a package. |
| 36 | +* Dependency Injection must always be done explicitly (e.g., via function arguments). This makes code behavior traceable and easy to mock in tests. |
| 37 | + |
| 38 | +### **II-2. Code Style and Quality (コードのスタイルと品質)** |
| 39 | + |
| 40 | +* Adhere to standard Go formatting (gofmt) and idiomatic Go practices. |
| 41 | +* Keep functions concise and focused on a single responsibility. |
| 42 | +* Identify and address the root cause of bugs, avoiding temporary or superficial fixes. |
| 43 | + |
| 44 | +### **II-3. Dependency Management (依存関係の管理)** |
| 45 | + |
| 46 | +* Use Go Modules for dependency management. |
| 47 | +* Run go mod tidy after adding or removing dependencies to ensure go.mod and go.sum are up-to-date. |
| 48 | +* Regularly scan project dependencies for known vulnerabilities using make vulncheck. |
| 49 | + |
| 50 | +## **III. Development Process & Workflow** |
| 51 | + |
| 52 | +*(開発プロセスとワークフロー)* |
| 53 | + |
| 54 | +These rules define the mandatory process for all development activities. |
| 55 | +(これらはすべての開発活動における必須のプロセスを定義するルールです。) |
| 56 | + |
| 57 | +### **III-1. Definition of "Major Refactoring" (「大規模改修」の定義)** |
| 58 | + |
| 59 | +Any change that meets one or more of the following criteria is considered a "Major Refactoring" and requires prior approval of a detailed development plan, including impact analysis and testing strategy. |
| 60 | + |
| 61 | +* **Changes to Initialization Logic**: Any modification involving init() functions, global variables, or package initialization order. |
| 62 | +* **Changes to Core Interfaces**: Modifying the signature of a central interface like Provider. |
| 63 | +* **Widespread Impact**: A change that requires modifications across three or more packages. |
| 64 | +* **Introduction of Cross-Cutting Concerns**: Adding or changing functionality that affects multiple components, such as authentication, logging, or caching. |
| 65 | + |
| 66 | +### **III-2. Safe Refactoring Protocol (安全なリファクタリング規約)** |
| 67 | + |
| 68 | +Even for changes not classified as "Major Refactoring," the following protocol must be strictly followed to prevent system-wide failure. |
| 69 | + |
| 70 | +* **III-2.1.【Establish Baseline】**: Commit the stable, fully-tested state of the code before starting. Commit message: refactor: Start refactoring X. |
| 71 | +* **III-2.2.【Make Minimal Changes】**: Make the smallest possible incremental change (e.g., extract one function, add one variable). |
| 72 | +* **III-2.3.【Test Immediately】**: Run make test immediately after the change. |
| 73 | + * **On Success**: Commit the change immediately (feat: Introduce Y / refactor: Extract Z). Return to Step **III-2.2**. |
| 74 | + * **On Failure**: **Discard all changes immediately (git reset --hard).** Do not attempt to fix the test by modifying other code. A test failure is a critical signal that the **design approach is flawed** and must be re-evaluated from scratch. |
| 75 | +* **III-2.4.【Complete】**: Achieve the final goal through a series of small, safe, and tested commits. |
| 76 | + |
| 77 | +### **III-3. Commit Message Conventions (コミットメッセージの規約)** |
| 78 | + |
| 79 | +* Use the Conventional Commits specification (e.g., feat:, fix:, refactor:, docs:). |
| 80 | +* Explain *why* a change was made, not just *what* was changed. |
| 81 | + |
| 82 | +### **III-4. Build and Linting (ビルドとリント)** |
| 83 | + |
| 84 | +* Always use the provided Makefile for building, testing, and cleaning the project. |
| 85 | +* Ensure all code passes lint checks (make lint) before committing. |
| 86 | + |
| 87 | +## **IV. Tooling & Operational Safety** |
| 88 | + |
| 89 | +*(ツール利用と操作の安全性)* |
| 90 | + |
| 91 | +These rules govern the safe use of development tools and file system operations to prevent irreversible errors. |
| 92 | +(これらは不可逆的なエラーを防ぐため、開発ツールとファイルシステム操作の安全な利用法を規定するルールです。) |
| 93 | + |
| 94 | +### **IV-1. Safe Code Modification Protocol (安全なコード修正手順)** |
| 95 | + |
| 96 | +* **Problem**: The code replacement tool can be unreliable and may corrupt files. |
| 97 | +* **Rule**: To prevent file corruption, all code modifications must follow a "diff-and-replace" workflow. |
| 98 | +* **Process**: |
| 99 | + * **IV-1.1.** Generate the complete, modified content of the target file into a **temporary file** (e.g., original_filename.new). |
| 100 | + * **IV-1.2.** Execute a diff command between the original file and the new temporary file to verify the changes are exactly as intended. |
| 101 | + * **IV-1.3.** Only after visual confirmation of the diff, replace the original file with the temporary file using a mv command. |
| 102 | + |
| 103 | +### **IV-2. Safe File System Operations (安全なファイルシステム操作)** |
| 104 | + |
| 105 | +* **Problem**: Accidental deletion of unintended files due to incorrect path context. |
| 106 | +* **Rule**: All commands that delete or modify files/directories (e.g., rm, mv) **must use absolute paths.** |
| 107 | +* **Reason**: This prevents catastrophic errors resulting from operating in an unexpected current working directory. Relative paths are strictly forbidden for destructive operations. |
| 108 | + |
| 109 | +### **IV-3. Safe Git Commit Procedure (安全なGitコミット手順)** |
| 110 | + |
| 111 | +* **Problem**: Complex commit messages can be misinterpreted by the shell, leading to incorrect or failed commits. |
| 112 | +* **Rule**: To prevent shell interpretation errors, commit messages **must be written to a temporary file first.** |
| 113 | +* **Process**: |
| 114 | + * **IV-3.1.** Write the full commit message (including subject, body, and any special characters) to a temporary file (e.g., .git/COMMIT_MSG). |
| 115 | + * **IV-3.2.** Use the git commit -F .git/COMMIT_MSG command to apply the message from the file. Direct command-line commits with -m are forbidden for multi-line or complex messages. |
| 116 | + |
| 117 | +## **V. Documentation Principles** |
| 118 | + |
| 119 | +*(ドキュメンテーションの原則)* |
| 120 | + |
| 121 | +* **V-1. Language Policy**: The primary documentation will be in English (e.g., README.md). Other languages will be provided as auxiliary documentation with a language suffix (e.g., README.ja.md). |
| 122 | +* **V-2. Maintenance**: When a feature is changed or added, ensure all relevant documentation (README.md, CHANGELOG.md, etc.) is updated accordingly. |
| 123 | + |
| 124 | +## **VI. Agent Operational Protocols (自己規律)** |
| 125 | + |
| 126 | +To prevent critical errors observed during the development of v1.2.0, the following operational protocols are mandatory for all future interactions. These supersede any general instructions where they conflict. |
| 127 | + |
| 128 | +### **VI-1. State-Aware Git Workflow (状態を意識したGitワークフロー)** |
| 129 | +- **Rule:** Before any state-changing Git command (`merge`, `push`, `tag`, `reset`, `branch`), the current state **must** be verified by running `git status && git branch` immediately prior to the operation. |
| 130 | +- **Reason:** To prevent operating on incorrect branches or assumptions about the repository's state. |
| 131 | + |
| 132 | +### **VI-2. Strict Adherence to Safety Protocols (安全プロトコルの厳守)** |
| 133 | +- **Rule:** The "Safe Code Modification Protocol" (IV-1) and "Safe Git Commit Procedure" (IV-3) are not optional guidelines but **mandatory, non-negotiable procedures**. All multi-line commits or complex file modifications **must** use the temporary file and diff method. |
| 134 | +- **Reason:** To eliminate syntax/escaping errors and ensure user verification before changes are applied. |
| 135 | + |
| 136 | +### **VI-3. Rigorous Verification Before Merging (マージ前の厳格な検証)** |
| 137 | +- **Rule:** A feature or fix is not considered "complete" until it has been functionally verified by the user. The standard workflow is: `Implement -> Build -> **Manual Test & User Confirmation** -> Commit -> Merge`. The "Manual Test & User Confirmation" step is mandatory and cannot be skipped. |
| 138 | +- **Reason:** To ensure the implemented code correctly solves the user's problem before it is integrated into the main branch. |
0 commit comments