mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 18:55:22 +00:00
feat(permission): integrate auto-review and hard guards
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const DEFAULT_PROVIDER = "openai-codex";
|
||||
export const DEFAULT_MODEL = "codex-auto-review";
|
||||
export const DEFAULT_TIMEOUT_MS = 90_000;
|
||||
export const DEFAULT_ANALYSIS_THRESHOLD = 500;
|
||||
export const DEFAULT_RETAIN_ANALYZED_BATCHES = 2;
|
||||
|
||||
export const REASONING_LEVELS = [
|
||||
"off",
|
||||
"minimal",
|
||||
"low",
|
||||
"medium",
|
||||
"high",
|
||||
"xhigh",
|
||||
"max",
|
||||
] as const;
|
||||
|
||||
export const autoReviewConfigFileSchema = z
|
||||
.strictObject({
|
||||
enabled: z.boolean().optional(),
|
||||
provider: z.string().trim().min(1).optional(),
|
||||
model: z.string().trim().min(1).optional(),
|
||||
reasoning: z.enum(REASONING_LEVELS).optional(),
|
||||
timeoutMs: z.number().int().positive().max(300_000).optional(),
|
||||
includeBaselinePolicy: z.boolean().optional(),
|
||||
additionalPolicy: z.string().trim().min(1).optional(),
|
||||
})
|
||||
.superRefine((value, context) => {
|
||||
if (value.includeBaselinePolicy === false && value.additionalPolicy === undefined) {
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
message: "additionalPolicy is required when includeBaselinePolicy is false",
|
||||
path: ["additionalPolicy"],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export const analysisConfigFileSchema = z.strictObject({
|
||||
enabled: z.boolean().optional(),
|
||||
threshold: z.number().int().min(1).max(100_000).optional(),
|
||||
retainAnalyzedBatches: z.number().int().min(0).max(20).optional(),
|
||||
timeoutMs: z.number().int().positive().max(300_000).optional(),
|
||||
});
|
||||
|
||||
export type AutoReviewConfigFile = z.infer<typeof autoReviewConfigFileSchema>;
|
||||
export type AutoReviewAnalysisConfigFile = z.infer<typeof analysisConfigFileSchema>;
|
||||
|
||||
export interface AutoReviewConfig {
|
||||
enabled: boolean;
|
||||
provider: string;
|
||||
model: string;
|
||||
reasoning: (typeof REASONING_LEVELS)[number];
|
||||
timeoutMs: number;
|
||||
includeBaselinePolicy: boolean;
|
||||
additionalPolicy?: string;
|
||||
}
|
||||
|
||||
export interface AutoReviewAnalysisConfig {
|
||||
enabled: boolean;
|
||||
threshold: number;
|
||||
retainAnalyzedBatches: number;
|
||||
timeoutMs: number;
|
||||
}
|
||||
|
||||
export const DEFAULT_AUTO_REVIEW_CONFIG: AutoReviewConfig = {
|
||||
enabled: true,
|
||||
provider: DEFAULT_PROVIDER,
|
||||
model: DEFAULT_MODEL,
|
||||
reasoning: "low",
|
||||
timeoutMs: DEFAULT_TIMEOUT_MS,
|
||||
includeBaselinePolicy: true,
|
||||
};
|
||||
|
||||
export const DEFAULT_AUTO_REVIEW_ANALYSIS_CONFIG: AutoReviewAnalysisConfig = {
|
||||
enabled: true,
|
||||
threshold: DEFAULT_ANALYSIS_THRESHOLD,
|
||||
retainAnalyzedBatches: DEFAULT_RETAIN_ANALYZED_BATCHES,
|
||||
timeoutMs: DEFAULT_TIMEOUT_MS,
|
||||
};
|
||||
|
||||
export function normalizeAutoReviewConfig(
|
||||
value?: AutoReviewConfigFile,
|
||||
): AutoReviewConfig {
|
||||
return {
|
||||
...DEFAULT_AUTO_REVIEW_CONFIG,
|
||||
...value,
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeAutoReviewAnalysisConfig(
|
||||
value?: AutoReviewAnalysisConfigFile,
|
||||
): AutoReviewAnalysisConfig {
|
||||
return {
|
||||
...DEFAULT_AUTO_REVIEW_ANALYSIS_CONFIG,
|
||||
...value,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user