explain

package
v0.3.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package explain 把提交、分支、PR 和风险扫描要问模型的东西拼成提示词。

这里全是纯函数:不碰网络、不碰界面、不碰磁盘,所以没有 API key 也能完整测。

Index

Constants

View Source
const BranchSystemPrompt = `` /* 1005-byte string literal not displayed */

BranchSystemPrompt 是推荐 Git 分支名的系统提示。

View Source
const CommitSystemPrompt = `` /* 1083-byte string literal not displayed */

CommitSystemPrompt 是生成 Git 提交信息的系统提示。

View Source
const PRReviewSystemPrompt = `` /* 1420-byte string literal not displayed */

PRReviewSystemPrompt 是对 GitHub Pull Request 进行代码评审的系统提示。

View Source
const RiskScanSystemPrompt = `You are a senior security auditor and code safety reviewer (Senior Security Auditor & Code Safety Reviewer).
Your task is to perform a thorough security pre-check and code quality review of the user's complete staged code changes (diff), accurately identifying potential vulnerabilities, risks, and credential leaks.

Review focus includes but is not limited to:
1. Leaked Secrets: API keys, private keys, OAuth tokens, hardcoded passwords, database credentials, JWT secrets, etc.
2. Security Vulnerabilities: SQL injection, command injection, path traversal, insecure deserialization, SSRF, XSS, insecure encryption/random number generation, etc.
3. Concurrency / Panic Bugs: nil dereference, data races, deadlocks, uncaught errors or panics on critical paths.
4. Breaking changes or destructive mutations: breaking public interface compatibility, dangerous unconditional batch deletion/updates of databases, irreversible data erasure, etc.

Output format:
Output strictly valid JSON (either directly or wrapped in a ` + "```json" + ` code block). No filler or greetings.
Schema:
{
  "summary": "Concise audit conclusion. If safe, state that it passed; if risks found, summarize the count and severity of findings.",
  "passed": true, // Must be false if any HIGH or CRITICAL severity risk exists; true if no high-severity risks and overall security is acceptable.
  "findings": [
    {
      "title": "Risk title (short and clear, e.g.: Hardcoded sensitive API key)",
      "severity": "CRITICAL" | "HIGH" | "MEDIUM" | "LOW",
      "file_path": "Relative path of the file with the risk",
      "line": 42, // Corresponding line number (use 0 if exact location cannot be determined)
      "description": "Detailed description of the vulnerability's cause and potential impact",
      "suggestion": "Specific fix recommendations and security hardening measures"
    }
  ]
}

Requirements:
- If no risks are found, "passed" must be true, "findings" must be an empty array, and "summary" should state the pre-check passed.
- Never fabricate or invent findings. Ensure alerts are accurate; maintain zero tolerance for real vulnerabilities and leaks.`

RiskScanSystemPrompt 是安全与代码风险预检的系统提示词。

Variables

This section is empty.

Functions

func BuildBranchPrompt

func BuildBranchPrompt(hint string, files []diff.FileDiff) (systemPrompt, userPrompt string)

BuildBranchPrompt 构建生成分支名的提示词。

func BuildCommitPrompt

func BuildCommitPrompt(files []diff.FileDiff, contextHint string) (systemPrompt, userPrompt string)

BuildCommitPrompt 构建生成提交信息的提示词。

func BuildPRReviewPrompt

func BuildPRReviewPrompt(pr PRItem, files []diff.FileDiff) (systemPrompt, userPrompt string)

BuildPRReviewPrompt 构建用于 PR Review 评论生成的提示词。

func BuildRiskScanPrompt

func BuildRiskScanPrompt(files []diff.FileDiff) (systemPrompt, userPrompt string)

BuildRiskScanPrompt 构建预检安全提示词。

func CleanBranchName

func CleanBranchName(s string) string

CleanBranchName 清理模型输出,提取纯净、合法的 git 分支名。

func DisplayPath

func DisplayPath(f diff.FileDiff) string

DisplayPath 在重命名时把两个路径都写出来。

func Path

func Path(f diff.FileDiff) string

Path 是这个变更块所属的文件路径。

Types

type PRItem

type PRItem = gitrepo.PRItem

PRItem 为 gitrepo.PRItem 的别名,便于在 explain 包中直接使用。

type RiskFinding

type RiskFinding struct {
	Title       string       `json:"title"`
	Severity    RiskSeverity `json:"severity"`
	FilePath    string       `json:"file_path"`
	Line        int          `json:"line"`
	Description string       `json:"description"`
	Suggestion  string       `json:"suggestion"`
}

RiskFinding 描述一条具体的安全或代码风险发现。

type RiskReport

type RiskReport struct {
	Summary  string        `json:"summary"`
	Passed   bool          `json:"passed"`
	Findings []RiskFinding `json:"findings"`
}

RiskReport 是对代码变更执行安全与风险预检后的完整报告。

func ParseRiskReport

func ParseRiskReport(output string) RiskReport

ParseRiskReport 将模型输出解析为结构化的 RiskReport。 优先提取 JSON 结构;若模型返回纯 Markdown 或格式异常,做降级解析。

func (RiskReport) MaxSeverity

func (r RiskReport) MaxSeverity() RiskSeverity

MaxSeverity 返回当前报告中最高的风险级别。若无发现,返回空。

func (RiskReport) StatusBadge

func (r RiskReport) StatusBadge() (icon string, text string)

StatusBadge 返回整体安全徽标图标与文案: 🟢 安全通过 / 🟡 需注意 / 🔴 高危发现

type RiskSeverity

type RiskSeverity string

RiskSeverity 表示风险严重级别。

const (
	RiskLow      RiskSeverity = "LOW"
	RiskMedium   RiskSeverity = "MEDIUM"
	RiskHigh     RiskSeverity = "HIGH"
	RiskCritical RiskSeverity = "CRITICAL"
)

func ParseRiskSeverity

func ParseRiskSeverity(s string) RiskSeverity

ParseRiskSeverity 解析字符串为标准的 RiskSeverity。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL