π File detail
utils/task/outputFormatting.ts
π§© .tsπ 39 linesπΎ 1,188 bytesπ text
β Back to All Filesπ― Use case
This file lives under βutils/β, which covers cross-cutting helpers (shell, tempfiles, settings, messages, process input, β¦). On the API surface it exposes TASK_MAX_OUTPUT_UPPER_LIMIT, TASK_MAX_OUTPUT_DEFAULT, getMaxTaskOutputLength, and formatTaskOutput β mainly functions, hooks, or classes. It composes internal code from envValidation and diskOutput (relative imports).
Generated from folder role, exports, dependency roots, and inline comments β not hand-reviewed for every path.
π§ Inline summary
import { validateBoundedIntEnvVar } from '../envValidation.js' import { getTaskOutputPath } from './diskOutput.js' export const TASK_MAX_OUTPUT_UPPER_LIMIT = 160_000 export const TASK_MAX_OUTPUT_DEFAULT = 32_000
π€ Exports (heuristic)
TASK_MAX_OUTPUT_UPPER_LIMITTASK_MAX_OUTPUT_DEFAULTgetMaxTaskOutputLengthformatTaskOutput
π₯οΈ Source preview
import { validateBoundedIntEnvVar } from '../envValidation.js'
import { getTaskOutputPath } from './diskOutput.js'
export const TASK_MAX_OUTPUT_UPPER_LIMIT = 160_000
export 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 }
}