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
17 lines · 722 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 `-z` listing arrived whole: every record NUL-terminated and
7 * the text short of the host's output cap, so no record was cut or lost.
8 *
9 * A cut inside a multi-byte character costs the decoded text up to
10 * MOST_UTF8_BYTES, hence the margin under the cap.
11 *
12 * @param stdout the listing as `$.process.run` returned it
13 * @returns whether it can be parsed as the whole answer
14 */
15export const isWholeListing = (stdout: string) =>
16 (stdout === '' || stdout.endsWith('\0')) &&
17 isUnderUtf8Ceiling(stdout, Limits.HOST_OUTPUT_CAP_BYTES - MOST_UTF8_BYTES)