skills-experimental/diff-optimizer-pattern/SKILL.md
# Diff Optimizer Pattern Skill Diff Optimizer Pattern - optimize single pass + merge cursorMove + remove no-op (0,0) + concat styleStr + dedupe hyperlinks + cancel hide/show pairs + result array + len counter。 ## 功能概述 从Claude Code的ink/optimizer.ts提取的Diff优化模式,用于OpenClaw的终端渲染优化。 ## 核心机制 ### optimize Function ```typescript export function optimize(diff: Diff): Diff { if (diff.length <= 1) { return diff // Single patch: no optimization needed } const result: Diff = [] let len = 0
npx skillsauth add bianhaifeng789-hue/openclaw-config skills-experimental/diff-optimizer-patternInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Diff Optimizer Pattern - optimize single pass + merge cursorMove + remove no-op (0,0) + concat styleStr + dedupe hyperlinks + cancel hide/show pairs + result array + len counter。
从Claude Code的ink/optimizer.ts提取的Diff优化模式,用于OpenClaw的终端渲染优化。
export function optimize(diff: Diff): Diff {
if (diff.length <= 1) {
return diff // Single patch: no optimization needed
}
const result: Diff = []
let len = 0 // Track result length for merge checks
for (const patch of diff) {
// Apply all rules in single pass
}
return result
}
// Single-pass optimization
// All rules applied together
// result array + len counter
// Skip no-ops
if (type === 'stdout') {
if (patch.content === '') continue // Empty stdout
} else if (type === 'cursorMove') {
if (patch.x === 0 && patch.y === 0) continue // No-op move
} else if (type === 'clear') {
if (patch.count === 0) continue // Clear 0 lines
}
// Skip empty content
// Skip (0,0) cursorMove
# Skip clear count=0
// Merge consecutive cursorMove
if (type === 'cursorMove' && lastType === 'cursorMove') {
result[lastIdx] = {
type: 'cursorMove',
x: last.x + patch.x,
y: last.y + patch.y,
}
continue
}
// Sum x and y coordinates
// Single cursorMove instead of multiple
# Reduce patches count
// Collapse consecutive cursorTo (only the last one matters)
if (type === 'cursorTo' && lastType === 'cursorTo') {
result[lastIdx] = patch // Replace with last
continue
}
// Only last cursorTo matters
// Replace previous
# Sequential cursorTo collapse
// Concat adjacent style patches. styleStr is a transition diff
// (computed by diffAnsiCodes(from, to)), not a setter
if (type === 'styleStr' && lastType === 'styleStr') {
result[lastIdx] = { type: 'styleStr', str: last.str + patch.str }
continue
}
// Concat style strings
// Transition diffs concatenated
# BCE (Background Color Erase) handled
// Dedupe hyperlinks
if (
type === 'hyperlink' &&
lastType === 'hyperlink' &&
patch.uri === last.uri
) {
continue // Same URI: skip duplicate
}
// Same hyperlink URI: skip
# OSC8 hyperlink dedupe
// Cancel cursor hide/show pairs
if (
(type === 'cursorShow' && lastType === 'cursorHide') ||
(type === 'cursorHide' && lastType === 'cursorShow')
) {
result.pop()
len--
continue
}
// Hide+Show pair cancels
// Remove both patches
# Cursor visibility cancel
const result: Diff = []
let len = 0
// After push:
result.push(patch)
len++
// After cancel:
result.pop()
len--
// Manual length tracking
// Faster than result.length
# Merge logic uses len
{
"originalPatches": 50,
"optimizedPatches": 30,
"mergedCursorMove": 5,
"dedupedHyperlinks": 3
}
for (patch of diff) → apply all rules → single iteration → O(n)
// 一次遍历应用所有规则
// O(n)复杂度
// 无nested loops
cursorMove: merge (sum x+y) | cursorTo: collapse (replace)
// cursorMove合并(累加坐标)
// cursorTo替换(只保留last)
# 不同类型处理方式不同
styleStr: transition diff → concat → BCE handled → can't drop first
// styleStr是transition diff
// 不能drop第一个
# BCE(Background Color Erase)问题
let len = 0 → len++ / len-- → faster than result.length
// 手动len计数
// 比result.length快
# merge逻辑需要len
ink/optimizer.ts (93 lines)business
IAA 日报飞书输出能力。 支持把固定 CSV 模板一键转换成: - 中文运营结论 - 飞书卡片 JSON - 飞书发送载荷 Use when: - 需要把 IAA 日报直接发到飞书 - 需要从 CSV 一键生成运营日报
data-ai
IAA日报分析模型 功能: - 渠道日报自动分析 - 小时级+日级ROI联动判断 - 按地区输出加量/降量/停投建议 - 按产品类型输出阈值 - 自动识别利润区/观察区/止损区 Use when: - 分析每天投放数据 - 生成运营日报结论 - 判断是否加量/降量/停投 - 对比美加澳/日韩表现 Keywords: - 日报模型, 投放日报, 加量, 降量, 停投, ROI日报, 分地区分析
data-ai
IAA固定日报分析模板 功能: - 固定字段模板(可直接贴每天数据) - 自动输出总盘结论 - 自动输出美加澳/日韩结论 - 自动给出加量/降量/停投建议 - 适配文件修复/清理两类产品 Use when: - 需要固定日报格式 - 每天复盘渠道表现 - 给运营团队出统一结论 Keywords: - 固定模板, 日报模板, ROI模板, IAA日报, 运营模板
development
# HyperlinkPool Pattern Skill HyperlinkPool Pattern - HyperlinkPool class + strings array + stringMap + Index 0 no hyperlink + intern(hyperlink) + get(id) + undefined handling + 5-minute reset + OSC8 hyperlink interning。 ## 功能概述 从Claude Code的ink/screen.ts提取的HyperlinkPool模式,用于OpenClaw的OSC8超链接池管理。 ## 核心机制 ### HyperlinkPool Class ```typescript export class HyperlinkPool { private strings: string[] = [''] // Index 0 = no hyperlink private stringMap = new Map<string, number>() // strings