Something went wrong. Try again.
source dump of claude code forked from oppi.li/claude-code
Something went wrong. Try again.
1.2 kB · 38 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839import { validateBoundedIntEnvVar } from '../envValidation.js'import { getTaskOutputPath } from './diskOutput.js'
export const TASK_MAX_OUTPUT_UPPER_LIMIT = 160_000export const TASK_MAX_OUTPUT_DEFAULT = 32_000
export function getMaxTaskOutputLength(): number { const result = validateBoundedIntEnvVar( 'TASK_MAX_OUTPUT_LENGTH', process.env.TASK_MAX_OUTPUT_LENGTH, TASK_MAX_OUTPUT_DEFAULT, TASK_MAX_OUTPUT_UPPER_LIMIT, ) return result.effective}
/** * Format task output for API consumption, truncating if too large. * When truncated, includes a header with the file path and returns * the last N characters that fit within the limit. */export function formatTaskOutput( output: string, taskId: string,): { content: string; wasTruncated: boolean } { const maxLen = getMaxTaskOutputLength()
if (output.length <= maxLen) { return { content: output, wasTruncated: false } }
const filePath = getTaskOutputPath(taskId) const header = `[Truncated. Full output: ${filePath}]\n\n` const availableSpace = maxLen - header.length const truncated = output.slice(-availableSpace)
return { content: header + truncated, wasTruncated: true }}