-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsummaries.ts
More file actions
38 lines (33 loc) · 932 Bytes
/
Copy pathsummaries.ts
File metadata and controls
38 lines (33 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* [LAYER: CORE]
* Bounded summaries for JoyRide execution artifacts.
*/
import { Buffer } from "node:buffer"
export interface JoyRideCommandOutputSummary {
text: string
originalBytes: number
summaryBytes: number
truncated: boolean
}
export function summarizeJoyRideCommandOutput(output: string, maxChars = 12_000): JoyRideCommandOutputSummary {
const originalBytes = Buffer.byteLength(output, "utf8")
if (output.length <= maxChars) {
return {
text: output,
originalBytes,
summaryBytes: originalBytes,
truncated: false,
}
}
const headLength = Math.max(0, Math.floor(maxChars * 0.65))
const tailLength = Math.max(0, maxChars - headLength)
const text = `${output.slice(0, headLength)}\n\n[JoyRide summary truncated ${output.length - maxChars} chars]\n\n${output.slice(
-tailLength,
)}`
return {
text,
originalBytes,
summaryBytes: Buffer.byteLength(text, "utf8"),
truncated: true,
}
}