Prepare CONTEXT, FILES, and DIFF for downstream automation by preferring a local git diff between PR base/head (or provided SHAs), and falling back to fetching a PR .diff over HTTPS when necessary. Returns prioritized file lists and batch metadata as action outputs.
Now supports optional adaptive chunking of changed files for large diffs.
- PR mode: Prefer local git diff between PR base/head; fallback to HTTPS
.diff - Non‑PR mode: Use
git diff <base_sha> <head_sha> - Extracts changed files from the diff
- Optional chunk prioritization via
critical_paths_jsonglob patterns - Outputs minified context JSON;
CHANGED_FILESandDIFFas JSON string literals; also writes file outputs under.ai/
token(optional; required in PR mode): GitHub token for API requestsrepository(optional):owner/repooverride (defaults toGITHUB_REPOSITORY)pr_number(optional): PR number override; if empty, falls back to SHAscontext_path(optional): Path to a JSON file with optionalcritical_pathsarraybase_sha(optional): Base commit SHA for non‑PR modehead_sha(optional): Head commit SHA for non‑PR mode
chunking_enabled: "true" to enable adaptive chunking (default: "false")max_diff_lines_per_chunk: integer budget for added+deleted per chunk (default: "1500")max_files_per_chunk: optional cap on number of files per chunk (default: unset)include_globs: CSV of globs to include (e.g.,*.swift,*.m)exclude_globs: CSV of globs to excludecritical_paths_json: JSON array of globs to prioritize earlier (e.g.,["**/Payments/**"])
CONTEXT: Minified JSON string of the provided context file (or{})TOTAL_FILES: Total changed files countCHANGED_FILES: JSON string literal of the newline‑joined list of changed filesDIFF: JSON string literal of the full diff content (may be large)DIFF_FILE: Absolute path to the full unified diff file (e.g.,.ai/diff.all.patch)CHANGED_FILES_FILE: Absolute path to the newline‑joined changed files file (e.g.,.ai/files.all.txt)
When chunking is enabled, additional outputs are provided:
CHUNK_COUNT: Number of generated chunksCHUNK_IDS_JSON: JSON array of chunk IDs as strings, e.g.,["0","1"]CHUNK_MANIFEST_DIR: Directory path containing manifests:files.<id>.txt: newline‑joined files in the chunkdiff.<id>.patch: unified diff for those files
- name: Prepare diff/context
uses: GulerSevil/actions-diff-patch@<ref>
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
pr_number: ${{ github.event.pull_request.number }}
context_path: .github/prompts/ios-risk-context.json
chunking_enabled: "true"
max_diff_lines_per_chunk: "1500"
include_globs: "*.swift,*.m"- name: Prepare diff/context
uses: GulerSevil/actions-diff-patch@<ref>
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
base_sha: ${{ github.sha }}^ # example: previous commit
head_sha: ${{ github.sha }}
context_path: .github/prompts/ios-risk-context.json
chunking_enabled: "true"- name: Prepare diff/context
id: prep
uses: GulerSevil/actions-diff-patch@<ref>
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
pr_number: ${{ github.event.pull_request.number }}
chunking_enabled: "true"
- name: Run AI for each chunk
if: steps.prep.outputs.CHUNK_COUNT != '0'
uses: some/ai-action@v1
with:
manifest_dir: ${{ steps.prep.outputs.CHUNK_MANIFEST_DIR }}
chunk_ids_json: ${{ steps.prep.outputs.CHUNK_IDS_JSON }}- name: Print all outputs
run: |
echo "CONTEXT=${{ steps.prep.outputs.CONTEXT }}"
echo "TOTAL_FILES=${{ steps.prep.outputs.TOTAL_FILES }}"
echo "CHANGED_FILES=${{ steps.prep.outputs.CHANGED_FILES }}"
echo "DIFF=${{ steps.prep.outputs.DIFF }}" # may be large
echo "DIFF_FILE=${{ steps.prep.outputs.DIFF_FILE }}"
echo "CHANGED_FILES_FILE=${{ steps.prep.outputs.CHANGED_FILES_FILE }}"
echo "CHUNK_COUNT=${{ steps.prep.outputs.CHUNK_COUNT }}"
echo "CHUNK_IDS_JSON=${{ steps.prep.outputs.CHUNK_IDS_JSON }}"
echo "CHUNK_MANIFEST_DIR=${{ steps.prep.outputs.CHUNK_MANIFEST_DIR }}"Provide critical_paths_json as a JSON array of globs (e.g., ["**/Payments/**", "**/*.swift"]). These globs are used to prioritize files into earlier chunks when chunking is enabled. This does not change the order of CHANGED_FILES.
["src/core/**", "infrastructure/**"]src/core/config/inputs.ts: parses all action inputs (including chunking and globs)src/core/filters/globs.ts: CSV parsing, include/exclude filtering, critical-path checkssrc/core/chunking/chunking.ts: file size computation, sorting, bin packing, manifest writingsrc/core/diff/diff.ts: diff utilities (file extraction, filtering, prioritization helpers)src/core/io/fsio.tsandsrc/core/io/context.ts: file I/O utilities and context loadersrc/adapters/http.tsandsrc/adapters/git.ts: network and git adapterssrc/index.ts: orchestration using the modules above
Requirements: Node 20+
- Install:
npm install - Build:
npm run build - Test:
npm run testornpm run test:watch
The TypeScript sources are under src/. Tests live under tests/ and are executed with Vitest.
- If
pr_numberis provided, the action attempts to fetch the.diffvia HTTPS first; on failure, it falls back togit diffifbase_shaandhead_shaare provided. - Ensure the token has permission to access the PR if using private repositories.
- Chunking is disabled by default and does not affect legacy outputs when off.