File size: 744 Bytes
b7b13c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
export function parseExecShellCommandError(
	toolResultString: string | undefined
): string | undefined {
	if (!toolResultString) return undefined;

	// Exec results are usually large plain-text stdout; only a JSON object
	// root can carry an error field, so skip the parse otherwise
	const trimmed = toolResultString.trimStart();

	if (trimmed[0] !== '{') return undefined;

	try {
		const parsed: unknown = JSON.parse(trimmed);

		if (
			parsed &&
			typeof parsed === 'object' &&
			!Array.isArray(parsed) &&
			typeof (parsed as Record<string, unknown>).error === 'string'
		) {
			return (parsed as { error: string }).error;
		}
	} catch {
		// Plain-text result = stdout/stderr, no structured error to surface.
	}

	return undefined;
}