Skip to content

install-hooks: prompt to confirm author identity when an API key is set - #2227

Open
svarlamov-git-ai wants to merge 2 commits into
feat/read-line-with-timeoutfrom
feat/install-hooks-author-prompt
Open

install-hooks: prompt to confirm author identity when an API key is set#2227
svarlamov-git-ai wants to merge 2 commits into
feat/read-line-with-timeoutfrom
feat/install-hooks-author-prompt

Conversation

@svarlamov-git-ai

@svarlamov-git-ai svarlamov-git-ai commented Aug 26, 2026

Copy link
Copy Markdown

Summary

On git-ai install-hooks, interactively prompt the user to confirm or override the author name/email used for AI-authorship attribution, and persist it to ~/.git-ai/config.json (author.name / author.email) so the prompt never reappears.

The prompt only fires when ALL of these hold — otherwise it skips silently:

  • stdin and stdout are real TTYs (GIT_AI_TEST_FORCE_TTY overrides for tests),
  • no git-ai author override is configured yet (if either author.name or author.email is set, skip),
  • an API key is present (GIT_AI_API_KEY env, config api_key, or the --api-key/API_KEY value persisted by this install run) — OSS installs are never prompted,
  • not --dry-run,
  • GIT_AI_NO_AUTHOR_PROMPT is not set (hard opt-out for scripts/CI).

UX: two line prompts (name, then email), each pre-filled from the git committer identity (git var GIT_COMMITTER_IDENT via the existing current_git_committer_identity_resolution()); Enter accepts the default. No input for 15s (via read_line_with_timeout from the PR below) aborts the prompt entirely and the install continues.

The prompt runs after persist_install_config_with_values (so a just-passed --api-key counts) and before async_run_install (so it never interleaves with spinner output). It is best-effort and can never fail the install.

Notes / risks

  • After a stdin timeout the leaked reader thread may hold stdin until process exit — the prompt aborts entirely on the first timeout and never reads stdin again (documented invariant on the helper).
  • In-process tests that call run(&[]) from a dev machine with a real TTY, an API key, and no author config could hit the prompt locally; the 15s timeout self-heals and GIT_AI_NO_AUTHOR_PROMPT is a hard escape hatch. CI is unaffected (non-TTY stdin).
  • One extra git var spawn only on the interactive prompt path of this one-shot command — not on any daemon/ingestion path.

Tests (TDD)

  • Unit: should_prompt_for_author truth table; prompt_author_identity via injected scripted reader/writer (confirm defaults, override, mixed, timeout on first/second prompt, all-empty, bracketed defaults in output).
  • Integration (spawned binary, isolated test HOME): non-TTY skips; forced-TTY + piped stdin saves author to config.json; pre-set author skips; no API key skips; --dry-run skips.

🤖 Generated with Claude Code

On interactive, non-dry-run installs where an API key is configured
(hosted usage) and no git-ai author override exists yet, prompt the user
to confirm or override the author name/email used for AI-authorship
attribution, defaulting to the git committer identity. The confirmed
values are saved to ~/.git-ai/config.json so the prompt never reappears.

The prompt is best-effort: it skips on non-TTY stdin/stdout, when the
GIT_AI_NO_AUTHOR_PROMPT env var is set, and after 15 seconds without
input (via read_line_with_timeout), and it never fails the install.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@svarlamov-git-ai
svarlamov-git-ai marked this pull request as ready for review August 26, 2026 19:15

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

- Default the prompt from the explicit global git config identity instead
  of `git var GIT_COMMITTER_IDENT`, which fabricates user@hostname on
  unconfigured machines and would have been persisted on Enter.
- Re-load the file config after the prompt completes so saving cannot
  clobber a concurrent config change made while waiting on input.
- Treat GIT_AI_NO_AUTHOR_PROMPT="", "0", "false" as not opted out,
  matching the repo's boolean env convention.
- Derive the auto-skip seconds in the banner from AUTHOR_PROMPT_TIMEOUT
  and clarify the timeout applies per prompt.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

2 participants