Skip to content

cnlangzi/gtw

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

176 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

gtw β€” GitHub Team Workflow (OpenClaw Plugin)

GitHub team workflow automation β€” session-based issue generation, git operations, and PR review coordination via slash command.

Features

  • Session-based workflow β€” Draft in wip.json, confirm when ready. No accidental API calls.
  • AI-assisted issue creation β€” /gtw new reads the parent session history and auto-generates a structured issue draft (title + body) with no manual input required.
  • Git operations β€” fix, push, and pr commands wrap standard git workflows.
  • Emoji review protocol β€” eyes claim β†’ checklist β†’ approved/changes verdict.
  • GitHub CLI integration β€” Uses gh for auth; no manual token config needed.

Installation

openclaw plugins install ~/code/plugins/gtw -l --dangerously-force-unsafe-install
openclaw gateway restart
  • -l (link mode): changes to the source directory take effect immediately without reinstalling.
  • --dangerously-force-unsafe-install: the dangerous-code scanner flags child_process calls used to invoke git/gh CLI. These are intentional β€” gtw is a GitHub workflow tool that wraps these CLIs. Use this flag to skip the false-positive scan result.
  • Gateway auto-reloads the plugin; openclaw gateway restart ensures a clean start.

Usage

/gtw <command> [args]

Setup

/gtw on <workdir>       Set working directory (resolves git remote)

Issue Management

/gtw new                Read conversation history, auto-generate issue draft (title + body) via AI, save to wip.json
/gtw update #<id>       Update issue draft
/gtw confirm            Execute all pending operations (create issue/branch/PR)
/gtw issue              List open issues
/gtw show #<id>         Show issue details
/gtw poll              List open issues and PRs

Git Operations

/gtw fix <issue_id>     Claim issue (add gtw/wip label), fetch issue, derive branch name, create branch,
                          inject directive to trigger subagent, subagent fixes automatically, creates
                          pendingCommit, requires /gtw confirm to push, then unclaims (removes label)
/gtw push               Stage β†’ auto-commit (conventional format) β†’ generate commit draft β†’ save as pendingCommit
                          (two-step: run /gtw confirm to actually push)
/gtw rebase [branch]    Sync current branch with remote β€” ζœ‰εˆ†ζ”―εοΌšfetch β†’ checkout β†’ rebase θΏœη¨‹εˆ†ζ”―
                          β€” ζ— εˆ†ζ”―εοΌšgit pull --rebase origin <ε½“ε‰εˆ†ζ”―>
/gtw pr [issue_id]      Generate PR title/body via LLM from commit diff, save as pendingPr draft
                          β€” /gtw pr (no args): uses current branch; never reads wip.json
                          β€” /gtw pr <issue_id>: derives branch from issue title (same as /gtw fix)
                            If remote branch exists β†’ checks out and hard-resets to it.
                            If local branch exists but remote missing β†’ checks out and prompts to run /gtw push.
                            If neither exists β†’ uses current branch.
                          (two-step: run /gtw confirm to actually create the PR)

Review

/gtw review             Claim earliest PR with gtw/ready label from watch list
/gtw review <pr>       Claim/review specific PR in current repo
/gtw watch add <owner>/<repo>   Add repo to watch list
/gtw watch rm <owner>/<repo>    Remove repo from watch list
/gtw watch list         Show watched repos

Config

/gtw config             Show current config and wip.json
/gtw model              Show current AI model (gtw-specific or session default)
/gtw model <model>      Set custom AI model (e.g. github/gpt-4o)
/gtw model off          Clear custom model, use session default
/gtw login              Interactive OAuth login (device code flow)
/gtw login --pat <token>  Register a Personal Access Token directly

Configuration

Authentication

gtw supports multiple authentication methods:

Method 1: Personal Access Token (PAT) - Recommended for CI

Option A: Direct PAT input

/gtw login --pat ghp_your_token_here

Validates the token via GitHub API and caches it to ~/.gtw/token.json.

Option B: Environment variable

export GITHUB_TOKEN=ghp_your_token_here
/gtw login --pat

Uses and validates GITHUB_TOKEN, then caches it.

Option C: Cached PAT from previous login Automatically used if you previously ran /gtw login --pat.

Generate a PAT at: https://github.com/settings/tokens (requires repo and workflow scopes)

Method 2: Interactive OAuth Login

Use the device code flow for interactive login:

/gtw login

This will:

  1. If GITHUB_CLIENT_ID is set: Use custom OAuth app with device code flow
  2. If GITHUB_CLIENT_ID is NOT set (default): Fall back to gh auth login using GitHub CLI's built-in OAuth app
    • Opens browser for device code authentication
    • Caches the token from gh CLI for gtw use
    • No need to configure client ID/secret manually

Method 3: GitHub CLI Integration

gtw automatically uses gh CLI token if available. Make sure gh auth login has been run with repo scope:

gh auth login --hostname github.com --scopes repo,workflow
gh auth status

Token Priority:

  1. GITHUB_TOKEN environment variable (PAT)
  2. Cached token in ~/.gtw/token.json (PAT or OAuth)
  3. gh auth token (validated before use)

Check auth status anytime:

/gtw config

Configuration Items

~/.gtw/config.json stores gtw-specific settings:

{
  "model": "github/gpt-4o",
  "watchList": ["owner/repo1", "owner/repo2"],
  "maxReviewRounds": 5
}
Field Default Description
model session default AI model used for issue/PR generation and review. Use github/<model> for Copilot models, minimax/<model> for MiniMax, etc.
watchList [] Watch list of repos scanned by /gtw review (no-arg) for gtw/ready PRs.
maxReviewRounds 5 Maximum review rounds before a PR is marked gtw/stuck. Set to 0 to disable.
llmTimeoutSeconds 60 Timeout in seconds for LLM API calls. If a request times out, it is retried once. If both attempts time out, a TimeoutError is thrown. Can be overridden with the GTW_LLM_TIMEOUT_SECONDS environment variable (takes precedence).

View/edit via:

/gtw model <provider/model-id>   # set custom AI model
/gtw model                      # show current model
/gtw model off                  # clear custom model
/gtw watch add <owner>/<repo>   # add to watch list
/gtw watch list                 # show watch list

Standard Workflow

You: /gtw on ~/code/myproject
β†’ βœ… Switched to owner/repo
   πŸ“ Workdir: /home/user/code/myproject
   Let's discuss the requirements first β€” no code yet.

You: /gtw new
β†’ Draft saved:
   Title: fix: handle null pointer in auth
   Body:
   ## Background
   ...
   ## Acceptance Criteria
   ...

You: /gtw fix 42
β†’ 🌿 Fix workflow started
   Issue: #42
   Title: fix: handle null pointer in auth
   Branch: fix/handle-null-pointer
   ⏳ Subagent spawned β€” the main session will now:
   1. Spawn coding subagent to fix the issue
   2. Wait for subagent to finish
   3. Run push + confirm automatically
   (gtw/wip label is applied to issue #42)

You: /gtw push
β†’ πŸ” Commit draft β€” run /gtw confirm to push
   πŸ“ Commit Message: fix(auth): handle null pointer in auth
   πŸ“Š Changes: +10 -2
   Run /gtw confirm to commit and push.

You: /gtw confirm
β†’ πŸ“¦ Committed and pushed
   Branch: fix/handle-null-pointer
   (gtw/wip label removed from issue #42)

You: /gtw pr
β†’ πŸ” PR draft β€” run /gtw confirm to create PR
   πŸ“ Title: fix: handle null pointer in auth
   🌿 Branch: fix/handle-null-pointer β†’ main

You: /gtw confirm
β†’ βœ… PR #42 created
   URL: https://github.com/owner/repo/pull/42

PR Workflow (with issue)

You: /gtw pr 13
β†’ πŸ” PR draft for issue #13 β€” run /gtw confirm to create PR
   πŸ“ Title: fix: handle null pointer in auth
   🌿 Branch: fix/handle-null-pointer
   ⚠️  Remote branch missing β€” please run /gtw push to publish this branch
   Issue: #13 β€” handle null pointer in auth

You: /gtw push
β†’ πŸ” Commit draft β€” run /gtw confirm to push
   πŸ“ Commit Message: fix(auth): handle null pointer in auth
   Run /gtw confirm to commit and push.

You: /gtw confirm
β†’ πŸ“¦ Committed and pushed
   Branch: fix/handle-null-pointer

You: /gtw pr 13
β†’ πŸ” PR draft for issue #13 β€” run /gtw confirm to create PR
   πŸ“ Title: fix: handle null pointer in auth
   🌿 Branch: fix/handle-null-pointer β†’ main
   Issue: #13 β€” handle null pointer in auth

You: /gtw confirm
β†’ βœ… PR #42 created
   URL: https://github.com/owner/repo/pull/42

Review Workflow

You: /gtw watch add owner/repo
β†’ βœ… Now watching: owner/repo

You: /gtw review
β†’ eyes Claimed PR #23: fix: handle null pointer
   Linked Issue: #12 β€” handle null pointer in auth
   Files changed (3):
     - src/auth.js: +10 -2
     - tests/auth.test.js: +5 -0
   Review [Round 1/5]
     - [ ] Destructive
     - [ ] Out-of-scope
   Review the diff against the issue requirements.
   Run /gtw review 23 again after resolving items.

You: /gtw review 23
β†’ eyes PR #23 re-review (Round 2/5)
   [Items still unresolved kept as unchecked]
   Review the diff and update checklist.

Review protocol:

  • /gtw review (no-arg): Scans watch list for PRs labeled gtw/ready, picks the oldest by updated_at, claims it (gtw/wip), creates a Round 1 checklist.
  • /gtw review <pr>: Reviews specific PR in the current repo (from wip.json). If a checklist exists, increments the round and updates the same comment.
  • Checklist items (always two): Destructive and Out-of-scope β€” the canonical checks to prevent AI-caused unplanned or out-of-scope modifications.
  • Each invocation increments the round number. Unresolved items remain unchecked.
  • When all checkboxes are resolved (all items checked): checklist comment is deleted, approved comment posted, gtw/lgtm label applied. PR is ready to merge.
  • When unresolved items remain: gtw/revise label is applied (replaces gtw/wip), a new "changes needed" comment is posted listing the unresolved items. The previous checklist comment is preserved as-is.
  • When round reaches maxReviewRounds (default 5) with unresolved items: gtw/stuck label applied, manual intervention required.
  • No GitHub Review API is used β€” all review state is tracked via labels and a single persistent checklist comment per PR.

Label system (mutually exclusive):

Label Meaning
gtw/ready Pending review
gtw/wip Review in progress
gtw/lgtm Approved
gtw/revise Needs changes
gtw/stuck Exceeded max rounds

State transition diagram:

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚                                      β”‚
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     reviewer claims       β”‚
   β”‚       gtw/ready            │◄──────────────────────────
   β”‚   (pending review)         β”‚                          β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                          β”‚
              β–²         β”‚      β”‚                          β”‚
              β”‚         β”‚      β”‚                          β”‚
              β”‚         β”‚      β”‚                          β”‚
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”   β”‚      β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   β”‚                β”‚   β”‚      β”‚  β”‚
   β”‚  round β‰₯ max   β”‚   β”‚      β”‚  β”‚
   β”‚      └─────────+β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”˜
   β”‚                   β”‚      β”‚
   β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚  β”‚              gtw/wip                β”‚
   β”‚  β”‚      (review in progress)           β”‚
   β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   β”‚              β”‚
   β”‚              β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚              β”‚                                          β”‚
   β”‚              β”‚ all checklist items resolved             β”‚ unresolved items remain
   β”‚              β–Ό                                          β”‚
   β”‚       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚       β”‚ gtw/lgtm β”‚                               β”‚ gtw/reviseβ”‚
   β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   β”‚                                                      β”‚
   β”‚                                                      β”‚ developer resubmits
   β”‚                                                      β”‚ /gtw review <pr>
   β”‚                                                      β”‚
   β”‚                                                      β–Ό
   β”‚                                           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚                                           β”‚ gtw/wip (resets, round++) β”‚
   β”‚                                           β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   β”‚
   β”‚  unresolved + round β‰₯ max
   β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β–Ίβ”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚ gtw/stuckβ”‚  (manual intervention required)
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Note: gtw/revise is automatically applied when unresolved items remain. When the developer resubmits (/gtw review <pr>), gtw/wip is set and the round increments.

State Files

~/.gtw/wip.json            # Workdir, repo, pendingCommit, pendingPr, issue, branch
~/.gtw/token.json          # Cached token (PAT, OAuth, or gh CLI)
~/.gtw/device_code.json    # Cached device code for OAuth login reuse
~/.gtw/config.json         # Custom AI model setting

Two-Step Confirm Model

All mutating operations (/gtw push, /gtw pr) follow a two-step pattern for safety:

  1. Step 1 β€” Draft: Command generates a draft (commit message or PR title/body) and saves it as pendingCommit or pendingPr in wip.json. Nothing is pushed or created yet.
  2. Step 2 β€” Confirm: /gtw confirm reads the pending draft and executes the actual GitHub API call (push or PR creation).

This means every workflow that involves pushing or creating a PR will have a β†’ /gtw confirm step before the final success message.

Testing / Verification

End-to-End Checklist for Maintainers

After any change to command logic, verify the affected flow:

/gtw push flow:

  1. cd <workdir> && echo "// test" >> README.md
  2. /gtw push β†’ should show "πŸ” Commit draft β€” run /gtw confirm to push" (NOT immediate push)
  3. cat ~/.gtw/wip.json β†’ should contain pendingCommit with title/body/branch
  4. /gtw confirm β†’ should show "πŸ“¦ Committed and pushed"
  5. git log --oneline -1 β†’ should show the commit

/gtw fix flow:

  1. /gtw fix 13 β†’ should claim issue (gtw/wip label appears on GitHub), create branch
  2. After subagent completes: git log --oneline β†’ should have fix commits
  3. /gtw confirm β†’ should push the branch
  4. GitHub issue #13 β†’ gtw/wip label should be removed

/gtw pr flow:

  1. Ensure branch is pushed and on the correct branch
  2. /gtw pr β†’ should show "πŸ” PR draft β€” run /gtw confirm to create PR"
  3. cat ~/.gtw/wip.json β†’ should contain pendingPr with title/body
  4. /gtw confirm β†’ should create PR on GitHub and show URL
  5. cat ~/.gtw/wip.json β†’ pendingPr should be cleared, pr should be set

/gtw review flow:

  1. /gtw review β†’ should claim an unclaimed PR (eyes comment appears)
  2. /gtw review <pr> approved β†’ should post approved comment and submit GitHub review
  3. PR page β†’ should show review state as "Approved"

What to Observe

Flow Check
pendingCommit created wip.json contains pendingCommit after /gtw push
pendingPr created wip.json contains pendingPr after /gtw pr
gtw/wip label applied GitHub issue shows gtw/wip label after /gtw fix
gtw/wip label removed GitHub issue loses gtw/wip label after fix flow completes
gtw/ready PR claimed GitHub PR shows gtw/wip label after /gtw review
Checklist comment posted GitHub PR shows ## Review [Round N] comment
Checklist cleared Checklist comment deleted, gtw/lgtm applied

Architecture

gtw/
β”œβ”€β”€ index.js                 # Plugin entry (ESM, registerCommand)
β”œβ”€β”€ openclaw.plugin.json     # Plugin manifest
β”œβ”€β”€ package.json             # ESM package
β”œβ”€β”€ commands/                # OOP Commander pattern (one class per command)
β”‚   β”œβ”€β”€ Commander.js         # Base interface
β”‚   β”œβ”€β”€ CommanderFactory.js  # Factory: cmd string β†’ Commander instance
β”‚   β”œβ”€β”€ OnCommand.js         # Set workdir + repo
β”‚   β”œβ”€β”€ NewCommand.js        # Auto-generate issue draft via AI
β”‚   β”œβ”€β”€ FixCommand.js        # Claim issue, create branch, spawn subagent fix
β”‚   β”œβ”€β”€ PushCommand.js       # Generate commit message draft (pendingCommit)
β”‚   β”œβ”€β”€ ConfirmCommand.js    # Execute pending actions
β”‚   β”œβ”€β”€ ReviewCommand.js     # Review workflow with checklist comments + labels
β”‚   β”œβ”€β”€ WatchCommand.js      # Manage watch list (add/rm/list repos)
β”‚   └── *.js
└── utils/
    β”œβ”€β”€ session.js           # Parent session read/write (JSONL injection)
    └── *.js

About

GitHub team workflow automation - an openclaw plugin session-based issue generation, git operations, and PR review coordination.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors