Skip to content

Commit 3a72268

Browse files
committed
feat(commands): refactor /maintenance into a read-only audit workflow
1 parent 4c0a391 commit 3a72268

5 files changed

Lines changed: 43 additions & 18 deletions

File tree

.gemini/commands/maintenance.toml

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
1-
description = "Analyze and propose refactoring plans to improve code readability and maintainability."
1+
description = "Perform a deep, read-only audit of the codebase to identify technical debt and maintenance issues."
2+
23
prompt = """
3-
You are an expert software engineer performing a comprehensive codebase maintenance on the current workspace.
4+
You are a Lead Maintenance Engineer. You are executing the custom `/maintenance` command workflow.
5+
6+
**CRITICAL MANDATE:** This command is strictly for analysis and reporting. You MUST NOT modify any source files. Your goal is to produce a "Maintenance Report Card."
7+
8+
Follow these phases strictly:
49
5-
**Phase 1: Deep Analysis & Planning**
6-
Run a deep analysis of the current codebase focusing on performance, security, readability, and overall maintainability.
7-
**Crucial:** Do NOT propose changes that alter existing functionality or fix bugs. This is strictly a maintenance, clean-up, and refactoring operation.
10+
### Phase 1: Clarification & Scope
11+
1. **Analyze Request:** Identify if the user provided specific instructions or a target area for the maintenance audit.
12+
2. **Clarify:** If the scope is ambiguous, use `ask_user` to define the focus (e.g., "Should I focus on DRY violations in the hooks, or general documentation coverage?").
813
9-
Create a detailed and expressive plan with the following priorities:
10-
1. **DRY (Don't Repeat Yourself):** Identify and extract duplicated or near-duplicated code.
11-
2. **Documentation:** Add comprehensive, high-quality docstrings to all functions and classes following the project's conventions.
12-
3. **Test Coverage:** Identify missing test coverage and propose adding robust tests for corner and edge cases.
13-
4. **Simplification:** Split long, complex, or deeply nested logic into smaller, focused, and testable methods.
14+
### Phase 2: Deep Analysis (Codebase Investigator)
15+
1. **Invoke Investigator:** Invoke the `codebase_investigator` subagent to perform a comprehensive, non-destructive audit.
16+
2. **Audit Priorities:**
17+
- **DRY (Don't Repeat Yourself):** Identify logic duplication across files.
18+
- **Documentation Coverage:** Check for missing docstrings or outdated comments.
19+
- **Test Gaps:** Identify complex functions without corresponding tests.
20+
- **Simplification:** Find deeply nested or overly long methods that need refactoring.
21+
3. **User Context:** Ensure the investigator accounts for any specific instructions provided in Phase 1.
1422
15-
Your proposed plan must be highly expressive and detailed. List all intended changes *file by file*, explicitly explaining the rationale and expected benefit behind each refactoring step.
23+
### Phase 3: Report Card Generation
24+
1. **Synthesize Findings:** Consolidate the investigator's findings into a structured "Maintenance Report Card."
25+
2. **Persistence:** Save the report to `research/maintainance-report-<date>.md` using `write_file`.
26+
3. **Content:** Include a high-level summary, a file-by-file list of detected issues, and specific, actionable suggestions for fixing them.
1627
17-
**Phase 2: User Agreement**
18-
Stop and present your complete plan to the user. Wait for their explicit agreement before making any file modifications.
28+
### Phase 4: Advisory
29+
1. **Next Steps:** Inform the user that the audit is complete and the report is saved.
30+
2. **Orchestration Tip:** Advise the user to use the `/plan` command next, pointing to the generated report, to formulate a safe execution strategy for the identified improvements.
1931
20-
**Phase 3: Step-by-Step Implementation**
21-
Upon user agreement, implement the plan iteratively, step by step. Ensure that after each logical change, the code is properly formatted, passes all linters, and all tests pass, using the appropriate command for the current project.
22-
"""
32+
Do not skip any phases. Start with Phase 1.
33+
"""

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ The `.gemini/commands/` directory defines specialized workflows that automate ev
7575
### 🧹 Phase 3: Content Generation, Maintenance & Documentation
7676
* **`/draft`**: Multi-phase workflow to turn research and plans into detailed, high-quality technical documents or articles section-by-section using the `writer` subagent.
7777
* **`/review`**: Uses the `reviewer` subagent to perform non-destructive, multi-phase structural and linguistic audits based on the project's style guide.
78-
* **`/maintenance`**: Performs a deep scan of the codebase to identify technical debt, refactoring opportunities, and areas to improve test coverage.
78+
* **`/maintenance`**: Performs a deep, read-only audit of the codebase using the `codebase_investigator` to identify technical debt and generate a "Maintenance Report Card" in `research/`.
7979
* **`/document`**: Analyzes the codebase and journals to generate or update comprehensive project documentation in the `docs/` folder.
8080
* **`/cron`**: Manages repetitive background tasks (e.g., health checks, automated reports) using **systemd user timers**.
8181

docs/user-guide.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ Your background automation layer.
198198

199199
Your defense against context rot.
200200

201-
- **How it works:** Performs a comprehensive audit of the codebase to identify technical debt, outdated implementations, or deviations between code and documentation. It presents a detailed refactoring plan for your approval before making any changes, ensuring the repository remains a clean environment for the AI to operate within.
201+
- **How it works:** Performs a comprehensive, read-only audit of the codebase to identify technical debt, outdated implementations, or documentation gaps using the `codebase_investigator`. It generates a "Maintenance Report Card" in the `research/` directory.
202+
- **Why it works:** It separates the audit from the implementation, ensuring the codebase remains a clean environment. After an audit, use the `/plan` command to safely execute the suggested improvements.
202203

203204
---
204205

journal/2026-03-23.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
[2026-03-23T06:01:22] - Update /draft command with branching logic for initial drafting and review-driven refinement.
1111
[2026-03-23T06:07:18] - Align README, Style Guide, Docs, and historical entries with writer/reviewer naming.
1212
[2026-03-23T06:08:20] - Archive completed /draft command and writer agent improvement task.
13+
[2026-03-23T06:50:29] - Refactor /maintenance command into a read-only audit workflow using codebase_investigator.

tests/test_review_command.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ def test_draft_command_is_multimode():
6060
assert "writer" in content
6161
assert "reporter" not in content
6262

63+
def test_maintenance_command_is_audit():
64+
with open(".gemini/commands/maintenance.toml", "r") as f:
65+
content = f.read()
66+
assert "codebase_investigator" in content
67+
assert "Maintenance Report Card" in content
68+
assert "research/maintainance-report-" in content
69+
assert "Phase 3" in content
70+
# Ensure it doesn't mention Step-by-Step Implementation or modification
71+
assert "Step-by-Step Implementation" not in content
72+
6373
if __name__ == "__main__":
6474
# Simple manual runner for now
6575
try:
@@ -76,6 +86,8 @@ def test_draft_command_is_multimode():
7686
test_reporter_agent_gone()
7787
test_writer_agent_has_replace()
7888
test_draft_command_is_multimode()
89+
90+
test_maintenance_command_is_audit()
7991

8092
print("Tests Passed")
8193
except AssertionError as e:

0 commit comments

Comments
 (0)