Repository navigation
Expand file tree
/
Copy pathtypes.ts
More file actions
154 lines (138 loc) · 3.85 KB
/
Copy pathtypes.ts
File metadata and controls
154 lines (138 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
* Shared SpecSync contracts. Confidence is always in [0, 1].
*/
/** Confidence score in [0, 1] only. Normalize at the LLM parse boundary. */
export type Confidence = number;
/**
* GitHub pull-request review comment side.
* LEFT = base/old file (pure deletions); RIGHT = head/new file (adds/modifies).
*/
export type DiffSide = "LEFT" | "RIGHT";
export interface SpecSuggestion {
functionName: string;
filePath: string;
lineNumber: number;
/** Review-comment side; defaults to RIGHT when omitted. */
side?: DiffSide;
preconditions: string[];
postconditions: string[];
invariants: string[];
edgeCases?: string[];
confidence: Confidence;
reasoning: string;
/** True when the suggestion came from the mock LLM fallback (not a live provider). */
isMock?: boolean;
}
export interface ProofFunctionStatus {
name: string;
filePath: string;
line: number;
hasProof: boolean;
theorem?: string;
lastVerified?: string;
}
export interface ProofResult {
theorem: string;
file: string;
valid: boolean;
}
export interface ProofStatus {
coverage: number;
totalFunctions: number;
coveredFunctions: number;
failedProofs: number;
functions: ProofFunctionStatus[];
proofs: ProofResult[];
}
export interface DriftFinding {
functionName: string;
filePath: string;
reason: string;
previousSpec?: string;
currentImplementation?: string;
confidence?: Confidence;
}
/** Payload for the analysis job queue (Phase 2). */
export interface AnalysisJobPayload {
installationId: number;
owner: string;
repo: string;
pr: number;
headSha: string;
}
/** Soft LLM cost estimate logged per analysis job. */
export interface SoftCostEstimate {
estimatedTokens: number;
llmCalls: number;
cappedAt: number;
skippedByBudget?: number;
}
/**
* Normalize a confidence value to [0, 1].
* Values greater than 1 are treated as a 0–100 percentage scale.
*/
export function normalizeConfidence(value: unknown, fallback = 0.5): Confidence {
if (typeof value !== "number" || Number.isNaN(value)) {
return fallback;
}
const scaled = value > 1 ? value / 100 : value;
return Math.min(1, Math.max(0, scaled));
}
/** Changed file metadata from GitHub pulls.listFiles / paginate. */
export interface ChangedFile {
filename: string;
status?: string;
additions?: number;
deletions?: number;
changes?: number;
patch?: string;
}
/** Diff-parser output for a single function change. */
export interface FunctionChange {
filePath: string;
functionName: string;
functionBody: string;
lineNumber: number;
/** LEFT for pure deletions; RIGHT otherwise. */
side: DiffSide;
changeType: string;
comments: Array<{ text: string; lineNumber: number; type: string }>;
testFiles: string[];
}
/** Extracted function region inside a unified diff. */
export interface DiffFunction {
name: string;
body: string;
lineNumber: number;
/** LEFT when the function only exists on the base side (deletion). */
side: DiffSide;
changeType: string;
}
/** Context passed into the LLM for a single function. */
export interface LLMFunctionContext {
functionName?: string;
language?: string;
functionBody?: string;
inputTypes?: Array<{ name?: string; type?: string; required?: boolean }>;
outputType?: string;
conditionalGuards?: Array<{ condition?: string }>;
loops?: unknown[];
earlyReturns?: Array<{ value?: string }>;
controlFlow?: string;
complexity?: number;
comments?: string;
}
/** Parsed / mock LLM specification payload (before SpecSuggestion enrichment). */
export interface GeneratedSpecPayload {
preconditions: string[];
postconditions: string[];
invariants: string[];
edgeCases: string[];
complexity?: { time?: string; space?: string };
security?: { vulnerabilities?: string[]; mitigations?: string[] };
confidence: Confidence;
reasoning: string;
isMock?: boolean;
unavailable?: boolean;
reason?: string;
}