spacehub

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

claude-code / mods / diff / hooks / git / parse / is-whole-listing / is-whole-listing.ts
19 lines · 860 BRaw
1import Limits from '../../../limits'
2import { isUnderUtf8Ceiling } from './is-under-utf8-ceiling'
3import { MOST_UTF8_BYTES } from './most-utf8-bytes'
4
5/**
6 * Whether a listing arrived whole: every record terminated (NUL for git's
7 * `-z` listings, a newline for line records) and the text short of the
8 * host's output cap, so no record was cut or lost.
9 *
10 * A cut inside a multi-byte character costs the decoded text up to
11 * MOST_UTF8_BYTES, hence the margin under the cap.
12 *
13 * @param stdout the listing as `$.process.run` returned it
14 * @param terminator what ends every record; NUL when absent
15 * @returns whether it can be parsed as the whole answer
16 */
17export const isWholeListing = (stdout: string, terminator = '\0') =>
18 (stdout === '' || stdout.endsWith(terminator)) &&
19 isUnderUtf8Ceiling(stdout, Limits.HOST_OUTPUT_CAP_BYTES - MOST_UTF8_BYTES)