-
-
Notifications
You must be signed in to change notification settings - Fork 87
feat(review): add cached repo quality-culture profile as AI-review grounding #3802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Repo quality-culture profile wiring (#2995): feeds the AI reviewer a compact, additive grounding block | ||
| // derived from the repo's OWN merge history (typical PR size, common accepted labels) so a verdict reads as | ||
| // grounded in how THIS repo actually operates, instead of generic boilerplate. Exactly the same shape/seam as | ||
| // `./rag-wire.ts` (retrieval) and `./grounding-wire.ts` (CI/file grounding): a thin HOST adapter over the | ||
| // self-contained, fixture-testable extractor (`./repo-culture-profile.ts`), splicing a pre-formatted block into | ||
| // the reviewer's USER prompt as reference context only. | ||
| // | ||
| // Two independent switches, same precedence as every other converged review knob in this codebase (see | ||
| // `review/feature-activation.ts`'s doc comment): a GLOBAL env kill-switch (GITTENSORY_REVIEW_CULTURE_PROFILE, | ||
| // default OFF) gates whether the capability exists AT ALL, and the per-repo `.gittensory.yml` | ||
| // `review.culture_profile` boolean (see signals/focus-manifest.ts) opts a specific repo in once the global | ||
| // switch is on. Both default OFF/absent ⇒ this module is never invoked, no D1 read happens, and the reviewer | ||
| // prompt is byte-identical to today. | ||
| // | ||
| // ADVISORY GROUNDING ONLY (house rule + #2995 requirement): this NEVER becomes a gate/scoring input. It only | ||
| // ever appends a reference-only block to the AI reviewer's USER prompt, exactly like the RAG/grounding/ | ||
| // enrichment sections it sits alongside in `services/ai-review.ts`'s buildUserPrompt. | ||
| import { extractRepoCultureProfile, type RepoCultureProfile } from "./repo-culture-profile"; | ||
| import { neutralizePromptInjection } from "./prompt-injection"; | ||
|
|
||
| /** True when the culture-profile grounding capability is enabled at all. Flag-OFF (default) → the per-repo | ||
| * override below is never even consulted (mirrors isRagEnabled / isGroundingEnabled / isReputationEnabled). */ | ||
| export function isRepoCultureProfileEnabled(env: { GITTENSORY_REVIEW_CULTURE_PROFILE?: string | undefined }): boolean { | ||
| return /^(1|true|yes|on)$/i.test(env.GITTENSORY_REVIEW_CULTURE_PROFILE ?? ""); | ||
| } | ||
|
|
||
| /** Format a present profile into the reviewer-prompt block. Mirrors `formatRetrievedContext`'s | ||
| * self-labelled, reference-only framing so the model treats it the same way it treats RAG context. */ | ||
| export function formatRepoCultureProfileSection(profile: RepoCultureProfile): string { | ||
| if (!profile.present) return ""; | ||
| const { pullRequestNorms, commonLabels } = profile; | ||
| const lines = [ | ||
| "=== REPO QUALITY-CULTURE PROFILE (reference, NOT a rule — derived from this repo's own merge history) ===", | ||
| `Based on ${pullRequestNorms.sampleSize} recently merged pull request(s) in this repository:`, | ||
| `- Typical merged PR size: ${pullRequestNorms.medianSizeBand} (median ${pullRequestNorms.medianChangedFiles} changed file(s)).`, | ||
| `- Typical PR description length: ~${pullRequestNorms.medianDescriptionLength} characters.`, | ||
| ]; | ||
| if (commonLabels.length > 0) { | ||
| // entry.label is author/maintainer-controlled GitHub label text from merged PRs -- neutralize it the same | ||
| // way safeReviewTitle neutralizes an untrusted PR title before it reaches the reviewer prompt (#271). | ||
| const labelSummary = commonLabels | ||
| .map((entry) => `${neutralizePromptInjection(entry.label).text} (${Math.round(entry.frequency * 100)}%)`) | ||
| .join(", "); | ||
| lines.push(`- Common labels on merged PRs: ${labelSummary}.`); | ||
| } | ||
| lines.push( | ||
| "Use this ONLY as soft context for what's typical here (e.g. don't flag a PR as unusually large if it matches this repo's own norm); it is NOT a rule and must never be treated as a blocker on its own.", | ||
| "=== END REPO QUALITY-CULTURE PROFILE ===", | ||
| ); | ||
| return lines.join("\n"); | ||
| } | ||
|
|
||
| /** | ||
| * Build the culture-profile grounding block to splice into the AI reviewer's USER prompt (flag-gated by the | ||
| * CALLER via `isRepoCultureProfileEnabled` + the per-repo `review.culture_profile` override, fully fail-safe). | ||
| * Returns "" — and the prompt stays byte-identical — whenever the profile is insufficient-data or anything | ||
| * errors. This NEVER throws. | ||
| */ | ||
| export async function buildRepoCultureProfileContext(env: Env, repoFullName: string): Promise<string> { | ||
| try { | ||
| const profile = await extractRepoCultureProfile(env, repoFullName); | ||
| return formatRepoCultureProfileSection(profile); | ||
| } catch { | ||
| return ""; // any error → review proceeds without this grounding (fail-safe) | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.