Commit 553b84b6 authored by Jude Gao's avatar Jude Gao

Add expert AI prompts for boundary issue resolution

Created context-aware prompts that developers can copy-paste to AI
assistants for evaluation and fix recommendations.

**Features:**
- Generate separate prompts for each heuristic detection type
- Prompts include specific file paths, prop names, and values
- Two-section format: EVALUATE and FIX

**EVALUATE Section:**
- Ask AI to verify if heuristic is correct
- Include specific detection context (prop paths, values, patterns)
- Guide AI to consider security implications

**FIX Section:**
- Provide 4 opinionated fix options
- Reference exact code locations and prop names
- Include code examples with actual boundary details
- Options: Server Component, Filter Data, Taint API, Restructure

**Sensitive Data Prompt:**
- Shows which props matched which patterns
- Includes full member chains (e.g., config.credentials.password)
- Suggests React taint API for runtime protection

**Non-Serializable Prompt:**
- Lists function props that cannot serialize
- Explains Server Actions as alternative
- Provides client-side event handler pattern

**Implementation:**
- Created expert-prompts.ts module
- Integrated into formatBoundaryAnalysis()
- One prompt per detection category per boundary
- Prompts use template interpolation for specific details

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent 2c548afd
This diff is collapsed.
import type { PropsTypeInfo, JsxLocation } from './type-resolver' import type { PropsTypeInfo, JsxLocation } from './type-resolver'
import { resolvePropsType } from './type-resolver' import { resolvePropsType } from './type-resolver'
import type ts from 'typescript/lib/tsserverlibrary' import type ts from 'typescript/lib/tsserverlibrary'
import {
generateSensitiveDataPrompt,
generateNonSerializablePrompt,
} from './expert-prompts'
export interface AnalyzedBoundary { export interface AnalyzedBoundary {
id: string id: string
...@@ -132,11 +136,85 @@ export function formatBoundaryAnalysis(analyzed: AnalyzedBoundary[]): string { ...@@ -132,11 +136,85 @@ export function formatBoundaryAnalysis(analyzed: AnalyzedBoundary[]): string {
sensitiveWarnings.push(`CREDENTIAL (${propDetails})`) sensitiveWarnings.push(`CREDENTIAL (${propDetails})`)
} }
const boundaryContext = {
serverFile: boundary.serverFile,
clientFile: boundary.clientFile,
componentName: boundary.localName,
}
// Generate expert prompts for each type of detection
if (sensitiveWarnings.length > 0) { if (sensitiveWarnings.length > 0) {
lines.push(` ⚠️ SENSITIVE DATA DETECTED:`) lines.push(` ⚠️ SENSITIVE DATA DETECTED:`)
for (const warning of sensitiveWarnings) { for (const warning of sensitiveWarnings) {
lines.push(` - ${warning}`) lines.push(` - ${warning}`)
} }
lines.push('')
// Generate a prompt for each sensitive data category
if (
flags.hasPassword &&
boundary.propsType.sensitiveProps.password.length > 0
) {
const prompt = generateSensitiveDataPrompt({
category: 'PASSWORD',
propPaths: boundary.propsType.sensitiveProps.password,
propValues: boundary.propsType.sensitiveSource,
boundaryContext,
})
lines.push(prompt)
}
if (
flags.hasSecret &&
boundary.propsType.sensitiveProps.secret.length > 0
) {
const prompt = generateSensitiveDataPrompt({
category: 'SECRET',
propPaths: boundary.propsType.sensitiveProps.secret,
propValues: boundary.propsType.sensitiveSource,
boundaryContext,
})
lines.push(prompt)
}
if (
flags.hasToken &&
boundary.propsType.sensitiveProps.token.length > 0
) {
const prompt = generateSensitiveDataPrompt({
category: 'TOKEN',
propPaths: boundary.propsType.sensitiveProps.token,
propValues: boundary.propsType.sensitiveSource,
boundaryContext,
})
lines.push(prompt)
}
if (
flags.hasApiKey &&
boundary.propsType.sensitiveProps.apiKey.length > 0
) {
const prompt = generateSensitiveDataPrompt({
category: 'API_KEY',
propPaths: boundary.propsType.sensitiveProps.apiKey,
propValues: boundary.propsType.sensitiveSource,
boundaryContext,
})
lines.push(prompt)
}
if (
flags.hasCredential &&
boundary.propsType.sensitiveProps.credential.length > 0
) {
const prompt = generateSensitiveDataPrompt({
category: 'CREDENTIAL',
propPaths: boundary.propsType.sensitiveProps.credential,
propValues: boundary.propsType.sensitiveSource,
boundaryContext,
})
lines.push(prompt)
}
} }
if ( if (
...@@ -149,6 +227,15 @@ export function formatBoundaryAnalysis(analyzed: AnalyzedBoundary[]): string { ...@@ -149,6 +227,15 @@ export function formatBoundaryAnalysis(analyzed: AnalyzedBoundary[]): string {
const propDetail = value ? `${funcProp} = {${value}}` : funcProp const propDetail = value ? `${funcProp} = {${value}}` : funcProp
lines.push(` - ${propDetail} (function type)`) lines.push(` - ${propDetail} (function type)`)
} }
lines.push('')
// Generate expert prompt for non-serializable props
const prompt = generateNonSerializablePrompt({
functionProps: boundary.propsType.functionProps,
propValues: boundary.propsType.propValues,
boundaryContext,
})
lines.push(prompt)
} }
} else if (boundary.analysisError) { } else if (boundary.analysisError) {
lines.push(` ⚠️ Type analysis failed: ${boundary.analysisError}`) lines.push(` ⚠️ Type analysis failed: ${boundary.analysisError}`)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment