Files
PaperClipAI/ui/src/hooks/useExecutionPolicy.ts
T
Devin FoleyandPaperclip 317ed367d4 Handle incomplete task policies and preserve review limits (#15593)
Apply the reviewed change for Handle incomplete task policies and preserve review limits.

Validation: local typecheck/build and focused regression tests, passing exact-head CI, Greptile 5/5, and independent source review. The PR records full-suite evidence and any local environment limitations.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-08 10:20:32 -07:00

24 lines
1.1 KiB
TypeScript

import { useEffect, useMemo, useRef } from "react";
import { readExecutionPolicy } from "../lib/issue-execution-policy";
import { captureBrowserException } from "../lib/sentry";
/** Keep an invalid policy visible without crashing the task or enabling edits. */
export function useExecutionPolicy(value: unknown) {
const result = useMemo(() => readExecutionPolicy(value), [value]);
const reported = useRef(false);
useEffect(() => {
if (result.success || reported.current) return;
reported.current = true;
// Schema diagnostics can contain the original data. Report only a closed
// field category, once per mounted component, through the existing gate.
const field = result.error.issues[0]?.path[0];
const category = field === "stages" ? "stages"
: field === "monitor" ? "monitor"
: field === "authorizationPolicy" ? "authorization"
: field === "reviewPreset" ? "review_preset"
: "policy";
captureBrowserException(new Error(`Invalid task execution policy (${category})`));
}, [result]);
return result;
}