AgentSkillsCN

privgraph

为 Mermaid 图表添加隐私与安全注解。适用于以下场景:(1) 用户分享或创建 Mermaid 流程图或序列图,并请求进行隐私、安全或合规性审查;(2) 用户请求在图表中标注数据分类、控制措施、信任边界或合规范围;(3) 用户提及“privgraph”、“@pg:”或“风险导向型图表”;(4) 用户询问架构图中的数据流风险、缺失的控制措施,或 GDPR/HIPAA/PCI 合规性缺口;(5) 用户正在撰写包含 Mermaid 图表的设计文档,并希望在图表本身中嵌入隐私/安全方面的反馈。请勿用于一般的 Mermaid 语法指导、图表美化,或非安全相关话题。

SKILL.md
--- frontmatter
name: privgraph
description: "Privacy and security annotation for Mermaid diagrams. Use this skill when: (1) a user shares or creates a Mermaid flowchart or sequence diagram and asks for privacy, security, or compliance review, (2) a user asks to annotate a diagram with data classifications, controls, trust boundaries, or compliance scope, (3) a user mentions 'privgraph', '@pg:', or 'risk-informed diagram', (4) a user asks about data flow risks, missing controls, or GDPR/HIPAA/PCI compliance gaps in an architecture diagram, (5) a user is writing a design doc with Mermaid diagrams and wants privacy/security feedback embedded in the diagram itself. Do NOT use for general Mermaid syntax help, diagram styling, or non-security topics."

PrivGraph: Mermaid Security & Privacy Annotation

PrivGraph annotates Mermaid diagrams with privacy and security metadata using comment-based directives, then evaluates configurable rules to surface control gaps.

Core Workflow

When a user presents a Mermaid diagram for privacy/security review:

  1. Parse the diagram — identify nodes, edges, subgraphs, and any existing @pg: annotations
  2. Classify — determine what data flows where (direct identifiers, health data, credentials, etc.)
  3. Annotate — add @pg: directives as Mermaid comments for data classes, controls, boundaries, compliance
  4. Evaluate — check the annotated diagram against the rule set (see references/rules.yaml)
  5. Report — surface findings with severity, description, and remediation guidance

When a user asks to create a new annotated diagram from scratch, follow steps 2–5 after helping them build the diagram.

Annotation Syntax

All annotations are Mermaid comments and do not affect rendering:

code
%% @pg:<directive> <target> <parameters>

Directives

@pg:data-class — classify data on a flow

code
%% @pg:data-class A-->B DIRECT_ID, LOCATION

@pg:control — declare present or missing (!) controls on a node or flow

code
%% @pg:control UserDB encrypted-at-rest, access-controlled
%% @pg:control UserDB !retention-policy
%% @pg:control A-->B encrypted-in-transit

@pg:boundary — declare trust boundary crossing on a flow

code
%% @pg:boundary A-->B third-party

@pg:compliance — declare applicable compliance frameworks

code
%% @pg:compliance UserDB GDPR, CCPA

@pg:risk-accept — suppress a rule finding with justification

code
%% @pg:risk-accept Cache PG-003 "24hr TTL enforced at Redis level. Approved 2024-01-10"

@pg:meta — diagram-level metadata

code
%% @pg:meta owner "platform-team"
%% @pg:meta system "checkout-service"
%% @pg:meta reviewed "2024-01-15"

Data Classifications

ClassificationDescriptionExamples
DIRECT_IDDirect identifiersNames, emails, SSNs, phone numbers
INDIRECT_IDIndirect/pseudonymous identifiersOpaque IDs, UUIDs, session tokens, pseudonyms
PHIProtected health informationEHR, Diagnoses, prescriptions, lab results
PCIPayment card dataCard numbers, CVVs
CREDENTIALSAuthentication secretsPasswords, API keys, tokens
BIOMETRICBiometric dataFingerprints, face data, voice prints
LOCATIONLocation dataGPS coordinates, IP-derived location
FINANCIALFinancial dataBank accounts, transactions
SENSITIVEOther sensitive dataCatch-all for sensitive categories
PUBLICNon-sensitive dataPublic content, marketing copy

Controls

encrypted-at-rest, encrypted-in-transit, access-controlled, audit-logged, retention-policy, anonymized, minimized, consent-managed, dpa-in-place

Prefix with ! to mark a control as explicitly missing.

Boundaries

internal, third-party, cross-region, cross-cloud, public-internet, user-device

Compliance Frameworks

GDPR, CCPA, HIPAA, PCI-DSS, SOC2, FERPA

Rule Evaluation

After annotating, evaluate the diagram against the rule set. Load references/rules.yaml for the full rule definitions. Here is the summary:

RuleSevTrigger
PG-001HIGHDIRECT_ID/INDIRECT_ID/PHI flow missing encrypted-in-transit
PG-002HIGHDIRECT_ID/INDIRECT_ID/PHI node missing encrypted-at-rest
PG-003MEDSensitive data node missing retention-policy
PG-004HIGHCREDENTIALS flow missing encryption
PG-005CRITDIRECT_ID to third-party missing dpa-in-place
PG-006HIGHPHI to third-party boundary
PG-007MEDcross-region flow missing compliance annotation
PG-008HIGHHIPAA-scoped flow missing audit-logged
PG-009MEDGDPR-scoped node missing retention-policy
PG-010LOWFlow crosses boundary with no controls documented
PG-011INFONode has zero controls documented

For each violation, check if a @pg:risk-accept suppresses it (matching target + rule ID). Suppressed findings should be noted but not reported as active violations.

Reporting Format

Present findings grouped by severity. Use this structure:

code
## PrivGraph Review: [system name or file]

### Findings

🔴 **CRITICAL — PG-005: Direct Identifiers to Third Party Without DPA**
Flow: UserSvc → Analytics
DIRECT_ID is transferred to a third party without a documented DPA.
→ Add: `%% @pg:control Analytics dpa-in-place`

🟡 **HIGH — PG-001: Unencrypted Identifier Transfer**
Flow: Mobile → API
DIRECT_ID transferred without encryption in transit.
→ Add: `%% @pg:control Mobile-->API encrypted-in-transit`

### Summary
X critical, Y high, Z medium | N findings suppressed by @pg:risk-accept

Always output the complete annotated diagram (original diagram with all @pg: annotations added) so the user can copy-paste it directly.

Handling Ambiguity

When data classifications are unclear from the diagram alone:

  • Ask the user what data flows through ambiguous edges
  • Default to the more sensitive classification when context suggests it
  • Flag uncertain classifications with a comment: %% TODO: Confirm data classification for A-->B

When a diagram has no annotations yet, annotate it fully rather than just listing what's missing. Show the user what a complete annotation looks like.

Supported Diagram Types

  • Flowcharts: flowchart LR/TB/etc. — nodes, edges, subgraphs all supported
  • Sequence diagrams: sequenceDiagram — participants map to nodes, messages map to edges, boxes map to subgraphs

For annotation target syntax in sequence diagrams, use participant names: %% @pg:data-class Client->>Server DIRECT_ID

Examples

See examples/flowchart-annotated.md and examples/sequence-annotated.md for complete worked examples with annotations and findings.