💻

Code Walkthrough

👤 paudyyin 📦 v1.1.0 ⭐ 4.2 ⬇️ 308 下載
💻 開發程式設計 免費

📖 技能介紹


name: code-walkthrough description: 呼叫鏈路追蹤 + 程式碼標註 + 信任邊界標註。生成視覺化的程式碼理解頁面,讓模組結構和資料流一目瞭然。


Code Walkthrough

生成視覺化的程式碼理解頁面,將傳統的純文本程式碼說明轉化為帶呼叫鏈路、程式碼標註、信任邊界標註的 HTML 頁面,讓審查者一眼看清程式碼的形狀。

何時使用

  • 需要解釋某個模組的呼叫鏈路和資料流
  • 新人 onboarding 時理解程式碼結構
  • 程式碼審查中解釋複雜邏輯
  • 標記安全邊界和外部依賴

核心能力

1. 呼叫鏈路追蹤

  • 從入口到出口的完整資料流
  • 模組間依賴關係圖(boxes & arrows)
  • 每個步驟標註檔案路徑和行號

2. 程式碼標註

  • 關鍵邏輯逐步驟 Walkthrough
  • 可展開/摺疊的原始碼塊
  • 每個步驟的解釋說明

3. 信任邊界標註

  • 標註安全邊界(哪些是可信的,哪些不可信)
  • 外部依賴標註
  • 資料驗證點標註

HTML 輸出

始終輸出一個自包含的 HTML 檔案,可通過 <canvas> 工具呈現。

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>[Module] — Code Walkthrough</title>
<style>
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --border: #30363d;
    --text: #c9d1d9;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --green: #2ea043;
    --yellow: #d29922;
    --red: #da3633;
  }
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px;
  }
  h1 { font-size: 24px; margin-bottom: 4px; }
  h2 { font-size: 20px; margin: 32px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
  h3 { font-size: 16px; margin: 16px 0 8px; }
  .meta { color: var(--text-muted); font-size: 14px; margin-bottom: 16px; }

  /* Request path diagram */
  .request-path { display: flex; align-items: center; gap: 8px; margin: 16px 0; flex-wrap: wrap; }
  .path-node {
    padding: 8px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
  }
  .path-node.trust { border-color: var(--green); }
  .path-node.untrusted { border-color: var(--yellow); }
  .path-arrow { color: var(--text-muted); font-size: 18px; }

  /* Call stack steps */
  .step {
    margin: 16px 0;
    padding: 16px;
    background: var(--surface);
    border-radius: 8px;
    border-left: 4px solid var(--accent);
  }
  .step-num {
    display: inline-block;
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    text-align: center;
    line-height: 24px;
    font-size: 12px;
    font-weight: 700;
    margin-right: 8px;
  }
  .step-title { font-weight: 600; }
  .step-file { font-family: monospace; font-size: 12px; color: var(--text-muted); }
  .step-desc { color: var(--text-muted); margin: 8px 0; }

  /* Collapsible code */
  details { margin: 8px 0; }
  summary { cursor: pointer; color: var(--accent); font-size: 13px; padding: 8px 0; }
  summary:hover { text-decoration: underline; }
  pre {
    background: var(--bg);
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
  }

  /* Trust boundary */
  .trust-boundary {
    padding: 12px 16px;
    margin: 12px 0;
    border: 2px dashed var(--yellow);
    border-radius: 8px;
    background: rgba(210,153,34,0.05);
  }
  .trust-boundary strong { color: var(--yellow); }

  /* Annotation */
  .annotation {
    padding: 8px 12px;
    margin: 8px 0;
    background: rgba(88,166,255,0.1);
    border-left: 3px solid var(--accent);
    border-radius: 0 6px 6px 0;
    font-size: 13px;
  }

  @media (max-width: 640px) {
    .request-path { flex-direction: column; }
    .path-arrow { transform: rotate(90deg); }
  }
</style>
</head>
<body>
  <!-- Content goes here -->
</body>
</html>

使用指南

步驟 1:識別入口點

從使用者可觸達的入口開始(API endpoint、CLI 命令、Webhook 等)。

步驟 2:追蹤呼叫鏈

沿資料流追蹤到最終輸出(資料庫寫入、響應返回、外部呼叫等)。 記錄每一步: - 檔案路徑和行號 - 函式名 - 關鍵邏輯說明

步驟 3:標註信任邊界

標記: - 可信區域:經過驗證的資料、內部服務 - 不可信區域:使用者輸入、外部 API、第三方服務 - 驗證點:資料校驗、許可權檢查的位置

步驟 4:生成 HTML

將以上資訊組織成自包含的 HTML 頁面,包含: 1. Request Path 圖 — 視覺化資料流 2. Call Stack Walkthrough — 逐步驟程式碼註解 3. Trust Boundary — 安全邊界標註

示例輸出結構

## Request Path

[Browser] → [LB] → [API /api/session] → [verifyToken middleware] → [SessionStore] → [sessions table]

## Call Stack Walkthrough

1. src/app/providers/AuthProvider.tsx:22-48
   On mount, the React provider issues GET /api/session...
   [show source]

2. src/server/routes/session.ts:9-27
   The route is thin — returns whatever req.ctx.session attached...
   [show source]

3. src/middleware/auth.ts:14-31 ← TRUST BOUNDARY
   This is the trust boundary. verifyToken reads the signed cookie...
   [show source]

## Trust Boundary

Everything below verifyToken is trusted. Everything above it is not.

7w4.net小蔥技能站收錄全網優質技能,值得收藏。

🤖 AI 評測

這個 Skill 整體質量不錯,概念清晰,能有效展示程式碼呼叫鏈路和安全邊界。文件結構完整,樣式美觀。主要不足是缺少完整的使用示例,容易讓人不知如何下手;另外存在版本號不一致的小問題。建議補充一個完整的實際案例來展示效果。

📊 多維度評分

適應性3.8
規範性4.3
有效性4.4
可靠性4
可信度4.7

📁 包含檔案 (4 個)

📄 SKILL.md 5.5 KB
📄 _meta.json 135 B
📄 package.json 226 B
📄 skill-card.md 2 KB