nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Feature] Include a git snapshot (branch, status, recent commits) in the session prompt

Open akramcodez opened this issue 2 weeks ago • 1 comments

Description

The system prompt includes OS, shell, home directory, working directory and date, and nothing about the repository state (generateSystemInfo in source/conversation/prompt-builder.ts). The model does not know the current branch, whether the tree is dirty, or what the last few commits were unless it spends a tool call to find out.

Use Case

Almost every session starts with the model running git status and git log, which costs a turn and an approval prompt on small local models, or never happens and the model gives advice that ignores uncommitted work, an in-progress rebase, or being on a detached HEAD. Claude Code and Codex CLI both start sessions with a compact git snapshot (branch, short status, recent commits) so the first answer is already grounded.

Proposed Solution

At session start, when the folder is a git repository, add a small block to the prompt: current branch (or detached HEAD), default branch, upstream ahead/behind counts, a short git status summary (counts plus up to N changed paths), and the last 3 to 5 commit subjects. Hard caps on size, a config switch (nanocoder.gitContext, default on, off in the nano profile), and no network access (local git only, with the same safe flags the git tools use). The block is labelled as a snapshot from session start so the model knows to re-check before acting on it.

Alternatives Considered

  • Let the model call the git tools itself. Costs a turn per session and depends on the model choosing to do it.
  • Put it in AGENTS.md. It changes every commit, so it cannot live there.

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] This feature aligns with the project's goals (local-first AI assistance)

Implementation Notes (optional)

Reuse the existing git helpers under source/tools/ rather than adding a second git runner, and make sure large repositories and missing git binaries degrade to an empty block rather than a slow or failing start.

akramcodez avatar Nov 17 '26 08:11 akramcodez

Hi, I'd like to pick this up. Plan: a small git-context module that reads the branch and default branch from .git (existing sync helpers), runs git status --porcelain --branch and git log -n5 once per session with the same read-only flags as the git tools (plus GIT_OPTIONAL_LOCKS=0, short timeouts, output cap), and adds a capped, clearly-labelled "snapshot from session start" block after system info. Skipped under the nano profile and behind nanocoder.gitContext (default on); outside a repo or without git it adds nothing and spawns nothing. Could you assign it to me?

utsxvrai avatar Nov 21 '26 11:11 utsxvrai