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
18 lines · 830 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, so no record was cut or lost.
7 *
8 * Every record is terminated (NUL for `-z` listings, a newline for line
9 * records) and the text is short of the host's output cap by MOST_UTF8_BYTES,
10 * what a cut inside a multi-byte character can cost the decoded text.
11 *
12 * @param stdout the listing as `$.process.run` returned it
13 * @param terminator what ends every record; NUL when absent
14 * @returns whether it can be parsed as the whole answer
15 */
16export const isWholeListing = (stdout: string, terminator = '\0') =>
17 (stdout === '' || stdout.endsWith(terminator)) &&
18 isUnderUtf8Ceiling(stdout, Limits.HOST_OUTPUT_CAP_BYTES - MOST_UTF8_BYTES)