surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| 1 | /** |
| 2 | * Git's output in /work for each invocation whose command line holds the |
| 3 | * key, over the given `--numstat -z` records and per-file bodies. |
| 4 | * |
| 5 | * `status` lists the paths dirty at the start (the baseline: every path |
| 6 | * with a body unless given); a body is keyed by the `-- <path>` its diff is |
| 7 | * asked with. |
| 8 | * |
| 9 | * @param numstat the `--numstat -z` records, joined |
| 10 | * @param bodies each path's unified diff after its header |
| 11 | * @param dirty the paths `status` lists as dirty when the session starts |
| 12 | * @returns the answers by key |
| 13 | */ |
| 14 | export const answersOf = ( |
| 15 | numstat: string, |
| 16 | bodies: Readonly<Record<string, string>>, |
| 17 | dirty: readonly string[] = Object.keys(bodies), |
| 18 | ): Readonly<Record<string, string>> => ({ |
| 19 | 'rev-parse --path-format=absolute': '/work\n/work/.git\n/work/.git\n', |
| 20 | 'status --porcelain': dirty.map(path => ` M ${path}\0`).join(''), |
| 21 | 'HEAD --shortstat': ` ${Object.keys(bodies).length} files changed`, |
| 22 | 'HEAD --numstat': numstat, |
| 23 | 'ls-files': '', |
| 24 | ...Object.fromEntries( |
| 25 | Object.entries(bodies).map(([path, body]) => [`-- ${path}`, body]), |
| 26 | ), |
| 27 | }) |