repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

extensions/diff-review/types.ts

Raw
File outline
export type ReviewCategory = "bug" | "style" | "perf" | "question";
export type ReviewSeverity = "high" | "medium" | "low";
export type ReviewSide = "additions" | "deletions";
export type FindingStatus = "open" | "resolved" | "closed_auto";

export type Finding = {
	id: string;
	round: number;
	file: string;
	prevFile?: string;
	side: ReviewSide;
	startLine: number;
	endLine: number;
	category: ReviewCategory;
	severity: ReviewSeverity;
	comment: string;
	notes?: string;
	status: FindingStatus;
	statusReason?: "file_removed" | "anchor_missing" | "manual";
	anchor: {
		before: string;
		selected: string;
		after: string;
	};
};

export type ReviewSource = {
	kind: "working-tree" | "staged" | "base";
	base?: string;
	files?: string[];
};

export type ReviewRoundEntry = {
	version: 1;
	kind: "round";
	round: number;
	source: ReviewSource;
	findings: Finding[];
	notes?: string;
	diffSummary: {
		filesChanged: number;
		additions: number;
		deletions: number;
		skippedFiles: string[];
	};
	createdAt: string;
};

export type ReviewLiveEntry = {
	version: 1;
	kind: "live";
	id: string;
	token: string;
	round: number;
	args: {
		staged: boolean;
		base?: string;
		files?: string[];
	};
	status: "open" | "closed";
	reason?: "browser" | "command" | "shutdown" | "timeout";
	createdAt: string;
};

export type ReviewState = {
	round: number;
	findings: Finding[];
	rounds: ReviewRoundEntry[];
	live?: ReviewLiveEntry;
};

export type DiffFileStatus =
	| "added"
	| "modified"
	| "deleted"
	| "renamed"
	| "binary";

export type DiffFileSummary = {
	path: string;
	prevPath?: string;
	status: DiffFileStatus;
	additions: number;
	deletions: number;
};

export type ReviewPayload = {
	round: number;
	source: ReviewSource;
	diffText: string;
	files: DiffFileSummary[];
	skippedFiles: string[];
	carriedFindings: Finding[];
};

export type FindingDraft = {
	file: string;
	prevFile?: string;
	side: ReviewSide;
	startLine: number;
	endLine: number;
	category: ReviewCategory;
	severity: ReviewSeverity;
	comment: string;
	notes?: string;
};

export type BrowserResult =
	| { type: "submit"; notes?: string; findings: Finding[] }
	| { type: "cancel"; reason: "browser" | "command" | "shutdown" | "timeout" };

export type DiffLineMap = Map<number, string>;

export type IndexedFileDiff = {
	file: string;
	prevFile?: string;
	status: DiffFileStatus;
	additions: DiffLineMap;
	deletions: DiffLineMap;
	oldLines: DiffLineMap;
	newLines: DiffLineMap;
};

export type DiffIndex = Map<string, IndexedFileDiff>;

export type CollectedDiff = {
	repoRoot: string;
	source: ReviewSource;
	diffText: string;
	files: DiffFileSummary[];
	diffIndex: DiffIndex;
	skippedFiles: string[];
	additions: number;
	deletions: number;
};