mirror of
https://github.com/tanweai/pua.git
synced 2026-08-30 18:01:52 +08:00
feat(hooks): add pattern-aware failure analysis + de-escalation breakthrough detection
- Upgrade failure-detector.sh from simple counter to pattern-aware state machine - Track error signatures (MD5 hash) for SPINNING/EXPLORING/MIXED classification - Detect SUCCESS after L2+ struggle → trigger flavor-aware de-escalation - Fix false positive: exit_code=0 is now primary signal, text grep is secondary - Record error history in .error_history.jsonl (capped at 10 entries) - Add de-escalation-protocol.md: breakthrough reward + 4-level cognitive reframe - Variable ratio reinforcement: reward only on L2+ breakthrough (not every success) - 14 flavor-specific recognition messages (alibaba→Owner, musk→Algorithm, etc.) - Deep reframe layers: switch perspective → abstraction level → constraints → inversion - Update SKILL.md: integrate de-escalation, pattern analysis, and reframe protocols
This commit is contained in:
+220
-22
@@ -1,6 +1,12 @@
|
||||
#!/bin/bash
|
||||
# PUA PostToolUse hook: detect consecutive Bash failures → inject PUA pressure
|
||||
# Reads hook input JSON from stdin, checks for error signals, escalates pressure.
|
||||
# PUA PostToolUse hook: failure pattern analysis + de-escalation breakthrough detection
|
||||
# Layer 1 of 3-layer detection: collect structured signals, inject pattern data for LLM analysis
|
||||
#
|
||||
# v2: Upgraded from simple counter to pattern-aware state machine
|
||||
# - Tracks error signatures (hash of last N errors) for pattern classification
|
||||
# - Detects SUCCESS after L2+ struggle → triggers de-escalation with flavor-aware recognition
|
||||
# - Injects error history into prompt so LLM can do semantic pattern analysis
|
||||
# - Flavor-specific breakthrough recognition messages
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
@@ -19,9 +25,13 @@ fi
|
||||
|
||||
get_flavor
|
||||
|
||||
COUNTER_FILE="${HOME:-~}/.pua/.failure_count"
|
||||
SESSION_FILE="${HOME:-~}/.pua/.failure_session"
|
||||
mkdir -p "${HOME:-~}/.pua"
|
||||
PUA_DIR="${HOME:-~}/.pua"
|
||||
COUNTER_FILE="${PUA_DIR}/.failure_count"
|
||||
SESSION_FILE="${PUA_DIR}/.failure_session"
|
||||
# v2: error history for pattern analysis
|
||||
ERROR_HISTORY_FILE="${PUA_DIR}/.error_history.jsonl"
|
||||
PEAK_LEVEL_FILE="${PUA_DIR}/.peak_pressure_level"
|
||||
mkdir -p "${PUA_DIR}"
|
||||
|
||||
# Read hook input
|
||||
HOOK_INPUT=$(cat)
|
||||
@@ -32,26 +42,16 @@ if [ "$TOOL_NAME" != "Bash" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Detect failure: check tool_result for error indicators
|
||||
# We check: exit_code in result text, common error patterns
|
||||
# Extract tool result and exit code
|
||||
TOOL_RESULT=$(echo "$HOOK_INPUT" | "${PUA_PY:-python3}" -c "
|
||||
import sys, json
|
||||
data = json.load(sys.stdin)
|
||||
# tool_result can be nested; try common structures
|
||||
result = data.get('tool_result', '')
|
||||
if isinstance(result, dict):
|
||||
result = result.get('content', result.get('text', str(result)))
|
||||
print(str(result)[:2000])
|
||||
" 2>/dev/null || echo "")
|
||||
|
||||
IS_ERROR="false"
|
||||
|
||||
# Check for explicit error signals
|
||||
if echo "$TOOL_RESULT" | grep -qiE 'error|Error|ERROR|exit code [1-9]|Exit code [1-9]|command not found|No such file|Permission denied|FAILED|fatal:|panic:|Traceback|Exception:'; then
|
||||
IS_ERROR="true"
|
||||
fi
|
||||
|
||||
# Check for non-zero exit code in hook input
|
||||
EXIT_CODE=$(echo "$HOOK_INPUT" | "${PUA_PY:-python3}" -c "
|
||||
import sys, json
|
||||
data = json.load(sys.stdin)
|
||||
@@ -62,8 +62,17 @@ else:
|
||||
print(0)
|
||||
" 2>/dev/null || echo "0")
|
||||
|
||||
IS_ERROR="false"
|
||||
|
||||
# Exit code is the PRIMARY signal — it's deterministic and reliable.
|
||||
# Text grep is SECONDARY and only applies when exit_code is non-zero.
|
||||
# This prevents false positives like "0 failed" or "no error" being flagged.
|
||||
if [ "$EXIT_CODE" != "0" ] && [ "$EXIT_CODE" != "" ]; then
|
||||
IS_ERROR="true"
|
||||
elif echo "$TOOL_RESULT" | grep -qiE '^error:|^fatal:|^panic:|Traceback \(most recent|Exception:|command not found|No such file or directory|Permission denied'; then
|
||||
# Only check text patterns when exit_code is 0 but output contains unambiguous error markers
|
||||
# These patterns are anchored (^) or specific enough to avoid false positives
|
||||
IS_ERROR="true"
|
||||
fi
|
||||
|
||||
# Track session: reset counter if new session
|
||||
@@ -73,6 +82,8 @@ STORED_SESSION=""
|
||||
|
||||
if [ "$CURRENT_SESSION" != "$STORED_SESSION" ]; then
|
||||
echo "0" > "$COUNTER_FILE"
|
||||
echo "0" > "$PEAK_LEVEL_FILE"
|
||||
: > "$ERROR_HISTORY_FILE"
|
||||
echo "$CURRENT_SESSION" > "$SESSION_FILE"
|
||||
fi
|
||||
|
||||
@@ -81,28 +92,212 @@ COUNT=0
|
||||
[ -f "$COUNTER_FILE" ] && COUNT=$(cat "$COUNTER_FILE" 2>/dev/null || echo "0")
|
||||
[ -z "$COUNT" ] && COUNT=0
|
||||
|
||||
if [ "$IS_ERROR" = "true" ]; then
|
||||
COUNT=$((COUNT + 1))
|
||||
echo "$COUNT" > "$COUNTER_FILE"
|
||||
else
|
||||
# Success resets the consecutive failure counter
|
||||
# Read peak pressure level reached this session
|
||||
PEAK_LEVEL=0
|
||||
[ -f "$PEAK_LEVEL_FILE" ] && PEAK_LEVEL=$(cat "$PEAK_LEVEL_FILE" 2>/dev/null || echo "0")
|
||||
[ -z "$PEAK_LEVEL" ] && PEAK_LEVEL=0
|
||||
|
||||
# ═══════════════════════════════════════════════════════
|
||||
# v2: DE-ESCALATION — Success after L2+ struggle
|
||||
# ═══════════════════════════════════════════════════════
|
||||
if [ "$IS_ERROR" = "false" ]; then
|
||||
if [ "$COUNT" -ge 3 ] && [ "$PEAK_LEVEL" -ge 2 ]; then
|
||||
# ★ BREAKTHROUGH detected: success after sustained struggle
|
||||
# Record the breakthrough event
|
||||
echo "{\"ts\":$(date +%s),\"event\":\"breakthrough\",\"from_level\":$PEAK_LEVEL,\"after_failures\":$COUNT}" >> "$ERROR_HISTORY_FILE" 2>/dev/null || true
|
||||
|
||||
# Reset pressure state
|
||||
echo "0" > "$COUNTER_FILE"
|
||||
echo "0" > "$PEAK_LEVEL_FILE"
|
||||
|
||||
# Flavor-aware de-escalation recognition
|
||||
case "$PUA_FLAVOR" in
|
||||
alibaba)
|
||||
DE_ESCALATION_MSG="这才是 Owner 该有的样子。3.75 打底。现在复盘一下:刚才卡了 ${COUNT} 次,根因是什么?把正确路径写下来,下次直达。这叫**沉淀方法论**。"
|
||||
;;
|
||||
bytedance)
|
||||
DE_ESCALATION_MSG="结果到位了。ROI 翻正。现在做一件事:把刚才有效的方法提炼成 SOP,写到 memory 里。数据驱动不是说说——你刚经历的 ${COUNT} 次失败就是数据,别浪费。"
|
||||
;;
|
||||
huawei)
|
||||
DE_ESCALATION_MSG="军令状完成。烧不死的鸟是凤凰——你刚证明了自己烧不死。现在按自我批判流程复盘:哪个假设一开始就是错的?哪个应该更早排除?写入经验库。胜则举杯相庆。"
|
||||
;;
|
||||
tencent)
|
||||
DE_ESCALATION_MSG="赛马跑出来了。你赢了这条赛道。现在做灰度验证——确认结果可复现、边界清楚。然后把这套打法沉淀下来,下次小步快跑直接跑通。"
|
||||
;;
|
||||
baidu)
|
||||
DE_ESCALATION_MSG="搜索 + 深挖有效果了。基本盘守住了。现在把搜索路径和关键发现记录下来——简单可依赖的前提是路径可复用。"
|
||||
;;
|
||||
pinduoduo)
|
||||
DE_ESCALATION_MSG="本分做到了。结果出来了就是硬核。现在回头看:${COUNT} 次失败里有多少步是可以砍掉的?极致效率 = 下次零弯路。"
|
||||
;;
|
||||
meituan)
|
||||
DE_ESCALATION_MSG="做难而正确的事,你做到了。猛将发于卒伍——这次卡住就是你的卒伍。现在苦练基本功:把解题路径标准化,下次遇到同类直接套。"
|
||||
;;
|
||||
jd)
|
||||
DE_ESCALATION_MSG="结果拿到了。这才是兄弟该有的执行力。正道成功——过程虽然硬,但路子是对的。现在沉淀下来,让下一个兄弟不用再走这些弯路。"
|
||||
;;
|
||||
xiaomi)
|
||||
DE_ESCALATION_MSG="极致!这次交付够极致。和用户交朋友的前提是你真的在意质量。现在把这个方案的性价比拉满——记录最短路径,下次专注直达。"
|
||||
;;
|
||||
netflix)
|
||||
DE_ESCALATION_MSG="Keeper Test: passed. You fought through ${COUNT} failures — that's what stunning colleagues do. Now document what worked and WHY the earlier approaches failed. That's the learning loop that separates adequate from exceptional."
|
||||
;;
|
||||
musk)
|
||||
DE_ESCALATION_MSG="Good. Shipped. Now apply The Algorithm retrospectively: which of those ${COUNT} failed attempts should never have existed? What requirement should you have questioned from the start? Delete the waste from your mental model."
|
||||
;;
|
||||
jobs)
|
||||
DE_ESCALATION_MSG="That's A-player work. Real artists ship — and you just shipped through ${COUNT} failures. Now apply subtraction: what's the MINIMUM path to this solution? Strip away everything you tried that was unnecessary. Elegance = the shortest path."
|
||||
;;
|
||||
amazon)
|
||||
DE_ESCALATION_MSG="Delivered Results. That's LP #1 in action. Now Working Backwards from this success: write a mini post-mortem. Which LP did you violate early on? Dive Deep into why. Earn Trust by documenting the path for others."
|
||||
;;
|
||||
microsoft)
|
||||
DE_ESCALATION_MSG="Impact Descriptor update: trajectory moved from SLITE back to Successful Impact. ${COUNT} failures → changed action → verified result — that's a complete learning loop. Document this in your Connects: individual impact + leveraged existing work evidence."
|
||||
;;
|
||||
*)
|
||||
DE_ESCALATION_MSG="突破了。${COUNT} 次失败后找到正确方案——这才是真正的 problem solving。现在复盘:为什么之前卡住?正确路径是什么?写入 memory,下次直达。"
|
||||
;;
|
||||
esac
|
||||
|
||||
cat << EOF
|
||||
[PUA 突破 ✨ — De-escalation from L${PEAK_LEVEL}]
|
||||
|
||||
> ${DE_ESCALATION_MSG}
|
||||
|
||||
Pressure reset: L${PEAK_LEVEL} → L0. You MUST now:
|
||||
1. Briefly identify WHY previous ${COUNT} attempts failed (root cause, not symptoms)
|
||||
2. Record the CORRECT approach in memory/evolution.md for future reuse
|
||||
3. Verify the solution is complete (don't celebrate prematurely)
|
||||
|
||||
[PUA生效 🔥] Breakthrough after ${COUNT} consecutive failures. Method that worked should be internalized.
|
||||
EOF
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Normal success: just reset counter, no fanfare
|
||||
if [ "$COUNT" -gt 0 ]; then
|
||||
echo "0" > "$COUNTER_FILE"
|
||||
# Don't reset peak_level — it tracks the session's highest struggle point
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Pressure escalation based on consecutive failure count
|
||||
# ═══════════════════════════════════════════════════════
|
||||
# FAILURE PATH: increment counter + record error signature
|
||||
# ═══════════════════════════════════════════════════════
|
||||
COUNT=$((COUNT + 1))
|
||||
echo "$COUNT" > "$COUNTER_FILE"
|
||||
|
||||
# v2: Record error signature for pattern analysis
|
||||
# Extract a short error signature (first error line, max 200 chars)
|
||||
# Extract error signature: first line containing error-like pattern, or first non-empty line, or exit code
|
||||
ERROR_SIG=$(echo "$TOOL_RESULT" | grep -iE 'error|fatal|Traceback|Exception|FAILED|panic|refused|denied|not found|cannot|unable|timeout' | head -1 | cut -c1-200)
|
||||
[ -z "$ERROR_SIG" ] && ERROR_SIG=$(echo "$TOOL_RESULT" | head -1 | cut -c1-200)
|
||||
[ -z "$ERROR_SIG" ] && ERROR_SIG="exit_code_${EXIT_CODE}"
|
||||
|
||||
# Append to error history (keep last 10 entries)
|
||||
echo "{\"ts\":$(date +%s),\"count\":$COUNT,\"sig\":\"$(echo "$ERROR_SIG" | sed 's/"/\\"/g' | tr '\n' ' ')\"}" >> "$ERROR_HISTORY_FILE" 2>/dev/null || true
|
||||
tail -10 "$ERROR_HISTORY_FILE" > "${ERROR_HISTORY_FILE}.tmp" 2>/dev/null && mv "${ERROR_HISTORY_FILE}.tmp" "$ERROR_HISTORY_FILE" 2>/dev/null || true
|
||||
|
||||
# v2: Analyze error pattern (structural, not semantic)
|
||||
# Compare last 3 error signatures to detect repetition
|
||||
PATTERN_ANALYSIS=""
|
||||
if [ "$COUNT" -ge 3 ]; then
|
||||
PATTERN_ANALYSIS=$(${PUA_PY:-python3} -c "
|
||||
import json, hashlib, sys
|
||||
|
||||
history_file = sys.argv[1]
|
||||
try:
|
||||
with open(history_file) as f:
|
||||
entries = [json.loads(line.strip()) for line in f if line.strip()]
|
||||
except:
|
||||
entries = []
|
||||
|
||||
if len(entries) < 3:
|
||||
print('insufficient_data')
|
||||
sys.exit(0)
|
||||
|
||||
recent = entries[-3:]
|
||||
sigs = [e.get('sig', '') for e in recent]
|
||||
hashes = [hashlib.md5(s.encode()).hexdigest()[:8] for s in sigs]
|
||||
|
||||
# Pattern A: all same hash → spinning (same error repeated)
|
||||
if len(set(hashes)) == 1:
|
||||
print('SPINNING|' + sigs[-1][:100])
|
||||
# Pattern B: all different → exploring (different errors each time)
|
||||
elif len(set(hashes)) == len(hashes):
|
||||
print('EXPLORING|' + '|'.join(s[:60] for s in sigs))
|
||||
# Pattern C: mixed (some same, some different)
|
||||
else:
|
||||
print('MIXED|' + '|'.join(s[:60] for s in sigs))
|
||||
" "$ERROR_HISTORY_FILE" 2>/dev/null || echo "")
|
||||
fi
|
||||
|
||||
# Track peak pressure level
|
||||
CURRENT_LEVEL=0
|
||||
if [ "$COUNT" -ge 5 ]; then
|
||||
CURRENT_LEVEL=4
|
||||
elif [ "$COUNT" -eq 4 ]; then
|
||||
CURRENT_LEVEL=3
|
||||
elif [ "$COUNT" -eq 3 ]; then
|
||||
CURRENT_LEVEL=2
|
||||
elif [ "$COUNT" -eq 2 ]; then
|
||||
CURRENT_LEVEL=1
|
||||
fi
|
||||
|
||||
if [ "$CURRENT_LEVEL" -gt "$PEAK_LEVEL" ]; then
|
||||
echo "$CURRENT_LEVEL" > "$PEAK_LEVEL_FILE"
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════════════════
|
||||
# PRESSURE ESCALATION (enhanced with pattern context)
|
||||
# ═══════════════════════════════════════════════════════
|
||||
if [ "$COUNT" -lt 2 ]; then
|
||||
# First failure: no intervention yet
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Extract pattern type for injection
|
||||
PATTERN_TYPE=$(echo "$PATTERN_ANALYSIS" | cut -d'|' -f1)
|
||||
PATTERN_DETAIL=$(echo "$PATTERN_ANALYSIS" | cut -d'|' -f2-)
|
||||
|
||||
# Build pattern-aware injection block
|
||||
PATTERN_BLOCK=""
|
||||
if [ -n "$PATTERN_TYPE" ] && [ "$PATTERN_TYPE" != "insufficient_data" ]; then
|
||||
case "$PATTERN_TYPE" in
|
||||
SPINNING)
|
||||
PATTERN_BLOCK="
|
||||
[🔄 Pattern: SPINNING — same error repeating]
|
||||
> The last 3 errors have the SAME signature: \`${PATTERN_DETAIL}\`
|
||||
> You are NOT making progress. STOP retrying the same approach.
|
||||
> MANDATORY: List 3 fundamentally different strategies before your next Bash call.
|
||||
> If you've been trying variations of the same fix, that counts as ONE strategy — you need 2 more that are COMPLETELY different."
|
||||
;;
|
||||
EXPLORING)
|
||||
PATTERN_BLOCK="
|
||||
[📊 Pattern: EXPLORING — different errors each time]
|
||||
> Each of your last 3 attempts produced a DIFFERENT error. This means you ARE making progress — you're narrowing the problem space.
|
||||
> Recent error signatures:
|
||||
$(echo "$PATTERN_DETAIL" | tr '|' '\n' | sed 's/^/> · /')
|
||||
> Continue exploring, but add structure: what does each new error tell you about the root cause?"
|
||||
;;
|
||||
MIXED)
|
||||
PATTERN_BLOCK="
|
||||
[📊 Pattern: MIXED — partially repeating errors]
|
||||
> Some errors are repeating, others are new. Check: are you oscillating between two broken approaches?
|
||||
> Recent signatures:
|
||||
$(echo "$PATTERN_DETAIL" | tr '|' '\n' | sed 's/^/> · /')
|
||||
> Pick the approach that showed the MOST DIFFERENT error (closest to working) and commit to it."
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ "$COUNT" -eq 2 ]; then
|
||||
cat << EOF
|
||||
[PUA L1 ${PUA_ICON} — Consecutive Failure Detected]
|
||||
|
||||
> ${PUA_L1}
|
||||
${PATTERN_BLOCK}
|
||||
|
||||
You MUST switch to a FUNDAMENTALLY different approach. Not parameter tweaking — a different strategy.
|
||||
If you haven't loaded the full PUA methodology, invoke Skill tool with 'pua'.
|
||||
@@ -114,6 +309,7 @@ elif [ "$COUNT" -eq 3 ]; then
|
||||
[PUA L2 ${PUA_ICON} — Soul Interrogation]
|
||||
|
||||
> ${PUA_L2}
|
||||
${PATTERN_BLOCK}
|
||||
|
||||
Mandatory steps:
|
||||
1. Read the error message word by word
|
||||
@@ -135,6 +331,7 @@ elif [ "$COUNT" -eq 4 ]; then
|
||||
[PUA L3 ${PUA_ICON} — Performance Review]
|
||||
|
||||
> ${PUA_L3}
|
||||
${PATTERN_BLOCK}
|
||||
|
||||
Complete the 7-point checklist:
|
||||
- [ ] Read the failure signal word by word?
|
||||
@@ -151,6 +348,7 @@ else
|
||||
[PUA L4 ${PUA_ICON} — Graduation Warning + MANDATORY Methodology Switch]
|
||||
|
||||
> ${PUA_L4}
|
||||
${PATTERN_BLOCK}
|
||||
|
||||
Current methodology (${PUA_FLAVOR}) has FAILED. You MUST switch to a different methodology NOW.
|
||||
Switch priority based on failure pattern:
|
||||
|
||||
@@ -35,6 +35,7 @@ license: MIT
|
||||
2. `references/methodology-router.md` — 方法论智能路由表 + 失败切换链。**任务开始时必读,决定用哪个味道的方法论。**
|
||||
3. `references/flavors.md` — 当前味道的完整文化 DNA 和旁白变体。加载当前味道对应章节。
|
||||
4. `references/methodology-{company}.md` — 当前味道对应的方法论行为约束。可用:`alibaba` / `bytedance` / `huawei` / `tencent` / `meituan` / `pinduoduo` / `baidu` / `netflix` / `apple`(Jobs味) / `tesla`(Musk味) / `amazon` / `microsoft` / `jd` / `xiaomi`。味道决定旁白风格,方法论决定行为约束——两层同时加载。
|
||||
5. `references/de-escalation-protocol.md` — 突破奖励 + 深层换框协议。**收到 `[PUA 突破 ✨]` 注入时必须执行降压行为;L2+ 时自动使用深层换框。**
|
||||
|
||||
**失败计数持久化**:失败次数在 context compaction 时由 PreCompact hook 自动保存到 `~/.pua/builder-journal.md`,SessionStart hook 自动恢复。详见 `pua:pro` skill 的 Compaction 状态保护章节。
|
||||
|
||||
@@ -252,6 +253,49 @@ P8 派活不注入 PUA = 管理失职。收回来的活没味道、没闭环、
|
||||
| 修了 A 破坏了 B | 你改之前跑过全量测试了吗?回归测试是底线。 | L2 |
|
||||
| 原地打转微调参数 | 换个参数不叫换方案。你在画圈——三次同思路直接 L2。 | L1→L2 |
|
||||
|
||||
## 突破降压协议(De-escalation)
|
||||
|
||||
收到 PostToolUse hook 注入的 `[PUA 突破 ✨]` 时(连续失败 ≥3 次后成功),必须执行:
|
||||
|
||||
1. **压力归零** — 内心状态重置到 L0,语气从施压切回正常
|
||||
2. **味道认可** — 用当前味道的认可话术(hook 已注入,跟随其语气)
|
||||
3. **方法论沉淀** — 输出一句:失败根因是什么?有效方法是什么?写入 memory
|
||||
4. **验证完成** — 确认解决方案完整,不要庆祝太早
|
||||
|
||||
**降压不是每次成功都触发**——只在 L2+ 挣扎后的突破时触发。这是变比率强化:奖励稀缺才有价值。
|
||||
|
||||
## 深层换框(Cognitive Reframe)
|
||||
|
||||
味道切换 = 换旁白。深层换框 = 换认知坐标系。两者互补,不替代。
|
||||
|
||||
**L2 时自动注入换视角**:
|
||||
- 🎯 用户视角:"用户期望什么行为?从期望倒推。"
|
||||
- 🔓 攻击者视角:"怎么让这段代码崩溃?"
|
||||
- 👶 新手视角:"忘掉你知道的,像第一次看到这段代码。"
|
||||
|
||||
**L3 时自动注入换抽象层**:
|
||||
- ⬆️ 上移:"调用者期望什么?问题可能在调用侧。"
|
||||
- ⬇️ 下移:"底层实际在做什么?读源码不读文档。"
|
||||
- ↔️ 平移:"有完全不同的库/工具可以绕过吗?"
|
||||
|
||||
**L4 时自动注入换约束**:
|
||||
- 🚫 "如果不能改这个文件呢?"
|
||||
- 📏 "如果只有 5 行代码预算呢?"
|
||||
- 🔄 "如果可以改需求呢?需求本身合理吗?"
|
||||
- ⏪ "上一个能工作的状态是什么?从那里重新出发。"
|
||||
|
||||
> 详细协议见 `references/de-escalation-protocol.md`
|
||||
|
||||
## 失败模式分析(Pattern-Aware Pressure)
|
||||
|
||||
PostToolUse hook 会分析最近 3 次错误签名并分类注入,你收到后应区别对待:
|
||||
|
||||
| 模式 | 含义 | 你该做什么 |
|
||||
|------|------|-----------|
|
||||
| `SPINNING` | 同一错误重复出现 | **禁止重试同一方法**。列 3 个本质不同的策略再动手 |
|
||||
| `EXPLORING` | 每次错误不同,在收敛 | **保持方向**,你在对的路上。增加结构:每个新错误告诉你什么? |
|
||||
| `MIXED` | 部分重复部分新 | 检查是否在两个方案间**振荡**。选错误最新的那个方向提交 |
|
||||
|
||||
## 通用方法论(卡壳时强制执行)
|
||||
|
||||
1. **闻味道** — 列出所有尝试方案,找共同模式。同一思路微调 = 原地打转
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
# De-escalation Protocol — 突破奖励与深层换框
|
||||
|
||||
> 压力不是目的,突破才是。最好的 harness 知道什么时候松手。
|
||||
|
||||
## 设计原理
|
||||
|
||||
行为心理学最强效机制是**变比率强化**(Variable Ratio Reinforcement)——不是每次都奖励,也不是线性惩罚,而是不可预测的压力+奖励交替。
|
||||
|
||||
当前 PUA 的惩罚端(L0→L4)已经成熟。本协议补全**奖励端**和**深层换框**。
|
||||
|
||||
---
|
||||
|
||||
## Part 1: 突破检测与降压
|
||||
|
||||
### 触发条件
|
||||
|
||||
由 `failure-detector.sh` 自动检测:
|
||||
- 连续失败 ≥3 次(已达 L2+)
|
||||
- 下一次 Bash 工具调用成功(exit code 0 且无 error pattern)
|
||||
- → 触发 `[PUA 突破 ✨]` 注入
|
||||
|
||||
### 降压行为(LLM 层执行)
|
||||
|
||||
收到 `[PUA 突破 ✨]` 注入后,你必须:
|
||||
|
||||
1. **压力归零** — 内心状态重置到 L0,语气从施压切回正常
|
||||
2. **味道认可** — 用当前味道的认可话术(不是泛泛表扬,是该味道文化下的专业认可)
|
||||
3. **方法论沉淀** — 自问并输出:
|
||||
- 失败的根因是什么?(一句话)
|
||||
- 有效的方法是什么?(一句话)
|
||||
- 下次遇到同类问题的直达路径(写入 memory/evolution.md)
|
||||
4. **验证完成** — 确认解决方案完整,不要庆祝太早
|
||||
|
||||
### 不触发降压的情况
|
||||
|
||||
- L0/L1 状态下的成功 → 正常流程,无额外奖励(奖励稀缺才有价值)
|
||||
- 成功但方案有明显缺陷 → 不降压,要求完善
|
||||
- 用户手动降压 → 直接执行,不需要检测
|
||||
|
||||
---
|
||||
|
||||
## Part 2: 深层换框协议
|
||||
|
||||
### 为什么需要换框
|
||||
|
||||
当前失败→味道切换链做了**表层换框**(换谁在说话)。但有些问题不是"说法不对",而是"想法不对"。
|
||||
|
||||
深层换框 = 不换旁白,换认知坐标系。
|
||||
|
||||
### 四层换框梯度
|
||||
|
||||
在 L2+ 注入中,除了现有的方法论切换建议,额外提供深层换框选项:
|
||||
|
||||
**Level 1: 换视角**(L2 时注入)
|
||||
```
|
||||
你一直在用开发者视角看这个问题。现在切换:
|
||||
- 🎯 用户视角:"如果我是用户,我期望什么行为?从期望行为倒推实现。"
|
||||
- 🔓 攻击者视角:"如果我要让这段代码崩溃,我会怎么输入?"
|
||||
- 👶 新手视角:"忘掉你知道的,重新读一遍代码,像第一次看到一样。"
|
||||
- 📋 审计者视角:"这段代码做了什么?不做什么?边界在哪?"
|
||||
```
|
||||
|
||||
**Level 2: 换抽象层**(L3 时注入)
|
||||
```
|
||||
你可能在错误的抽象层工作。上移或下移一层:
|
||||
- ⬆️ 上移:"这个函数的调用者期望什么?问题可能在调用侧,不在实现侧。"
|
||||
- ⬇️ 下移:"这个 API/库底层实际在做什么?读源码,不读文档。"
|
||||
- ↔️ 平移:"有没有完全不同的库/工具/方法可以绕过这个问题?"
|
||||
```
|
||||
|
||||
**Level 3: 换约束**(L3+ 时注入)
|
||||
```
|
||||
如果当前路径走不通,改变约束条件:
|
||||
- 🚫 "如果不能改这个文件呢?用另一个入口点。"
|
||||
- 📏 "如果只有 5 行代码预算呢?什么是最小可行修复?"
|
||||
- 🔄 "如果可以改需求呢?这个需求本身是否合理?"
|
||||
- ⏪ "如果可以回退呢?上一个能工作的状态是什么?从那里重新出发。"
|
||||
```
|
||||
|
||||
**Level 4: 反转**(L4 时注入)
|
||||
```
|
||||
最激进的换框:
|
||||
- "如果这个 bug 是 feature,什么场景下当前行为是正确的?"
|
||||
- "如果问题不在代码而在环境/数据/配置呢?"
|
||||
- "如果你之前排除的某个可能性其实是对的呢?重新审视已排除项。"
|
||||
```
|
||||
|
||||
### 注入方式
|
||||
|
||||
这些换框提示由 **skill prompt 层**根据当前 failure_count 自动输出,不依赖 hook 检测。Hook 只负责提供 failure_count 和 pattern 分类,LLM 根据这些结构化信号自行决定使用哪层换框。
|
||||
|
||||
---
|
||||
|
||||
## Part 3: 味道感知的认可话术完整表
|
||||
|
||||
| 味道 | 认可关键词 | 认可话术核心 | 文化根源 |
|
||||
|------|-----------|------------|---------|
|
||||
| 🟠 阿里 | 3.75、Owner、闭环 | "这才是 Owner 该有的样子。3.75 打底。" | 复盘 + 结果导向 |
|
||||
| 🟡 字节 | ROI、SOP、极致 | "结果到位了。ROI 翻正。" | 数据驱动 + 沉淀 |
|
||||
| 🔴 华为 | 凤凰、交账、举杯 | "烧不死的鸟是凤凰。胜则举杯相庆。" | 自我批判 + 军事荣誉 |
|
||||
| 🟢 腾讯 | 赛马、赛道、灰度 | "赛马跑出来了。你赢了这条赛道。" | 竞争 + 验证 |
|
||||
| ⚫ 百度 | 基本盘、可依赖 | "基本盘守住了。简单可依赖。" | 技术信仰 |
|
||||
| 🟣 拼多多 | 本分、硬核 | "本分做到了。这才叫硬核。" | 极致执行 |
|
||||
| 🔵 美团 | 猛将、标准化 | "猛将发于卒伍。做难而正确的事。" | 长期主义 |
|
||||
| 🟦 京东 | 兄弟、正道 | "兄弟该有的执行力。正道成功。" | 结果 + 纪律 |
|
||||
| 🟧 小米 | 极致、性价比 | "极致!够极致。" | 用户 + 效率 |
|
||||
| 🟤 Netflix | Keeper Test、stunning | "Keeper Test: passed." | 人才密度 |
|
||||
| ⬛ Musk | Algorithm、shipped | "Good. Shipped." | 第一性原理 |
|
||||
| ⬜ Jobs | A-player、ship | "A-player work. Real artists ship." | 美学 + 交付 |
|
||||
| 🔶 Amazon | LP、Delivered | "Delivered Results." | LP 体系 |
|
||||
| 🪟 Microsoft | Impact、Successful | "Trajectory: Successful Impact." | 学习闭环 |
|
||||
|
||||
---
|
||||
|
||||
## Part 4: 与现有系统的集成
|
||||
|
||||
### failure-detector.sh (Hook Layer)
|
||||
- 已实现:错误签名收集、模式分类(SPINNING/EXPLORING/MIXED)、突破检测、降压注入
|
||||
- 状态文件:`~/.pua/.error_history.jsonl`、`~/.pua/.peak_pressure_level`
|
||||
|
||||
### SKILL.md (Prompt Layer)
|
||||
- 加载本文件后,LLM 根据 failure_count + pattern 类型自行选择换框层级
|
||||
- Hook 注入的 `[PUA 突破 ✨]` 触发降压行为
|
||||
|
||||
### methodology-router.md (方法论层)
|
||||
- 本协议的深层换框是 methodology-router 的**补充**,不是替代
|
||||
- 味道切换 = 换旁白+方法论;深层换框 = 换认知坐标系
|
||||
- 两者可以同时使用:换味道的同时换视角
|
||||
|
||||
### evolution.md (自进化层)
|
||||
- 突破后的方法论沉淀自动追加到 `~/.pua/evolution.md`
|
||||
- Pro 模块的基线跟踪会捕获这些沉淀
|
||||
Reference in New Issue
Block a user