Skip to content

Add --json output mode (Bounty: $2 crypto)#51

Open
qlufiq-collab wants to merge 16 commits into
promptpolish-ai:mainfrom
qlufiq-collab:bounty/promptpolish-ai/git-context-2
Open

Add --json output mode (Bounty: $2 crypto)#51
qlufiq-collab wants to merge 16 commits into
promptpolish-ai:mainfrom
qlufiq-collab:bounty/promptpolish-ai/git-context-2

Conversation

@qlufiq-collab

@qlufiq-collab qlufiq-collab commented Jun 12, 2026

Copy link
Copy Markdown

Summary

Add a --json flag to git-context so the generated repo context can be consumed programmatically. With --json, the tool emits a structured JSON document instead of the human-readable Markdown block, while preserving every existing flag and code path.

Changes

  • git-context — Add import json, register --json argument, refactor main() to collect git/tree/file data once and branch on --json to either emit json.dumps(..., indent=2) or the existing Markdown sections.
  • git_context/__init__.py — Same change; this file is kept identical to the standalone script (it is the package entry point).

Test Plan

  • python3 git-context --json | python3 -m json.tool → valid JSON with keys repo, generated, path, git, log, branches, tree.
  • python3 git-context --json --files → JSON document additionally contains a files key with source contents.
  • python3 git-context --json -o /tmp/ctx.json → writes valid JSON to disk; json.load succeeds.
  • python3 git-context → unchanged Markdown output (default text mode is untouched).
  • python3 -m git_context --json → module entry point produces the same JSON.

Notes

  • Zero new dependencies; json is in the stdlib.
  • JSON shape: git is an object with branch, remote, unstaged, staged, clean; log and branches are arrays of lines for easy iteration; tree and files are kept as preformatted strings to match the existing rendering.
  • --json composes with --depth, --files, --log, --output, and --dir.

Closes #2

lufiaq and others added 16 commits June 12, 2026 03:54
## Summary

Add a `--json` flag to `git-context` so the generated repo context can be consumed programmatically. With `--json`, the tool emits a structured JSON document instead of the human-readable Markdown block, while preserving every existing flag and code path.

## Changes

- `git-context` — Add `import json`, register `--json` argument, refactor `main()` to collect git/tree/file data once and branch on `--json` to either emit `json.dumps(..., indent=2)` or the existing Markdown sections.
- `git_context/__init__.py` — Same change; this file is kept identical to the standalone script (it is the package entry point).

## Test Plan

- `python3 git-context --json | python3 -m json.tool` → valid JSON with keys `repo`, `generated`, `path`, `git`, `log`, `branches`, `tree`.
- `python3 git-context --json --files` → JSON document additionally contains a `files` key with source contents.
- `python3 git-context --json -o /tmp/ctx.json` → writes valid JSON to disk; `json.load` succeeds.
- `python3 git-context` → unchanged Markdown output (default text mode is untouched).
- `python3 -m git_context --json` → module entry point produces the same JSON.

## Notes

- Zero new dependencies; `json` is in the stdlib.
- JSON shape: `git` is an object with `branch`, `remote`, `unstaged`, `staged`, `clean`; `log` and `branches` are arrays of lines for easy iteration; `tree` and `files` are kept as preformatted strings to match the existing rendering.
- `--json` composes with `--depth`, `--files`, `--log`, `--output`, and `--dir`.

Closes promptpolish-ai#2

Bounty: promptpolish-ai#2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --json output mode (Bounty: $2 crypto)

1 participant