mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-24 10:13:11 +02:00
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>
24 lines
1.1 KiB
TypeScript
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;
|
|
}
|