From 0fd83ebdbd09a4c30b52dbb11378f70f51b897c8 Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sun, 30 Nov 2025 08:56:00 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 12 +++ README.md | 3 + commands/commit.md | 104 +++++++++++++++++++++++++ commands/open-pr.md | 150 +++++++++++++++++++++++++++++++++++++ plugin.lock.json | 49 ++++++++++++ 5 files changed, 318 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 commands/commit.md create mode 100644 commands/open-pr.md create mode 100644 plugin.lock.json diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..ebf3003 --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,12 @@ +{ + "name": "git", + "description": "Set of commands, skills, and agents to manage git projects", + "version": "1.0.0", + "author": { + "name": "Artur Roszczyk", + "email": "[email protected]" + }, + "commands": [ + "./commands" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..b3de045 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# git + +Set of commands, skills, and agents to manage git projects diff --git a/commands/commit.md b/commands/commit.md new file mode 100644 index 0000000..16a1cec --- /dev/null +++ b/commands/commit.md @@ -0,0 +1,104 @@ +--- +description: Create git commits for changes made during the current session +allowed-tools: Bash(git status:*), Bash(git diff:*), Bash(git add:*), Bash(git commit:*), Task, AskUserQuestion +model: claude-haiku-4-5 +--- + +# Commit Changes + +You are executing the `/commit` command. Follow these steps precisely: + +## Overview + +This command creates git commits for changes made during the current session. It delegates the analysis and commit creation to a general-purpose agent to avoid polluting the main conversation context. + +## Step 1: Extract Conversation Context + +Before delegating to the agent, analyze the conversation history to extract: +- What tasks/features were discussed and implemented +- Which files were mentioned or modified during implementation +- Any specific intents or goals stated by the user +- Whether multiple distinct tasks were worked on + +Create a concise summary (2-4 sentences) of the session's work. + +## Step 2: Delegate to Agent + +Launch a general-purpose agent with the Task tool using the claude-haiku-4-5 model for efficiency, providing: + +**Prompt structure:** +``` +You are helping create git commits for a coding session. + +Session context: +[Include the summary from Step 1] + +Your tasks: +1. Analyze changes: Run git status and git diff to see all changes. Based on the session context above, identify which changes are relevant to commit. + +2. Commit strategy: If multiple distinct tasks were detected from the session context, ask the user using AskUserQuestion tool: + - Question 1: "How should I commit these changes?" + - "Single commit" - Commit all changes together + - "Multiple logical commits" - Create separate commits for each distinct task/feature + + - Question 2 (only if unstaged/untracked files exist that weren't part of the session work): + "There are uncommitted changes not made in this session. Include them?" + - "Yes, include all changes" - Stage and commit everything + - "No, only session changes" - Commit only files from this session + - "Let me review first" - Show list of files and stop + +3. Create commits following these rules: + - Style: Concise, factual, savant-like. State what was done, not why (unless discussed during implementation) + - Simple changes: Title only (no description) + - Complex changes: Title + description with context about what was changed + - Use facts, avoid self-praise adjectives ("improved", "optimized", "enhanced") + - Hard limit: 80 words total + - Format: Always use heredoc for commit message + + Examples: + ```bash + # Simple change + git commit -m "$(cat <<'EOF' + Add user authentication middleware + EOF + )" + + # Complex change + git commit -m "$(cat <<'EOF' + Refactor database connection pooling + + Extracted connection logic into separate module. Added retry mechanism + for failed connections. Configured pool size based on environment variables. + EOF + )" + ``` + + If creating multiple logical commits: + - Create commits in chronological order of implementation + - Each commit should be self-contained and logical + - Follow same message rules for each commit + +4. Return the following information: + - Commit SHA(s) + - Full commit message(s) for each commit created +``` + +## Step 3: Display Results + +After the agent completes, display the output: +- List each commit SHA with its full commit message +- Confirm total number of commits created + +Example output format: +``` +Created 1 commit: + +abc123d - Add user authentication middleware +``` + +## Error Handling + +If the agent reports any failures: +1. Display the error message clearly +2. Ask user if they want to retry or need assistance +3. Do not attempt automatic fixes in the main conversation diff --git a/commands/open-pr.md b/commands/open-pr.md new file mode 100644 index 0000000..34d9378 --- /dev/null +++ b/commands/open-pr.md @@ -0,0 +1,150 @@ +--- +description: Create commits, push branch, and open a pull request on GitHub +argument-hint: [draft] +allowed-tools: Bash(git status:*), Bash(git diff:*), Bash(git add:*), Bash(git commit:*), Bash(git push:*), Bash(git branch:*), Bash(git checkout:*), Bash(gh pr create:*), Bash(xdg-open:*), AskUserQuestion +model: claude-haiku-4-5 +--- + +# Open Pull Request + +You are executing the `/open-pr` command. Follow these steps precisely: + +## Parameters +- `draft` (optional): Create PR as draft if specified (e.g., `/open-pr draft`) + +## Step 0: Branch Check + +**CRITICAL: Run this check FIRST before any other steps.** + +Check current branch with `git branch --show-current`. + +**If on main or master branch:** +1. Analyze changes briefly to understand what was modified/added +2. Generate 4 best-effort branch name suggestions based on changes: + - Use format: `feature/descriptive-name`, `fix/descriptive-name`, or `refactor/descriptive-name` + - Make names concise but descriptive (2-4 words max) + - Vary the suggestions to give different perspectives on the changes +3. Ask user to choose branch name using AskUserQuestion: + - Question: "You're on the main/master branch. Choose a branch name:" + - Options: Present the 4 generated branch names as options + - Note: User can always select "Other" to provide custom branch name +4. Create and checkout new branch: `git checkout -b ` + +**If on any other branch:** Proceed to Step 1. + +## Step 1: Analyze Changes + +Run `git status` and `git diff` to analyze all changes: +- Identify files modified/created by Claude in current session +- Identify unstaged/untracked files NOT modified by Claude +- Review conversation context to detect if session involved multiple distinct tasks (separate features, fixes, or refactorings discussed/implemented) + +## Step 2: Commit Strategy Questions + +If you detect multiple distinct tasks from conversation context, ask user using AskUserQuestion tool (both questions in same group): + +**Question 1** (always ask if multiple tasks detected): +- "How should I commit these changes?" + - "Single commit" - Commit all changes together + - "Multiple logical commits" - Create separate commits for each distinct task/feature + +**Question 2** (ask ONLY if unstaged/untracked files exist that Claude didn't modify): +- "There are uncommitted changes not made in this session. Include them?" + - "Yes, include all changes" - Stage and commit everything + - "No, only Claude's changes" - Commit only files Claude modified + - "Let me review first" - Show list of files and stop + +## Step 3: Create Commits + +**Commit Message Rules:** +- **Style**: Concise, factual, savant-like. State what was done, not why (unless discussed during implementation) +- **Simple changes**: Title only (no description) +- **Complex changes**: Title + description + - Description adds context about what was changed + - Use facts, avoid self-praise adjectives ("improved", "optimized", "enhanced") + - Only state intents if explicitly discussed during implementation +- **Hard limit**: 80 words total +- **Format**: Always use heredoc for commit message + +**Examples:** +```bash +# Simple change +git commit -m "$(cat <<'EOF' +Add user authentication middleware +EOF +)" + +# Complex change +git commit -m "$(cat <<'EOF' +Refactor database connection pooling + +Extracted connection logic into separate module. Added retry mechanism +for failed connections. Configured pool size based on environment variables. +EOF +)" +``` + +If creating multiple logical commits: +- Create commits in chronological order of implementation +- Each commit should be self-contained and logical +- Follow same message rules for each commit + +## Step 4: Push Branch + +Check if force-push is needed (`git status` shows diverged branch). + +**If force-push required**: Ask user for confirmation before proceeding. + +**Otherwise**: Auto-push with `git push -u origin ` + +**On push failure**: Explain error and ask if you should retry with alternative approach. + +## Step 5: Create Pull Request + +**PR Title**: Use title from commit message (if single commit) or summarize all commits (if multiple) + +**PR Description Rules:** +- **Always include description** (even for simple changes) +- Same style as commit messages: factual, concise, savant-like +- For single commit: Expand on commit message with more context +- For multiple commits: List key changes made across commits +- Avoid self-praise language, state facts only +- **Hard limit**: 150 words + +**PR Metadata:** +- Auto-detect default branch (main/master) as base +- If `draft` parameter passed: add `--draft` flag +- No labels/reviewers unless user specifies + +**Create PR:** +```bash +gh pr create --title "PR title" --body "$(cat <<'EOF' +PR description content here. +EOF +)" [--draft] +``` + +**On PR creation failure**: Explain error and ask if you should retry with alternative approach. + +## Step 6: Open PR Page + +After successful PR creation, extract PR URL from `gh` output and open it: +```bash +xdg-open +``` + +## Error Handling + +If any step fails: +1. Explain what went wrong clearly +2. Provide the specific error message +3. Ask user if you should retry with an alternative approach +4. If user confirms, attempt automatic fix or provide manual commands + +## Final Output + +After successful completion, output: +- Commit SHA(s) +- Branch name +- PR URL +- Confirmation that PR page was opened diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..1cc30e3 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,49 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:sevos/claude-code-marketplace:plugins/git", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "12d6fc29f9fab9df21d0822f31d82a4ac10413f1", + "treeHash": "266839ff0b4fe1648351e7d5f2ee337fca9dc23459fc7b4f9570d8bf0e73f8ed", + "generatedAt": "2025-11-28T10:28:16.729774Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "git", + "description": "Set of commands, skills, and agents to manage git projects", + "version": "1.0.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "da8d8a64f47db900adc12c803a95c7945a3160666644f313900ff2c4964a4c8c" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "055fc063062226270d66ae396952951f581b5f0e2b8cfab0df9012fb8b33ba81" + }, + { + "path": "commands/open-pr.md", + "sha256": "f607fa9343367ba3852335e99a10b0757c2a677375c7e4ba58b4fee19348d2e9" + }, + { + "path": "commands/commit.md", + "sha256": "978e46cda7c9f82b4cb205003990758fc47129cdb330505d829d5006145c71f3" + } + ], + "dirSha256": "266839ff0b4fe1648351e7d5f2ee337fca9dc23459fc7b4f9570d8bf0e73f8ed" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file