<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <author>
    <name>李孟瑶</name>
  </author>
  <generator uri="https://hexo.io/">Hexo</generator>
  <id>https://w-li-you.github.io/</id>
  <link href="https://w-li-you.github.io/" rel="alternate"/>
  <link href="https://w-li-you.github.io/atom.xml" rel="self"/>
  <rights>All rights reserved 2026, 李孟瑶</rights>
  <subtitle>记录 Java 后端、中间件和工作中遇到问题的学习笔记</subtitle>
  <title>脑瓜呆呆</title>
  <updated>2026-07-05T15:48:14.460Z</updated>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="AI编程" scheme="https://w-li-you.github.io/categories/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="AI编程" scheme="https://w-li-you.github.io/tags/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="索引" scheme="https://w-li-you.github.io/tags/%E7%B4%A2%E5%BC%95/"/>
    <content>
      <![CDATA[<h1 id="AI-编程-·-个人文档索引"><a href="#AI-编程-·-个人文档索引" class="headerlink" title="AI 编程 · 个人文档索引"></a>AI 编程 · 个人文档索引</h1><blockquote><p>桌面备忘 · 2026-07-03</p></blockquote><hr><a id="more"></a><h2 id="怎么用这套文档"><a href="#怎么用这套文档" class="headerlink" title="怎么用这套文档"></a>怎么用这套文档</h2><table><thead><tr><th>我想…</th><th>先看</th></tr></thead><tbody><tr><td>跑一个大需求从头到尾</td><td><strong><a href="/2026/06/02/my-ai-coding-workflow/">我的 AI 编程工作流</a></strong></td></tr><tr><td>选 Phase 0/1/2 用什么模型</td><td><strong><a href="/2026/05/18/ai-model-selection-comparison/">我的 AI 模型选型对比</a></strong></td></tr><tr><td>写 / 改 CLAUDE.md</td><td><strong><a href="/2026/03/08/claude-md-how-to-write/">CLAUDE.md 怎么写</a></strong></td></tr><tr><td>配 Skills / Hooks / Rules</td><td><strong><a href="/2026/03/28/claude-code-seven-configurations/">Claude Code 七种配置方式</a></strong></td></tr><tr><td>理解为什么要 Spec 不用 Vibe</td><td><strong><a href="/2026/02/22/spec-coding-personal-notes/">Spec Coding</a></strong></td></tr><tr><td>理解「我的优势是什么」</td><td><strong><a href="/2026/02/08/ai-coding-expertise-advantage/">AI 编程时代你的优势</a></strong></td></tr><tr><td>深入看配置体系设计</td><td><strong><a href="/2026/04/12/claude-code-config-system-notes/">Claude Code 配置体系笔记</a></strong></td></tr></tbody></table><hr><h2 id="文档清单（按学习顺序）"><a href="#文档清单（按学习顺序）" class="headerlink" title="文档清单（按学习顺序）"></a>文档清单（按学习顺序）</h2><table><thead><tr><th>文章</th><th>类型</th><th>一句话</th></tr></thead><tbody><tr><td><a href="/2026/02/08/ai-coding-expertise-advantage/">AI 编程时代你的优势</a></td><td>方法论</td><td>领域专业度 &gt; 编码；说清、拆活、验收</td></tr><tr><td><a href="/2026/02/22/spec-coding-personal-notes/">Spec Coding</a></td><td>方法论</td><td>先对齐再写码；和 spec-kit / 工作流对应</td></tr><tr><td><a href="/2026/03/08/claude-md-how-to-write/">CLAUDE.md 怎么写</a></td><td>配置</td><td>200 行内、只放事实、Hook 管强制</td></tr><tr><td><a href="/2026/03/28/claude-code-seven-configurations/">Claude Code 七种配置方式</a></td><td>配置</td><td>七种方式的加载时机和选型</td></tr><tr><td><a href="/2026/04/12/claude-code-config-system-notes/">Claude Code 配置体系</a></td><td>配置</td><td>从官方设计到可迁移的工程思维</td></tr><tr><td><a href="/2026/05/18/ai-model-selection-comparison/">我的 AI 模型选型对比</a></td><td>选型备忘</td><td>Opus 规划、Sonnet 写、换 AI 审</td></tr><tr><td><a href="/2026/06/02/my-ai-coding-workflow/">我的 AI 编程工作流</a></td><td><strong>操作手册</strong></td><td>Grill → PRD → Issues → Implement → 双道审查</td></tr></tbody></table><hr><h2 id="概念怎么串起来"><a href="#概念怎么串起来" class="headerlink" title="概念怎么串起来"></a>概念怎么串起来</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">                  ┌─────────────────────────┐</span><br><span class="line">                  │  我的优势：懂行 + 担责   │  ← Anthropic 研究</span><br><span class="line">                  └───────────┬─────────────┘</span><br><span class="line">                              │</span><br><span class="line">      ┌───────────────────────┼───────────────────────┐</span><br><span class="line">      ▼                       ▼                       ▼</span><br><span class="line">Spec Coding              工作流 Skills           CLAUDE.md / Hooks</span><br><span class="line">先对齐再写码              Grill→PRD→Issues        事实 vs 流程 vs 强制</span><br><span class="line">      │                       │                       │</span><br><span class="line">      └───────────────────────┴───────────────────────┘</span><br><span class="line">                              │</span><br><span class="line">                  Opus 规划 → Sonnet 实现</span><br><span class="line">                  → 换 AI 审查 → 人工签字 → MR</span><br></pre></td></tr></table></figure><hr><h2 id="维护约定"><a href="#维护约定" class="headerlink" title="维护约定"></a>维护约定</h2><ul><li>全是<strong>个人备忘</strong>，不对了随时改</li><li>模型感受带「待验证」= 样本少，大方向对</li><li>工作流变了先改<a href="/2026/06/02/my-ai-coding-workflow/">工作流</a>，模型映射改<a href="/2026/05/18/ai-model-selection-comparison/">选型对比</a></li></ul>]]>
    </content>
    <id>https://w-li-you.github.io/2026/07/03/ai-coding-doc-index/</id>
    <link href="https://w-li-you.github.io/2026/07/03/ai-coding-doc-index/"/>
    <published>2026-07-02T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h1 id="AI-编程-·-个人文档索引"><a href="#AI-编程-·-个人文档索引" class="headerlink" title="AI 编程 · 个人文档索引"></a>AI 编程 · 个人文档索引</h1><blockquote>
<p>桌面备忘 · 2026-07-03</p>
</blockquote>
<hr>]]>
    </summary>
    <title>AI 编程 · 个人文档索引</title>
    <updated>2026-07-05T15:48:14.460Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="中间件" scheme="https://w-li-you.github.io/categories/%E4%B8%AD%E9%97%B4%E4%BB%B6/"/>
    <category term="Elasticsearch" scheme="https://w-li-you.github.io/tags/Elasticsearch/"/>
    <category term="分布式系统" scheme="https://w-li-you.github.io/tags/%E5%88%86%E5%B8%83%E5%BC%8F%E7%B3%BB%E7%BB%9F/"/>
    <category term="搜索引擎" scheme="https://w-li-you.github.io/tags/%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E/"/>
    <content>
      <![CDATA[<blockquote><p>本文是 ES 存储引擎系列的进阶篇，深入剖析相关度评分：从 BM25 算法的 <code>k1</code>/<code>b</code> 参数，到分布式 IDF 问题，再到 Function Score 的各类函数（weight、field_value_factor、decay、random_score、script_score）实战。</p></blockquote><a id="more"></a><h2 id="第一部分：控制相关度（BM25）"><a href="#第一部分：控制相关度（BM25）" class="headerlink" title="第一部分：控制相关度（BM25）"></a>第一部分：控制相关度（BM25）</h2><h3 id="评分框架演进"><a href="#评分框架演进" class="headerlink" title="评分框架演进"></a>评分框架演进</h3><p>现代 ES 默认使用 <strong>BM25</strong> 概率模型替代了早期的 TF-IDF 向量空间模型：</p><table><thead><tr><th>旧”实用评分函数”组件</th><th>在现代框架中的状态</th></tr></thead><tbody><tr><td>布尔模型</td><td>不变，仍是匹配的第一阶段</td></tr><tr><td>词频（TF）</td><td>进化，从线性增长变为 BM25 的非线性饱和函数（由 <code>k1</code> 控制）</td></tr><tr><td>逆向文档频率（IDF）</td><td>进化，使用更稳健的 BM25 IDF 公式（含平滑项）</td></tr><tr><td>字段长度归一化</td><td>进化，变为 BM25 中由 <code>b</code> 参数控制的、基于平均长度的归一化</td></tr><tr><td>向量空间模型</td><td>被 BM25 概率模型取代</td></tr></tbody></table><h3 id="查询上下文-vs-过滤上下文"><a href="#查询上下文-vs-过滤上下文" class="headerlink" title="查询上下文 vs 过滤上下文"></a>查询上下文 vs 过滤上下文</h3><ul><li><strong>查询上下文</strong>：回答”这个文档和查询语句有多匹配？”，计算 <code>_score</code>。使用 <code>match</code>、<code>term</code>（在 <code>should</code> 中）等。</li><li><strong>过滤上下文</strong>：回答”是否匹配？”，答案是 是/否。不计算 <code>_score</code>，但结果会被缓存，性能极高。</li></ul><blockquote><p>实际搜索通常是<strong>混合模型</strong>：用布尔逻辑（<code>filter</code>）快速精确过滤，用评分查询（<code>must</code>、<code>should</code>）对结果集相关度排序。</p></blockquote><hr><h3 id="BM25-饱和度参数-k1"><a href="#BM25-饱和度参数-k1" class="headerlink" title="BM25 饱和度参数 k1"></a>BM25 饱和度参数 <code>k1</code></h3><p><code>k1</code> 控制词频对相关度贡献的<strong>边际效益递减速度</strong>。传统 TF-IDF 中词频线性增长（出现 100 次得分就是 100），存在明显问题——“的”字出现 100 次并不代表相关 100 倍。</p><p><strong>BM25 TF 公式（文档长度等于平均长度时的简化）：</strong></p><p>$$\text{TF}_{\text{BM25}} = \frac{f \cdot (k_1 + 1)}{f + k_1}$$</p><p>BM25 词频饱和效果（k1=1.2）：</p><table><thead><tr><th>词频 f</th><th>BM25 TF 值</th></tr></thead><tbody><tr><td>1</td><td>1.000</td></tr><tr><td>5</td><td>1.548</td></tr><tr><td>10</td><td>1.710</td></tr><tr><td>50</td><td>1.902</td></tr><tr><td>∞</td><td>→ 2.2（上限为 k1+1）</td></tr></tbody></table><p><strong>完整公式（含长度归一化）：</strong></p><p>$$\text{TF}_{\text{BM25}} = \frac{f \cdot (k_1 + 1)}{f + k_1 \cdot \left(1 - b + b \cdot \dfrac{|D|}{\text{avgdl}}\right)}$$</p><p><strong><code>k1</code> 取值场景参考：</strong></p><table><thead><tr><th>k1 值</th><th>场景特征</th><th>适用案例</th></tr></thead><tbody><tr><td>0.5 – 1.2（低）</td><td>短文本、标题搜索，需快速饱和</td><td>推文搜索、商品标题、日志错误匹配</td></tr><tr><td>1.2 – 1.8（中）</td><td>通用网页搜索，安全默认值</td><td>Google/Bing 式搜索、企业文档库</td></tr><tr><td>1.8 – 2.5+（高）</td><td>长文档，一个相关词需出现多次</td><td>学术论文全文、小说/剧本、技术手册</td></tr></tbody></table><hr><h3 id="BM25-长度归一化参数-b"><a href="#BM25-长度归一化参数-b" class="headerlink" title="BM25 长度归一化参数 b"></a>BM25 长度归一化参数 <code>b</code></h3><p><code>b</code> 决定文档长度与平均长度的差异如何影响词频贡献。</p><ul><li><strong>b = 0</strong>：禁用长度归一化</li><li><strong>b = 0.75（默认）</strong>：中度惩罚长文档，奖励短文档</li><li><strong>b = 1</strong>：强烈惩罚长文档</li></ul><p><strong>自定义 BM25 配置示例：</strong></p><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">PUT /my_index</span><br><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;settings&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;index&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">      <span class="attr">&quot;similarity&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">        <span class="attr">&quot;my_custom_bm25&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;BM25&quot;</span><span class="punctuation">,</span> <span class="attr">&quot;b&quot;</span><span class="punctuation">:</span> <span class="number">0.3</span><span class="punctuation">,</span> <span class="attr">&quot;k1&quot;</span><span class="punctuation">:</span> <span class="number">1.6</span> <span class="punctuation">&#125;</span></span><br><span class="line">      <span class="punctuation">&#125;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line">  <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">  <span class="attr">&quot;mappings&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;properties&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">      <span class="attr">&quot;title&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="attr">&quot;type&quot;</span><span class="punctuation">:</span> <span class="string">&quot;text&quot;</span><span class="punctuation">,</span> <span class="attr">&quot;similarity&quot;</span><span class="punctuation">:</span> <span class="string">&quot;my_custom_bm25&quot;</span> <span class="punctuation">&#125;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line">  <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure><hr><h3 id="逆向文档频率（IDF）"><a href="#逆向文档频率（IDF）" class="headerlink" title="逆向文档频率（IDF）"></a>逆向文档频率（IDF）</h3><p>词在集合所有文档里出现的频率越高，权重<strong>越低</strong>。</p><p>$$\text{IDF}(q_i) = \log\left(1 + \frac{N - n(q_i) + 0.5}{n(q_i) + 0.5}\right)$$</p><p><strong>与经典 IDF 的关键区别：</strong> <code>+1</code>/<code>+0.5</code> 平滑防止极端值；永远为正；对高频词的惩罚更温和。</p><hr><h3 id="分布式-IDF-问题"><a href="#分布式-IDF-问题" class="headerlink" title="分布式 IDF 问题"></a>分布式 IDF 问题</h3><p>在分布式集群中，数据被水平分割到多个<strong>分片</strong>，每个分片是独立的 Lucene 索引，<strong>分片之间不共享 IDF 统计信息</strong>。</p><p>**默认 <code>QUERY_THEN_FETCH</code>**：各分片独立计算 IDF（各自为政），导致同一个词在不同分片中 IDF 不同：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">分片1：idf₁ = log(1 + (3000-150+0.5)/(150+0.5)) ≈ 3.04</span><br><span class="line">分片2：idf₂ = log(1 + (3500-200+0.5)/(200+0.5)) ≈ 2.88</span><br><span class="line">分片3：idf₃ = log(1 + (2500-100+0.5)/(100+0.5)) ≈ 3.24</span><br></pre></td></tr></table></figure><p>**精确方式 <code>DFS_QUERY_THEN_FETCH</code>**：先预查询收集全局统计，广播给所有分片统一计算 IDF。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">GET /my_index/_search?search_type=dfs_query_then_fetch</span><br></pre></td></tr></table></figure><blockquote><p>⚠️ <code>dfs_query_then_fetch</code> 需要额外预查询阶段，代价较高，生产中谨慎使用。数据量大、分片多时，默认模式的近似误差通常可接受。</p></blockquote><hr><h2 id="第二部分：Function-Score"><a href="#第二部分：Function-Score" class="headerlink" title="第二部分：Function Score"></a>第二部分：Function Score</h2><p>Function Score 是 ES 的”评分增强器”，允许在基础查询评分上通过一系列函数二次评分。</p><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;function_score&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;query&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="attr">&quot;match&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="attr">&quot;title&quot;</span><span class="punctuation">:</span> <span class="string">&quot;咖啡&quot;</span> <span class="punctuation">&#125;</span> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;functions&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span> ... <span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;score_mode&quot;</span><span class="punctuation">:</span> <span class="string">&quot;sum&quot;</span><span class="punctuation">,</span>       <span class="comment">// 函数得分之间如何组合</span></span><br><span class="line">    <span class="attr">&quot;boost_mode&quot;</span><span class="punctuation">:</span> <span class="string">&quot;multiply&quot;</span><span class="punctuation">,</span>  <span class="comment">// 函数分与基础分如何组合</span></span><br><span class="line">    <span class="attr">&quot;max_boost&quot;</span><span class="punctuation">:</span> <span class="number">10</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;min_score&quot;</span><span class="punctuation">:</span> <span class="number">2.0</span></span><br><span class="line">  <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure><h3 id="函数组合方式：score-mode"><a href="#函数组合方式：score-mode" class="headerlink" title="函数组合方式：score_mode"></a>函数组合方式：<code>score_mode</code></h3><blockquote><p>示例：<code>func1=1.5, func2=2.0, func3=0.5</code></p></blockquote><table><thead><tr><th>score_mode</th><th>计算</th><th>结果</th><th>适用场景</th></tr></thead><tbody><tr><td><code>sum</code></td><td>相加</td><td>4.0</td><td>多个独立因素叠加</td></tr><tr><td><code>multiply</code></td><td>相乘</td><td>1.5</td><td>因素相互依赖</td></tr><tr><td><code>avg</code></td><td>平均</td><td>1.33</td><td>平滑影响</td></tr><tr><td><code>first</code></td><td>第一个非空</td><td>1.5</td><td>优先级明确</td></tr><tr><td><code>max</code></td><td>取最大</td><td>2.0</td><td>取最优因素</td></tr><tr><td><code>min</code></td><td>取最小</td><td>0.5</td><td>限流</td></tr></tbody></table><h3 id="与基础分组合：boost-mode"><a href="#与基础分组合：boost-mode" class="headerlink" title="与基础分组合：boost_mode"></a>与基础分组合：<code>boost_mode</code></h3><blockquote><p>示例：<code>_score=2.0</code>，<code>functions_score=4.0</code></p></blockquote><table><thead><tr><th>boost_mode</th><th>计算</th><th>结果</th><th>效果</th></tr></thead><tbody><tr><td><code>multiply</code></td><td>_score × func</td><td>8.0</td><td>基础相关性 × 业务规则（最常用）</td></tr><tr><td><code>replace</code></td><td>func</td><td>4.0</td><td>完全用函数分替代</td></tr><tr><td><code>sum</code></td><td>相加</td><td>6.0</td><td>相关性 + 业务规则</td></tr><tr><td><code>avg</code></td><td>平均</td><td>3.0</td><td>各占一半</td></tr></tbody></table><hr><h3 id="Weight：最简单的加权"><a href="#Weight：最简单的加权" class="headerlink" title="Weight：最简单的加权"></a>Weight：最简单的加权</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span> <span class="attr">&quot;weight&quot;</span><span class="punctuation">:</span> <span class="number">2.0</span><span class="punctuation">,</span> <span class="attr">&quot;filter&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="attr">&quot;term&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="attr">&quot;featured&quot;</span><span class="punctuation">:</span> <span class="literal"><span class="keyword">true</span></span> <span class="punctuation">&#125;</span> <span class="punctuation">&#125;</span> <span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure><blockquote><p>⚠️ <code>weight</code> 不是乘数，是固定值！匹配时函数得分为 2，不是乘以 2 倍；不匹配时为 1.0。</p></blockquote><h3 id="Field-Value-Factor：字段值参与评分"><a href="#Field-Value-Factor：字段值参与评分" class="headerlink" title="Field Value Factor：字段值参与评分"></a>Field Value Factor：字段值参与评分</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;field_value_factor&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;field&quot;</span><span class="punctuation">:</span> <span class="string">&quot;popularity&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;factor&quot;</span><span class="punctuation">:</span> <span class="number">1.2</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;modifier&quot;</span><span class="punctuation">:</span> <span class="string">&quot;log1p&quot;</span><span class="punctuation">,</span>   <span class="comment">// 推荐：平滑且正值</span></span><br><span class="line">    <span class="attr">&quot;missing&quot;</span><span class="punctuation">:</span> <span class="number">1</span></span><br><span class="line">  <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure><p><strong><code>modifier</code> 函数对比：</strong></p><table><thead><tr><th>modifier</th><th>公式</th><th>特点</th></tr></thead><tbody><tr><td><code>none</code></td><td>factor × field</td><td>线性，易导致分数爆炸</td></tr><tr><td><code>log1p</code></td><td>log(1 + factor × field)</td><td><strong>推荐！平滑且正值</strong></td></tr><tr><td><code>square</code></td><td>(factor × field)²</td><td>放大差异（如 4-5 星区间）</td></tr><tr><td><code>sqrt</code></td><td>√(factor × field)</td><td>缩小差异</td></tr><tr><td><code>reciprocal</code></td><td>1 / (factor × field)</td><td>反转关系（如越便宜越靠前）</td></tr></tbody></table><hr><h3 id="Decay-衰减函数：时间、距离、数值的平滑衰减"><a href="#Decay-衰减函数：时间、距离、数值的平滑衰减" class="headerlink" title="Decay 衰减函数：时间、距离、数值的平滑衰减"></a>Decay 衰减函数：时间、距离、数值的平滑衰减</h3><table><thead><tr><th>函数</th><th>曲线特点</th><th>最适用场景</th></tr></thead><tbody><tr><td><code>gauss</code>（高斯）</td><td>平滑柔和，钟形曲线</td><td>地理距离、评分衰减</td></tr><tr><td><code>exp</code>（指数）</td><td>一开始掉得快，越往后越平</td><td>新闻时效性、热点快速衰退</td></tr><tr><td><code>linear</code>（线性）</td><td>匀速直线下降</td><td>价格偏好、简单规则</td></tr></tbody></table><p><strong>高斯衰减示例（以上海为原点的地理距离）：</strong></p><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;gauss&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;location&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">      <span class="attr">&quot;origin&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="attr">&quot;lat&quot;</span><span class="punctuation">:</span> <span class="number">31.2304</span><span class="punctuation">,</span> <span class="attr">&quot;lon&quot;</span><span class="punctuation">:</span> <span class="number">121.4737</span> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">      <span class="attr">&quot;scale&quot;</span><span class="punctuation">:</span> <span class="string">&quot;10km&quot;</span><span class="punctuation">,</span></span><br><span class="line">      <span class="attr">&quot;offset&quot;</span><span class="punctuation">:</span> <span class="string">&quot;1km&quot;</span><span class="punctuation">,</span></span><br><span class="line">      <span class="attr">&quot;decay&quot;</span><span class="punctuation">:</span> <span class="number">0.3</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line">  <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure><p>衰减三阶段：<code>offset</code> 内（≤1km）几乎不衰减 → <code>offset ~ offset+scale</code>（1~11km）平滑下降至 decay（0.3）→ 超过后继续趋近 0 但越来越平缓。</p><hr><h3 id="Random-Score：引入随机性"><a href="#Random-Score：引入随机性" class="headerlink" title="Random Score：引入随机性"></a>Random Score：引入随机性</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span> <span class="attr">&quot;random_score&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="attr">&quot;seed&quot;</span><span class="punctuation">:</span> <span class="string">&quot;用户ID&quot;</span><span class="punctuation">,</span> <span class="attr">&quot;field&quot;</span><span class="punctuation">:</span> <span class="string">&quot;_seq_no&quot;</span> <span class="punctuation">&#125;</span> <span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure><blockquote><p>相同种子 + 相同字段 → 相同随机分数（可复现，保证分页连贯）。</p></blockquote><p>适用场景：商品推荐（避免每次展示同样商品）、内容发现、打散同分文档、探索与利用。</p><hr><h3 id="Script-Score：完全自定义评分"><a href="#Script-Score：完全自定义评分" class="headerlink" title="Script Score：完全自定义评分"></a>Script Score：完全自定义评分</h3><p>当内置函数无法满足需求时的终极方案，可访问 <code>doc[&#39;field&#39;].value</code>、<code>_score</code>、<code>params.*</code>：</p><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;script_score&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">    <span class="attr">&quot;script&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">      <span class="attr">&quot;source&quot;</span><span class="punctuation">:</span> <span class="string">&quot;&quot;</span><span class="string">&quot;</span></span><br><span class="line"><span class="string">        double price = doc[&#x27;price&#x27;].value;</span></span><br><span class="line"><span class="string">        double rating = doc[&#x27;rating&#x27;].value;</span></span><br><span class="line"><span class="string">        double priceFactor = 1.0 / (1.0 + price * 0.001);</span></span><br><span class="line"><span class="string">        double ratingFactor = rating / 5.0;</span></span><br><span class="line"><span class="string">        return _score * (priceFactor * params.price_weight</span></span><br><span class="line"><span class="string">                       + ratingFactor * params.rating_weight);</span></span><br><span class="line"><span class="string">      &quot;</span><span class="string">&quot;&quot;</span><span class="punctuation">,</span></span><br><span class="line">      <span class="attr">&quot;params&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="attr">&quot;price_weight&quot;</span><span class="punctuation">:</span> <span class="number">0.6</span><span class="punctuation">,</span> <span class="attr">&quot;rating_weight&quot;</span><span class="punctuation">:</span> <span class="number">0.4</span> <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">      <span class="attr">&quot;lang&quot;</span><span class="punctuation">:</span> <span class="string">&quot;painless&quot;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line">  <span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure><hr><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><table><thead><tr><th>层次</th><th>工具</th><th>核心作用</th></tr></thead><tbody><tr><td>基础相关性</td><td>BM25（<code>k1</code>/<code>b</code>）</td><td>词频饱和 + 长度归一化，替代 TF-IDF</td></tr><tr><td>分布式准确性</td><td><code>dfs_query_then_fetch</code></td><td>统一全局 IDF，代价较高</td></tr><tr><td>业务加权</td><td><code>weight</code> / <code>field_value_factor</code></td><td>分类加权、热度/价格/评分参与排序</td></tr><tr><td>平滑衰减</td><td><code>gauss</code> / <code>exp</code> / <code>linear</code></td><td>时间、距离、数值的自然衰减</td></tr><tr><td>多样性</td><td><code>random_score</code></td><td>打散、探索发现</td></tr><tr><td>终极定制</td><td><code>script_score</code></td><td>完全自定义评分逻辑</td></tr></tbody></table><blockquote><p>相关度调优的核心：先用 BM25 保证基础相关性，再用 Function Score 叠加业务规则，<code>boost_mode: multiply</code> 是最常用的组合方式。</p></blockquote>]]>
    </content>
    <id>https://w-li-you.github.io/2026/06/22/es-relevance-scoring/</id>
    <link href="https://w-li-you.github.io/2026/06/22/es-relevance-scoring/"/>
    <published>2026-06-21T16:00:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>本文是 ES 存储引擎系列的进阶篇，深入剖析相关度评分：从 BM25 算法的 <code>k1</code>/<code>b</code> 参数，到分布式 IDF 问题，再到 Function Score 的各类函数（weight、field_value_factor、decay、random_score、script_score）实战。</p>
</blockquote>]]>
    </summary>
    <title>Elasticsearch 相关度评分：从 BM25 到 Function Score 实战</title>
    <updated>2026-07-01T13:04:48.823Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="中间件" scheme="https://w-li-you.github.io/categories/%E4%B8%AD%E9%97%B4%E4%BB%B6/"/>
    <category term="Elasticsearch" scheme="https://w-li-you.github.io/tags/Elasticsearch/"/>
    <category term="分布式系统" scheme="https://w-li-you.github.io/tags/%E5%88%86%E5%B8%83%E5%BC%8F%E7%B3%BB%E7%BB%9F/"/>
    <content>
      <![CDATA[<blockquote><p>本文是 ES 存储引擎系列的延伸篇，承接<a href="/2026/02/16/es-segment-commitpoint-translog/">段、提交点与 Translog</a> 和<a href="/2026/03/05/es-near-realtime-search-crud/">近实时搜索与实时 CRUD</a>。理解了 Segment 的不可变性后，就能真正理解 PIT 是如何”冻结视图”实现一致性深度分页的。</p></blockquote><a id="more"></a><h2 id="一、什么是-PIT"><a href="#一、什么是-PIT" class="headerlink" title="一、什么是 PIT"></a>一、什么是 PIT</h2><p>PIT（Point-In-Time）是 Elasticsearch 在 <strong>7.10 版本</strong>引入的关键特性。它允许你在一个特定的、一致的时间点对索引进行查询，即使在查询过程中数据正在被实时更新、删除或修改。</p><p>可以把它想象成给整个索引拍一张**”快照”<strong>——但它不复制数据，只记录一个”视图”（即 Lucene Segment 的引用列表）。在这个快照的”时间窗口”内，你执行的所有分页查询看到的都是</strong>完全相同的数据状态**。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">时间轴：[创建PIT] ---- [数据变更/段合并] ---- [PIT查询] ---- [PIT删除/过期]</span><br><span class="line">           ↑                 ↑                    ↑                ↑</span><br><span class="line">       记录当前          新数据写入，          查询被 PIT      释放对旧段的</span><br><span class="line">       所有段的引用       产生新段，但 PIT     &quot;冻结&quot;的旧段     引用，允许</span><br><span class="line">                         引用的旧段不删除      （数据不变）      Lucene 清理</span><br></pre></td></tr></table></figure><hr><h2 id="二、为什么需要-PIT"><a href="#二、为什么需要-PIT" class="headerlink" title="二、为什么需要 PIT"></a>二、为什么需要 PIT</h2><h3 id="2-1-传统分页的核心痛点"><a href="#2-1-传统分页的核心痛点" class="headerlink" title="2.1 传统分页的核心痛点"></a>2.1 传统分页的核心痛点</h3><p>在频繁更新的索引上使用 <code>from/size</code> 或 <code>search_after</code> 分页，会遇到<strong>数据漂移（Data Drift）</strong>问题：</p><ol><li>你执行第一次查询（<code>from=0, size=10</code>），获取了 10 条结果。</li><li>这时有一条新数据写入，或原有的一条被删除。</li><li>你执行第二次查询（<code>from=10, size=10</code>）获取下一页。</li><li>由于索引状态已改变，你可能会看到：<ul><li><strong>重复数据</strong>：上页的最后一条又被排到了这页的第一条。</li><li><strong>丢失数据</strong>：某条本该在这页的数据，因排序变化被挤到了下一页或消失。</li></ul></li></ol><blockquote><p>这就像一个按字母排序的名单，翻到第 2 页时正好有人插入到第 1、2 页之间，所有人位置后移一位——第 1 页最后一个人又出现在第 2 页开头。</p></blockquote><h3 id="2-2-各分页方案对比"><a href="#2-2-各分页方案对比" class="headerlink" title="2.2 各分页方案对比"></a>2.2 各分页方案对比</h3><table><thead><tr><th>分页方案</th><th>适用场景</th><th>优点</th><th>缺点</th></tr></thead><tbody><tr><td><code>from/size</code></td><td>浅分页（前几页）</td><td>简单直观，支持随机跳页</td><td>深分页性能差；数据不一致</td></tr><tr><td><code>scroll</code></td><td>大批量导出（一次性）</td><td>数据一致，适合全量导出</td><td>有状态，资源消耗大；不适合实时分页</td></tr><tr><td><code>search_after</code></td><td>深度分页（无跳页需求）</td><td>性能好，无深度限制</td><td>不支持随机跳页；无 PIT 时数据不一致</td></tr><tr><td><strong><code>PIT + search_after</code></strong></td><td><strong>深度分页（推荐）</strong></td><td><strong>数据一致 + 性能优秀</strong></td><td><strong>需管理 PIT 生命周期</strong></td></tr></tbody></table><blockquote><p>官方推荐：<strong>PIT + search_after</strong> 是替代 scroll API 的现代方案，比 scroll 更高效、更灵活。</p></blockquote><hr><h2 id="三、PIT-的底层原理"><a href="#三、PIT-的底层原理" class="headerlink" title="三、PIT 的底层原理"></a>三、PIT 的底层原理</h2><h3 id="3-1-依赖-Lucene-Segment-的不可变性"><a href="#3-1-依赖-Lucene-Segment-的不可变性" class="headerlink" title="3.1 依赖 Lucene Segment 的不可变性"></a>3.1 依赖 Lucene Segment 的不可变性</h3><p>理解 PIT 的关键在于 ES 底层的 Segment 机制（详见<a href="/2026/02/16/es-segment-commitpoint-translog/">段、提交点与 Translog</a>）：</p><ul><li>ES 的数据存储在<strong>不可变的 Segment 文件</strong>中。</li><li>新数据写入产生新 Segment；删除/更新只标记旧数据，不立即删除文件。</li><li>Lucene 定期执行 <strong>Segment 合并（Merge）</strong>，清理已删除数据。</li></ul><h3 id="3-2-PIT-如何冻结视图"><a href="#3-2-PIT-如何冻结视图" class="headerlink" title="3.2 PIT 如何冻结视图"></a>3.2 PIT 如何冻结视图</h3><p>创建 PIT 时，ES 会：</p><ol><li><strong>记录当前所有 Segment 的引用列表</strong>。</li><li><strong>阻止这些 Segment 被合并/删除</strong>，即使后续发生大量写入和合并。</li><li>后续在该 PIT 下的所有查询，只会看到这些被”冻结”的 Segment。</li></ol><blockquote><p>这就是 PIT 不复制数据却能保证一致性的原因：<strong>它只是持有了旧 Segment 的引用，阻止了这些文件被回收</strong>。</p></blockquote><h3 id="3-3-PIT-存储的内容"><a href="#3-3-PIT-存储的内容" class="headerlink" title="3.3 PIT 存储的内容"></a>3.3 PIT 存储的内容</h3><table><thead><tr><th>内容</th><th>说明</th></tr></thead><tbody><tr><td><strong>Segment 列表和位置</strong></td><td>记录创建时每个分片上活跃的 Segment 文件列表（最重要）</td></tr><tr><td><strong>时间戳和存活时间</strong></td><td>记录创建时间和 <code>keep_alive</code>，用于过期清理</td></tr><tr><td><strong>索引映射和状态</strong></td><td>记录各索引的 mapping 快照，确保字段解析一致</td></tr><tr><td><strong>唯一的 PIT ID</strong></td><td>Base64 编码字符串，包含分片路由信息</td></tr></tbody></table><hr><h2 id="四、PIT-的使用"><a href="#四、PIT-的使用" class="headerlink" title="四、PIT 的使用"></a>四、PIT 的使用</h2><h3 id="4-1-创建-PIT"><a href="#4-1-创建-PIT" class="headerlink" title="4.1 创建 PIT"></a>4.1 创建 PIT</h3><figure class="highlight http"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">POST /my-index/_pit?keep_alive=1m</span><br></pre></td></tr></table></figure><ul><li><code>keep_alive</code>：告诉 ES”请将这个时间点视图<strong>至少保持 1 分钟</strong>“。</li><li>响应返回一个 <code>id</code>，作为后续查询的标识。支持多索引和通配符（<code>/logs-*/_pit</code>）。</li></ul><h3 id="4-2-使用-PIT-search-after-深度分页"><a href="#4-2-使用-PIT-search-after-深度分页" class="headerlink" title="4.2 使用 PIT + search_after 深度分页"></a>4.2 使用 PIT + search_after 深度分页</h3><p><strong>第一页查询：</strong></p><figure class="highlight http"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">POST /_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;size&quot;: 10,</span><br><span class="line">  &quot;pit&quot;: &#123; &quot;id&quot;: &quot;i9W1AwIMc2...&quot;, &quot;keep_alive&quot;: &quot;5m&quot; &#125;,</span><br><span class="line">  &quot;query&quot;: &#123; &quot;match&quot;: &#123; &quot;title&quot;: &quot;test&quot; &#125; &#125;,</span><br><span class="line">  &quot;sort&quot;: [</span><br><span class="line">    &#123; &quot;create_time&quot;: &quot;desc&quot; &#125;,</span><br><span class="line">    &#123; &quot;_shard_doc&quot;: &quot;asc&quot; &#125;</span><br><span class="line">  ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p><strong>关键注意事项：</strong></p><ul><li>使用 PIT 的查询<strong>不需要</strong>在 URL 中指定索引名（索引信息已编码在 PIT id 里）。</li><li><code>sort</code> 必须是<strong>唯一的字段组合</strong>，推荐 <code>_shard_doc</code>（ES 内置唯一排序字段）或 <code>时间字段 + _id</code>。</li><li><code>keep_alive</code> 续期：每次查询带上 PIT id 会重新延长生命周期，相当于”续费”。</li></ul><p><strong>取第一页最后一条的 <code>sort</code> 值，作为下一页的 <code>search_after</code>：</strong></p><figure class="highlight http"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">POST /_search</span><br><span class="line">&#123;</span><br><span class="line">  &quot;size&quot;: 10,</span><br><span class="line">  &quot;pit&quot;: &#123; &quot;id&quot;: &quot;&#123;最新pit_id&#125;&quot;, &quot;keep_alive&quot;: &quot;5m&quot; &#125;,</span><br><span class="line">  &quot;query&quot;: &#123; &quot;match&quot;: &#123; &quot;title&quot;: &quot;test&quot; &#125; &#125;,</span><br><span class="line">  &quot;sort&quot;: [&#123; &quot;create_time&quot;: &quot;desc&quot; &#125;, &#123; &quot;_shard_doc&quot;: &quot;asc&quot; &#125;],</span><br><span class="line">  &quot;search_after&quot;: [1720000000000, 1234567]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><blockquote><p>⚠️ 每次响应都会返回一个<strong>新的 pit_id</strong>，下一次查询要用<strong>最新返回的 pit_id</strong>，而非最初创建的 id。</p></blockquote><h3 id="4-3-删除-PIT"><a href="#4-3-删除-PIT" class="headerlink" title="4.3 删除 PIT"></a>4.3 删除 PIT</h3><figure class="highlight http"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">DELETE /_pit</span><br><span class="line">&#123; &quot;id&quot;: &quot;i9W1AwIMc2...&quot; &#125;</span><br></pre></td></tr></table></figure><p>PIT 会占用 ES 资源（主要是<strong>文件句柄</strong>，用于保留旧 Segment 不被删除）。<strong>完成分页后必须主动删除，释放资源。</strong></p><hr><h2 id="五、最佳实践"><a href="#五、最佳实践" class="headerlink" title="五、最佳实践"></a>五、最佳实践</h2><h3 id="5-1-keep-alive-设置原则"><a href="#5-1-keep-alive-设置原则" class="headerlink" title="5.1 keep_alive 设置原则"></a>5.1 keep_alive 设置原则</h3><table><thead><tr><th>场景</th><th>建议 keep_alive</th></tr></thead><tbody><tr><td>实时用户翻页（前端）</td><td>1m ～ 3m</td></tr><tr><td>后台批量数据导出</td><td>5m ～ 15m</td></tr><tr><td>大规模离线数据同步</td><td>30m（谨慎使用）</td></tr></tbody></table><ul><li><strong>不宜过长</strong>：太长会导致大量旧 Segment 无法合并释放。</li><li><strong>必须续期</strong>：分页可能超过初始 <code>keep_alive</code> 时，务必每次查询续期，否则 PIT 过期会触发 <code>search_phase_execution_exception</code>。</li></ul><h3 id="5-2-排序唯一性是基石"><a href="#5-2-排序唯一性是基石" class="headerlink" title="5.2 排序唯一性是基石"></a>5.2 排序唯一性是基石</h3><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">&quot;sort&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line">  <span class="punctuation">&#123;</span> <span class="attr">&quot;create_time&quot;</span><span class="punctuation">:</span> <span class="string">&quot;desc&quot;</span> <span class="punctuation">&#125;</span><span class="punctuation">,</span>   <span class="comment">// 业务排序字段</span></span><br><span class="line">  <span class="punctuation">&#123;</span> <span class="attr">&quot;_shard_doc&quot;</span><span class="punctuation">:</span> <span class="string">&quot;asc&quot;</span> <span class="punctuation">&#125;</span>      <span class="comment">// 全局唯一字段，保证排序不重复</span></span><br><span class="line"><span class="punctuation">]</span></span><br></pre></td></tr></table></figure><ul><li><code>_shard_doc</code> 是 ES 7.12+ 提供的内置唯一字段，性能最优。</li><li>也可用 <code>_id</code>，但字符串排序性能略逊。</li></ul><h3 id="5-3-资源管理"><a href="#5-3-资源管理" class="headerlink" title="5.3 资源管理"></a>5.3 资源管理</h3><ul><li><p><strong>主动清理</strong>：用完即删，不要依赖过期自动清理。业务代码应在 <code>finally</code> 块中删除 PIT。</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">String</span> <span class="variable">pitId</span> <span class="operator">=</span> createPit();</span><br><span class="line"><span class="keyword">try</span> &#123;</span><br><span class="line">    doPageSearch(pitId);</span><br><span class="line">&#125; <span class="keyword">finally</span> &#123;</span><br><span class="line">    deletePit(pitId);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li><li><p><strong>监控 PIT 数量</strong>：通过 <code>GET /_nodes/stats/indices/search</code> 关注 <code>open_contexts</code> 字段，持续增大说明有 PIT 泄漏。</p></li></ul><h3 id="5-4-PIT-的局限性"><a href="#5-4-PIT-的局限性" class="headerlink" title="5.4 PIT 的局限性"></a>5.4 PIT 的局限性</h3><table><thead><tr><th>限制</th><th>说明</th></tr></thead><tbody><tr><td>不支持随机跳页</td><td>只能顺序翻页，不能直接跳到第 N 页</td></tr><tr><td>不保留实时数据</td><td>只是”视图快照”，不适合查询最新数据</td></tr><tr><td>集群重启失效</td><td>节点宕机或集群重启后自动失效</td></tr><tr><td>资源占用</td><td>大量并发 PIT 会阻止 Segment 合并，增大磁盘/内存压力</td></tr><tr><td>不支持 <code>from</code></td><td>必须配合 <code>search_after</code>，不能使用 <code>from</code> 偏移</td></tr></tbody></table><hr><h2 id="六、PIT-vs-Scroll-API"><a href="#六、PIT-vs-Scroll-API" class="headerlink" title="六、PIT vs Scroll API"></a>六、PIT vs Scroll API</h2><table><thead><tr><th>对比维度</th><th>Scroll API</th><th>PIT + search_after</th></tr></thead><tbody><tr><td>引入版本</td><td>早期版本</td><td>7.10+</td></tr><tr><td>数据一致性</td><td>✅ 一致</td><td>✅ 一致</td></tr><tr><td>性能</td><td>一般（需维护游标上下文）</td><td>更好（无状态游标，只需 sort 值）</td></tr><tr><td>并发查询</td><td>❌ 不支持</td><td>✅ 支持（多消费者共享同一 PIT）</td></tr><tr><td>适用场景</td><td>大批量一次性导出（旧方案）</td><td>用户分页、深度翻页（推荐）</td></tr><tr><td>官方态度</td><td>逐渐废弃</td><td>✅ 推荐</td></tr></tbody></table><blockquote><p>ES 官方在 8.x 文档中明确建议：<strong>新项目应使用 PIT + search_after 替代 scroll</strong>。</p></blockquote><hr><h2 id="七、总结"><a href="#七、总结" class="headerlink" title="七、总结"></a>七、总结</h2><table><thead><tr><th>要点</th><th>说明</th></tr></thead><tbody><tr><td>核心价值</td><td>在频繁变更的索引上实现一致性分页，解决数据漂移问题</td></tr><tr><td>底层机制</td><td>持有 Lucene Segment 引用，阻止段合并/回收</td></tr><tr><td>推荐搭配</td><td><code>PIT + search_after</code>，排序字段必须唯一</td></tr><tr><td>生命周期</td><td>创建 → 续期（每次查询带 keep_alive）→ 主动删除</td></tr><tr><td>适用版本</td><td>ES 7.10+，推荐 7.12+（<code>_shard_doc</code> 支持）</td></tr></tbody></table>]]>
    </content>
    <id>https://w-li-you.github.io/2026/06/08/es-pit-point-in-time/</id>
    <link href="https://w-li-you.github.io/2026/06/08/es-pit-point-in-time/"/>
    <published>2026-06-07T16:00:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>本文是 ES 存储引擎系列的延伸篇，承接<a href="/2026/02/16/es-segment-commitpoint-translog/">段、提交点与 Translog</a> 和<a href="/2026/03/05/es-near-realtime-search-crud/">近实时搜索与实时 CRUD</a>。理解了 Segment 的不可变性后，就能真正理解 PIT 是如何”冻结视图”实现一致性深度分页的。</p>
</blockquote>]]>
    </summary>
    <title>Elasticsearch 深度分页：PIT（Point-In-Time）时间窗口详解</title>
    <updated>2026-07-01T13:04:57.885Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="AI编程" scheme="https://w-li-you.github.io/categories/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="AI编程" scheme="https://w-li-you.github.io/tags/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="Claude Code" scheme="https://w-li-you.github.io/tags/Claude-Code/"/>
    <category term="Cursor" scheme="https://w-li-you.github.io/tags/Cursor/"/>
    <category term="工作流" scheme="https://w-li-you.github.io/tags/%E5%B7%A5%E4%BD%9C%E6%B5%81/"/>
    <content>
      <![CDATA[<h1 id="我的-AI-编程工作流"><a href="#我的-AI-编程工作流" class="headerlink" title="我的 AI 编程工作流"></a>我的 AI 编程工作流</h1><blockquote><p>个人实践总结 · Cursor / Claude Code 大需求开发<br>核心理念：<strong>规划用强模型想清楚，执行用快模型低成本落地，AI 审查 + 人工审查双保险</strong></p></blockquote><hr><a id="more"></a><h2 id="这套流程在解决什么"><a href="#这套流程在解决什么" class="headerlink" title="这套流程在解决什么"></a>这套流程在解决什么</h2><p>我踩过最典型的坑：Vibe Coding 一个大需求，改到第三轮前面写好的接口被动了，一个下午耗在「一句一句掰扯」上。根因不是模型笨，是<strong>缺对齐物</strong>——Spec Coding 那套 specify → plan → tasks → implement，我用自己的 Skills 落地成 Grill → PRD → Issues → Implement。</p><p>Anthropic 40 万会话的研究也印证：<strong>人 ~70% 规划、Agent ~80% 执行</strong>；成败看领域专业度，不是语法。所以我 Phase 0 不省 Opus，Phase 2 必须人工签字——<strong>AI 不能担责</strong>。</p><h3 id="配套个人总结（桌面同目录）"><a href="#配套个人总结（桌面同目录）" class="headerlink" title="配套个人总结（桌面同目录）"></a>配套个人总结（桌面同目录）</h3><table><thead><tr><th>文档</th><th>讲什么</th></tr></thead><tbody><tr><td>《Spec-Coding规约驱动开发-个人总结》</td><td>为什么要分阶段对齐、和 spec-kit 的对应</td></tr><tr><td>《AI编程时代你的优势是什么-个人总结》</td><td>懂行 &gt; 会写代码，说清/拆活/验收</td></tr><tr><td>《CLAUDE.md怎么写-个人总结》</td><td>项目常驻记忆怎么写</td></tr><tr><td>《Claude-Code七种配置方式-个人总结》</td><td>Skills / Rules / Hooks 放哪</td></tr><tr><td>《我的AI模型选型对比》</td><td>各阶段用什么模型</td></tr><tr><td>《MewCode-Agent项目-个人总结》</td><td>Agent 架构 mental model（选用）</td></tr></tbody></table><hr><h2 id="一、总览"><a href="#一、总览" class="headerlink" title="一、总览"></a>一、总览</h2><h3 id="需求分流"><a href="#需求分流" class="headerlink" title="需求分流"></a>需求分流</h3><table><thead><tr><th>类型</th><th>特征</th><th>推荐流程</th></tr></thead><tbody><tr><td><strong>小需求</strong></td><td>改个 Bug、加个小接口、一次性脚本</td><td>直接 Vibe Coding，或单会话 <code>/implement</code></td></tr><tr><td><strong>大需求</strong></td><td>跨模块、要长期维护、涉及架构决策</td><td>走完整 <strong>Grill → PRD → Issues → Implement</strong> 流水线</td></tr></tbody></table><p>本文重点描述<strong>大需求</strong>流程。</p><h3 id="全流程一览"><a href="#全流程一览" class="headerlink" title="全流程一览"></a>全流程一览</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">┌─────────────────────────────────────────────────────────────────┐</span><br><span class="line">│  Phase 0 · 规划（单会话，Opus 4.8）                               │</span><br><span class="line">│  /grill-with-docs  →  /to-prd  →  /to-issues                     │</span><br><span class="line">│  产出：决策纪要 + PRD + 可独立执行的 Issue 列表                    │</span><br><span class="line">└────────────────────────────┬────────────────────────────────────┘</span><br><span class="line">                             │ 人工确认 breakdown 后发布</span><br><span class="line">                             ▼</span><br><span class="line">┌─────────────────────────────────────────────────────────────────┐</span><br><span class="line">│  Phase 1 · 实现（每 Issue 新会话，Sonnet 4.6）                    │</span><br><span class="line">│  /implement  →  测试全绿  →  commit（暂不提 MR）                  │</span><br><span class="line">└────────────────────────────┬────────────────────────────────────┘</span><br><span class="line">                             │</span><br><span class="line">                             ▼</span><br><span class="line">┌─────────────────────────────────────────────────────────────────┐</span><br><span class="line">│  Phase 2 · 审查（AI 审查 + 人工审查，两道门）                     │</span><br><span class="line">│  ① 切换其他 AI · /review                                        │</span><br><span class="line">│  ② 人工过 diff（兜底，保证代码对我可控）                           │</span><br><span class="line">│  两道都过 → MR                                                   │</span><br><span class="line">└─────────────────────────────────────────────────────────────────┘</span><br></pre></td></tr></table></figure><h3 id="模型-AI-选型原则"><a href="#模型-AI-选型原则" class="headerlink" title="模型 / AI 选型原则"></a>模型 / AI 选型原则</h3><table><thead><tr><th>阶段</th><th>AI / 模型</th><th>原因</th></tr></thead><tbody><tr><td><strong>规划</strong>（Grill / PRD / Issues）</td><td><strong>Opus 4.8</strong>（Cursor）</td><td>思考更全面，擅长权衡架构取舍、发现遗漏边界、梳理依赖</td></tr><tr><td><strong>实现</strong>（Implement）</td><td><strong>Sonnet 4.6</strong>（Cursor）</td><td>执行快、消费低；Issue 范围已收窄，不需要重推理</td></tr><tr><td><strong>AI 审查</strong></td><td><strong>切换其他 AI</strong></td><td>交叉验证 Standards + Spec，发现 implement 盲区</td></tr><tr><td><strong>人工审查</strong></td><td><strong>我自己</strong></td><td>兜底：审查 AI 漏掉的业务/运行时/安全风险；<strong>保证代码对我可控</strong></td></tr></tbody></table><p><strong>审查常用组合</strong>（AI 审查部分，任选其一，关键是和实现 AI 不同）：</p><table><thead><tr><th>实现 AI</th><th>审查 AI</th><th>说明</th></tr></thead><tbody><tr><td>Sonnet 4.6（Cursor）</td><td><strong>Opus 4.8</strong>（Cursor 新会话）</td><td>强模型审弱模型的产出，查遗漏和架构问题</td></tr><tr><td>Sonnet 4.6（Cursor）</td><td><strong>GPT / Codex</strong>（其他 IDE 或 CLI）</td><td>跨厂商，审查视角完全独立</td></tr><tr><td>Sonnet 4.6（Cursor）</td><td><strong>Claude Code</strong>（终端）</td><td>不同工具链，上下文隔离更彻底</td></tr></tbody></table><blockquote><p>规划阶段省下的返工成本，远大于 Opus 的 token 差价。<br>AI 审查 + 人工审查的成本，远小于「代码完全不可控」或漏审上线后的返工。<br><strong>AI 不能担责</strong>——最终 merge 的决定权必须在我手里。</p></blockquote><hr><h2 id="二、Phase-0：规划（Opus-4-8-·-单会话）"><a href="#二、Phase-0：规划（Opus-4-8-·-单会话）" class="headerlink" title="二、Phase 0：规划（Opus 4.8 · 单会话）"></a>二、Phase 0：规划（Opus 4.8 · 单会话）</h2><p>目标：在写一行代码之前，把「做什么、为什么、怎么验、拆成几块」全部对齐。</p><h3 id="Step-1：-grill-with-docs-—-压力测试-沉淀决策"><a href="#Step-1：-grill-with-docs-—-压力测试-沉淀决策" class="headerlink" title="Step 1：/grill-with-docs — 压力测试 + 沉淀决策"></a>Step 1：<code>/grill-with-docs</code> — 压力测试 + 沉淀决策</h3><p><strong>做什么</strong>：对改造方案/大需求进行 relentless interview（逐条追问），同时用 <code>/domain-modeling</code> 把术语和 ADR 写进文档。</p><p><strong>输入</strong>：</p><ul><li>模糊的需求描述、改造想法、或现有方案草稿</li><li>可选：相关 issue、会议纪要、<code>.scratch/</code> 里的讨论笔记</li></ul><p><strong>过程要点</strong>：</p><ul><li>AI <strong>一次只问一个问题</strong>，逐条确认后再继续</li><li>能读代码库回答的问题，AI 应先去探索代码，而不是问你</li><li>每个问题 AI 会给出<strong>推荐答案</strong>，你可以采纳或修正</li><li>讨论中 crystallise 的术语 → 写入 <code>CONTEXT.md</code> / <code>CONTEXT-MAP.md</code></li><li>架构取舍 → 写入 <code>docs/adr/</code></li></ul><p><strong>产出</strong>：</p><ul><li>决策纪要（范围、优先级、验收标准、Out-of-Scope）</li><li>领域词汇表更新（如有）</li><li>ADR 记录（如有）</li></ul><p><strong>我的检查清单</strong>：</p><ul><li><input disabled="" type="checkbox"> 范围边界清楚了吗？（In-Scope / Out-of-Scope）</li><li><input disabled="" type="checkbox"> 验收标准可量化吗？（不是「做好就行」）</li><li><input disabled="" type="checkbox"> 有没有「现在不做但容易误做」的坑被明确排除？</li><li><input disabled="" type="checkbox"> 分支策略、部署约束等工程决策是否已定？</li></ul><p><strong>示例触发</strong>：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">/grill-with-docs</span><br><span class="line"></span><br><span class="line">我想给 scm-rec-py 做 v1 MVP：搜索兜底推荐 + pgvector 向量编码，</span><br><span class="line">GBDT+LR 先不做。帮我 stress-test 这个改造计划。</span><br></pre></td></tr></table></figure><hr><h3 id="Step-2：-to-prd-—-合成-PRD"><a href="#Step-2：-to-prd-—-合成-PRD" class="headerlink" title="Step 2：/to-prd — 合成 PRD"></a>Step 2：<code>/to-prd</code> — 合成 PRD</h3><p><strong>做什么</strong>：把当前会话（Grill 讨论 + 代码库理解）<strong>直接合成</strong> PRD，<strong>不再 interview</strong>。</p><p><strong>输入</strong>：Step 1 完成的同一会话上下文</p><p><strong>过程要点</strong>：</p><ol><li>AI 探索代码库，用项目领域词汇写 PRD</li><li>AI 草拟<strong>测试 seam</strong>（优先用现有 seam，越少越好，理想是 1 个）</li><li><strong>与你确认 seam 是否符合预期</strong></li><li>按模板写 PRD，发布到 Issue Tracker，打 <code>ready-for-agent</code> 标签</li></ol><p><strong>PRD 结构</strong>：</p><table><thead><tr><th>章节</th><th>内容</th></tr></thead><tbody><tr><td>Problem Statement</td><td>用户视角的问题</td></tr><tr><td>Solution</td><td>用户视角的解决方案</td></tr><tr><td>User Stories</td><td>详尽编号列表：<code>As an &lt;actor&gt;, I want &lt;feature&gt;, so that &lt;benefit&gt;</code></td></tr><tr><td>Implementation Decisions</td><td>模块、接口、架构、Schema、API 契约（<strong>不写具体文件路径</strong>）</td></tr><tr><td>Testing Decisions</td><td>测什么行为、哪些模块、参考现有测试风格</td></tr><tr><td>Out of Scope</td><td>明确不做的事</td></tr><tr><td>Further Notes</td><td>其他补充</td></tr></tbody></table><p><strong>我的检查清单</strong>：</p><ul><li><input disabled="" type="checkbox"> User Stories 是否覆盖了所有功能面？</li><li><input disabled="" type="checkbox"> Implementation Decisions 里没有过时的文件路径？</li><li><input disabled="" type="checkbox"> Testing Decisions 里的 seam 是我认可的测试切入点？</li><li><input disabled="" type="checkbox"> Out of Scope 和 Grill 阶段的决策一致？</li></ul><p><strong>注意</strong>：PRD 发布到 GitLab Issues（本项目用 <code>glab</code> CLI，见 <code>docs/agents/issue-tracker.md</code>）。</p><hr><h3 id="Step-3：-to-issues-—-垂直切片拆任务"><a href="#Step-3：-to-issues-—-垂直切片拆任务" class="headerlink" title="Step 3：/to-issues — 垂直切片拆任务"></a>Step 3：<code>/to-issues</code> — 垂直切片拆任务</h3><p><strong>做什么</strong>：把 PRD/计划拆成<strong>可独立抓取</strong>的 Issue，每个 Issue 是一个 <strong>tracer bullet</strong>（垂直切片）。</p><p><strong>输入</strong>：同一会话中的 PRD，或指定 issue 编号/URL</p><p><strong>核心原则：垂直切片，不要水平分层</strong></p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">❌ 错误（水平切片）          ✅ 正确（垂直切片）</span><br><span class="line">Issue 1: 写 Schema           Issue 1: 用户能创建项目（Schema + API + 测试）</span><br><span class="line">Issue 2: 写 API              Issue 2: 用户能添加任务到项目</span><br><span class="line">Issue 3: 写前端              Issue 3: 用户能在看板拖拽任务</span><br><span class="line">Issue 4: 写测试</span><br></pre></td></tr></table></figure><p>每个 slice：</p><ul><li>穿过<strong>所有集成层</strong>（schema → API → 业务逻辑 → 测试）</li><li>完成后<strong>可独立 demo 或验证</strong></li><li>如有 prefactor 需求，<strong>单独作为第一个 slice</strong></li></ul><p><strong>过程要点</strong>：</p><ol><li>AI 草拟 breakdown，列出每个 slice 的：<ul><li><strong>Title</strong></li><li><strong>Blocked by</strong>（依赖关系）</li><li><strong>User stories covered</strong></li></ul></li><li><strong>Quiz 你</strong>：粒度对不对？依赖对不对？要不要合并/拆分？</li><li>迭代直到你 approve</li><li>按依赖顺序发布 Issue（blocker 先发），打 <code>ready-for-agent</code></li></ol><p><strong>Issue 模板</strong>：</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">## What to build</span></span><br><span class="line">端到端行为描述（不是逐层实现说明）</span><br><span class="line"></span><br><span class="line"><span class="section">## Acceptance criteria</span></span><br><span class="line"><span class="bullet">-</span> [ ] 可验证条件 1</span><br><span class="line"><span class="bullet">-</span> [ ] 可验证条件 2</span><br><span class="line"></span><br><span class="line"><span class="section">## Blocked by</span></span><br><span class="line"><span class="bullet">-</span> #123 或 None - can start immediately</span><br></pre></td></tr></table></figure><p><strong>我的检查清单</strong>：</p><ul><li><input disabled="" type="checkbox"> 每个 Issue 能独立验收吗？</li><li><input disabled="" type="checkbox"> 依赖关系正确吗？（不会 circular block）</li><li><input disabled="" type="checkbox"> 第一个 Issue 是 prefactor 吗？（如需要）</li><li><input disabled="" type="checkbox"> Issue 粒度：一个会话能做完吗？（太大就拆，太小就合并）</li><li><input disabled="" type="checkbox"> 父 Issue（PRD）没有被关闭或修改？</li></ul><p><strong>Phase 0 结束标志</strong>：Issue 列表发布完毕，你可以从「无 blocker 的 Issue」开始执行。</p><hr><h2 id="三、Phase-1：实现（Sonnet-4-6-·-每-Issue-新会话）"><a href="#三、Phase-1：实现（Sonnet-4-6-·-每-Issue-新会话）" class="headerlink" title="三、Phase 1：实现（Sonnet 4.6 · 每 Issue 新会话）"></a>三、Phase 1：实现（Sonnet 4.6 · 每 Issue 新会话）</h2><p>目标：每个 Issue 在干净上下文中实现、自测通过、提交代码。<strong>审查不在此阶段做</strong>。</p><h3 id="为什么要「一-Issue-一会话」？"><a href="#为什么要「一-Issue-一会话」？" class="headerlink" title="为什么要「一 Issue 一会话」？"></a>为什么要「一 Issue 一会话」？</h3><table><thead><tr><th>好处</th><th>说明</th></tr></thead><tbody><tr><td>上下文干净</td><td>不会混入上一个 Issue 的残留讨论</td></tr><tr><td>成本可控</td><td>Sonnet 消费低，短会话比长会话更省</td></tr><tr><td>失败隔离</td><td>一个 Issue 跑偏，不影响其他</td></tr><tr><td>可追溯</td><td>会话 ↔ Issue ↔ Commit 一一对应</td></tr></tbody></table><h3 id="Step-4：-implement-—-实现"><a href="#Step-4：-implement-—-实现" class="headerlink" title="Step 4：/implement — 实现"></a>Step 4：<code>/implement</code> — 实现</h3><p><strong>做什么</strong>：根据 Issue 或 PRD 描述实现代码。</p><p><strong>操作</strong>：</p><ol><li><strong>切换模型</strong> → Sonnet 4.6</li><li><strong>新开 Cursor Agent 会话</strong></li><li>附上 Issue 链接或编号</li><li>调用 <code>/implement</code></li></ol><p><strong>Implement 内置行为</strong>（skill 定义）：</p><ul><li>在 PRD 预定义的 seam 处使用 <code>/tdd</code>（先测后写，垂直 RED→GREEN）</li><li>定期跑 typecheck、单测文件</li><li>全部完成后跑完整测试套件</li><li>提交到当前分支</li></ul><p><strong>注意</strong>：Implement 完成后<strong>不要在同一会话里自审</strong>。进入 Phase 2，切换其他 AI 做 <code>/review</code>。</p><p><strong>我的操作习惯</strong>：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">新会话 · Sonnet 4.6</span><br><span class="line"></span><br><span class="line">/implement</span><br><span class="line"></span><br><span class="line">请实现 GitLab Issue #I-14：pgvector ANN 查询优化</span><br><span class="line">Issue 链接：https://gitlab.xxx/issues/14</span><br><span class="line">当前分支：feat/I-14-pgvector-ann</span><br></pre></td></tr></table></figure><p><strong>分支策略</strong>（参考 scm-rec-py）：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">lmy/v1-mvp（集成线）</span><br><span class="line">  └── feat/I-xx-简述（单 Issue 短分支）</span><br></pre></td></tr></table></figure><p><strong>我的检查清单</strong>：</p><ul><li><input disabled="" type="checkbox"> 当前在正确的 feat 分支上？</li><li><input disabled="" type="checkbox"> Issue 的 Acceptance Criteria 逐条满足？</li><li><input disabled="" type="checkbox"> <code>/tdd</code> 在预定义 seam 上用了吗？</li><li><input disabled="" type="checkbox"> 测试全绿？</li><li><input disabled="" type="checkbox"> 代码已 commit，准备进入审查？</li></ul><hr><h2 id="四、Phase-2：审查（AI-审查-人工审查）"><a href="#四、Phase-2：审查（AI-审查-人工审查）" class="headerlink" title="四、Phase 2：审查（AI 审查 + 人工审查）"></a>四、Phase 2：审查（AI 审查 + 人工审查）</h2><p>目标：<strong>两道门都过</strong>才提 MR——AI 交叉验证 + 人工兜底，避免代码对我完全不可控。</p><h3 id="审查分工：AI-审什么，人审什么"><a href="#审查分工：AI-审什么，人审什么" class="headerlink" title="审查分工：AI 审什么，人审什么"></a>审查分工：AI 审什么，人审什么</h3><table><thead><tr><th>维度</th><th>AI 审查（<code>/review</code>）</th><th>人工审查（我自己）</th></tr></thead><tbody><tr><td>编码规范</td><td>✅ 对照 CODING_STANDARDS</td><td>扫一眼风格是否顺眼</td></tr><tr><td>Spec 对齐</td><td>✅ 对照 Issue/PRD 逐条核验</td><td>✅ 确认「做的是我要的」</td></tr><tr><td>scope creep</td><td>✅ 发现多做/少做</td><td>✅ 有没有「顺手改」我不想要的</td></tr><tr><td><strong>业务逻辑</strong></td><td>部分（靠 spec 描述）</td><td>✅ <strong>领域经验判断对不对</strong></td></tr><tr><td><strong>并发/性能/资源</strong></td><td>容易漏</td><td>✅ <strong>高并发、OOM、热点 key 等运行时坑</strong></td></tr><tr><td><strong>安全/权限/敏感数据</strong></td><td>容易漏</td><td>✅ 鉴权、密钥、日志脱敏、危险命令</td></tr><tr><td><strong>可维护性</strong></td><td>部分</td><td>✅ <strong>我能不能看懂、以后能不能改</strong></td></tr><tr><td><strong>部署/配置影响</strong></td><td>容易漏</td><td>✅ 环境变量、Nacos、启动项变化</td></tr><tr><td><strong>测试是否真验到了</strong></td><td>看有没有测试</td><td>✅ 测试是否覆盖关键场景（如压测）</td></tr></tbody></table><blockquote><p>AI 审查是「自动化质检」；人工审查是「负责人签字」——<strong>两道都过才能 merge</strong>。</p></blockquote><h3 id="为什么要换-AI-还要人工？"><a href="#为什么要换-AI-还要人工？" class="headerlink" title="为什么要换 AI + 还要人工？"></a>为什么要换 AI + 还要人工？</h3><table><thead><tr><th>风险</th><th>只有 implement AI 自审</th><th>只有 AI 审查</th><th><strong>AI 审查 + 人工审查</strong></th></tr></thead><tbody><tr><td>实现偏见</td><td>高</td><td>低</td><td>低</td></tr><tr><td>审查 AI 漏检</td><td>—</td><td>有</td><td><strong>人工兜底</strong></td></tr><tr><td>代码不可控</td><td>高</td><td>中</td><td><strong>低——人必须看懂 diff</strong></td></tr><tr><td>业务/运行时 bug</td><td>高</td><td>中</td><td><strong>低——人凭领域经验拦截</strong></td></tr></tbody></table><hr><h3 id="Step-5：-review-—-AI-双轴审查"><a href="#Step-5：-review-—-AI-双轴审查" class="headerlink" title="Step 5：/review — AI 双轴审查"></a>Step 5：<code>/review</code> — AI 双轴审查</h3><p><strong>操作</strong>：</p><ol><li><strong>切换 AI</strong>（见上方选型表，必须和 implement 不同）</li><li><strong>新开一个会话</strong>（不要复用 implement 会话）</li><li>只提供审查所需的最小上下文：<ul><li>Issue 链接 / PRD 路径</li><li>固定点（如 <code>lmy/v1-mvp</code> 或 merge-base）</li><li>命令：<code>/review since lmy/v1-mvp</code>（或具体 commit / 分支名）</li></ul></li></ol><p><strong>示例触发</strong>（Opus 审查 Sonnet 的实现）：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">新会话 · Opus 4.8（或 Codex / Claude Code）</span><br><span class="line"></span><br><span class="line">/review since lmy/v1-mvp</span><br><span class="line"></span><br><span class="line">审查 feat/I-14-pgvector-ann 分支上的改动。</span><br><span class="line">Spec 来源：GitLab Issue #I-14</span><br></pre></td></tr></table></figure><p><strong>做什么</strong>：从固定点审查 diff，<strong>Standards + Spec 两个维度并行</strong>：</p><table><thead><tr><th>轴</th><th>审查什么</th></tr></thead><tbody><tr><td><strong>Standards</strong></td><td>是否符合仓库编码规范（CODING_STANDARDS、CONTRIBUTING 等）</td></tr><tr><td><strong>Spec</strong></td><td>是否忠实实现了 Issue/PRD 的要求（不多不少）</td></tr></tbody></table><p><strong>典型结论组合</strong>：</p><ul><li>Standards ✅ + Spec ✅ → 进入 <strong>Step 6 人工审查</strong></li><li>Standards ✅ + Spec ❌ → 回 Phase 1 修</li><li>Standards ❌ + Spec ✅ → 回 Phase 1 修</li></ul><p><strong>AI 审查发现问题后的处理</strong>：</p><ol><li>回到 <strong>Sonnet 4.6 · 新会话</strong>修代码</li><li>修完 commit → 重新 AI 审查 → 再进入人工审查</li></ol><p><strong>AI 审查检查清单</strong>：</p><ul><li><input disabled="" type="checkbox"> 审查 AI 和实现 AI 不是同一个？</li><li><input disabled="" type="checkbox"> 审查会话里没有 implement 过程的历史？</li><li><input disabled="" type="checkbox"> Spec 来源（Issue / PRD）已提供给审查 AI？</li><li><input disabled="" type="checkbox"> Standards + Spec 两轴都 OK？</li></ul><hr><h3 id="Step-6：人工审查-—-兜底签字"><a href="#Step-6：人工审查-—-兜底签字" class="headerlink" title="Step 6：人工审查 — 兜底签字"></a>Step 6：人工审查 — 兜底签字</h3><p><strong>什么时候做</strong>：AI 审查两轴都通过之后，<strong>提 MR 之前</strong>。</p><p><strong>怎么做</strong>（建议 15–30 分钟，视 diff 大小）：</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1. 看完整 diff</span></span><br><span class="line">git diff lmy/v1-mvp...HEAD</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2. 对照 Issue Acceptance Criteria 逐条勾选</span></span><br><span class="line"><span class="comment"># 3. 重点文件逐段读，确保「我看得懂、我敢 merge」</span></span><br></pre></td></tr></table></figure><p><strong>人工审查重点</strong>（按优先级）：</p><ol><li><p><strong>我是否理解每一行关键改动？</strong><br>看不懂的 → 要么让 AI 解释，要么要求重写，<strong>禁止「AI 写的应该没问题」式 merge</strong></p></li><li><p><strong>业务/领域是否正确？</strong><br>例如：秒杀扣库存有没有超卖风险、推荐链路降级顺序对不对</p></li><li><p><strong>运行时会不会炸？</strong><br>内存、连接池、并发、超时、重试、幂等</p></li><li><p><strong>有没有动到我不期望的地方？</strong><br>顺手 refactor、改配置、删日志、动其他模块</p></li><li><p><strong>测试真的验到了吗？</strong><br>不能只有 happy path；关键边界、失败路径有没有覆盖</p></li><li><p><strong>上线后我能不能排障？</strong><br>日志够不够、错误信息清不清楚、开关能不能回滚</p></li></ol><p><strong>人工审查结论</strong>：</p><table><thead><tr><th>结论</th><th>动作</th></tr></thead><tbody><tr><td>✅ 通过</td><td>提 MR</td></tr><tr><td>⚠️ 有小疑问但可接受</td><td>在 MR 描述里记一笔，或补一条 follow-up Issue</td></tr><tr><td>❌ 不通过</td><td>回 Phase 1 修，或新开会话让 AI 按我的反馈改</td></tr></tbody></table><p><strong>人工审查检查清单</strong>：</p><ul><li><input disabled="" type="checkbox"> diff 全看过一遍（至少所有非测试的关键文件）？</li><li><input disabled="" type="checkbox"> Issue Acceptance Criteria 逐条确认？</li><li><input disabled="" type="checkbox"> 关键业务逻辑我理解且认可？</li><li><input disabled="" type="checkbox"> 并发/性能/安全敏感点检查过？</li><li><input disabled="" type="checkbox"> 测试覆盖我关心的场景？</li><li><input disabled="" type="checkbox"> <strong>我敢为这个 merge 负责？</strong></li></ul><hr><h3 id="Step-7：MR-Issue-闭环"><a href="#Step-7：MR-Issue-闭环" class="headerlink" title="Step 7：MR + Issue 闭环"></a>Step 7：MR + Issue 闭环</h3><p><strong>前提</strong>：AI 审查 ✅ <strong>且</strong> 人工审查 ✅</p><p><strong>Commit</strong>（Phase 1 完成时）：</p><ul><li><code>/implement</code> 完成后 commit 到 feat 分支</li><li>commit message 引用 Issue 编号（如 <code>feat: pgvector ANN query (#I-14)</code>）</li></ul><p><strong>MR</strong>（AI 审查 + 人工审查都通过后）：</p><ul><li>从 <code>feat/I-xx</code> → <code>lmy/v1-mvp</code>（或项目集成线）</li><li>如果单个 Issue 改动过大，用 <code>/split-to-prs</code> 拆成多个小 MR（<strong>先出方案，你 approve 后再执行</strong>）</li></ul><p><strong>Issue 闭环</strong>：</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">glab issue close &lt;issue-id&gt;</span><br></pre></td></tr></table></figure><hr><h2 id="五、Skill-速查表"><a href="#五、Skill-速查表" class="headerlink" title="五、Skill 速查表"></a>五、Skill 速查表</h2><table><thead><tr><th>阶段</th><th>Skill</th><th>AI / 模型</th><th>触发</th><th>产出</th></tr></thead><tbody><tr><td>压力测试</td><td><code>/grill-with-docs</code></td><td>Opus 4.8</td><td>大需求启动</td><td>决策纪要 + CONTEXT/ADR</td></tr><tr><td>写 PRD</td><td><code>/to-prd</code></td><td>Opus 4.8</td><td>Grill 完成后</td><td>PRD Issue</td></tr><tr><td>拆任务</td><td><code>/to-issues</code></td><td>Opus 4.8</td><td>PRD 完成后</td><td>多个垂直切片 Issue</td></tr><tr><td>实现</td><td><code>/implement</code></td><td>Sonnet 4.6</td><td>每 Issue 新会话</td><td>代码 + 测试 + commit</td></tr><tr><td>测试驱动</td><td><code>/tdd</code></td><td>Sonnet 4.6</td><td>implement 内</td><td>行为测试</td></tr><tr><td><strong>AI 审查</strong></td><td><strong><code>/review</code></strong></td><td><strong>其他 AI</strong>（Opus / Codex / Claude Code）</td><td>implement 后 · 新会话</td><td>Standards + Spec 报告</td></tr><tr><td><strong>人工审查</strong></td><td>—</td><td><strong>我自己</strong></td><td>AI 审查通过后 · 提 MR 前</td><td>签字确认，代码可控</td></tr><tr><td>拆 MR</td><td><code>/split-to-prs</code></td><td>Sonnet 4.6</td><td>改动过大时</td><td>多个小 MR 方案</td></tr><tr><td>调试</td><td><code>/diagnosing-bugs</code></td><td>按需</td><td>测试失败/回归</td><td>诊断报告</td></tr><tr><td>领域建模</td><td><code>/domain-modeling</code></td><td>Opus 4.8</td><td>grill 内自动</td><td>CONTEXT/ADR</td></tr><tr><td>架构设计</td><td><code>/codebase-design</code></td><td>Opus 4.8</td><td>需要定 seam 时</td><td>接口/seam 方案</td></tr></tbody></table><hr><h2 id="六、与小需求流程的对比"><a href="#六、与小需求流程的对比" class="headerlink" title="六、与小需求流程的对比"></a>六、与小需求流程的对比</h2><table><thead><tr><th></th><th>大需求</th><th>小需求</th></tr></thead><tbody><tr><td>起点</td><td><code>/grill-with-docs</code></td><td>直接描述需求</td></tr><tr><td>文档</td><td>PRD + Issues</td><td>无 / 口头</td></tr><tr><td>实现 AI</td><td>Sonnet 4.6</td><td>Sonnet 一把梭</td></tr><tr><td>审查</td><td>AI 审查 + <strong>人工审查</strong></td><td>改动大时至少人工过 diff</td></tr><tr><td>会话</td><td>规划 1 + 实现 1 + AI 审查 1 + 人工审查（每 Issue）</td><td>通常 1 会话</td></tr><tr><td>验收</td><td>AI <code>/review</code> + <strong>人工签字</strong></td><td>手动看一眼</td></tr><tr><td>适用</td><td>跨模块改造、新功能、架构变更</td><td>Bug fix、小改动、探索性原型</td></tr></tbody></table><hr><h2 id="七、实践原则"><a href="#七、实践原则" class="headerlink" title="七、实践原则"></a>七、实践原则</h2><h3 id="1-规划阶段不要省"><a href="#1-规划阶段不要省" class="headerlink" title="1. 规划阶段不要省"></a>1. 规划阶段不要省</h3><p>前面一行代码都没写，全在规划——理清楚了，implement 才是一次跑通。Grill + PRD + Issues 对应 Spec Coding 的 specify → plan → tasks；<code>/speckit-specify</code> 强调需求阶段零技术词，我的 <code>/grill-with-docs</code> 更重读代码库和写 ADR，但「先对齐再写码」是同一件事。</p><p>Opus 一个 Grill 会话的 token 成本，通常远低于 implement 完发现方向错了的返工。</p><h3 id="2-人的价值在「懂行」"><a href="#2-人的价值在「懂行」" class="headerlink" title="2. 人的价值在「懂行」"></a>2. 人的价值在「懂行」</h3><ul><li>AI 负责 ~80% 执行决策（怎么写）</li><li>人负责 ~70% 规划决策（做什么、约束是什么）</li><li><strong>Prompt 质量 = 领域专业度</strong>，不是语法能力</li></ul><h3 id="3-垂直切片-gt-水平分层"><a href="#3-垂直切片-gt-水平分层" class="headerlink" title="3. 垂直切片 &gt; 水平分层"></a>3. 垂直切片 &gt; 水平分层</h3><ul><li>每个 Issue 端到端可验证</li><li><code>/tdd</code> 也在垂直 slice 内 RED→GREEN，不要先写完全部测试</li></ul><h3 id="4-重要规则落文件"><a href="#4-重要规则落文件" class="headerlink" title="4. 重要规则落文件"></a>4. 重要规则落文件</h3><ul><li>项目规范 → <code>CLAUDE.md</code> / <code>AGENTS.md</code></li><li>架构决策 → <code>docs/adr/</code></li><li>领域词汇 → <code>CONTEXT.md</code></li><li>不要只在对话里说，压缩上下文后会丢</li></ul><h3 id="5-AI-审查-人工审查，两道门"><a href="#5-AI-审查-人工审查，两道门" class="headerlink" title="5. AI 审查 + 人工审查，两道门"></a>5. AI 审查 + 人工审查，两道门</h3><ul><li>Implement 和 AI Review <strong>必须不同会话、不同 AI</strong></li><li>AI 审查通过后，<strong>人工必须过 diff</strong>——不能 AI 说 OK 就 merge</li><li>人工审查的核心问题：<strong>「我看得懂吗？我敢负责吗？」</strong></li><li>看不懂 → 让 AI 解释或重写，禁止盲 merge</li></ul><h3 id="6-会话管理"><a href="#6-会话管理" class="headerlink" title="6. 会话管理"></a>6. 会话管理</h3><table><thead><tr><th>场景</th><th>做法</th></tr></thead><tbody><tr><td>换 Issue</td><td><strong>新开会话</strong></td></tr><tr><td>换阶段</td><td>规划 Opus → 实现 Sonnet → AI 审查 → <strong>人工审查</strong></td></tr><tr><td>AI 审查</td><td>新开会话，不带 implement 历史</td></tr><tr><td>人工审查</td><td>自己看 diff，不依赖 AI 会话</td></tr><tr><td>上下文太长</td><td>不要 <code>/compact</code> 后继续 implement，开新会话</td></tr><tr><td>一个 Issue 做不完</td><td>拆 Issue，不要硬撑一个会话</td></tr></tbody></table><p>一 Issue 一会话还有一层原因：Skills 压缩后按预算重注入，<strong>最早触发的先被踢</strong>——规划、implement、review 挤一个会话里，后半段容易「选择性失忆」。</p><h3 id="7-配置层：Skills-承载流程，CLAUDE-md-只放事实"><a href="#7-配置层：Skills-承载流程，CLAUDE-md-只放事实" class="headerlink" title="7. 配置层：Skills 承载流程，CLAUDE.md 只放事实"></a>7. 配置层：Skills 承载流程，CLAUDE.md 只放事实</h3><table><thead><tr><th>内容</th><th>放哪</th><th>例子</th></tr></thead><tbody><tr><td>构建命令、技术栈、目录</td><td>CLAUDE.md / AGENTS.md</td><td><code>uv run pytest</code>、Nacos 约定</td></tr><tr><td>工作流 SOP</td><td>Skills</td><td><code>/grill-with-docs</code>、<code>/implement</code>、<code>/review</code></td></tr><tr><td>路径级规范</td><td><code>.claude/rules/</code> + paths</td><td>API 层 Zod 校验</td></tr><tr><td>格式化 / 危险命令拦截</td><td><strong>Hooks</strong>（待配）</td><td>PostToolUse Prettier、PreToolUse 拦删 migration</td></tr></tbody></table><p>流程写进 CLAUDE.md = 每次说「你好」也带着 deploy runbook；我的 Skills 就是 Spec Coding 工序的代码化。</p><hr><h2 id="八、Checklist-模板"><a href="#八、Checklist-模板" class="headerlink" title="八、Checklist 模板"></a>八、Checklist 模板</h2><h3 id="大需求启动前"><a href="#大需求启动前" class="headerlink" title="大需求启动前"></a>大需求启动前</h3><ul><li><input disabled="" type="checkbox"> 需求足够大，值得走完整流程？（否则直接 implement）</li><li><input disabled="" type="checkbox"> 当前分支策略清楚？</li><li><input disabled="" type="checkbox"> Issue Tracker 可用（<code>glab</code> auth OK）？</li></ul><h3 id="Phase-0-完成"><a href="#Phase-0-完成" class="headerlink" title="Phase 0 完成"></a>Phase 0 完成</h3><ul><li><input disabled="" type="checkbox"> Grill 决策纪要确认</li><li><input disabled="" type="checkbox"> PRD 发布，seam 确认</li><li><input disabled="" type="checkbox"> Issues 发布，breakdown approve</li><li><input disabled="" type="checkbox"> 切换 Sonnet 4.6</li></ul><h3 id="每个-Issue-·-Phase-1-实现完成"><a href="#每个-Issue-·-Phase-1-实现完成" class="headerlink" title="每个 Issue · Phase 1 实现完成"></a>每个 Issue · Phase 1 实现完成</h3><ul><li><input disabled="" type="checkbox"> Sonnet 4.6 · 新会话 + <code>/implement</code></li><li><input disabled="" type="checkbox"> Acceptance Criteria 全满足</li><li><input disabled="" type="checkbox"> 测试全绿，代码已 commit</li></ul><h3 id="每个-Issue-·-Phase-2-AI-审查完成"><a href="#每个-Issue-·-Phase-2-AI-审查完成" class="headerlink" title="每个 Issue · Phase 2 AI 审查完成"></a>每个 Issue · Phase 2 AI 审查完成</h3><ul><li><input disabled="" type="checkbox"> <strong>切换其他 AI</strong> · 新会话 + <code>/review</code></li><li><input disabled="" type="checkbox"> Standards + Spec 两轴通过</li><li><input disabled="" type="checkbox"> 有问题则回 Sonnet 修完 → 再 AI 复审</li></ul><h3 id="每个-Issue-·-Phase-2-人工审查完成"><a href="#每个-Issue-·-Phase-2-人工审查完成" class="headerlink" title="每个 Issue · Phase 2 人工审查完成"></a>每个 Issue · Phase 2 人工审查完成</h3><ul><li><input disabled="" type="checkbox"> <code>git diff</code> 全看过，关键文件逐段理解</li><li><input disabled="" type="checkbox"> Acceptance Criteria 逐条人工确认</li><li><input disabled="" type="checkbox"> 业务逻辑 / 并发 / 安全敏感点检查过</li><li><input disabled="" type="checkbox"> <strong>我敢为这个 merge 负责</strong></li><li><input disabled="" type="checkbox"> MR 提交 + Issue close</li></ul><h3 id="全部-Issue-完成"><a href="#全部-Issue-完成" class="headerlink" title="全部 Issue 完成"></a>全部 Issue 完成</h3><ul><li><input disabled="" type="checkbox"> 集成线（如 <code>lmy/v1-mvp</code>）测试通过</li><li><input disabled="" type="checkbox"> 需要时 <code>/split-to-prs</code> 整理 MR</li><li><input disabled="" type="checkbox"> 更新 <code>CONTEXT.md</code> / ADR（如有新决策）</li></ul><hr><h2 id="九、示例：一次完整大需求"><a href="#九、示例：一次完整大需求" class="headerlink" title="九、示例：一次完整大需求"></a>九、示例：一次完整大需求</h2><p>以 scm-rec-py v1 MVP 改造为例：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">1. [Opus 4.8 · Cursor · 会话 A] 规划</span><br><span class="line">   /grill-with-docs → v1 范围、验收标准、分支策略定稿</span><br><span class="line">   /to-prd          → Epic PRD 发布到 GitLab</span><br><span class="line">   /to-issues       → I-10 ONNX、I-11 OOM、I-12 索引性能… </span><br><span class="line"></span><br><span class="line">2. [Sonnet 4.6 · Cursor · 会话 B] feat/I-10-onnx · 实现</span><br><span class="line">   /implement #I-10 → 测试全绿 → commit</span><br><span class="line"></span><br><span class="line">3. [Opus 4.8 · Cursor · 会话 C] feat/I-10-onnx · AI 审查</span><br><span class="line">   /review since lmy/v1-mvp → Standards ✅ Spec ✅</span><br><span class="line"></span><br><span class="line">4. [我 · 人工] feat/I-10-onnx · 人工审查</span><br><span class="line">   git diff 过一遍 → 业务/并发/测试确认 → ✅ 签字</span><br><span class="line"></span><br><span class="line">5. 提 MR → merge → close #I-10</span><br><span class="line"></span><br><span class="line">6. [Sonnet · 会话 D] feat/I-11-oom · 实现</span><br><span class="line">   /implement #I-11 → commit</span><br><span class="line"></span><br><span class="line">7. [其他 AI · 会话 E] · AI 审查 → [我 · 人工审查] → MR → close</span><br><span class="line"></span><br><span class="line">8. … 逐个 Issue：实现 → AI 审查 → 人工审查 …</span><br><span class="line"></span><br><span class="line">9. 全部完成后 lmy/v1-mvp 集成验收</span><br></pre></td></tr></table></figure><hr><h2 id="十、还没做好的-待改进"><a href="#十、还没做好的-待改进" class="headerlink" title="十、还没做好的 / 待改进"></a>十、还没做好的 / 待改进</h2><table><thead><tr><th>项</th><th>现状</th><th>计划</th></tr></thead><tbody><tr><td>Hooks</td><td>格式化、lint 还靠 CLAUDE.md 建议</td><td>PostToolUse format + PreToolUse 危险命令拦截</td></tr><tr><td>CLAUDE.md 审计</td><td>部分 repo 可能超标、混入了流程</td><td>流程迁 Skills，200 行内 + 索引</td></tr><tr><td>spec-kit 对比</td><td>用自定义 Skills，未跑过官方 spec-kit</td><td>挑一个 demo 项目 A/B 对比</td></tr><tr><td>Stop Hook 验证</td><td>靠 implement 内跑测试</td><td>考虑 Stop hook 做确定性 gate（待验证 ROI）</td></tr><tr><td>审查 DeepSeek 初筛</td><td>省 token 但漏检过</td><td>仅小改动用，大改动 Opus/Codex</td></tr></tbody></table><hr><p><em>最后更新：2026-07-03 · 和桌面其他「个人总结」配套使用</em></p>]]>
    </content>
    <id>https://w-li-you.github.io/2026/06/02/my-ai-coding-workflow/</id>
    <link href="https://w-li-you.github.io/2026/06/02/my-ai-coding-workflow/"/>
    <published>2026-06-01T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h1 id="我的-AI-编程工作流"><a href="#我的-AI-编程工作流" class="headerlink" title="我的 AI 编程工作流"></a>我的 AI 编程工作流</h1><blockquote>
<p>个人实践总结 · Cursor / Claude Code 大需求开发<br>核心理念：<strong>规划用强模型想清楚，执行用快模型低成本落地，AI 审查 + 人工审查双保险</strong></p>
</blockquote>
<hr>]]>
    </summary>
    <title>我的 AI 编程工作流</title>
    <updated>2026-07-05T15:48:14.473Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="AI编程" scheme="https://w-li-you.github.io/categories/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="AI编程" scheme="https://w-li-you.github.io/tags/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="Cursor" scheme="https://w-li-you.github.io/tags/Cursor/"/>
    <category term="模型选型" scheme="https://w-li-you.github.io/tags/%E6%A8%A1%E5%9E%8B%E9%80%89%E5%9E%8B/"/>
    <content>
      <![CDATA[<h1 id="我的-AI-模型选型对比"><a href="#我的-AI-模型选型对比" class="headerlink" title="我的 AI 模型选型对比"></a>我的 AI 模型选型对比</h1><blockquote><p>个人使用备忘 · 感受来自日常开发，<strong>不一定完全准确</strong><br>配合《我的AI编程工作流》· 索引见《AI编程-个人文档索引》<br>最后更新：2026-07-03</p></blockquote><hr><a id="more"></a><h2 id="一、一句话选型"><a href="#一、一句话选型" class="headerlink" title="一、一句话选型"></a>一、一句话选型</h2><table><thead><tr><th>场景</th><th>我一般用</th><th>备选</th></tr></thead><tbody><tr><td>定技术方案 / Grill / PRD</td><td><strong>Opus 4.8</strong></td><td>Opus 4.7</td></tr><tr><td>写代码 / Implement</td><td><strong>Sonnet 4.6</strong></td><td>Composer 2.5</td></tr><tr><td>AI 审查</td><td><strong>Opus 4.8</strong> 或 <strong>GPT-5.3 Codex</strong></td><td>DeepSeek Pro</td></tr><tr><td>人工审查</td><td><strong>我自己</strong></td><td>—</td></tr><tr><td>查工单 / 快问快答</td><td><strong>Composer 2.5</strong></td><td>—</td></tr></tbody></table><hr><h2 id="二、总览（我的主观打分）"><a href="#二、总览（我的主观打分）" class="headerlink" title="二、总览（我的主观打分）"></a>二、总览（我的主观打分）</h2><table><thead><tr><th>模型</th><th>费用感知</th><th>速度感受</th><th>定方案</th><th>写代码</th><th>审查</th><th>一句话</th></tr></thead><tbody><tr><td>Opus 4.8</td><td>贵</td><td>慢</td><td>★★★★★</td><td>好</td><td>很好</td><td>定方案专用，贵但值得</td></tr><tr><td>Opus 4.7</td><td>贵</td><td>慢</td><td>★★★★☆</td><td>好</td><td>很好</td><td>和 4.8 日常差不多</td></tr><tr><td>Sonnet 5</td><td>中高</td><td>偏慢</td><td>好</td><td>好</td><td>好</td><td>卡在中间，我很少用</td></tr><tr><td>Sonnet 4.6</td><td>中</td><td>还行</td><td>够用</td><td>★★★★★</td><td>够用</td><td>写代码主力</td></tr><tr><td>GPT-5.3 Codex</td><td>中</td><td>中</td><td>一般</td><td>专精</td><td>好</td><td>审查换厂商用</td></tr><tr><td>GPT-5.5</td><td>高</td><td>中</td><td>较好</td><td>好</td><td>较好</td><td>用得少</td></tr><tr><td>Composer 2.5</td><td>低</td><td>快</td><td>弱</td><td>快</td><td>一般</td><td>查工单、小活</td></tr><tr><td>DeepSeek Pro</td><td>极低</td><td>快</td><td>弱</td><td>一般</td><td>初筛</td><td>便宜审查，要人工补</td></tr></tbody></table><hr><h2 id="三、各模型使用感受"><a href="#三、各模型使用感受" class="headerlink" title="三、各模型使用感受"></a>三、各模型使用感受</h2><h3 id="Opus-4-8"><a href="#Opus-4-8" class="headerlink" title="Opus 4.8"></a>Opus 4.8</h3><p><strong>我怎么用</strong>：大需求开 <code>/grill-with-docs</code>、出 PRD、拆 Issues，重要改动的 AI 审查也用它。</p><p><strong>我的感受</strong>：</p><ul><li>思考明显慢，转圈时间长，但<strong>想的东西确实全</strong>——会反问我「验收标准是什么」「这个 Out-of-Scope 要不要排除」，有时候还会帮我把边界想得更清楚</li><li><strong>贵</strong>，是目前账单里最能感觉到花钱的模型，一个 Grill 会话下来用量肉眼可见</li><li>写具体代码也能写，但拿它 implement 小 Issue 有点浪费，我基本不用它写 CRUD</li></ul><p><strong>和 4.7 比</strong>：日常短对话体感差别不大（待验证：超长会话 4.8 可能更稳，我还没专门 A/B 测过）</p><p><strong>印象</strong>：像资深架构师，慢，但适合「先把方向定死」</p><hr><h3 id="Opus-4-7"><a href="#Opus-4-7" class="headerlink" title="Opus 4.7"></a>Opus 4.7</h3><p><strong>我的感受</strong>：</p><ul><li>和 4.8 <strong>用起来感觉差不多</strong>，没感到明显「代差」</li><li>同样慢、同样贵、同样会追问</li><li>4.8 排队或限额时直接换 4.7，规划质量没觉得掉档</li></ul><p><strong>印象</strong>：4.8 的平替，够用了</p><hr><h3 id="Sonnet-5"><a href="#Sonnet-5" class="headerlink" title="Sonnet 5"></a>Sonnet 5</h3><p><strong>我的感受</strong>：</p><ul><li>官方说 speed + intelligence 平衡，但我用起来<strong>体感偏慢</strong>，没有 4.6 那种「说干就干」的爽感</li><li>虽然 token 单价在促销，但<strong>用量下得很快</strong>，怀疑是 thinking 在背后烧（待验证：没试过调低 effort）</li><li>能力应该比 4.6 强，但对我来说<strong>定位尴尬</strong>——定方案不如 Opus 深，写代码不如 4.6 听话省心</li></ul><p><strong>印象</strong>：试了几回就回到 4.6 了，暂时不是主力</p><hr><h3 id="Sonnet-4-6"><a href="#Sonnet-4-6" class="headerlink" title="Sonnet 4.6"></a>Sonnet 4.6</h3><p><strong>我怎么用</strong>：每个 Issue 新开会话 <code>/implement</code>，工作流里 Phase 1 固定用它。</p><p><strong>我的感受</strong>：</p><ul><li><strong>非常听话</strong>——Issue 和 Acceptance Criteria 写清楚，基本按条做，很少自作主张大改架构</li><li>速度、费用都在能接受的范围，比 Opus 省很多</li><li>让它单独做 Grill 或写大 PRD <strong>深度不够</strong>，会漏一些边界考量</li><li>不适合审自己刚写的代码，和 implement 同模型容易「互相放过」</li></ul><p><strong>印象</strong>：靠谱的执行者，给清楚任务就稳定交付</p><hr><h3 id="GPT-5-3-Codex（我用的-Codex）"><a href="#GPT-5-3-Codex（我用的-Codex）" class="headerlink" title="GPT-5.3 Codex（我用的 Codex）"></a>GPT-5.3 Codex（我用的 Codex）</h3><p><strong>我怎么用</strong>：主要是 <strong>换 OpenAI 审 Claude 写的代码</strong>，做 AI 审查那道门。</p><p><strong>我的感受</strong>：</p><ul><li>看 diff、找规范问题、对照 Issue 检查 <strong>够用</strong></li><li><strong>不太习惯它的输出风格</strong>——文字偏短、偏「任务清单」，写技术方案或 PRD 时缺少 Opus 那种「为什么选 A 不选 B」的讨论</li><li>不是不能用，是 <strong>和 Claude 习惯不一样</strong>，prompt 要重新适应</li><li>implement 试过几次，能写，但我更信任 4.6 的「听话」</li></ul><p><strong>和其他 Codex 型号</strong>：具体用的 5.3，5.1/5.2 没仔细对比过（待验证）</p><p><strong>印象</strong>：适合当「第二双眼」审代码，不适合当「主笔」写方案</p><hr><h3 id="GPT-5-5"><a href="#GPT-5-5" class="headerlink" title="GPT-5.5"></a>GPT-5.5</h3><p><strong>我的感受</strong>：</p><ul><li>用得不多，偶尔通用任务</li><li>比 Codex 写文档像样一点，但 <strong>定大方案还是 Opus 更顺</strong></li><li>费用感知比 Codex 高，和 Opus 档接近，所以不常选</li></ul><p><strong>印象</strong>：有能力的通用模型，但在我工作流里没占到固定位置</p><hr><h3 id="Composer-2-5"><a href="#Composer-2-5" class="headerlink" title="Composer 2.5"></a>Composer 2.5</h3><p><strong>我怎么用</strong>：查 SCM 工单、快速总结、FAQ 类问答；极小改动有时也用它。</p><p><strong>我的感受</strong>：</p><ul><li><strong>快</strong>，响应几乎不用等</li><li><strong>便宜</strong>，用量几乎无感，适合高频低价值任务</li><li>写技术方案 <strong>深度不够</strong>，Grill 级讨论 hold 不住</li><li>复杂 Issue implement <strong>不如 4.6 稳</strong>，有过改着改着偏题的情况（样本不多，待验证）</li></ul><p><strong>印象</strong>：日常杂活神器，别拿它干重活</p><hr><h3 id="DeepSeek-Pro（V4-Pro）"><a href="#DeepSeek-Pro（V4-Pro）" class="headerlink" title="DeepSeek Pro（V4-Pro）"></a>DeepSeek Pro（V4-Pro）</h3><p><strong>我怎么用</strong>：审查阶段 <strong>省钱初筛</strong>——先看一遍 diff，再人工过，重要改动 Opus/Codex 复审。</p><p><strong>我的感受</strong>：</p><ul><li><strong>极便宜</strong>，审查几轮也不心疼</li><li>速度 OK，中文业务场景理解还行</li><li><strong>考虑不够全面</strong>——并发、边界 case、顺手改别的文件这类问题，漏过几次（所以必须人工补）</li><li>不能当最终审查，只能当第一道筛子</li></ul><p><strong>印象</strong>：便宜的预审员，后面还得我自己签字</p><hr><h2 id="四、按工作流怎么用"><a href="#四、按工作流怎么用" class="headerlink" title="四、按工作流怎么用"></a>四、按工作流怎么用</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">Phase 0 规划        Opus 4.8（4.7 也行）</span><br><span class="line">Phase 1 实现        Sonnet 4.6</span><br><span class="line">Phase 2 AI 审查     Opus 4.8 / Codex（换厂商）</span><br><span class="line">                    或 DeepSeek 初筛 + 人工</span><br><span class="line">Phase 2 人工审查    我自己（必做）</span><br><span class="line">日常查工单          Composer 2.5</span><br></pre></td></tr></table></figure><hr><h2 id="五、我常用的组合"><a href="#五、我常用的组合" class="headerlink" title="五、我常用的组合"></a>五、我常用的组合</h2><table><thead><tr><th>组合</th><th>什么时候用</th><th>体感</th></tr></thead><tbody><tr><td>Opus 规划 → Sonnet 写 → Opus 审 → 人工</td><td>大需求、要上心的改动</td><td>最稳，贵</td></tr><tr><td>Opus 规划 → Sonnet 写 → Codex 审 → 人工</td><td>想和 Claude 实现隔离</td><td>推荐，审查视角更独立</td></tr><tr><td>Opus 规划 → Sonnet 写 → DeepSeek 审 → 人工</td><td>想省审查 token</td><td>能用，人工得多看两眼</td></tr><tr><td>Composer 查工单</td><td>WTGD 排查、FAQ</td><td>快省，够用</td></tr></tbody></table><hr><h2 id="六、费用-vs-质量（我的体感）"><a href="#六、费用-vs-质量（我的体感）" class="headerlink" title="六、费用 vs 质量（我的体感）"></a>六、费用 vs 质量（我的体感）</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">          质量</span><br><span class="line">           ↑</span><br><span class="line">Opus ●     │      GPT-5.5 ●</span><br><span class="line">Sonnet 5 ● │</span><br><span class="line">           │           Sonnet 4.6 ●</span><br><span class="line">Codex ●    │</span><br><span class="line">           │      Composer ●</span><br><span class="line">           │           DeepSeek ●</span><br><span class="line">           └────────────────→ 费用（越低越右）</span><br></pre></td></tr></table></figure><hr><h2 id="七、快速决策"><a href="#七、快速决策" class="headerlink" title="七、快速决策"></a>七、快速决策</h2><ul><li><strong>要想清楚再动手</strong> → Opus 4.8</li><li><strong>Issue 明确了开写</strong> → Sonnet 4.6</li><li><strong>审别人/AI 写的代码</strong> → 换 Opus 或 Codex，最后人工过</li><li><strong>查工单、小问答</strong> → Composer 2.5</li><li><strong>审查想省钱</strong> → DeepSeek 初筛，人工不能省</li></ul><hr><h2 id="八、备注"><a href="#八、备注" class="headerlink" title="八、备注"></a>八、备注</h2><ul><li>上面都是 <strong>我个人习惯</strong>，换项目、换 prompt 可能不一样</li><li>带「待验证」的是样本少或没系统对比过，大方向应该对</li><li>模型更新快，这篇不对了随时改</li></ul><hr><p><em>感受会随模型更新变，当个人备忘用。</em></p>]]>
    </content>
    <id>https://w-li-you.github.io/2026/05/18/ai-model-selection-comparison/</id>
    <link href="https://w-li-you.github.io/2026/05/18/ai-model-selection-comparison/"/>
    <published>2026-05-17T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h1 id="我的-AI-模型选型对比"><a href="#我的-AI-模型选型对比" class="headerlink" title="我的 AI 模型选型对比"></a>我的 AI 模型选型对比</h1><blockquote>
<p>个人使用备忘 · 感受来自日常开发，<strong>不一定完全准确</strong><br>配合《我的AI编程工作流》· 索引见《AI编程-个人文档索引》<br>最后更新：2026-07-03</p>
</blockquote>
<hr>]]>
    </summary>
    <title>我的 AI 模型选型对比</title>
    <updated>2026-07-05T15:33:40.240Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="读书笔记" scheme="https://w-li-you.github.io/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/"/>
    <category term="读书笔记" scheme="https://w-li-you.github.io/tags/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/"/>
    <category term="管理" scheme="https://w-li-you.github.io/tags/%E7%AE%A1%E7%90%86/"/>
    <content>
      <![CDATA[<blockquote><p>本篇涵盖第十一、十二章：在混乱中管理，以及管理者的自我修炼。这是本系列最后一篇。</p></blockquote><a id="more"></a><h2 id="十一、在组织变革中管理"><a href="#十一、在组织变革中管理" class="headerlink" title="十一、在组织变革中管理"></a>十一、在组织变革中管理</h2><p>格鲁夫在英特尔经历了从存储芯片转型到微处理器的战略转型，这段经历让他对”组织变革”有了切身体会。</p><h3 id="战略转折点（Strategic-Inflection-Point）"><a href="#战略转折点（Strategic-Inflection-Point）" class="headerlink" title="战略转折点（Strategic Inflection Point）"></a>战略转折点（Strategic Inflection Point）</h3><p>他定义了一个概念：<strong>战略转折点</strong>——当外部力量（技术、市场、竞争）的变化大到足以从根本上改变一个行业的规则时，就到了战略转折点。</p><p>处于转折点时，企业有两种选择：</p><ol><li>认清现实，主动调整方向（英特尔的选择）</li><li>固守原有模式，等待被淘汰</li></ol><blockquote><p>“记忆芯片的竞争我们输了，但我们没有等着它把我们淹没。”</p></blockquote><h3 id="变革中的管理挑战"><a href="#变革中的管理挑战" class="headerlink" title="变革中的管理挑战"></a>变革中的管理挑战</h3><p>变革最难的不是技术方向的选择，而是<strong>让人相信变革是必须的</strong>。格鲁夫说，旧业务的捍卫者永远比新方向的倡导者更有说服力——因为他们有数据，有历史，有情感。</p><p>管理者在变革中的职责：</p><ul><li>接受”混乱中间地带”是必须经历的过程</li><li>不要过早强行收敛，允许不同方向的探索</li><li>但也不能无限期拖延，必须在合适的时机<strong>收敛并拍板</strong></li></ul><h3 id="对个人的影响"><a href="#对个人的影响" class="headerlink" title="对个人的影响"></a>对个人的影响</h3><p>组织转型期，对中层管理者心理冲击最大——他们的经验和人脉都绑定在旧业务上，转型意味着放弃已有的优势重新出发。格鲁夫对此的态度是：</p><blockquote><p>“你已经做过一次从零开始了，你可以再做一次。”</p></blockquote><hr><h2 id="十二、管理者的修炼"><a href="#十二、管理者的修炼" class="headerlink" title="十二、管理者的修炼"></a>十二、管理者的修炼</h2><p>最后一章，格鲁夫回归到个人层面，讨论一个管理者如何持续成长。</p><h3 id="培训下属：最高杠杆活动之一"><a href="#培训下属：最高杠杆活动之一" class="headerlink" title="培训下属：最高杠杆活动之一"></a>培训下属：最高杠杆活动之一</h3><p>他认为，管理者亲自培训下属，是<strong>杠杆率最高的活动之一</strong>。一次高质量的培训，可以提升整个团队的能力，效果持续多年。</p><p>这和外包培训本质不同：外包培训传递的是通用知识，而管理者的亲授传递的是<strong>该组织特有的文化、标准和方法论</strong>，是无法外包的。</p><h3 id="给新晋管理者的忠告"><a href="#给新晋管理者的忠告" class="headerlink" title="给新晋管理者的忠告"></a>给新晋管理者的忠告</h3><p>格鲁夫对从个人贡献者（IC）晋升为管理者的人有几条建议：</p><ol><li><p><strong>认清角色转变</strong>：你的价值来源从”亲自做出成果”变成了”帮助团队做出成果”。这个转变在心理上比职级调整更难。</p></li><li><p><strong>不要管你不该管的事</strong>：继续用老方法（自己撸袖子写代码）可能带来短期安慰，但会剥夺下属成长的机会，也让你没时间做真正的管理工作。</p></li><li><p><strong>建立自己的管理风格，而不是模仿某人</strong>：好的管理者各有风格，共同点是<strong>了解自己的局限性</strong>，并主动弥补。</p></li></ol><h3 id="最后：管理的本质"><a href="#最后：管理的本质" class="headerlink" title="最后：管理的本质"></a>最后：管理的本质</h3><p>格鲁夫在结尾写道：</p><blockquote><p>“管理是一项艰难的工作，没有捷径。它需要你不断审视自己的判断，承认错误，在不确定中做决策，在不完美的信息下推进团队前行。但当你做对了，你会看到那些比你聪明的人，因为你的工作而发挥出更大的价值——那就是管理的意义所在。”</p></blockquote><hr><h2 id="全书总结"><a href="#全书总结" class="headerlink" title="全书总结"></a>全书总结</h2><p>六篇笔记下来，格鲁夫这本书给我印象最深的三点：</p><ol><li><strong>产出导向</strong>：管理者的价值在于团队产出，不在于自己有多忙。</li><li><strong>TRM 模型</strong>：管理风格要匹配对方在具体任务上的成熟度，没有万能风格。</li><li><strong>会议和信息</strong>：1on1 是最重要的管理工具，做好了比任何激励制度都有效。</li></ol><p>这本书写于 1983 年，但书里讨论的问题——如何激励人、如何做决策、如何在组织变革中生存——在今天的技术团队管理中依然高度相关。</p>]]>
    </content>
    <id>https://w-li-you.github.io/2026/05/05/grove-high-output-management-6/</id>
    <link href="https://w-li-you.github.io/2026/05/05/grove-high-output-management-6/"/>
    <published>2026-05-04T16:00:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>本篇涵盖第十一、十二章：在混乱中管理，以及管理者的自我修炼。这是本系列最后一篇。</p>
</blockquote>]]>
    </summary>
    <title>《格鲁夫给经理人的第一课》读书笔记（六）：转型、挑战与管理者的修炼</title>
    <updated>2026-07-01T11:45:45.498Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="管理" scheme="https://w-li-you.github.io/categories/%E7%AE%A1%E7%90%86/"/>
    <category term="管理" scheme="https://w-li-you.github.io/tags/%E7%AE%A1%E7%90%86/"/>
    <category term="华为" scheme="https://w-li-you.github.io/tags/%E5%8D%8E%E4%B8%BA/"/>
    <category term="IPD" scheme="https://w-li-you.github.io/tags/IPD/"/>
    <category term="产品研发" scheme="https://w-li-you.github.io/tags/%E4%BA%A7%E5%93%81%E7%A0%94%E5%8F%91/"/>
    <content>
      <![CDATA[<blockquote><p>IPD（集成产品开发）是集成业界最佳实践的研发管理体系，强调”把强大研发能力建在超越研发部的组织上”，实现”让成功从偶然到必然”。本文梳理 IPD 的核心理念、流程与跨部门团队机制。</p></blockquote><a id="more"></a><h2 id="一、IPD-的定位与企业流程架构"><a href="#一、IPD-的定位与企业流程架构" class="headerlink" title="一、IPD 的定位与企业流程架构"></a>一、IPD 的定位与企业流程架构</h2><h3 id="企业流程分类"><a href="#企业流程分类" class="headerlink" title="企业流程分类"></a>企业流程分类</h3><table><thead><tr><th>流程类型</th><th>定义</th><th>核心流程</th></tr></thead><tbody><tr><td><strong>主（价值）流程</strong></td><td>客户价值创造的端到端流程</td><td>IPD、LTC、ITR</td></tr><tr><td><strong>使能流程</strong></td><td>响应主流程需求，支撑主流程价值实现</td><td>—</td></tr><tr><td><strong>支撑流程</strong></td><td>公司基础性流程，保障企业高效低风险运作</td><td>—</td></tr></tbody></table><h3 id="三大主流程（”2-5-个”主流程）"><a href="#三大主流程（”2-5-个”主流程）" class="headerlink" title="三大主流程（”2.5 个”主流程）"></a>三大主流程（”2.5 个”主流程）</h3><table><thead><tr><th>流程</th><th>全称</th><th>驱动力</th><th>核心比喻</th></tr></thead><tbody><tr><td><strong>IPD</strong></td><td>集成产品开发</td><td>产品驱动，从客户普遍需求出发</td><td>“做炮弹”（打造有竞争力的产品）</td></tr><tr><td><strong>LTC</strong></td><td>线索到回款</td><td>营销驱动，从市场线索出发</td><td>“打炮弹”（实现商业成功）</td></tr><tr><td><strong>ITR</strong></td><td>问题到解决</td><td>解决客户使用中的问题</td><td>投入相对较少，视为”半个”主流程</td></tr></tbody></table><hr><h2 id="二、IPD-的渊源与成效"><a href="#二、IPD-的渊源与成效" class="headerlink" title="二、IPD 的渊源与成效"></a>二、IPD 的渊源与成效</h2><ul><li><strong>1986 年</strong>：美国 PRTM 公司提出 PACE（产品及生命周期优化法）；</li><li><strong>1990 年代初</strong>：IBM 引入 PACE 并完善，形成 IPD 体系；</li><li><strong>1999 年</strong>：华为启动 IPD 变革，成为 IPD 在中国发扬光大的关键载体（相关著作《从偶然到必然》）。</li></ul><p><strong>IBM 变革成效：</strong></p><table><thead><tr><th>产品类型</th><th>变革前上市周期</th><th>变革后上市周期</th></tr></thead><tbody><tr><td>高端产品</td><td>70 个月</td><td>20 个月</td></tr><tr><td>中端产品</td><td>50 个月</td><td>10 个月</td></tr></tbody></table><p>研发损失从 26% 降至 6%；研发费用占比从 12% 降至 6%。华为变革后，研发从”偶然推出高水平产品”转变为”可制度性推出有竞争力产品”。</p><hr><h2 id="三、IPD-的六大核心理念"><a href="#三、IPD-的六大核心理念" class="headerlink" title="三、IPD 的六大核心理念"></a>三、IPD 的六大核心理念</h2><ol><li><strong>产品开发是投资行为</strong>（而非救火行为），追求商业成功而非仅产品成功；</li><li><strong>产品研发是基于市场的创新</strong>（市场驱动），而非闭门造车；</li><li><strong>采用结构化的并行开发流程</strong>，打破”串行触发”的低效模式；</li><li><strong>强调跨部门协同</strong>，组建跨部门核心团队；</li><li><strong>技术开发与产品开发分离</strong>，提前储备技术，避免临时攻关；</li><li><strong>采用基于平台的异步开发模式与重用策略</strong>，提升效率、降低成本。</li></ol><blockquote><p>📌 理念转变案例：华为 2000 年”呆死料颁奖大会”，通过展示研发失误导致的废料和救火机票，警示员工摒弃”闭门造车”思维，重视商业成功。</p></blockquote><hr><h2 id="四、IPD-的核心流程"><a href="#四、IPD-的核心流程" class="headerlink" title="四、IPD 的核心流程"></a>四、IPD 的核心流程</h2><h3 id="4-1-需求管理流程"><a href="#4-1-需求管理流程" class="headerlink" title="4.1 需求管理流程"></a>4.1 需求管理流程</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">需求收集 → 需求处理 → 需求分发 → 全流程跟踪管理</span><br></pre></td></tr></table></figure><p><strong>需求分发的 A/B/C 分类：</strong></p><table><thead><tr><th>类别</th><th>周期</th><th>纳入路径</th></tr></thead><tbody><tr><td><strong>A 类</strong></td><td>长期</td><td>纳入 SP/BP 战略/业务规划</td></tr><tr><td><strong>B 类</strong></td><td>中期</td><td>纳入产品路标</td></tr><tr><td><strong>C 类</strong></td><td>短期/紧急</td><td>纳入项目任务书或当前版本变更</td></tr></tbody></table><h3 id="4-2-产品开发流程（IPD-核心，16446N）"><a href="#4-2-产品开发流程（IPD-核心，16446N）" class="headerlink" title="4.2 产品开发流程（IPD 核心，16446N）"></a>4.2 产品开发流程（IPD 核心，16446N）</h3><table><thead><tr><th>要素</th><th>含义</th></tr></thead><tbody><tr><td><strong>1</strong></td><td>1 个跨部门核心团队</td></tr><tr><td><strong>6</strong></td><td>6 个开发阶段</td></tr><tr><td><strong>4</strong></td><td>4 级计划 WBS</td></tr><tr><td><strong>4</strong></td><td>4 个决策评审点（DCP）</td></tr><tr><td><strong>6</strong></td><td>6 个技术评审点（TR1-TR6）</td></tr><tr><td><strong>N</strong></td><td>N 份阶段性文档交付物</td></tr></tbody></table><p>核心阶段：<code>概念 → 计划 → 开发 → 验证 → 发布 → 生命周期管理</code>。</p><h3 id="4-3-技术开发流程（与产品开发分离）"><a href="#4-3-技术开发流程（与产品开发分离）" class="headerlink" title="4.3 技术开发流程（与产品开发分离）"></a>4.3 技术开发流程（与产品开发分离）</h3><p><strong>核心价值</strong>：技术货架化，提前储备关键技术，实现技术复用，避免临时攻关导致的进度延误。理想状态是技术提前 ready 再启动产品开发，最晚不晚于详细开发阶段完成技术迁移。</p><hr><h2 id="五、IPD-的跨部门团队（核心小组法）"><a href="#五、IPD-的跨部门团队（核心小组法）" class="headerlink" title="五、IPD 的跨部门团队（核心小组法）"></a>五、IPD 的跨部门团队（核心小组法）</h2><h3 id="团队构成"><a href="#团队构成" class="headerlink" title="团队构成"></a>团队构成</h3><table><thead><tr><th>团队</th><th>角色定位</th><th>职责</th></tr></thead><tbody><tr><td><strong>IPMT</strong>（集成产品管理团队）</td><td>“银行家”</td><td>负责投资决策，把控产品方向</td></tr><tr><td><strong>PDT</strong>（产品开发团队）</td><td>“小企业”</td><td>负责产品开发全流程，对结果负责</td></tr><tr><td><strong>核心组</strong></td><td>各职能领域代表</td><td>每个代表背后有对应的外围执行小组</td></tr></tbody></table><p><strong>组织形态</strong>：矩阵型组织——横向跨职能，纵向归属原职能部门，实现”<strong>大平台上的小公司</strong>“（大平台强壮，小公司灵活）。</p><h3 id="运作机制：保障”力出一孔、利出一孔”"><a href="#运作机制：保障”力出一孔、利出一孔”" class="headerlink" title="运作机制：保障”力出一孔、利出一孔”"></a>运作机制：保障”力出一孔、利出一孔”</h3><ul><li><strong>目标与考核</strong>：各职能代表的 PBC 需经团队 Leader 及原职能部门考核人共同签署；</li><li><strong>沟通机制</strong>：产品开发中每周沟通；</li><li><strong>决策机制</strong>：核心组负责日常决策，重大分歧由 IPMT 拍板；</li><li><strong>核心强调</strong>：跨部门团队需实现”<strong>命（绩效）、钱（奖金）、权（决策）</strong>“统一。</li></ul><hr><h2 id="六、企业发展与-IPD-的关联"><a href="#六、企业发展与-IPD-的关联" class="headerlink" title="六、企业发展与 IPD 的关联"></a>六、企业发展与 IPD 的关联</h2><p><strong>企业成长三阶段：</strong></p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">① 兵来将挡（无章法，无需复杂管理）</span><br><span class="line">② 有管理但不完善（易遇&quot;玻璃天花板&quot;，需变革）</span><br><span class="line">③ 管理先进完善（成功可复制）</span><br></pre></td></tr></table></figure><p><strong>IPD 木桶模型</strong>：IPD 包含 9 个核心模块，如同木桶的 9 块板，需全部完善才能实现预期效果，单一模块无法达到 1/9 的收益。</p><hr><h2 id="七、落地实践：团队产品开发的改进方向"><a href="#七、落地实践：团队产品开发的改进方向" class="headerlink" title="七、落地实践：团队产品开发的改进方向"></a>七、落地实践：团队产品开发的改进方向</h2><p>结合 IPD 所学，团队产品开发常见问题及改进：</p><table><thead><tr><th>问题</th><th>现状</th><th>改进方向</th></tr></thead><tbody><tr><td>缺乏结构化流程</td><td>“救火式”开发频发，先开发后评审</td><td>参考 16446N 梳理结构化流程，明确阶段交付物与评审点</td></tr><tr><td>跨部门协同不足</td><td>存在”部门墙”，沟通脱节</td><td>组建轻量化 PDT，建立每周协同机制，绩效与团队目标挂钩</td></tr><tr><td>需求管理不规范</td><td>分类与优先级混乱，易体外流转</td><td>落地 A/B/C 分类，给每项需求编号，全生命周期跟踪</td></tr><tr><td>技术与产品未分离</td><td>临时攻关，复用率低</td><td>组建技术开发小组，搭建技术货架，明确衔接节点</td></tr></tbody></table><blockquote><p>💡 落地建议：先试点 1–2 个核心产品的流程优化，沉淀经验后逐步推广，避免碎片化改进，真正实现产品开发从”偶然成功”向”必然成功”转变。</p></blockquote><hr><h2 id="八、课程总结"><a href="#八、课程总结" class="headerlink" title="八、课程总结"></a>八、课程总结</h2><ul><li><strong>IPD 核心</strong>：以”市场驱动、投资思维”为核心，通过结构化流程、跨部门协同、技术与产品分离、重用策略，实现产品商业成功的可复制性；</li><li><strong>关键落地要点</strong>：先建立 IPD 整体认知（Overview），再逐步推进流程重整、产品重整、跨部门团队构建，避免碎片化学习；</li><li><strong>核心价值</strong>：打破部门墙，提升协同效率，提前规避技术风险，实现”让成功从偶然到必然”。</li></ul>]]>
    </content>
    <id>https://w-li-you.github.io/2026/04/28/ipd-integrated-product-development/</id>
    <link href="https://w-li-you.github.io/2026/04/28/ipd-integrated-product-development/"/>
    <published>2026-04-27T16:00:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>IPD（集成产品开发）是集成业界最佳实践的研发管理体系，强调”把强大研发能力建在超越研发部的组织上”，实现”让成功从偶然到必然”。本文梳理 IPD 的核心理念、流程与跨部门团队机制。</p>
</blockquote>]]>
    </summary>
    <title>IPD 集成产品开发学习笔记</title>
    <updated>2026-07-01T12:01:04.716Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="读书笔记" scheme="https://w-li-you.github.io/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/"/>
    <category term="读书笔记" scheme="https://w-li-you.github.io/tags/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/"/>
    <category term="管理" scheme="https://w-li-you.github.io/tags/%E7%AE%A1%E7%90%86/"/>
    <content>
      <![CDATA[<blockquote><p>本篇涵盖第九、十章：中层管理者的定位，以及如何在矩阵组织中生存。</p></blockquote><a id="more"></a><h2 id="九、中层管理者：最被低估的角色"><a href="#九、中层管理者：最被低估的角色" class="headerlink" title="九、中层管理者：最被低估的角色"></a>九、中层管理者：最被低估的角色</h2><p>格鲁夫明确为中层管理者正名。在很多人眼里，中层是”传话筒”——上传下达，没有实质价值；格鲁夫认为这是最大的误解。</p><h3 id="中层的核心价值"><a href="#中层的核心价值" class="headerlink" title="中层的核心价值"></a>中层的核心价值</h3><p>中层管理者是<strong>组织的神经系统</strong>：</p><ul><li>向上：把一线真实情况转化为高层可以决策的信息</li><li>向下：把公司战略转化为团队可以执行的具体任务</li><li>横向：在不同部门之间协调资源和信息</li></ul><p>这两个方向都要求极强的<strong>信息过滤和转译能力</strong>——直接往上推原始数据、往下传原始指令，都是失职。</p><h3 id="中层管理者的干预职责"><a href="#中层管理者的干预职责" class="headerlink" title="中层管理者的干预职责"></a>中层管理者的干预职责</h3><blockquote><p>“当你看到一个错误正在发生，而你有能力阻止它，不阻止就是失职。”</p></blockquote><p>格鲁夫批评了一种常见心态：看到问题但认为”不是我的职责”而袖手旁观。他认为，任何层级的管理者，在自己的<strong>影响力范围内</strong>，都有责任主动干预——哪怕越级。</p><p>这和”向上管理”的概念有些重叠，但格鲁夫说的更彻底：不是讨好上级，而是在组织需要时勇于发声。</p><hr><h2 id="十、矩阵组织与双重汇报"><a href="#十、矩阵组织与双重汇报" class="headerlink" title="十、矩阵组织与双重汇报"></a>十、矩阵组织与双重汇报</h2><p>英特尔是最早实践矩阵管理的公司之一。格鲁夫在书中详细分析了矩阵组织的利弊。</p><h3 id="矩阵的设计逻辑"><a href="#矩阵的设计逻辑" class="headerlink" title="矩阵的设计逻辑"></a>矩阵的设计逻辑</h3><p>纯粹的职能型组织（按功能划分：研发/市场/销售各自独立）的问题：</p><ul><li>各部门各自优化，缺乏整体视角</li><li>跨部门协作需要层层升级，决策慢</li></ul><p>纯粹的事业部型组织（每个产品线独立）的问题：</p><ul><li>资源重复，每个部门都有自己的 HR、财务、工程</li><li>共性能力无法复用</li></ul><p>矩阵组织兼顾两者：员工同时向<strong>职能线</strong>（专业能力的归属）和<strong>业务线</strong>（具体产品/项目的归属）汇报。</p><h3 id="矩阵的核心矛盾"><a href="#矩阵的核心矛盾" class="headerlink" title="矩阵的核心矛盾"></a>矩阵的核心矛盾</h3><p>双头汇报在执行层面容易产生冲突：</p><ul><li>职能线说”先做架构优化”，业务线说”先交付需求”</li><li>员工夹在中间，不知道听谁的</li></ul><p>格鲁夫的解法：<strong>预先约定优先级</strong>。在组织设计时就明确，当职能目标和业务目标冲突时，谁有最终决策权。这个约定越清晰，矩阵运转越顺畅。</p><h3 id="负面案例的警示"><a href="#负面案例的警示" class="headerlink" title="负面案例的警示"></a>负面案例的警示</h3><p>他特别提到：很多矩阵失败，不是因为结构设计有问题，而是因为<strong>关键的多余汇报关系没有被清晰说明</strong>，导致员工在模糊地带无法决策。</p><p>在技术团队里，这对应的是：一个工程师同时属于”基础架构组”和”某业务 Pod”，当两边都催 deadline 时，他的困境本质上是组织设计的失败，不是个人能力问题。</p><hr><h2 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h2><p>中层不是传话筒，是<strong>信息转译者和组织协调者</strong>。矩阵管理是强大但容易出错的组织形态，成功的关键不是结构本身，而是对冲突场景的<strong>提前约定</strong>。</p>]]>
    </content>
    <id>https://w-li-you.github.io/2026/04/15/grove-high-output-management-5/</id>
    <link href="https://w-li-you.github.io/2026/04/15/grove-high-output-management-5/"/>
    <published>2026-04-14T16:00:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>本篇涵盖第九、十章：中层管理者的定位，以及如何在矩阵组织中生存。</p>
</blockquote>]]>
    </summary>
    <title>《格鲁夫给经理人的第一课》读书笔记（五）：中层管理者的双重角色</title>
    <updated>2026-07-01T11:45:45.498Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="AI编程" scheme="https://w-li-you.github.io/categories/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="AI编程" scheme="https://w-li-you.github.io/tags/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="Agent" scheme="https://w-li-you.github.io/tags/Agent/"/>
    <category term="Claude Code" scheme="https://w-li-you.github.io/tags/Claude-Code/"/>
    <content>
      <![CDATA[<h1 id="Claude-Code-配置体系-—-学习笔记"><a href="#Claude-Code-配置体系-—-学习笔记" class="headerlink" title="Claude Code 配置体系 — 学习笔记"></a>Claude Code 配置体系 — 学习笔记</h1><blockquote><p>学习日期：2026-07-03<br>主题：AI 编程助手的「调教」架构 — 从 Anthropic 官方设计到可迁移的工程思维</p></blockquote><hr><a id="more"></a><h2 id="一、为什么这件事值得学"><a href="#一、为什么这件事值得学" class="headerlink" title="一、为什么这件事值得学"></a>一、为什么这件事值得学</h2><p>Claude Code 的配置体系，表面上是「怎么让 AI 更听话」，底层其实是在回答一个更通用的问题：</p><p><strong>如何把「概率性的 LLM」包装成「可预期的工程工具」？</strong></p><p>大多数人对 AI 编程助手的用法还停留在：写一段 prompt，希望它每次都照做。但长对话、上下文压缩、任务切换、安全边界——这些真实场景会迅速击穿这种 naive 方案。</p><p>Anthropic 官方把 7 种配置方式拆开讲，本质上是在做<strong>关注点分离</strong>：什么必须常驻、什么按需加载、什么必须确定性执行、什么可以隔离出去。这套思路不只适用于 Claude Code，任何要落地生产的 Agent 系统都值得借鉴。</p><hr><h2 id="二、核心认知：上下文是稀缺资源"><a href="#二、核心认知：上下文是稀缺资源" class="headerlink" title="二、核心认知：上下文是稀缺资源"></a>二、核心认知：上下文是稀缺资源</h2><p>在深入每种配置之前，先建立一个底层模型：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">上下文窗口 = 有限的工作台面积</span><br></pre></td></tr></table></figure><p>所有配置方式的差异，都可以归结为三个问题：</p><ol><li><strong>什么时候占用了工作台？</strong>（加载时机）</li><li><strong>对话变长、要「收拾桌子」时，它还在不在？</strong>（压缩行为）</li><li><strong>它占多大面积？</strong>（token 成本）</li></ol><p>很多人配置 AI 助手时的典型错误：<strong>把所有想让它知道的东西都塞进 CLAUDE.md</strong>。结果不是 AI 变聪明了，而是：</p><ul><li>简单任务也背着几百行无关规范</li><li>真正重要的指令被稀释，遵循度下降</li><li>token 账单无声上涨</li></ul><p><strong>我的判断</strong>：配置 AI 助手和写软件架构一样 — 不是「能塞多少塞多少」，而是「什么信息在什么生命周期里可见」。</p><hr><h2 id="三、七种方式，一张心智地图"><a href="#三、七种方式，一张心智地图" class="headerlink" title="三、七种方式，一张心智地图"></a>三、七种方式，一张心智地图</h2><p>我不按官方文档顺序记，而是按<strong>信息的生命周期</strong>来理解：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">会话启动</span><br><span class="line">  │</span><br><span class="line">  ├─ 始终在场 ────────── CLAUDE.md（根目录）</span><br><span class="line">  │                      Output Styles（替换系统提示）</span><br><span class="line">  │</span><br><span class="line">  ├─ 条件加载 ────────── Rules（读特定路径时）</span><br><span class="line">  │                      子目录 CLAUDE.md（读该目录时）</span><br><span class="line">  │</span><br><span class="line">  ├─ 按需触发 ────────── Skills（用户 / AI 主动调用）</span><br><span class="line">  │                      Append System Prompt（单次 CLI）</span><br><span class="line">  │</span><br><span class="line">  ├─ 隔离执行 ────────── Subagents（独立窗口，只回结论）</span><br><span class="line">  │</span><br><span class="line">  └─ 确定性执行 ──────── Hooks（不经过 AI 决策）</span><br></pre></td></tr></table></figure><p>这张地图比记住 7 个名词更重要。遇到新需求时，先问「这条信息属于哪个生命周期」，再选配置方式，而不是反过来。</p><hr><h2 id="四、逐层理解-个人思考"><a href="#四、逐层理解-个人思考" class="headerlink" title="四、逐层理解 + 个人思考"></a>四、逐层理解 + 个人思考</h2><h3 id="4-1-CLAUDE-md-—-不是百科全书，是索引卡"><a href="#4-1-CLAUDE-md-—-不是百科全书，是索引卡" class="headerlink" title="4.1 CLAUDE.md — 不是百科全书，是索引卡"></a>4.1 CLAUDE.md — 不是百科全书，是索引卡</h3><p><strong>官方定位</strong>：项目手册，放「事实」不放「流程」。</p><p><strong>我的理解</strong>：</p><p>CLAUDE.md 最接近真实团队里的 onboarding 文档 — 新同事第一天需要知道的：用什么技术栈、怎么构建、目录怎么组织、命名有什么规矩。你不会在 onboarding 里塞一份 50 页的部署 runbook，那是运维手册，需要时再去翻。</p><p>几个我自己会遵守的原则：</p><table><thead><tr><th>原则</th><th>理由</th></tr></thead><tbody><tr><td>200 行以内</td><td>超出后边际收益为负，指令遵循度反而下降</td></tr><tr><td>只写「不变的事实」</td><td>技术栈、构建命令、目录约定 — 这些不会随任务变</td></tr><tr><td>用指针代替全文</td><td>「部署流程见 <code>/deploy</code> skill」比复制粘贴 30 步强</td></tr><tr><td>定期审计</td><td>项目演进后 CLAUDE.md 容易过时，比没有更糟的是有但错的</td></tr></tbody></table><p><strong>一个反直觉的点</strong>：CLAUDE.md 越精简，AI 表现往往越好。不是因为 AI 变聪明了，而是因为信号噪声比提高了 — 每条指令的「权重」更大。</p><hr><h3 id="4-2-Rules-—-精准的「地方法规」"><a href="#4-2-Rules-—-精准的「地方法规」" class="headerlink" title="4.2 Rules — 精准的「地方法规」"></a>4.2 Rules — 精准的「地方法规」</h3><p>Rules 解决的是 CLAUDE.md 覆盖不了的问题：<strong>同一条规范，只在特定文件类型 / 路径下生效</strong>。</p><p>比如「所有 API handler 必须用 Zod 验证」 — 这条规则对前端改 CSS 毫无意义，加载它纯属浪费。Rules 的 <code>paths</code> 作用域就是为此设计的。</p><p><strong>和子目录 CLAUDE.md 怎么选？</strong></p><ul><li>规范绑定一个模块目录 → 子目录 CLAUDE.md 足够</li><li>规范跨目录生效（如所有 <code>*.test.ts</code>） → 必须用 Rules</li></ul><p><strong>我的思考</strong>：Rules 本质上是 AI 时代的 <code>.editorconfig</code> / <code>eslint overrides</code> — 按路径施加不同约束。如果你已经在项目里用 lint 规则做分层约束，Rules 的配置思路应该很直觉。</p><hr><h3 id="4-3-Skills-—-目前最被低估的能力"><a href="#4-3-Skills-—-目前最被低估的能力" class="headerlink" title="4.3 Skills — 目前最被低估的能力"></a>4.3 Skills — 目前最被低估的能力</h3><p>Skills 的渐进式加载设计，我认为是整个配置体系里最优雅的部分：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">会话开始 → 只加载 Skill 名称 + 一行描述（几乎零成本）</span><br><span class="line">触发时   → 加载完整 SKILL.md（按需付费）</span><br></pre></td></tr></table></figure><p>这意味着你可以定义几十个 Skill — 部署、审查、创建组件、写测试、发版 checklist — 而平时它们不占上下文。</p><p><strong>为什么我说它被低估？</strong></p><p>大多数人把 Skills 当成「高级 prompt 模板」，但它真正的价值是<strong>工作流封装</strong>：</p><ul><li>把重复性、多步骤、需要判断分支的流程固化下来</li><li>新人（或未来的自己）不需要重新摸索「审查代码要检查哪些点」</li><li>团队可以共享同一套 Skill，减少「每个人 prompt 写法不同导致结果不一致」</li></ul><p><strong>一个需要注意的坑</strong>：压缩对话时，已触发的 Skills 会按预算重新注入，最早触发的可能被丢弃。所以一次会话里不要贪多 — 聚焦当前任务，完成后再开新会话触发下一个 Skill。</p><p><strong>我的实践方向</strong>：任何我做过两次以上的多步骤流程，都值得封装成 Skill。判断标准不是「流程复不复杂」，而是「下次还需不需要重新解释一遍」。</p><hr><h3 id="4-4-Subagents-—-上下文隔离的利器"><a href="#4-4-Subagents-—-上下文隔离的利器" class="headerlink" title="4.4 Subagents — 上下文隔离的利器"></a>4.4 Subagents — 上下文隔离的利器</h3><p>Subagent 和 Skill 最容易混淆，我的区分标准很简单：</p><table><thead><tr><th></th><th>Skill</th><th>Subagent</th></tr></thead><tbody><tr><td>执行位置</td><td>主对话上下文</td><td>独立上下文窗口</td></tr><tr><td>中间过程</td><td>可见，可干预</td><td>不可见，只回结论</td></tr><tr><td>适合场景</td><td>需要协作、逐步确认</td><td>调研、搜索、分析类「只要结果」</td></tr></tbody></table><p><strong>典型 Subagent 场景</strong>：</p><ul><li>在代码库里深度搜索 Bug 根因（中间可能翻几十个文件）</li><li>分析日志定位性能瓶颈</li><li>调研某个库有没有替代方案</li><li>批量迁移（Claude Code 的 <code>/batch</code> 本质就是 Subagent 编排）</li></ul><p><strong>我的思考</strong>：Subagent 解决的是 LLM 上下文窗口的「污染问题」。调研类任务的中间过程可能产生几万 token 的噪音，如果全堆在主对话里，很快就会把真正重要的上下文挤出去。Subagent 相当于把「脏活」外包出去，主对话保持干净。</p><p>这跟微服务里的「异步任务队列」思维类似 — 长耗时、高噪音的任务不应该阻塞主流程。</p><hr><h3 id="4-5-Hooks-—-唯一确定性的一环"><a href="#4-5-Hooks-—-唯一确定性的一环" class="headerlink" title="4.5 Hooks — 唯一确定性的一环"></a>4.5 Hooks — 唯一确定性的一环</h3><p>前面所有配置方式 — CLAUDE.md、Rules、Skills — 本质上都是<strong>给 AI 的建议</strong>。AI 大概率会遵循，但在以下情况下可能失效：</p><ul><li>长对话后上下文被压缩</li><li>任务复杂，AI 注意力被分散</li><li>遇到 prompt 注入（文件里藏了恶意指令）</li></ul><p><strong>Hooks 不同</strong>：它是自动化代码，绑定到 Claude Code 的生命周期事件，触发即执行，不经过 AI 决策。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">PreToolUse   → 工具调用前（拦截危险操作）</span><br><span class="line">PostToolUse  → 工具调用后（自动格式化、跑 lint）</span><br><span class="line">PreCompact   → 压缩对话前（保存关键状态）</span><br></pre></td></tr></table></figure><p><strong>我认为最值得记住的观点</strong>：</p><blockquote><p>「永远不要做 X」不能靠指令保证，必须靠 Hook + 权限双保险。</p></blockquote><p>这跟软件安全里的 fail-closed 设计一脉相承 — 默认拒绝，显式允许。你不会靠注释防止函数被误调用，你会用类型系统和权限检查兜底。AI 助手的安全边界也应该一样。</p><p><strong>典型 Hook 用法</strong>：</p><ul><li>编辑文件后自动 Prettier（不依赖 AI 记得格式化）</li><li>提交前自动 lint</li><li>拦截删除数据库迁移文件的操作</li><li>完成任务后发通知</li></ul><p><strong>判断标准</strong>：「每次 X 后必须做 Y」→ 用 Hook，不要写进 CLAUDE.md。</p><hr><h3 id="4-6-Output-Styles-amp-Append-System-Prompt-—-轻量调参"><a href="#4-6-Output-Styles-amp-Append-System-Prompt-—-轻量调参" class="headerlink" title="4.6 Output Styles &amp; Append System Prompt — 轻量调参"></a>4.6 Output Styles &amp; Append System Prompt — 轻量调参</h3><p>这两个我用得少，但理解它们的边界很重要：</p><p><strong>Output Styles</strong>：</p><ul><li>注入系统提示词，永不被压缩</li><li>⚠️ 会<strong>替换</strong>默认系统提示词 — 内置的安全行为、修改范围判断等会丢失</li><li>内置 Proactive / Explanatory / Learning 三种，够用就别自定义</li></ul><p><strong>Append System Prompt</strong>：</p><ul><li>CLI 参数，单次生效，追加而非替换</li><li>适合临时调整语气或输出格式</li><li>指令越多遵循度越低，别滥用</li></ul><p><strong>我的建议</strong>：90% 的场景不需要碰这两个。需要改 AI 行为时，优先想能不能用 Skill 或 Rule 解决。</p><hr><h2 id="五、决策框架（我自己的版本）"><a href="#五、决策框架（我自己的版本）" class="headerlink" title="五、决策框架（我自己的版本）"></a>五、决策框架（我自己的版本）</h2><p>遇到新需求，我按这个顺序想：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">1. 这是「项目事实」还是「操作流程」？</span><br><span class="line">   ├─ 事实 → CLAUDE.md</span><br><span class="line">   └─ 流程 → Skill</span><br><span class="line"></span><br><span class="line">2. 这条规范是否只在特定路径下有意义？</span><br><span class="line">   └─ 是 → Rule（带 paths）</span><br><span class="line"></span><br><span class="line">3. 中间过程是否很长、且我不需要看到？</span><br><span class="line">   └─ 是 → Subagent</span><br><span class="line"></span><br><span class="line">4. 这件事是否「必须发生」，不能依赖 AI 自觉？</span><br><span class="line">   └─ 是 → Hook</span><br><span class="line"></span><br><span class="line">5. 这是「绝对不能做」的安全红线？</span><br><span class="line">   └─ 是 → Hook + 权限，不要只写指令</span><br><span class="line"></span><br><span class="line">6. 只是临时调整一次会话的行为？</span><br><span class="line">   └─ 是 → Append System Prompt</span><br></pre></td></tr></table></figure><hr><h2 id="六、可迁移到-Agent-系统的设计原则"><a href="#六、可迁移到-Agent-系统的设计原则" class="headerlink" title="六、可迁移到 Agent 系统的设计原则"></a>六、可迁移到 Agent 系统的设计原则</h2><p>Claude Code 的配置体系，提炼成 4 条可以迁移到其他 Agent 项目的设计原则：</p><h3 id="6-1-事实与流程分离"><a href="#6-1-事实与流程分离" class="headerlink" title="6.1 事实与流程分离"></a>6.1 事实与流程分离</h3><p>常驻上下文只放「不变的事实」，可变的多步骤流程按需加载。这直接对应软件工程里的「数据与逻辑分离」。</p><h3 id="6-2-渐进式披露（Progressive-Disclosure）"><a href="#6-2-渐进式披露（Progressive-Disclosure）" class="headerlink" title="6.2 渐进式披露（Progressive Disclosure）"></a>6.2 渐进式披露（Progressive Disclosure）</h3><p>不要一次性把所有信息塞给 AI。先给索引，需要时再展开。这和 UI 设计里的 progressive disclosure 是同一个思想 — 减少认知负荷，提高信号质量。</p><h3 id="6-3-确定性优于概率性"><a href="#6-3-确定性优于概率性" class="headerlink" title="6.3 确定性优于概率性"></a>6.3 确定性优于概率性</h3><p>凡是「必须发生」或「绝对不能发生」的事，不要指望 LLM 的概率性遵循。用 Hook、权限、类型系统、中间件等确定性机制兜底。</p><h3 id="6-4-隔离执行，避免污染"><a href="#6-4-隔离执行，避免污染" class="headerlink" title="6.4 隔离执行，避免污染"></a>6.4 隔离执行，避免污染</h3><p>长耗时、高噪音的任务（搜索、分析、调研）应该在隔离环境中执行，只把结论带回主流程。这跟分布式系统里的 bulkhead pattern（舱壁模式）同构。</p><hr><h2 id="七、对我当前工作的启发"><a href="#七、对我当前工作的启发" class="headerlink" title="七、对我当前工作的启发"></a>七、对我当前工作的启发</h2><p>结合 Cursor / Claude Code 的日常使用，我打算做的几件事：</p><ol><li><strong>审计 CLAUDE.md</strong>：把超过 5 行的流程性内容移到 Skills</li><li><strong>封装重复流程</strong>：代码审查、部署检查、新模块脚手架 — 每个做成 Skill</li><li><strong>Rules 按路径分层</strong>：API 层、DB 层、前端组件层各一套，避免全局加载</li><li><strong>关键安全操作用 Hook</strong>：不依赖 AI「记得不要删 migration」</li><li><strong>调研类任务主动用 Subagent</strong>：保持主对话上下文干净</li></ol><hr><h2 id="八、遗留问题-amp-待验证"><a href="#八、遗留问题-amp-待验证" class="headerlink" title="八、遗留问题 &amp; 待验证"></a>八、遗留问题 &amp; 待验证</h2><ul><li><input disabled="" type="checkbox"> Skills 在团队间共享的最佳实践是什么？Git 管理 vs 个人本地？</li><li><input disabled="" type="checkbox"> Subagent 嵌套 5 层的实际使用场景有哪些？是否过度设计？</li><li><input disabled="" type="checkbox"> Hook 的性能开销在长会话中是否可感知？</li><li><input disabled="" type="checkbox"> Output Style 替换默认提示词后，哪些内置行为会丢失？需要实测清单</li><li><input disabled="" type="checkbox"> 这套配置体系迁移到 Cursor Rules / Skills 时的对应关系</li></ul><hr><h2 id="九、一句话总结"><a href="#九、一句话总结" class="headerlink" title="九、一句话总结"></a>九、一句话总结</h2><blockquote><p>配置 AI 编程助手，不是在写更好的 prompt，而是在设计一套<strong>信息生命周期管理系统</strong> — 什么常驻、什么按需、什么隔离、什么确定性执行。CLAUDE.md 是索引卡，Skills 是工作流，Subagents 是外包，Hooks 是安全网。搞清楚了这四层，7 种配置方式自然各归其位。</p></blockquote><hr><p><em>本笔记为个人学习总结，参考了 Anthropic 官方博文《Steering Claude Code》及社区解读，加入了个人理解和工程化思考。</em></p>]]>
    </content>
    <id>https://w-li-you.github.io/2026/04/12/claude-code-config-system-notes/</id>
    <link href="https://w-li-you.github.io/2026/04/12/claude-code-config-system-notes/"/>
    <published>2026-04-11T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h1 id="Claude-Code-配置体系-—-学习笔记"><a href="#Claude-Code-配置体系-—-学习笔记" class="headerlink" title="Claude Code 配置体系 — 学习笔记"></a>Claude Code 配置体系 — 学习笔记</h1><blockquote>
<p>学习日期：2026-07-03<br>主题：AI 编程助手的「调教」架构 — 从 Anthropic 官方设计到可迁移的工程思维</p>
</blockquote>
<hr>]]>
    </summary>
    <title>Claude Code 配置体系 · 学习笔记</title>
    <updated>2026-07-05T15:33:40.251Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="AI编程" scheme="https://w-li-you.github.io/categories/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="AI编程" scheme="https://w-li-you.github.io/tags/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="Claude Code" scheme="https://w-li-you.github.io/tags/Claude-Code/"/>
    <category term="Cursor" scheme="https://w-li-you.github.io/tags/Cursor/"/>
    <content>
      <![CDATA[<h1 id="Claude-Code-七种配置方式-·-个人总结"><a href="#Claude-Code-七种配置方式-·-个人总结" class="headerlink" title="Claude Code 七种配置方式 · 个人总结"></a>Claude Code 七种配置方式 · 个人总结</h1><blockquote><p>看了几篇解读 + 对照官方文档后的自己的理解 · 2026-07-03</p></blockquote><hr><a id="more"></a><h2 id="先讲清楚：为什么分七种"><a href="#先讲清楚：为什么分七种" class="headerlink" title="先讲清楚：为什么分七种"></a>先讲清楚：为什么分七种</h2><p>以前我配置 Claude Code，基本就是往 CLAUDE.md 里堆东西。后来发现两件事：</p><ol><li><strong>上下文窗口是硬资源</strong>——塞越多，遵循度越差，长对话里尤其明显</li><li><strong>「建议」和「必做」是两回事</strong>——写在 md 里的是概率性遵守，Hook 才是确定性执行</li></ol><p>官方把配置拆成七种，本质上是在回答三个问题：<strong>什么时候进上下文、压缩后还在不在、占多少 token</strong>。选错位置，等于白写。</p><p>我自己的三条判断：</p><table><thead><tr><th>内容类型</th><th>放哪</th></tr></thead><tbody><tr><td>事实（技术栈、命令、目录）</td><td>CLAUDE.md</td></tr><tr><td>流程（部署、审查、多步 SOP）</td><td>Skills</td></tr><tr><td>必须发生 / 绝对不能发生</td><td>Hooks + 权限</td></tr></tbody></table><hr><h2 id="一张表看清七种方式"><a href="#一张表看清七种方式" class="headerlink" title="一张表看清七种方式"></a>一张表看清七种方式</h2><table><thead><tr><th>方式</th><th>加载时机</th><th>压缩后</th><th>Token</th><th>性质</th></tr></thead><tbody><tr><td>根 CLAUDE.md</td><td>会话开始，全程在</td><td>缓存后重读，不丢</td><td>高，每行都占</td><td>建议</td></tr><tr><td>子目录 CLAUDE.md</td><td>读到该目录文件时</td><td><strong>丢了，直到再碰该目录</strong></td><td>低</td><td>建议</td></tr><tr><td>Rules（无 paths）</td><td>会话开始</td><td>重新注入</td><td>中</td><td>建议</td></tr><tr><td>Rules（有 paths）</td><td>匹配路径被读时</td><td>重新注入</td><td>低</td><td>建议</td></tr><tr><td>Skills</td><td>开始只加载名+描述；触发才加载全文</td><td>已触发的按预算重注入，<strong>最早的先丢</strong></td><td>低→中</td><td>建议</td></tr><tr><td>Subagents</td><td>开始只加载名+描述+工具；Agent 工具调用时才跑</td><td>主会话只收<strong>最终摘要</strong></td><td>主会话几乎零</td><td>隔离执行</td></tr><tr><td>Hooks</td><td>生命周期事件</td><td><strong>完全绕过压缩</strong></td><td>配置不进上下文</td><td><strong>确定性</strong></td></tr><tr><td>Output Styles</td><td>会话开始，进系统提示</td><td>不压缩</td><td>高，且<strong>权重最高</strong></td><td>替换/追加系统提示</td></tr><tr><td>Append Prompt</td><td>CLI 单次传入</td><td>不压缩，仅当次</td><td>中，首请求后缓存</td><td>追加，单次</td></tr></tbody></table><blockquote><p>注：Output Styles 和 Append Prompt 算第七种里的两个变体，官方表格是分开列的。</p></blockquote><hr><h2 id="1-CLAUDE-md-—-项目常驻记忆"><a href="#1-CLAUDE-md-—-项目常驻记忆" class="headerlink" title="1. CLAUDE.md — 项目常驻记忆"></a>1. CLAUDE.md — 项目常驻记忆</h2><p><strong>放什么</strong>：构建命令、目录结构、monorepo 布局、命名规范、团队约定——AI 需要<strong>始终知道</strong>的事实。</p><p><strong>不放什么</strong>：部署 runbook、审查清单、30 行以上的步骤——这些该进 Skills。</p><p><strong>两种加载行为（之前我搞混了）</strong>：</p><table><thead><tr><th>类型</th><th>行为</th></tr></thead><tbody><tr><td><strong>根目录</strong></td><td>会话开始就加载；会话内 memoized；<strong>压缩后会重新读取</strong></td></tr><tr><td><strong>子目录</strong>（如 <code>app/api/CLAUDE.md</code>）</td><td>只有 Claude 读到该目录下文件才加载；压缩后<strong>会丢</strong>，直到再次碰那个目录</td></tr></tbody></table><p>子目录 CLAUDE.md 和 path-scoped Rules 的压缩行为一样——这点容易记错。</p><p><strong>200 行</strong>：官方明确建议上限。不是玄学，是实测：行数多了，无关任务也带着跑，遵循度反而下降。我有过类似体验，把流程全塞 CLAUDE.md 后，长对话里 AI 开始「选择性失忆」。</p><p><strong>索引思维</strong>：CLAUDE.md 当目录，不当百科全书。</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">前端规范 → docs/FRONTEND.md</span><br><span class="line">部署 → /deploy 技能</span><br><span class="line">安全策略 → .claude/rules/security.md（path-scoped）</span><br></pre></td></tr></table></figure><p><strong>Monorepo</strong>：各团队子目录放自己的 CLAUDE.md；用 <code>claudeMdExcludes</code> 跳过不碰的团队目录。组织级安全策略可以 MDM 下发，个人 settings 无法 exclude。</p><p><strong>个人 vs 项目</strong>：个人偏好（semantic commit、语气）放 <code>~/.claude/</code> 用户级；团队约定放项目级。别把个人习惯写进团队 CLAUDE.md。</p><p><strong>维护方式</strong>：当代码对待——有 owner、PR review、出问题时回溯是不是某条规则太长或被淹没了。</p><hr><h2 id="2-Rules-—-路径级约束"><a href="#2-Rules-—-路径级约束" class="headerlink" title="2. Rules — 路径级约束"></a>2. Rules — 路径级约束</h2><p><code>.claude/rules/</code> 下的 Markdown，YAML frontmatter 里加 <code>paths</code> 做作用域：</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">---</span></span><br><span class="line"><span class="attr">paths:</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">&quot;src/api/**&quot;</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">&quot;**/*.handler.ts&quot;</span></span><br><span class="line"><span class="meta">---</span></span><br><span class="line"><span class="string">所有</span> <span class="string">API</span> <span class="string">handler</span> <span class="string">必须用</span> <span class="string">Zod</span> <span class="string">校验输入</span></span><br></pre></td></tr></table></figure><p><strong>无 paths 的 Rule = 另一个 CLAUDE.md</strong>：会话开始就加载，改文档也带着，浪费 token。写 Rule 如果不加 paths，和直接往 CLAUDE.md 堆没区别。</p><p>** vs 子目录 CLAUDE.md**：</p><ul><li>规范只跟某个模块目录走 → 子目录 CLAUDE.md</li><li>规范跨目录（所有 <code>*.test.ts</code>、所有 migration 文件）→ path-scoped Rule</li></ul><hr><h2 id="3-Skills-—-按需加载的流程"><a href="#3-Skills-—-按需加载的流程" class="headerlink" title="3. Skills — 按需加载的流程"></a>3. Skills — 按需加载的流程</h2><p><code>.claude/skills/&lt;name&gt;/SKILL.md</code>，渐进式加载：</p><ul><li>会话开始：只有 <strong>name + description</strong>（几乎不占 token）</li><li>触发时：加载完整 body（<code>/code-review</code> 手动调，或 AI 根据 description 自动匹配）</li></ul><p><strong>Commands 已合并进 Skills</strong>：<code>.claude/commands/</code> 还能用但是 legacy；新东西一律放 <code>.claude/skills/</code>。Skills 多了 <strong>auto-invocation</strong>——AI 看 description 自己决定要不要调，Commands 时代没有这能力。</p><p>两种触发模式：</p><table><thead><tr><th>模式</th><th>谁控制</th></tr></thead><tbody><tr><td>用户调用 <code>/skill-name</code></td><td>我</td></tr><tr><td>auto-invocation</td><td>AI 读 description 自行匹配</td></tr></tbody></table><p>auto-invocation 写 description 要精准——太宽会误触发，太窄永远调不到。</p><p><strong>压缩预算</strong>：一次会话触发太多 Skill，压缩后按总预算重注入，<strong>最早触发的先被踢</strong>。所以大需求别在一个会话里 <code>/grill</code> + <code>/deploy</code> + <code>/review</code> 全跑一遍，分会话更稳。</p><p><strong>我的用法</strong>：工作流里的 <code>/grill-with-docs</code>、<code>/to-prd</code>、<code>/implement</code>、<code>/review</code> 本质上都是 Skills。Phase 0 规划、Phase 1 实现、Phase 2 审查各开新会话，也是为了避免 Skill 预算和上下文互相污染。</p><hr><h2 id="4-Subagents-—-隔离干活的"><a href="#4-Subagents-—-隔离干活的" class="headerlink" title="4. Subagents — 隔离干活的"></a>4. Subagents — 隔离干活的</h2><p><code>.claude/agents/</code> 下每个文件一个独立助手，YAML frontmatter 配 name、description、model、tools 等。</p><p><strong>和 Skills 的核心区别</strong>：</p><table><thead><tr><th></th><th>Skill</th><th>Subagent</th></tr></thead><tbody><tr><td>执行位置</td><td>主对话线程</td><td>独立上下文窗口</td></tr><tr><td>中间过程</td><td>全在主对话里</td><td><strong>不回主对话</strong></td></tr><tr><td>自动触发</td><td>可以</td><td><strong>不行</strong>，必须 Agent 工具显式调用</td></tr><tr><td>适合</td><td>要看过程、随时干预</td><td>只要结论、过程很长</td></tr></tbody></table><p>调研 50 个文件找 Bug 根因、扫日志、依赖审计——中间几万 token 的中间结果，主对话不需要看，Subagent 合适。</p><p>支持嵌套最多 5 层；<code>/batch</code> 批量迁移本质就是 Subagent 编排。很多工具现在能自动创建 Subagent，但理解「隔离上下文」这个设计点，才知道什么时候该手动 spawn。</p><p><strong>我的倾向</strong>：implement 阶段仍是一 Issue 一会话 + Skill，不用 Subagent——我要看 diff 过程。调研型、只关心结论的任务才考虑 Subagent。</p><hr><h2 id="5-Hooks-—-唯一靠谱的「必做」"><a href="#5-Hooks-—-唯一靠谱的「必做」" class="headerlink" title="5. Hooks — 唯一靠谱的「必做」"></a>5. Hooks — 唯一靠谱的「必做」</h2><p>前面六种本质上都是<strong>给 AI 的建议</strong>。Hooks 是 harness 在生命周期事件上跑的<strong>确定性逻辑</strong>，跟模型想不想无关。</p><p>注册位置：<code>.claude/settings.json</code>（项目级）或 <code>~/.claude/settings.json</code>（用户级），也可 managed policy（组织级，用户改不了）。</p><p>常见事件：<code>PreToolUse</code>、<code>PostToolUse</code>、<code>PreCompact</code>、<code>SessionStart</code>、<code>Stop</code> 等。</p><p><strong>Hook 类型要分清</strong>（之前容易误以为全是 shell 脚本）：</p><table><thead><tr><th>类型</th><th>是否确定性</th></tr></thead><tbody><tr><td>command / HTTP / mcp_tool</td><td>✅ 确定性</td></tr><tr><td>prompt / agent</td><td>❌ 仍靠模型判断</td></tr></tbody></table><p>经典用法：</p><ul><li>PostToolUse：编辑后自动 Prettier / lint</li><li>PreToolUse：检测危险操作，<code>exit code 2</code> <strong>拦截</strong>工具调用（拦截原因会进上下文让 AI 知道为啥被拒）</li><li>PreCompact：压缩前备份对话</li><li>Stop：跑测试脚本，<strong>不通过不让结束本轮</strong>（best practices 里提到的 unattended 验证闭环）</li></ul><p><strong>「永远不要做 X」</strong>：CLAUDE.md 写「别删 migration 文件」——长会话、压缩、文件里的 prompt injection 都可能破功。真防线是 PreToolUse Hook + Managed Settings 权限，组织级强制的 managed settings 用户本地改不掉。</p><p>这跟 fail-closed 设计一脉相承：别指望 AI 自觉，靠类型系统和权限兜底。</p><hr><h2 id="6-Output-Styles-—-慎用的高权重开关"><a href="#6-Output-Styles-—-慎用的高权重开关" class="headerlink" title="6. Output Styles — 慎用的高权重开关"></a>6. Output Styles — 慎用的高权重开关</h2><p><code>.claude/output-styles/</code> 注入系统提示，<strong>不压缩</strong>，且官方说它是七种里<strong>指令遵循权重最高</strong>的。</p><p>自定义 Output Style 默认会<strong>替换</strong> Claude Code 内置系统提示——改范围、注释习惯、安全处理、跑测试再收工这些默认行为会全没，变成「通用助手」而非「编程助手」。</p><p>frontmatter 里设 <code>keep-coding-instructions: true</code> 可以保留默认编程指令，自定义前先查内置三种：</p><ul><li><strong>Proactive</strong> — 更主动执行</li><li><strong>Explanatory</strong> — 详细解释</li><li><strong>Learning</strong> — 协作学习模式</li></ul><p>我基本不用自定义 Output Style——改系统提示的副作用太大，不如 Skills 精准。</p><hr><h2 id="7-Append-System-Prompt-—-临时微调"><a href="#7-Append-System-Prompt-—-临时微调" class="headerlink" title="7. Append System Prompt — 临时微调"></a>7. Append System Prompt — 临时微调</h2><p>CLI <code>--append-system-prompt</code>，<strong>追加</strong>不替换，<strong>仅当次 invocation</strong> 生效，不持久化到文件。</p><p>适合：临时调语气、输出格式、加一段领域知识。</p><p>限制：追加越多，每条遵循度越低，冲突时更明显。首请求后 prompt caching 会降 input cost，但 verbose 风格会增加 output token。</p><p>和 Output Style 对比：Append 是加法、单次；Output Style 是文件级、可能替换默认行为、权重更高。</p><hr><h2 id="决策树（我自己用的）"><a href="#决策树（我自己用的）" class="headerlink" title="决策树（我自己用的）"></a>决策树（我自己用的）</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">要写一条配置</span><br><span class="line">    │</span><br><span class="line">    ├─ 全局事实，≤200 行          → 根 CLAUDE.md</span><br><span class="line">    ├─ 某模块事实                 → 子目录 CLAUDE.md</span><br><span class="line">    ├─ 跨目录规范                 → Rules + paths</span><br><span class="line">    ├─ 无 paths 的 Rule           → 别写，等于第二个 CLAUDE.md</span><br><span class="line">    ├─ 多步流程 / SOP             → Skills</span><br><span class="line">    ├─ 调研只要结论               → Subagent</span><br><span class="line">    ├─ 每次 X 后必做 Y            → Hook（command 型）</span><br><span class="line">    ├─ 绝对不能 X                 → PreToolUse Hook + 权限</span><br><span class="line">    ├─ 改整体行为模式             → Output Style（先看内置）</span><br><span class="line">    └─ 临时调一次                 → --append-system-prompt</span><br></pre></td></tr></table></figure><hr><h2 id="不在「七法」里但经常一起出现的"><a href="#不在「七法」里但经常一起出现的" class="headerlink" title="不在「七法」里但经常一起出现的"></a>不在「七法」里但经常一起出现的</h2><table><thead><tr><th>能力</th><th>和七法的关系</th></tr></thead><tbody><tr><td><strong>Plugins</strong></td><td>把 Skills + Subagents + Hooks + Output Styles 打包分享，不是第八种配置方式</td></tr><tr><td><strong>MCP Servers</strong></td><td>扩展工具面（读 DB、调 API），和「怎么调教行为」是另一条线</td></tr><tr><td><strong>Agent Teams</strong></td><td>Subagent 的规模化编排，日常多数场景用不到</td></tr><tr><td><strong>Permissions / Managed Settings</strong></td><td>和 Hook 配合做组织级硬边界</td></tr></tbody></table><p>Cursor 侧有 <code>.cursor/rules</code>、<code>.cursor/skills</code> 等平行概念，思路类似：常驻规则 vs 按需技能 vs 确定性 hook。跨工具迁移配置时，先对齐「加载时机」而不是文件名。</p><hr><h2 id="设计思想（对我自己的启发）"><a href="#设计思想（对我自己的启发）" class="headerlink" title="设计思想（对我自己的启发）"></a>设计思想（对我自己的启发）</h2><ol><li><strong>事实 / 流程分离</strong> — CLAUDE.md 是内存常驻变量，Skills 是按需 import 的函数</li><li><strong>作用域收窄</strong> — path-scoped Rules、子目录 CLAUDE.md、Skill 渐进加载，都是在对抗 context bloat</li><li><strong>概率 vs 确定</strong> — 「建议 AI 跑 lint」和「编辑完必跑 lint」不是一回事；安全边界必须确定性</li><li><strong>隔离 vs 透明</strong> — Skill 透明可干预，Subagent 隔离保主对话干净；选型看你要控过程还是只要结果</li><li><strong>配置也是代码</strong> — CLAUDE.md 会膨胀、会过时、会互相打架；需要 owner 和定期 prune</li></ol><p>搭自己的 Agent 系统（不限 Claude Code）也适用：把「常驻记忆」「按需 SOP」「硬 guardrail」「后台 worker」分开设计，比一个大 system prompt 靠谱得多。</p><hr><h2 id="和我现有工作流的对照"><a href="#和我现有工作流的对照" class="headerlink" title="和我现有工作流的对照"></a>和我现有工作流的对照</h2><table><thead><tr><th>配置原则</th><th>我现在的做法</th><th>待改进</th></tr></thead><tbody><tr><td>CLAUDE.md 只放事实</td><td>Phase 0 用 <code>/grill-with-docs</code> 沉淀到 docs/</td><td>检查各项目 CLAUDE.md 是否超标、有无流程混入</td></tr><tr><td>Skills 放流程</td><td><code>/grill-with-docs</code> → <code>/to-prd</code> → <code>/to-issues</code> → <code>/implement</code> → <code>/review</code></td><td>description 写好 auto-invocation 边界</td></tr><tr><td>一 Issue 一会话</td><td>Phase 1 实现阶段</td><td>避免 Skill 预算和上下文交叉污染</td></tr><tr><td>审查换 AI</td><td>Phase 2 换厂商/换模型</td><td>本质是 Subagent/新会话隔离，不是同会话里叠 Skill</td></tr><tr><td>Hooks 做确定性</td><td>还没系统配</td><td>format/lint、危险命令拦截、Stop 前跑测试</td></tr><tr><td>索引而非百科全书</td><td>docs/ + CONTEXT.md 指针</td><td>monorepo 可考虑 path-scoped Rules</td></tr></tbody></table><p><strong>一个具体计划</strong>：</p><ul><li><input disabled="" type="checkbox"> 各 repo CLAUDE.md 审计：流程性内容迁 Skills，超 200 行拆索引</li><li><input disabled="" type="checkbox"> 加 PostToolUse format hook，别写在 CLAUDE.md 里赌 AI 记得</li><li><input disabled="" type="checkbox"> 加 PreToolUse 拦截 <code>rm -rf</code>、删 migration、动生产配置等</li><li><input disabled="" type="checkbox"> <code>/review</code> Skill 的 description 写清楚触发条件，避免 implement 会话误调</li><li><input disabled="" type="checkbox"> 调研型任务试 Subagent，implement 仍保持主对话可见</li></ul><hr><h2 id="最后想说的"><a href="#最后想说的" class="headerlink" title="最后想说的"></a>最后想说的</h2><p>七种方式看起来多，记一个核心就够：<strong>上下文窗口是最 scarce 的资源，确定性和概率性不要混用</strong>。</p><p>我之前的误区是把所有东西往 CLAUDE.md 塞——省事，但长对话里 AI 反而更不听话。拆成 Facts / Flows / Guards 三层之后，token 省下来，遵循度反而上去。</p><p>Output Styles 和 Append Prompt 我日常几乎不用；Hooks 和 path-scoped Rules 是被低估的两块——前者管「必须发生」，后者管「别什么都加载」。Skills 是目前 ROI 最高的投入点，把工作流里重复说的话封装成 <code>/xxx</code>，比每次 copy prompt 强一个数量级。</p>]]>
    </content>
    <id>https://w-li-you.github.io/2026/03/28/claude-code-seven-configurations/</id>
    <link href="https://w-li-you.github.io/2026/03/28/claude-code-seven-configurations/"/>
    <published>2026-03-27T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h1 id="Claude-Code-七种配置方式-·-个人总结"><a href="#Claude-Code-七种配置方式-·-个人总结" class="headerlink" title="Claude Code 七种配置方式 · 个人总结"></a>Claude Code 七种配置方式 · 个人总结</h1><blockquote>
<p>看了几篇解读 + 对照官方文档后的自己的理解 · 2026-07-03</p>
</blockquote>
<hr>]]>
    </summary>
    <title>Claude Code 七种配置方式 · 个人总结</title>
    <updated>2026-07-05T15:33:40.249Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="管理" scheme="https://w-li-you.github.io/categories/%E7%AE%A1%E7%90%86/"/>
    <category term="管理" scheme="https://w-li-you.github.io/tags/%E7%AE%A1%E7%90%86/"/>
    <category term="华为" scheme="https://w-li-you.github.io/tags/%E5%8D%8E%E4%B8%BA/"/>
    <category term="财经" scheme="https://w-li-you.github.io/tags/%E8%B4%A2%E7%BB%8F/"/>
    <category term="预算管理" scheme="https://w-li-you.github.io/tags/%E9%A2%84%E7%AE%97%E7%AE%A1%E7%90%86/"/>
    <content>
      <![CDATA[<blockquote><p>全面预算是企业战略目标、经营计划的货币化表达，是”作战计划的具体呈现”，并非单纯的费用、收入核算工具。本文基于华为财经实践，梳理全面预算管理的本质、落地体系与标杆启示。</p></blockquote><a id="more"></a><h2 id="一、核心认知：全面预算的本质与价值"><a href="#一、核心认知：全面预算的本质与价值" class="headerlink" title="一、核心认知：全面预算的本质与价值"></a>一、核心认知：全面预算的本质与价值</h2><h3 id="1-1-定义与核心定位"><a href="#1-1-定义与核心定位" class="headerlink" title="1.1 定义与核心定位"></a>1.1 定义与核心定位</h3><ul><li><strong>核心定义</strong>：全面预算是企业战略目标、经营计划的<strong>货币化表达</strong>，是”作战计划的具体呈现”。</li><li><strong>核心价值</strong>：整合”计划、协调、控制、评价、激励”五大职能，是少数能统筹企业所有关键问题的管理工具——上可对齐公司战略，下可管控日常运营。</li><li><strong>关键认知纠偏</strong>：预算做不准是正常的，其核心意义不在于”绝对精准”，而在于通过全流程推进，锤炼团队认知、形成经营共识、推动跨部门协同。</li></ul><h3 id="1-2-核心逻辑：平衡短期盈利与长期发展"><a href="#1-2-核心逻辑：平衡短期盈利与长期发展" class="headerlink" title="1.2 核心逻辑：平衡短期盈利与长期发展"></a>1.2 核心逻辑：平衡短期盈利与长期发展</h3><p>核心经营目标是实现”<strong>多赚、快赚、稳赚</strong>“，最终达成企业价值最大化。预算分为两大类：</p><table><thead><tr><th>分类</th><th>聚焦</th><th>内容</th></tr></thead><tbody><tr><td><strong>经营预算</strong></td><td>短期盈利</td><td>产品、区域、客户的当期盈利目标，保障现金流与利润稳定</td></tr><tr><td><strong>战略预算</strong></td><td>长期格局</td><td>核心技术研发、关键市场突破、管理能力建设，哪怕短期不产生效益</td></tr></tbody></table><blockquote><p>核心原则：不追求当年价值最大化，需持续投入未来能力（华为研发投入常年占收入 16%），杜绝短视经营。</p></blockquote><h3 id="1-3-底层支撑工具：杜邦分析（ROE）"><a href="#1-3-底层支撑工具：杜邦分析（ROE）" class="headerlink" title="1.3 底层支撑工具：杜邦分析（ROE）"></a>1.3 底层支撑工具：杜邦分析（ROE）</h3><p>$$\text{ROE} = \frac{\text{净利润}}{\text{收入}} \times \frac{\text{收入}}{\text{总资产}} \times \frac{\text{总资产}}{\text{权益}}$$</p><p>三大分解维度对应”多赚、快赚、稳赚”：</p><table><thead><tr><th>维度</th><th>对应</th><th>关键指标</th></tr></thead><tbody><tr><td><strong>利润政策</strong></td><td>多赚</td><td>销售毛利率——提升产品溢价能力</td></tr><tr><td><strong>周转政策</strong></td><td>快赚</td><td>DSO（应收账款周转天数）、ITO（库存周转率）——加快资金回笼</td></tr><tr><td><strong>结构政策</strong></td><td>稳赚</td><td>资产负债率——匹配行业特性，避免杠杆过低或过高</td></tr></tbody></table><blockquote><p>关键提醒：避免”一表独大”（仅关注利润表），需联动利润表、资产负债表、现金流量表。</p></blockquote><hr><h2 id="二、经营痛点与预算的关联"><a href="#二、经营痛点与预算的关联" class="headerlink" title="二、经营痛点与预算的关联"></a>二、经营痛点与预算的关联</h2><p><strong>核心痛点</strong>：利润账面好看，但现金流不足，甚至资金周转困难。根本原因是运营效率低下（应收账款周期过长、垫资严重）。</p><p><strong>改善路径</strong>：将”OCF（经营现金流）增长大于经营利润增长”纳入核心财务目标，通过全面预算管控运营资产效率。</p><blockquote><p>破解逻辑：通过”目标—策略—计划—资源—财务结果”的闭环管理，将顶层经营目标（如 ROE）层层分解到业务单元、产品、客户，破解”资源平均撒胡椒面”的低效问题。</p></blockquote><hr><h2 id="三、落地体系：道、法、术、器、人"><a href="#三、落地体系：道、法、术、器、人" class="headerlink" title="三、落地体系：道、法、术、器、人"></a>三、落地体系：道、法、术、器、人</h2><h3 id="3-1-组织支撑（人）"><a href="#3-1-组织支撑（人）" class="headerlink" title="3.1 组织支撑（人）"></a>3.1 组织支撑（人）</h3><p>核心组织是<strong>经营管理 COE</strong>（能力中心），隶属 CFO 体系。关键角色分工：</p><table><thead><tr><th>角色</th><th>职责</th></tr></thead><tbody><tr><td>一把手</td><td>各业务单元一把手是预算第一责任人</td></tr><tr><td>财经体系（CFO、财经 BP）</td><td>“支撑、赋能”而非”包办预算”，实现业财融合</td></tr><tr><td>业务单元</td><td>“编制、执行、复盘”，对预算完成情况负责</td></tr></tbody></table><h3 id="3-2-核心工具（器）"><a href="#3-2-核心工具（器）" class="headerlink" title="3.2 核心工具（器）"></a>3.2 核心工具（器）</h3><ul><li><strong>预算白皮书</strong>（核心中的核心）：预算编制的”指导手册”，华为会与高层反复推敲 6 遍以上。分面向管理者（经营指导意见、关键财务指标、资源配置规则）与面向操作者（预算模板、编制方法、预算日历、基线库）两大层面；</li><li><strong>管理核算规则</strong>：内部兄弟单元结算规则（量价模型）、后台部门费用分摊规则等，实现”亲兄弟明算账”。</li></ul><h3 id="3-3-核心流程（法）：从战略到执行的闭环"><a href="#3-3-核心流程（法）：从战略到执行的闭环" class="headerlink" title="3.3 核心流程（法）：从战略到执行的闭环"></a>3.3 核心流程（法）：从战略到执行的闭环</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">战略规划(SP) → 年度业务计划(BP) → 全面预算编制 → 滚动预测</span><br><span class="line">    → 经营分析 → 偏差纠偏 → 绩效评价 → 复盘优化</span><br></pre></td></tr></table></figure><p>关键要点：</p><ul><li><strong>预算编制</strong>：”目标→策略→业务计划→资源计划→财务结果”，既做”语文题”（业务策略）也做”数学题”（量化数据）；预算假设需<strong>显性化</strong>，作为后续复盘依据；</li><li><strong>执行与管控</strong>：重点管控三大偏差（目标差距、执行差距、预测变动偏差），偏差超 5% 需分析根因；推行<strong>滚动预测</strong>（预算管理之魂），每月编制，采用”3+9””4+8”模式；</li><li><strong>经营分析与复盘</strong>：核心是”认知复盘”而非单纯数据复盘，借助”三个 GAP + 三个清单（确定类、风险类、机会类）”分层推进。</li></ul><h3 id="3-4-关键机制（术）：激活组织活力"><a href="#3-4-关键机制（术）：激活组织活力" class="headerlink" title="3.4 关键机制（术）：激活组织活力"></a>3.4 关键机制（术）：激活组织活力</h3><p>核心机制是<strong>服务资源化、资源市场化</strong>，建立前中后台”资源买卖关系”，传递经营压力。</p><blockquote><p>华为案例：后方专家按级别定费率（如 22 级专家 5 万/天），一线”呼唤炮火”时需提前算账；专家的负载率（UR 值）直接反映其价值，倒逼提升效率。</p></blockquote><h3 id="3-5-基础支撑（数据-IT）"><a href="#3-5-基础支撑（数据-IT）" class="headerlink" title="3.5 基础支撑（数据 + IT）"></a>3.5 基础支撑（数据 + IT）</h3><p>建立<strong>基线库</strong>，实现基线受控管理，避免各业务单元选取对自身有利的基线；管报”诉出一口”，由账务管理部统一出具，确保数据质量与口径一致。</p><hr><h2 id="四、标杆实践启示"><a href="#四、标杆实践启示" class="headerlink" title="四、标杆实践启示"></a>四、标杆实践启示</h2><p><strong>华为预算管理变革路径：</strong> 建立经营管理 COE → 制定预算白皮书与管理规则 → 推行经营六要素模型 → 强化滚动预测与偏差管理 → 建立资源市场化机制 → 重视战略预算与未来投入。</p><blockquote><p>核心启示：预算管理不可一蹴而就，需匹配企业发展阶段，循序渐进；不追求”大而全”，重点在”适配、落地、复盘、优化”。</p></blockquote><p><strong>企业自检四大维度：</strong></p><table><thead><tr><th>维度</th><th>自检问题</th></tr></thead><tbody><tr><td>组织</td><td>是否有明确的预算责任主体？财经是否深入业务前端？</td></tr><tr><td>工具</td><td>是否有预算白皮书和管理核算规则？是否建立基线库？</td></tr><tr><td>流程</td><td>战略与预算是否衔接？是否推行滚动预测和偏差管理？</td></tr><tr><td>数据</td><td>管报与财报是否勾稽？预算假设是否显性化？</td></tr></tbody></table><hr><h2 id="五、核心总结"><a href="#五、核心总结" class="headerlink" title="五、核心总结"></a>五、核心总结</h2><ol><li><strong>全面预算的核心</strong>：不是”控成本”，而是”促战略落地、优资源配置、提经营效率、保稳健发展”；</li><li><strong>落地关键</strong>：业财融合、组织协同、工具支撑、复盘优化，杜绝”形式化预算”；</li><li><strong>核心抓手</strong>：预算白皮书、经营管理规则、经营六要素模型、滚动预测、三个 GAP + 三个清单；</li><li><strong>认知底线</strong>：资源有限，预算的本质是”取舍”，需聚焦主航道业务、优质客户、核心能力。</li></ol>]]>
    </content>
    <id>https://w-li-you.github.io/2026/03/25/comprehensive-budget-management/</id>
    <link href="https://w-li-you.github.io/2026/03/25/comprehensive-budget-management/"/>
    <published>2026-03-24T16:00:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>全面预算是企业战略目标、经营计划的货币化表达，是”作战计划的具体呈现”，并非单纯的费用、收入核算工具。本文基于华为财经实践，梳理全面预算管理的本质、落地体系与标杆启示。</p>
</blockquote>]]>
    </summary>
    <title>全面预算管理核心笔记（基于华为财经实践）</title>
    <updated>2026-07-01T13:04:56.368Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="读书笔记" scheme="https://w-li-you.github.io/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/"/>
    <category term="读书笔记" scheme="https://w-li-you.github.io/tags/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/"/>
    <category term="管理" scheme="https://w-li-you.github.io/tags/%E7%AE%A1%E7%90%86/"/>
    <content>
      <![CDATA[<blockquote><p>本篇涵盖第七、八章：激励理论与 OKR 的前身——目标管理（MBO）。</p></blockquote><a id="more"></a><h2 id="七、为什么人会努力工作"><a href="#七、为什么人会努力工作" class="headerlink" title="七、为什么人会努力工作"></a>七、为什么人会努力工作</h2><p>格鲁夫借用马斯洛需求层次，但给出了更具操作性的分析框架。他认为，当一个员工的基本生存需求（薪资）满足后，驱动他工作的是两类动力：</p><h3 id="外在动力（Competence-驱动）"><a href="#外在动力（Competence-驱动）" class="headerlink" title="外在动力（Competence 驱动）"></a>外在动力（Competence 驱动）</h3><p>当员工处于<strong>能力提升阶段</strong>时，外部的认可（奖金、晋升、表扬）是有效激励。<br>此时管理者应该：</p><ul><li>设置清晰可衡量的目标</li><li>给予及时的正向反馈</li><li>提供展示能力的机会</li></ul><h3 id="内在动力（Achievement-驱动）"><a href="#内在动力（Achievement-驱动）" class="headerlink" title="内在动力（Achievement 驱动）"></a>内在动力（Achievement 驱动）</h3><p>当员工在某领域已有相当能力后，他的驱动力来自<strong>内部的自我实现</strong>——想把事情做到极致，不是为了奖励，而是不能忍受做差。</p><p>此时过度的外部激励反而会伤害内在动力（对应心理学上的”过度理由效应”）。管理者应该：</p><ul><li>给有挑战性的目标</li><li>减少干预，给自主空间</li><li>认可他的专业判断</li></ul><h3 id="运动员心态"><a href="#运动员心态" class="headerlink" title="运动员心态"></a>运动员心态</h3><p>格鲁夫有个精彩的比喻：顶级运动员的训练量远超职业需要，他们不是为了奖金，而是<strong>对自己的标准</strong>。管理者应该帮助员工建立对自己工作的高标准，这比任何激励制度都更持久。</p><hr><h2 id="八、目标管理（MBO）：OKR-的雏形"><a href="#八、目标管理（MBO）：OKR-的雏形" class="headerlink" title="八、目标管理（MBO）：OKR 的雏形"></a>八、目标管理（MBO）：OKR 的雏形</h2><p>格鲁夫在英特尔发展了一套目标管理体系，后来由他的下属约翰·杜尔带到谷歌，演变成广为人知的 <strong>OKR</strong>（Objectives &amp; Key Results）。</p><h3 id="两个核心问题"><a href="#两个核心问题" class="headerlink" title="两个核心问题"></a>两个核心问题</h3><p>每个管理者都应该能清楚地回答：</p><ol><li><strong>我想去哪里？</strong>（Objective，方向性目标）</li><li><strong>我怎么知道自己到了那里？</strong>（Key Results，可量化的结果指标）</li></ol><h3 id="目标设置原则"><a href="#目标设置原则" class="headerlink" title="目标设置原则"></a>目标设置原则</h3><p><strong>方向性目标（Objective）</strong>：</p><ul><li>要有激励性，让人略感挑战</li><li>不需要量化，但要清晰有方向感</li><li>例：”成为团队最可靠的基础设施后端”</li></ul><p><strong>关键结果（Key Results）</strong>：</p><ul><li><strong>必须可量化</strong>，否则无法判断是否达成</li><li>通常 3-5 个，太多等于没有重点</li><li>例：”P99 接口延迟 &lt; 50ms；系统可用性 ≥ 99.9%；新服务上线后 0 个 P0 故障”</li></ul><h3 id="对齐与透明"><a href="#对齐与透明" class="headerlink" title="对齐与透明"></a>对齐与透明</h3><p>格鲁夫强调目标必须<strong>公开</strong>，上下对齐：</p><ul><li>上级目标分解成下级的目标，形成层级一致性</li><li>公开让每个人都知道团队在做什么，减少各自为战</li></ul><h3 id="目标应该设多高"><a href="#目标应该设多高" class="headerlink" title="目标应该设多高"></a>目标应该设多高</h3><blockquote><p>“如果所有目标都完成了，说明目标设得太低了。”</p></blockquote><p>格鲁夫建议关键结果的达成率在 <strong>70% 左右</strong>是健康的——说明目标有挑战性，达到 100% 反而应该反思是否在保守。</p><p>这个理念被谷歌 OKR 完整继承，也是为什么谷歌的 OKR 和绩效评估刻意分离——OKR 是挑战性目标，不直接绑定绩效奖金。</p><hr><h2 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h2><p>激励的核心是<strong>匹配</strong>：能力提升阶段用外在激励，成熟阶段培养内在标准。目标管理则是让团队聚焦和对齐的工具，格鲁夫那套在英特尔实践的方法，后来成了硅谷最流行的管理范式。</p>]]>
    </content>
    <id>https://w-li-you.github.io/2026/03/12/grove-high-output-management-4/</id>
    <link href="https://w-li-you.github.io/2026/03/12/grove-high-output-management-4/"/>
    <published>2026-03-11T16:00:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>本篇涵盖第七、八章：激励理论与 OKR 的前身——目标管理（MBO）。</p>
</blockquote>]]>
    </summary>
    <title>《格鲁夫给经理人的第一课》读书笔记（四）：激励与目标管理</title>
    <updated>2026-07-01T11:45:45.498Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="AI编程" scheme="https://w-li-you.github.io/categories/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="AI编程" scheme="https://w-li-you.github.io/tags/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="Claude Code" scheme="https://w-li-you.github.io/tags/Claude-Code/"/>
    <category term="Cursor" scheme="https://w-li-you.github.io/tags/Cursor/"/>
    <content>
      <![CDATA[<h1 id="CLAUDE-md-怎么写-·-个人总结"><a href="#CLAUDE-md-怎么写-·-个人总结" class="headerlink" title="CLAUDE.md 怎么写 · 个人总结"></a>CLAUDE.md 怎么写 · 个人总结</h1><blockquote><p>看了几篇讲 AI 上下文配置的文章 + 对照 Claude Code 官方 best practices 后的自己的理解 · 2026-07-03</p></blockquote><hr><a id="more"></a><h2 id="我踩过的坑"><a href="#我踩过的坑" class="headerlink" title="我踩过的坑"></a>我踩过的坑</h2><p>AI 不听话，我第一反应总是「换更强的模型」。后来发现很多时候是<strong>上下文给错了</strong>——该常驻的没写进文件，该按需加载的全塞根目录，该用 Hook 硬拦的却写成一句「请不要…」。</p><p>新会话 AI 是白纸。技术栈、构建命令、团队约定、历史 ADR，你不写它就猜，猜错返工，返工比多写几行配置贵多了。</p><hr><h2 id="CLAUDE-md-到底是什么"><a href="#CLAUDE-md-到底是什么" class="headerlink" title="CLAUDE.md 到底是什么"></a>CLAUDE.md 到底是什么</h2><p>项目根目录（或子目录）的 Markdown，Claude Code <strong>会话开始就读</strong>，相当于给 AI 的入职手册。</p><p>但它本质是<strong>建议</strong>，不是强制执行。写得越具体、越短，遵循越好；模糊要求（「写干净代码」）等于没写。</p><p>Cursor 侧是 <code>.cursor/rules</code> + <code>AGENTS.md</code>；Claude Code 是 <code>CLAUDE.md</code>。<code>AGENTS.md</code> 已是跨工具开放标准（Agentic AI Foundation 维护），多 Agent 团队可以 AGENTS.md 放通用约定、CLAUDE.md 放 Claude 特有配置，或在 CLAUDE.md 里 <code>@AGENTS.md</code> 导入，避免维护两份 diverge 的内容。</p><hr><h2 id="篇幅：200-行不是形式主义"><a href="#篇幅：200-行不是形式主义" class="headerlink" title="篇幅：200 行不是形式主义"></a>篇幅：200 行不是形式主义</h2><p>官方建议 <strong>200 行以内</strong>。每一行会话全程占 token——改个 CSS 也带着后端部署规范，纯属浪费。</p><p>有社区数据说 <del>50 行遵循率 ~94%、</del>400 行掉到 ~71%（待验证：样本和方法我不清楚，但方向对——<strong>越长越稀释</strong>）。</p><p>还有说法 AI 合理遵循约 150–200 条指令，超过后质量均匀下降。我不数条数，用一句自检：<strong>删掉这行 AI 会犯错吗？</strong> 不会就删。</p><p><strong>只放事实，不放流程</strong>——构建命令、目录结构、命名规范是事实；部署 runbook、审查清单是流程，应进 Skills（见《Claude-Code七种配置方式-个人总结》）。</p><hr><h2 id="写什么、不写什么"><a href="#写什么、不写什么" class="headerlink" title="写什么、不写什么"></a>写什么、不写什么</h2><h3 id="该写"><a href="#该写" class="headerlink" title="该写"></a>该写</h3><ul><li>AI 猜不到的：<code>npm run test</code>、<code>uv sync</code> 这类构建命令</li><li>跟默认不同的：必须用 Zod 校验、统一 <code>BaseResponse</code> 包装</li><li>团队 Git 规范、必需 env var、非显而易见的坑</li><li><strong>正面、可验证</strong>的指令</li></ul><h3 id="不该写"><a href="#不该写" class="headerlink" title="不该写"></a>不该写</h3><ul><li>读代码就能知道的结构</li><li>「写干净代码」「注意性能」</li><li>大段 API 文档——放 <code>docs/</code>，CLAUDE.md 里写指针</li></ul><h3 id="否定句慎用"><a href="#否定句慎用" class="headerlink" title="否定句慎用"></a>否定句慎用</h3><p>有文章说 87.5% 规则违反来自否定句（待验证）。白熊效应确实存在——「不要用 class 组件」反而激活 class 组件概念。我习惯改成正面表述：</p><table><thead><tr><th>别这么写</th><th>改成</th></tr></thead><tbody><tr><td>不要用 any</td><td>所有变量有明确 TS 类型</td></tr><tr><td>别在主分支直接提交</td><td>变更走 feature 分支 + PR</td></tr></tbody></table><hr><h2 id="大项目：别全堆根目录"><a href="#大项目：别全堆根目录" class="headerlink" title="大项目：别全堆根目录"></a>大项目：别全堆根目录</h2><h3 id="path-scoped-Rules"><a href="#path-scoped-Rules" class="headerlink" title="path-scoped Rules"></a>path-scoped Rules</h3><p><code>.claude/rules/</code> + frontmatter <code>paths</code>，只在 Claude 读匹配文件时加载：</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">---</span></span><br><span class="line"><span class="attr">paths:</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">&quot;src/api/**&quot;</span></span><br><span class="line"><span class="meta">---</span></span><br><span class="line"><span class="string">API</span> <span class="string">handler</span> <span class="string">必须</span> <span class="string">Zod</span> <span class="string">校验输入</span></span><br></pre></td></tr></table></figure><p>改前端时不加载 API 规则。无 paths 的 Rule = 第二个 CLAUDE.md，会话开始就全量加载。</p><h3 id="子目录-CLAUDE-md"><a href="#子目录-CLAUDE-md" class="headerlink" title="子目录 CLAUDE.md"></a>子目录 CLAUDE.md</h3><p><code>app/api/CLAUDE.md</code> 只在读该目录文件时加载。<strong>压缩后会丢</strong>，直到再碰那个目录——和根 CLAUDE.md 行为不同，别搞混。</p><h3 id="指针做渐进披露"><a href="#指针做渐进披露" class="headerlink" title="@ 指针做渐进披露"></a>@ 指针做渐进披露</h3><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">## 参考</span></span><br><span class="line"><span class="bullet">-</span> API 架构 → @docs/api-architecture.md（改 API 时读）</span><br><span class="line"><span class="bullet">-</span> 部署 → /deploy 技能</span><br></pre></td></tr></table></figure><p>核心思想：<strong>CLAUDE.md 当目录，不当百科全书</strong>。官方叫 just-in-time context，和 Skills 按需加载是一脉的。</p><hr><h2 id="Hooks-管「必须发生」"><a href="#Hooks-管「必须发生」" class="headerlink" title="Hooks 管「必须发生」"></a>Hooks 管「必须发生」</h2><p>格式化、提交前 lint、危险命令拦截——写 CLAUDE.md 里 AI <strong>可能</strong>忘。Hook 触发必执行，跟模型无关。</p><p>PreToolUse + <code>exit code 2</code> 可以硬拦删 migration 等操作。CLAUDE.md 负责建议，Hooks 负责强制——这条和我另一篇「七种配置方式」总结是同一逻辑。</p><hr><h2 id="多层级配置"><a href="#多层级配置" class="headerlink" title="多层级配置"></a>多层级配置</h2><table><thead><tr><th>层级</th><th>位置</th><th>特点</th></tr></thead><tbody><tr><td>组织级</td><td>IT/MDM 下发</td><td>最早加载，<strong>不可 exclude</strong></td></tr><tr><td>用户级</td><td><code>~/.claude/CLAUDE.md</code></td><td>本机所有项目，个人偏好</td></tr><tr><td>项目级</td><td><code>./CLAUDE.md</code></td><td>团队共享，进 Git</td></tr><tr><td>本地级</td><td><code>./CLAUDE.local.md</code></td><td>个人覆盖，不进 Git</td></tr></tbody></table><p>优先级大致：本地 &gt; 项目 &gt; 用户；组织级是底线。</p><p><strong>口头说的不算</strong>：对话里「后面都用 async/await」，压缩后就没了。持久化信息必须落文件。</p><hr><h2 id="怎么起步"><a href="#怎么起步" class="headerlink" title="怎么起步"></a>怎么起步</h2><ol><li><strong><code>/init</code></strong> 自动生成初稿——一定要人工精简，一条烂指令的破坏力超过一行烂代码</li><li><strong>从实战沉淀</strong>：先协作 1–2 个任务，再让 AI 回顾对话总结规范写成 CLAUDE.md</li><li><strong>从 20 行开始</strong>：技术栈 + 构建/测试命令 + AI 反复犯的 3–5 条，用着再加</li></ol><p>Claude Code 创始人习惯：AI 犯错时不只改代码，让它把纠正写进 CLAUDE.md。Auto Memory（<code>~/.claude/projects/.../memory/</code>）也会自动记模式，用 <code>/memory</code> 查看——和 CLAUDE.md 互补，但不能替代团队级约定。</p><hr><h2 id="规则不生效时我查什么"><a href="#规则不生效时我查什么" class="headerlink" title="规则不生效时我查什么"></a>规则不生效时我查什么</h2><ol><li><code>/memory</code> 看 CLAUDE.md 有没有被加载</li><li>指令是否够具体——「格式化好」→「2 空格、单行 80 字符」</li><li>有没有矛盾——CLAUDE.md 说 MyBatis Plus，rules 说 Flex</li><li>该用 Hook 的是不是错写在 md 里</li></ol><p>官方还建议：CLAUDE.md 当代码维护——AI 反复犯同一错，说明规则太长被淹没了，或表述歧义。</p><hr><h2 id="和我工作流的关系"><a href="#和我工作流的关系" class="headerlink" title="和我工作流的关系"></a>和我工作流的关系</h2><table><thead><tr><th>原则</th><th>我的做法</th></tr></thead><tbody><tr><td>事实进 CLAUDE.md / AGENTS.md</td><td>Phase 0 <code>/grill-with-docs</code> 沉淀到 docs/ 和 CONTEXT</td></tr><tr><td>流程进 Skills</td><td><code>/grill-with-docs</code>、<code>/implement</code>、<code>/review</code></td></tr><tr><td>≤200 行 + 索引</td><td>大文档用 <code>@docs/</code> 指针，不全量塞</td></tr><tr><td>强制检查</td><td>待补 Hooks（format/lint/危险命令）</td></tr></tbody></table><p>以前 README 给人看，现在 CLAUDE.md 给 AI 看——本质都是「把重要信息组织清楚」，但给 AI 的版本要更<strong>短、具体、可执行</strong>。</p><hr><h2 id="待办"><a href="#待办" class="headerlink" title="待办"></a>待办</h2><ul><li><input disabled="" type="checkbox"> 各 repo 审计 CLAUDE.md：流程迁 Skills、超 200 行拆索引</li><li><input disabled="" type="checkbox"> 统一 AGENTS.md + CLAUDE.md 分工，避免双份维护 diverge</li><li><input disabled="" type="checkbox"> 配 PostToolUse format Hook</li><li><input disabled="" type="checkbox"> AI 犯错后追加规则，定期 prune 过时条目</li></ul>]]>
    </content>
    <id>https://w-li-you.github.io/2026/03/08/claude-md-how-to-write/</id>
    <link href="https://w-li-you.github.io/2026/03/08/claude-md-how-to-write/"/>
    <published>2026-03-07T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h1 id="CLAUDE-md-怎么写-·-个人总结"><a href="#CLAUDE-md-怎么写-·-个人总结" class="headerlink" title="CLAUDE.md 怎么写 · 个人总结"></a>CLAUDE.md 怎么写 · 个人总结</h1><blockquote>
<p>看了几篇讲 AI 上下文配置的文章 + 对照 Claude Code 官方 best practices 后的自己的理解 · 2026-07-03</p>
</blockquote>
<hr>]]>
    </summary>
    <title>CLAUDE.md 怎么写 · 个人总结</title>
    <updated>2026-07-05T15:33:40.247Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="中间件" scheme="https://w-li-you.github.io/categories/%E4%B8%AD%E9%97%B4%E4%BB%B6/"/>
    <category term="Elasticsearch" scheme="https://w-li-you.github.io/tags/Elasticsearch/"/>
    <category term="分布式系统" scheme="https://w-li-you.github.io/tags/%E5%88%86%E5%B8%83%E5%BC%8F%E7%B3%BB%E7%BB%9F/"/>
    <content>
      <![CDATA[<blockquote><p>本文是 ES 存储引擎系列的第二篇，承接<a href="/2026/02/16/es-segment-commitpoint-translog/">上一篇关于段、提交点、Translog 的介绍</a>，详细拆解”写入确认→Refresh→Flush→段合并”的完整生命周期，并解释为什么 ES 需要同时支持”近实时搜索”和”实时 CRUD”两套机制。</p></blockquote><a id="more"></a><h2 id="写在前面"><a href="#写在前面" class="headerlink" title="写在前面"></a>写在前面</h2><p>ES 的写入流程不是”写完就能立刻搜到”这么简单，而是经历了多个阶段，每个阶段都在<strong>性能</strong>和<strong>数据安全/可见性</strong>之间做权衡：</p><pre class="mermaid">graph LR    A[&quot;1. 写入确认&lt;br&gt;Translog 落地&quot;] --&gt; B[&quot;2. Refresh&lt;br&gt;近实时可搜索&quot;]    B --&gt; C[&quot;3. Flush&lt;br&gt;持久化到磁盘&quot;]    C --&gt; D[&quot;4. 段合并&lt;br&gt;优化存储结构&quot;]</pre><table><thead><tr><th>阶段</th><th>解决的问题</th><th>默认触发频率</th></tr></thead><tbody><tr><td>写入与确认</td><td>数据不丢失（持久化保证）</td><td>每次写请求</td></tr><tr><td>Refresh</td><td>数据能被搜索到（近实时可见性）</td><td>默认 1 秒</td></tr><tr><td>Flush</td><td>数据真正落到磁盘（持久化）</td><td>Translog 达 512MB 或 30 分钟</td></tr><tr><td>段合并</td><td>控制段数量、回收已删除文档空间</td><td>段数量/删除比例超过阈值</td></tr></tbody></table><h2 id="一、写入与确认——实时的持久化"><a href="#一、写入与确认——实时的持久化" class="headerlink" title="一、写入与确认——实时的持久化"></a>一、写入与确认——实时的持久化</h2><h3 id="1-1-写入流程"><a href="#1-1-写入流程" class="headerlink" title="1.1 写入流程"></a>1.1 写入流程</h3><ol><li><strong>客户端请求</strong>：客户端发送写入请求，即向 ES 的协调节点发送一个索引文档的请求。</li><li><strong>路由</strong>：协调节点根据文档 ID 确定所属主分片，将请求转发给主分片所在的节点。</li><li><strong>写入缓冲区</strong>：主分片将文档写入内存缓冲区（此时文档<strong>不可搜索</strong>）。</li><li><strong>记录 Translog</strong>：记录 Translog，防止数据丢失。</li><li><strong>确认写入</strong>：根据配置的 <code>durability</code> 级别，等待 Translog 同步到磁盘后（<code>async</code> 级别无需等待，直接返回），客户端收到”写入成功”的确认（<strong>但此时搜索仍不可见</strong>）。</li></ol><pre class="mermaid">sequenceDiagram    participant C as 客户端    participant Co as 协调节点    participant P as 主分片    participant T as Translog    C-&gt;&gt;Co: 发送写入请求    Co-&gt;&gt;P: 路由转发到主分片    P-&gt;&gt;P: 写入内存缓冲区，此时不可搜索    P-&gt;&gt;T: 记录 Translog    T--&gt;&gt;P: 按 durability 策略确认落盘    P--&gt;&gt;Co: 写入成功    Co--&gt;&gt;C: 返回写入成功，此时搜索不可见</pre><div class="note warning"><p><strong>重要认知</strong>：在这一步，客户端拿到”写入成功”的响应，并不代表文档已经可以被 <code>_search</code> 接口搜到。这正是”近实时（Near Real-Time）”这个名字的由来——写入是被持久化保证的（数据不丢），但可见性有延迟。这是 ES 区别于传统数据库（写完立刻能查到）的一个常被忽视、却很重要的语义差异，很多线上 Bug（例如”刚插入的数据搜不到”）的根因都在这里。</p></div><h2 id="二、Refresh——实现”近实时搜索”"><a href="#二、Refresh——实现”近实时搜索”" class="headerlink" title="二、Refresh——实现”近实时搜索”"></a>二、Refresh——实现”近实时搜索”</h2><h3 id="2-1-为什么需要-Refresh"><a href="#2-1-为什么需要-Refresh" class="headerlink" title="2.1 为什么需要 Refresh"></a>2.1 为什么需要 Refresh</h3><p>Lucene 允许新段被写入和打开——使其包含的文档在未进行一次完整提交时便对搜索可见。这种方式比进行一次提交代价要小得多，并且在不影响性能的前提下可以被频繁地执行。</p><p>在 Elasticsearch 中，写入和打开一个新段的轻量过程叫做 <strong>Refresh</strong>。默认情况下每个分片会<strong>每秒自动刷新一次</strong>。这就是为什么我们说 Elasticsearch 是<strong>近实时搜索</strong>：文档的变化并不是立即对搜索可见，但会在一秒之内变为可见。Refresh 是将内存中的文档数据转化为可搜索形式的过程。</p><ul><li>在 Refresh <strong>之前</strong>，文档只存在于写入层面（内存缓冲区），完全不可被搜索。</li><li>在 Refresh <strong>之后</strong>，文档被构建成搜索数据结构，立即可被 <code>_search</code> API 查询到。</li></ul><h3 id="2-2-Refresh-流程"><a href="#2-2-Refresh-流程" class="headerlink" title="2.2 Refresh 流程"></a>2.2 Refresh 流程</h3><ol><li><strong>触发 Refresh</strong>：默认每秒一次，自动触发 Refresh 操作。</li><li><strong>创建新的段</strong>：Refresh 操作会清空内存缓冲区，为缓冲区中的所有文档构建倒排索引，生成一个全新的、不可变的 Lucene 段（这个段本身就是一个完整的倒排索引）。</li><li><strong>段被写入文件系统缓存</strong>：这个新创建的段被写入到操作系统的文件系统缓存中，这是一个内存操作，速度极快。</li><li><strong>段被打开，文档可被搜索</strong>：一旦段在文件系统缓存中就绪，它就会被”打开”，此时这个新段内的所有文档立即变得可被 <code>_search</code> API 搜索到。</li></ol><div class="note info"><p><strong>关键点</strong>：第 3 步只是写入<strong>操作系统的文件系统缓存</strong>（page cache），而不是直接 fsync 到物理磁盘——这正是 Refresh 操作能做到”轻量、可被频繁执行”的原因。真正把数据强制写入物理磁盘的，是下一节的 <strong>Flush</strong> 操作。也正因如此，Refresh 之后的数据仍然存在丢失风险（如果机器突然断电，文件系统缓存中尚未 fsync 的数据可能丢失）——但 Translog 已经记录了这些操作，所以即使段丢失，也能通过重放 Translog 恢复。</p></div><h3 id="2-3-Refresh-触发条件"><a href="#2-3-Refresh-触发条件" class="headerlink" title="2.3 Refresh 触发条件"></a>2.3 Refresh 触发条件</h3><h4 id="①-时间间隔触发（设置为-1-可禁止自动刷新）"><a href="#①-时间间隔触发（设置为-1-可禁止自动刷新）" class="headerlink" title="① 时间间隔触发（设置为 -1 可禁止自动刷新）"></a>① 时间间隔触发（设置为 -1 可禁止自动刷新）</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">PUT /my_index/_settings</span><br><span class="line">&#123;</span><br><span class="line">  <span class="string">&quot;index.refresh_interval&quot;</span>: <span class="string">&quot;1s&quot;</span> // 默认值</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h4 id="②-内存缓冲区触发"><a href="#②-内存缓冲区触发" class="headerlink" title="② 内存缓冲区触发"></a>② 内存缓冲区触发</h4><p>内存缓冲区接近满状态时触发，通常在持续高写入压力下发生。</p><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;index.translog.flush_threshold_size&quot;</span><span class="punctuation">:</span> <span class="string">&quot;512mb&quot;</span><span class="punctuation">,</span> # 间接影响</span><br><span class="line">  <span class="attr">&quot;index.memory.index_buffer_size&quot;</span><span class="punctuation">:</span> <span class="string">&quot;10%&quot;</span>         # 索引缓冲区大小</span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure><h4 id="③-显式手动触发"><a href="#③-显式手动触发" class="headerlink" title="③ 显式手动触发"></a>③ 显式手动触发</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 刷新特定索引</span></span><br><span class="line">POST /my_index/_refresh</span><br><span class="line"></span><br><span class="line"><span class="comment"># 刷新多个索引</span></span><br><span class="line">POST /index1,index2/_refresh</span><br><span class="line"></span><br><span class="line"><span class="comment"># 刷新所有索引</span></span><br><span class="line">POST /_refresh</span><br></pre></td></tr></table></figure><h4 id="④-特殊情况"><a href="#④-特殊情况" class="headerlink" title="④ 特殊情况"></a>④ 特殊情况</h4><p>Flush 前、索引恢复或重分配时、索引设置变更等场景也会触发 Refresh。</p><div class="note warning"><p><strong>生产环境调优提示</strong>：<code>refresh_interval</code> 是 ES 性能调优中最常见的一个参数。如果业务场景对”秒级可见性”不敏感（比如离线批量导入数据），可以把 <code>refresh_interval</code> 临时调大甚至设为 <code>-1</code>（禁用自动刷新），导入完成后再手动 <code>_refresh</code> 一次或恢复默认值——这样能显著提升批量写入吞吐量，因为减少了频繁构建小段、再合并小段的开销。这是 ES 官方推荐的”批量导入加速”标准做法之一。</p></div><h2 id="三、Flush——持久化变更"><a href="#三、Flush——持久化变更" class="headerlink" title="三、Flush——持久化变更"></a>三、Flush——持久化变更</h2><h3 id="3-1-为什么需要-Flush"><a href="#3-1-为什么需要-Flush" class="headerlink" title="3.1 为什么需要 Flush"></a>3.1 为什么需要 Flush</h3><p>Flush 是将内存中和文件系统缓存中的数据<strong>永久写入磁盘</strong>，并创建一个新的持久化状态点的过程。</p><ul><li>在 Flush <strong>之前</strong>，数据可能只存在于内存或文件系统缓存中，有丢失风险。</li><li>在 Flush <strong>之后</strong>，数据已被安全写入物理磁盘，即使断电也不会丢失。</li></ul><h3 id="3-2-段持久化和提交流程"><a href="#3-2-段持久化和提交流程" class="headerlink" title="3.2 段持久化和提交流程"></a>3.2 段持久化和提交流程</h3><ol><li><strong>触发 Flush</strong>：当 Translog 大小达到阈值（默认 512MB）或定时触发时，启动 Flush。</li><li><strong>确保数据在段中</strong>：首先执行一次 Refresh，确保所有数据都已转化成段，保证 Flush 能捕获到所有未持久化的数据。</li><li><strong>段持久化到磁盘</strong>：调用 <code>fsync</code>，强制操作系统将文件系统缓存中的所有脏页（dirty pages）真正写入物理磁盘。</li><li><strong>创建新提交点</strong>：生成一个新的提交点（<code>segments_N</code>）文件，记录当前所有已持久化的、有效的段的完整列表；提交点本身也会通过 <code>fsync</code> 确保写入磁盘。</li><li><strong>清空 Translog</strong>：由于所有操作都已被安全持久化到段中，对应的 Translog 记录不再需要——当前 Translog 文件被删除（截断），并创建一个新的、空的 Translog 文件。</li></ol><pre class="mermaid">flowchart LR    A[&quot;触发 Flush&quot;] --&gt; B[&quot;执行 Refresh&lt;br&gt;确保数据已转化成段&quot;]    B --&gt; C[&quot;调用 fsync&lt;br&gt;段持久化到磁盘&quot;]    C --&gt; D[&quot;创建新提交点 segments_N&quot;]    D --&gt; E[&quot;清空旧 Translog&lt;br&gt;创建新的空 Translog&quot;]</pre><h3 id="3-3-Flush-触发条件"><a href="#3-3-Flush-触发条件" class="headerlink" title="3.3 Flush 触发条件"></a>3.3 Flush 触发条件</h3><h4 id="①-Translog-大小触发（主要方式）"><a href="#①-Translog-大小触发（主要方式）" class="headerlink" title="① Translog 大小触发（主要方式）"></a>① Translog 大小触发（主要方式）</h4><p>这是最常见、最重要的触发条件。Translog 文件持续增长，当大小达到 <code>flush_threshold_size</code>（默认 512MB），自动触发 Flush 操作，Translog 被清空，重新开始记录。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">PUT /my_index/_settings</span><br><span class="line">&#123;</span><br><span class="line">  <span class="string">&quot;index.translog.flush_threshold_size&quot;</span>: <span class="string">&quot;512mb&quot;</span> // 默认值</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h4 id="②-时间间隔触发"><a href="#②-时间间隔触发" class="headerlink" title="② 时间间隔触发"></a>② 时间间隔触发</h4><p>即使 Translog 大小未达标，也会按时间间隔强制 Flush，用于：</p><ul><li><strong>数据安全</strong>：防止少量写入的数据长时间留在内存中。</li><li><strong>系统维护</strong>：定期清理和优化索引结构。</li></ul><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">PUT /my_index/_settings</span><br><span class="line">&#123;</span><br><span class="line">  <span class="string">&quot;index.translog.flush_threshold_period&quot;</span>: <span class="string">&quot;30m&quot;</span> // 默认30分钟</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h4 id="③-显式手动触发-1"><a href="#③-显式手动触发-1" class="headerlink" title="③ 显式手动触发"></a>③ 显式手动触发</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Flush 特定索引</span></span><br><span class="line">POST /my_index/_flush</span><br><span class="line"></span><br><span class="line"><span class="comment"># Flush 多个索引</span></span><br><span class="line">POST /index1,index2/_flush</span><br><span class="line"></span><br><span class="line"><span class="comment"># Flush 所有索引</span></span><br><span class="line">POST /_flush</span><br><span class="line"></span><br><span class="line"><span class="comment"># 带参数的Flush</span></span><br><span class="line">POST /my_index/_flush?wait_if_ongoing=<span class="literal">true</span></span><br></pre></td></tr></table></figure><ul><li><code>wait_if_ongoing</code>：如果已有 Flush 在进行，是否等待。</li><li><code>force</code>：强制 Flush，即使没有需要 Flush 的数据。</li></ul><h4 id="④-系统事件触发"><a href="#④-系统事件触发" class="headerlink" title="④ 系统事件触发"></a>④ 系统事件触发</h4><p>在特定系统事件发生时自动触发：索引关闭时、分片重分配时、节点关闭前、备份/快照前。</p><div class="note info"><p><strong>Refresh vs Flush 的本质区别</strong>：很多初学者容易混淆这两个操作，可以这样区分——Refresh 解决的是”<strong>能不能搜到</strong>“的问题（数据从内存进入可搜索的段，但段可能还只在文件系统缓存里）；Flush 解决的是”<strong>会不会丢</strong>“的问题（把文件系统缓存中的数据真正 fsync 到物理磁盘，并清空 Translog）。即使从不手动 Flush，数据也不会丢失（因为有 Translog 兜底），但 Translog 会无限增长，故障重启时需要重放的操作也会越来越多，恢复时间变长——这就是为什么需要定期 Flush 把”未完成的事务”清空。</p></div><h2 id="四、段合并"><a href="#四、段合并" class="headerlink" title="四、段合并"></a>四、段合并</h2><h3 id="4-1-为什么需要段合并"><a href="#4-1-为什么需要段合并" class="headerlink" title="4.1 为什么需要段合并"></a>4.1 为什么需要段合并</h3><p>由于段的不可变性和频繁的 Refresh，会导致一些问题：<strong>段数量爆炸、逻辑删除累积、存储效率低</strong>。</p><p>段合并是 Lucene 后台将多个小的、已提交的段合并成更大的、更优化的新段的过程。在合并过程中，会物理清除那些在 <code>.del</code> 文件中被标记为”已删除”的文档，真正释放磁盘空间。</p><ul><li>合并过程中，搜索继续在旧段上进行（不影响线上搜索可用性）。</li><li>新合并段准备好后，原子性切换到新段。</li></ul><h3 id="4-2-段合并过程"><a href="#4-2-段合并过程" class="headerlink" title="4.2 段合并过程"></a>4.2 段合并过程</h3><ol><li><strong>选择合并候选段</strong>：合并策略（默认 <code>TieredMergePolicy</code>）分析所有段，选择一组大小相近、包含较多删除文档的段作为合并候选，策略目标是平衡合并开销和收益。</li><li><strong>创建新合并段</strong>：系统创建一个全新的、更大的段，只从原始段中拷贝<strong>未被标记为删除</strong>的文档，真正物理删除那些在 <code>.del</code> 文件中标记的文档。</li><li><strong>替换旧段</strong>：新合并段创建完成后，系统生成一个新的提交点，新提交点引用新合并段，不再引用被合并的旧段，新段被打开，立即可被搜索。</li><li><strong>清理旧段</strong>：被替换的旧段被标记为”待删除”，在安全的时候，这些旧段文件被物理删除，此时被删除文档的磁盘空间真正被释放。</li></ol><pre class="mermaid">graph LR    subgraph 合并前        S1[&quot;段 1 小&quot;]        S2[&quot;段 2 小&quot;]        S3[&quot;段 3 含较多删除&quot;]    end    S1 --&gt;|拷贝未删除文档| M[&quot;新合并段 大&quot;]    S2 --&gt;|拷贝未删除文档| M    S3 --&gt;|拷贝未删除文档| M    M --&gt; CP[&quot;新提交点引用新段&quot;]    CP --&gt;|旧段标记待删除并物理清理| Done[&quot;磁盘空间释放&quot;]</pre><h3 id="4-3-段合并策略"><a href="#4-3-段合并策略" class="headerlink" title="4.3 段合并策略"></a>4.3 段合并策略</h3><p>Elasticsearch 使用<strong>合并策略（Merge Policy）</strong>来决定哪些段应该被合并以及如何合并。默认且最常用的策略是 <strong>TieredMergePolicy</strong>，采用”分层”的思想来管理段——按段大小分成若干层（小段、中段、大段），优先在同一层内进行合并，避免大段被反复参与合并造成不必要的 I/O 开销。</p><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">PUT /my_index/_settings</span><br><span class="line">&#123;</span><br><span class="line">  <span class="string">&quot;index.merge.policy&quot;</span>: &#123;</span><br><span class="line">    // 每层允许的段数量（越小合并越频繁）</span><br><span class="line">    <span class="string">&quot;segments_per_tier&quot;</span>: 10,</span><br><span class="line">    // 单次合并最多涉及多少个段</span><br><span class="line">    <span class="string">&quot;max_merge_at_once&quot;</span>: 10,</span><br><span class="line">    // 合并后段的最大大小</span><br><span class="line">    <span class="string">&quot;max_merged_segment&quot;</span>: <span class="string">&quot;5gb&quot;</span>,</span><br><span class="line">    // 触发合并的删除文档比例阈值</span><br><span class="line">    <span class="string">&quot;deletes_pct_allowed&quot;</span>: 33,</span><br><span class="line">    // 小于此值的段被视为同一大小（避免对小段过度合并）</span><br><span class="line">    <span class="string">&quot;floor_segment&quot;</span>: <span class="string">&quot;2mb&quot;</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h3 id="4-4-段合并的触发条件"><a href="#4-4-段合并的触发条件" class="headerlink" title="4.4 段合并的触发条件"></a>4.4 段合并的触发条件</h3><h4 id="①-自动触发（TieredMergePolicy）"><a href="#①-自动触发（TieredMergePolicy）" class="headerlink" title="① 自动触发（TieredMergePolicy）"></a>① 自动触发（TieredMergePolicy）</h4><ul><li><strong>段数量和大小</strong>：当某一”层”的段数量超过阈值时——由 <code>segments_per_tier</code> 控制。</li><li><strong>删除文档比例</strong>：当某个段中包含大量被删除的文档时——由 <code>deletes_pct_allowed</code> 控制。</li></ul><h4 id="②-手动触发"><a href="#②-手动触发" class="headerlink" title="② 手动触发"></a>② 手动触发</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 强制合并索引（谨慎使用！）</span></span><br><span class="line">POST /my_index/_forcemerge</span><br><span class="line"></span><br><span class="line"><span class="comment"># 只合并包含删除的段</span></span><br><span class="line">POST /my_index/_forcemerge?only_expunge_deletes=<span class="literal">true</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 合并到指定段数量</span></span><br><span class="line">POST /my_index/_forcemerge?max_num_segments=1</span><br></pre></td></tr></table></figure><div class="note warning"><p><strong><code>_forcemerge</code> 使用警告</strong>：手动强制合并存在以下风险，生产环境务必谨慎使用：</p><ul><li><strong>长时间阻塞</strong>：大索引可能耗时数小时。</li><li><strong>资源耗尽</strong>：消耗大量 CPU、内存、I/O。</li><li><strong>磁盘空间翻倍</strong>：合并期间新旧段共存，磁盘占用会短暂翻倍。</li><li><strong>无法中断</strong>：强制停止可能导致索引损坏。</li></ul><p><code>_forcemerge</code> 通常只建议在<strong>只读索引</strong>（如日志类场景中，前一天已经不再写入的旧索引）上使用，将其合并为单个段以节省存储和提升查询性能；对于仍在持续写入的活跃索引，应该让 <code>TieredMergePolicy</code> 自动管理，不要手动干预。</p></div><h2 id="五、从写入到搜索完整流程图"><a href="#五、从写入到搜索完整流程图" class="headerlink" title="五、从写入到搜索完整流程图"></a>五、从写入到搜索完整流程图</h2><pre class="mermaid">graph TD    A[&quot;客户端发送写入请求&quot;] --&gt; B[&quot;协调节点路由至主分片&quot;]    B --&gt; C[&quot;数据写入内存缓冲区&quot;]    C --&gt; D[&quot;操作追加至 Translog&quot;]    D --&gt; E{&quot;Translog 持久化策略&quot;}    E --&gt;|request 默认| F[&quot;等待 Translog fsync&quot;]    E --&gt;|async| G[&quot;按间隔异步刷盘&quot;]    F --&gt; H[&quot;返回客户端：写入成功&quot;]    G --&gt; H    H --&gt; I{&quot;等待 Refresh 触发?&quot;}    I --&gt;|是，默认 1s| J[&quot;清空内存缓冲区&lt;br&gt;构建倒排索引，创建新 Lucene 段&quot;]    J --&gt; K[&quot;段写入文件系统缓存&quot;]    K --&gt; L[&quot;段被打开，文档可被搜索&quot;]    L --&gt; M[&quot;数据可被搜索&lt;br&gt;存在于文件系统缓存的段中&quot;]    M --&gt; N{&quot;等待 Flush 触发?&quot;}    N --&gt;|是| O[&quot;执行 Refresh&quot;]    O --&gt; P[&quot;调用 fsync 将所有段持久化至磁盘&quot;]    P --&gt; Q[&quot;创建新提交点，记录所有有效段&quot;]    Q --&gt; R[&quot;清空旧 Translog&quot;]    R --&gt; S[&quot;数据被持久化&lt;br&gt;存在于磁盘的段中&quot;]    M --&gt; T[&quot;段合并：优化存储与查询&quot;]    S --&gt; T    T --&gt; U[&quot;选择多个小段&quot;]    U --&gt; V[&quot;合并为新的大段&lt;br&gt;物理删除已标记文档&quot;]    V --&gt; W[&quot;新提交点排除旧段&quot;]    W --&gt; X[&quot;删除旧段，释放空间&quot;]</pre><h2 id="六、实时-CRUD-操作"><a href="#六、实时-CRUD-操作" class="headerlink" title="六、实时 CRUD 操作"></a>六、实时 CRUD 操作</h2><h3 id="6-1-为什么有了近实时搜索后，还要有实时的-CRUD？"><a href="#6-1-为什么有了近实时搜索后，还要有实时的-CRUD？" class="headerlink" title="6.1 为什么有了近实时搜索后，还要有实时的 CRUD？"></a>6.1 为什么有了近实时搜索后，还要有实时的 CRUD？</h3><p>近实时搜索是通过 Refresh 操作实现的，默认每秒一次，将内存缓冲区的数据变成可搜索的段。而<strong>实时 CRUD</strong> 是通过 Translog 实现的——当通过文档 ID 进行获取、更新、删除时，会先检查内存缓冲区和 Translog，从而获取最新版本的数据，**不依赖 Refresh 的”秒级延迟”**。</p><p>这两种机制服务于完全不同的使用场景和用户需求，核心问题是：<strong>如何在同一系统中协调”高性能搜索”和”强一致性操作”这两种看似矛盾的需求？</strong></p><h4 id="①-从用户心理角度看，人们对不同操作有着截然不同的期望"><a href="#①-从用户心理角度看，人们对不同操作有着截然不同的期望" class="headerlink" title="① 从用户心理角度看，人们对不同操作有着截然不同的期望"></a>① 从用户心理角度看，人们对不同操作有着截然不同的期望</h4><ul><li><strong>搜索场景</strong>中，用户能够接受短暂延迟：当用户搜索”最新手机”时，如果结果中不包含 1 秒前刚上架的商品，他们通常能够理解。</li><li><strong>直接操作场景</strong>中，用户要求立即反馈：更新个人信息后立即查看，期望看到变化立即生效；库存信息需要及时更新不能超卖——这种”所见即所得”的心理预期是用户体验的底线。</li></ul><h4 id="②-应该让低成本的操作实时，高成本的操作近实时"><a href="#②-应该让低成本的操作实时，高成本的操作近实时" class="headerlink" title="② 应该让低成本的操作实时，高成本的操作近实时"></a>② 应该让低成本的操作实时，高成本的操作近实时</h4><ul><li><strong>近实时搜索的成本较高</strong>：需要构建完整的倒排索引结构，涉及分词、排序、压缩等复杂计算，需要管理多个段文件的合并和优化。</li><li><strong>实时 CRUD 的成本较低</strong>：基于文档 ID 的操作只需查询 Translog 和内存缓冲区，类似于数据库的主键查询，通过简单索引快速定位，资源消耗可控，不会对系统造成过大压力。</li></ul><h4 id="③-需要提供灵活的工具而非僵硬的规则"><a href="#③-需要提供灵活的工具而非僵硬的规则" class="headerlink" title="③ 需要提供灵活的工具而非僵硬的规则"></a>③ 需要提供灵活的工具而非僵硬的规则</h4><p>Elasticsearch 通过清晰的 API 设计明确了这种权衡：</p><table><thead><tr><th>API</th><th>语义</th></tr></thead><tbody><tr><td><code>/_search</code></td><td>接受近实时特性，获得极致性能</td></tr><tr><td><code>/_doc/&#123;id&#125;</code></td><td>获得实时一致性，满足强一致性需求（点查）</td></tr><tr><td><code>?refresh=true</code> 参数</td><td>在需要时强制立即可见，灵活控制</td></tr></tbody></table><p>这种设计让开发者能够根据具体场景选择合适工具，而不是被迫接受”一刀切”的解决方案。</p><h3 id="6-2-实时-CRUD-具体流程"><a href="#6-2-实时-CRUD-具体流程" class="headerlink" title="6.2 实时 CRUD 具体流程"></a>6.2 实时 CRUD 具体流程</h3><p>对于基于文档 ID 的 CRUD 操作，**Translog 是查找最新数据的”真相源”**。</p><ol><li><strong>检查内存缓冲区</strong>：在接收请求的数据节点上，系统会检查当前内存缓冲区中是否有该文档 ID 的任何未提交的更改。如果找到，说明这是绝对最新的版本，可以直接返回。</li><li><strong>查询 Translog</strong>：如果在内存缓冲区中没有找到，系统会查询该分片的 Translog——它按时间顺序记录了所有操作，因此能告诉我们关于这个文档 ID 的最新操作是什么（索引/创建、更新、删除）。</li><li><strong>根据 Translog 记录采取行动</strong>：<ul><li><strong>情况 A：Translog 显示文档存在（创建或更新）</strong>——Translog 不仅记录操作类型，还记录了该文档在哪个 Lucene 段中。系统直接定位到对应的段文件，读取文档内容并返回。即使这个段是几个小时前创建的，只要 Translog 指出这是最新版本的位置，就会从这里读取。</li><li><strong>情况 B：Translog 显示文档已被删除</strong>——系统会立即返回 <code>404 Not Found</code>，而不会再去任何段中查找。即使某些旧段中还存在这个文档的数据，但由于 Translog 记录了删除操作，它被认为已不存在。</li></ul></li><li><strong>作为最后手段的段查找</strong>：如果 Translog 中也没有该文档 ID 的记录，说明文档要么不存在，要么最后一次操作已经被持久化。此时，系统会回退到标准的搜索方式，在所有已提交的段中查找该文档。</li></ol><pre class="mermaid">flowchart TD    A[&quot;GET&#x2F;UPDATE&#x2F;DELETE 请求，带文档 ID&quot;] --&gt; B{&quot;内存缓冲区中&lt;br&gt;有该 ID 的未提交更改?&quot;}    B --&gt;|是| C[&quot;直接返回最新版本&quot;]    B --&gt;|否| D{&quot;查询该分片 Translog&quot;}    D --&gt;|记录为创建&#x2F;更新| E[&quot;定位到 Translog 记录的&lt;br&gt;Lucene 段，读取并返回&quot;]    D --&gt;|记录为删除| F[&quot;立即返回 404 Not Found&quot;]    D --&gt;|无该 ID 记录| G[&quot;回退到标准段查找方式&quot;]</pre><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>ES 的写入到可搜索/可持久化的完整生命周期，本质上是围绕**”四层缓冲”**展开的：</p><ol><li><strong>内存缓冲区</strong>（写入但不可搜索）</li><li><strong>Translog</strong>（保证不丢，支撑实时 CRUD）</li><li><strong>文件系统缓存中的段</strong>（Refresh 后可搜索，但未 fsync）</li><li><strong>磁盘上持久化的段</strong>（Flush 后真正落盘）</li></ol><p>而<strong>段合并</strong>则是在这套机制运行过程中，持续清理”逻辑删除”留下的存储碎片，维持系统长期运行的健康度。</p><p>理解了这套机制，再回头看”为什么 ES 是近实时搜索”和”为什么 GET 操作却是实时的”，答案就很清晰了：<strong>两者依赖的是完全不同的数据通路</strong>——前者依赖 Refresh 后的段，后者依赖 Translog 本身。这也是 ES 设计中”用合适的工具做合适的事”这一工程哲学的典型体现。</p>]]>
    </content>
    <id>https://w-li-you.github.io/2026/03/05/es-near-realtime-search-crud/</id>
    <link href="https://w-li-you.github.io/2026/03/05/es-near-realtime-search-crud/"/>
    <published>2026-03-04T16:00:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>本文是 ES 存储引擎系列的第二篇，承接<a href="/2026/02/16/es-segment-commitpoint-translog/">上一篇关于段、提交点、Translog 的介绍</a>，详细拆解”写入确认→Refresh→Flush→段合并”的完整生命周期，并解释为什么 ES 需要同时支持”近实时搜索”和”实时 CRUD”两套机制。</p>
</blockquote>]]>
    </summary>
    <title>Elasticsearch 近实时搜索与实时 CRUD 操作机制</title>
    <updated>2026-07-01T13:04:58.891Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="管理" scheme="https://w-li-you.github.io/categories/%E7%AE%A1%E7%90%86/"/>
    <category term="管理" scheme="https://w-li-you.github.io/tags/%E7%AE%A1%E7%90%86/"/>
    <category term="华为" scheme="https://w-li-you.github.io/tags/%E5%8D%8E%E4%B8%BA/"/>
    <category term="绩效管理" scheme="https://w-li-you.github.io/tags/%E7%BB%A9%E6%95%88%E7%AE%A1%E7%90%86/"/>
    <content>
      <![CDATA[<blockquote><p>华为的管理逻辑其实很简单，就是”价值创造—价值评价—价值分配”的闭环循环。本文梳理华为绩效管理的核心精髓、关键落地机制及激励体系设计思路。</p></blockquote><a id="more"></a><h2 id="一、核心底层逻辑：价值链循环"><a href="#一、核心底层逻辑：价值链循环" class="headerlink" title="一、核心底层逻辑：价值链循环"></a>一、核心底层逻辑：价值链循环</h2><p>华为管理的本质是”价值创造—价值评价—价值分配”的闭环，三个环节环环相扣、缺一不可：</p><table><thead><tr><th>环节</th><th>通俗理解</th><th>核心</th></tr></thead><tbody><tr><td><strong>价值创造</strong></td><td>做大蛋糕</td><td>让所有人聚焦客户需求，实实在在创造价值，不养闲人、不允许躺平</td></tr><tr><td><strong>价值评价</strong></td><td>论功</td><td>最关键的一步，承上启下，核心是公平公正。评价不好，整个循环就会断档</td></tr><tr><td><strong>价值分配</strong></td><td>行赏</td><td>多劳多得，与价值评价结果直接挂钩，激励持续创造价值</td></tr></tbody></table><blockquote><p>感悟：学华为不可盲目照搬制度，需吃透价值链循环逻辑，结合企业实际调整。企业驱动员工奋斗，核心是做好利益牵引，让努力有回报。</p></blockquote><hr><h2 id="二、绩效管理核心精髓"><a href="#二、绩效管理核心精髓" class="headerlink" title="二、绩效管理核心精髓"></a>二、绩效管理核心精髓</h2><h3 id="五不看，只看责任与贡献"><a href="#五不看，只看责任与贡献" class="headerlink" title="五不看，只看责任与贡献"></a>五不看，只看责任与贡献</h3><p>不看资历、学历、能力、潜力、态度，仅以<strong>当期责任履行情况和实际贡献</strong>为评价标准，杜绝”光说不做””靠资历混日子”。</p><blockquote><p>补充：不是说华为没人情味。对于员工的历史贡献，会通过升职、加薪、配股等方式回馈；只是当期绩效评价只看当下表现，这样才公平。</p></blockquote><h3 id="分层分级，比例控制"><a href="#分层分级，比例控制" class="headerlink" title="分层分级，比例控制"></a>分层分级，比例控制</h3><p>同一岗位、同一级别的员工放在一起评比，不跨层级对比。同时严格控制绩效比例：</p><table><thead><tr><th>等级</th><th>比例</th></tr></thead><tbody><tr><td>A 类（优秀）</td><td>不超过 15%</td></tr><tr><td>B+ 类（良好）</td><td>35% 左右</td></tr><tr><td>B 类（正常）</td><td>40%</td></tr><tr><td>C 类（待改进）</td><td>5%–10%</td></tr></tbody></table><h3 id="三个实用知识点"><a href="#三个实用知识点" class="headerlink" title="三个实用知识点"></a>三个实用知识点</h3><ol><li>绩效管理不是要让所有人满意，主管只要做到”<strong>公平公正、激励希望</strong>“八个字就够了；</li><li>主管的核心能力是<strong>绩效诊断</strong>，不是简单打分——找出员工绩效不好的根本原因，帮其明确改进方向；</li><li>绩效管理的核心是”<strong>做大蛋糕</strong>“，不是”内部内卷”，不是比谁加班更多。</li></ol><hr><h2 id="三、关键落地机制"><a href="#三、关键落地机制" class="headerlink" title="三、关键落地机制"></a>三、关键落地机制</h2><p>华为靠三大机制确保价值评价公平公正，杜绝黑箱操作：</p><table><thead><tr><th>机制</th><th>内容</th></tr></thead><tbody><tr><td><strong>公开透明</strong></td><td>绩效目标、员工自评、主管评语、绩效等级全员可见——“阳光是最好的杀毒剂”</td></tr><tr><td><strong>鼓励申诉</strong></td><td>每个周期主动开通申诉通道，申诉成功可调整绩效，且会影响主管绩效，倒逼主管公平打分</td></tr><tr><td><strong>内部人才市场</strong></td><td>员工换部门无需当前主管批准，找到下家即可走；某部门大量员工流失即说明主管管理有问题</td></tr></tbody></table><blockquote><p>华为绩效申诉率仅千分之 1.6，离职率约 8%（主动淘汰 5%、主动离职 3%），处于高科技行业低位，印证了机制的有效性。</p></blockquote><hr><h2 id="四、激励体系：物质-非物质双轮驱动"><a href="#四、激励体系：物质-非物质双轮驱动" class="headerlink" title="四、激励体系：物质 + 非物质双轮驱动"></a>四、激励体系：物质 + 非物质双轮驱动</h2><h3 id="物质激励：低固定、高弹性，拉开差距"><a href="#物质激励：低固定、高弹性，拉开差距" class="headerlink" title="物质激励：低固定、高弹性，拉开差距"></a>物质激励：低固定、高弹性，拉开差距</h3><p>固定工资只占 40%，剩余 60% 是与绩效直接挂钩的奖金。同一岗位同一级别，A 类员工年收入约是 B 类的 2.8 倍（目标 3–5 倍）。</p><blockquote><p>核心逻辑：固定工资不用太高，避免员工躺平；浮动奖金要足够有吸引力，让奋斗者拿到超额回报。</p></blockquote><h3 id="非物质激励：愿景-机会-荣誉"><a href="#非物质激励：愿景-机会-荣誉" class="headerlink" title="非物质激励：愿景 + 机会 + 荣誉"></a>非物质激励：愿景 + 机会 + 荣誉</h3><ul><li><strong>愿景使命激励</strong>：将员工工作与中国科技崛起绑定，激发使命感；</li><li><strong>机会激励</strong>：奋斗者优先获得发展机会（干部选拔四优先、任职资格体系、蒙哥马利计划）；</li><li><strong>荣誉激励</strong>：金牌奖、明日之星奖等，注重仪式感，让付出被看见。</li></ul><hr><h2 id="五、核心认知与避坑点"><a href="#五、核心认知与避坑点" class="headerlink" title="五、核心认知与避坑点"></a>五、核心认知与避坑点</h2><p><strong>三个核心价值观不能丢：</strong> “以客户为中心”（价值创造原则）、”以奋斗为本”（价值分配原则）、”责任结果导向”（价值评价原则）。</p><p><strong>两个常见误区要避开：</strong></p><ol><li>盲目照搬华为制度，忽略自身实际（中小企业照搬复杂机制只会增加成本）；</li><li>把绩效搞成内部内卷，比谁加班多、比谁更惨。</li></ol><p><strong>文化落地不是靠背诵心得：</strong> 真正的文化落地，是通过机制让员工知道、理解、认同，最后自觉去做。</p><hr><h2 id="六、延伸思考：OKR-与-PBC-的差异"><a href="#六、延伸思考：OKR-与-PBC-的差异" class="headerlink" title="六、延伸思考：OKR 与 PBC 的差异"></a>六、延伸思考：OKR 与 PBC 的差异</h2><p>华为针对<strong>高不确定性岗位</strong>（研发、创新业务）采用 OKR，针对<strong>确定性岗位</strong>（行政、运维、成熟销售）采用 PBC：</p><table><thead><tr><th>维度</th><th>OKR</th><th>PBC</th></tr></thead><tbody><tr><td>导向</td><td>目标引领，挑战高目标，允许试错</td><td>结果落地，完成既定责任</td></tr><tr><td>与薪酬关系</td><td>不直接绑定</td><td>直接挂钩</td></tr><tr><td>灵活性</td><td>目标可动态调整</td><td>目标一旦确定基本不调整</td></tr><tr><td>评价方式</td><td>侧重自我驱动和过程</td><td>侧重结果和责任考核</td></tr></tbody></table><p><strong>企业选择工具的考虑因素：</strong> 岗位不确定性（最核心）、企业发展阶段、管理成熟度、激励导向。</p><hr><h2 id="七、中小企业能否照搬”低固定、高弹性”"><a href="#七、中小企业能否照搬”低固定、高弹性”" class="headerlink" title="七、中小企业能否照搬”低固定、高弹性”"></a>七、中小企业能否照搬”低固定、高弹性”</h2><p><strong>不适合直接照搬</strong>，核心原因：</p><ol><li><strong>成本承受能力不足</strong>：中小企业盈利不稳定、现金流紧张，业务淡季奖金大幅减少会导致员工批量离职；</li><li><strong>绩效体系不完善</strong>：高弹性薪酬需公平精准的评价体系支撑，评价不公只会引发不满；</li><li><strong>人才吸引力不足</strong>：品牌与发展空间不及华为，低固定工资难以吸引和留住核心人才。</li></ol><blockquote><p><strong>建议</strong>：中小企业可借鉴其核心逻辑，调整固浮比例（固定 60%–70%、浮动 30%–40%），兼顾员工安全感与激励效果。</p></blockquote><hr><h2 id="八、总结"><a href="#八、总结" class="headerlink" title="八、总结"></a>八、总结</h2><blockquote><p>华为绩效管理与激励体系的核心，是通过”价值创造—价值评价—价值分配”闭环，实现”利益牵引 + 使命驱动”：以责任结果导向保障公平，以低固定高弹性薪酬拉开激励差距，以愿景、机会、荣誉唤醒使命感，最终推动全员聚焦客户价值，形成”奋斗者有回报、躺平者被淘汰”的良性循环。</p></blockquote>]]>
    </content>
    <id>https://w-li-you.github.io/2026/02/25/huawei-performance-incentive/</id>
    <link href="https://w-li-you.github.io/2026/02/25/huawei-performance-incentive/"/>
    <published>2026-02-24T16:00:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>华为的管理逻辑其实很简单，就是”价值创造—价值评价—价值分配”的闭环循环。本文梳理华为绩效管理的核心精髓、关键落地机制及激励体系设计思路。</p>
</blockquote>]]>
    </summary>
    <title>华为绩效管理与激励体系学习总结</title>
    <updated>2026-07-01T11:59:33.769Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="AI编程" scheme="https://w-li-you.github.io/categories/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="AI编程" scheme="https://w-li-you.github.io/tags/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="个人总结" scheme="https://w-li-you.github.io/tags/%E4%B8%AA%E4%BA%BA%E6%80%BB%E7%BB%93/"/>
    <category term="Spec Coding" scheme="https://w-li-you.github.io/tags/Spec-Coding/"/>
    <content>
      <![CDATA[<h1 id="Spec-Coding（规约驱动开发）·-个人总结"><a href="#Spec-Coding（规约驱动开发）·-个人总结" class="headerlink" title="Spec Coding（规约驱动开发）· 个人总结"></a>Spec Coding（规约驱动开发）· 个人总结</h1><blockquote><p>看了 spec-kit 介绍 + 规约驱动相关讨论，对照自己工作流后的理解 · 2026-07-03</p></blockquote><hr><a id="more"></a><h2 id="为什么跟-AI-越聊越乱"><a href="#为什么跟-AI-越聊越乱" class="headerlink" title="为什么跟 AI 越聊越乱"></a>为什么跟 AI 越聊越乱</h2><p>典型场景：「帮我加登录」→「密码要加密」→「失败要有提示」→ 改到第三轮注册接口被动了。</p><p>直觉怪模型不够聪明。<strong>真相是输入就是碎的</strong>——AI 每次只看到这一句话 + 眼前上下文，做第五步时可能忘了第一步为什么那么设计。你和 AI 之间缺一份<strong>双方都认可的对齐物</strong>。</p><p>Vibe Coding 爽在不用写文档，适合小玩具、一次性脚本、周末 demo。正经项目、要长期维护的，口头一句句喂，就像跟外包说需求——双方都没有完整图。</p><hr><h2 id="Spec-Coding-是什么"><a href="#Spec-Coding-是什么" class="headerlink" title="Spec Coding 是什么"></a>Spec Coding 是什么</h2><p><strong>先把要做成什么样讲清楚，再让 AI 动手。</strong></p><p>不是写一份死合同，而是分台阶、每阶停一下对一次。任何一步发现前面想岔了，随时回去改——规约是<strong>活的共识</strong>，不是瀑布式签字定死。</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">需求（做什么、为什么，不谈技术）</span><br><span class="line">    ↓</span><br><span class="line">方案（用什么技术、怎么架构）</span><br><span class="line">    ↓</span><br><span class="line">任务（拆成可独立执行的活）</span><br><span class="line">    ↓</span><br><span class="line">实现（照着任务清单写代码）</span><br></pre></td></tr></table></figure><table><thead><tr><th></th><th>Vibe Coding</th><th>Spec Coding</th></tr></thead><tbody><tr><td>步骤</td><td>四步糊在一起</td><td>四步分开，每步有产物</td></tr><tr><td>纠错</td><td>代码写完才发现方向错</td><td>第一步就能发现理解偏差</td></tr><tr><td>产物</td><td>碎片对话</td><td>可检查、可修改的文档</td></tr></tbody></table><hr><h2 id="spec-kit：把流程做成斜杠命令"><a href="#spec-kit：把流程做成斜杠命令" class="headerlink" title="spec-kit：把流程做成斜杠命令"></a>spec-kit：把流程做成斜杠命令</h2><p>GitHub 官方的 spec-kit 把上面四步封装成 Skill，装在 <code>.claude/skills/</code> 下：</p><table><thead><tr><th>命令</th><th>干什么</th></tr></thead><tbody><tr><td><code>/speckit-constitution</code></td><td>项目铁律（如「所有接口写测试」）</td></tr><tr><td><code>/speckit-specify</code></td><td><strong>只写需求，不提技术</strong></td></tr><tr><td><code>/speckit-plan</code></td><td>基于需求定技术方案</td></tr><tr><td><code>/speckit-tasks</code></td><td>拆任务清单</td></tr><tr><td><code>/speckit-implement</code></td><td>按任务实现</td></tr></tbody></table><p>兜底：</p><table><thead><tr><th>命令</th><th>什么时候用</th></tr></thead><tbody><tr><td><code>/speckit-clarify</code></td><td>specify 后、plan 前——把模糊点问清</td></tr><tr><td><code>/speckit-analyze</code></td><td>tasks 后、implement 前——需求/方案/任务交叉比对</td></tr></tbody></table><p><strong>关键细节</strong>：Skill 是 Claude Code <strong>启动时</strong>扫描的，必须 <code>cd</code> 进项目目录再开 <code>claude</code>，斜杠命令才会出现。</p><p>安装：<code>uv tool install specify-cli --from git+https://github.com/github/spec-kit.git</code>，然后 <code>specify init &lt;项目名&gt; --integration claude</code>。</p><hr><h2 id="和标准瀑布的区别"><a href="#和标准瀑布的区别" class="headerlink" title="和标准瀑布的区别"></a>和标准瀑布的区别</h2><table><thead><tr><th></th><th>瀑布</th><th>规约驱动</th></tr></thead><tbody><tr><td>文档</td><td>签字定死，改要走变更</td><td>随时改，AI 几秒重生</td></tr><tr><td>节奏</td><td>一次定死扛着走</td><td>边走边对齐</td></tr></tbody></table><p>表面都是分阶段，内核完全不同——规约是橡皮泥，不是石头。</p><p><strong>选型标准</strong>：这东西打不打算<strong>长期维护、持续加功能</strong>？是 → Spec；几十行跑一次就扔 → Vibe 一把梭。</p><hr><h2 id="和我自己的工作流：本质一样，工具不同"><a href="#和我自己的工作流：本质一样，工具不同" class="headerlink" title="和我自己的工作流：本质一样，工具不同"></a>和我自己的工作流：本质一样，工具不同</h2><p>我没直接用 spec-kit，但大需求走的是同一套逻辑：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">/grill-with-docs  ≈  constitution + specify + clarify（压力测试 + 对齐边界）</span><br><span class="line">/to-prd           ≈  plan（技术方案 + 验收标准）</span><br><span class="line">/to-issues        ≈  tasks（垂直切片 Issue）</span><br><span class="line">/implement        ≈  implement</span><br><span class="line">/review           ≈  人工 + AI 验收</span><br></pre></td></tr></table></figure><p>区别是我用<strong>自定义 Skills</strong> 而不是 spec-kit 默认模板，Grill 阶段会读代码库、写 ADR，比纯 spec-kit 更重「领域建模」。</p><p>spec-kit 的 <code>/speckit-specify</code> 强调<strong>需求阶段零技术词</strong>——这点我认同，也是性价比最高的一次检查：花 2 分钟读 spec，省 2 小时返工。</p><hr><h2 id="实操教训"><a href="#实操教训" class="headerlink" title="实操教训"></a>实操教训</h2><ol><li><strong>specify 只谈需求</strong>——「React + SQLite」留到 plan</li><li><strong>每步产物亲自过</strong>——不对当场改，别攒到 implement</li><li><strong>大项目分阶段 implement</strong>——别一条命令从头撸到尾；上下文太长会顾此失彼</li><li><strong>implement 前一行代码都没有是正常的</strong>——到 tasks 步还在规划，说明做对了</li></ol><p>有人用 spec-kit 做看板 demo，10 分钟跑通——我信小 demo 可以，但生产级项目别指望一次 <code>/speckit-implement</code> 搞定。</p><hr><h2 id="和-MewCode-Agent-项目的关联"><a href="#和-MewCode-Agent-项目的关联" class="headerlink" title="和 MewCode Agent 项目的关联"></a>和 MewCode Agent 项目的关联</h2><p>MewCode Agent 虽没用 spec-kit，但文档结构也是：</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">spec.md → plan.md → task.md → checklist.md → 代码</span><br></pre></td></tr></table></figure><p>让 AI 写代码前先把规划做满——这和 spec-kit 哲学一致，只是文件命名不同。</p><hr><h2 id="我的判断"><a href="#我的判断" class="headerlink" title="我的判断"></a>我的判断</h2><p>AI 时代瓶颈从「会不会写代码」转向<strong>能不能把事情讲清楚</strong>。Spec Coding 的价值不是文档本身，是把「先想清楚再写」从废话变成<strong>绕不过去的工序</strong>。</p><table><thead><tr><th>场景</th><th>我选</th></tr></thead><tbody><tr><td>改 Bug、小接口、脚本</td><td>Vibe 或单会话 <code>/implement</code></td></tr><tr><td>跨模块、要维护、有架构决策</td><td>Grill → PRD → Issues → Implement</td></tr></tbody></table><p>规约驱动真正值钱的是<strong>对齐成本前置</strong>——第一步发现理解偏差，比 implement 完返工便宜一个数量级。</p><hr><h2 id="待办"><a href="#待办" class="headerlink" title="待办"></a>待办</h2><ul><li><input disabled="" type="checkbox"> 挑一个 repo 用 spec-kit 完整跑一遍，和我的 Skills 流程对比差异</li><li><input disabled="" type="checkbox"> constitution 级铁律（测试、安全）是否该单独文件化</li><li><input disabled="" type="checkbox"> 大需求 implement 继续一 Issue 一会话，别合并成 mega-session</li></ul>]]>
    </content>
    <id>https://w-li-you.github.io/2026/02/22/spec-coding-personal-notes/</id>
    <link href="https://w-li-you.github.io/2026/02/22/spec-coding-personal-notes/"/>
    <published>2026-02-21T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h1 id="Spec-Coding（规约驱动开发）·-个人总结"><a href="#Spec-Coding（规约驱动开发）·-个人总结" class="headerlink" title="Spec Coding（规约驱动开发）· 个人总结"></a>Spec Coding（规约驱动开发）· 个人总结</h1><blockquote>
<p>看了 spec-kit 介绍 + 规约驱动相关讨论，对照自己工作流后的理解 · 2026-07-03</p>
</blockquote>
<hr>]]>
    </summary>
    <title>Spec Coding（规约驱动开发）· 个人总结</title>
    <updated>2026-07-05T15:33:40.253Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="中间件" scheme="https://w-li-you.github.io/categories/%E4%B8%AD%E9%97%B4%E4%BB%B6/"/>
    <category term="Elasticsearch" scheme="https://w-li-you.github.io/tags/Elasticsearch/"/>
    <category term="分布式系统" scheme="https://w-li-you.github.io/tags/%E5%88%86%E5%B8%83%E5%BC%8F%E7%B3%BB%E7%BB%9F/"/>
    <content>
      <![CDATA[<blockquote><p>本文是 ES 存储引擎系列的第一篇，梳理段（Segment）、提交点（Commit Point）、Translog 三个核心概念，它们是理解 ES 近实时搜索与实时 CRUD 机制的基础。</p></blockquote><a id="more"></a><h2 id="写在前面"><a href="#写在前面" class="headerlink" title="写在前面"></a>写在前面</h2><p>ES 基于 <strong>Lucene</strong> 构建，并在 Lucene 之上引入了<strong>提交点（Commit Point）</strong>这一概念——一个列出了所有已知段的文件。理解 ES 的存储机制，本质上就是理解”段 + 提交点 + Translog”这三者如何协同工作，在<strong>性能</strong>与<strong>数据安全</strong>之间做平衡。</p><pre class="mermaid">graph LR    A[&quot;内存缓冲区&lt;br&gt;In-memory Buffer&quot;] --&gt;|Refresh| B[&quot;段 Segment&lt;br&gt;不可变倒排索引&quot;]    A --&gt;|实时追加| C[&quot;Translog&lt;br&gt;事务日志&quot;]    B --&gt;|Flush &#x2F; fsync| D[&quot;磁盘&quot;]    C --&gt;|Flush 后清空| D    D --&gt; E[&quot;提交点 Commit Point&lt;br&gt;segments_N&quot;]    E --&gt;|引用| B</pre><h2 id="一、段（Segment）"><a href="#一、段（Segment）" class="headerlink" title="一、段（Segment）"></a>一、段（Segment）</h2><h3 id="1-1-什么是段"><a href="#1-1-什么是段" class="headerlink" title="1.1 什么是段"></a>1.1 什么是段</h3><p>段是 <strong>Lucene 索引的基础构建模块</strong>，是一个<strong>不可变的倒排索引子集</strong>。</p><ol><li>一个完整的 Lucene 索引（对应 ES 里面的一个<strong>分片</strong>）是由多个段组成的。</li><li>每个段本身是一个完整的、独立的倒排索引，包含了索引中一部分文档的数据（词项字典、倒排列表等）。</li><li>段<strong>一旦创建，就是不可变的</strong>（无法修改一个已存在的段）。</li></ol><div class="note info"><p><strong>类比理解</strong>：可以把”分片”理解为一本书，把每个”段”理解为书里的一个独立章节。每次写入新内容不是去修改已有章节，而是新增一个章节；要找一段内容时，需要把所有章节都翻一遍（搜索时合并多个段的结果）。章节积累多了就需要”合订”（段合并），把多个小章节整理成一个大章节，提升翻阅效率。</p></div><h3 id="1-2-查看段信息"><a href="#1-2-查看段信息" class="headerlink" title="1.2 查看段信息"></a>1.2 查看段信息</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看所有索引的段信息</span></span><br><span class="line">GET /_cat/segments?v</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看特定索引的段信息（按文档数排序）</span></span><br><span class="line">GET /_cat/segments/my_index?v&amp;s=docs:desc</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看段的详细信息</span></span><br><span class="line">GET /my_index/_segments</span><br></pre></td></tr></table></figure><p><strong>字段说明：</strong></p><table><thead><tr><th>字段</th><th>说明</th></tr></thead><tbody><tr><td><code>index</code></td><td>索引名称</td></tr><tr><td><code>shard</code></td><td>分片编号</td></tr><tr><td><code>prirep</code></td><td>表示是主分片（p）还是副本分片（r）</td></tr><tr><td><code>ip</code></td><td>节点 IP 地址</td></tr><tr><td><code>segment</code></td><td>段名称</td></tr><tr><td><code>generation</code></td><td>段代编号，数字越大表示段越新</td></tr><tr><td><code>docs.count</code></td><td>该段中包含的文档数（未删除的）</td></tr><tr><td><code>docs.deleted</code></td><td>该段中标记为删除的文档数</td></tr><tr><td><code>size</code></td><td>段磁盘大小</td></tr><tr><td><code>size.memory</code></td><td>段在内存中的大小（单位字节）</td></tr><tr><td><code>committed</code></td><td>是否已提交（true 表示已提交，即已持久化）</td></tr><tr><td><code>searchable</code></td><td>是否可搜索（true 表示可搜索）</td></tr><tr><td><code>version</code></td><td>Lucene 版本</td></tr><tr><td><code>compound</code></td><td>是否为复合文件（true 表示段文件被合并为一个文件）</td></tr></tbody></table><div class="note info"><p><strong>实用排查技巧</strong>：当索引出现性能下降时，<code>GET /_cat/segments/my_index?v&amp;s=docs.deleted:desc</code> 可以快速定位”删除文档比例过高”的段——<code>docs.deleted</code> 远大于 <code>docs.count</code> 的段，往往是触发段合并、释放磁盘空间的优先目标。</p></div><h3 id="1-3-不可变性的价值"><a href="#1-3-不可变性的价值" class="headerlink" title="1.3 不可变性的价值"></a>1.3 不可变性的价值</h3><p>段的不可变性看似”浪费”（每次写入都要新建段、定期合并），但这个设计选择带来了四个关键收益：</p><h4 id="①-不需要锁"><a href="#①-不需要锁" class="headerlink" title="① 不需要锁"></a>① 不需要锁</h4><p>读写无需锁，因为不用担心数据在读取时被修改，极大提升了搜索的并发性能。写入不阻塞读取——当新的段被创建时，现有的段不会被修改，搜索可以继续在旧的段上进行，直到新的段准备好并被<strong>原子性地</strong>切换进去。</p><div class="note info"><p><strong>原子性的切换</strong>：当一个新的段通过 Refresh 操作创建完成后，它被打开并加入到当前索引的可搜索段集合里面，这个加入操作是原子的——对于搜索请求来讲，要么完全看不到这个新段，要么完全看到这个新段，基于提交点机制实现。</p></div><h4 id="②-内核文件系统缓存友好"><a href="#②-内核文件系统缓存友好" class="headerlink" title="② 内核文件系统缓存友好"></a>② 内核文件系统缓存友好</h4><p>这是段设计带来的最大性能优势之一。一旦一个段文件被操作系统加载到文件系统缓存（page cache）中，由于它永远不会改变，可以一直留在那里。后续的搜索请求就可以直接在内存的缓存中进行，避免了昂贵的磁盘 I/O 操作。</p><h4 id="③-过滤器缓存等长期有效"><a href="#③-过滤器缓存等长期有效" class="headerlink" title="③ 过滤器缓存等长期有效"></a>③ 过滤器缓存等长期有效</h4><p>对于过滤器缓存（Filter Cache）这样的缓存，因为段永远不会改变，这个缓存项永远有效，直到这个段被合并或删除——这避免了在每次数据变更时都使大量缓存失效，极大地提升了过滤查询的重复性能。</p><h4 id="④-压缩优势"><a href="#④-压缩优势" class="headerlink" title="④ 压缩优势"></a>④ 压缩优势</h4><p>因为数据是批量写入并保持不变的，压缩算法可以处理更大的、连续的数据块，从而获得更高的压缩率。</p><div class="note warning"><p><strong>不可变性的代价</strong>：正因为段不可变，删除文档不会立即释放磁盘空间，而是先做”逻辑删除”标记；段数量也会随着频繁写入不断膨胀。这些代价由后续的”段合并”机制来偿还——本质上是用后台异步整理的成本，换取了前台读写的高性能，是一种典型的空间换时间、异步换同步的工程权衡。</p></div><h2 id="二、提交点（Commit-Point）"><a href="#二、提交点（Commit-Point）" class="headerlink" title="二、提交点（Commit Point）"></a>二、提交点（Commit Point）</h2><h3 id="2-1-什么是提交点"><a href="#2-1-什么是提交点" class="headerlink" title="2.1 什么是提交点"></a>2.1 什么是提交点</h3><p>提交点是一个文件，它记录了<strong>当前索引中所有已知的、有效的段</strong>，以及它们的信息。</p><ul><li>分片级别，通常被命名为 <code>segments_N</code>（N 递增，如 <code>segments_1</code>、<code>segments_2</code>），类似一个清单，列了”在当前时间点，构成这个完整索引的所有段文件有哪些”。</li></ul><pre class="mermaid">graph TD    A[&quot;Commit Point&quot;] --&gt; B[&quot;段 1&quot;]    A --&gt; C[&quot;段 2&quot;]    A --&gt; D[&quot;段 3&quot;]    B --&gt; E[&quot;Searchable 可搜索&quot;]    C --&gt; E    D --&gt; E</pre><h3 id="2-2-为什么删除文档不会立刻释放空间？"><a href="#2-2-为什么删除文档不会立刻释放空间？" class="headerlink" title="2.2 为什么删除文档不会立刻释放空间？"></a>2.2 为什么删除文档不会立刻释放空间？</h3><p>段是不可变的，每个提交点会包含一个 <code>.del</code> 文件，文件中会列出被删除文档的段信息。被标记删除的文档依然可以被查询到，但是会在最终结果被返回前从结果集中移除。</p><div class="note info"><p>**这是”逻辑删除”而非”物理删除”**：和很多数据库系统（如 MySQL InnoDB 的 MVCC、Kafka 的墓碑消息）的设计思路类似——先打标记、延迟回收，把”真正释放空间”这个相对昂贵的操作，挪到后台异步进行（即段合并），避免阻塞前台的写入/删除请求。</p></div><h3 id="2-3-核心作用"><a href="#2-3-核心作用" class="headerlink" title="2.3 核心作用"></a>2.3 核心作用</h3><h4 id="①-定义一致性视图"><a href="#①-定义一致性视图" class="headerlink" title="① 定义一致性视图"></a>① 定义一致性视图</h4><p>提交点为索引提供了一个在某个时间点上的、完整且一致的视图，确保了：</p><ul><li><strong>搜索一致性</strong>：搜索基于一个固定的段集合进行，不会出现读到一半数据被修改的情况。</li><li><strong>原子性更新</strong>：当新的段被加入或旧的段被合并删除时，是通过创建一个新的提交点来原子性地切换整个索引视图的。</li></ul><h4 id="②-实现故障恢复"><a href="#②-实现故障恢复" class="headerlink" title="② 实现故障恢复"></a>② 实现故障恢复</h4><p>当 Elasticsearch 节点重启时，它会找到最新的提交点文件（<code>segments_N</code>），根据这个提交点，就知道需要将哪些段文件加载到内存中来重建索引。</p><div class="note info"><p><strong>如何找到最新的提交点？</strong></p><p>Lucene 使用一个名为 <code>segments.gen</code> 的辅助文件，这个文件很小，只包含两个 <code>long</code> 整数，指向当前最新提交点的世代号。启动时，系统先读取 <code>segments.gen</code> 找到大概方向，然后会验证 <code>segments_N</code> 文件是否存在和完整，最终确认最新的提交点。</p></div><p>提交点还<strong>提供恢复基线</strong>：这个由提交点定义的索引状态，是 Translog 重放的起点。Translog 中所有发生在这个提交点之后的操作，都会被重新执行。</p><h4 id="③-管理段的生命周期"><a href="#③-管理段的生命周期" class="headerlink" title="③ 管理段的生命周期"></a>③ 管理段的生命周期</h4><p>提交点是段的”生死簿”。一个段只有在被某个提交点引用时，才是”活”的。一旦一个段不再被任何当前或未来提交点引用，它就变成了磁盘上的”僵尸文件”，可以被安全地删除（主要发生在段合并里面）。</p><div class="note info"><p><strong>额外延伸：Lucene 的 <code>IndexDeletionPolicy</code></strong></p><p>Lucene 内部通过 <code>IndexDeletionPolicy</code> 来决定哪些旧的提交点（以及它们引用但不再被新提交点引用的段）可以被物理删除。默认策略 <code>KeepOnlyLastCommitDeletionPolicy</code> 只保留最新一次提交，一旦新提交点生成，旧提交点引用的”僵尸段”就会被清理。ES 在快照备份场景下，会临时通过快照机制”钉住”某些历史提交点，防止被过早清理，这也是为什么长期未完成的快照任务可能导致磁盘空间异常增长的原因之一。</p></div><h2 id="三、Translog（事务日志）"><a href="#三、Translog（事务日志）" class="headerlink" title="三、Translog（事务日志）"></a>三、Translog（事务日志）</h2><h3 id="3-1-什么是-Translog"><a href="#3-1-什么是-Translog" class="headerlink" title="3.1 什么是 Translog"></a>3.1 什么是 Translog</h3><p>Translog 全称 <strong>Transaction Log</strong>，即事务日志。它是一个<strong>仅追加（append-only）</strong>的日志文件，用于记录所有对分片进行的未持久化的操作。</p><ul><li>本质是<strong>写操作日志 / 重做日志（Redo Log）</strong>，为了防止在数据被持久化到 Lucene 段之前，因硬件故障或节点重启导致数据丢失。</li><li>每个分片都有自己的 Translog 文件，按时间顺序记录所有创建、更新、删除文档的操作。</li></ul><div class="note info"><p><strong>类比理解</strong>：Translog 在设计思想上与 MySQL InnoDB 的 <strong>Redo Log</strong>、Kafka 的<strong>日志分段（Log Segment）</strong>非常相似——都是”先写日志再异步落地数据结构”的 WAL（Write-Ahead Log）模式，本质上都是用顺序写盘的低成本，去交换随机更新数据结构（B+树/倒排索引）的高成本，同时保障故障恢复时数据不丢失。</p></div><h3 id="3-2-主要作用"><a href="#3-2-主要作用" class="headerlink" title="3.2 主要作用"></a>3.2 主要作用</h3><h4 id="①-数据安全和故障恢复"><a href="#①-数据安全和故障恢复" class="headerlink" title="① 数据安全和故障恢复"></a>① 数据安全和故障恢复</h4><ul><li><strong>持久化保证</strong>：当一个写操作被确认成功，数据可能不会被立即搜索到（需要 Refresh），但该操作已经被记录在了 Translog 中。</li><li><strong>恢复重放</strong>：在节点故障重启后，Elasticsearch 首先从提交点恢复最后一个持久化的索引状态，然后重放 Translog 中所有之后的操作，从而将分片恢复到故障前的最新状态。</li></ul><h4 id="②-实现实时-GET-操作"><a href="#②-实现实时-GET-操作" class="headerlink" title="② 实现实时 GET 操作"></a>② 实现实时 GET 操作</h4><p>这是 Translog 的一个关键副产品。它使得通过文档 ID 进行 GET、UPDATE、DELETE 操作是<strong>实时</strong>的，即使文档还没有被 Refresh 成可搜索的段（详见本系列第二篇关于”实时 CRUD”的介绍）。</p><h3 id="3-3-配置参数"><a href="#3-3-配置参数" class="headerlink" title="3.3 配置参数"></a>3.3 配置参数</h3><table><thead><tr><th>参数名称</th><th>描述</th><th>默认值</th><th>建议与说明</th></tr></thead><tbody><tr><td><code>index.translog.durability</code></td><td>持久化策略</td><td><code>request</code></td><td><code>request</code>：每个写请求都执行 fsync，最安全但性能影响大。<code>async</code>：异步持久化，性能更好，但故障时可能丢失数据</td></tr><tr><td><code>index.translog.sync_interval</code></td><td><code>async</code> 模式下，Translog 刷盘的时间间隔</td><td><code>5s</code></td><td>增大此值（如 <code>120s</code>）可减少磁盘 I/O，提升性能，但会增加数据丢失的风险</td></tr><tr><td><code>index.translog.flush_threshold_size</code></td><td>Translog 触发 flush 的最大大小</td><td><code>512mb</code></td><td>增大此值（如 <code>1gb</code>）可减少 flush 和段合并的频率，提升写入性能，但会增加故障恢复时间</td></tr><tr><td><code>index.translog.flush_threshold_period</code></td><td>触发 flush 的最大时间间隔</td><td><code>30m</code></td><td>即使 Translog 未达大小阈值，超过此时间也会触发 flush</td></tr><tr><td><code>index.translog.retention.size</code></td><td>为支持操作恢复，保留的 Translog 文件总大小</td><td><code>512mb</code></td><td>即使 Translog 中的操作已经被包含在 Lucene 的提交点（已 flush 到磁盘），ES 仍会保留这些 Translog 文件以便恢复使用，超过此大小旧文件将被删除</td></tr><tr><td><code>index.translog.retention.age</code></td><td>Translog 文件的最长保留时间</td><td><code>12h</code></td><td>超过这个时间的 Translog 文件将被删除</td></tr></tbody></table><h3 id="3-4-调优建议"><a href="#3-4-调优建议" class="headerlink" title="3.4 调优建议"></a>3.4 调优建议</h3><div class="note warning"><p><strong>追求极致写入速度</strong>：如果业务能容忍在发生故障时丢失少量数据（例如有手段进行补录），可以采用异步（<code>async</code>）持久化策略，并适当调大 <code>sync_interval</code>（如 120 秒）和 <code>flush_threshold_size</code>（如 1GB）。这可以显著降低磁盘 I/O，是影响写入速度的最大因素。</p><p><strong>保证数据可靠性</strong>：如果系统对数据安全要求很高，则应坚持使用默认的请求（<code>request</code>）持久化策略，确保每次写请求都持久化到磁盘。</p></div><div class="note info"><p><strong>进一步延伸：<code>retention.size</code> / <code>retention.age</code> 存在的意义</strong></p><p>这两个参数容易被忽略，但在<strong>副本分片恢复</strong>场景中很关键：当一个副本分片短暂离线后重新加入集群，ES 优先尝试用”基于序列号的增量恢复”（Sequence-Number-based Recovery）——即只重放该副本掉线期间主分片 Translog 中新增的操作，而不是全量复制整个分片数据。这种增量恢复能否成功，取决于主分片的 Translog 是否还保留着副本掉线期间的操作记录，这正是 <code>retention.size</code>/<code>retention.age</code> 控制的范围。如果保留的 Translog 不够（比如副本掉线时间过长，超过了 <code>retention.age</code>），就只能退化为代价高得多的全量恢复（Full Recovery）。因此在网络不稳定、节点经常短暂掉线重连的集群里，适当调大这两个参数能显著提升恢复效率，但代价是占用更多磁盘空间。</p></div><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>段、提交点、Translog 三者共同构成了 ES 存储引擎”高性能 + 高可靠”的基石：</p><ul><li><strong>段</strong>通过不可变性换取了无锁并发、缓存友好、压缩率高等多重收益；</li><li><strong>提交点</strong>为索引提供了原子性切换的一致性视图，同时充当段的生命周期”生死簿”；</li><li><strong>Translog</strong> 作为 WAL 日志，弥补了”数据写入内存 → 真正落盘”之间的时间差，是故障恢复和实时 GET 的基础。</li></ul><p>理解了这三者，再看下一篇”近实时搜索与实时 CRUD 操作机制”，就能更清楚地理解 Refresh、Flush、段合并这些操作分别在解决什么问题。</p>]]>
    </content>
    <id>https://w-li-you.github.io/2026/02/16/es-segment-commitpoint-translog/</id>
    <link href="https://w-li-you.github.io/2026/02/16/es-segment-commitpoint-translog/"/>
    <published>2026-02-15T16:00:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>本文是 ES 存储引擎系列的第一篇，梳理段（Segment）、提交点（Commit Point）、Translog 三个核心概念，它们是理解 ES 近实时搜索与实时 CRUD 机制的基础。</p>
</blockquote>]]>
    </summary>
    <title>Elasticsearch 核心概念：段、提交点与 Translog</title>
    <updated>2026-07-05T15:37:16.168Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="AI编程" scheme="https://w-li-you.github.io/categories/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="AI编程" scheme="https://w-li-you.github.io/tags/AI%E7%BC%96%E7%A8%8B/"/>
    <category term="个人总结" scheme="https://w-li-you.github.io/tags/%E4%B8%AA%E4%BA%BA%E6%80%BB%E7%BB%93/"/>
    <category term="Agent" scheme="https://w-li-you.github.io/tags/Agent/"/>
    <content>
      <![CDATA[<h1 id="AI-编程时代，你的优势是什么-·-个人总结"><a href="#AI-编程时代，你的优势是什么-·-个人总结" class="headerlink" title="AI 编程时代，你的优势是什么 · 个人总结"></a>AI 编程时代，你的优势是什么 · 个人总结</h1><blockquote><p>读了 Anthropic 2026.6 关于 Claude Code 的大规模研究 + 几篇解读后的自己的理解 · 2026-07-03</p></blockquote><hr><a id="more"></a><h2 id="研究在说什么"><a href="#研究在说什么" class="headerlink" title="研究在说什么"></a>研究在说什么</h2><p>Anthropic 分析了约 <strong>40 万次</strong> Claude Code 会话、<strong>23.5 万</strong>用户（2025.10–2026.4），报告名 <em>Agentic coding and persistent returns to expertise</em>。</p><p>核心结论：<strong>决定 Agent 编程成败的， increasingly 是领域专业度，不是编码背景。</strong></p><p>这不是某博主体感，是隐私 preserving 分类器 + 遥测交叉验证的统计结果（分类器读 transcript，不只看 job title）。</p><hr><h2 id="人机分工已经变了"><a href="#人机分工已经变了" class="headerlink" title="人机分工已经变了"></a>人机分工已经变了</h2><p>典型会话里：</p><ul><li><strong>人 ~70% 规划决策</strong>（做什么、什么算完成）</li><li><strong>Claude ~80% 执行决策</strong>（改哪些文件、写什么代码、跑什么命令）</li></ul><p>用户发一条 prompt，Claude 平均链式执行 ~10 个 action、产出 ~2400 词——人决定方向，Agent 填细节。</p><p>「怎么写代码」这块硬功夫 Agent 接走了大头；剩下「做什么」靠的是<strong>对这件事本身的理解</strong>。</p><hr><h2 id="会写代码的护城河还守得住吗？"><a href="#会写代码的护城河还守得住吗？" class="headerlink" title="会写代码的护城河还守得住吗？"></a>会写代码的护城河还守得住吗？</h2><h3 id="各职业成功率（产出代码的会话，verified-success）"><a href="#各职业成功率（产出代码的会话，verified-success）" class="headerlink" title="各职业成功率（产出代码的会话，verified success）"></a>各职业成功率（产出代码的会话，verified success）</h3><table><thead><tr><th>群体</th><th>成功率</th></tr></thead><tbody><tr><td>软件/数学相关职业</td><td><strong>34%</strong></td></tr><tr><td>其他职业</td><td><strong>29%</strong></td></tr><tr><td>差距</td><td><strong>5 个百分点</strong></td></tr></tbody></table><ul><li>十大职业群全部落在软件工程师 <strong>7 个点以内</strong></li><li><strong>管理岗 verified success 甚至略高于软件工程</strong>（可能 partly 因为更愿意在 transcript 里确认完成）</li><li>七个月观察期内，这个 gap <strong>没有缩小也没有扩大</strong>——模型变强了，职业差距没抹平</li></ul><p>整体（含不产代码的会话）：软件相关 ~30%，其他 ~26%。</p><p>结论：<strong>编码背景正在变得 less decisive</strong>，但不是 zero——5pp 差距真实存在，只是远小于直觉预期。</p><hr><h2 id="真正拉开差距的是什么"><a href="#真正拉开差距的是什么" class="headerlink" title="真正拉开差距的是什么"></a>真正拉开差距的是什么</h2><h3 id="同一条-prompt，不同专业度"><a href="#同一条-prompt，不同专业度" class="headerlink" title="同一条 prompt，不同专业度"></a>同一条 prompt，不同专业度</h3><table><thead><tr><th>水平</th><th>每 prompt 触发 action</th><th>每 prompt 产出字数</th></tr></thead><tbody><tr><td>新手</td><td>~5</td><td>~600</td></tr><tr><td>专家</td><td>~12</td><td>~3200</td></tr></tbody></table><p>差在<strong>会不会派活</strong>——跟 Java 语法无关，跟<strong>懂不懂这个领域的门道</strong>直接相关。</p><p>秒杀例子：</p><ul><li>新手：「写个扣库存接口」→ 直接 <code>update set stock = stock - 1</code>，单线程测试 OK</li><li>老手：「Redis 预扣 + Lua 原子扣减 + 热点限流 + 异步落库最终一致」→ 一整套</li></ul><p>差别不在语法，在于懂超卖、击穿、一致性。</p><h3 id="翻车时的差距"><a href="#翻车时的差距" class="headerlink" title="翻车时的差距"></a>翻车时的差距</h3><table><thead><tr><th></th><th>新手</th><th>中级/专家</th></tr></thead><tbody><tr><td>遇麻烦后放弃（abandon）</td><td><strong>19%</strong></td><td><strong>5–7%</strong></td></tr></tbody></table><p>专家也会遇到 AI 瞎写——区别在于<strong>一眼看出哪不对、知道往哪救</strong>。本地全绿不信，上压测；新手本地 OK 就上线，真秒杀超卖。</p><hr><h2 id="得先修炼成专家吗？不用"><a href="#得先修炼成专家吗？不用" class="headerlink" title="得先修炼成专家吗？不用"></a>得先修炼成专家吗？不用</h2><p>verified success 按 expertise 分级：</p><table><thead><tr><th>水平</th><th>verified success</th><th>partial success</th></tr></thead><tbody><tr><td>新手</td><td><strong>15%</strong></td><td>77%</td></tr><tr><td>中级+</td><td><strong>28–33%</strong></td><td>91–92%</td></tr></tbody></table><p><strong>最大跳跃：新手 → 中级</strong>；中级 → 专家曲线平了。</p><p>官方原话：<em>a working grasp of the domain captures most of the benefit, while deep specialization adds only a bit more.</em></p><p>翻译：<strong>及格线很低</strong>。不需要二十年老炮，知道一件正常的活该长什么样、关键约束是什么、做出来对不对，就已经跨过收益最大的坎。</p><hr><h2 id="七个月趋势：Agent-在扛更值钱的活"><a href="#七个月趋势：Agent-在扛更值钱的活" class="headerlink" title="七个月趋势：Agent 在扛更值钱的活"></a>七个月趋势：Agent 在扛更值钱的活</h2><table><thead><tr><th>变化</th><th>数据</th></tr></thead><tbody><tr><td>修 bug 占比</td><td>33% → <strong>19%</strong></td></tr><tr><td>运维/部署</td><td>14% → <strong>21%</strong></td></tr><tr><td>写作 + 数据分析</td><td><del>10% → **</del>20%**</td></tr><tr><td>任务估算价值</td><td>平均 <strong>+27%</strong></td></tr></tbody></table><p>Agent 从「帮你打补丁的小工」→ 能扛端到端部署、数据分析、文档的主力。人顺势从抠 bug → 更靠近「想清楚要什么」。</p><p>截至 2026.4，新手和专家的 success gap <strong>没有因模型进步而收敛</strong>——领域判断力暂时还没被 Agent 替代。</p><hr><h2 id="用好-AI-编程的三件事（全不考编码）"><a href="#用好-AI-编程的三件事（全不考编码）" class="headerlink" title="用好 AI 编程的三件事（全不考编码）"></a>用好 AI 编程的三件事（全不考编码）</h2><table><thead><tr><th>#</th><th>能力</th><th>本质</th></tr></thead><tbody><tr><td>1</td><td><strong>说清问题</strong></td><td>约束、边界、坑——不只说「做什么」</td></tr><tr><td>2</td><td><strong>拆好活</strong></td><td>大需求逐环实现，每环可验收</td></tr><tr><td>3</td><td><strong>会验收</strong></td><td>压测、边界 case、并发；不信本地全绿</td></tr></tbody></table><p>这三件和我工作流完全对齐：Grill 说清 → Issues 拆活 → AI 审查 + 人工审查验收。</p><hr><h2 id="「AI-不能担责」——我的理解"><a href="#「AI-不能担责」——我的理解" class="headerlink" title="「AI 不能担责」——我的理解"></a>「AI 不能担责」——我的理解</h2><p>研究数据支持一个直觉：<strong>AI 能执行，不能为你的业务决策担责。</strong></p><ul><li>34% verified success 意味着 <strong>66% 的会话 strict 意义下不算完全成功</strong>——即使专家也一样</li><li>你必须懂行，才能指方向、拆任务、验结果、在 AI 瞎写时救回来</li><li>护城河不是语法和 API（Agent 比你熟），是<strong>你在某个领域里比 AI 更懂这件事本身</strong></li></ul><p>Non-engineer 29% vs engineer 34% 说明红利不 exclusive 给程序员——<strong>懂业务的人照样能指挥 Agent</strong>。反过来说，只会写 CRUD、不懂业务的程序员，优势在缩小。</p><hr><h2 id="对我工作流的启示"><a href="#对我工作流的启示" class="headerlink" title="对我工作流的启示"></a>对我工作流的启示</h2><table><thead><tr><th>研究结论</th><th>我的应对</th></tr></thead><tbody><tr><td>规划决策主要在人</td><td>Phase 0 Opus Grill，不跳过</td></tr><tr><td>执行 Agent 接</td><td>Phase 1 Sonnet implement，Issue 收窄范围</td></tr><tr><td>专家更会验收</td><td>Phase 2 换 AI 审查 + <strong>人工必过 diff</strong></td></tr><tr><td>新手→中级收益最大</td><td>不必焦虑「要成为全栈专家」，先把负责域吃透</td></tr><tr><td>任务价值在涨</td><td>把时间从抠 bug 转向想清楚要什么</td></tr></tbody></table><p><strong>Spec Coding + 双道审查</strong>，本质上就是在系统化地做「说清、拆活、验收」——研究给的是统计背书，不是新方法论。</p><hr><h2 id="待验证-研究局限"><a href="#待验证-研究局限" class="headerlink" title="待验证 / 研究局限"></a>待验证 / 研究局限</h2><ul><li>分类器读 transcript，不能测「代码上线后是否真的在用」</li><li>expertise 是 task-specific 的——Rust 新手和 reconciliation 专家可以同一个人</li><li>非交互式 usage（CI 里的 Agent）未纳入</li><li>我的体感：partial success 91% 看着高，但「部分成功」离「可 merge 上线」可能还差很远——verified 15–33% 更接近真实交付门槛</li></ul><hr><h2 id="一句话"><a href="#一句话" class="headerlink" title="一句话"></a>一句话</h2><p>同样一个 Claude Code，有人开挂有人骂笨——差在<strong>懂不懂行</strong>，不是会不会写代码。我的优势不是和 AI 比语法，是<strong>比它更懂我要解决的那个问题</strong>，并且<strong>敢为 merge 担责</strong>。</p>]]>
    </content>
    <id>https://w-li-you.github.io/2026/02/08/ai-coding-expertise-advantage/</id>
    <link href="https://w-li-you.github.io/2026/02/08/ai-coding-expertise-advantage/"/>
    <published>2026-02-07T16:00:00.000Z</published>
    <summary>
      <![CDATA[<h1 id="AI-编程时代，你的优势是什么-·-个人总结"><a href="#AI-编程时代，你的优势是什么-·-个人总结" class="headerlink" title="AI 编程时代，你的优势是什么 · 个人总结"></a>AI 编程时代，你的优势是什么 · 个人总结</h1><blockquote>
<p>读了 Anthropic 2026.6 关于 Claude Code 的大规模研究 + 几篇解读后的自己的理解 · 2026-07-03</p>
</blockquote>
<hr>]]>
    </summary>
    <title>AI 编程时代，你的优势是什么 · 个人总结</title>
    <updated>2026-07-05T15:33:40.237Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="读书笔记" scheme="https://w-li-you.github.io/categories/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/"/>
    <category term="读书笔记" scheme="https://w-li-you.github.io/tags/%E8%AF%BB%E4%B9%A6%E7%AC%94%E8%AE%B0/"/>
    <category term="管理" scheme="https://w-li-you.github.io/tags/%E7%AE%A1%E7%90%86/"/>
    <content>
      <![CDATA[<blockquote><p>本篇涵盖第五、六章：管理风格的弹性匹配，以及任务相关成熟度（Task-Relevant Maturity）。</p></blockquote><a id="more"></a><h2 id="五、任务相关成熟度（TRM）"><a href="#五、任务相关成熟度（TRM）" class="headerlink" title="五、任务相关成熟度（TRM）"></a>五、任务相关成熟度（TRM）</h2><p>这是本书最有实操价值的概念之一。格鲁夫指出，管理风格没有绝对的好坏，<strong>适合的才是最好的</strong>。决定管理风格的核心变量是：</p><blockquote><p><strong>任务相关成熟度（Task-Relevant Maturity, TRM）</strong><br>指下属在<strong>特定任务</strong>上的经验、能力和意愿，而非其整体能力水平。</p></blockquote><p>关键点：TRM 是<strong>任务相关的</strong>，不是人相关的。一个 10 年经验的工程师，在做一项全新技术方向的工作时，TRM 可能很低。</p><h3 id="三种管理风格对应三个-TRM-层级"><a href="#三种管理风格对应三个-TRM-层级" class="headerlink" title="三种管理风格对应三个 TRM 层级"></a>三种管理风格对应三个 TRM 层级</h3><table><thead><tr><th>TRM 水平</th><th>对应管理风格</th><th>核心做法</th></tr></thead><tbody><tr><td>低（新手/新任务）</td><td>结构化指令型</td><td>明确告知做什么、怎么做、检查节点</td></tr><tr><td>中（有基础但不稳定）</td><td>双向沟通型</td><td>共同讨论，解释原因，给予支持</td></tr><tr><td>高（熟练且自驱）</td><td>授权型</td><td>给目标，给资源，放手执行</td></tr></tbody></table><h3 id="常见错误"><a href="#常见错误" class="headerlink" title="常见错误"></a>常见错误</h3><ul><li><strong>对高 TRM 员工仍事无巨细</strong>：会让他们感到不被信任，产生挫败感，进而离职。</li><li><strong>对低 TRM 员工过度授权</strong>：等于把他扔进深水区，结果是失败和信心受损。</li></ul><p>在技术团队里，这个模型非常实用：新入职的校招生（低 TRM）需要详细的任务拆解；老员工接手陌生技术方向（中 TRM）需要一起讨论方案；核心老鸟（高 TRM）只需要给清楚目标和边界。</p><hr><h2 id="六、绩效评估：最难开口的对话"><a href="#六、绩效评估：最难开口的对话" class="headerlink" title="六、绩效评估：最难开口的对话"></a>六、绩效评估：最难开口的对话</h2><p>格鲁夫对绩效评估的看法很直接：</p><blockquote><p>“绩效评估是管理者最重要也最容易逃避的职责。”</p></blockquote><h3 id="评估的三个目的"><a href="#评估的三个目的" class="headerlink" title="评估的三个目的"></a>评估的三个目的</h3><ol><li><strong>评价过去表现</strong>：客观描述发生了什么，避免”月晕效应”（一个突出的优点掩盖其他问题）</li><li><strong>提升未来绩效</strong>：给出具体可行的改进方向</li><li><strong>激励</strong>：让员工知道努力有回报</li></ol><h3 id="格式化评估的误区"><a href="#格式化评估的误区" class="headerlink" title="格式化评估的误区"></a>格式化评估的误区</h3><p>他特别批评了”三明治反馈法”（好话-坏话-好话）：表面上温和，实际上让被评估者只记住了两头的好话，忽略了中间的问题。</p><p>更有效的做法：直接、具体、基于事实，不绕弯子。</p><h3 id="对”明星员工”的评估"><a href="#对”明星员工”的评估" class="headerlink" title="对”明星员工”的评估"></a>对”明星员工”的评估</h3><p>很多管理者对高绩效员工只是”点赞”，缺乏实质反馈。格鲁夫认为这是浪费——明星员工同样需要被告知<strong>哪里还有提升空间</strong>，否则就是在阻碍他们成长。</p><hr><h2 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h2><p>TRM 模型给了管理者一个清晰的决策框架：<strong>在授权和指令之间的选择，取决于对方在这件具体事情上的成熟度</strong>，而不是对这个人的整体印象。绩效评估则提醒我们，管理者的职责是说真话，而不是维持表面的和谐。</p>]]>
    </content>
    <id>https://w-li-you.github.io/2026/02/08/grove-high-output-management-3/</id>
    <link href="https://w-li-you.github.io/2026/02/08/grove-high-output-management-3/"/>
    <published>2026-02-07T16:00:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>本篇涵盖第五、六章：管理风格的弹性匹配，以及任务相关成熟度（Task-Relevant Maturity）。</p>
</blockquote>]]>
    </summary>
    <title>《格鲁夫给经理人的第一课》读书笔记（三）：团队成熟度与管理风格</title>
    <updated>2026-07-01T11:45:45.498Z</updated>
  </entry>
  <entry>
    <author>
      <name>李孟瑶</name>
    </author>
    <category term="管理" scheme="https://w-li-you.github.io/categories/%E7%AE%A1%E7%90%86/"/>
    <category term="管理" scheme="https://w-li-you.github.io/tags/%E7%AE%A1%E7%90%86/"/>
    <category term="华为" scheme="https://w-li-you.github.io/tags/%E5%8D%8E%E4%B8%BA/"/>
    <category term="人才管理" scheme="https://w-li-you.github.io/tags/%E4%BA%BA%E6%89%8D%E7%AE%A1%E7%90%86/"/>
    <content>
      <![CDATA[<blockquote><p>任正非对华为人才体系的核心关注点是干部。本文承接<a href="/2025/12/20/huawei-management-strategy/">上篇战略部分</a>，梳理华为管理的底层逻辑”三道”，以及干部选拔、培养、文化建设与激励体系。</p></blockquote><a id="more"></a><h2 id="一、底层逻辑：管理的”三道”"><a href="#一、底层逻辑：管理的”三道”" class="headerlink" title="一、底层逻辑：管理的”三道”"></a>一、底层逻辑：管理的”三道”</h2><p>企业竞争的本质是管理竞争，管理竞争的核心是认知竞争。华为管理的底层逻辑可概括为”三道”：</p><table><thead><tr><th>三道</th><th>内涵</th><th>落地逻辑</th></tr></thead><tbody><tr><td><strong>商道</strong></td><td>以客户为中心，创造顾客为唯一目的</td><td>赚钱只是价值创造后的自然结果；通过共情客户需求形成不可替代的合作关系（如为德国研发下水道基站、为美国农村提供低成本微波通讯）</td></tr><tr><td><strong>天道</strong></td><td>物竞天择，以高淘汰构建危机感</td><td>“高目标、高压力、高淘汰”激活组织活力；每年干部末位淘汰 10%、员工淘汰 5%</td></tr><tr><td><strong>人道</strong></td><td>顺应人性自私，以利益驱动凝聚人心</td><td>建立”正大光明捞好处”的机制，通过利他实现利己，而非考验人性</td></tr></tbody></table><hr><h2 id="二、核心认知误区打破"><a href="#二、核心认知误区打破" class="headerlink" title="二、核心认知误区打破"></a>二、核心认知误区打破</h2><table><thead><tr><th>传统认知</th><th>华为价值导向</th></tr></thead><tbody><tr><td>员工满意度</td><td><strong>重责任，轻满意</strong>——企业与员工本质是利益交换关系</td></tr><tr><td>公平与激励</td><td><strong>效率优先，拒绝平均</strong>——留住”孙悟空”式核心人才</td></tr><tr><td>人性化管理</td><td><strong>奋斗成就价值</strong>——通过奋斗实现个人价值与阶层跨越</td></tr><tr><td>用人理念</td><td><strong>疑人要用，用人要疑</strong>——授权与监督并行，划定红线防腐败</td></tr><tr><td>管理效能</td><td><strong>重有效，轻完美</strong>——“简单有效”，适配比完美更重要</td></tr><tr><td>人才选拔</td><td><strong>选拔为先，培训赋能</strong>——发挥”歪瓜裂枣”式人才的突出优点</td></tr><tr><td>问题与机遇</td><td><strong>聚焦机会，以增长破局</strong>——规模扩大后诸多内部问题会自然化解</td></tr></tbody></table><hr><h2 id="三、干部选拔：实战赛马，四维立标"><a href="#三、干部选拔：实战赛马，四维立标" class="headerlink" title="三、干部选拔：实战赛马，四维立标"></a>三、干部选拔：实战赛马，四维立标</h2><h3 id="核心原则"><a href="#核心原则" class="headerlink" title="核心原则"></a>核心原则</h3><p>“将军是打出来的”，坚持选拔制与淘汰制，通过实战赛马筛选。三大优先原则：</p><ul><li>优先从<strong>成功团队</strong>选干部（沉淀优秀基因）；</li><li>优先从<strong>主攻战场、一线及艰苦地区</strong>选干部（艰苦环境是试金石）；</li><li>优先从<strong>长远发展关键事件</strong>中选干部。</li></ul><p>同时明确”以岗选人，而非以人定岗”，核心看人与岗位的适配度。</p><h3 id="四维选拔标准"><a href="#四维选拔标准" class="headerlink" title="四维选拔标准"></a>四维选拔标准</h3><table><thead><tr><th>维度</th><th>要求</th></tr></thead><tbody><tr><td><strong>品德</strong></td><td>底线要求，通过《商业行为准则》明确红线，违规一票否决</td></tr><tr><td><strong>价值观与使命感</strong></td><td>文化引领基础，关键节点的行为是试金石</td></tr><tr><td><strong>绩效</strong></td><td>必要条件，需进入前 25%</td></tr><tr><td><strong>能力与经验</strong></td><td>以结果为导向，通过”经验地图”聚焦三项核心经验</td></tr></tbody></table><h3 id="后备干部储备"><a href="#后备干部储备" class="headerlink" title="后备干部储备"></a>后备干部储备</h3><p>为每位现任干部配备继任者（继任 1 为即时可接任者，继任 2 为差一项经验的储备者，Two-job away 为高潜人才），通过”有人随时可替代”构建危机感，倒逼现任干部持续奋斗。</p><hr><h2 id="四、干部培养：训战结合，分层锻造"><a href="#四、干部培养：训战结合，分层锻造" class="headerlink" title="四、干部培养：训战结合，分层锻造"></a>四、干部培养：训战结合，分层锻造</h2><p>华为大学以”对内赋能、训战结合”为核心宗旨，对标黄埔军校。四大教学方针：坚持选拔制、训战结合、循环赋能、优秀者培养优秀者（无专业教师，高级干部每年需完成 32 小时授课）。</p><p><strong>从秀才到将军的三阶锻造：</strong></p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">① 秀才变战士：半个月魔鬼训练筛骨干，强化服从、纪律与团队意识</span><br><span class="line">② 战士变班长：训战结合练带队能力，参与铁三角作战</span><br><span class="line">③ 班长变将军：聚焦认知升级，锤炼格局，&quot;神经粗糙、个性坚强&quot;</span><br></pre></td></tr></table></figure><p>坚持”之字形”跨部门轮岗，核心覆盖研发、市场客户经理、财经三大岗位，萃取技术、客户洞察、经营三大核心能力。</p><h3 id="干部三砍：明确分层定位"><a href="#干部三砍：明确分层定位" class="headerlink" title="干部三砍：明确分层定位"></a>干部三砍：明确分层定位</h3><ul><li><strong>高级干部砍手脚</strong>：摒弃事务性干预，聚焦战略布局；</li><li><strong>中层干部砍屁股</strong>：打破部门本位，实现端到端协同；</li><li><strong>基层干部砍脑袋</strong>：强化执行力，聚焦战术落地。</li></ul><h3 id="干部六大责任"><a href="#干部六大责任" class="headerlink" title="干部六大责任"></a>干部六大责任</h3><p>思想导航、捕捉机会、达成目标、抓住主要矛盾、提升效率、赋能团队。领导者最核心的能力是<strong>影响文化的能力</strong>，需以身作则，行胜于言。</p><hr><h2 id="五、文化建设：以故事为载体"><a href="#五、文化建设：以故事为载体" class="headerlink" title="五、文化建设：以故事为载体"></a>五、文化建设：以故事为载体</h2><p><strong>核心文化内核——狼文化：</strong> 敏锐的嗅觉（捕捉机会）、不屈不挠的进攻意识（结果导向）、团队作战（群体奋斗）。配套”狼狈文化”实现平衡——狼负责前端进攻，狈负责后端防守与管理。</p><p><strong>文化落地路径：</strong> 文化深入人心不靠空洞说教，而靠鲜活故事。新员工入职会收到 100 个一线故事。同时强调<strong>持续自我批判</strong>（设立战略蓝军挑战自我）、<strong>以熵减变革对抗衰退</strong>。</p><hr><h2 id="六、激励体系：物质与非物质协同"><a href="#六、激励体系：物质与非物质协同" class="headerlink" title="六、激励体系：物质与非物质协同"></a>六、激励体系：物质与非物质协同</h2><h3 id="激励理论支撑"><a href="#激励理论支撑" class="headerlink" title="激励理论支撑"></a>激励理论支撑</h3><ul><li><strong>马斯洛需求层次</strong>：生理→安全→社交→尊重→自我实现，低层次满足后转向高层次；</li><li><strong>赫兹伯格双因素</strong>：保健因素（如基本工资，不给则不满）vs 激励因素（如认可、荣誉，能点燃斗志）。奖金需拉开差距才能保持激励属性。</li></ul><h3 id="差异化激励设计"><a href="#差异化激励设计" class="headerlink" title="差异化激励设计"></a>差异化激励设计</h3><p>不同群体需求差异显著：新生代重物质、认可与成长，中生代重授权与机会，老员工重尊重与信任，空降兵重成就感与工作家庭平衡。</p><h3 id="激励组合拳"><a href="#激励组合拳" class="headerlink" title="激励组合拳"></a>激励组合拳</h3><ul><li><strong>物质激励</strong>：多重、多次、多维度，涵盖工资、奖金分红、专项补贴，针对艰苦地区增设家属补助；</li><li><strong>非物质激励</strong>：场景化、多元化，包括公开认可、领袖合影、父母颁奖、评选”明日之星”。</li></ul><blockquote><p>激励的终极目标是”三个人干五个人的活，给四个人的钱”，通过科学价值分配撬动更大价值创造。</p></blockquote><hr><h2 id="七、组织与流程能力建设"><a href="#七、组织与流程能力建设" class="headerlink" title="七、组织与流程能力建设"></a>七、组织与流程能力建设</h2><p><strong>人才管理六环节闭环：</strong> 选、用、流、育、激、管，以选拔为核心，坚持”选后再育、以战验才”。建立”无尖双塔”人才金字塔——管理通道与专家通道级别对等、薪酬无差，打破”唯有当官才有出路”的困境。</p><p><strong>分层 KPI：</strong> 绩效结果遵循”战略-组织-个体”解码路径，各部门 KPI 围绕”独特价值创造”设计，权重向主要矛盾倾斜（超过 50%）。</p><p><strong>管理者双重角色：</strong> 管理是”完成目标的执行与平衡”，领导是”点燃团队的追随力”。做到”用兵狠、爱兵切”，刚柔并济。领导者的核心职责是培养接班人——“不培养接班人是对公司最大的不负责任”。</p><hr><h2 id="八、核心逻辑总结"><a href="#八、核心逻辑总结" class="headerlink" title="八、核心逻辑总结"></a>八、核心逻辑总结</h2><blockquote><p>华为管理的底层逻辑可归结为”<strong>价值共生</strong>“——以客户为中心创造价值，以奋斗者为本分配价值，以自我批判和熵减变革保障价值持续创造，以文化凝聚共识。</p></blockquote><p>其核心是对”人性、实战、价值”的深刻把握：正视人性自私，用利益驱动奋斗；坚守实战导向，让干部在战场成长；聚焦客户价值，拒绝形式主义。虽行业不同、场景有别，但其对”实战、人性、价值”的把握，值得所有企业借鉴——但<strong>不可盲目照搬制度，需吃透逻辑，结合企业实际调整</strong>。</p>]]>
    </content>
    <id>https://w-li-you.github.io/2026/01/25/huawei-management-cadre/</id>
    <link href="https://w-li-you.github.io/2026/01/25/huawei-management-cadre/"/>
    <published>2026-01-24T16:00:00.000Z</published>
    <summary>
      <![CDATA[<blockquote>
<p>任正非对华为人才体系的核心关注点是干部。本文承接<a href="/2025/12/20/huawei-management-strategy/">上篇战略部分</a>，梳理华为管理的底层逻辑”三道”，以及干部选拔、培养、文化建设与激励体系。</p>
</blockquote>]]>
    </summary>
    <title>华为管理法学习笔记（下）：干部管理、文化与激励</title>
    <updated>2026-07-01T12:03:33.620Z</updated>
  </entry>
</feed>
