Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"name": "security-tools",
"source": "./plugins/security-tools",
"description": "Harden GitHub Actions workflows against supply-chain and injection attacks."
},
{
"name": "pr-tools",
"source": "./plugins/pr-tools",
"description": "Open well-formed GitHub pull requests from Claude Code and attach screenshots and recordings to them."
}
]
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Add the marketplace, then install the plugin you want:

- **[skill-tools](./plugins/skill-tools/)** — Tools for authoring and reviewing Claude Code skills. Includes the `skill-review` skill, which reviews skills against a closed 7-category quality rubric (Structural Discipline, Integrity, Test Coverage, Security, Content Quality, Convention, Cost) with structured JSON output and a determinism contract.
- **[security-tools](./plugins/security-tools/)** — Harden GitHub Actions workflows against supply-chain and injection attacks. Includes the `secure-github-actions` skill (a 14-rule review checklist plus audit commands) and a hook that auto-loads it when you edit a workflow file.
- **[pr-tools](./plugins/pr-tools/)** — Open well-formed GitHub pull requests from Claude Code and attach screenshots and recordings to them. Includes `create-pr` (intent-gathering, diff validation, public-repo safeguards) and `attach-github-assets` (upload local images/recordings to GitHub for use in PR and issue markdown).

## License

Expand Down
15 changes: 15 additions & 0 deletions plugins/pr-tools/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "pr-tools",
"version": "0.1.0",
"description": "Open well-formed GitHub pull requests from Claude Code and attach screenshots and recordings to them.",
"author": {
"name": "Fin 2x"
},
"keywords": [
"github",
"pull-request",
"pr",
"workflow"
],
"license": "MIT"
}
14 changes: 14 additions & 0 deletions plugins/pr-tools/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog

All notable changes to the `pr-tools` plugin are documented here.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2026-07-07

### Added

- Initial release of the `pr-tools` plugin.
- `create-pr` skill — opens or updates a well-formed GitHub pull request for the current branch, with intent-gathering, diff validation, and public-repo safeguards.
- `attach-github-assets` skill — uploads local screenshots and recordings to GitHub and returns markdown-ready URLs.
21 changes: 21 additions & 0 deletions plugins/pr-tools/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Intercom

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 25 additions & 0 deletions plugins/pr-tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# pr-tools

Open well-formed GitHub pull requests from Claude Code and attach screenshots and recordings to them.

Part of the [`fin-2x`](../../README.md) marketplace.

## Install

```
/plugin marketplace add intercom/2x-skills
/plugin install pr-tools@fin-2x
```

## Skills

- **[attach-github-assets](./skills/attach-github-assets/)** — Upload local files (screenshots, screen recordings, images, videos) to GitHub as user-attachment assets and return markdown-ready URLs for PR descriptions, issue bodies, or PR/issue comments.
- **[create-pr](./skills/create-pr/)** — Open or update a well-formed GitHub pull request for the current branch: gathers intent, validates the diff against it, applies public-repo safeguards, and writes a clean Why/How description.

## Hooks

`pr-tools` installs a `PreToolUse` hook that intercepts direct `gh pr create` calls and redirects you to the `create-pr` skill, so PRs go through its intent-gathering and public-repo safeguards. Once `create-pr` is loaded in the session, `gh pr create` runs normally. The hook only matches real invocations (not `gh pr create` mentioned inside a quoted string or heredoc), fails open on any ambiguity, and clears its per-session state on context compaction.

## License

MIT
23 changes: 23 additions & 0 deletions plugins/pr-tools/hooks/clear-skill-markers-on-compact.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
# PreCompact hook that clears skill activation markers.
#
# After context compaction, the agent loses awareness of previously loaded
# skills. Without clearing markers, the intercept-gh-pr-create hook would
# still find a stale marker and allow gh pr create through — even though
# the agent no longer has the create-pr skill instructions in context.

hook_data=$(cat)

if [[ "$hook_data" =~ \"session_id\"[[:space:]]*:[[:space:]]*\"([^\"]+)\" ]]; then
session_id="${BASH_REMATCH[1]}"
else
exit 0
fi

# Clear both session-scoped and agent-scoped markers
marker_dir="/tmp/activated-skills/${session_id}"
if [[ -d "$marker_dir" ]]; then
rm -rf "$marker_dir"
fi

exit 0
25 changes: 25 additions & 0 deletions plugins/pr-tools/hooks/hooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"hooks": {
"PreToolUse": [
{
"matcher": "Skill",
"hooks": [
{ "type": "command", "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/track-skill-activation.sh\"" }
]
},
{
"matcher": "Bash",
"hooks": [
{ "type": "command", "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/intercept-gh-pr-create.sh\"" }
]
}
],
"PreCompact": [
{
"hooks": [
{ "type": "command", "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/clear-skill-markers-on-compact.sh\"" }
]
}
]
}
}
102 changes: 102 additions & 0 deletions plugins/pr-tools/hooks/intercept-gh-pr-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/bin/bash
# PreToolUse hook that intercepts gh pr create and redirects to create-pr skill
#
# Blocks direct `gh pr create` unless the create-pr skill has already been
# activated in this session. Activation is tracked via marker files written
# by track-skill-activation.sh (deterministic, no transcript grepping).
#
# Markers are cleared on context compaction (by clear-skill-markers-on-compact.sh)
# so the agent must re-invoke the skill after compaction.
#
# `/rewind`, however, fires NO hook, so a marker is NOT cleared when the user
# rewinds the conversation back past the create-pr load — leaving the guard
# permanently satisfied even though the skill is no longer in context. To close
# that gap, when a session-scoped marker is found we re-validate it against the
# current branch of the transcript (skill-active-in-transcript.py): the marker
# only counts if the create-pr Skill tool_use is still an ancestor of the latest
# leaf. We fail OPEN (honour the marker) whenever validation is inconclusive, so
# this can only ever re-block a load that was provably rewound away — never a
# legitimate in-context activation.

# Read hook event data from stdin
hook_data=$(cat)

# Extract tool name and command from the JSON
tool_name=$(echo "$hook_data" | jq -r '.tool_name // empty' 2>/dev/null)
command=$(echo "$hook_data" | jq -r '.tool_input.command // empty' 2>/dev/null)

# Only intercept Bash tool calls
if [[ "$tool_name" != "Bash" ]]; then
exit 0
fi

# Strip single-quoted, double-quoted, and heredoc-delimited content before
# matching so that the phrase inside a quoted flag value or heredoc body
# isn't treated as a real invocation. Logic lives in a sibling helper so
# it can be tested (and reused) on its own.
HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
STRIP_HELPER="${HOOK_DIR}/../scripts/strip-quoted-and-heredocs.py"
SKILL_ACTIVE_HELPER="${HOOK_DIR}/../scripts/skill-active-in-transcript.py"

cleaned_command=$(printf '%s' "$command" | python3 "$STRIP_HELPER")

# Check if the cleaned command contains "gh pr create"
if [[ "$cleaned_command" =~ gh[[:space:]]+pr[[:space:]]+create ]]; then
# Allow if the create-pr skill has been activated in this session
# Pure bash JSON extraction — matches track-skill-activation.sh approach
# Regex handles both minified and pretty-printed JSON
if [[ "$hook_data" =~ \"session_id\"[[:space:]]*:[[:space:]]*\"([^\"]+)\" ]]; then
session_id="${BASH_REMATCH[1]}"
else
# Can't determine session — don't block
exit 0
fi

# Check agent-scoped markers first (subagent context), then session-scoped
if [[ "$hook_data" =~ \"agent_id\"[[:space:]]*:[[:space:]]*\"([^\"]+)\" ]]; then
agent_marker_dir="/tmp/activated-skills/${session_id}/${BASH_REMATCH[1]}"
if [[ -f "${agent_marker_dir}/create-pr" || -f "${agent_marker_dir}/pr-tools:create-pr" ]]; then
exit 0
fi
else
marker_dir="/tmp/activated-skills/${session_id}"
if [[ -f "${marker_dir}/create-pr" || -f "${marker_dir}/pr-tools:create-pr" ]]; then
# Marker present. Re-validate it against the current transcript branch
# so a marker left behind by a /rewind (which fires no hook, so it is
# never cleared) doesn't keep the guard satisfied after the create-pr
# load was rewound out of context. Fail OPEN unless the load is
# provably absent from the active branch (helper exit code 1).
if [[ "$hook_data" =~ \"transcript_path\"[[:space:]]*:[[:space:]]*\"([^\"]+)\" ]]; then
transcript_path="${BASH_REMATCH[1]}"
else
transcript_path=""
fi

if [[ -n "$transcript_path" && -f "$transcript_path" ]] && command -v python3 >/dev/null 2>&1; then
python3 "$SKILL_ACTIVE_HELPER" "$transcript_path" create-pr
if [[ "$?" -ne 1 ]]; then
# 0 = create-pr still active in this branch; 2 = undetermined.
# Either way, honour the marker.
exit 0
fi
# Exit 1: create-pr was rewound away — fall through and re-block.
else
# No transcript available to validate — preserve prior behaviour.
exit 0
fi
fi
fi

echo "❌ Direct gh pr create detected - use the create-pr skill instead.

Use: Skill(skill: \"pr-tools:create-pr\")

The create-pr skill ensures proper PR descriptions by:
- Extracting intent from the session (asks if missing)
- Following the Why?/How? format standard
- Creating meaningful documentation" >&2
exit 2
fi

# Command is allowed
exit 0
45 changes: 45 additions & 0 deletions plugins/pr-tools/hooks/track-skill-activation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
# Synchronous PreToolUse:Skill hook that records skill activations.
#
# Writes a marker file per session+skill so other hooks can deterministically
# check whether a given skill has been loaded in this session.
#
# Marker location: /tmp/activated-skills/{session_id}/{skill_name}
# /tmp/activated-skills/{session_id}/{agent_id}/{skill_name} (inside subagents)
#
# Markers are cleared on context compaction (by clear-skill-markers-on-compact.sh)
# so the agent must re-invoke skills after compaction.
#
# This replaces the old approach of grepping the transcript for skill names,
# which caused false positives when file contents happened to mention a skill.

hook_data=$(cat)

# Pure bash JSON extraction — avoids jq overhead on every Skill call
# Regex handles both minified ("key":"val") and pretty-printed ("key": "val") JSON
if [[ "$hook_data" =~ \"session_id\"[[:space:]]*:[[:space:]]*\"([^\"]+)\" ]]; then
session_id="${BASH_REMATCH[1]}"
else
exit 0
fi

if [[ "$hook_data" =~ \"skill\"[[:space:]]*:[[:space:]]*\"([^\"]+)\" ]]; then
skill_name="${BASH_REMATCH[1]}"
else
exit 0
fi

# Scope markers to agent_id when running inside a subagent, so that a skill
# activated in one agent doesn't unlock guarded commands for other agents.
if [[ "$hook_data" =~ \"agent_id\"[[:space:]]*:[[:space:]]*\"([^\"]+)\" ]]; then
marker_dir="/tmp/activated-skills/${session_id}/${BASH_REMATCH[1]}"
else
marker_dir="/tmp/activated-skills/${session_id}"
fi
mkdir -p "$marker_dir"
touch "${marker_dir}/${skill_name}"

# Clean up stale session dirs older than 24h
find /tmp/activated-skills -mindepth 1 -maxdepth 1 -type d -mtime +1 -exec rm -rf {} + 2>/dev/null &

exit 0
Loading