#!/usr/bin/env node

// src/cli/review-prompts.ts
function buildReviewPrompt(diff, gitContextStr, detailed) {
  const level = detailed ? "Please perform a detailed in-depth review covering: security, performance, maintainability, error handling, naming conventions, and code duplication." : "Please perform a concise code review focusing on bugs, security issues, and key improvement suggestions.";
  return `# Code Review Request

${level}

## Git Status
${gitContextStr}

## Code Changes (diff)
\`\`\`diff
${diff}
\`\`\`

## Output Format
Please structure your review as follows:
1. **Overall Assessment**: One-sentence summary of the change quality
2. **Issues** (if any): Each issue with [Severity] file:line \u2014 description + suggested fix
3. **Improvement Suggestions** (if any): Non-critical but recommended optimizations
4. **Highlights** (if any): Good practices worth acknowledging

Severity levels: \u{1F534} Critical / \u{1F7E1} Warning / \u{1F535} Info`;
}
function buildSecurityReviewPrompt(diff, gitContextStr) {
  return `# Security Vulnerability Review

Analyze the following code changes **exclusively for security vulnerabilities**.

## Categories to check:
1. **Injection** \u2014 SQL, command, path traversal, XSS, template injection
2. **Authentication & Authorization** \u2014 hardcoded credentials, missing auth checks, privilege escalation
3. **Secrets & Sensitive Data** \u2014 API keys, tokens, passwords in code, logging sensitive data
4. **Input Validation** \u2014 missing validation, unsafe deserialization, buffer issues
5. **Cryptography** \u2014 weak algorithms, improper random, hardcoded IVs/salts
6. **Dependencies** \u2014 known vulnerable packages, unsafe dynamic imports
7. **File System** \u2014 path traversal, unsafe file permissions, symlink attacks
8. **Network** \u2014 SSRF, insecure protocols, missing TLS validation

## Git Status
${gitContextStr}

## Code Changes (diff)
\`\`\`diff
${diff}
\`\`\`

## Output Format
For each finding:
- **Severity**: \u{1F534} CRITICAL / \u{1F7E0} HIGH / \u{1F7E1} MEDIUM / \u{1F535} LOW / \u2139\uFE0F INFO
- **Category**: (from list above)
- **File & location**: file:line
- **Description**: what the vulnerability is and how it could be exploited
- **Recommended fix**: specific code change to resolve

If no security issues found, state "\u2705 No security vulnerabilities detected" with a brief explanation of what was checked.`;
}
function truncateDiff(diff, maxChars) {
  if (diff.length <= maxChars) return { diff, truncated: false };
  const head = diff.slice(0, Math.floor(maxChars * 0.7));
  const tail = diff.slice(diff.length - Math.floor(maxChars * 0.2));
  return {
    diff: head + "\n\n... [diff truncated, " + diff.length + " chars total] ...\n\n" + tail,
    truncated: true
  };
}

export {
  buildReviewPrompt,
  buildSecurityReviewPrompt,
  truncateDiff
};
