Parent directory

types.ts

2624 bytes
  1export const DECISION_CATEGORIES = [
  2  "read_only",
  3  "build_test",
  4  "git_local",
  5  "git_remote",
  6  "file_mutation",
  7  "system",
  8  "network",
  9  "uncertain",
 10  "dangerous",
 11  "config_allow",
 12  "web_read",
 13  "empty",
 14  "session_allow",
 15  "external_directory",
 16  "bash",
 17  "read",
 18  "write",
 19  "edit",
 20  "find",
 21  "grep",
 22  "ls",
 23  "webfetch",
 24] as const;
 25
 26export type DecisionCategory = (typeof DECISION_CATEGORIES)[number];
 27
 28const decisionCategorySet: ReadonlySet<string> = new Set(DECISION_CATEGORIES);
 29
 30export function isDecisionCategory(value: unknown): value is DecisionCategory {
 31  return typeof value === "string" && decisionCategorySet.has(value);
 32}
 33
 34export type Decision = {
 35  decision: "allow" | "deny" | "ask";
 36  reason: string;
 37  category: DecisionCategory;
 38};
 39
 40export type LLMEvaluationResult = {
 41  decision: Decision;
 42  source?: "llm" | "none";
 43  rawResponse?: string;
 44  error?: string;
 45};
 46
 47export type PolicyReviewer = {
 48  evaluate(request: PolicyRequest, context: PolicyContext): Promise<LLMEvaluationResult>;
 49};
 50
 51export type PiReasoningEffort = "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
 52
 53export type ReviewerConfig =
 54  | {
 55      kind: "none";
 56    }
 57  | {
 58      kind: "pi";
 59      provider: string;
 60      model: string;
 61      reasoningEffort?: PiReasoningEffort;
 62      promptCacheKey?: string;
 63    }
 64  | {
 65      kind: "llama.cpp";
 66      baseUrl: string;
 67      model: string;
 68      enableThinking: boolean;
 69    };
 70
 71export type CacheEntry = {
 72  key: string;
 73  toolName: string;
 74  decision: Decision;
 75  source: "llm";
 76  createdAt: string;
 77};
 78
 79export type DecisionCache = {
 80  lookup(key: string): Promise<Decision | undefined>;
 81  write(entry: CacheEntry): Promise<void>;
 82};
 83
 84export type DecisionSource = "session" | "static" | "deterministic" | "cache" | "llm" | "none";
 85
 86export type AuditEntry = {
 87  toolName: string;
 88  inputSummary: string;
 89  decision: Decision;
 90  source: DecisionSource;
 91  timingMs: number;
 92  sessionId?: string;
 93  rawResponse?: string;
 94};
 95
 96export type DecisionAudit = {
 97  record(entry: AuditEntry): Promise<void>;
 98};
 99
100export type PolicyEvaluation = {
101  decision: Decision;
102  source: DecisionSource;
103  rawResponse?: string;
104  error?: string;
105  approvalRequests?: PolicyRequest[];
106};
107
108export type PolicyRequest = {
109  toolName: string;
110  input: Record<string, unknown>;
111};
112
113export type PolicyContext = {
114  sessionId?: string;
115  cwd?: string;
116  signal?: AbortSignal;
117};
118
119export type PolicyPrecheck = {
120  source: Exclude<DecisionSource, "llm" | "cache" | "deterministic" | "none">;
121  decide(request: PolicyRequest, context: PolicyContext): Promise<Decision | undefined>;
122};