investigating-repository-history
Investigate GitHub repository history before risky code changes using git blame/log, GitHub PRs, review comments, squash/rebase/cherry-pick/rename heuristics, and cited evidence. Use when asking why code exists, whether a change is safe, what PR introduced behavior, or before edi
Install
npx skills add https://github.com/CodeAlive-AI/ai-driven-development/tree/main/skills/investigating-repository-history
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install codealive-ai-ai-driven-development@llmmart
git clone https://github.com/CodeAlive-AI/ai-driven-development.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole codealive-ai/ai-driven-development collection as a plugin from our marketplace. Git is the plain clone.
README
Repository History Investigator skill
A production-oriented Agent Skill for Claude Code, Codex, and compatible agents. It helps a coding agent inspect GitHub repository history before risky edits using local git history, GitHub PRs, review comments, and anomaly-aware provenance matching.
Contents
investigating-repository-history/
├── SKILL.md
├── scripts/
│ ├── history_context.py
│ ├── compact_pr.py
│ └── validate_skill.py
├── references/
│ ├── ANOMALIES.md
│ ├── GH_CLI.md
│ ├── DECISION_ATOMS.md
│ ├── OUTPUT_SCHEMA.md
│ └── EVALUATION.md
├── tests/
│ └── test_skill.py
├── agents/
│ └── openai.yaml
└── assets/
└── history-note-template.md
Install
For repository-scoped Codex use, copy this folder to:
$REPO_ROOT/.agents/skills/investigating-repository-history
For personal Codex use:
$HOME/.agents/skills/investigating-repository-history
For Claude Code, copy it to your Claude skills directory, for example:
$HOME/.claude/skills/investigating-repository-history
Validate
python3 scripts/validate_skill.py .
Tests
Run the full self-contained test suite (stdlib unittest, no external deps):
python3 -m unittest tests.test_skill -v
Tests cover: package structure, YAML frontmatter, gh-only access policy (no
direct api.github.com calls), --help / --version for every script, the
validate_skill.py validator, and a local-only smoke test of history_context.py
that builds a tiny throw-away git repo and runs inspect with --no-gh.
Quick run
From a git repository with gh authenticated:
python3 scripts/history_context.py inspect \
--repo-dir /path/to/repo \
--path src/foo.ts \
--start 10 --end 30 \
--question "Can I remove this check?" \
--format markdown
Skill manifest
Repository History Investigator
Use this skill to reconstruct the historical intent behind code before changing it. The goal is not merely “find the blame commit”; the goal is to return a compact, cited history note explaining relevant PRs, review comments, constraints, rejected approaches, and anomalies.
Contents
- Trigger conditions
- Core rule
- Fast path
- Progressive disclosure
- Investigation workflow
- Evidence confidence rules
- Output template
- Gotchas
- Available scripts
Trigger conditions
Use this skill when the user asks any of these:
- “Why is this code written this way?”
- “Can I remove/simplify/change this check, constraint, branch, migration, public API, or feature flag?”
- “Which PR introduced this behavior or regression?”
- “Find the relevant PR/review discussion/history for this code.”
- Before editing code that touches API compatibility, security, concurrency, persistence, migrations, performance, generated interfaces, feature flags, or unclear legacy/workaround logic.
Do not use this skill for trivial new code with no dependency on existing behavior.
Core rule
Before making a risky edit, produce a history note answering:
- What code scope was inspected?
- Which commits and PRs are relevant?
- Which review comments or PR discussions explain intent?
- What constraints, risks, rejected approaches, or tests were found?
- Is the evidence strong, weak, contradictory, stale, truncated, or unknown?
- How should the implementation plan change?
If the evidence is weak, say UNKNOWN and lower confidence. Never invent intent from a semantic match alone.
Fast path
From the repository working tree, run the collector first. If the skill directory is not the current directory, prefix the script path with the installed skill path and pass --repo-dir /path/to/repo.
python3 scripts/history_context.py inspect \
--repo-dir /path/to/repo \
--path path/to/file.ext \
--start 120 --end 160 \
--question "Can I remove this constraint?" \
--format markdown
For symbol-level questions without exact lines:
python3 scripts/history_context.py inspect \
--repo-dir /path/to/repo \
--path path/to/file.ext \
--symbol SymbolOrFunctionName \
--question "Why does this behavior exist?" \
--format markdown
For JSON suitable for deeper agent reasoning:
python3 scripts/history_context.py inspect \
--repo-dir /path/to/repo \
--path path/to/file.ext \
--start 120 --end 160 \
--symbol SymbolOrFunctionName \
--question "What PR introduced this behavior?" \
--format json \
--output history-context.json
Then read only the relevant sections of the output. Do not paste huge raw PR/comment dumps into the final answer.
Progressive disclosure
Load these files only when needed:
references/ANOMALIES.md— use when exact commit→PR mapping fails, or when squash, rebase, cherry-pick, backport, revert, rename, split, generated files, or mass refactors are possible.references/GH_CLI.md— use when the script fails or manualgh apicalls are needed.references/DECISION_ATOMS.md— use when converting PR/comment evidence into constraints, risks, rejected approaches, or test requirements.references/OUTPUT_SCHEMA.md— use when producing a formal machine-readable report.references/EVALUATION.md— use when testing or improving the skill.
Investigation workflow
- Define scope. Identify paths, line ranges, symbols, tests, error strings, feature flags, and any proposed diff.
- Collect local history. Use the script or manual
git blame -w -M -C -C -C,git log --follow,git log -S, andgit log -G. - Map commits to PRs. Prefer exact GitHub commit→PR association. Treat it as one signal, not the entire answer.
- Fetch PR evidence. For candidate PRs, inspect PR body, files, commits, reviews, inline review comments, and issue comments.
- Resolve anomalies. If mapping is weak, apply the Provenance Mesh: commit association + patch equivalence + content/symbol lineage.
- Extract decision atoms. Convert evidence into explicit claims: constraints, compatibility requirements, security invariants, performance constraints, rejected approaches, test requirements.
- Assess risk. Downgrade confidence for semantic-only matches, path-only matches, reverted PRs, API truncation, large PRs, generated files, or missing PRs.
- Produce a history note before editing code.
Evidence confidence rules
High confidence:
- exact GitHub commit→PR association; or
- patch/hunk equivalence plus path/symbol agreement; or
- review comment remaps to the current hunk/symbol and matches the proposed change.
Medium confidence:
- same symbol/path plus relevant PR discussion, but no patch-level match.
Low confidence:
- semantic search only, title/body match only, path-only match, or stale/reverted evidence.
Never claim “this was decided” unless a commit, PR body, review, review comment, issue comment, or linked issue supports it.
Output template
Use this concise template in the final answer or implementation plan:
## History note
Scope inspected: [paths, lines, symbols]
Relevant evidence:
- PR #[n] — [relation: exact/squash-like/rename-lineage/search], [why relevant], [confidence]
- Commit [sha] — [what it changed], [relation]
- Review/comment — [constraint or concern]
Decision atoms:
- [constraint/risk/rejected approach/test requirement] — [claim] — evidence: [PR/comment/commit]
Risk: [low|medium|high|unknown]
Confidence: [0.00-1.00]
Unknowns/truncation: [none or list]
Plan impact: [proceed|modify plan|ask human|do not change]
Gotchas
git blameis a seed generator, not truth. Formatting commits, moves, squashes, and refactors can hide origin.- A PR can be relevant even if it did not introduce the current line; review comments may explain why an alternative was rejected.
- Squash merges often require patch/hunk matching because the final commit SHA differs from PR commits.
- File paths are not identity. Track file lineage, directory moves, symbol fingerprints, and hunk context.
- Reverted PRs are stale evidence unless a later PR reintroduced the same decision.
- Large
gh apiresponses may be truncated by the underlying GitHub endpoints. If truncation is possible, mark evidence incomplete. - General PR conversation comments come from issue comments; inline review comments come from PR review comments.
Available scripts
scripts/history_context.py— main collector for local Git + GitHub PR evidence. Runpython3 scripts/history_context.py --help.scripts/compact_pr.py— fetch one or more PRs and print compact evidence. Runpython3 scripts/compact_pr.py --help.scripts/validate_skill.py— validate this skill’s frontmatter and basic structure.
Files (ai-driven-development)
-
agents
-
openai.yaml 374 B
Loading…
-
-
assets
-
history-note-template.md 233 B
Loading…
-
-
references
-
ANOMALIES.md 4.5 KB
Loading… -
DECISION_ATOMS.md 1.8 KB
Loading… -
EVALUATION.md 1.1 KB
Loading… -
GH_CLI.md 3.4 KB
Loading… -
OUTPUT_SCHEMA.md 1.9 KB
Loading…
-
-
scripts
-
compact_pr.py 6 KB
Loading… -
history_context.py 42.8 KB
Loading… -
validate_skill.py 2.9 KB
Loading…
-
-
tests
-
test_skill.py 10 KB
Loading… -
__init__.py 0 B
Loading…
-
-
LICENSE 1 KB · in bundle
-
README.md 1.9 KB
# Repository History Investigator skill A production-oriented Agent Skill for Claude Code, Codex, and compatible agents. It helps a coding agent inspect GitHub repository history before risky edits using local git history, GitHub PRs, review comments, and anomaly-aware provenance matching. ## Contents ```text investigating-repository-history/ ├── SKILL.md ├── scripts/ │ ├── history_context.py │ ├── compact_pr.py │ └── validate_skill.py ├── references/ │ ├── ANOMALIES.md │ ├── GH_CLI.md │ ├── DECISION_ATOMS.md │ ├── OUTPUT_SCHEMA.md │ └── EVALUATION.md ├── tests/ │ └── test_skill.py ├── agents/ │ └── openai.yaml └── assets/ └── history-note-template.md ``` ## Install For repository-scoped Codex use, copy this folder to: ```text $REPO_ROOT/.agents/skills/investigating-repository-history ``` For personal Codex use: ```text $HOME/.agents/skills/investigating-repository-history ``` For Claude Code, copy it to your Claude skills directory, for example: ```text $HOME/.claude/skills/investigating-repository-history ``` ## Validate ```bash python3 scripts/validate_skill.py . ``` ## Tests Run the full self-contained test suite (stdlib `unittest`, no external deps): ```bash python3 -m unittest tests.test_skill -v ``` Tests cover: package structure, YAML frontmatter, gh-only access policy (no direct `api.github.com` calls), `--help` / `--version` for every script, the `validate_skill.py` validator, and a local-only smoke test of `history_context.py` that builds a tiny throw-away git repo and runs `inspect` with `--no-gh`. ## Quick run From a git repository with `gh` authenticated: ```bash python3 scripts/history_context.py inspect \ --repo-dir /path/to/repo \ --path src/foo.ts \ --start 10 --end 30 \ --question "Can I remove this check?" \ --format markdown ``` -
SKILL.md 7.7 KB
--- name: investigating-repository-history description: Investigate GitHub repository history before risky code changes using git blame/log, GitHub PRs, review comments, squash/rebase/cherry-pick/rename heuristics, and cited evidence. Use when asking why code exists, whether a change is safe, what PR introduced behavior, or before editing API, compatibility, security, concurrency, persistence, migration, or performance-sensitive code. license: MIT compatibility: Designed for Claude Code, Codex, and similar coding agents. Requires a local git clone; bundled scripts require Python 3.9+, git, and authenticated GitHub CLI `gh` for GitHub PR evidence. allowed-tools: Bash(git:*) Bash(gh:*) Bash(python3:*) Read Grep metadata: version: "1.0.0" methodology: "Provenance Mesh" --- # Repository History Investigator Use this skill to reconstruct the historical intent behind code before changing it. The goal is not merely “find the blame commit”; the goal is to return a compact, cited history note explaining relevant PRs, review comments, constraints, rejected approaches, and anomalies. ## Contents - [Trigger conditions](#trigger-conditions) - [Core rule](#core-rule) - [Fast path](#fast-path) - [Progressive disclosure](#progressive-disclosure) - [Investigation workflow](#investigation-workflow) - [Evidence confidence rules](#evidence-confidence-rules) - [Output template](#output-template) - [Gotchas](#gotchas) - [Available scripts](#available-scripts) ## Trigger conditions Use this skill when the user asks any of these: - “Why is this code written this way?” - “Can I remove/simplify/change this check, constraint, branch, migration, public API, or feature flag?” - “Which PR introduced this behavior or regression?” - “Find the relevant PR/review discussion/history for this code.” - Before editing code that touches API compatibility, security, concurrency, persistence, migrations, performance, generated interfaces, feature flags, or unclear legacy/workaround logic. Do not use this skill for trivial new code with no dependency on existing behavior. ## Core rule Before making a risky edit, produce a **history note** answering: 1. What code scope was inspected? 2. Which commits and PRs are relevant? 3. Which review comments or PR discussions explain intent? 4. What constraints, risks, rejected approaches, or tests were found? 5. Is the evidence strong, weak, contradictory, stale, truncated, or unknown? 6. How should the implementation plan change? If the evidence is weak, say `UNKNOWN` and lower confidence. Never invent intent from a semantic match alone. ## Fast path From the repository working tree, run the collector first. If the skill directory is not the current directory, prefix the script path with the installed skill path and pass `--repo-dir /path/to/repo`. ```bash python3 scripts/history_context.py inspect \ --repo-dir /path/to/repo \ --path path/to/file.ext \ --start 120 --end 160 \ --question "Can I remove this constraint?" \ --format markdown ``` For symbol-level questions without exact lines: ```bash python3 scripts/history_context.py inspect \ --repo-dir /path/to/repo \ --path path/to/file.ext \ --symbol SymbolOrFunctionName \ --question "Why does this behavior exist?" \ --format markdown ``` For JSON suitable for deeper agent reasoning: ```bash python3 scripts/history_context.py inspect \ --repo-dir /path/to/repo \ --path path/to/file.ext \ --start 120 --end 160 \ --symbol SymbolOrFunctionName \ --question "What PR introduced this behavior?" \ --format json \ --output history-context.json ``` Then read only the relevant sections of the output. Do not paste huge raw PR/comment dumps into the final answer. ## Progressive disclosure Load these files only when needed: - `references/ANOMALIES.md` — use when exact commit→PR mapping fails, or when squash, rebase, cherry-pick, backport, revert, rename, split, generated files, or mass refactors are possible. - `references/GH_CLI.md` — use when the script fails or manual `gh api` calls are needed. - `references/DECISION_ATOMS.md` — use when converting PR/comment evidence into constraints, risks, rejected approaches, or test requirements. - `references/OUTPUT_SCHEMA.md` — use when producing a formal machine-readable report. - `references/EVALUATION.md` — use when testing or improving the skill. ## Investigation workflow 1. **Define scope.** Identify paths, line ranges, symbols, tests, error strings, feature flags, and any proposed diff. 2. **Collect local history.** Use the script or manual `git blame -w -M -C -C -C`, `git log --follow`, `git log -S`, and `git log -G`. 3. **Map commits to PRs.** Prefer exact GitHub commit→PR association. Treat it as one signal, not the entire answer. 4. **Fetch PR evidence.** For candidate PRs, inspect PR body, files, commits, reviews, inline review comments, and issue comments. 5. **Resolve anomalies.** If mapping is weak, apply the Provenance Mesh: commit association + patch equivalence + content/symbol lineage. 6. **Extract decision atoms.** Convert evidence into explicit claims: constraints, compatibility requirements, security invariants, performance constraints, rejected approaches, test requirements. 7. **Assess risk.** Downgrade confidence for semantic-only matches, path-only matches, reverted PRs, API truncation, large PRs, generated files, or missing PRs. 8. **Produce a history note** before editing code. ## Evidence confidence rules High confidence: - exact GitHub commit→PR association; or - patch/hunk equivalence plus path/symbol agreement; or - review comment remaps to the current hunk/symbol and matches the proposed change. Medium confidence: - same symbol/path plus relevant PR discussion, but no patch-level match. Low confidence: - semantic search only, title/body match only, path-only match, or stale/reverted evidence. Never claim “this was decided” unless a commit, PR body, review, review comment, issue comment, or linked issue supports it. ## Output template Use this concise template in the final answer or implementation plan: ```markdown ## History note Scope inspected: [paths, lines, symbols] Relevant evidence: - PR #[n] — [relation: exact/squash-like/rename-lineage/search], [why relevant], [confidence] - Commit [sha] — [what it changed], [relation] - Review/comment — [constraint or concern] Decision atoms: - [constraint/risk/rejected approach/test requirement] — [claim] — evidence: [PR/comment/commit] Risk: [low|medium|high|unknown] Confidence: [0.00-1.00] Unknowns/truncation: [none or list] Plan impact: [proceed|modify plan|ask human|do not change] ``` ## Gotchas - `git blame` is a seed generator, not truth. Formatting commits, moves, squashes, and refactors can hide origin. - A PR can be relevant even if it did not introduce the current line; review comments may explain why an alternative was rejected. - Squash merges often require patch/hunk matching because the final commit SHA differs from PR commits. - File paths are not identity. Track file lineage, directory moves, symbol fingerprints, and hunk context. - Reverted PRs are stale evidence unless a later PR reintroduced the same decision. - Large `gh api` responses may be truncated by the underlying GitHub endpoints. If truncation is possible, mark evidence incomplete. - General PR conversation comments come from issue comments; inline review comments come from PR review comments. ## Available scripts - `scripts/history_context.py` — main collector for local Git + GitHub PR evidence. Run `python3 scripts/history_context.py --help`. - `scripts/compact_pr.py` — fetch one or more PRs and print compact evidence. Run `python3 scripts/compact_pr.py --help`. - `scripts/validate_skill.py` — validate this skill’s frontmatter and basic structure.
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.