const EXPECTED_TOOL_VALIDATION_FAILURES = {
    edit: [
        "file must be read first before editing",
        "file has been modified since it was read",
        "the file changed since you read it (anchor mismatch)",
        "old_text and new_text are identical",
        "invalid edit:",
        "span overlaps another span edit",
        "old_text found ",
        "old_text not found in ",
    ],
    write: [
        "file must be read first before editing",
        "existing files must be read first before overwriting",
        "file has been modified since it was read",
    ],
};
export function shouldCaptureUsagePollingError(error) {
    if (typeof error !== "object" || error === null || !("status" in error))
        return true;
    return error.status !== 429 && error.status !== "429";
}
export function shouldCaptureToolFailure(toolName, result) {
    const expectedFailures = EXPECTED_TOOL_VALIDATION_FAILURES[toolName];
    if (!expectedFailures)
        return true;
    const normalizedResult = result.toLowerCase();
    return !expectedFailures.some((fragment) => normalizedResult.includes(fragment));
}
function errorMomReporter() {
    return globalThis
        .__GG_ERROR_MOM__;
}
function sidecarProcessTag() {
    if (process.argv.includes("--subagent-worker"))
        return "subagent-worker";
    if (process.argv.includes("--json"))
        return "json-worker";
    return "app-sidecar";
}
export function captureSidecarError(error, culprit, tags = {}, context) {
    errorMomReporter()?.captureError(error, {
        culprit,
        tags: { process: sidecarProcessTag(), ...tags },
        ...(context ? { context } : {}),
    });
}
export async function flushSidecarErrors() {
    await errorMomReporter()?.flush();
}
export function wrapSidecarHandler(fn, culprit) {
    return (errorMomReporter()?.wrap(fn, {
        culprit,
        tags: { process: sidecarProcessTag() },
    }) ?? fn);
}
//# sourceMappingURL=sidecar-error-reporter.js.map